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.ovf; |
20 | |
21 | /** |
22 | * |
23 | * @author Adrian Cole |
24 | */ |
25 | public class Property { |
26 | public static Builder builder() { |
27 | return new Builder(); |
28 | } |
29 | |
30 | public static class Builder { |
31 | protected String key; |
32 | protected String value; |
33 | protected String label; |
34 | protected String description; |
35 | |
36 | /** |
37 | * @see Property#getKey |
38 | */ |
39 | public Builder key(String key) { |
40 | this.key = key; |
41 | return this; |
42 | } |
43 | |
44 | /** |
45 | * @see Property#getValue |
46 | */ |
47 | public Builder value(String value) { |
48 | this.value = value; |
49 | return this; |
50 | } |
51 | |
52 | /** |
53 | * @see Section#getLabel |
54 | */ |
55 | public Builder label(String label) { |
56 | this.label = label; |
57 | return this; |
58 | } |
59 | |
60 | /** |
61 | * @see Section#getDescription |
62 | */ |
63 | public Builder description(String description) { |
64 | this.description = description; |
65 | return this; |
66 | } |
67 | |
68 | public Property build() { |
69 | return new Property(key, value, label, description); |
70 | } |
71 | |
72 | public Builder fromProperty(Property in) { |
73 | return key(in.getKey()).value(in.getValue()).description(in.getDescription()).label(in.getLabel()); |
74 | } |
75 | } |
76 | |
77 | private final String key; |
78 | private final String value; |
79 | private final String label; |
80 | private final String description; |
81 | |
82 | public Property(String key, String value, String label, String description) { |
83 | this.key = key; |
84 | this.value = value; |
85 | this.label = label; |
86 | this.description = description; |
87 | } |
88 | |
89 | @Override |
90 | public int hashCode() { |
91 | final int prime = 31; |
92 | int result = 1; |
93 | result = prime * result + ((key == null) ? 0 : key.hashCode()); |
94 | return result; |
95 | } |
96 | |
97 | @Override |
98 | public boolean equals(Object obj) { |
99 | if (this == obj) |
100 | return true; |
101 | if (obj == null) |
102 | return false; |
103 | if (getClass() != obj.getClass()) |
104 | return false; |
105 | Property other = (Property) obj; |
106 | if (key == null) { |
107 | if (other.key != null) |
108 | return false; |
109 | } else if (!key.equals(other.key)) |
110 | return false; |
111 | return true; |
112 | } |
113 | |
114 | @Override |
115 | public String toString() { |
116 | return String.format("[key=%s, value=%s, label=%s, description=%s]", key, value, label, description); |
117 | } |
118 | |
119 | public String getKey() { |
120 | return key; |
121 | } |
122 | |
123 | public String getDescription() { |
124 | return description; |
125 | } |
126 | |
127 | public String getLabel() { |
128 | return label; |
129 | } |
130 | |
131 | public String getValue() { |
132 | return value; |
133 | } |
134 | } |