com.opengamma.sdk.margin.TradeSensitivity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-margin Show documentation
Show all versions of sdk-margin Show documentation
OpenGamma SDK - Provides access to the Margin service
/*
* Copyright (C) 2018 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sdk.margin;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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;
/**
* The sensitivity of a single trade in the portfolio to one or more curves.
*/
@BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of")
public final class TradeSensitivity implements ImmutableBean {
/**
* The total sensitivity, calculated as the sum of all the curves, expressed in the reporting currency.
*/
@PropertyDefinition
private final double sensitivity;
/**
* The list of curve sensitivities.
*/
@PropertyDefinition(validate = "notNull")
private final List curveSensitivity;
//------------------------- AUTOGENERATED START -------------------------
/**
* The meta-bean for {@code TradeSensitivity}.
* @return the meta-bean, not null
*/
public static MetaBean meta() {
return TradeSensitivity.Meta.INSTANCE;
}
static {
MetaBean.register(TradeSensitivity.Meta.INSTANCE);
}
/**
* Obtains an instance.
* @param sensitivity the value of the property
* @param curveSensitivity the value of the property, not null
* @return the instance
*/
public static TradeSensitivity of(
double sensitivity,
List curveSensitivity) {
return new TradeSensitivity(
sensitivity,
curveSensitivity);
}
private TradeSensitivity(
double sensitivity,
List curveSensitivity) {
JodaBeanUtils.notNull(curveSensitivity, "curveSensitivity");
this.sensitivity = sensitivity;
this.curveSensitivity = Collections.unmodifiableList(new ArrayList<>(curveSensitivity));
}
@Override
public MetaBean metaBean() {
return TradeSensitivity.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the total sensitivity, calculated as the sum of all the curves, expressed in the reporting currency.
* @return the value of the property
*/
public double getSensitivity() {
return sensitivity;
}
//-----------------------------------------------------------------------
/**
* Gets the list of curve sensitivities.
* @return the value of the property, not null
*/
public List getCurveSensitivity() {
return curveSensitivity;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
TradeSensitivity other = (TradeSensitivity) obj;
return JodaBeanUtils.equal(sensitivity, other.sensitivity) &&
JodaBeanUtils.equal(curveSensitivity, other.curveSensitivity);
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(sensitivity);
hash = hash * 31 + JodaBeanUtils.hashCode(curveSensitivity);
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("TradeSensitivity{");
buf.append("sensitivity").append('=').append(sensitivity).append(',').append(' ');
buf.append("curveSensitivity").append('=').append(JodaBeanUtils.toString(curveSensitivity));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code TradeSensitivity}.
*/
private 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 sensitivity} property.
*/
private final MetaProperty sensitivity = DirectMetaProperty.ofImmutable(
this, "sensitivity", TradeSensitivity.class, Double.TYPE);
/**
* The meta-property for the {@code curveSensitivity} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty> curveSensitivity = DirectMetaProperty.ofImmutable(
this, "curveSensitivity", TradeSensitivity.class, (Class) List.class);
/**
* The meta-properties.
*/
private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"sensitivity",
"curveSensitivity");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 564403871: // sensitivity
return sensitivity;
case 1610426928: // curveSensitivity
return curveSensitivity;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder extends TradeSensitivity> builder() {
return new TradeSensitivity.Builder();
}
@Override
public Class extends TradeSensitivity> beanType() {
return TradeSensitivity.class;
}
@Override
public Map> metaPropertyMap() {
return metaPropertyMap$;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 564403871: // sensitivity
return ((TradeSensitivity) bean).getSensitivity();
case 1610426928: // curveSensitivity
return ((TradeSensitivity) bean).getCurveSensitivity();
}
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 TradeSensitivity}.
*/
private static final class Builder extends DirectPrivateBeanBuilder {
private double sensitivity;
private List curveSensitivity = Collections.emptyList();
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 564403871: // sensitivity
return sensitivity;
case 1610426928: // curveSensitivity
return curveSensitivity;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@SuppressWarnings("unchecked")
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 564403871: // sensitivity
this.sensitivity = (Double) newValue;
break;
case 1610426928: // curveSensitivity
this.curveSensitivity = (List) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public TradeSensitivity build() {
return new TradeSensitivity(
sensitivity,
curveSensitivity);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("TradeSensitivity.Builder{");
buf.append("sensitivity").append('=').append(JodaBeanUtils.toString(sensitivity)).append(',').append(' ');
buf.append("curveSensitivity").append('=').append(JodaBeanUtils.toString(curveSensitivity));
buf.append('}');
return buf.toString();
}
}
//-------------------------- AUTOGENERATED END --------------------------
}