/* * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.analytics.ircurve.strips; 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.util.ArgumentChecker; import com.opengamma.util.time.Tenor; /** * */ @BeanDefinition public class PeriodicallyCompoundedRateNode extends CurveNode { /** Serialization version */ private static final long serialVersionUID = 1L; /** * The tenor. */ @PropertyDefinition(validate = "notNull") private Tenor _tenor; /** * The number of composition periods per year (1 for annual, 2 for semi-annual, etc.). */ @PropertyDefinition private int _compoundingPeriodsPerYear; /** * For the builder. */ /* package */PeriodicallyCompoundedRateNode() { super(); } /** * @param curveNodeIdMapperName The curve node id mapper name, not null * @param tenor The tenor, not null * @param compoundingPeriodsPerYear the number of compounding periods per year, (1 for annual, 2 for semi-annual, etc.). */ public PeriodicallyCompoundedRateNode(final String curveNodeIdMapperName, final Tenor tenor, final int compoundingPeriodsPerYear) { super(curveNodeIdMapperName); ArgumentChecker.isTrue(compoundingPeriodsPerYear > 0, "Must have at least one compounding period per year"); setTenor(tenor); setCompoundingPeriodsPerYear(compoundingPeriodsPerYear); } /** * @param curveNodeIdMapperName The curve node id mapper name, not null * @param tenor The tenor, not null * @param name The name * @param compoundingPeriodsPerYear the number of compounding periods per year, (1 for annual, 2 for semi-annual, etc.). */ public PeriodicallyCompoundedRateNode(final String curveNodeIdMapperName, final Tenor tenor, final String name, final int compoundingPeriodsPerYear) { super(curveNodeIdMapperName, name); ArgumentChecker.isTrue(compoundingPeriodsPerYear > 0, "Must have at least one compounding period per year"); setTenor(tenor); setCompoundingPeriodsPerYear(compoundingPeriodsPerYear); } @Override public Tenor getResolvedMaturity() { return _tenor; } @Override public <T> T accept(final CurveNodeVisitor<T> visitor) { ArgumentChecker.notNull(visitor, "visitor"); return visitor.visitPeriodicallyCompoundedRateNode(this); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code PeriodicallyCompoundedRateNode}. * @return the meta-bean, not null */ public static PeriodicallyCompoundedRateNode.Meta meta() { return PeriodicallyCompoundedRateNode.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(PeriodicallyCompoundedRateNode.Meta.INSTANCE); } @Override public PeriodicallyCompoundedRateNode.Meta metaBean() { return PeriodicallyCompoundedRateNode.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the tenor. * @return the value of the property, not null */ public Tenor getTenor() { return _tenor; } /** * Sets the tenor. * @param tenor the new value of the property, not null */ public void setTenor(Tenor tenor) { JodaBeanUtils.notNull(tenor, "tenor"); this._tenor = tenor; } /** * Gets the the {@code tenor} property. * @return the property, not null */ public final Property<Tenor> tenor() { return metaBean().tenor().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the number of composition periods per year (1 for annual, 2 for semi-annual, etc.). * @return the value of the property */ public int getCompoundingPeriodsPerYear() { return _compoundingPeriodsPerYear; } /** * Sets the number of composition periods per year (1 for annual, 2 for semi-annual, etc.). * @param compoundingPeriodsPerYear the new value of the property */ public void setCompoundingPeriodsPerYear(int compoundingPeriodsPerYear) { this._compoundingPeriodsPerYear = compoundingPeriodsPerYear; } /** * Gets the the {@code compoundingPeriodsPerYear} property. * @return the property, not null */ public final Property<Integer> compoundingPeriodsPerYear() { return metaBean().compoundingPeriodsPerYear().createProperty(this); } //----------------------------------------------------------------------- @Override public PeriodicallyCompoundedRateNode clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { PeriodicallyCompoundedRateNode other = (PeriodicallyCompoundedRateNode) obj; return JodaBeanUtils.equal(getTenor(), other.getTenor()) && (getCompoundingPeriodsPerYear() == other.getCompoundingPeriodsPerYear()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getTenor()); hash = hash * 31 + JodaBeanUtils.hashCode(getCompoundingPeriodsPerYear()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("PeriodicallyCompoundedRateNode{"); 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("tenor").append('=').append(JodaBeanUtils.toString(getTenor())).append(',').append(' '); buf.append("compoundingPeriodsPerYear").append('=').append(JodaBeanUtils.toString(getCompoundingPeriodsPerYear())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code PeriodicallyCompoundedRateNode}. */ public static class Meta extends CurveNode.Meta { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code tenor} property. */ private final MetaProperty<Tenor> _tenor = DirectMetaProperty.ofReadWrite( this, "tenor", PeriodicallyCompoundedRateNode.class, Tenor.class); /** * The meta-property for the {@code compoundingPeriodsPerYear} property. */ private final MetaProperty<Integer> _compoundingPeriodsPerYear = DirectMetaProperty.ofReadWrite( this, "compoundingPeriodsPerYear", PeriodicallyCompoundedRateNode.class, Integer.TYPE); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "tenor", "compoundingPeriodsPerYear"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 110246592: // tenor return _tenor; case 1668812287: // compoundingPeriodsPerYear return _compoundingPeriodsPerYear; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends PeriodicallyCompoundedRateNode> builder() { return new DirectBeanBuilder<PeriodicallyCompoundedRateNode>(new PeriodicallyCompoundedRateNode()); } @Override public Class<? extends PeriodicallyCompoundedRateNode> beanType() { return PeriodicallyCompoundedRateNode.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code tenor} property. * @return the meta-property, not null */ public final MetaProperty<Tenor> tenor() { return _tenor; } /** * The meta-property for the {@code compoundingPeriodsPerYear} property. * @return the meta-property, not null */ public final MetaProperty<Integer> compoundingPeriodsPerYear() { return _compoundingPeriodsPerYear; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 110246592: // tenor return ((PeriodicallyCompoundedRateNode) bean).getTenor(); case 1668812287: // compoundingPeriodsPerYear return ((PeriodicallyCompoundedRateNode) bean).getCompoundingPeriodsPerYear(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 110246592: // tenor ((PeriodicallyCompoundedRateNode) bean).setTenor((Tenor) newValue); return; case 1668812287: // compoundingPeriodsPerYear ((PeriodicallyCompoundedRateNode) bean).setCompoundingPeriodsPerYear((Integer) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((PeriodicallyCompoundedRateNode) bean)._tenor, "tenor"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }