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

com.opengamma.sdk.margin.LchMarginIndex 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.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;

/**
 * A breakdown of the margin calculation at the index level.
 */
@BeanDefinition(builderScope = "private", metaScope = "private", factoryName = "of")
public final class LchMarginIndex implements ImmutableBean {

  /**
   * The index name.
   */
  @PropertyDefinition(validate = "notNull")
  private final String indexName;
  /**
   * The diversified base margin for the index, expressed in the reporting currency.
   */
  @PropertyDefinition
  private final double diversifiedBaseMargin;
  /**
   * The undiversified base margin for the index, expressed in the reporting currency.
   */
  @PropertyDefinition
  private final double undiversifiedBaseMargin;
  /**
   * The identifiers of the scenarios used to calculate margin for the index.
   * The scenarios can be accessed from {@link LchMarginDetail#findScenario(String)}.
   */
  @PropertyDefinition(validate = "notNull")
  private final List indexScenarioIds;

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

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

  /**
   * Obtains an instance.
   * @param indexName  the value of the property, not null
   * @param diversifiedBaseMargin  the value of the property
   * @param undiversifiedBaseMargin  the value of the property
   * @param indexScenarioIds  the value of the property, not null
   * @return the instance
   */
  public static LchMarginIndex of(
      String indexName,
      double diversifiedBaseMargin,
      double undiversifiedBaseMargin,
      List indexScenarioIds) {
    return new LchMarginIndex(
      indexName,
      diversifiedBaseMargin,
      undiversifiedBaseMargin,
      indexScenarioIds);
  }

  private LchMarginIndex(
      String indexName,
      double diversifiedBaseMargin,
      double undiversifiedBaseMargin,
      List indexScenarioIds) {
    JodaBeanUtils.notNull(indexName, "indexName");
    JodaBeanUtils.notNull(indexScenarioIds, "indexScenarioIds");
    this.indexName = indexName;
    this.diversifiedBaseMargin = diversifiedBaseMargin;
    this.undiversifiedBaseMargin = undiversifiedBaseMargin;
    this.indexScenarioIds = Collections.unmodifiableList(new ArrayList<>(indexScenarioIds));
  }

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

  //-----------------------------------------------------------------------
  /**
   * Gets the index name.
   * @return the value of the property, not null
   */
  public String getIndexName() {
    return indexName;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the diversified base margin for the index, expressed in the reporting currency.
   * @return the value of the property
   */
  public double getDiversifiedBaseMargin() {
    return diversifiedBaseMargin;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the undiversified base margin for the index, expressed in the reporting currency.
   * @return the value of the property
   */
  public double getUndiversifiedBaseMargin() {
    return undiversifiedBaseMargin;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the identifiers of the scenarios used to calculate margin for the index.
   * The scenarios can be accessed from {@link LchMarginDetail#findScenario(String)}.
   * @return the value of the property, not null
   */
  public List getIndexScenarioIds() {
    return indexScenarioIds;
  }

  //-----------------------------------------------------------------------
  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      LchMarginIndex other = (LchMarginIndex) obj;
      return JodaBeanUtils.equal(indexName, other.indexName) &&
          JodaBeanUtils.equal(diversifiedBaseMargin, other.diversifiedBaseMargin) &&
          JodaBeanUtils.equal(undiversifiedBaseMargin, other.undiversifiedBaseMargin) &&
          JodaBeanUtils.equal(indexScenarioIds, other.indexScenarioIds);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash = hash * 31 + JodaBeanUtils.hashCode(indexName);
    hash = hash * 31 + JodaBeanUtils.hashCode(diversifiedBaseMargin);
    hash = hash * 31 + JodaBeanUtils.hashCode(undiversifiedBaseMargin);
    hash = hash * 31 + JodaBeanUtils.hashCode(indexScenarioIds);
    return hash;
  }

  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder(160);
    buf.append("LchMarginIndex{");
    buf.append("indexName").append('=').append(indexName).append(',').append(' ');
    buf.append("diversifiedBaseMargin").append('=').append(diversifiedBaseMargin).append(',').append(' ');
    buf.append("undiversifiedBaseMargin").append('=').append(undiversifiedBaseMargin).append(',').append(' ');
    buf.append("indexScenarioIds").append('=').append(JodaBeanUtils.toString(indexScenarioIds));
    buf.append('}');
    return buf.toString();
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code LchMarginIndex}.
   */
  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 indexName} property.
     */
    private final MetaProperty indexName = DirectMetaProperty.ofImmutable(
        this, "indexName", LchMarginIndex.class, String.class);
    /**
     * The meta-property for the {@code diversifiedBaseMargin} property.
     */
    private final MetaProperty diversifiedBaseMargin = DirectMetaProperty.ofImmutable(
        this, "diversifiedBaseMargin", LchMarginIndex.class, Double.TYPE);
    /**
     * The meta-property for the {@code undiversifiedBaseMargin} property.
     */
    private final MetaProperty undiversifiedBaseMargin = DirectMetaProperty.ofImmutable(
        this, "undiversifiedBaseMargin", LchMarginIndex.class, Double.TYPE);
    /**
     * The meta-property for the {@code indexScenarioIds} property.
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    private final MetaProperty> indexScenarioIds = DirectMetaProperty.ofImmutable(
        this, "indexScenarioIds", LchMarginIndex.class, (Class) List.class);
    /**
     * The meta-properties.
     */
    private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
        this, null,
        "indexName",
        "diversifiedBaseMargin",
        "undiversifiedBaseMargin",
        "indexScenarioIds");

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

