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 | import org.jclouds.javax.annotation.Nullable; |
22 | |
23 | /** |
24 | * Metadata about a virtual machine or grouping of them |
25 | * |
26 | * @author Adrian Cole |
27 | */ |
28 | public class Section<T extends Section<T>> { |
29 | |
30 | public static <T extends Section<T>> Builder<T> builder() { |
31 | return new Builder<T>(); |
32 | } |
33 | |
34 | public Builder<T> toBuilder() { |
35 | return new Builder<T>().fromSection(this); |
36 | } |
37 | |
38 | public static class Builder<T extends Section<T>> { |
39 | protected String info; |
40 | |
41 | /** |
42 | * @see Section#getInfo |
43 | */ |
44 | public Builder<T> info(String info) { |
45 | this.info = info; |
46 | return this; |
47 | } |
48 | |
49 | public Section<T> build() { |
50 | return new Section<T>(info); |
51 | } |
52 | |
53 | public Builder<T> fromSection(Section<T> in) { |
54 | return info(in.getInfo()); |
55 | } |
56 | } |
57 | |
58 | protected final String info; |
59 | |
60 | public Section(@Nullable String info) { |
61 | this.info = info; |
62 | } |
63 | |
64 | /** |
65 | * |
66 | * @return ovf info |
67 | */ |
68 | public String getInfo() { |
69 | return info; |
70 | } |
71 | |
72 | @Override |
73 | public int hashCode() { |
74 | final int prime = 31; |
75 | int result = 1; |
76 | result = prime * result + ((info == null) ? 0 : info.hashCode()); |
77 | return result; |
78 | } |
79 | |
80 | @Override |
81 | public boolean equals(Object obj) { |
82 | if (this == obj) |
83 | return true; |
84 | if (obj == null) |
85 | return false; |
86 | if (getClass() != obj.getClass()) |
87 | return false; |
88 | Section<?> other = (Section<?>) obj; |
89 | if (info == null) { |
90 | if (other.info != null) |
91 | return false; |
92 | } else if (!info.equals(other.info)) |
93 | return false; |
94 | return true; |
95 | } |
96 | |
97 | @Override |
98 | public String toString() { |
99 | return "[info=" + getInfo() + "]"; |
100 | } |
101 | |
102 | } |