/**
* Copyright (C) 2014 - 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.financial.convention.businessday.BusinessDayConvention;
import com.opengamma.id.ExternalIdBundle;
import com.opengamma.util.ArgumentChecker;
/**
* Conventions for bonds.
*/
@BeanDefinition
public class BondConvention extends FinancialConvention {
/**
* The type of the convention.
*/
public static final ConventionType TYPE = ConventionType.of("Bond");
/** Serialization version. */
private static final long serialVersionUID = 1L;
/**
* The number of ex-dividend days.
*/
@PropertyDefinition
private int _exDividendDays;
/**
* The number of settlement days.
*/
@PropertyDefinition
private int _settlementDays;
/**
* The business day convention.
*/
@PropertyDefinition
private BusinessDayConvention _businessDayConvention;
/**
* True if the schedule follows the EOM convention.
*/
@PropertyDefinition
private boolean _isEOM;
/**
* True if the schedule is calculated from the bond maturity.
*/
@PropertyDefinition
private boolean _isCalculateScheduleFromMaturity;
/**
* For the builder.
*/
/* package */BondConvention() {
super();
}
/**
* @param name The convention name, not null
* @param externalIdBundle The external id bundle, not null
* @param exDividendDays The number of ex-dividend days, not negative
* @param settlementDays The number of settlement days, not negative
* @param businessDayConvention The business day convention
* @param isEOM True if the schedule is generated using the end-of-month convention.
* @param isCalculateScheduleFromMaturity True if the schedule is to be calculated from the bond maturity date.
*/
public BondConvention(final String name, final ExternalIdBundle externalIdBundle, final int exDividendDays, final int settlementDays,
final BusinessDayConvention businessDayConvention, final boolean isEOM, final boolean isCalculateScheduleFromMaturity) {
super(name, externalIdBundle);
setExDividendDays(exDividendDays);
setSettlementDays(settlementDays);
setBusinessDayConvention(businessDayConvention);
setIsEOM(isEOM);
setIsCalculateScheduleFromMaturity(isCalculateScheduleFromMaturity);
}
@Override
public ConventionType getConventionType() {
return TYPE;
}
@Override
public <T> T accept(final FinancialConventionVisitor<T> visitor) {
ArgumentChecker.notNull(visitor, "visitor");
return visitor.visitBondConvention(this);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code BondConvention}.
* @return the meta-bean, not null
*/
public static BondConvention.Meta meta() {
return BondConvention.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(BondConvention.Meta.INSTANCE);
}
@Override
public BondConvention.Meta metaBean() {
return BondConvention.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the number of ex-dividend days.
* @return the value of the property
*/
public int getExDividendDays() {
return _exDividendDays;
}
/**
* Sets the number of ex-dividend days.
* @param exDividendDays the new value of the property
*/
public void setExDividendDays(int exDividendDays) {
this._exDividendDays = exDividendDays;
}
/**
* Gets the the {@code exDividendDays} property.
* @return the property, not null
*/
public final Property<Integer> exDividendDays() {
return metaBean().exDividendDays().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the number of settlement days.
* @return the value of the property
*/
public int getSettlementDays() {
return _settlementDays;
}
/**
* Sets the number of settlement days.
* @param settlementDays the new value of the property
*/
public void setSettlementDays(int settlementDays) {
this._settlementDays = settlementDays;
}
/**
* Gets the the {@code settlementDays} property.
* @return the property, not null
*/
public final Property<Integer> settlementDays() {
return metaBean().settlementDays().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the business day convention.
* @return the value of the property
*/
public BusinessDayConvention getBusinessDayConvention() {
return _businessDayConvention;
}
/**
* Sets the business day convention.
* @param businessDayConvention the new value of the property
*/
public void setBusinessDayConvention(BusinessDayConvention businessDayConvention) {
this._businessDayConvention = businessDayConvention;
}
/**
* Gets the the {@code businessDayConvention} property.
* @return the property, not null
*/
public final Property<BusinessDayConvention> businessDayConvention() {
return metaBean().businessDayConvention().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets true if the schedule follows the EOM convention.
* @return the value of the property
*/
public boolean isIsEOM() {
return _isEOM;
}
/**
* Sets true if the schedule follows the EOM convention.
* @param isEOM the new value of the property
*/
public void setIsEOM(boolean isEOM) {
this._isEOM = isEOM;
}
/**
* Gets the the {@code isEOM} property.
* @return the property, not null
*/
public final Property<Boolean> isEOM() {
return metaBean().isEOM().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets true if the schedule is calculated from the bond maturity.
* @return the value of the property
*/
public boolean isIsCalculateScheduleFromMaturity() {
return _isCalculateScheduleFromMaturity;
}
/**
* Sets true if the schedule is calculated from the bond maturity.
* @param isCalculateScheduleFromMaturity the new value of the property
*/
public void setIsCalculateScheduleFromMaturity(boolean isCalculateScheduleFromMaturity) {
this._isCalculateScheduleFromMaturity = isCalculateScheduleFromMaturity;
}
/**
* Gets the the {@code isCalculateScheduleFromMaturity} property.
* @return the property, not null
*/
public final Property<Boolean> isCalculateScheduleFromMaturity() {
return metaBean().isCalculateScheduleFromMaturity().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public BondConvention clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
BondConvention other = (BondConvention) obj;
return (getExDividendDays() == other.getExDividendDays()) &&
(getSettlementDays() == other.getSettlementDays()) &&
JodaBeanUtils.equal(getBusinessDayConvention(), other.getBusinessDayConvention()) &&
(isIsEOM() == other.isIsEOM()) &&
(isIsCalculateScheduleFromMaturity() == other.isIsCalculateScheduleFromMaturity()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getExDividendDays());
hash = hash * 31 + JodaBeanUtils.hashCode(getSettlementDays());
hash = hash * 31 + JodaBeanUtils.hashCode(getBusinessDayConvention());
hash = hash * 31 + JodaBeanUtils.hashCode(isIsEOM());
hash = hash * 31 + JodaBeanUtils.hashCode(isIsCalculateScheduleFromMaturity());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(192);
buf.append("BondConvention{");
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("exDividendDays").append('=').append(JodaBeanUtils.toString(getExDividendDays())).append(',').append(' ');
buf.append("settlementDays").append('=').append(JodaBeanUtils.toString(getSettlementDays())).append(',').append(' ');
buf.append("businessDayConvention").append('=').append(JodaBeanUtils.toString(getBusinessDayConvention())).append(',').append(' ');
buf.append("isEOM").append('=').append(JodaBeanUtils.toString(isIsEOM())).append(',').append(' ');
buf.append("isCalculateScheduleFromMaturity").append('=').append(JodaBeanUtils.toString(isIsCalculateScheduleFromMaturity())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code BondConvention}.
*/
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 exDividendDays} property.
*/
private final MetaProperty<Integer> _exDividendDays = DirectMetaProperty.ofReadWrite(
this, "exDividendDays", BondConvention.class, Integer.TYPE);
/**
* The meta-property for the {@code settlementDays} property.
*/
private final MetaProperty<Integer> _settlementDays = DirectMetaProperty.ofReadWrite(
this, "settlementDays", BondConvention.class, Integer.TYPE);
/**
* The meta-property for the {@code businessDayConvention} property.
*/
private final MetaProperty<BusinessDayConvention> _businessDayConvention = DirectMetaProperty.ofReadWrite(
this, "businessDayConvention", BondConvention.class, BusinessDayConvention.class);
/**
* The meta-property for the {@code isEOM} property.
*/
private final MetaProperty<Boolean> _isEOM = DirectMetaProperty.ofReadWrite(
this, "isEOM", BondConvention.class, Boolean.TYPE);
/**
* The meta-property for the {@code isCalculateScheduleFromMaturity} property.
*/
private final MetaProperty<Boolean> _isCalculateScheduleFromMaturity = DirectMetaProperty.ofReadWrite(
this, "isCalculateScheduleFromMaturity", BondConvention.class, Boolean.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"exDividendDays",
"settlementDays",
"businessDayConvention",
"isEOM",
"isCalculateScheduleFromMaturity");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1527377607: // exDividendDays
return _exDividendDays;
case -295948000: // settlementDays
return _settlementDays;
case -1002835891: // businessDayConvention
return _businessDayConvention;
case 100464505: // isEOM
return _isEOM;
case 134021390: // isCalculateScheduleFromMaturity
return _isCalculateScheduleFromMaturity;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends BondConvention> builder() {
return new DirectBeanBuilder<BondConvention>(new BondConvention());
}
@Override
public Class<? extends BondConvention> beanType() {
return BondConvention.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code exDividendDays} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> exDividendDays() {
return _exDividendDays;
}
/**
* The meta-property for the {@code settlementDays} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> settlementDays() {
return _settlementDays;
}
/**
* The meta-property for the {@code businessDayConvention} property.
* @return the meta-property, not null
*/
public final MetaProperty<BusinessDayConvention> businessDayConvention() {
return _businessDayConvention;
}
/**
* The meta-property for the {@code isEOM} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> isEOM() {
return _isEOM;
}
/**
* The meta-property for the {@code isCalculateScheduleFromMaturity} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> isCalculateScheduleFromMaturity() {
return _isCalculateScheduleFromMaturity;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1527377607: // exDividendDays
return ((BondConvention) bean).getExDividendDays();
case -295948000: // settlementDays
return ((BondConvention) bean).getSettlementDays();
case -1002835891: // businessDayConvention
return ((BondConvention) bean).getBusinessDayConvention();
case 100464505: // isEOM
return ((BondConvention) bean).isIsEOM();
case 134021390: // isCalculateScheduleFromMaturity
return ((BondConvention) bean).isIsCalculateScheduleFromMaturity();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -1527377607: // exDividendDays
((BondConvention) bean).setExDividendDays((Integer) newValue);
return;
case -295948000: // settlementDays
((BondConvention) bean).setSettlementDays((Integer) newValue);
return;
case -1002835891: // businessDayConvention
((BondConvention) bean).setBusinessDayConvention((BusinessDayConvention) newValue);
return;
case 100464505: // isEOM
((BondConvention) bean).setIsEOM((Boolean) newValue);
return;
case 134021390: // isCalculateScheduleFromMaturity
((BondConvention) bean).setIsCalculateScheduleFromMaturity((Boolean) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}