| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.Map; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.jclouds.domain.internal.LocationImpl; |
| 27 | |
| 28 | import com.google.common.collect.ImmutableMap; |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | |
| 31 | /** |
| 32 | * |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | public class LocationBuilder { |
| 36 | protected LocationScope scope; |
| 37 | protected String id; |
| 38 | protected String description; |
| 39 | protected Location parent; |
| 40 | protected Set<String> iso3166Codes = ImmutableSet.of(); |
| 41 | protected Map<String, Object> metadata = ImmutableMap.of(); |
| 42 | |
| 43 | public LocationBuilder scope(LocationScope scope) { |
| 44 | this.scope = scope; |
| 45 | return this; |
| 46 | } |
| 47 | |
| 48 | public LocationBuilder id(String id) { |
| 49 | this.id = id; |
| 50 | return this; |
| 51 | } |
| 52 | |
| 53 | public LocationBuilder description(String description) { |
| 54 | this.description = description; |
| 55 | return this; |
| 56 | } |
| 57 | |
| 58 | public LocationBuilder parent(Location parent) { |
| 59 | this.parent = parent; |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | public LocationBuilder iso3166Codes(Iterable<String> iso3166Codes) { |
| 64 | this.iso3166Codes = ImmutableSet.copyOf(checkNotNull(iso3166Codes, "iso3166Codes")); |
| 65 | return this; |
| 66 | } |
| 67 | |
| 68 | public LocationBuilder metadata(Map<String, Object> metadata) { |
| 69 | this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); |
| 70 | return this; |
| 71 | } |
| 72 | |
| 73 | public Location build() { |
| 74 | return new LocationImpl(scope, id, description, parent, iso3166Codes, metadata); |
| 75 | } |
| 76 | } |