All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barchart.ondemand.api.responses.SDFuturesOptions Maven / Gradle / Ivy

The newest version!
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 SDFuturesOptions 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 (SDFuturesOption f : all()) {
			if (f.getType() != null && f.getType().equalsIgnoreCase("call")) {
				results.add(f);
			}
		}

		return results;
	}

	public Collection puts() {

		final List results = new ArrayList();
		for (SDFuturesOption f : all()) {
			if (f.getType() != null && f.getType().equalsIgnoreCase("put")) {
				results.add(f);
			}
		}

		return results;
	}

	public Collection forContractMonth(final String month) {
		final List results = new ArrayList();

		for (SDFuturesOption f : all()) {
			if (f.getContractMonth().equalsIgnoreCase(month)) {
				results.add(f);
			}
		}

		return results;
	}

	public Collection allContractMonths() {
		final List results = new ArrayList();

		for (SDFuturesOption f : all()) {
			if (!results.contains(f.getContractMonth())) {
				results.add(f.getContractMonth());
			}
		}

		return results;
	}

	public Collection allExpirations() {
		final List results = new ArrayList();

		for (SDFuturesOption f : all()) {
			if (!results.contains(f.getExpirationDate())) {
				results.add(f.getExpirationDate());
			}
		}

		return results;
	}

	public Map expirationsForMonth(final String month) {
		final Map results = new HashMap();

		final Collection all = forContractMonth(month);

		if (all == null) {
			return new HashMap();
		}

		for (SDFuturesOption a : all) {
			if (results.get(a.getExpirationDate()) == null) {
				results.put(a.getExpirationDate(), new SDFuturesOptions());
			}

			results.get(a.getExpirationDate()).results.add(a);
		}

		return results;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy