StockUpdate adjustments

First of all, let's add the necessary fields for the text:

private final String twitterStatus;
[...]

public StockUpdate(String stockSymbol, BigDecimal price, Date date,
String twitterStatus) {

if (stockSymbol == null) {
stockSymbol = "";
}

if (twitterStatus == null) {
twitterStatus = "";
}

this.stockSymbol = stockSymbol;
this.price = price;
this.date = date;
this.twitterStatus = twitterStatus;
}

Here, we have added some additional checks so that we won't run into NullPointerException later on. Also, the existing .create() method has to be updated to the following:

public static StockUpdate create(YahooStockQuote r) {
return new StockUpdate(r.getSymbol(), r.getLastTradePriceOnly(),
new Date(), "");
}

Later, we will also need a call to check whether it is a status update from Twitter or a just regular stock update:

public boolean isTwitterStatusUpdate() {
return !twitterStatus.isEmpty();
}

Finally, we need to create a new .create() method to handle the Status type from Twitter4j:

public static StockUpdate create(Status status) {
return new StockUpdate("", BigDecimal.ZERO, status.getCreatedAt(),
status.getText());
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.71.211