1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.controller;
17
18 import java.io.Serializable;
19
20 import com.fatwire.assetapi.data.AssetId;
21 import com.openmarket.xcelerate.asset.AssetIdImpl;
22
23
24
25
26
27
28
29 public class AssetIdWithSite implements AssetId, Comparable<AssetIdWithSite>, Serializable {
30
31 private static final long serialVersionUID = 1L;
32 private final AssetIdImpl id;
33 private final String site;
34
35 public AssetIdWithSite(AssetId id, String site) {
36 if (id == null)
37 throw new NullPointerException("id can not be null.");
38 if (id instanceof AssetIdImpl) {
39 this.id = (AssetIdImpl) id;
40 } else {
41 this.id = new AssetIdImpl(id.getType(), id.getId());
42 }
43 this.site = site;
44 }
45
46 public AssetIdWithSite(String type, long id, String site) {
47 if (type == null || site == null)
48 throw new NullPointerException("type=" + type + ",site=" + site);
49 this.id = new AssetIdImpl(type, id);
50 this.site = site;
51
52 }
53
54
55
56
57
58
59
60 public long getId() {
61 return id.getId();
62 }
63
64
65
66
67
68
69
70 public String getType() {
71 return id.getType();
72 }
73
74 public AssetId getAssetId() {
75 return id;
76 }
77
78
79
80
81 public String getSite() {
82 return site;
83 }
84
85
86
87
88
89
90
91 @Override
92 public String toString() {
93 return "AssetIdWithSite [type=" + id.getType() + ", id=" + id.getId() + ", site=" + site + "]";
94 }
95
96
97
98
99
100
101
102 public int compareTo(AssetIdWithSite o) {
103 if (this == o)
104 return 0;
105 int l = id.compareTo(o.getAssetId());
106 if (l != 0)
107 return l;
108
109 return this.site.compareTo(o.site);
110 }
111
112
113
114
115
116
117 @Override
118 public int hashCode() {
119 final int prime = 31;
120 int result = 1;
121 result = prime * result + ((id == null) ? 0 : id.hashCode());
122 result = prime * result + ((site == null) ? 0 : site.hashCode());
123 return result;
124 }
125
126
127
128
129
130
131 @Override
132 public boolean equals(Object obj) {
133 if (this == obj)
134 return true;
135 if (obj == null)
136 return false;
137 if (obj instanceof AssetIdImpl)
138 return id.equals(obj);
139 if (!(obj instanceof AssetIdWithSite))
140 return false;
141 AssetIdWithSite other = (AssetIdWithSite) obj;
142 if (id == null) {
143 if (other.id != null)
144 return false;
145 } else if (!id.equals(other.id))
146 return false;
147 if (site == null) {
148 if (other.site != null)
149 return false;
150 } else if (!site.equals(other.site))
151 return false;
152 return true;
153 }
154
155 }