| 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.vcloud.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.List; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | import org.jclouds.javax.annotation.Nullable; |
| 28 | |
| 29 | import org.jclouds.vcloud.domain.ReferenceType; |
| 30 | import org.jclouds.vcloud.domain.Org; |
| 31 | import org.jclouds.vcloud.domain.Task; |
| 32 | |
| 33 | import com.google.common.collect.Iterables; |
| 34 | import com.google.common.collect.Lists; |
| 35 | import com.google.common.collect.Maps; |
| 36 | |
| 37 | /** |
| 38 | * Locations of resources in vCloud |
| 39 | * |
| 40 | * @author Adrian Cole |
| 41 | * |
| 42 | */ |
| 43 | public class OrgImpl extends ReferenceTypeImpl implements Org { |
| 44 | private final String fullName; |
| 45 | @Nullable |
| 46 | private final String description; |
| 47 | private final Map<String, ReferenceType> catalogs = Maps.newLinkedHashMap(); |
| 48 | private final Map<String, ReferenceType> vdcs = Maps.newLinkedHashMap(); |
| 49 | private final Map<String, ReferenceType> networks = Maps.newLinkedHashMap(); |
| 50 | private final ReferenceType tasksList; |
| 51 | private final List<Task> tasks = Lists.newArrayList(); |
| 52 | |
| 53 | public OrgImpl(String name, String type, URI id, String fullName, String description, |
| 54 | Map<String, ReferenceType> catalogs, Map<String, ReferenceType> vdcs, Map<String, ReferenceType> networks, |
| 55 | @Nullable ReferenceType tasksList, Iterable<Task> tasks) { |
| 56 | super(name, type, id); |
| 57 | this.fullName = checkNotNull(fullName, "fullName"); |
| 58 | this.description = description; |
| 59 | this.catalogs.putAll(checkNotNull(catalogs, "catalogs")); |
| 60 | this.vdcs.putAll(checkNotNull(vdcs, "vdcs")); |
| 61 | this.networks.putAll(checkNotNull(networks, "networks")); |
| 62 | this.tasksList = tasksList; |
| 63 | Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks")); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String getFullName() { |
| 68 | return fullName; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String getDescription() { |
| 73 | return description; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Map<String, ReferenceType> getCatalogs() { |
| 78 | return catalogs; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public Map<String, ReferenceType> getVDCs() { |
| 83 | return vdcs; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Map<String, ReferenceType> getNetworks() { |
| 88 | return networks; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public ReferenceType getTasksList() { |
| 93 | return tasksList; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public List<Task> getTasks() { |
| 98 | return tasks; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public int hashCode() { |
| 103 | final int prime = 31; |
| 104 | int result = super.hashCode(); |
| 105 | result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode()); |
| 106 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 107 | result = prime * result + ((fullName == null) ? 0 : fullName.hashCode()); |
| 108 | result = prime * result + ((networks == null) ? 0 : networks.hashCode()); |
| 109 | result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); |
| 110 | result = prime * result + ((tasksList == null) ? 0 : tasksList.hashCode()); |
| 111 | result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode()); |
| 112 | return result; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public boolean equals(Object obj) { |
| 117 | if (this == obj) |
| 118 | return true; |
| 119 | if (!super.equals(obj)) |
| 120 | return false; |
| 121 | if (getClass() != obj.getClass()) |
| 122 | return false; |
| 123 | OrgImpl other = (OrgImpl) obj; |
| 124 | if (catalogs == null) { |
| 125 | if (other.catalogs != null) |
| 126 | return false; |
| 127 | } else if (!catalogs.equals(other.catalogs)) |
| 128 | return false; |
| 129 | if (description == null) { |
| 130 | if (other.description != null) |
| 131 | return false; |
| 132 | } else if (!description.equals(other.description)) |
| 133 | return false; |
| 134 | if (fullName == null) { |
| 135 | if (other.fullName != null) |
| 136 | return false; |
| 137 | } else if (!fullName.equals(other.fullName)) |
| 138 | return false; |
| 139 | if (networks == null) { |
| 140 | if (other.networks != null) |
| 141 | return false; |
| 142 | } else if (!networks.equals(other.networks)) |
| 143 | return false; |
| 144 | if (tasks == null) { |
| 145 | if (other.tasks != null) |
| 146 | return false; |
| 147 | } else if (!tasks.equals(other.tasks)) |
| 148 | return false; |
| 149 | if (tasksList == null) { |
| 150 | if (other.tasksList != null) |
| 151 | return false; |
| 152 | } else if (!tasksList.equals(other.tasksList)) |
| 153 | return false; |
| 154 | if (vdcs == null) { |
| 155 | if (other.vdcs != null) |
| 156 | return false; |
| 157 | } else if (!vdcs.equals(other.vdcs)) |
| 158 | return false; |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public int compareTo(ReferenceType o) { |
| 164 | return (this == o) ? 0 : getHref().compareTo(o.getHref()); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String toString() { |
| 169 | return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", fullName=" + fullName |
| 170 | + ", description=" + description + ", catalogs=" + catalogs + ", networks=" + networks + ", tasksList=" |
| 171 | + tasksList + ", vdcs=" + vdcs + ", tasks=" + tasks + "]"; |
| 172 | } |
| 173 | |
| 174 | } |