All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kg.apc.charting.rows.GraphRowExactValues Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package kg.apc.charting.rows;

import kg.apc.charting.AbstractGraphRow;
import kg.apc.charting.elements.GraphPanelChartExactElement;
import kg.apc.charting.AbstractGraphPanelChartElement;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentSkipListMap;

public class GraphRowExactValues
      extends AbstractGraphRow
      implements Iterator>
{
   private ConcurrentSkipListMap values;
   private Iterator> iterator;

   /**
    * 
    */
   public GraphRowExactValues()
   {
      super();
      values = new ConcurrentSkipListMap();
   }

   /**
    *
    * @param xVal
    * @param yVal
    */
   @Override
   public void add(long xVal, double yVal)
   {
      GraphPanelChartExactElement el;
      el = new GraphPanelChartExactElement(xVal, yVal);
      values.put((long) values.size(), el);

      super.add(xVal, yVal);
   }

   /**
    *
    * @return
    */
   @Override
   public Iterator> iterator()
   {
      iterator = values.entrySet().iterator();
      return this;
   }

   public boolean hasNext()
   {
      return iterator != null && iterator.hasNext();
   }

   public Entry next()
   {
      GraphPanelChartExactElement el = (GraphPanelChartExactElement) iterator.next().getValue();
      return new ExactEntry(el.getX(), el);
   }

   public void remove()
   {
      throw new UnsupportedOperationException("Not supported yet.");
   }

   private static class ExactEntry
         implements Entry
   {
      private long key;
      private final AbstractGraphPanelChartElement value;

      public ExactEntry(long aKey, AbstractGraphPanelChartElement aValue)
      {
         key = aKey;
         value = aValue;
      }

      public Long getKey()
      {
         return key;
      }

      public AbstractGraphPanelChartElement getValue()
      {
         return value;
      }

      public AbstractGraphPanelChartElement setValue(AbstractGraphPanelChartElement value)
      {
         throw new UnsupportedOperationException("Not supported yet.");
      }
   }

    @Override
    public int size()
    {
        return values.size();
    }

    @Override
    public AbstractGraphPanelChartElement getElement(long value)
    {
        AbstractGraphPanelChartElement ret = null;
        Iterator> it = values.entrySet().iterator();

        while(it.hasNext() && ret == null)
        {
            GraphPanelChartExactElement el = (GraphPanelChartExactElement) it.next().getValue();
            if(el.getX() == value)
            {
                ret = el;
            }
        }

        return ret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy