com.opengamma.strata.market.curve.CurveId Maven / Gradle / Ivy
Show all versions of strata-market Show documentation
/*
* Copyright (C) 2016 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.strata.market.curve;
import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.joda.beans.impl.direct.DirectPrivateBeanBuilder;
import com.opengamma.strata.data.MarketDataName;
import com.opengamma.strata.data.NamedMarketDataId;
import com.opengamma.strata.data.ObservableSource;
/**
* An identifier used to access a curve by name.
*
* This is used when there is a need to obtain an instance of {@link Curve}.
*/
@BeanDefinition(builderScope = "private", cacheHashCode = true)
public final class CurveId
implements NamedMarketDataId, ImmutableBean, Serializable {
/**
* The curve group name.
*/
@PropertyDefinition(validate = "notNull")
private final CurveGroupName curveGroupName;
/**
* The curve name.
*/
@PropertyDefinition(validate = "notNull")
private final CurveName curveName;
/**
* The source of observable market data.
*/
@PropertyDefinition(validate = "notNull")
private final ObservableSource observableSource;
//-------------------------------------------------------------------------
/**
* Obtains an instance used to obtain a curve by name.
*
* @param groupName the curve group name
* @param curveName the curve name
* @return the identifier
*/
public static CurveId of(String groupName, String curveName) {
return new CurveId(CurveGroupName.of(groupName), CurveName.of(curveName), ObservableSource.NONE);
}
/**
* Obtains an instance used to obtain a curve by name.
*
* @param groupName the curve group name
* @param curveName the curve name
* @return the identifier
*/
public static CurveId of(CurveGroupName groupName, CurveName curveName) {
return new CurveId(groupName, curveName, ObservableSource.NONE);
}
/**
* Obtains an instance used to obtain a curve by name, specifying the source of observable market data.
*
* @param groupName the curve group name
* @param curveName the curve name
* @param obsSource the source of observable market data
* @return the identifier
*/
public static CurveId of(CurveGroupName groupName, CurveName curveName, ObservableSource obsSource) {
return new CurveId(groupName, curveName, obsSource);
}
//-------------------------------------------------------------------------
@Override
public Class getMarketDataType() {
return Curve.class;
}
@Override
public MarketDataName getMarketDataName() {
return curveName;
}
//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code CurveId}.
* @return the meta-bean, not null
*/
public static CurveId.Meta meta() {
return CurveId.Meta.INSTANCE;
}
static {
MetaBean.register(CurveId.Meta.INSTANCE);
}
/**
* The serialization version id.
*/
private static final long serialVersionUID = 1L;
/**
* The cached hash code, using the racy single-check idiom.
*/
private transient int cacheHashCode;
private CurveId(
CurveGroupName curveGroupName,
CurveName curveName,
ObservableSource observableSource) {
JodaBeanUtils.notNull(curveGroupName, "curveGroupName");
JodaBeanUtils.notNull(curveName, "curveName");
JodaBeanUtils.notNull(observableSource, "observableSource");
this.curveGroupName = curveGroupName;
this.curveName = curveName;
this.observableSource = observableSource;
}
@Override
public CurveId.Meta metaBean() {
return CurveId.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the curve group name.
* @return the value of the property, not null
*/
public CurveGroupName getCurveGroupName() {
return curveGroupName;
}
//-----------------------------------------------------------------------
/**
* Gets the curve name.
* @return the value of the property, not null
*/
public CurveName getCurveName() {
return curveName;
}
//-----------------------------------------------------------------------
/**
* Gets the source of observable market data.
* @return the value of the property, not null
*/
public ObservableSource getObservableSource() {
return observableSource;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
CurveId other = (CurveId) obj;
return JodaBeanUtils.equal(curveGroupName, other.curveGroupName) &&
JodaBeanUtils.equal(curveName, other.curveName) &&
JodaBeanUtils.equal(observableSource, other.observableSource);
}
return false;
}
@Override
public int hashCode() {
int hash = cacheHashCode;
if (hash == 0) {
hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(curveGroupName);
hash = hash * 31 + JodaBeanUtils.hashCode(curveName);
hash = hash * 31 + JodaBeanUtils.hashCode(observableSource);
cacheHashCode = hash;
}
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("CurveId{");
buf.append("curveGroupName").append('=').append(curveGroupName).append(',').append(' ');
buf.append("curveName").append('=').append(curveName).append(',').append(' ');
buf.append("observableSource").append('=').append(JodaBeanUtils.toString(observableSource));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CurveId}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code curveGroupName} property.
*/
private final MetaProperty curveGroupName = DirectMetaProperty.ofImmutable(
this, "curveGroupName", CurveId.class, CurveGroupName.class);
/**
* The meta-property for the {@code curveName} property.
*/
private final MetaProperty curveName = DirectMetaProperty.ofImmutable(
this, "curveName", CurveId.class, CurveName.class);
/**
* The meta-property for the {@code observableSource} property.
*/
private final MetaProperty observableSource = DirectMetaProperty.ofImmutable(
this, "observableSource", CurveId.class, ObservableSource.class);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"curveGroupName",
"curveName",
"observableSource");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -382645893: // curveGroupName
return curveGroupName;
case 771153946: // curveName
return curveName;
case 1793526590: // observableSource
return observableSource;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder extends CurveId> builder() {
return new CurveId.Builder();
}
@Override
public Class extends CurveId> beanType() {
return CurveId.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code curveGroupName} property.
* @return the meta-property, not null
*/
public MetaProperty curveGroupName() {
return curveGroupName;
}
/**
* The meta-property for the {@code curveName} property.
* @return the meta-property, not null
*/
public MetaProperty curveName() {
return curveName;
}
/**
* The meta-property for the {@code observableSource} property.
* @return the meta-property, not null
*/
public MetaProperty observableSource() {
return observableSource;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -382645893: // curveGroupName
return ((CurveId) bean).getCurveGroupName();
case 771153946: // curveName
return ((CurveId) bean).getCurveName();
case 1793526590: // observableSource
return ((CurveId) bean).getObservableSource();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code CurveId}.
*/
private static final class Builder extends DirectPrivateBeanBuilder {
private CurveGroupName curveGroupName;
private CurveName curveName;
private ObservableSource observableSource;
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -382645893: // curveGroupName
return curveGroupName;
case 771153946: // curveName
return curveName;
case 1793526590: // observableSource
return observableSource;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -382645893: // curveGroupName
this.curveGroupName = (CurveGroupName) newValue;
break;
case 771153946: // curveName
this.curveName = (CurveName) newValue;
break;
case 1793526590: // observableSource
this.observableSource = (ObservableSource) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public CurveId build() {
return new CurveId(
curveGroupName,
curveName,
observableSource);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("CurveId.Builder{");
buf.append("curveGroupName").append('=').append(JodaBeanUtils.toString(curveGroupName)).append(',').append(' ');
buf.append("curveName").append('=').append(JodaBeanUtils.toString(curveName)).append(',').append(' ');
buf.append("observableSource").append('=').append(JodaBeanUtils.toString(observableSource));
buf.append('}');
return buf.toString();
}
}
//-------------------------- AUTOGENERATED END --------------------------
}