1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package samples.services; 20 21 import java.util.Date; 22 23 public class GetQuoteResponse { 24 String symbol; 25 double last; 26 String lastTradeTimestamp; 27 double change; 28 double open; 29 double high; 30 double low; 31 int volume; 32 double marketCap; 33 double prevClose; 34 double percentageChange; 35 double earnings; 36 double peRatio; 37 String name; 38 39 public GetQuoteResponse() { 40 } 41 42 public GetQuoteResponse(String symbol) { 43 this.symbol = symbol; 44 this.last = getRandom(100, 0.9, true); 45 this.lastTradeTimestamp = new Date().toString(); 46 this.change = getRandom(3, 0.5, false); 47 this.open = getRandom(last, 0.05, false); 48 this.high = getRandom(last, 0.05, false); 49 this.low = getRandom(last, 0.05, false); 50 this.volume = (int) getRandom(10000, 1.0, true); 51 this.marketCap = getRandom(10E6, 5.0, false); 52 this.prevClose = getRandom(last, 0.15, false); 53 this.percentageChange = change / prevClose * 100; 54 this.earnings = getRandom(10, 0.4, false); 55 this.peRatio = getRandom(20, 0.30, false); 56 this.name = symbol + " Company"; 57 } 58 59 public String getSymbol() { 60 return symbol; 61 } 62 63 public void setSymbol(String symbol) { 64 this.symbol = symbol; 65 } 66 67 public double getLast() { 68 return last; 69 } 70 71 public void setLast(double last) { 72 this.last = last; 73 } 74 75 public String getLastTradeTimestamp() { 76 return lastTradeTimestamp; 77 } 78 79 public void setLastTradeTimestamp(String lastTradeTimestamp) { 80 this.lastTradeTimestamp = lastTradeTimestamp; 81 } 82 83 public double getChange() { 84 return change; 85 } 86 87 public void setChange(double change) { 88 this.change = change; 89 } 90 91 public double getOpen() { 92 return open; 93 } 94 95 public void setOpen(double open) { 96 this.open = open; 97 } 98 99 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, boolean onlypositive) { 172 double rand = Math.random(); 173 return (base + ((rand > 0.5 ? 1 : -1) * varience * base * rand)) 174 * (onlypositive ? 1 : (rand > 0.5 ? 1 : -1)); 175 } 176 177 }