/**
* Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.fxforwardcurve;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.joda.beans.Bean;
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.google.common.collect.ImmutableList;
import com.opengamma.core.config.Config;
import com.opengamma.core.config.ConfigGroups;
import com.opengamma.util.money.UnorderedCurrencyPair;
import com.opengamma.util.time.Tenor;
import java.util.Arrays;
/**
* Definition of an FX forward curve.
*/
@Config(description = "FX forward curve definition", group = ConfigGroups.CURVES_LEGACY)
@BeanDefinition
public final class FXForwardCurveDefinition implements ImmutableBean {
/**
* The curve name.
*/
@PropertyDefinition(validate = "notNull")
private final String _name;
/**
* The target currency pair.
*/
@PropertyDefinition(validate = "notNull")
private final UnorderedCurrencyPair _target;
/**
* The tenors.
*/
@PropertyDefinition(validate = "notNull")
private final ImmutableList<Tenor> _tenors;
/**
* Obtains a definition.
*
* @param name the name, not null
* @param target the target currencies, not null
* @param tenors the tenors, not null
* @return the definition, not null
*/
public static FXForwardCurveDefinition of(final String name, final UnorderedCurrencyPair target, final List<Tenor> tenors) {
return new FXForwardCurveDefinition(name, target, tenors);
}
//-------------------------------------------------------------------------
/**
* Gets the tenors as an array.
*
* @return the array of tenors, not null
*/
public Tenor[] getTenorsArray() {
return _tenors.toArray(new Tenor[_tenors.size()]);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code FXForwardCurveDefinition}.
* @return the meta-bean, not null
*/
public static FXForwardCurveDefinition.Meta meta() {
return FXForwardCurveDefinition.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(FXForwardCurveDefinition.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static FXForwardCurveDefinition.Builder builder() {
return new FXForwardCurveDefinition.Builder();
}
private FXForwardCurveDefinition(
String name,
UnorderedCurrencyPair target,
List<Tenor> tenors) {
JodaBeanUtils.notNull(name, "name");
JodaBeanUtils.notNull(target, "target");
JodaBeanUtils.notNull(tenors, "tenors");
this._name = name;
this._target = target;
this._tenors = ImmutableList.copyOf(tenors);
}
@Override
public FXForwardCurveDefinition.Meta metaBean() {
return FXForwardCurveDefinition.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 curve name.
* @return the value of the property, not null
*/
public String getName() {
return _name;
}
//-----------------------------------------------------------------------
/**
* Gets the target currency pair.
* @return the value of the property, not null
*/
public UnorderedCurrencyPair getTarget() {
return _target;
}
//-----------------------------------------------------------------------
/**
* Gets the tenors.
* @return the value of the property, not null
*/
public ImmutableList<Tenor> getTenors() {
return _tenors;
}
//-----------------------------------------------------------------------
/**
* Returns a builder that allows this bean to be mutated.
* @return the mutable builder, not null
*/
public Builder toBuilder() {
return new Builder(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
FXForwardCurveDefinition other = (FXForwardCurveDefinition) obj;
return JodaBeanUtils.equal(getName(), other.getName()) &&
JodaBeanUtils.equal(getTarget(), other.getTarget()) &&
JodaBeanUtils.equal(getTenors(), other.getTenors());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getName());
hash = hash * 31 + JodaBeanUtils.hashCode(getTarget());
hash = hash * 31 + JodaBeanUtils.hashCode(getTenors());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("FXForwardCurveDefinition{");
buf.append("name").append('=').append(getName()).append(',').append(' ');
buf.append("target").append('=').append(getTarget()).append(',').append(' ');
buf.append("tenors").append('=').append(JodaBeanUtils.toString(getTenors()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code FXForwardCurveDefinition}.
*/
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", FXForwardCurveDefinition.class, String.class);
/**
* The meta-property for the {@code target} property.
*/
private final MetaProperty<UnorderedCurrencyPair> _target = DirectMetaProperty.ofImmutable(
this, "target", FXForwardCurveDefinition.class, UnorderedCurrencyPair.class);
/**
* The meta-property for the {@code tenors} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<ImmutableList<Tenor>> _tenors = DirectMetaProperty.ofImmutable(
this, "tenors", FXForwardCurveDefinition.class, (Class) ImmutableList.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"name",
"target",
"tenors");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 3373707: // name
return _name;
case -880905839: // target
return _target;
case -877322829: // tenors
return _tenors;
}
return super.metaPropertyGet(propertyName);
}
@Override
public FXForwardCurveDefinition.Builder builder() {
return new FXForwardCurveDefinition.Builder();
}
@Override
public Class<? extends FXForwardCurveDefinition> beanType() {
return FXForwardCurveDefinition.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 target} property.
* @return the meta-property, not null
*/
public MetaProperty<UnorderedCurrencyPair> target() {
return _target;
}
/**
* The meta-property for the {@code tenors} property.
* @return the meta-property, not null
*/
public MetaProperty<ImmutableList<Tenor>> tenors() {
return _tenors;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 3373707: // name
return ((FXForwardCurveDefinition) bean).getName();
case -880905839: // target
return ((FXForwardCurveDefinition) bean).getTarget();
case -877322829: // tenors
return ((FXForwardCurveDefinition) bean).getTenors();
}
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 FXForwardCurveDefinition}.
*/
public static final class Builder extends DirectFieldsBeanBuilder<FXForwardCurveDefinition> {
private String _name;
private UnorderedCurrencyPair _target;
private List<Tenor> _tenors = new ArrayList<Tenor>();
/**
* Restricted constructor.
*/
private Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(FXForwardCurveDefinition beanToCopy) {
this._name = beanToCopy.getName();
this._target = beanToCopy.getTarget();
this._tenors = new ArrayList<Tenor>(beanToCopy.getTenors());
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 3373707: // name
return _name;
case -880905839: // target
return _target;
case -877322829: // tenors
return _tenors;
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 -880905839: // target
this._target = (UnorderedCurrencyPair) newValue;
break;
case -877322829: // tenors
this._tenors = (List<Tenor>) 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 FXForwardCurveDefinition build() {
return new FXForwardCurveDefinition(
_name,
_target,
_tenors);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code name} property in the builder.
* @param name the new value, not null
* @return this, for chaining, not null
*/
public Builder name(String name) {
JodaBeanUtils.notNull(name, "name");
this._name = name;
return this;
}
/**
* Sets the {@code target} property in the builder.
* @param target the new value, not null
* @return this, for chaining, not null
*/
public Builder target(UnorderedCurrencyPair target) {
JodaBeanUtils.notNull(target, "target");
this._target = target;
return this;
}
/**
* Sets the {@code tenors} property in the builder.
* @param tenors the new value, not null
* @return this, for chaining, not null
*/
public Builder tenors(List<Tenor> tenors) {
JodaBeanUtils.notNull(tenors, "tenors");
this._tenors = tenors;
return this;
}
/**
* Sets the {@code tenors} property in the builder
* from an array of objects.
* @param tenors the new value, not null
* @return this, for chaining, not null
*/
public Builder tenors(Tenor... tenors) {
return tenors(Arrays.asList(tenors));
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(128);
buf.append("FXForwardCurveDefinition.Builder{");
buf.append("name").append('=').append(JodaBeanUtils.toString(_name)).append(',').append(' ');
buf.append("target").append('=').append(JodaBeanUtils.toString(_target)).append(',').append(' ');
buf.append("tenors").append('=').append(JodaBeanUtils.toString(_tenors));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}