All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.sdk.margin.TradeValuation Maven / Gradle / Ivy

There is a newer version: 3.6.4
Show newest version
/*
 * 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.Map;
import java.util.NoSuchElementException;
import java.util.Optional;

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 valuation of a single trade in the portfolio.
 */
@BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of")
public final class TradeValuation implements ImmutableBean {

  /**
   * The trade identifier, empty if not known.
   */
  @PropertyDefinition(validate = "notNull")
  private final String tradeId;
  /**
   * The value of the trade, in the trade currency.
   */
  @PropertyDefinition(get = "optional")
  private final TradeValue value;
  /**
   * The delta of the trade.
   */
  @PropertyDefinition(get = "optional")
  private final TradeSensitivity delta;
  /**
   * The gamma of the trade.
   */
  @PropertyDefinition(get = "optional")
  private final TradeSensitivity gamma;

  //------------------------- AUTOGENERATED START -------------------------
  /**
   * The meta-bean for {@code TradeValuation}.
   * @return the meta-bean, not null
   */
  public static MetaBean meta() {
    return TradeValuation.Meta.INSTANCE;
  }

  static {
    MetaBean.register(TradeValuation.Meta.INSTANCE);
  }

  /**
   * Obtains an instance.
   * @param tradeId  the value of the property, not null
   * @param value  the value of the property
   * @param delta  the value of the property
   * @param gamma  the value of the property
   * @return the instance
   */
  public static TradeValuation of(
      String tradeId,
      TradeValue value,
      TradeSensitivity delta,
      TradeSensitivity gamma) {
    return new TradeValuation(
      tradeId,
      value,
      delta,
      gamma);
  }

  private TradeValuation(
      String tradeId,
      TradeValue value,
      TradeSensitivity delta,
      TradeSensitivity gamma) {
    JodaBeanUtils.notNull(tradeId, "tradeId");
    this.tradeId = tradeId;
    this.value = value;
    this.delta = delta;
    this.gamma = gamma;
  }

  @Override
  public MetaBean metaBean() {
    return TradeValuation.Meta.INSTANCE;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the trade identifier, empty if not known.
   * @return the value of the property, not null
   */
  public String getTradeId() {
    return tradeId;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the value of the trade, in the trade currency.
   * @return the optional value of the property, not null
   */
  public Optional getValue() {
    return Optional.ofNullable(value);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the delta of the trade.
   * @return the optional value of the property, not null
   */
  public Optional getDelta() {
    return Optional.ofNullable(delta);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the gamma of the trade.
   * @return the optional value of the property, not null
   */
  public Optional getGamma() {
    return Optional.ofNullable(gamma);
  }

  //-----------------------------------------------------------------------
  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      TradeValuation other = (TradeValuation) obj;
      return JodaBeanUtils.equal(tradeId, other.tradeId) &&
          JodaBeanUtils.equal(value, other.value) &&
          JodaBeanUtils.equal(delta, other.delta) &&
          JodaBeanUtils.equal(gamma, other.gamma);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash = hash * 31 + JodaBeanUtils.hashCode(tradeId);
    hash = hash * 31 + JodaBeanUtils.hashCode(value);
    hash = hash * 31 + JodaBeanUtils.hashCode(delta);
    hash = hash * 31 + JodaBeanUtils.hashCode(gamma);
    return hash;
  }

  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder(160);
    buf.append("TradeValuation{");
    buf.append("tradeId").append('=').append(tradeId).append(',').append(' ');
    buf.append("value").append('=').append(value).append(',').append(' ');
    buf.append("delta").append('=').append(delta).append(',').append(' ');
    buf.append("gamma").append('=').append(JodaBeanUtils.toString(gamma));
    buf.append('}');
    return buf.toString();
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code TradeValuation}.
   */
  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 tradeId} property.
     */
    private final MetaProperty tradeId = DirectMetaProperty.ofImmutable(
        this, "tradeId", TradeValuation.class, String.class);
    /**
     * The meta-property for the {@code value} property.
     */
    private final MetaProperty value = DirectMetaProperty.ofImmutable(
        this, "value", TradeValuation.class, TradeValue.class);
    /**
     * The meta-property for the {@code delta} property.
     */
    private final MetaProperty delta = DirectMetaProperty.ofImmutable(
        this, "delta", TradeValuation.class, TradeSensitivity.class);
    /**
     * The meta-property for the {@code gamma} property.
     */
    private final MetaProperty gamma = DirectMetaProperty.ofImmutable(
        this, "gamma", TradeValuation.class, TradeSensitivity.class);
    /**
     * The meta-properties.
     */
    private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
        this, null,
        "tradeId",
        "value",
        "delta",
        "gamma");

    /**
     * Restricted constructor.
     */
    private Meta() {
    }

    @Override
    protected MetaProperty metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case -1067372129:  // tradeId
          return tradeId;
        case 111972721:  // value
          return value;
        case 95468472:  // delta
          return delta;
        case 98120615:  // gamma
          return gamma;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder builder() {
      return new TradeValuation.Builder();
    }

    @Override
    public Class beanType() {
      return TradeValuation.class;
    }

    @Override
    public Map> metaPropertyMap() {
      return metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    @Override
    protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
      switch (propertyName.hashCode()) {
        case -1067372129:  // tradeId
          return ((TradeValuation) bean).getTradeId();
        case 111972721:  // value
          return ((TradeValuation) bean).value;
        case 95468472:  // delta
          return ((TradeValuation) bean).delta;
        case 98120615:  // gamma
          return ((TradeValuation) bean).gamma;
      }
      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 TradeValuation}.
   */
  private static final class Builder extends DirectPrivateBeanBuilder {

    private String tradeId;
    private TradeValue value;
    private TradeSensitivity delta;
    private TradeSensitivity gamma;

    /**
     * Restricted constructor.
     */
    private Builder() {
    }

    //-----------------------------------------------------------------------
    @Override
    public Object get(String propertyName) {
      switch (propertyName.hashCode()) {
        case -1067372129:  // tradeId
          return tradeId;
        case 111972721:  // value
          return value;
        case 95468472:  // delta
          return delta;
        case 98120615:  // gamma
          return gamma;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
    }

    @Override
    public Builder set(String propertyName, Object newValue) {
      switch (propertyName.hashCode()) {
        case -1067372129:  // tradeId
          this.tradeId = (String) newValue;
          break;
        case 111972721:  // value
          this.value = (TradeValue) newValue;
          break;
        case 95468472:  // delta
          this.delta = (TradeSensitivity) newValue;
          break;
        case 98120615:  // gamma
          this.gamma = (TradeSensitivity) newValue;
          break;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
      return this;
    }

    @Override
    public TradeValuation build() {
      return new TradeValuation(
          tradeId,
          value,
          delta,
          gamma);
    }

    //-----------------------------------------------------------------------
    @Override
    public String toString() {
      StringBuilder buf = new StringBuilder(160);
      buf.append("TradeValuation.Builder{");
      buf.append("tradeId").append('=').append(JodaBeanUtils.toString(tradeId)).append(',').append(' ');
      buf.append("value").append('=').append(JodaBeanUtils.toString(value)).append(',').append(' ');
      buf.append("delta").append('=').append(JodaBeanUtils.toString(delta)).append(',').append(' ');
      buf.append("gamma").append('=').append(JodaBeanUtils.toString(gamma));
      buf.append('}');
      return buf.toString();
    }

  }

  //-------------------------- AUTOGENERATED END --------------------------
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy