/*
 * Copyright 2012 Jakub Dominik Kozlowski <mail@jakub-kozlowski.com>
 * Distributed under the The MIT License.
 * (See accompanying file LICENSE)
 */

package icebook.exec;

import com.google.common.primitives.Longs;

import javax.annotation.Nonnegative;
import javax.annotation.concurrent.Immutable;

import static com.google.common.base.Preconditions.checkArgument;

/**
 * Represents a trade.
 *
 * @author Jakub D Kozlowski
 * @since 1.0
 */
@Immutable
public final class Trade {

    private final long buyOrderId;

    private final long sellOrderId;

    private final long price;

    private final long quantity;

    /**
     * Default constructor.
     *
     * @param buyOrderId  id of the buy order.
     * @param sellOrderId id of the sell order.
     * @param price       execution price.
     * @param quantity    quantity executed.
     */
    public Trade(@Nonnegative final long buyOrderId,
                 @Nonnegative final long sellOrderId,
                 @Nonnegative final long price,
                 @Nonnegative final long quantity) {
        checkArgument(Longs.min(buyOrderId, sellOrderId, price, quantity) > 0, "all arguments have to be positive.");
        this.buyOrderId = buyOrderId;
        this.sellOrderId = sellOrderId;
        this.price = price;
        this.quantity = quantity;
    }

    /**
     * Gets the buyOrderId.
     *
     * @return the buyOrderId.
     */
    public long getBuyOrderId() {
        return buyOrderId;
    }

    /**
     * Gets the sellOrderId.
     *
     * @return the sellOrderId.
     */
    public long getSellOrderId() {
        return sellOrderId;
    }

    /**
     * Gets the price.
     *
     * @return the price.
     */
    public long getPrice() {
        return price;
    }

    /**
     * Gets the quantity.
     *
     * @return the quantity.
     */
    public long getQuantity() {
        return quantity;
    }
}

@@ -170,16 +170,109 @@
 .exec;%0A%0A
+import com.google.common.base.Objects;%0Aimport com.google.common.base.Objects.ToStringHelper;%0A
 import c
@@ -1993,11 +1993,1118 @@
 y;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        Trade trade = (Trade) o;%0A%0A        if (buyOrderId != trade.buyOrderId) return false;%0A        if (price != trade.price) return false;%0A        if (quantity != trade.quantity) return false;%0A        if (sellOrderId != trade.sellOrderId) return false;%0A%0A        return true;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = (int) (buyOrderId %5E (buyOrderId %3E%3E%3E 32));%0A        result = 31 * result + (int) (sellOrderId %5E (sellOrderId %3E%3E%3E 32));%0A        result = 31 * result + (int) (price %5E (price %3E%3E%3E 32));%0A        result = 31 * result + (int) (quantity %5E (quantity %3E%3E%3E 32));%0A        return result;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        final ToStringHelper helper = Objects.toStringHelper(this);%0A        helper.add(%22buyOrderId%22, buyOrderId);%0A        helper.add(%22sellOrderId%22, sellOrderId);%0A        helper.add(%22price%22, price);%0A        helper.add(%22quantity%22, quantity);%0A        return helper.toString();%0A    %7D
 %0A%7D%0A

Implement hashCode, toString, equals in Trade.