| 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.providers; |
| 20 | |
| 21 | import java.net.URI; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import com.google.common.collect.ImmutableSet; |
| 25 | |
| 26 | /** |
| 27 | * The BaseProviderMetadata class is an abstraction of {@link ProviderMetadata} to be extended by |
| 28 | * those implementing ProviderMetadata. |
| 29 | * |
| 30 | * (Note: This class must be abstract to allow {@link java.util.ServiceLoader} to work properly. |
| 31 | * |
| 32 | * @author Jeremy Whitlock <jwhitlock@apache.org> |
| 33 | */ |
| 34 | public abstract class BaseProviderMetadata implements ProviderMetadata { |
| 35 | |
| 36 | /** |
| 37 | * @see java.lang.Object#hashCode() |
| 38 | */ |
| 39 | @Override |
| 40 | public int hashCode() { |
| 41 | final int prime = 31; |
| 42 | int result = 1; |
| 43 | URI console = getConsole(); |
| 44 | URI homepage = getHomepage(); |
| 45 | URI docs = getApiDocumentation(); |
| 46 | String id = getId(); |
| 47 | String name = getName(); |
| 48 | String identityName = getIdentityName(); |
| 49 | String credentialName = getCredentialName(); |
| 50 | String type = getType(); |
| 51 | Set<String> linkedServices = getLinkedServices(); |
| 52 | Set<String> iso3166Codes = getIso3166Codes(); |
| 53 | |
| 54 | result = prime * result + ((console == null) ? 0 : console.hashCode()); |
| 55 | result = prime * result + ((homepage == null) ? 0 : homepage.hashCode()); |
| 56 | result = prime * result + ((docs == null) ? 0 : docs.hashCode()); |
| 57 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 58 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 59 | result = prime * result + ((identityName == null) ? 0 : identityName.hashCode()); |
| 60 | result = prime * result + ((credentialName == null) ? 0 : credentialName.hashCode()); |
| 61 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
| 62 | result = prime * result + ((linkedServices == null) ? 0 : linkedServices.hashCode()); |
| 63 | result = prime * result + ((iso3166Codes == null) ? 0 : iso3166Codes.hashCode()); |
| 64 | |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @see java.lang.Object#equals(java.lang.Object) |
| 70 | */ |
| 71 | @Override |
| 72 | public boolean equals(Object obj) { |
| 73 | URI tConsole = getConsole(); |
| 74 | URI tHomepage = getHomepage(); |
| 75 | URI tDocs = getApiDocumentation(); |
| 76 | String tId = getId(); |
| 77 | String tName = getName(); |
| 78 | String tIdentityName = getIdentityName(); |
| 79 | String tCredentialName = getCredentialName(); |
| 80 | String tType = getType(); |
| 81 | Set<String> tLinkedServices = getLinkedServices(); |
| 82 | Set<String> tIso3166Codes = getIso3166Codes(); |
| 83 | |
| 84 | if (this == obj) |
| 85 | return true; |
| 86 | if (obj == null) |
| 87 | return false; |
| 88 | if (getClass() != obj.getClass()) |
| 89 | return false; |
| 90 | |
| 91 | ProviderMetadata other = (ProviderMetadata) obj; |
| 92 | URI oConsole = other.getConsole(); |
| 93 | URI oHomepage = other.getHomepage(); |
| 94 | URI oDocs = other.getApiDocumentation(); |
| 95 | String oId = other.getId(); |
| 96 | String oName = other.getName(); |
| 97 | String oIdentityName = other.getIdentityName(); |
| 98 | String oCredentialName = other.getCredentialName(); |
| 99 | String oType = other.getType(); |
| 100 | Set<String> oLinkedServices = other.getLinkedServices(); |
| 101 | Set<String> oIso3166Codes = other.getIso3166Codes(); |
| 102 | |
| 103 | if (tConsole == null) { |
| 104 | if (oConsole != null) |
| 105 | return false; |
| 106 | } else if (!tConsole.equals(oConsole)) |
| 107 | return false; |
| 108 | if (tDocs == null) { |
| 109 | if (oDocs != null) |
| 110 | return false; |
| 111 | } else if (!tDocs.equals(oDocs)) |
| 112 | return false; |
| 113 | if (tHomepage == null) { |
| 114 | if (oHomepage != null) |
| 115 | return false; |
| 116 | } else if (!tHomepage.equals(oHomepage)) |
| 117 | return false; |
| 118 | if (tId == null) { |
| 119 | if (oId != null) |
| 120 | return false; |
| 121 | } else if (!tId.equals(oId)) |
| 122 | return false; |
| 123 | if (tName == null) { |
| 124 | if (oName != null) |
| 125 | return false; |
| 126 | } else if (!tName.equals(oName)) |
| 127 | return false; |
| 128 | if (tIdentityName == null) { |
| 129 | if (oIdentityName != null) |
| 130 | return false; |
| 131 | } else if (!tIdentityName.equals(oIdentityName)) |
| 132 | return false; |
| 133 | if (tCredentialName == null) { |
| 134 | if (oCredentialName != null) |
| 135 | return false; |
| 136 | } else if (!tCredentialName.equals(oCredentialName)) |
| 137 | return false; |
| 138 | if (tType == null) { |
| 139 | if (oType != null) |
| 140 | return false; |
| 141 | } else if (!tType.equals(oType)) |
| 142 | return false; |
| 143 | if (tLinkedServices == null) { |
| 144 | if (oLinkedServices != null) |
| 145 | return false; |
| 146 | } else if (!tLinkedServices.equals(oLinkedServices)) |
| 147 | return false; |
| 148 | if (tIso3166Codes == null) { |
| 149 | if (oIso3166Codes != null) |
| 150 | return false; |
| 151 | } else if (!tIso3166Codes.equals(oIso3166Codes)) |
| 152 | return false; |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public String toString() { |
| 158 | return "[id=" + getId() + ", type=" + getType() + ", name=" + getName() + ", identityName=" + getIdentityName() |
| 159 | + ", credentialName=" + getCredentialName() + ", homePage=" + getHomepage() + ", console=" |
| 160 | + getConsole() + ", apiDocs=" + getApiDocumentation() + ", linkedServices=" + getLinkedServices() + |
| 161 | ", iso3166Codes=" + getIso3166Codes() + "]"; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public Set<String> getLinkedServices() { |
| 166 | return ImmutableSet.of(getId()); |
| 167 | } |
| 168 | } |