/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.analytics.isda.credit; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import org.joda.beans.Bean; import org.joda.beans.BeanDefinition; import org.joda.beans.ImmutableBean; 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.DirectFieldsBeanBuilder; import org.joda.beans.impl.direct.DirectMetaBean; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.google.common.collect.ImmutableMap; import com.opengamma.core.marketdatasnapshot.NamedSnapshot; import com.opengamma.id.UniqueId; import com.opengamma.util.money.Currency; /** * A snapshot containing yield curve market data. This defines a set of yield curves * which can be bootstrapped and used in a pricing environment. Curves are indexed * on a per-currency basis since they are typically accessed as such. */ @BeanDefinition public class YieldCurveDataSnapshot implements NamedSnapshot, ImmutableBean { /** * Unique id for this snapshot. */ @PropertyDefinition(overrideGet = true) private final UniqueId _uniqueId; /** * Name for this snapshot. */ @PropertyDefinition(validate = "notNull", overrideGet = true) private final String _name; /** * Yield curve data, indexed by currency. */ @PropertyDefinition(validate = "notNull") private final Map<Currency, YieldCurveData> _yieldCurves; @Override public NamedSnapshot withUniqueId(UniqueId uniqueId) { return new YieldCurveDataSnapshot.Builder(this).uniqueId(uniqueId).build(); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code YieldCurveDataSnapshot}. * @return the meta-bean, not null */ public static YieldCurveDataSnapshot.Meta meta() { return YieldCurveDataSnapshot.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(YieldCurveDataSnapshot.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static YieldCurveDataSnapshot.Builder builder() { return new YieldCurveDataSnapshot.Builder(); } /** * Restricted constructor. * @param builder the builder to copy from, not null */ protected YieldCurveDataSnapshot(YieldCurveDataSnapshot.Builder builder) { JodaBeanUtils.notNull(builder._name, "name"); JodaBeanUtils.notNull(builder._yieldCurves, "yieldCurves"); this._uniqueId = builder._uniqueId; this._name = builder._name; this._yieldCurves = ImmutableMap.copyOf(builder._yieldCurves); } @Override public YieldCurveDataSnapshot.Meta metaBean() { return YieldCurveDataSnapshot.Meta.INSTANCE; } @Override public <R> Property<R> property(String propertyName) { return metaBean().<R>metaProperty(propertyName).createProperty(this); } @Override public Set<String> propertyNames() { return metaBean().metaPropertyMap().keySet(); } //----------------------------------------------------------------------- /** * Gets unique id for this snapshot. * @return the value of the property */ @Override public UniqueId getUniqueId() { return _uniqueId; } //----------------------------------------------------------------------- /** * Gets name for this snapshot. * @return the value of the property, not null */ @Override public String getName() { return _name; } //----------------------------------------------------------------------- /** * Gets yield curve data, indexed by currency. * @return the value of the property, not null */ public Map<Currency, YieldCurveData> getYieldCurves() { return _yieldCurves; } //----------------------------------------------------------------------- /** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { YieldCurveDataSnapshot other = (YieldCurveDataSnapshot) obj; return JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) && JodaBeanUtils.equal(getName(), other.getName()) && JodaBeanUtils.equal(getYieldCurves(), other.getYieldCurves()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getUniqueId()); hash = hash * 31 + JodaBeanUtils.hashCode(getName()); hash = hash * 31 + JodaBeanUtils.hashCode(getYieldCurves()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("YieldCurveDataSnapshot{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("uniqueId").append('=').append(JodaBeanUtils.toString(getUniqueId())).append(',').append(' '); buf.append("name").append('=').append(JodaBeanUtils.toString(getName())).append(',').append(' '); buf.append("yieldCurves").append('=').append(JodaBeanUtils.toString(getYieldCurves())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code YieldCurveDataSnapshot}. */ public static class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code uniqueId} property. */ private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofImmutable( this, "uniqueId", YieldCurveDataSnapshot.class, UniqueId.class); /** * The meta-property for the {@code name} property. */ private final MetaProperty<String> _name = DirectMetaProperty.ofImmutable( this, "name", YieldCurveDataSnapshot.class, String.class); /** * The meta-property for the {@code yieldCurves} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<Map<Currency, YieldCurveData>> _yieldCurves = DirectMetaProperty.ofImmutable( this, "yieldCurves", YieldCurveDataSnapshot.class, (Class) Map.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "uniqueId", "name", "yieldCurves"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -294460212: // uniqueId return _uniqueId; case 3373707: // name return _name; case 119589713: // yieldCurves return _yieldCurves; } return super.metaPropertyGet(propertyName); } @Override public YieldCurveDataSnapshot.Builder builder() { return new YieldCurveDataSnapshot.Builder(); } @Override public Class<? extends YieldCurveDataSnapshot> beanType() { return YieldCurveDataSnapshot.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * 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 name} property. * @return the meta-property, not null */ public final MetaProperty<String> name() { return _name; } /** * The meta-property for the {@code yieldCurves} property. * @return the meta-property, not null */ public final MetaProperty<Map<Currency, YieldCurveData>> yieldCurves() { return _yieldCurves; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -294460212: // uniqueId return ((YieldCurveDataSnapshot) bean).getUniqueId(); case 3373707: // name return ((YieldCurveDataSnapshot) bean).getName(); case 119589713: // yieldCurves return ((YieldCurveDataSnapshot) bean).getYieldCurves(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { metaProperty(propertyName); if (quiet) { return; } throw new UnsupportedOperationException("Property cannot be written: " + propertyName); } } //----------------------------------------------------------------------- /** * The bean-builder for {@code YieldCurveDataSnapshot}. */ public static class Builder extends DirectFieldsBeanBuilder<YieldCurveDataSnapshot> { private UniqueId _uniqueId; private String _name; private Map<Currency, YieldCurveData> _yieldCurves = new HashMap<Currency, YieldCurveData>(); /** * Restricted constructor. */ protected Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ protected Builder(YieldCurveDataSnapshot beanToCopy) { this._uniqueId = beanToCopy.getUniqueId(); this._name = beanToCopy.getName(); this._yieldCurves = new HashMap<Currency, YieldCurveData>(beanToCopy.getYieldCurves()); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case -294460212: // uniqueId return _uniqueId; case 3373707: // name return _name; case 119589713: // yieldCurves return _yieldCurves; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case -294460212: // uniqueId this._uniqueId = (UniqueId) newValue; break; case 3373707: // name this._name = (String) newValue; break; case 119589713: // yieldCurves this._yieldCurves = (Map<Currency, YieldCurveData>) newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return this; } @Override public Builder set(MetaProperty<?> property, Object value) { super.set(property, value); return this; } @Override public Builder setString(String propertyName, String value) { setString(meta().metaProperty(propertyName), value); return this; } @Override public Builder setString(MetaProperty<?> property, String value) { super.setString(property, value); return this; } @Override public Builder setAll(Map<String, ? extends Object> propertyValueMap) { super.setAll(propertyValueMap); return this; } @Override public YieldCurveDataSnapshot build() { return new YieldCurveDataSnapshot(this); } //----------------------------------------------------------------------- /** * Sets the {@code uniqueId} property in the builder. * @param uniqueId the new value * @return this, for chaining, not null */ public Builder uniqueId(UniqueId uniqueId) { this._uniqueId = uniqueId; return this; } /** * Sets the {@code name} property in the builder. * @param name the new value, not null * @return this, for chaining, not null */ public Builder name(String name) { JodaBeanUtils.notNull(name, "name"); this._name = name; return this; } /** * Sets the {@code yieldCurves} property in the builder. * @param yieldCurves the new value, not null * @return this, for chaining, not null */ public Builder yieldCurves(Map<Currency, YieldCurveData> yieldCurves) { JodaBeanUtils.notNull(yieldCurves, "yieldCurves"); this._yieldCurves = yieldCurves; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("YieldCurveDataSnapshot.Builder{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } protected void toString(StringBuilder buf) { buf.append("uniqueId").append('=').append(JodaBeanUtils.toString(_uniqueId)).append(',').append(' '); buf.append("name").append('=').append(JodaBeanUtils.toString(_name)).append(',').append(' '); buf.append("yieldCurves").append('=').append(JodaBeanUtils.toString(_yieldCurves)).append(',').append(' '); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }