001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 *
017 * Derived from code developed by Opentick Corporation, http://www.opentick.com.
018 */
019 package org.otfeed.event;
020
021 import static org.otfeed.event.IdentityUtil.safeCompare;
022 import static org.otfeed.event.IdentityUtil.safeHashCode;
023 import static org.otfeed.event.IdentityUtil.equalsTo;
024
025 import java.io.Serializable;
026
027 /**
028 * Provides exchange information.
029 */
030 public final class OTExchange implements Comparable<OTExchange>, Serializable {
031
032 private static final long serialVersionUID = 7151477567631158035L;
033
034 private String code;
035 private String title;
036 private String description;
037 private boolean available;
038 private String subscriptionURL;
039
040 /**
041 * Default constructor.
042 */
043 public OTExchange() { }
044
045 /**
046 * Constructor.
047 * @param code Exchange code.
048 * @param title Exchange title.
049 * @param description Description of the exchange.
050 * @param available Available field.
051 * @param subscriptionURL URL.
052 */
053 public OTExchange(String code,
054 String title,
055 String description,
056 boolean available,
057 String subscriptionURL) {
058 this.title = title;
059 this.code = code;
060 this.description = description;
061 this.available = available;
062 this.subscriptionURL = subscriptionURL;
063 }
064
065 /**
066 *
067 * @return Exchange code.
068 */
069 public String getCode() {
070 return this.code;
071 }
072
073 /**
074 * Sets exchange code.
075 *
076 * @param code Exchange code.
077 */
078 public void setCode(String code) {
079 this.code = code;
080 }
081
082 /**
083 * @return The exchange title.
084 */
085 public String getTitle() {
086 return this.title;
087 }
088
089 /**
090 * Sets exchange title.
091 *
092 * @param title Exchange title.
093 */
094 public void setTitle(String title) {
095 this.title = title;
096 }
097
098 /**
099 * @return A description of the exchange.
100 */
101 public String getDescription() {
102 return this.description;
103 }
104
105 /**
106 * Sets description of the exchange.
107 *
108 * @param description Description of the exchange.
109 */
110 public void setDescription(String description) {
111 this.description = description;
112 }
113
114 /**
115 * @return Is available.
116 */
117 public boolean isAvailable() {
118 return this.available;
119 }
120
121 /**
122 * Sets available field.
123 *
124 * @param available Available field.
125 */
126 public void setAvailable(boolean available) {
127 this.available = available;
128 }
129
130 /**
131 * @return If the user is not subscribed to this exchange,
132 * he can go to this URL to do so.
133 */
134 public String getSubscriptionURL() {
135 return this.subscriptionURL;
136 }
137
138 /**
139 * Sets SubscriptionURL field.
140 *
141 * @param url URL.
142 */
143 public void setSubscriptionURL(String url) {
144 this.subscriptionURL = url;
145 }
146
147 @Override
148 public String toString() {
149 return "OTExchange: code=" + code + ", title=" + title
150 + ", description=" + description
151 + ", available=" + available
152 + ", subscriptionURL=" + subscriptionURL;
153 }
154
155 @Override
156 public int hashCode() {
157 return safeHashCode(code)
158 + 3 * safeHashCode(title)
159 + 5 * safeHashCode(description)
160 + 7 * safeHashCode(subscriptionURL)
161 + 11 * safeHashCode(available);
162 }
163
164 @Override
165 public boolean equals(Object o) {
166 return equalsTo(this, o);
167 }
168
169 public int compareTo(OTExchange other) {
170 int rc;
171
172 if((rc = safeCompare(code, other.code)) != 0) {
173 return rc;
174 }
175
176 if((rc = safeCompare(title, other.title)) != 0) {
177 return rc;
178 }
179
180 if((rc = safeCompare(description, other.description)) != 0) {
181 return rc;
182 }
183
184 if((rc = safeCompare(available, other.available)) != 0) {
185 return rc;
186 }
187
188 if((rc = safeCompare(subscriptionURL, other.subscriptionURL)) != 0) {
189 return rc;
190 }
191
192 return 0;
193 }
194 }