com.lucadev.coinmarketcap.model.CoinListingList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coinmarketcap-api Show documentation
Show all versions of coinmarketcap-api Show documentation
A REST API client specifically developed to connect to the CoinMarketCap API.
The newest version!
package com.lucadev.coinmarketcap.model;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
/**
* Wrapper to manage a list of Coinlistings
*
* @author Luca Camphuisen
* @since 6-5-18
*/
public class CoinListingList implements List {
private final List coinListings;
/**
* Construct from a {@link List}
*
* @param coinListings
*/
public CoinListingList(List coinListings) {
this.coinListings = coinListings;
}
private Optional search(Predicate predicate) {
return coinListings.stream().filter(predicate).findFirst();
}
/**
* Search through listings
*
* @param id the listing id to search for
* @return the {@link Optional} with our {@link CoinListing} result
*/
public Optional getById(long id) {
return search(listing -> listing.getId() == id);
}
/**
* Search through listings
*
* @param name the name of the listing. Case insensitive
* @return the {@link Optional} with our {@link CoinListing} result
*/
public Optional getByName(String name) {
return search(listing -> listing.getName().equalsIgnoreCase(name));
}
/**
* Search through listings
*
* @param symbol the symbol of the listing. Case insensitive
* @return the {@link Optional} with our {@link CoinListing} result
*/
public Optional getBySymbol(String symbol) {
return search(listing -> listing.getSymbol().equalsIgnoreCase(symbol));
}
/**
* Search through listings
*
* @param websiteSlug the website slug of the listing. Case insensitive
* @return the {@link Optional} with our {@link CoinListing} result
*/
public Optional getByWebsiteSlug(String websiteSlug) {
return search(listing -> listing.getWebsiteSlug().equalsIgnoreCase(websiteSlug));
}
@Override
public int size() {
return coinListings.size();
}
@Override
public boolean isEmpty() {
return coinListings.isEmpty();
}
@Override
public boolean contains(Object o) {
return coinListings.contains(o);
}
@Override
public Iterator iterator() {
return coinListings.iterator();
}
@Override
public Object[] toArray() {
return coinListings.toArray();
}
@Override
public T[] toArray(T[] ts) {
return coinListings.toArray(ts);
}
@Override
public boolean add(CoinListing coinListing) {
return coinListings.add(coinListing);
}
@Override
public boolean remove(Object o) {
return coinListings.remove(o);
}
@Override
public boolean containsAll(Collection> collection) {
return coinListings.containsAll(collection);
}
@Override
public boolean addAll(Collection extends CoinListing> collection) {
return coinListings.addAll(collection);
}
@Override
public boolean addAll(int i, Collection extends CoinListing> collection) {
return coinListings.addAll(i, collection);
}
@Override
public boolean removeAll(Collection> collection) {
return coinListings.removeAll(collection);
}
@Override
public boolean retainAll(Collection> collection) {
return coinListings.retainAll(collection);
}
@Override
public void replaceAll(UnaryOperator unaryOperator) {
coinListings.replaceAll(unaryOperator);
}
@Override
public void sort(Comparator super CoinListing> comparator) {
coinListings.sort(comparator);
}
@Override
public void clear() {
coinListings.clear();
}
@Override
public boolean equals(Object o) {
return coinListings.equals(o);
}
@Override
public int hashCode() {
return coinListings.hashCode();
}
@Override
public CoinListing get(int i) {
return coinListings.get(i);
}
@Override
public CoinListing set(int i, CoinListing coinListing) {
return coinListings.set(i, coinListing);
}
@Override
public void add(int i, CoinListing coinListing) {
coinListings.add(i, coinListing);
}
@Override
public CoinListing remove(int i) {
return coinListings.remove(i);
}
@Override
public int indexOf(Object o) {
return coinListings.indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
return coinListings.lastIndexOf(o);
}
@Override
public ListIterator listIterator() {
return coinListings.listIterator();
}
@Override
public ListIterator listIterator(int i) {
return coinListings.listIterator(i);
}
@Override
public List subList(int i, int i1) {
return coinListings.subList(i, i1);
}
@Override
public Spliterator spliterator() {
return coinListings.spliterator();
}
@Override
public boolean removeIf(Predicate super CoinListing> predicate) {
return coinListings.removeIf(predicate);
}
@Override
public Stream stream() {
return coinListings.stream();
}
@Override
public Stream parallelStream() {
return coinListings.parallelStream();
}
@Override
public void forEach(Consumer super CoinListing> consumer) {
coinListings.forEach(consumer);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy