1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.savvis.vpdc.domain;
20
21 import java.net.URI;
22
23
24
25
26
27
28
29 public class ResourceImpl implements Resource {
30 public static Builder builder() {
31 return new Builder();
32 }
33
34 public static class Builder {
35 protected String id;
36 protected String name;
37 protected String type;
38 protected URI href;
39
40 public Builder id(String id) {
41 this.id = id;
42 return this;
43 }
44
45 public Builder name(String name) {
46 this.name = name;
47 return this;
48 }
49
50 public Builder type(String type) {
51 this.type = type;
52 return this;
53 }
54
55 public Builder href(URI href) {
56 this.href = href;
57 return this;
58 }
59
60 public ResourceImpl build() {
61 return new ResourceImpl(id, name, type, href);
62 }
63
64 public static Builder fromResource(ResourceImpl in) {
65 return new Builder().id(in.getId()).name(in.getName()).type(in.getType()).href(in.getHref());
66 }
67 }
68
69 protected final String id;
70 protected final String name;
71 protected final String type;
72 protected final URI href;
73
74 public ResourceImpl(String id, String name, String type, URI href) {
75 this.id = id;
76 this.name = name;
77 this.type = type;
78 this.href = href;
79 }
80
81 public String getId() {
82 return id;
83 }
84
85 public String getName() {
86 return name;
87 }
88
89 public String getType() {
90 return type;
91 }
92
93 public URI getHref() {
94 return href;
95 }
96
97 public int compareTo(Resource that) {
98 return (this == that) ? 0 : getHref().compareTo(that.getHref());
99 }
100
101 @Override
102 public int hashCode() {
103 final int prime = 31;
104 int result = 1;
105 result = prime * result + ((href == null) ? 0 : href.hashCode());
106 result = prime * result + ((id == null) ? 0 : id.hashCode());
107 result = prime * result + ((name == null) ? 0 : name.hashCode());
108 result = prime * result + ((type == null) ? 0 : type.hashCode());
109 return result;
110 }
111
112 @Override
113 public boolean equals(Object obj) {
114 if (this == obj)
115 return true;
116 if (obj == null)
117 return false;
118 if (getClass() != obj.getClass())
119 return false;
120 ResourceImpl other = (ResourceImpl) obj;
121 if (href == null) {
122 if (other.href != null)
123 return false;
124 } else if (!href.equals(other.href))
125 return false;
126 if (id == null) {
127 if (other.id != null)
128 return false;
129 } else if (!id.equals(other.id))
130 return false;
131 if (name == null) {
132 if (other.name != null)
133 return false;
134 } else if (!name.equals(other.name))
135 return false;
136 if (type == null) {
137 if (other.type != null)
138 return false;
139 } else if (!type.equals(other.type))
140 return false;
141 return true;
142 }
143
144 public Builder toBuilder() {
145 return Builder.fromResource(this);
146 }
147
148 @Override
149 public String toString() {
150 return "[id=" + id + ", href=" + href + ", name=" + name + ", type=" + type + "]";
151 }
152 }