/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.master.region; import java.io.Serializable; import java.util.Map; import org.joda.beans.Bean; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.Property; import org.joda.beans.PropertyDefinition; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.core.region.Region; import com.opengamma.id.ExternalId; import com.opengamma.id.UniqueId; import com.opengamma.master.AbstractDocument; import com.opengamma.util.ArgumentChecker; import com.opengamma.util.PublicSPI; /** * A document used to pass into and out of the region master. * <p> * The region master provides full management of the region database. * Each element is stored in a document. */ @PublicSPI @BeanDefinition public class RegionDocument extends AbstractDocument implements Serializable { /** Serialization version. */ private static final long serialVersionUID = 1L; /** * The region object held by the document. */ @PropertyDefinition private ManageableRegion _region; /** * The region unique identifier. * This field is managed by the master but must be set for updates. */ @PropertyDefinition private UniqueId _uniqueId; /** * The provider external identifier for the data. * This optional field can be used to capture the identifier used by the data provider. * This can be useful when receiving updates from the same provider. */ @PropertyDefinition private ExternalId _providerId; /** * Creates an instance. */ public RegionDocument() { } /** * Creates an instance from a region. * * @param region the region, not null */ public RegionDocument(final Region region) { ArgumentChecker.notNull(region, "region"); setUniqueId(region.getUniqueId()); if (region instanceof ManageableRegion) { setRegion((ManageableRegion) region); } else { setRegion(new ManageableRegion(region)); } } //------------------------------------------------------------------------- @Override public ManageableRegion getValue() { return getRegion(); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code RegionDocument}. * @return the meta-bean, not null */ public static RegionDocument.Meta meta() { return RegionDocument.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(RegionDocument.Meta.INSTANCE); } @Override public RegionDocument.Meta metaBean() { return RegionDocument.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the region object held by the document. * @return the value of the property */ public ManageableRegion getRegion() { return _region; } /** * Sets the region object held by the document. * @param region the new value of the property */ public void setRegion(ManageableRegion region) { this._region = region; } /** * Gets the the {@code region} property. * @return the property, not null */ public final Property<ManageableRegion> region() { return metaBean().region().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the region unique identifier. * This field is managed by the master but must be set for updates. * @return the value of the property */ public UniqueId getUniqueId() { return _uniqueId; } /** * Sets the region unique identifier. * This field is managed by the master but must be set for updates. * @param uniqueId the new value of the property */ public void setUniqueId(UniqueId uniqueId) { this._uniqueId = uniqueId; } /** * Gets the the {@code uniqueId} property. * This field is managed by the master but must be set for updates. * @return the property, not null */ public final Property<UniqueId> uniqueId() { return metaBean().uniqueId().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the provider external identifier for the data. * This optional field can be used to capture the identifier used by the data provider. * This can be useful when receiving updates from the same provider. * @return the value of the property */ public ExternalId getProviderId() { return _providerId; } /** * Sets the provider external identifier for the data. * This optional field can be used to capture the identifier used by the data provider. * This can be useful when receiving updates from the same provider. * @param providerId the new value of the property */ public void setProviderId(ExternalId providerId) { this._providerId = providerId; } /** * Gets the the {@code providerId} property. * This optional field can be used to capture the identifier used by the data provider. * This can be useful when receiving updates from the same provider. * @return the property, not null */ public final Property<ExternalId> providerId() { return metaBean().providerId().createProperty(this); } //----------------------------------------------------------------------- @Override public RegionDocument clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { RegionDocument other = (RegionDocument) obj; return JodaBeanUtils.equal(getRegion(), other.getRegion()) && JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) && JodaBeanUtils.equal(getProviderId(), other.getProviderId()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getRegion()); hash = hash * 31 + JodaBeanUtils.hashCode(getUniqueId()); hash = hash * 31 + JodaBeanUtils.hashCode(getProviderId()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("RegionDocument{"); 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("region").append('=').append(JodaBeanUtils.toString(getRegion())).append(',').append(' '); buf.append("uniqueId").append('=').append(JodaBeanUtils.toString(getUniqueId())).append(',').append(' '); buf.append("providerId").append('=').append(JodaBeanUtils.toString(getProviderId())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code RegionDocument}. */ public static class Meta extends AbstractDocument.Meta { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code region} property. */ private final MetaProperty<ManageableRegion> _region = DirectMetaProperty.ofReadWrite( this, "region", RegionDocument.class, ManageableRegion.class); /** * The meta-property for the {@code uniqueId} property. */ private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofReadWrite( this, "uniqueId", RegionDocument.class, UniqueId.class); /** * The meta-property for the {@code providerId} property. */ private final MetaProperty<ExternalId> _providerId = DirectMetaProperty.ofReadWrite( this, "providerId", RegionDocument.class, ExternalId.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "region", "uniqueId", "providerId"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -934795532: // region return _region; case -294460212: // uniqueId return _uniqueId; case 205149932: // providerId return _providerId; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends RegionDocument> builder() { return new DirectBeanBuilder<RegionDocument>(new RegionDocument()); } @Override public Class<? extends RegionDocument> beanType() { return RegionDocument.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code region} property. * @return the meta-property, not null */ public final MetaProperty<ManageableRegion> region() { return _region; } /** * The meta-property for the {@code uniqueId} property. * @return the meta-property, not null */ public final MetaProperty<UniqueId> uniqueId() { return _uniqueId; } /** * The meta-property for the {@code providerId} property. * @return the meta-property, not null */ public final MetaProperty<ExternalId> providerId() { return _providerId; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -934795532: // region return ((RegionDocument) bean).getRegion(); case -294460212: // uniqueId return ((RegionDocument) bean).getUniqueId(); case 205149932: // providerId return ((RegionDocument) bean).getProviderId(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -934795532: // region ((RegionDocument) bean).setRegion((ManageableRegion) newValue); return; case -294460212: // uniqueId ((RegionDocument) bean).setUniqueId((UniqueId) newValue); return; case 205149932: // providerId ((RegionDocument) bean).setProviderId((ExternalId) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }