Package com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb

Source Code of com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb.SwapTrade

/**
* Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb;

import static com.google.common.base.Predicates.not;

import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;

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.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.threeten.bp.LocalDate;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.opengamma.integration.tool.portfolio.xml.v1_0.conversion.SwapTradeSecurityExtractor;
import com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb.SwapLeg.Direction;

@XmlRootElement
@BeanDefinition
public class SwapTrade extends Trade {

  @XmlElement(name = "effectiveDate", required = true)
  @PropertyDefinition
  private LocalDate _effectiveDate;

  @XmlElementWrapper(name = "legs")
  @XmlElements({
      @XmlElement(name = "floatingLeg", type = FloatingLeg.class),
      @XmlElement(name = "fixedLeg", type = FixedLeg.class),
  })
  @PropertyDefinition
  private List<SwapLeg> _swapLegs;

  @Override
  public boolean canBePositionAggregated() {
    return false;
  }

  @Override
  public SwapTradeSecurityExtractor getSecurityExtractor() {
    return new SwapTradeSecurityExtractor(this);
  }

  /**
   * Helper method for extracting the pay legs on a swap.
   * @return the pay legs for this trade
   */
  public Iterable<SwapLeg> getPayLegs() {
    return Iterables.filter(getSwapLegs(), new IsPayLegPredicate());
  }

  /**
   * Helper method for extracting the receive legs on a swap.
   * @return the receive legs for this trade
   */
  public Iterable<SwapLeg> getReceiveLegs() {
    return Iterables.filter(getSwapLegs(), not(new IsPayLegPredicate()));
  }

  private static final class IsPayLegPredicate implements Predicate<SwapLeg> {

    @Override
    public boolean apply(SwapLeg input) {
      return input.getDirection() == Direction.PAY;
    }

  }

  /**
   * Helper method for extracting the fixed legs on a swap.
   * @return the instances of {@link FixedLeg} on this swap.
   */
  public Iterable<FixedLeg> getFixedLegs() {
    return Iterables.filter(getSwapLegs(), FixedLeg.class);
  }

  /**
   * Helper method for extracting the floating legs on a swap.
   * @return the instances of {@link FloatingLeg} on this swap.
   */
  public Iterable<FloatingLeg> getFloatingLegs() {
    return Iterables.filter(getSwapLegs(), FloatingLeg.class);
  }

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

  static {
    JodaBeanUtils.registerMetaBean(SwapTrade.Meta.INSTANCE);
  }

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

  @Override
  protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
      case -930389515// effectiveDate
        return getEffectiveDate();
      case -318692264// swapLegs
        return getSwapLegs();
    }
    return super.propertyGet(propertyName, quiet);
  }

  @SuppressWarnings("unchecked")
  @Override
  protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
      case -930389515// effectiveDate
        setEffectiveDate((LocalDate) newValue);
        return;
      case -318692264// swapLegs
        setSwapLegs((List<SwapLeg>) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      SwapTrade other = (SwapTrade) obj;
      return JodaBeanUtils.equal(getEffectiveDate(), other.getEffectiveDate()) &&
          JodaBeanUtils.equal(getSwapLegs(), other.getSwapLegs()) &&
          super.equals(obj);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash += hash * 31 + JodaBeanUtils.hashCode(getEffectiveDate());
    hash += hash * 31 + JodaBeanUtils.hashCode(getSwapLegs());
    return hash ^ super.hashCode();
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the effectiveDate.
   * @return the value of the property
   */
  public LocalDate getEffectiveDate() {
    return _effectiveDate;
  }

  /**
   * Sets the effectiveDate.
   * @param effectiveDate  the new value of the property
   */
  public void setEffectiveDate(LocalDate effectiveDate) {
    this._effectiveDate = effectiveDate;
  }

  /**
   * Gets the the {@code effectiveDate} property.
   * @return the property, not null
   */
  public final Property<LocalDate> effectiveDate() {
    return metaBean().effectiveDate().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the swapLegs.
   * @return the value of the property
   */
  public List<SwapLeg> getSwapLegs() {
    return _swapLegs;
  }

  /**
   * Sets the swapLegs.
   * @param swapLegs  the new value of the property
   */
  public void setSwapLegs(List<SwapLeg> swapLegs) {
    this._swapLegs = swapLegs;
  }

  /**
   * Gets the the {@code swapLegs} property.
   * @return the property, not null
   */
  public final Property<List<SwapLeg>> swapLegs() {
    return metaBean().swapLegs().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code SwapTrade}.
   */
  public static class Meta extends Trade.Meta {
    /**
     * The singleton instance of the meta-bean.
     */
    static final Meta INSTANCE = new Meta();

    /**
     * The meta-property for the {@code effectiveDate} property.
     */
    private final MetaProperty<LocalDate> _effectiveDate = DirectMetaProperty.ofReadWrite(
        this, "effectiveDate", SwapTrade.class, LocalDate.class);
    /**
     * The meta-property for the {@code swapLegs} property.
     */
    @SuppressWarnings({"unchecked", "rawtypes" })
    private final MetaProperty<List<SwapLeg>> _swapLegs = DirectMetaProperty.ofReadWrite(
        this, "swapLegs", SwapTrade.class, (Class) List.class);
    /**
     * The meta-properties.
     */
    private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
        this, (DirectMetaPropertyMap) super.metaPropertyMap(),
        "effectiveDate",
        "swapLegs");

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

    @Override
    protected MetaProperty<?> metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case -930389515// effectiveDate
          return _effectiveDate;
        case -318692264// swapLegs
          return _swapLegs;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder<? extends SwapTrade> builder() {
      return new DirectBeanBuilder<SwapTrade>(new SwapTrade());
    }

    @Override
    public Class<? extends SwapTrade> beanType() {
      return SwapTrade.class;
    }

    @Override
    public Map<String, MetaProperty<?>> metaPropertyMap() {
      return _metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-property for the {@code effectiveDate} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<LocalDate> effectiveDate() {
      return _effectiveDate;
    }

    /**
     * The meta-property for the {@code swapLegs} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<List<SwapLeg>> swapLegs() {
      return _swapLegs;
    }

  }

  ///CLOVER:ON
  //-------------------------- AUTOGENERATED END --------------------------
}
TOP

Related Classes of com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb.SwapTrade

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.