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
020 package org.otfeed.event;
021
022 import static org.otfeed.event.IdentityUtil.safeCompare;
023 import static org.otfeed.event.IdentityUtil.safeHashCode;
024 import static org.otfeed.event.IdentityUtil.equalsTo;
025
026 import java.io.Serializable;
027
028 /**
029 * Provides information about the symbol.
030 */
031 public final class OTSymbol implements Comparable<OTSymbol>, Serializable {
032
033 private static final long serialVersionUID = 6692254804572091563L;
034
035 private String code;
036 private String company;
037 private String currency;
038 private InstrumentEnum type;
039
040 /**
041 * Default constructor.
042 */
043 public OTSymbol() { }
044
045 /**
046 * Constructor.
047 * @param code String that identifies the equity, option, future, or index.
048 * @param company Company name.
049 * @param currency Currency.
050 * @param type Instrument type.
051 */
052 public OTSymbol(String code, String company,
053 String currency, InstrumentEnum type) {
054 this.code = code;
055 this.company = company;
056 this.currency = currency;
057 this.type = type;
058 }
059
060
061 /**
062 *
063 * @return String that identifies the equity, option, future, or index.
064 */
065 public String getCode() {
066 return this.code;
067 }
068
069
070 /**
071 * Sets code of the symbol.
072 * @param code String that identifies the equity, option, future, or index.
073 */
074 public void setCode(String code) {
075 this.code = code;
076 }
077
078 /**
079 *
080 * @return Company name.
081 */
082 public String getCompany() {
083 return this.company;
084 }
085
086 /**
087 * Sets company name.
088 * @param company Company name.
089 */
090 public void setCompany(String company) {
091 this.company = company;
092 }
093
094 /**
095 *
096 * @return The currency for any prices provided in the events for this symbol; in the current system this value is "USD" for United States Dollars.
097 */
098 public String getCurrency() {
099 return this.currency;
100 }
101
102 /**
103 * Sets currency.
104 * @param currency Currency.
105 */
106 public void setCurrency(String currency) {
107 this.currency = currency;
108 }
109
110 /**
111 *
112 * @return Instrument type.
113 */
114 public InstrumentEnum getType() {
115 return this.type;
116 }
117
118 /**
119 * Sets instrument type.
120 * @param type Instrument type.
121 */
122 public void setType(InstrumentEnum type) {
123 this.type = type;
124 }
125
126 @Override
127 public String toString() {
128 return "OTSymbol: code=" + code + ", company=" + company + ", currency=" + currency + ", type=" + type;
129 }
130
131 @Override
132 public int hashCode() {
133 return safeHashCode(code)
134 + 3 * safeHashCode(company)
135 + 5 * safeHashCode(currency)
136 + 7 * safeHashCode(type);
137 }
138
139 @Override
140 public boolean equals(Object o) {
141 return equalsTo(this, o);
142 }
143
144 public int compareTo(OTSymbol other) {
145 int rc;
146
147 if((rc = safeCompare(code, other.code)) != 0) {
148 return rc;
149 }
150
151 if((rc = safeCompare(company, other.company)) != 0) {
152 return rc;
153 }
154
155 if((rc = safeCompare(currency, other.currency)) != 0) {
156 return rc;
157 }
158
159 if((rc = safeCompare(type, other.type)) != 0) {
160 return rc;
161 }
162
163 return 0;
164 }
165 }