-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStockService.java
More file actions
55 lines (50 loc) · 2.01 KB
/
SimpleStockService.java
File metadata and controls
55 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.origamisoftware.teach.advanced.services;
import com.origamisoftware.teach.advanced.model.StockQuote;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* An implementation of the StockService that returns hard coded data.
*/
public class SimpleStockService implements StockService {
/**
* Return the current price for a share of stock for the given symbol
*
* @param symbol the stock symbol of the company you want a quote for.
* e.g. APPL for APPLE
* @return a <CODE>BigDecimal</CODE> instance
* @throws StockServiceException if using the service generates an exception.
* If this happens, trying the service may work, depending on the actual cause of the
* error.
*/
@Override
public StockQuote getQuote(String symbol) {
// a dead simple implementation.
return new StockQuote(new BigDecimal(100), Calendar.getInstance().getTime(), symbol);
}
/**
* Get a historical list of stock quotes for the provide symbol
*
* @param symbol the stock symbol to search for
* @param from the date of the first stock quote
* @param until the date of the last stock quote
* @return a list of StockQuote instances
* @throws StockServiceException if using the service generates an exception.
* If this happens, trying the service may work, depending on the actual cause of the
* error.
*/
@Override
public List<StockQuote> getQuote(String symbol, Calendar from, Calendar until) {
// a dead simple implementation.
List<StockQuote> stockQuotes = new ArrayList<>();
Date aDay = from.getTime();
while (until.after(aDay)) {
stockQuotes.add(new StockQuote(new BigDecimal(100), aDay, symbol));
from.add(Calendar.DAY_OF_YEAR, 1);
aDay = from.getTime();
}
return stockQuotes;
}
}