/*
 * 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.awt.Color;
import java.math.BigDecimal;
import java.util.Collection;

import org.ojalgo.finance.portfolio.SimpleAsset;

/**
 * A component asset of the {@linkplain ModernPortfolio} portfolio.
 *
 * @author apete
 */
interface ModernAsset extends ModernPortfolio {

    static Color mixColours(final Collection<? extends ModernAsset> assets) {

        int tmpR = 0;
        int tmpG = 0;
        int tmpB = 0;

        for (final ModernAsset tmpModernAsset : assets) {

            final float tmpWeight = tmpModernAsset.getWeight().floatValue();
            final Color tmpColour = tmpModernAsset.getAssetColour();

            tmpR += tmpWeight * tmpColour.getRed();
            tmpG += tmpWeight * tmpColour.getGreen();
            tmpB += tmpWeight * tmpColour.getBlue();
        }

        while (tmpR < 0) {
            tmpR += 255;
        }
        while (tmpG < 0) {
            tmpG += 255;
        }
        while (tmpB < 0) {
            tmpB += 255;
        }

        while (tmpR > 255) {
            tmpR -= 255;
        }
        while (tmpG > 255) {
            tmpG -= 255;
        }
        while (tmpB > 255) {
            tmpB -= 255;
        }

        return new Color(tmpR, tmpG, tmpB);
    }

    Color getAssetColour();

    String getAssetKey();

    BigDecimal getWeight();

    int index();

    SimpleAsset toDefinitionPortfolio();

}

@@ -1653,20 +1653,17 @@
 l float 
-tmpW
+w
 eight = 
@@ -1727,20 +1727,17 @@
 l Color 
-tmpC
+c
 olour = 
@@ -1786,36 +1786,44 @@
     tmpR += 
-tmpW
+Math.round(w
 eight * 
 tmpColour.ge
@@ -1802,36 +1802,33 @@
 .round(weight * 
-tmpC
+c
 olour.getRed();%0A
@@ -1825,16 +1825,17 @@
 getRed()
+)
 ;%0A      
@@ -1844,36 +1844,44 @@
     tmpG += 
-tmpW
+Math.round(w
 eight * 
 tmpColour.ge
@@ -1860,36 +1860,33 @@
 .round(weight * 
-tmpC
+c
 olour.getGreen()
@@ -1885,16 +1885,17 @@
 tGreen()
+)
 ;%0A      
@@ -1912,20 +1912,28 @@
  += 
-tmpW
+Math.round(w
 eight * 
 tmpC
@@ -1932,12 +1932,9 @@
 t * 
-tmpC
+c
 olou
@@ -1940,24 +1940,25 @@
 ur.getBlue()
+)
 ;%0A        %7D%0A

Update ModernAsset.java