O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cleaning stock adapter

In the StockDataAdapter.java file, there was a code block to avoid adding the same values that are already present in the stream:

for (StockUpdate stockUpdate : data) {        if (stockUpdate.getStockSymbol()            .equals(newStockUpdate.getStockSymbol())) {        if (stockUpdate.getPrice()            .equals(newStockUpdate.getPrice())                    && stockUpdate.getTwitterStatus()                    .equals(newStockUpdate.getTwitterStatus())) {                return;            }            break;        }    }

However, it would be better to make the .add() method simpler by freeing it up from this responsibility of skipping duplicate values; now we can handle it in the flow. Let's start by extracting a method to check whether there is a duplicate value:

public void add(StockUpdate newStockUpdate) {this.data.add(0, newStockUpdate); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required