    @Override
    protected MetaProperty metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case -807707011:  // indexName
          return indexName;
        case -1581942027:  // diversifiedBaseMargin
          return diversifiedBaseMargin;
        case 1473689084:  // undiversifiedBaseMargin
          return undiversifiedBaseMargin;
        case -993826602:  // indexScenarioIds
          return indexScenarioIds;
      }
      return super.metaPropertyGet(propertyName);
    }

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

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

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

    //-----------------------------------------------------------------------
    @Override
    protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
      switch (propertyName.hashCode()) {
        case -807707011:  // indexName
          return ((LchMarginIndex) bean).getIndexName();
        case -1581942027:  // diversifiedBaseMargin
          return ((LchMarginIndex) bean).getDiversifiedBaseMargin();
        case 1473689084:  // undiversifiedBaseMargin
          return ((LchMarginIndex) bean).getUndiversifiedBaseMargin();
        case -993826602:  // indexScenarioIds
          return ((LchMarginIndex) bean).getIndexScenarioIds();
      }
      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 LchMarginIndex}.
   */
  private static final class Builder extends DirectPrivateBeanBuilder {

    private String indexName;
    private double diversifiedBaseMargin;
    private double undiversifiedBaseMargin;
    private List indexScenarioIds = Collections.emptyList();

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

    //-----------------------------------------------------------------------
    @Override
    public Object get(String propertyName) {
      switch (propertyName.hashCode()) {
        case -807707011:  // indexName
          return indexName;
        case -1581942027:  // diversifiedBaseMargin
          return diversifiedBaseMargin;
        case 1473689084:  // undiversifiedBaseMargin
          return undiversifiedBaseMargin;
        case -993826602:  // indexScenarioIds
          return indexScenarioIds;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
    }

    @SuppressWarnings("unchecked")
    @Override
    public Builder set(String propertyName, Object newValue) {
      switch (propertyName.hashCode()) {
        case -807707011:  // indexName
          this.indexName = (String) newValue;
          break;
        case -1581942027:  // diversifiedBaseMargin
          this.diversifiedBaseMargin = (Double) newValue;
          break;
        case 1473689084:  // undiversifiedBaseMargin
          this.undiversifiedBaseMargin = (Double) newValue;
          break;
        case -993826602:  // indexScenarioIds
          this.indexScenarioIds = (List) newValue;
          break;
        default:
          throw new NoSuchElementException("Unknown property: " + propertyName);
      }
      return this;
    }

    @Override
    public LchMarginIndex build() {
      return new LchMarginIndex(
          indexName,
          diversifiedBaseMargin,
          undiversifiedBaseMargin,
          indexScenarioIds);
    }

    //-----------------------------------------------------------------------
    @Override
    public String toString() {
      StringBuilder buf = new StringBuilder(160);
      buf.append("LchMarginIndex.Builder{");
      buf.append("indexName").append('=').append(JodaBeanUtils.toString(indexName)).append(',').append(' ');
      buf.append("diversifiedBaseMargin").append('=').append(JodaBeanUtils.toString(diversifiedBaseMargin)).append(',').append(' ');
      buf.append("undiversifiedBaseMargin").append('=').append(JodaBeanUtils.toString(undiversifiedBaseMargin)).append(',').append(' ');
      buf.append("indexScenarioIds").append('=').append(JodaBeanUtils.toString(indexScenarioIds));
      buf.append('}');
      return buf.toString();
    }

  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy