/*
 *  The MIT License (MIT)
 *
 *  View the full license at:
 *  https://github.com/hendrixjoseph/FamilyTree/blob/master/LICENSE.md
 *
 *  Copyright (c) 2015 Joseph Hendrix
 *
 *  Hosted on GitHub at https://github.com/hendrixjoseph/FamilyTree
 *
 */

package edu.wright.hendrix11.c3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Joe Hendrix
 */
public class ChartModel
{
    private static final Logger LOG = Logger.getLogger(ChartModel.class.getName());
    private Map<String, ? extends Number[]> arrayData = new LinkedHashMap<>();
    private List<String> barLabels = new ArrayList<>();
    private Map<String, ? extends Number> data = new LinkedHashMap<>();
    private String title;
    private String xAxisLabel;
    private String yAxisLabel;

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getxAxisLabel()
    {
        return xAxisLabel;
    }

    public void setxAxisLabel(String xAxisLabel)
    {
        this.xAxisLabel = xAxisLabel;
    }

    public String getyAxisLabel()
    {
        return yAxisLabel;
    }

    public void setyAxisLabel(String yAxisLabel)
    {
        this.yAxisLabel = yAxisLabel;
    }

    /**
     * @param barLabels
     */
    public void setBarLabels(String[] barLabels)
    {
        this.barLabels = Arrays.asList(barLabels);
    }

    /**
     * @return
     */
    public List<String> getBarLabels()
    {
        return barLabels;
    }

    /**
     * @param barLabels
     */
    public void setBarLabels(List<String> barLabels)
    {
        this.barLabels = barLabels;
    }

    public Map<String, ? extends Number[]> getArrayData()
    {
        return arrayData;
    }

    public void setArrayData(Map<String, ? extends Number[]> arrayData)
    {
        data = new LinkedHashMap<>();
        this.arrayData = arrayData;
    }

    public Map<String, ? extends Number> getData()
    {
        return data;
    }

    public void setData(Map<String, ? extends Number> data)
    {
        arrayData = new LinkedHashMap<>();
        this.data = data;
    }

    /**
     * @return
     */
    public Set<String> getAxisLabels()
    {
        if ( hasArrayData() )
            return arrayData.keySet();
        else
            return data.keySet();
    }

    public Number[] getArrayData(String label)
    {
        return arrayData.get(label);
    }

    /**
     * @return
     */
    public Integer getNumLabels()
    {
        return getAxisLabels().size();
    }

    /**
     * @return
     */
    public Integer getNumValues()
    {
        if ( hasArrayData() )
        {
            int i = 0;

            for ( Number[] n : arrayData.values() )
            {
                i += n.length;
            }

            return i;
        }
        else
        {
            return data.size();
        }
    }

    /**
     * @return
     */
    public Number getMax()
    {
        Number max = null;

        if ( hasArrayData() )
        {
            for ( Number[] numbers : arrayData.values() )
            {
                for ( Number number : numbers )
                {
                    max = max(max, number);
                }
            }
        }
        else
        {
            for ( Number number : data.values() )
            {
                LOG.log(Level.SEVERE, "Max before: " + max);
                max = max(max, number);
                LOG.log(Level.SEVERE, "Max after: " + max);
            }
        }

        return max;
    }

    public Number getData(String label)
    {
        return data.get(label);
    }

    public boolean hasArrayData()
    {
        return arrayData != null && !arrayData.isEmpty();
    }

    private Number max(Number n1, Number n2)
    {
        if ( n1 == null && n2 == null )
        {
            return null;
        }
        else if ( n1 == null )
        {
            return n2;
        }
        else if ( n2 == null )
        {
            return n1;
        }
        else
        {
            if ( n1 instanceof Comparable )
            {
                Comparable compare = (Comparable<?>) n1;
                return compare.compareTo(n2) < 0 ? n2 : n1;
            }
            else
            {
                return n1.doubleValue() - n2.doubleValue() < 0 ? n2 : n1;
            }
        }
    }
}

@@ -2618,1942 +2618,186 @@
     
-/**%0A     * @return%0A     */%0A    public Integer getNumLabels()%0A    %7B%0A        return getAxisLabels().size();%0A    %7D%0A%0A    /**%0A     * @return%0A     */%0A    public Integer getNumValues()%0A    %7B%0A        if ( hasArrayData() )%0A        %7B%0A            int i = 0;%0A%0A            for ( Number%5B%5D n : arrayData.values() )%0A            %7B%0A                i += n.length;%0A            %7D%0A%0A            return i;%0A        %7D%0A        else%0A        %7B%0A            return data.size();%0A        %7D%0A    %7D%0A%0A    /**%0A     * @return%0A     */%0A    public Number getMax()%0A    %7B%0A        Number max = null;%0A%0A        if ( hasArrayData() )%0A        %7B%0A            for ( Number%5B%5D numbers : arrayData.values() )%0A            %7B%0A                for ( Number number : numbers )%0A                %7B%0A                    max = max(max, number);%0A                %7D%0A            %7D%0A        %7D%0A        else%0A        %7B%0A            for ( Number number : data.values() )%0A            %7B%0A                LOG.log(Level.SEVERE, %22Max before: %22 + max);%0A                max = max(max, number);%0A                LOG.log(Level.SEVERE, %22Max after: %22 + max);%0A            %7D%0A        %7D%0A%0A        return max;%0A    %7D%0A%0A    public Number getData(String label)%0A    %7B%0A        return data.get(label);%0A    %7D%0A%0A    public boolean hasArrayData()%0A    %7B%0A        return arrayData != null && !arrayData.isEmpty();%0A    %7D%0A%0A    private Number max(Number n1, Number n2)%0A    %7B%0A        if ( n1 == null && n2 == null )%0A        %7B%0A            return null;%0A        %7D%0A        else if ( n1 == null )%0A        %7B%0A            return n2;%0A        %7D%0A        else if ( n2 == null )%0A        %7B%0A            return n1;%0A        %7D%0A        else%0A        %7B%0A            if ( n1 instanceof Comparable )%0A            %7B%0A                Comparable compare = (Comparable%3C?%3E) n1;%0A                return compare.compareTo(n2) %3C 0 ? n2 : n1;%0A            %7D%0A            else%0A            %7B%0A                return n1.doubleValue() - n2.doubleValue() %3C 0 ? n2 : n1;%0A            %7D%0A        %7D
+public Number getData(String label)%0A    %7B%0A        return data.get(label);%0A    %7D%0A%0A    public boolean hasArrayData()%0A    %7B%0A        return arrayData != null && !arrayData.isEmpty();
 %0A   

Update ChartModel.java