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.cim; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | /** |
24 | * |
25 | * The type of resource this allocation setting represents. |
26 | * |
27 | * @author Adrian Cole |
28 | * @see <a |
29 | * href="http://dmtf.org/sites/default/files/cim/cim_schema_v2280/cim_schema_2.28.0Final-Doc.zip" |
30 | * /> |
31 | * |
32 | */ |
33 | public abstract class SettingData implements Comparable<SettingData> { |
34 | |
35 | public static Builder builder() { |
36 | return new Builder(); |
37 | } |
38 | |
39 | public Builder toBuilder() { |
40 | return builder().fromSettingData(this); |
41 | } |
42 | |
43 | public static class Builder { |
44 | protected String elementName; |
45 | protected String instanceID; |
46 | |
47 | /** |
48 | * @see SettingData#getElementName |
49 | */ |
50 | public Builder elementName(String elementName) { |
51 | this.elementName = checkNotNull(elementName, "elementName"); |
52 | return this; |
53 | } |
54 | |
55 | /** |
56 | * @see SettingData#getInstanceID |
57 | */ |
58 | public Builder instanceID(String instanceID) { |
59 | this.instanceID = checkNotNull(instanceID, "instanceID"); |
60 | return this; |
61 | } |
62 | |
63 | public Builder fromSettingData(SettingData in) { |
64 | return elementName(in.getElementName()).instanceID(in.getInstanceID()); |
65 | } |
66 | } |
67 | |
68 | protected final String elementName; |
69 | protected final String instanceID; |
70 | |
71 | public SettingData(String elementName, String instanceID) { |
72 | this.elementName = checkNotNull(elementName, "elementName"); |
73 | this.instanceID = checkNotNull(instanceID, "instanceID"); |
74 | } |
75 | |
76 | /** |
77 | * The user-friendly name for this instance of SettingData. In addition, the user-friendly name |
78 | * can be used as an index property for a search or query. (Note: The name does not have to be |
79 | * unique within a namespace.) |
80 | */ |
81 | public String getElementName() { |
82 | return elementName; |
83 | } |
84 | |
85 | /** |
86 | * Within the scope of the instantiating Namespace, InstanceID opaquely and uniquely identifies |
87 | * an instance of this class. |
88 | */ |
89 | public String getInstanceID() { |
90 | return instanceID; |
91 | } |
92 | |
93 | @Override |
94 | public int hashCode() { |
95 | final int prime = 31; |
96 | int result = 1; |
97 | result = prime * result + ((elementName == null) ? 0 : elementName.hashCode()); |
98 | result = prime * result + ((instanceID == null) ? 0 : instanceID.hashCode()); |
99 | return result; |
100 | } |
101 | |
102 | @Override |
103 | public boolean equals(Object obj) { |
104 | if (this == obj) |
105 | return true; |
106 | if (obj == null) |
107 | return false; |
108 | if (getClass() != obj.getClass()) |
109 | return false; |
110 | SettingData other = (SettingData) obj; |
111 | if (elementName == null) { |
112 | if (other.elementName != null) |
113 | return false; |
114 | } else if (!elementName.equals(other.elementName)) |
115 | return false; |
116 | if (instanceID == null) { |
117 | if (other.instanceID != null) |
118 | return false; |
119 | } else if (!instanceID.equals(other.instanceID)) |
120 | return false; |
121 | return true; |
122 | } |
123 | |
124 | @Override |
125 | public String toString() { |
126 | return String.format("[elementName=%s, instanceID=%s]", elementName, instanceID); |
127 | } |
128 | |
129 | /** |
130 | * {@inheritDoc} |
131 | */ |
132 | @Override |
133 | public int compareTo(SettingData o) { |
134 | if (instanceID == null) |
135 | return -1; |
136 | return (this == o) ? 0 : instanceID.compareTo(o.instanceID); |
137 | } |
138 | |
139 | } |