/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.master.holiday; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.OpenGammaRuntimeException; import com.opengamma.id.VersionCorrection; import com.opengamma.master.AbstractSearchResult; import com.opengamma.util.PublicSPI; /** * Result from searching for holidays. * <p> * The returned documents will match the search criteria. * See {@link HolidaySearchRequest} for more details. */ @PublicSPI @BeanDefinition public class HolidaySearchResult extends AbstractSearchResult<HolidayDocument> { /** * Creates an instance. */ public HolidaySearchResult() { } /** * Creates an instance from a collection of documents. * * @param coll the collection of documents to add, not null */ public HolidaySearchResult(Collection<HolidayDocument> coll) { super(coll); } /** * Creates an instance specifying the version-correction searched for. * * @param versionCorrection the version-correction of the data, not null */ public HolidaySearchResult(VersionCorrection versionCorrection) { setVersionCorrection(versionCorrection); } //------------------------------------------------------------------------- /** * Gets the returned holidays from within the documents. * * @return the holidays, not null */ public List<ManageableHoliday> getHolidays() { List<ManageableHoliday> result = new ArrayList<ManageableHoliday>(); if (getDocuments() != null) { for (HolidayDocument doc : getDocuments()) { result.add(doc.getHoliday()); } } return result; } /** * Gets the first holiday, or null if no documents. * * @return the first holiday, null if none */ public ManageableHoliday getFirstHoliday() { return getDocuments().size() > 0 ? getDocuments().get(0).getHoliday() : null; } /** * Gets the single result expected from a query. * <p> * This throws an exception if more than 1 result is actually available. * Thus, this method implies an assumption about uniqueness of the queried holiday. * * @return the matching holiday, not null * @throws IllegalStateException if no holiday was found */ public ManageableHoliday getSingleHoliday() { if (getDocuments().size() != 1) { throw new OpenGammaRuntimeException("Expecting zero or single resulting match, and was " + getDocuments().size()); } else { return getDocuments().get(0).getHoliday(); } } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code HolidaySearchResult}. * @return the meta-bean, not null */ public static HolidaySearchResult.Meta meta() { return HolidaySearchResult.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(HolidaySearchResult.Meta.INSTANCE); } @Override public HolidaySearchResult.Meta metaBean() { return HolidaySearchResult.Meta.INSTANCE; } //----------------------------------------------------------------------- @Override public HolidaySearchResult clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { return super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(32); buf.append("HolidaySearchResult{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } @Override protected void toString(StringBuilder buf) { super.toString(buf); } //----------------------------------------------------------------------- /** * The meta-bean for {@code HolidaySearchResult}. */ public static class Meta extends AbstractSearchResult.Meta<HolidayDocument> { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap()); /** * Restricted constructor. */ protected Meta() { } @Override public BeanBuilder<? extends HolidaySearchResult> builder() { return new DirectBeanBuilder<HolidaySearchResult>(new HolidaySearchResult()); } @Override public Class<? extends HolidaySearchResult> beanType() { return HolidaySearchResult.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }