com.barchart.ondemand.api.responses.EquitiesOptions Maven / Gradle / Ivy
package com.barchart.ondemand.api.responses;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonProperty;
public class EquitiesOptions extends ResponseBase {
@JsonProperty("results")
public List results = new ArrayList();
public Collection all() {
if (results == null) {
return new ArrayList();
}
return Collections.unmodifiableCollection(results);
}
public Collection calls() {
final List results = new ArrayList();
for (EquitiesOption f : all()) {
if (f.getType() != null && f.getType().equalsIgnoreCase("call")) {
results.add(f);
}
}
return results;
}
public Collection puts() {
final List results = new ArrayList();
for (EquitiesOption f : all()) {
if (f.getType() != null && f.getType().equalsIgnoreCase("put")) {
results.add(f);
}
}
return results;
}
public Collection allExpirations() {
final List results = new ArrayList();
for (EquitiesOption f : all()) {
if (!results.contains(f.getExpirationDate())) {
results.add(f.getExpirationDate());
}
}
return results;
}
public Collection forExpirationDate(final String date) {
final List results = new ArrayList();
for (EquitiesOption f : all()) {
if (f.getExpirationDate().equalsIgnoreCase(date)) {
results.add(f);
}
}
return results;
}
public Map expirationsForDate(final String date) {
final Map results = new HashMap();
final Collection all = forExpirationDate(date);
if (all == null) {
return new HashMap();
}
for (EquitiesOption a : all) {
if (results.get(a.getExpirationDate()) == null) {
results.put(a.getExpirationDate(), new EquitiesOptions());
}
results.get(a.getExpirationDate()).results.add(a);
}
return results;
}
public EquitiesOption forSymbol(final String symbol) {
for (EquitiesOption f : all()) {
if (f.getSymbol().equalsIgnoreCase(symbol)) {
return f;
}
}
return null;
}
}