001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package samples.services;
020:
021: import java.util.Date;
022:
023: public class GetQuoteResponse {
024: String symbol;
025: double last;
026: String lastTradeTimestamp;
027: double change;
028: double open;
029: double high;
030: double low;
031: int volume;
032: double marketCap;
033: double prevClose;
034: double percentageChange;
035: double earnings;
036: double peRatio;
037: String name;
038:
039: public GetQuoteResponse() {
040: }
041:
042: public GetQuoteResponse(String symbol) {
043: this .symbol = symbol;
044: this .last = getRandom(100, 0.9, true);
045: this .lastTradeTimestamp = new Date().toString();
046: this .change = getRandom(3, 0.5, false);
047: this .open = getRandom(last, 0.05, false);
048: this .high = getRandom(last, 0.05, false);
049: this .low = getRandom(last, 0.05, false);
050: this .volume = (int) getRandom(10000, 1.0, true);
051: this .marketCap = getRandom(10E6, 5.0, false);
052: this .prevClose = getRandom(last, 0.15, false);
053: this .percentageChange = change / prevClose * 100;
054: this .earnings = getRandom(10, 0.4, false);
055: this .peRatio = getRandom(20, 0.30, false);
056: this .name = symbol + " Company";
057: }
058:
059: public String getSymbol() {
060: return symbol;
061: }
062:
063: public void setSymbol(String symbol) {
064: this .symbol = symbol;
065: }
066:
067: public double getLast() {
068: return last;
069: }
070:
071: public void setLast(double last) {
072: this .last = last;
073: }
074:
075: public String getLastTradeTimestamp() {
076: return lastTradeTimestamp;
077: }
078:
079: public void setLastTradeTimestamp(String lastTradeTimestamp) {
080: this .lastTradeTimestamp = lastTradeTimestamp;
081: }
082:
083: public double getChange() {
084: return change;
085: }
086:
087: public void setChange(double change) {
088: this .change = change;
089: }
090:
091: public double getOpen() {
092: return open;
093: }
094:
095: public void setOpen(double open) {
096: this .open = open;
097: }
098:
099: public double getHigh() {
100: return high;
101: }
102:
103: public void setHigh(double high) {
104: this .high = high;
105: }
106:
107: public double getLow() {
108: return low;
109: }
110:
111: public void setLow(double low) {
112: this .low = low;
113: }
114:
115: public int getVolume() {
116: return volume;
117: }
118:
119: public void setVolume(int volume) {
120: this .volume = volume;
121: }
122:
123: public double getMarketCap() {
124: return marketCap;
125: }
126:
127: public void setMarketCap(double marketCap) {
128: this .marketCap = marketCap;
129: }
130:
131: public double getPrevClose() {
132: return prevClose;
133: }
134:
135: public void setPrevClose(double prevClose) {
136: this .prevClose = prevClose;
137: }
138:
139: public double getPercentageChange() {
140: return percentageChange;
141: }
142:
143: public void setPercentageChange(double percentageChange) {
144: this .percentageChange = percentageChange;
145: }
146:
147: public double getEarnings() {
148: return earnings;
149: }
150:
151: public void setEarnings(double earnings) {
152: this .earnings = earnings;
153: }
154:
155: public double getPeRatio() {
156: return peRatio;
157: }
158:
159: public void setPeRatio(double peRatio) {
160: this .peRatio = peRatio;
161: }
162:
163: public String getName() {
164: return name;
165: }
166:
167: public void setName(String name) {
168: this .name = name;
169: }
170:
171: private static double getRandom(double base, double varience,
172: boolean onlypositive) {
173: double rand = Math.random();
174: return (base + ((rand > 0.5 ? 1 : -1) * varience * base * rand))
175: * (onlypositive ? 1 : (rand > 0.5 ? 1 : -1));
176: }
177:
178: }
|