/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.master.security; 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.PropertyDefinition; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.OpenGammaRuntimeException; import com.opengamma.master.AbstractHistoryResult; import com.opengamma.util.PublicSPI; import org.joda.beans.Bean; import org.joda.beans.Property; import org.joda.beans.impl.direct.DirectMetaProperty; /** * Result providing the history of a security. * <p> * The returned documents may be a mixture of versions and corrections. * The document instant fields are used to identify which are which. * See {@link SecurityHistoryRequest} for more details. */ @PublicSPI @BeanDefinition public class SecurityHistoryResult extends AbstractHistoryResult<SecurityDocument> { /** * The number of items that were removed because the user is not authorized to see them. */ @PropertyDefinition private int _unauthorizedCount; /** * Creates an instance. */ public SecurityHistoryResult() { } /** * Creates an instance from a collection of documents. * * @param coll the collection of documents to add, not null */ public SecurityHistoryResult(Collection<SecurityDocument> coll) { super(coll); } //------------------------------------------------------------------------- /** * Gets the returned securities from within the documents. * * @return the securities, not null */ public List<ManageableSecurity> getSecurities() { List<ManageableSecurity> result = new ArrayList<ManageableSecurity>(); if (getDocuments() != null) { for (SecurityDocument doc : getDocuments()) { result.add(doc.getSecurity()); } } return result; } /** * Gets the first security, or null if no documents. * * @return the first security, null if none */ public ManageableSecurity getFirstSecurity() { return getDocuments().size() > 0 ? getDocuments().get(0).getSecurity() : 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 security. * * @return the matching security, not null * @throws IllegalStateException if no security was found */ public ManageableSecurity getSingleSecurity() { if (getDocuments().size() != 1) { throw new OpenGammaRuntimeException("Expecting zero or single resulting match, and was " + getDocuments().size()); } else { return getDocuments().get(0).getSecurity(); } } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code SecurityHistoryResult}. * @return the meta-bean, not null */ public static SecurityHistoryResult.Meta meta() { return SecurityHistoryResult.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(SecurityHistoryResult.Meta.INSTANCE); } @Override public SecurityHistoryResult.Meta metaBean() { return SecurityHistoryResult.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the number of items that were removed because the user is not authorized to see them. * @return the value of the property */ public int getUnauthorizedCount() { return _unauthorizedCount; } /** * Sets the number of items that were removed because the user is not authorized to see them. * @param unauthorizedCount the new value of the property */ public void setUnauthorizedCount(int unauthorizedCount) { this._unauthorizedCount = unauthorizedCount; } /** * Gets the the {@code unauthorizedCount} property. * @return the property, not null */ public final Property<Integer> unauthorizedCount() { return metaBean().unauthorizedCount().createProperty(this); } //----------------------------------------------------------------------- @Override public SecurityHistoryResult clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { SecurityHistoryResult other = (SecurityHistoryResult) obj; return (getUnauthorizedCount() == other.getUnauthorizedCount()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getUnauthorizedCount()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("SecurityHistoryResult{"); 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); buf.append("unauthorizedCount").append('=').append(JodaBeanUtils.toString(getUnauthorizedCount())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code SecurityHistoryResult}. */ public static class Meta extends AbstractHistoryResult.Meta<SecurityDocument> { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code unauthorizedCount} property. */ private final MetaProperty<Integer> _unauthorizedCount = DirectMetaProperty.ofReadWrite( this, "unauthorizedCount", SecurityHistoryResult.class, Integer.TYPE); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "unauthorizedCount"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 2063040635: // unauthorizedCount return _unauthorizedCount; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends SecurityHistoryResult> builder() { return new DirectBeanBuilder<SecurityHistoryResult>(new SecurityHistoryResult()); } @Override public Class<? extends SecurityHistoryResult> beanType() { return SecurityHistoryResult.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code unauthorizedCount} property. * @return the meta-property, not null */ public final MetaProperty<Integer> unauthorizedCount() { return _unauthorizedCount; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 2063040635: // unauthorizedCount return ((SecurityHistoryResult) bean).getUnauthorizedCount(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 2063040635: // unauthorizedCount ((SecurityHistoryResult) bean).setUnauthorizedCount((Integer) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }