/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sesame.marketdata;
import java.io.Serializable;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
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.DirectFieldsBeanBuilder;
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.link.ConfigLink;
import com.opengamma.financial.analytics.curve.CurveConstructionConfiguration;
import com.opengamma.sesame.MulticurveBundle;
import com.opengamma.util.ArgumentChecker;
/**
* Identifier of a bundle of curves.
*/
@BeanDefinition(builderScope = "private")
public final class MulticurveId implements MarketDataId<MulticurveBundle>, ImmutableBean, Serializable {
/** The name of the bundle. */
@PropertyDefinition(validate = "notEmpty")
private final String _name;
/** Link to the configuration for building the bundle. */
@PropertyDefinition(validate = "notNull", get = "private")
private final ConfigLink<CurveConstructionConfiguration> _curveConfigLink;
private MulticurveId(String name) {
this(name, ConfigLink.resolvable(name, CurveConstructionConfiguration.class));
}
private MulticurveId(CurveConstructionConfiguration config) {
this(ArgumentChecker.notNull(config, "config").getName(), ConfigLink.resolved(config));
}
@Override
public Class<MulticurveBundle> getMarketDataType() {
return MulticurveBundle.class;
}
/**
* Creates an ID for the curve bundle with the specified name.
*
* @param name the curve bundle name
* @return an ID for the curve bundle
*/
public static MulticurveId of(String name) {
return new MulticurveId(name);
}
/**
* Creates an ID for the curve bundle built from the specified configuration
*
* @param config configuration for building the curve bundle
* @return an ID for the curve bundle
*/
public static MulticurveId of(CurveConstructionConfiguration config) {
return new MulticurveId(config);
}
/**
* Resolves and returns the configuration for the curve.
* <p>
* Resolution needs to be done lazily as an ID can be created outside the engine when pre-populating a
* {@code MarketDataEnvironment}. If resolution were done eagerly it would fail.
*
* @return the configuration for the curve
*/
public CurveConstructionConfiguration resolveConfig() {
return _curveConfigLink.resolve();
}
@Override
public int hashCode() {
// manually implemented so IDs are equal regardless of whether the link is resolved
return _name.hashCode();
}
@Override
public boolean equals(Object obj) {
// manually implemented so IDs are equal regardless of whether the link is resolved
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
MulticurveId other = (MulticurveId) obj;
return Objects.equals(this._name, other._name);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code MulticurveId}.
* @return the meta-bean, not null
*/
public static MulticurveId.Meta meta() {
return MulticurveId.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(MulticurveId.Meta.INSTANCE);
}
private MulticurveId(
String name,
ConfigLink<CurveConstructionConfiguration> curveConfigLink) {
JodaBeanUtils.notEmpty(name, "name");
JodaBeanUtils.notNull(curveConfigLink, "curveConfigLink");
this._name = name;
this._curveConfigLink = curveConfigLink;
}
@Override
public MulticurveId.Meta metaBean() {
return MulticurveId.Meta.INSTANCE;
}
@Override
public <R> Property<R> property(String propertyName) {
return metaBean().<R>metaProperty(propertyName).createProperty(this);
}
@Override
public Set<String> propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the name of the bundle.
* @return the value of the property, not empty
*/
public String getName() {
return _name;
}
//-----------------------------------------------------------------------
/**
* Gets link to the configuration for building the bundle.
* @return the value of the property, not null
*/
private ConfigLink<CurveConstructionConfiguration> getCurveConfigLink() {
return _curveConfigLink;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("MulticurveId{");
buf.append("name").append('=').append(getName()).append(',').append(' ');
buf.append("curveConfigLink").append('=').append(JodaBeanUtils.toString(getCurveConfigLink()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code MulticurveId}.
*/
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 name} property.
*/
private final MetaProperty<String> _name = DirectMetaProperty.ofImmutable(
this, "name", MulticurveId.class, String.class);
/**
* The meta-property for the {@code curveConfigLink} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<ConfigLink<CurveConstructionConfiguration>> _curveConfigLink = DirectMetaProperty.ofImmutable(
this, "curveConfigLink", MulticurveId.class, (Class) ConfigLink.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"name",
"curveConfigLink");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3373707: // name
return _name;
case 587920555: // curveConfigLink
return _curveConfigLink;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends MulticurveId> builder() {
return new MulticurveId.Builder();
}
@Override
public Class<? extends MulticurveId> beanType() {
return MulticurveId.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code name} property.
* @return the meta-property, not null
*/
public MetaProperty<String> name() {
return _name;
}
/**
* The meta-property for the {@code curveConfigLink} property.
* @return the meta-property, not null
*/
public MetaProperty<ConfigLink<CurveConstructionConfiguration>> curveConfigLink() {
return _curveConfigLink;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3373707: // name
return ((MulticurveId) bean).getName();
case 587920555: // curveConfigLink
return ((MulticurveId) bean).getCurveConfigLink();
}
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 MulticurveId}.
*/
private static final class Builder extends DirectFieldsBeanBuilder<MulticurveId> {
private String _name;
private ConfigLink<CurveConstructionConfiguration> _curveConfigLink;
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3373707: // name
return _name;
case 587920555: // curveConfigLink
return _curveConfigLink;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@SuppressWarnings("unchecked")
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 3373707: // name
this._name = (String) newValue;
break;
case 587920555: // curveConfigLink
this._curveConfigLink = (ConfigLink<CurveConstructionConfiguration>) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder set(MetaProperty<?> property, Object value) {
super.set(property, value);
return this;
}
@Override
public Builder setString(String propertyName, String value) {
setString(meta().metaProperty(propertyName), value);
return this;
}
@Override
public Builder setString(MetaProperty<?> property, String value) {
super.setString(property, value);
return this;
}
@Override
public Builder setAll(Map<String, ? extends Object> propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public MulticurveId build() {
return new MulticurveId(
_name,
_curveConfigLink);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("MulticurveId.Builder{");
buf.append("name").append('=').append(JodaBeanUtils.toString(_name)).append(',').append(' ');
buf.append("curveConfigLink").append('=').append(JodaBeanUtils.toString(_curveConfigLink));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}