/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.analytics.parameters; 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.ImmutableValidator; 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.ComparisonChain; import com.google.common.collect.Ordering; import com.opengamma.util.ArgumentChecker; import com.opengamma.util.time.Tenor; /** * Represents a volatility entry within a table defined by * {@link HullWhiteOneFactorVolatilityTable}. An entry generally * consists of the volatility between a start tenor (inclusive) * and the end tenor (exclusive). However, in order to allow an * infinite range to be covered, the end tenor can be set to null. * Within a table of entries, at most one can have a null end tenor. */ @BeanDefinition public final class HullWhiteOneFactorVolatilityEntry implements ImmutableBean, Comparable<HullWhiteOneFactorVolatilityEntry> { /** * The start tenor for this entry. */ @PropertyDefinition(validate = "notNull") private final Tenor _startTenor; /** * The end tenor for this entry. A null indicates that that * the range defined by this entry has no end, so all points * beyond the start tenor are covered. */ @PropertyDefinition() private final Tenor _endTenor; /** * THe volatility for this entry. */ @PropertyDefinition private final double _volatility; @Override public int compareTo(HullWhiteOneFactorVolatilityEntry that) { return ComparisonChain.start() .compare(_startTenor, that._startTenor) .compare(_endTenor, that._endTenor, Ordering.natural().nullsLast()) .result(); } @ImmutableValidator private void validate() { ArgumentChecker.notNegative(_volatility, "volatility"); ArgumentChecker.isTrue(_endTenor == null || _startTenor.compareTo(_endTenor) < 0, "Start tenor [{}] must be shorter than end tenor [{}]", _startTenor, _endTenor); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code HullWhiteOneFactorVolatilityEntry}. * @return the meta-bean, not null */ public static HullWhiteOneFactorVolatilityEntry.Meta meta() { return HullWhiteOneFactorVolatilityEntry.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(HullWhiteOneFactorVolatilityEntry.Meta.INSTANCE); } /** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static HullWhiteOneFactorVolatilityEntry.Builder builder() { return new HullWhiteOneFactorVolatilityEntry.Builder(); } private HullWhiteOneFactorVolatilityEntry( Tenor startTenor, Tenor endTenor, double volatility) { JodaBeanUtils.notNull(startTenor, "startTenor"); this._startTenor = startTenor; this._endTenor = endTenor; this._volatility = volatility; validate(); } @Override public HullWhiteOneFactorVolatilityEntry.Meta metaBean() { return HullWhiteOneFactorVolatilityEntry.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 the start tenor for this entry. * @return the value of the property, not null */ public Tenor getStartTenor() { return _startTenor; } //----------------------------------------------------------------------- /** * Gets the end tenor for this entry. A null indicates that that * the range defined by this entry has no end, so all points * beyond the start tenor are covered. * @return the value of the property */ public Tenor getEndTenor() { return _endTenor; } //----------------------------------------------------------------------- /** * Gets tHe volatility for this entry. * @return the value of the property */ public double getVolatility() { return _volatility; } //----------------------------------------------------------------------- /** * 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()) { HullWhiteOneFactorVolatilityEntry other = (HullWhiteOneFactorVolatilityEntry) obj; return JodaBeanUtils.equal(getStartTenor(), other.getStartTenor()) && JodaBeanUtils.equal(getEndTenor(), other.getEndTenor()) && JodaBeanUtils.equal(getVolatility(), other.getVolatility()); } return false; } @Override public int hashCode() { int hash = getClass().hashCode(); hash = hash * 31 + JodaBeanUtils.hashCode(getStartTenor()); hash = hash * 31 + JodaBeanUtils.hashCode(getEndTenor()); hash = hash * 31 + JodaBeanUtils.hashCode(getVolatility()); return hash; } @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("HullWhiteOneFactorVolatilityEntry{"); buf.append("startTenor").append('=').append(getStartTenor()).append(',').append(' '); buf.append("endTenor").append('=').append(getEndTenor()).append(',').append(' '); buf.append("volatility").append('=').append(JodaBeanUtils.toString(getVolatility())); buf.append('}'); return buf.toString(); } //----------------------------------------------------------------------- /** * The meta-bean for {@code HullWhiteOneFactorVolatilityEntry}. */ public static final class Meta extends DirectMetaBean { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code startTenor} property. */ private final MetaProperty<Tenor> _startTenor = DirectMetaProperty.ofImmutable( this, "startTenor", HullWhiteOneFactorVolatilityEntry.class, Tenor.class); /** * The meta-property for the {@code endTenor} property. */ private final MetaProperty<Tenor> _endTenor = DirectMetaProperty.ofImmutable( this, "endTenor", HullWhiteOneFactorVolatilityEntry.class, Tenor.class); /** * The meta-property for the {@code volatility} property. */ private final MetaProperty<Double> _volatility = DirectMetaProperty.ofImmutable( this, "volatility", HullWhiteOneFactorVolatilityEntry.class, Double.TYPE); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, null, "startTenor", "endTenor", "volatility"); /** * Restricted constructor. */ private Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1583746178: // startTenor return _startTenor; case 1714950821: // endTenor return _endTenor; case -1917967323: // volatility return _volatility; } return super.metaPropertyGet(propertyName); } @Override public HullWhiteOneFactorVolatilityEntry.Builder builder() { return new HullWhiteOneFactorVolatilityEntry.Builder(); } @Override public Class<? extends HullWhiteOneFactorVolatilityEntry> beanType() { return HullWhiteOneFactorVolatilityEntry.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code startTenor} property. * @return the meta-property, not null */ public MetaProperty<Tenor> startTenor() { return _startTenor; } /** * The meta-property for the {@code endTenor} property. * @return the meta-property, not null */ public MetaProperty<Tenor> endTenor() { return _endTenor; } /** * The meta-property for the {@code volatility} property. * @return the meta-property, not null */ public MetaProperty<Double> volatility() { return _volatility; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1583746178: // startTenor return ((HullWhiteOneFactorVolatilityEntry) bean).getStartTenor(); case 1714950821: // endTenor return ((HullWhiteOneFactorVolatilityEntry) bean).getEndTenor(); case -1917967323: // volatility return ((HullWhiteOneFactorVolatilityEntry) bean).getVolatility(); } 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 HullWhiteOneFactorVolatilityEntry}. */ public static final class Builder extends DirectFieldsBeanBuilder<HullWhiteOneFactorVolatilityEntry> { private Tenor _startTenor; private Tenor _endTenor; private double _volatility; /** * Restricted constructor. */ private Builder() { } /** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(HullWhiteOneFactorVolatilityEntry beanToCopy) { this._startTenor = beanToCopy.getStartTenor(); this._endTenor = beanToCopy.getEndTenor(); this._volatility = beanToCopy.getVolatility(); } //----------------------------------------------------------------------- @Override public Object get(String propertyName) { switch (propertyName.hashCode()) { case -1583746178: // startTenor return _startTenor; case 1714950821: // endTenor return _endTenor; case -1917967323: // volatility return _volatility; default: throw new NoSuchElementException("Unknown property: " + propertyName); } } @Override public Builder set(String propertyName, Object newValue) { switch (propertyName.hashCode()) { case -1583746178: // startTenor this._startTenor = (Tenor) newValue; break; case 1714950821: // endTenor this._endTenor = (Tenor) newValue; break; case -1917967323: // volatility this._volatility = (Double) 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 HullWhiteOneFactorVolatilityEntry build() { return new HullWhiteOneFactorVolatilityEntry( _startTenor, _endTenor, _volatility); } //----------------------------------------------------------------------- /** * Sets the {@code startTenor} property in the builder. * @param startTenor the new value, not null * @return this, for chaining, not null */ public Builder startTenor(Tenor startTenor) { JodaBeanUtils.notNull(startTenor, "startTenor"); this._startTenor = startTenor; return this; } /** * Sets the {@code endTenor} property in the builder. * @param endTenor the new value * @return this, for chaining, not null */ public Builder endTenor(Tenor endTenor) { this._endTenor = endTenor; return this; } /** * Sets the {@code volatility} property in the builder. * @param volatility the new value * @return this, for chaining, not null */ public Builder volatility(double volatility) { this._volatility = volatility; return this; } //----------------------------------------------------------------------- @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("HullWhiteOneFactorVolatilityEntry.Builder{"); buf.append("startTenor").append('=').append(JodaBeanUtils.toString(_startTenor)).append(',').append(' '); buf.append("endTenor").append('=').append(JodaBeanUtils.toString(_endTenor)).append(',').append(' '); buf.append("volatility").append('=').append(JodaBeanUtils.toString(_volatility)); buf.append('}'); return buf.toString(); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }