com.algoTrader.vo.ib.UpdatePortfolio.java Source code

Java tutorial

Introduction

Here is the source code for com.algoTrader.vo.ib.UpdatePortfolio.java

Source

// license-header java merge-point
//
/**
 * @author Generated on 02/10/2014 17:31:00+0000 Do not modify by hand!
 *
 * TEMPLATE:     ValueObject.vsl in andromda-java-cartridge.
 * MODEL CLASS:  Data::AlgoTrader::com.algoTrader::vo::ib::UpdatePortfolio
 * STEREOTYPE:   ValueObject
 */
package com.algoTrader.vo.ib;

import com.ib.client.Contract;
import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * TODO: Model Documentation for class UpdatePortfolio
 */
public class UpdatePortfolio implements Serializable, Comparable<UpdatePortfolio> {
    /** The serial version UID of this class. Needed for serialization. */
    private static final long serialVersionUID = -5626780965820494415L;

    // Class attributes
    /** TODO: Model Documentation for attribute contract */
    protected Contract contract;
    /** TODO: Model Documentation for attribute position */
    protected int position;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setPosition = false;
    /** TODO: Model Documentation for attribute marketPrice */
    protected double marketPrice;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setMarketPrice = false;
    /** TODO: Model Documentation for attribute marketValue */
    protected double marketValue;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setMarketValue = false;
    /** TODO: Model Documentation for attribute averageCost */
    protected double averageCost;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setAverageCost = false;
    /** TODO: Model Documentation for attribute unrealizedPNL */
    protected double unrealizedPNL;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setUnrealizedPNL = false;
    /** TODO: Model Documentation for attribute realizedPNL */
    protected double realizedPNL;
    /**
     * boolean setter for primitive attribute, so we can tell if it's initialized
     */
    protected boolean setRealizedPNL = false;
    /** TODO: Model Documentation for attribute accountName */
    protected String accountName;

    /** Default Constructor with no properties */
    public UpdatePortfolio() {
        // Documented empty block - avoid compiler warning - no super constructor
    }

    /**
     * Constructor with all properties
     * @param contractIn Contract
     * @param positionIn int
     * @param marketPriceIn double
     * @param marketValueIn double
     * @param averageCostIn double
     * @param unrealizedPNLIn double
     * @param realizedPNLIn double
     * @param accountNameIn String
     */
    public UpdatePortfolio(final Contract contractIn, final int positionIn, final double marketPriceIn,
            final double marketValueIn, final double averageCostIn, final double unrealizedPNLIn,
            final double realizedPNLIn, final String accountNameIn) {
        this.contract = contractIn;
        this.position = positionIn;
        this.setPosition = true;
        this.marketPrice = marketPriceIn;
        this.setMarketPrice = true;
        this.marketValue = marketValueIn;
        this.setMarketValue = true;
        this.averageCost = averageCostIn;
        this.setAverageCost = true;
        this.unrealizedPNL = unrealizedPNLIn;
        this.setUnrealizedPNL = true;
        this.realizedPNL = realizedPNLIn;
        this.setRealizedPNL = true;
        this.accountName = accountNameIn;
    }

    /**
     * Copies constructor from other UpdatePortfolio
     *
     * @param otherBean Cannot be <code>null</code>
     * @throws NullPointerException if the argument is <code>null</code>
     */
    public UpdatePortfolio(final UpdatePortfolio otherBean) {
        this.contract = otherBean.getContract();
        this.position = otherBean.getPosition();
        this.setPosition = true;
        this.marketPrice = otherBean.getMarketPrice();
        this.setMarketPrice = true;
        this.marketValue = otherBean.getMarketValue();
        this.setMarketValue = true;
        this.averageCost = otherBean.getAverageCost();
        this.setAverageCost = true;
        this.unrealizedPNL = otherBean.getUnrealizedPNL();
        this.setUnrealizedPNL = true;
        this.realizedPNL = otherBean.getRealizedPNL();
        this.setRealizedPNL = true;
        this.accountName = otherBean.getAccountName();
    }

    /**
     * Copies all properties from the argument value object into this value object.
     * @param otherBean Cannot be <code>null</code>
     */
    public void copy(final UpdatePortfolio otherBean) {
        if (null != otherBean) {
            this.setContract(otherBean.getContract());
            this.setPosition(otherBean.getPosition());
            this.setPosition = true;
            this.setMarketPrice(otherBean.getMarketPrice());
            this.setMarketPrice = true;
            this.setMarketValue(otherBean.getMarketValue());
            this.setMarketValue = true;
            this.setAverageCost(otherBean.getAverageCost());
            this.setAverageCost = true;
            this.setUnrealizedPNL(otherBean.getUnrealizedPNL());
            this.setUnrealizedPNL = true;
            this.setRealizedPNL(otherBean.getRealizedPNL());
            this.setRealizedPNL = true;
            this.setAccountName(otherBean.getAccountName());
        }
    }

    /**
     * TODO: Model Documentation for attribute contract
     * Get the contract Attribute
     * @return contract Contract
     */
    public Contract getContract() {
        return this.contract;
    }

    /**
     * 
     * @param value Contract
     */
    public void setContract(final Contract value) {
        this.contract = value;
    }

    /**
     * TODO: Model Documentation for attribute position
     * Get the position Attribute
     * @return position int
     */
    public int getPosition() {
        return this.position;
    }

    /**
     * 
     * @param value int
     */
    public void setPosition(final int value) {
        this.position = value;
        this.setPosition = true;
    }

    /**
     * Return true if the primitive attribute position is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetPosition() {
        return this.setPosition;
    }

    /**
     * TODO: Model Documentation for attribute marketPrice
     * Get the marketPrice Attribute
     * @return marketPrice double
     */
    public double getMarketPrice() {
        return this.marketPrice;
    }

    /**
     * 
     * @param value double
     */
    public void setMarketPrice(final double value) {
        this.marketPrice = value;
        this.setMarketPrice = true;
    }

    /**
     * Return true if the primitive attribute marketPrice is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetMarketPrice() {
        return this.setMarketPrice;
    }

    /**
     * TODO: Model Documentation for attribute marketValue
     * Get the marketValue Attribute
     * @return marketValue double
     */
    public double getMarketValue() {
        return this.marketValue;
    }

    /**
     * 
     * @param value double
     */
    public void setMarketValue(final double value) {
        this.marketValue = value;
        this.setMarketValue = true;
    }

    /**
     * Return true if the primitive attribute marketValue is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetMarketValue() {
        return this.setMarketValue;
    }

    /**
     * TODO: Model Documentation for attribute averageCost
     * Get the averageCost Attribute
     * @return averageCost double
     */
    public double getAverageCost() {
        return this.averageCost;
    }

    /**
     * 
     * @param value double
     */
    public void setAverageCost(final double value) {
        this.averageCost = value;
        this.setAverageCost = true;
    }

    /**
     * Return true if the primitive attribute averageCost is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetAverageCost() {
        return this.setAverageCost;
    }

    /**
     * TODO: Model Documentation for attribute unrealizedPNL
     * Get the unrealizedPNL Attribute
     * @return unrealizedPNL double
     */
    public double getUnrealizedPNL() {
        return this.unrealizedPNL;
    }

    /**
     * 
     * @param value double
     */
    public void setUnrealizedPNL(final double value) {
        this.unrealizedPNL = value;
        this.setUnrealizedPNL = true;
    }

    /**
     * Return true if the primitive attribute unrealizedPNL is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetUnrealizedPNL() {
        return this.setUnrealizedPNL;
    }

    /**
     * TODO: Model Documentation for attribute realizedPNL
     * Get the realizedPNL Attribute
     * @return realizedPNL double
     */
    public double getRealizedPNL() {
        return this.realizedPNL;
    }

    /**
     * 
     * @param value double
     */
    public void setRealizedPNL(final double value) {
        this.realizedPNL = value;
        this.setRealizedPNL = true;
    }

    /**
     * Return true if the primitive attribute realizedPNL is set, through the setter or constructor
     * @return true if the attribute value has been set
     */
    public boolean isSetRealizedPNL() {
        return this.setRealizedPNL;
    }

    /**
     * TODO: Model Documentation for attribute accountName
     * Get the accountName Attribute
     * @return accountName String
     */
    public String getAccountName() {
        return this.accountName;
    }

    /**
     * 
     * @param value String
     */
    public void setAccountName(final String value) {
        this.accountName = value;
    }

    /**
     * @param object to compare this object against
     * @return boolean if equal
     * @see Object#equals(Object)
     */
    @Override
    public boolean equals(final Object object) {
        if (object == null || object.getClass() != this.getClass()) {
            return false;
        }
        // Check if the same object instance
        if (object == this) {
            return true;
        }
        UpdatePortfolio rhs = (UpdatePortfolio) object;
        return new EqualsBuilder().append(this.getContract(), rhs.getContract())
                .append(this.getPosition(), rhs.getPosition()).append(this.getMarketPrice(), rhs.getMarketPrice())
                .append(this.getMarketValue(), rhs.getMarketValue())
                .append(this.getAverageCost(), rhs.getAverageCost())
                .append(this.getUnrealizedPNL(), rhs.getUnrealizedPNL())
                .append(this.getRealizedPNL(), rhs.getRealizedPNL())
                .append(this.getAccountName(), rhs.getAccountName()).isEquals();
    }

