| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.trmk.vcloud_0_8.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import javax.annotation.Nullable; |
| 27 | |
| 28 | import org.jclouds.trmk.vcloud_0_8.domain.Org; |
| 29 | import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; |
| 30 | |
| 31 | import com.google.common.collect.ImmutableMap; |
| 32 | |
| 33 | /** |
| 34 | * Locations of resources in vCloud |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | * |
| 38 | */ |
| 39 | public class OrgImpl extends ReferenceTypeImpl implements Org { |
| 40 | @Nullable |
| 41 | private final String description; |
| 42 | private final Map<String, ReferenceType> catalogs; |
| 43 | private final Map<String, ReferenceType> vdcs; |
| 44 | private final ReferenceType keys; |
| 45 | private final ImmutableMap<String, ReferenceType> tasksLists; |
| 46 | |
| 47 | public OrgImpl(String name, String type, URI id, String description, Map<String, ReferenceType> catalogs, |
| 48 | Map<String, ReferenceType> vdcs, Map<String, ReferenceType> tasksLists, ReferenceType keys) { |
| 49 | super(name, type, id); |
| 50 | this.description = description; |
| 51 | this.catalogs = ImmutableMap.copyOf(checkNotNull(catalogs, "catalogs")); |
| 52 | this.vdcs = ImmutableMap.copyOf(checkNotNull(vdcs, "vdcs")); |
| 53 | this.tasksLists = ImmutableMap.copyOf(checkNotNull(tasksLists, "tasksLists")); |
| 54 | this.keys = checkNotNull(keys, "keys"); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String getDescription() { |
| 59 | return description; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public Map<String, ReferenceType> getCatalogs() { |
| 64 | return catalogs; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public Map<String, ReferenceType> getVDCs() { |
| 69 | return vdcs; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | final int prime = 31; |
| 75 | int result = super.hashCode(); |
| 76 | result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode()); |
| 77 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 78 | result = prime * result + ((keys == null) ? 0 : keys.hashCode()); |
| 79 | result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode()); |
| 80 | result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode()); |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object obj) { |
| 86 | if (this == obj) |
| 87 | return true; |
| 88 | if (!super.equals(obj)) |
| 89 | return false; |
| 90 | if (getClass() != obj.getClass()) |
| 91 | return false; |
| 92 | OrgImpl other = (OrgImpl) obj; |
| 93 | if (catalogs == null) { |
| 94 | if (other.catalogs != null) |
| 95 | return false; |
| 96 | } else if (!catalogs.equals(other.catalogs)) |
| 97 | return false; |
| 98 | if (description == null) { |
| 99 | if (other.description != null) |
| 100 | return false; |
| 101 | } else if (!description.equals(other.description)) |
| 102 | return false; |
| 103 | if (keys == null) { |
| 104 | if (other.keys != null) |
| 105 | return false; |
| 106 | } else if (!keys.equals(other.keys)) |
| 107 | return false; |
| 108 | if (tasksLists == null) { |
| 109 | if (other.tasksLists != null) |
| 110 | return false; |
| 111 | } else if (!tasksLists.equals(other.tasksLists)) |
| 112 | return false; |
| 113 | if (vdcs == null) { |
| 114 | if (other.vdcs != null) |
| 115 | return false; |
| 116 | } else if (!vdcs.equals(other.vdcs)) |
| 117 | return false; |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public int compareTo(ReferenceType o) { |
| 123 | return (this == o) ? 0 : getHref().compareTo(o.getHref()); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public String toString() { |
| 128 | return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description |
| 129 | + ", catalogs=" + catalogs + ", tasksLists=" + tasksLists + ", vdcs=" + vdcs + ", keys=" + keys + "]"; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public Map<String, ReferenceType> getTasksLists() { |
| 134 | return tasksLists; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public ReferenceType getKeys() { |
| 139 | return keys; |
| 140 | } |
| 141 | |
| 142 | } |