/**
* Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.convention;
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.convention.ConventionType;
import com.opengamma.id.ExternalId;
import com.opengamma.id.ExternalIdBundle;
import com.opengamma.util.ArgumentChecker;
import com.opengamma.util.time.Tenor;
/**
* Conventions for the CMS leg of a swap.
*/
@BeanDefinition
public class CMSLegConvention extends FinancialConvention {
/**
* Type of the convention.
*/
public static final ConventionType TYPE = ConventionType.of("ConstantMaturitySwapLeg");
/** Serialization version. */
private static final long serialVersionUID = 1L;
/**
* The swap index convention.
*/
@PropertyDefinition(validate = "notNull")
private ExternalId _swapIndexConvention;
/**
* The payment tenor.
*/
@PropertyDefinition(validate = "notNull")
private Tenor _paymentTenor;
/**
* Whether fixing in advance (true) or in arrears (false).
*/
@PropertyDefinition
private boolean _isAdvanceFixing;
/**
* Creates an instance.
*/
protected CMSLegConvention() {
super();
}
/**
* Creates an instance.
*
* @param name the convention name, not null
* @param externalIdBundle the external identifiers for this convention, not null
* @param swapIndexConvention the id of the swap index convention, not null
* @param paymentTenor the payment tenor, not null
* @param isAdvanceFixing true if the fixing is in advance
*/
public CMSLegConvention(
final String name, final ExternalIdBundle externalIdBundle, final ExternalId swapIndexConvention,
final Tenor paymentTenor, final boolean isAdvanceFixing) {
super(name, externalIdBundle);
setSwapIndexConvention(swapIndexConvention);
setPaymentTenor(paymentTenor);
setIsAdvanceFixing(isAdvanceFixing);
}
//-------------------------------------------------------------------------
/**
* Gets the type identifying this convention.
*
* @return the {@link #TYPE} constant, not null
*/
@Override
public ConventionType getConventionType() {
return TYPE;
}
/**
* Accepts a visitor to manage traversal of the hierarchy.
*
* @param <T> the result type of the visitor
* @param visitor the visitor, not null
* @return the result
*/
@Override
public <T> T accept(final FinancialConventionVisitor<T> visitor) {
ArgumentChecker.notNull(visitor, "visitor");
return visitor.visitCMSLegConvention(this);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code CMSLegConvention}.
* @return the meta-bean, not null
*/
public static CMSLegConvention.Meta meta() {
return CMSLegConvention.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(CMSLegConvention.Meta.INSTANCE);
}
@Override
public CMSLegConvention.Meta metaBean() {
return CMSLegConvention.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the swap index convention.
* @return the value of the property, not null
*/
public ExternalId getSwapIndexConvention() {
return _swapIndexConvention;
}
/**
* Sets the swap index convention.
* @param swapIndexConvention the new value of the property, not null
*/
public void setSwapIndexConvention(ExternalId swapIndexConvention) {
JodaBeanUtils.notNull(swapIndexConvention, "swapIndexConvention");
this._swapIndexConvention = swapIndexConvention;
}
/**
* Gets the the {@code swapIndexConvention} property.
* @return the property, not null
*/
public final Property<ExternalId> swapIndexConvention() {
return metaBean().swapIndexConvention().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the payment tenor.
* @return the value of the property, not null
*/
public Tenor getPaymentTenor() {
return _paymentTenor;
}
/**
* Sets the payment tenor.
* @param paymentTenor the new value of the property, not null
*/
public void setPaymentTenor(Tenor paymentTenor) {
JodaBeanUtils.notNull(paymentTenor, "paymentTenor");
this._paymentTenor = paymentTenor;
}
/**
* Gets the the {@code paymentTenor} property.
* @return the property, not null
*/
public final Property<Tenor> paymentTenor() {
return metaBean().paymentTenor().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets whether fixing in advance (true) or in arrears (false).
* @return the value of the property
*/
public boolean isIsAdvanceFixing() {
return _isAdvanceFixing;
}
/**
* Sets whether fixing in advance (true) or in arrears (false).
* @param isAdvanceFixing the new value of the property
*/
public void setIsAdvanceFixing(boolean isAdvanceFixing) {
this._isAdvanceFixing = isAdvanceFixing;
}
/**
* Gets the the {@code isAdvanceFixing} property.
* @return the property, not null
*/
public final Property<Boolean> isAdvanceFixing() {
return metaBean().isAdvanceFixing().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public CMSLegConvention clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
CMSLegConvention other = (CMSLegConvention) obj;
return JodaBeanUtils.equal(getSwapIndexConvention(), other.getSwapIndexConvention()) &&
JodaBeanUtils.equal(getPaymentTenor(), other.getPaymentTenor()) &&
(isIsAdvanceFixing() == other.isIsAdvanceFixing()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getSwapIndexConvention());
hash = hash * 31 + JodaBeanUtils.hashCode(getPaymentTenor());
hash = hash * 31 + JodaBeanUtils.hashCode(isIsAdvanceFixing());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("CMSLegConvention{");
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("swapIndexConvention").append('=').append(JodaBeanUtils.toString(getSwapIndexConvention())).append(',').append(' ');
buf.append("paymentTenor").append('=').append(JodaBeanUtils.toString(getPaymentTenor())).append(',').append(' ');
buf.append("isAdvanceFixing").append('=').append(JodaBeanUtils.toString(isIsAdvanceFixing())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CMSLegConvention}.
*/
public static class Meta extends FinancialConvention.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code swapIndexConvention} property.
*/
private final MetaProperty<ExternalId> _swapIndexConvention = DirectMetaProperty.ofReadWrite(
this, "swapIndexConvention", CMSLegConvention.class, ExternalId.class);
/**
* The meta-property for the {@code paymentTenor} property.
*/
private final MetaProperty<Tenor> _paymentTenor = DirectMetaProperty.ofReadWrite(
this, "paymentTenor", CMSLegConvention.class, Tenor.class);
/**
* The meta-property for the {@code isAdvanceFixing} property.
*/
private final MetaProperty<Boolean> _isAdvanceFixing = DirectMetaProperty.ofReadWrite(
this, "isAdvanceFixing", CMSLegConvention.class, Boolean.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"swapIndexConvention",
"paymentTenor",
"isAdvanceFixing");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1606291504: // swapIndexConvention
return _swapIndexConvention;
case -507548582: // paymentTenor
return _paymentTenor;
case 1363941829: // isAdvanceFixing
return _isAdvanceFixing;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends CMSLegConvention> builder() {
return new DirectBeanBuilder<CMSLegConvention>(new CMSLegConvention());
}
@Override
public Class<? extends CMSLegConvention> beanType() {
return CMSLegConvention.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code swapIndexConvention} property.
* @return the meta-property, not null
*/
public final MetaProperty<ExternalId> swapIndexConvention() {
return _swapIndexConvention;
}
/**
* The meta-property for the {@code paymentTenor} property.
* @return the meta-property, not null
*/
public final MetaProperty<Tenor> paymentTenor() {
return _paymentTenor;
}
/**
* The meta-property for the {@code isAdvanceFixing} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> isAdvanceFixing() {
return _isAdvanceFixing;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1606291504: // swapIndexConvention
return ((CMSLegConvention) bean).getSwapIndexConvention();
case -507548582: // paymentTenor
return ((CMSLegConvention) bean).getPaymentTenor();
case 1363941829: // isAdvanceFixing
return ((CMSLegConvention) bean).isIsAdvanceFixing();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -1606291504: // swapIndexConvention
((CMSLegConvention) bean).setSwapIndexConvention((ExternalId) newValue);
return;
case -507548582: // paymentTenor
((CMSLegConvention) bean).setPaymentTenor((Tenor) newValue);
return;
case 1363941829: // isAdvanceFixing
((CMSLegConvention) bean).setIsAdvanceFixing((Boolean) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((CMSLegConvention) bean)._swapIndexConvention, "swapIndexConvention");
JodaBeanUtils.notNull(((CMSLegConvention) bean)._paymentTenor, "paymentTenor");
super.validate(bean);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}