/**
* Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.curve;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
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.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.opengamma.core.config.Config;
import com.opengamma.core.config.ConfigGroups;
import com.opengamma.financial.analytics.ircurve.strips.CurveNode;
import com.opengamma.id.UniqueId;
/**
* Basic curve definition class containing only a name and curve nodes. Some curve definitions (e.g. {@link InterpolatedCurveDefinition}) will descend from this class,
* but this can be used as a nodal curve definition.
*/
@BeanDefinition
@Config(description = "Curve definition", group = ConfigGroups.CURVES)
public class CurveDefinition extends AbstractCurveDefinition {
/** Serialization version */
private static final long serialVersionUID = 1L;
/**
* The constituents of the curve.
*/
@PropertyDefinition(validate = "notNull")
private SortedSet<CurveNode> _nodes = new TreeSet<>();
/**
* For the builder
*/
public CurveDefinition() {
super();
}
/**
* @param name The name of the curve definition, not null
* @param nodes The curve nodes, not null
*/
public CurveDefinition(final String name, final Set<CurveNode> nodes) {
super(name);
setNodes(new TreeSet<>(nodes));
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code CurveDefinition}.
* @return the meta-bean, not null
*/
public static CurveDefinition.Meta meta() {
return CurveDefinition.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(CurveDefinition.Meta.INSTANCE);
}
@Override
public CurveDefinition.Meta metaBean() {
return CurveDefinition.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the constituents of the curve.
* @return the value of the property, not null
*/
public SortedSet<CurveNode> getNodes() {
return _nodes;
}
/**
* Sets the constituents of the curve.
* @param nodes the new value of the property, not null
*/
public void setNodes(SortedSet<CurveNode> nodes) {
JodaBeanUtils.notNull(nodes, "nodes");
this._nodes = nodes;
}
/**
* Gets the the {@code nodes} property.
* @return the property, not null
*/
public final Property<SortedSet<CurveNode>> nodes() {
return metaBean().nodes().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public CurveDefinition clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
CurveDefinition other = (CurveDefinition) obj;
return JodaBeanUtils.equal(getNodes(), other.getNodes()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getNodes());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(64);
buf.append("CurveDefinition{");
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("nodes").append('=').append(JodaBeanUtils.toString(getNodes())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CurveDefinition}.
*/
public static class Meta extends AbstractCurveDefinition.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code nodes} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<SortedSet<CurveNode>> _nodes = DirectMetaProperty.ofReadWrite(
this, "nodes", CurveDefinition.class, (Class) SortedSet.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"nodes");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 104993457: // nodes
return _nodes;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends CurveDefinition> builder() {
return new DirectBeanBuilder<CurveDefinition>(new CurveDefinition());
}
@Override
public Class<? extends CurveDefinition> beanType() {
return CurveDefinition.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code nodes} property.
* @return the meta-property, not null
*/
public final MetaProperty<SortedSet<CurveNode>> nodes() {
return _nodes;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 104993457: // nodes
return ((CurveDefinition) bean).getNodes();
}
return super.propertyGet(bean, propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case 104993457: // nodes
((CurveDefinition) bean).setNodes((SortedSet<CurveNode>) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((CurveDefinition) bean)._nodes, "nodes");
super.validate(bean);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}