/**
* 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 an equity index.
*/
@BeanDefinition
@SecurityDescription(type = EquityIndex.INDEX_TYPE, description = "Equity index")
public class EquityIndex extends Index {
/** Serialization version */
private static final long serialVersionUID = 1L;
/**
* The index type.
*/
public static final String INDEX_TYPE = "EQUITY_INDEX";
/**
* The equity components of the index.
*/
@PropertyDefinition(validate = "notNull")
private List<EquityIndexComponent> _equityComponents;
/**
* The weighting calculation type.
*/
@PropertyDefinition(validate = "notNull")
private IndexWeightingType _weightingType;
/**
* For the builder.
*/
public EquityIndex() {
super(INDEX_TYPE);
}
/**
* Constructs an equity index with no description.
* @param name The index name, not null
* @param equityComponents The equity components, not null
* @param weightingType The index weighting type, not null
*/
public EquityIndex(final String name, final List<EquityIndexComponent> equityComponents, final IndexWeightingType weightingType) {
super(INDEX_TYPE, name);
ArgumentChecker.notNull(equityComponents, "equityComponents");
setEquityComponents(equityComponents);
setWeightingType(weightingType);
}
/**
* Constructs an equity index.
* @param name The index name, not null
* @param description The index description, not null
* @param equityComponents The equity components, not null
* @param weightingType The index weighting type, not null
*/
public EquityIndex(final String name, final String description, final List<EquityIndexComponent> equityComponents, final IndexWeightingType weightingType) {
super(INDEX_TYPE, name, description);
ArgumentChecker.notNull(equityComponents, "equityComponents");
setEquityComponents(equityComponents);
setWeightingType(weightingType);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code EquityIndex}.
* @return the meta-bean, not null
*/
public static EquityIndex.Meta meta() {
return EquityIndex.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(EquityIndex.Meta.INSTANCE);
}
@Override
public EquityIndex.Meta metaBean() {
return EquityIndex.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the equity components of the index.
* @return the value of the property, not null
*/
public List<EquityIndexComponent> getEquityComponents() {
return _equityComponents;
}
/**
* Sets the equity components of the index.
* @param equityComponents the new value of the property, not null
*/
public void setEquityComponents(List<EquityIndexComponent> equityComponents) {
JodaBeanUtils.notNull(equityComponents, "equityComponents");
this._equityComponents = equityComponents;
}
/**
* Gets the the {@code equityComponents} property.
* @return the property, not null
*/
public final Property<List<EquityIndexComponent>> equityComponents() {
return metaBean().equityComponents().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 EquityIndex clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
EquityIndex other = (EquityIndex) obj;
return JodaBeanUtils.equal(getEquityComponents(), other.getEquityComponents()) &&
JodaBeanUtils.equal(getWeightingType(), other.getWeightingType()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getEquityComponents());
hash = hash * 31 + JodaBeanUtils.hashCode(getWeightingType());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("EquityIndex{");
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("equityComponents").append('=').append(JodaBeanUtils.toString(getEquityComponents())).append(',').append(' ');
buf.append("weightingType").append('=').append(JodaBeanUtils.toString(getWeightingType())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code EquityIndex}.
*/
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 equityComponents} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<List<EquityIndexComponent>> _equityComponents = DirectMetaProperty.ofReadWrite(
this, "equityComponents", EquityIndex.class, (Class) List.class);
/**
* The meta-property for the {@code weightingType} property.
*/
private final MetaProperty<IndexWeightingType> _weightingType = DirectMetaProperty.ofReadWrite(
this, "weightingType", EquityIndex.class, IndexWeightingType.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"equityComponents",
"weightingType");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281080901: // equityComponents
return _equityComponents;
case 86270148: // weightingType
return _weightingType;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends EquityIndex> builder() {
return new DirectBeanBuilder<EquityIndex>(new EquityIndex());
}
@Override
public Class<? extends EquityIndex> beanType() {
return EquityIndex.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code equityComponents} property.
* @return the meta-property, not null
*/
public final MetaProperty<List<EquityIndexComponent>> equityComponents() {
return _equityComponents;
}
/**
* 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 -281080901: // equityComponents
return ((EquityIndex) bean).getEquityComponents();
case 86270148: // weightingType
return ((EquityIndex) 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 -281080901: // equityComponents
((EquityIndex) bean).setEquityComponents((List<EquityIndexComponent>) newValue);
return;
case 86270148: // weightingType
((EquityIndex) bean).setWeightingType((IndexWeightingType) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((EquityIndex) bean)._equityComponents, "equityComponents");
JodaBeanUtils.notNull(((EquityIndex) bean)._weightingType, "weightingType");
super.validate(bean);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}