/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sesame.marketdata.scenarios;
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;
/**
* A perturbation that transforms an item of market data with a filter that decides what data it applies to.
*/
@BeanDefinition
public final class SinglePerturbationMapping implements ImmutableBean {
/** A rule or set of rules to decide whether a {@link Perturbation} applies to a piece of market data. */
@PropertyDefinition(validate = "notNull")
private final MarketDataFilter _filter;
/** A perturbation applied to a single piece of data as part of a scenario. */
@PropertyDefinition(validate = "notNull")
private final Perturbation _perturbation;
/**
* Returns a mapping containing the specified filter and perturbation.
*
* @return a mapping containing the specified filter and perturbation
*/
public static SinglePerturbationMapping of(MarketDataFilter filter, Perturbation perturbation) {
return new SinglePerturbationMapping(filter, perturbation);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code SinglePerturbationMapping}.
* @return the meta-bean, not null
*/
public static SinglePerturbationMapping.Meta meta() {
return SinglePerturbationMapping.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(SinglePerturbationMapping.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static SinglePerturbationMapping.Builder builder() {
return new SinglePerturbationMapping.Builder();
}
private SinglePerturbationMapping(
MarketDataFilter filter,
Perturbation perturbation) {
JodaBeanUtils.notNull(filter, "filter");
JodaBeanUtils.notNull(perturbation, "perturbation");
this._filter = filter;
this._perturbation = perturbation;
}
@Override
public SinglePerturbationMapping.Meta metaBean() {
return SinglePerturbationMapping.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 a rule or set of rules to decide whether a {@link Perturbation} applies to a piece of market data.
* @return the value of the property, not null
*/
public MarketDataFilter getFilter() {
return _filter;
}
//-----------------------------------------------------------------------
/**
* Gets a perturbation applied to a single piece of data as part of a scenario.
* @return the value of the property, not null
*/
public Perturbation getPerturbation() {
return _perturbation;
}
//-----------------------------------------------------------------------
/**
* 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()) {
SinglePerturbationMapping other = (SinglePerturbationMapping) obj;
return JodaBeanUtils.equal(getFilter(), other.getFilter()) &&
JodaBeanUtils.equal(getPerturbation(), other.getPerturbation());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getFilter());
hash = hash * 31 + JodaBeanUtils.hashCode(getPerturbation());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("SinglePerturbationMapping{");
buf.append("filter").append('=').append(getFilter()).append(',').append(' ');
buf.append("perturbation").append('=').append(JodaBeanUtils.toString(getPerturbation()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code SinglePerturbationMapping}.
*/
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 filter} property.
*/
private final MetaProperty<MarketDataFilter> _filter = DirectMetaProperty.ofImmutable(
this, "filter", SinglePerturbationMapping.class, MarketDataFilter.class);
/**
* The meta-property for the {@code perturbation} property.
*/
private final MetaProperty<Perturbation> _perturbation = DirectMetaProperty.ofImmutable(
this, "perturbation", SinglePerturbationMapping.class, Perturbation.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"filter",
"perturbation");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1274492040: // filter
return _filter;
case -924739417: // perturbation
return _perturbation;
}
return super.metaPropertyGet(propertyName);
}
@Override
public SinglePerturbationMapping.Builder builder() {
return new SinglePerturbationMapping.Builder();
}
@Override
public Class<? extends SinglePerturbationMapping> beanType() {
return SinglePerturbationMapping.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code filter} property.
* @return the meta-property, not null
*/
public MetaProperty<MarketDataFilter> filter() {
return _filter;
}
/**
* The meta-property for the {@code perturbation} property.
* @return the meta-property, not null
*/
public MetaProperty<Perturbation> perturbation() {
return _perturbation;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1274492040: // filter
return ((SinglePerturbationMapping) bean).getFilter();
case -924739417: // perturbation
return ((SinglePerturbationMapping) bean).getPerturbation();
}
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 SinglePerturbationMapping}.
*/
public static final class Builder extends DirectFieldsBeanBuilder<SinglePerturbationMapping> {
private MarketDataFilter _filter;
private Perturbation _perturbation;
/**
* Restricted constructor.
*/
private Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
private Builder(SinglePerturbationMapping beanToCopy) {
this._filter = beanToCopy.getFilter();
this._perturbation = beanToCopy.getPerturbation();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case -1274492040: // filter
return _filter;
case -924739417: // perturbation
return _perturbation;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case -1274492040: // filter
this._filter = (MarketDataFilter) newValue;
break;
case -924739417: // perturbation
this._perturbation = (Perturbation) 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 SinglePerturbationMapping build() {
return new SinglePerturbationMapping(
_filter,
_perturbation);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code filter} property in the builder.
* @param filter the new value, not null
* @return this, for chaining, not null
*/
public Builder filter(MarketDataFilter filter) {
JodaBeanUtils.notNull(filter, "filter");
this._filter = filter;
return this;
}
/**
* Sets the {@code perturbation} property in the builder.
* @param perturbation the new value, not null
* @return this, for chaining, not null
*/
public Builder perturbation(Perturbation perturbation) {
JodaBeanUtils.notNull(perturbation, "perturbation");
this._perturbation = perturbation;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("SinglePerturbationMapping.Builder{");
buf.append("filter").append('=').append(JodaBeanUtils.toString(_filter)).append(',').append(' ');
buf.append("perturbation").append('=').append(JodaBeanUtils.toString(_perturbation));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}