/*
 * Copyright 1997-2018 Optimatika
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.ojalgo.finance.business;

import java.math.BigDecimal;
import java.util.Currency;

import org.ojalgo.constant.BigMath;
import org.ojalgo.function.BigFunction;
import org.ojalgo.type.StandardType;

public interface QuantityPriceAmountStructure {

    static BigDecimal getImpliedAmount(final QuantityPriceAmountStructure aQuantityPriceAmount) {
        final BigDecimal tmpQuantity = aQuantityPriceAmount.getQuantity();
        final BigDecimal tmpPrice = aQuantityPriceAmount.getPrice();
        if ((tmpQuantity != null) && (tmpPrice != null)) {
            return BigFunction.MULTIPLY.invoke(tmpQuantity, tmpPrice);
        } else {
            return BigMath.ZERO;
        }
    }

    static BigDecimal getImpliedPrice(final QuantityPriceAmountStructure aQuantityPriceAmount) {
        final BigDecimal tmpQuantity = aQuantityPriceAmount.getQuantity();
        final BigDecimal tmpAmount = aQuantityPriceAmount.getAmount();
        if ((tmpAmount != null) && (tmpQuantity != null) && (tmpQuantity.signum() != 0)) {
            return BigFunction.DIVIDE.invoke(tmpAmount, tmpQuantity);
        } else {
            return BigMath.ONE;
        }
    }

    static BigDecimal getImpliedQuantity(final QuantityPriceAmountStructure aQuantityPriceAmount) {
        final BigDecimal tmpPrice = aQuantityPriceAmount.getPrice();
        final BigDecimal tmpAmount = aQuantityPriceAmount.getAmount();
        if ((tmpAmount != null) && (tmpPrice != null) && (tmpPrice.signum() != 0)) {
            return BigFunction.DIVIDE.invoke(tmpAmount, tmpPrice);
        } else {
            return BigMath.ZERO;
        }
    }

    /**
     * quantity * price = amount
     *
     * @see StandardType#AMOUNT
     */
    BigDecimal getAmount();

    Currency getCurrency();

    /**
     * quantity * price = amount
     *
     * @see StandardType#PRICE
     */
    BigDecimal getPrice();

    /**
     * quantity * price = amount
     *
     * @see StandardType#QUANTITY
     */
    BigDecimal getQuantity();

}

@@ -1441,36 +1441,25 @@
 ructure 
-aQuantityPriceAmount
+structure
 ) %7B%0A    
@@ -1471,36 +1471,33 @@
 inal BigDecimal 
-tmpQ
+q
 uantity = aQuant
@@ -1490,36 +1490,25 @@
 ntity = 
-aQuantityPriceAmount
+structure
 .getQuan
@@ -1544,39 +1544,25 @@
 mal 
-tmpP
+p
 rice = 
-aQuantityPriceAmount
+structure
 .get
@@ -1583,20 +1583,17 @@
    if ((
-tmpQ
+q
 uantity 
@@ -1597,36 +1597,33 @@
 ty != null) && (
-tmpP
+p
 rice != null)) %7B
@@ -1670,20 +1670,17 @@
 .invoke(
-tmpQ
+q
 uantity,
@@ -1680,20 +1680,17 @@
 antity, 
-tmpP
+p
 rice);%0A 
@@ -1828,36 +1828,25 @@
 ructure 
-aQuantityPriceAmount
+structure
 ) %7B%0A    
@@ -1866,20 +1866,17 @@
 Decimal 
-tmpQ
+q
 uantity 
@@ -1877,36 +1877,25 @@
 ntity = 
-aQuantityPriceAmount
+structure
 .getQuan
@@ -1923,36 +1923,33 @@
  BigDecimal 
-tmpA
+a
 mount = 
 aQuantityPri
@@ -1936,36 +1936,25 @@
 mount = 
-aQuantityPriceAmount
+structure
 .getAmou
@@ -1964,36 +1964,33 @@
 );%0A        if ((
-tmpA
+a
 mount != null) &
@@ -1988,28 +1988,25 @@
 = null) && (
-tmpQ
+q
 uantity != n
@@ -2014,20 +2014,17 @@
 ll) && (
-tmpQ
+q
 uantity.
@@ -2090,23 +2090,17 @@
 oke(
-tmpA
+a
 mount, 
-tmpQ
+q
 uant
@@ -2247,36 +2247,25 @@
 ructure 
-aQuantityPriceAmount
+structure
 ) %7B%0A    
@@ -2289,39 +2289,25 @@
 mal 
-tmpP
+p
 rice = 
-aQuantityPriceAmount
+structure
 .get
@@ -2344,20 +2344,17 @@
 mal 
-tmpA
+a
 mount = 
 aQua
@@ -2353,28 +2353,17 @@
 t = 
-aQuantityPriceAmount
+structure
 .get
@@ -2385,20 +2385,17 @@
    if ((
-tmpA
+a
 mount !=
@@ -2401,28 +2401,25 @@
 = null) && (
-tmpP
+p
 rice != null
@@ -2424,20 +2424,17 @@
 ll) && (
-tmpP
+p
 rice.sig
@@ -2497,23 +2497,17 @@
 oke(
-tmpA
+a
 mount, 
-tmpP
+p
 rice

Update src/main/java/org/ojalgo/finance/business/QuantityPriceAmountStructure.java