    /**
     * @param object to compare this object against
     * @return int if equal
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(final UpdatePortfolio object) {
        if (object == null) {
            return -1;
        }
        // Check if the same object instance
        if (object == this) {
            return 0;
        }
        return new CompareToBuilder().append(this.getContract(), object.getContract())
                .append(this.getPosition(), object.getPosition())
                .append(this.getMarketPrice(), object.getMarketPrice())
                .append(this.getMarketValue(), object.getMarketValue())
                .append(this.getAverageCost(), object.getAverageCost())
                .append(this.getUnrealizedPNL(), object.getUnrealizedPNL())
                .append(this.getRealizedPNL(), object.getRealizedPNL())
                .append(this.getAccountName(), object.getAccountName()).toComparison();
    }

    /**
     * @return int hashCode value
     * @see Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(1249046965, -82296885).append(this.getContract()).append(this.getPosition())
                .append(this.getMarketPrice()).append(this.getMarketValue()).append(this.getAverageCost())
                .append(this.getUnrealizedPNL()).append(this.getRealizedPNL()).append(this.getAccountName())
                .toHashCode();
    }

    /**
     * @return String representation of object
     * @see Object#toString()
     */
    @Override
    public String toString() {
        return new ToStringBuilder(this).append("contract", this.getContract())
                .append("position", this.getPosition()).append("marketPrice", this.getMarketPrice())
                .append("marketValue", this.getMarketValue()).append("averageCost", this.getAverageCost())
                .append("unrealizedPNL", this.getUnrealizedPNL()).append("realizedPNL", this.getRealizedPNL())
                .append("accountName", this.getAccountName()).toString();
    }

    /**
     * Compares the properties of this instance to the properties of the argument. This method will return
     * {@code false} as soon as it detects that the argument is {@code null} or not of the same type as
     * (or a sub-type of) this instance's type.
     *
     * <p/>For array, collection or map properties the comparison will be done one level deep, in other words:
     * the elements will be compared using the {@code equals()} operation.
     *
     * <p/>Note that two properties will be considered equal when both values are {@code null}.
     *
     * @param thatObject the object containing the properties to compare against this instance
     * @return this method will return {@code true} in case the argument has the same type as this class, or is a
     *      sub-type of this class and all properties as found on this class have equal values when queried on that
     *      argument instance; in all other cases this method will return {@code false}
     */
    public boolean equalProperties(final Object thatObject) {
        if (thatObject == null || !this.getClass().isAssignableFrom(thatObject.getClass())) {
            return false;
        }

        final UpdatePortfolio that = (UpdatePortfolio) thatObject;

        return equal(this.getContract(), that.getContract()) && equal(this.getPosition(), that.getPosition())
                && equal(this.getMarketPrice(), that.getMarketPrice())
                && equal(this.getMarketValue(), that.getMarketValue())
                && equal(this.getAverageCost(), that.getAverageCost())
                && equal(this.getUnrealizedPNL(), that.getUnrealizedPNL())
                && equal(this.getRealizedPNL(), that.getRealizedPNL())
                && equal(this.getAccountName(), that.getAccountName());
    }

    /**
     * This is a convenient helper method which is able to detect whether or not two values are equal. Two values
     * are equal when they are both {@code null}, are arrays of the same length with equal elements or are
     * equal objects (this includes {@link java.util.Collection} and {@link java.util.Map} instances).
     *
     * <p/>Note that for array, collection or map instances the comparison runs one level deep.
     *
     * @param first the first object to compare, may be {@code null}
     * @param second the second object to compare, may be {@code null}
     * @return this method will return {@code true} in case both objects are equal as explained above;
     *      in all other cases this method will return {@code false}
     */
    protected static boolean equal(final Object first, final Object second) {
        final boolean equal;

        if (first == null) {
            equal = (second == null);
        } else if (first.getClass().isArray() && (second != null) && second.getClass().isArray()) {
            equal = Arrays.equals((Object[]) first, (Object[]) second);
        } else // note that the following also covers java.util.Collection and java.util.Map
        {
            equal = first.equals(second);
        }

        return equal;
    }

    // UpdatePortfolio value-object java merge-point
}