/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.financial.security.index; import java.util.List; 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.master.security.SecurityDescription; import com.opengamma.util.ArgumentChecker; /** * Class representing a bond index. */ @BeanDefinition @SecurityDescription(type = BondIndex.INDEX_TYPE, description = "Bond index") public class BondIndex extends Index { /** Serialization version */ private static final long serialVersionUID = 1L; /** * The index type. */ public static final String INDEX_TYPE = "BOND_INDEX"; /** * The bond components of the index. */ @PropertyDefinition(validate = "notNull") private List<BondIndexComponent> _bondComponents; /** * The weighting calculation type. */ @PropertyDefinition(validate = "notNull") private IndexWeightingType _weightingType; /** * For the builder. */ public BondIndex() { super(INDEX_TYPE); } /** * Constructs an bond index with no description. * @param name The index name, not null * @param bondComponents The bond components, not null * @param weightingType The index weighting type, not null */ public BondIndex(final String name, final List<BondIndexComponent> bondComponents, final IndexWeightingType weightingType) { super(INDEX_TYPE, name); ArgumentChecker.notNull(bondComponents, "bondComponents"); setBondComponents(bondComponents); setWeightingType(weightingType); } /** * Constructs an bond index. * @param name The index name, not null * @param description The index description, not null * @param bondComponents The bond components, not null * @param weightingType The index weighting type, not null */ public BondIndex(final String name, final String description, final List<BondIndexComponent> bondComponents, final IndexWeightingType weightingType) { super(INDEX_TYPE, name, description); ArgumentChecker.notNull(bondComponents, "bondComponents"); setBondComponents(bondComponents); setWeightingType(weightingType); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code BondIndex}. * @return the meta-bean, not null */ public static BondIndex.Meta meta() { return BondIndex.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(BondIndex.Meta.INSTANCE); } @Override public BondIndex.Meta metaBean() { return BondIndex.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the bond components of the index. * @return the value of the property, not null */ public List<BondIndexComponent> getBondComponents() { return _bondComponents; } /** * Sets the bond components of the index. * @param bondComponents the new value of the property, not null */ public void setBondComponents(List<BondIndexComponent> bondComponents) { JodaBeanUtils.notNull(bondComponents, "bondComponents"); this._bondComponents = bondComponents; } /** * Gets the the {@code bondComponents} property. * @return the property, not null */ public final Property<List<BondIndexComponent>> bondComponents() { return metaBean().bondComponents().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the weighting calculation type. * @return the value of the property, not null */ public IndexWeightingType getWeightingType() { return _weightingType; } /** * Sets the weighting calculation type. * @param weightingType the new value of the property, not null */ public void setWeightingType(IndexWeightingType weightingType) { JodaBeanUtils.notNull(weightingType, "weightingType"); this._weightingType = weightingType; } /** * Gets the the {@code weightingType} property. * @return the property, not null */ public final Property<IndexWeightingType> weightingType() { return metaBean().weightingType().createProperty(this); } //----------------------------------------------------------------------- @Override public BondIndex clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { BondIndex other = (BondIndex) obj; return JodaBeanUtils.equal(getBondComponents(), other.getBondComponents()) && JodaBeanUtils.equal(getWeightingType(), other.getWeightingType()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getBondComponents()); hash = hash * 31 + JodaBeanUtils.hashCode(getWeightingType()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("BondIndex{"); 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("bondComponents").append('=').append(JodaBeanUtils.toString(getBondComponents())).append(',').append(' '); buf.append("weightingType").append('=').append(JodaBeanUtils.toString(getWeightingType())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code BondIndex}. */ public static class Meta extends Index.Meta { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code bondComponents} property. */ @SuppressWarnings({"unchecked", "rawtypes" }) private final MetaProperty<List<BondIndexComponent>> _bondComponents = DirectMetaProperty.ofReadWrite( this, "bondComponents", BondIndex.class, (Class) List.class); /** * The meta-property for the {@code weightingType} property. */ private final MetaProperty<IndexWeightingType> _weightingType = DirectMetaProperty.ofReadWrite( this, "weightingType", BondIndex.class, IndexWeightingType.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "bondComponents", "weightingType"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1249361351: // bondComponents return _bondComponents; case 86270148: // weightingType return _weightingType; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends BondIndex> builder() { return new DirectBeanBuilder<BondIndex>(new BondIndex()); } @Override public Class<? extends BondIndex> beanType() { return BondIndex.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code bondComponents} property. * @return the meta-property, not null */ public final MetaProperty<List<BondIndexComponent>> bondComponents() { return _bondComponents; } /** * The meta-property for the {@code weightingType} property. * @return the meta-property, not null */ public final MetaProperty<IndexWeightingType> weightingType() { return _weightingType; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1249361351: // bondComponents return ((BondIndex) bean).getBondComponents(); case 86270148: // weightingType return ((BondIndex) bean).getWeightingType(); } return super.propertyGet(bean, propertyName, quiet); } @SuppressWarnings("unchecked") @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -1249361351: // bondComponents ((BondIndex) bean).setBondComponents((List<BondIndexComponent>) newValue); return; case 86270148: // weightingType ((BondIndex) bean).setWeightingType((IndexWeightingType) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((BondIndex) bean)._bondComponents, "bondComponents"); JodaBeanUtils.notNull(((BondIndex) bean)._weightingType, "weightingType"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }