/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.analytics.volatility.cube;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
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.id.UniqueId;
import com.opengamma.id.UniqueIdentifiable;
import com.opengamma.util.tuple.Triple;
/**
* Hold the valid range of X, Y and Z for a cube.
* @param <X> Type of the x-data
* @param <Y> Type of the y-data
* @param <Z> Type of the z-data
*/
@Config(description = "Volatility cube definition", group = ConfigGroups.VOL)
@BeanDefinition
public class VolatilityCubeDefinition<X, Y, Z> implements Bean, Serializable, UniqueIdentifiable {
/** Serialization version */
private static final long serialVersionUID = 1L;
/**
* The unique id.
*/
@PropertyDefinition
private UniqueId _uniqueId;
/**
* The definition name.
*/
@PropertyDefinition(validate = "notNull")
private String _name;
/**
* The cube quote type.
*/
@PropertyDefinition(validate = "notNull")
private String _cubeQuoteType;
/**
* The x values.
*/
@PropertyDefinition(validate = "notNull")
private X[] _xs;
/**
* The y values.
*/
@PropertyDefinition(validate = "notNull")
private Y[] _ys;
/**
* The z values.
*/
@PropertyDefinition(validate = "notNull")
private Z[] _zs;
/**
* For the builder.
*/
/* package */ VolatilityCubeDefinition() {
}
/**
* @param name The definition name, not null
* @param cubeQuoteType The cube quote type, not null
* @param xs The x values, not null
* @param ys The y values, not null
* @param zs The z values, not null
*/
public VolatilityCubeDefinition(final String name, final String cubeQuoteType, final X[] xs, final Y[] ys, final Z[] zs) {
setName(name);
setCubeQuoteType(cubeQuoteType);
setXs(xs);
setYs(ys);
setZs(zs);
}
/**
* Gets an iterator over all points in the definition.
* @return The iterator
*/
public Iterable<Triple<X, Y, Z>> getAllPoints() {
final Iterator<Triple<X, Y, Z>> iterator = new Iterator<Triple<X, Y, Z>>() {
private int _idx;
@Override
public synchronized boolean hasNext() {
return _idx < _xs.length;
}
@Override
public synchronized Triple<X, Y, Z> next() {
final int idx = _idx++;
return Triple.of(_xs[idx], _ys[idx], _zs[idx]);
}
@Override
public void remove() {
throw new UnsupportedOperationException("This iterator is immutable.");
}
};
return new Iterable<Triple<X, Y, Z>>() {
@Override
public Iterator<Triple<X, Y, Z>> iterator() {
return iterator;
}
};
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code VolatilityCubeDefinition}.
* @return the meta-bean, not null
*/
@SuppressWarnings("rawtypes")
public static VolatilityCubeDefinition.Meta meta() {
return VolatilityCubeDefinition.Meta.INSTANCE;
}
/**
* The meta-bean for {@code VolatilityCubeDefinition}.
* @param <R> the first generic type
* @param <S> the second generic type
* @param <T> the second generic type
* @param cls1 the first generic type
* @param cls2 the second generic type
* @param cls3 the third generic type
* @return the meta-bean, not null
*/
@SuppressWarnings("unchecked")
public static <R, S, T> VolatilityCubeDefinition.Meta<R, S, T> metaVolatilityCubeDefinition(Class<R> cls1, Class<S> cls2, Class<T> cls3) {
return VolatilityCubeDefinition.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(VolatilityCubeDefinition.Meta.INSTANCE);
}
@SuppressWarnings("unchecked")
@Override
public VolatilityCubeDefinition.Meta<X, Y, Z> metaBean() {
return VolatilityCubeDefinition.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 unique id.
* @return the value of the property
*/
public UniqueId getUniqueId() {
return _uniqueId;
}
/**
* Sets the unique id.
* @param uniqueId the new value of the property
*/
public void setUniqueId(UniqueId uniqueId) {
this._uniqueId = uniqueId;
}
/**
* Gets the the {@code uniqueId} property.
* @return the property, not null
*/
public final Property<UniqueId> uniqueId() {
return metaBean().uniqueId().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the definition name.
* @return the value of the property, not null
*/
public String getName() {
return _name;
}
/**
* Sets the definition name.
* @param name the new value of the property, not null
*/
public void setName(String name) {
JodaBeanUtils.notNull(name, "name");
this._name = name;
}
/**
* Gets the the {@code name} property.
* @return the property, not null
*/
public final Property<String> name() {
return metaBean().name().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the cube quote type.
* @return the value of the property, not null
*/
public String getCubeQuoteType() {
return _cubeQuoteType;
}
/**
* Sets the cube quote type.
* @param cubeQuoteType the new value of the property, not null
*/
public void setCubeQuoteType(String cubeQuoteType) {
JodaBeanUtils.notNull(cubeQuoteType, "cubeQuoteType");
this._cubeQuoteType = cubeQuoteType;
}
/**
* Gets the the {@code cubeQuoteType} property.
* @return the property, not null
*/
public final Property<String> cubeQuoteType() {
return metaBean().cubeQuoteType().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the x values.
* @return the value of the property, not null
*/
public X[] getXs() {
return _xs;
}
/**
* Sets the x values.
* @param xs the new value of the property, not null
*/
public void setXs(X[] xs) {
JodaBeanUtils.notNull(xs, "xs");
this._xs = xs;
}
/**
* Gets the the {@code xs} property.
* @return the property, not null
*/
public final Property<X[]> xs() {
return metaBean().xs().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the y values.
* @return the value of the property, not null
*/
public Y[] getYs() {
return _ys;
}
/**
* Sets the y values.
* @param ys the new value of the property, not null
*/
public void setYs(Y[] ys) {
JodaBeanUtils.notNull(ys, "ys");
this._ys = ys;
}
/**
* Gets the the {@code ys} property.
* @return the property, not null
*/
public final Property<Y[]> ys() {
return metaBean().ys().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the z values.
* @return the value of the property, not null
*/
public Z[] getZs() {
return _zs;
}
/**
* Sets the z values.
* @param zs the new value of the property, not null
*/
public void setZs(Z[] zs) {
JodaBeanUtils.notNull(zs, "zs");
this._zs = zs;
}
/**
* Gets the the {@code zs} property.
* @return the property, not null
*/
public final Property<Z[]> zs() {
return metaBean().zs().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public VolatilityCubeDefinition<X, Y, Z> clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
VolatilityCubeDefinition<?, ?, ?> other = (VolatilityCubeDefinition<?, ?, ?>) obj;
return JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) &&
JodaBeanUtils.equal(getName(), other.getName()) &&
JodaBeanUtils.equal(getCubeQuoteType(), other.getCubeQuoteType()) &&
JodaBeanUtils.equal(getXs(), other.getXs()) &&
JodaBeanUtils.equal(getYs(), other.getYs()) &&
JodaBeanUtils.equal(getZs(), other.getZs());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getUniqueId());
hash = hash * 31 + JodaBeanUtils.hashCode(getName());
hash = hash * 31 + JodaBeanUtils.hashCode(getCubeQuoteType());
hash = hash * 31 + JodaBeanUtils.hashCode(getXs());
hash = hash * 31 + JodaBeanUtils.hashCode(getYs());
hash = hash * 31 + JodaBeanUtils.hashCode(getZs());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(224);
buf.append("VolatilityCubeDefinition{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
protected void toString(StringBuilder buf) {
buf.append("uniqueId").append('=').append(JodaBeanUtils.toString(getUniqueId())).append(',').append(' ');
buf.append("name").append('=').append(JodaBeanUtils.toString(getName())).append(',').append(' ');
buf.append("cubeQuoteType").append('=').append(JodaBeanUtils.toString(getCubeQuoteType())).append(',').append(' ');
buf.append("xs").append('=').append(JodaBeanUtils.toString(getXs())).append(',').append(' ');
buf.append("ys").append('=').append(JodaBeanUtils.toString(getYs())).append(',').append(' ');
buf.append("zs").append('=').append(JodaBeanUtils.toString(getZs())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code VolatilityCubeDefinition}.
* @param <X> the type
* @param <Y> the type
* @param <Z> the type
*/
public static class Meta<X, Y, Z> extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
@SuppressWarnings("rawtypes")
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code uniqueId} property.
*/
private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofReadWrite(
this, "uniqueId", VolatilityCubeDefinition.class, UniqueId.class);
/**
* The meta-property for the {@code name} property.
*/
private final MetaProperty<String> _name = DirectMetaProperty.ofReadWrite(
this, "name", VolatilityCubeDefinition.class, String.class);
/**
* The meta-property for the {@code cubeQuoteType} property.
*/
private final MetaProperty<String> _cubeQuoteType = DirectMetaProperty.ofReadWrite(
this, "cubeQuoteType", VolatilityCubeDefinition.class, String.class);
/**
* The meta-property for the {@code xs} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<X[]> _xs = (DirectMetaProperty) DirectMetaProperty.ofReadWrite(
this, "xs", VolatilityCubeDefinition.class, Object[].class);
/**
* The meta-property for the {@code ys} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<Y[]> _ys = (DirectMetaProperty) DirectMetaProperty.ofReadWrite(
this, "ys", VolatilityCubeDefinition.class, Object[].class);
/**
* The meta-property for the {@code zs} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<Z[]> _zs = (DirectMetaProperty) DirectMetaProperty.ofReadWrite(
this, "zs", VolatilityCubeDefinition.class, Object[].class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"uniqueId",
"name",
"cubeQuoteType",
"xs",
"ys",
"zs");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return _uniqueId;
case 3373707: // name
return _name;
case 1081076513: // cubeQuoteType
return _cubeQuoteType;
case 3835: // xs
return _xs;
case 3866: // ys
return _ys;
case 3897: // zs
return _zs;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends VolatilityCubeDefinition<X, Y, Z>> builder() {
return new DirectBeanBuilder<VolatilityCubeDefinition<X, Y, Z>>(new VolatilityCubeDefinition<X, Y, Z>());
}
@SuppressWarnings({"unchecked", "rawtypes" })
@Override
public Class<? extends VolatilityCubeDefinition<X, Y, Z>> beanType() {
return (Class) VolatilityCubeDefinition.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code uniqueId} property.
* @return the meta-property, not null
*/
public final MetaProperty<UniqueId> uniqueId() {
return _uniqueId;
}
/**
* The meta-property for the {@code name} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> name() {
return _name;
}
/**
* The meta-property for the {@code cubeQuoteType} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> cubeQuoteType() {
return _cubeQuoteType;
}
/**
* The meta-property for the {@code xs} property.
* @return the meta-property, not null
*/
public final MetaProperty<X[]> xs() {
return _xs;
}
/**
* The meta-property for the {@code ys} property.
* @return the meta-property, not null
*/
public final MetaProperty<Y[]> ys() {
return _ys;
}
/**
* The meta-property for the {@code zs} property.
* @return the meta-property, not null
*/
public final MetaProperty<Z[]> zs() {
return _zs;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getUniqueId();
case 3373707: // name
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getName();
case 1081076513: // cubeQuoteType
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getCubeQuoteType();
case 3835: // xs
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getXs();
case 3866: // ys
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getYs();
case 3897: // zs
return ((VolatilityCubeDefinition<?, ?, ?>) bean).getZs();
}
return super.propertyGet(bean, propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -294460212: // uniqueId
((VolatilityCubeDefinition<X, Y, Z>) bean).setUniqueId((UniqueId) newValue);
return;
case 3373707: // name
((VolatilityCubeDefinition<X, Y, Z>) bean).setName((String) newValue);
return;
case 1081076513: // cubeQuoteType
((VolatilityCubeDefinition<X, Y, Z>) bean).setCubeQuoteType((String) newValue);
return;
case 3835: // xs
((VolatilityCubeDefinition<X, Y, Z>) bean).setXs((X[]) newValue);
return;
case 3866: // ys
((VolatilityCubeDefinition<X, Y, Z>) bean).setYs((Y[]) newValue);
return;
case 3897: // zs
((VolatilityCubeDefinition<X, Y, Z>) bean).setZs((Z[]) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((VolatilityCubeDefinition<?, ?, ?>) bean)._name, "name");
JodaBeanUtils.notNull(((VolatilityCubeDefinition<?, ?, ?>) bean)._cubeQuoteType, "cubeQuoteType");
JodaBeanUtils.notNull(((VolatilityCubeDefinition<?, ?, ?>) bean)._xs, "xs");
JodaBeanUtils.notNull(((VolatilityCubeDefinition<?, ?, ?>) bean)._ys, "ys");
JodaBeanUtils.notNull(((VolatilityCubeDefinition<?, ?, ?>) bean)._zs, "zs");
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}