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

net.sf.jagg.model.AnalyticContext Maven / Gradle / Ivy

Go to download

jAgg is a Java 5.0 API that supports “group by” operations on Lists of Java objects: aggregate operations such as count, sum, max, min, avg, and many more. It also allows custom aggregate operations.

The newest version!
package net.sf.jagg.model;

import java.util.List;

import net.sf.jagg.model.AnalyticValue;
import net.sf.jagg.util.PartitionAndOrderByComparator;

/**
 * An AnalyticContext stores all of the context information
 * necessary to perform one analytic operation on a list of values.
 *
 * @author Randy Gettman
 * @since 0.9.0
 */
public class AnalyticContext
{
   private List> mySortedValues;
   private PartitionAndOrderByComparator myComparator;
   private List myDependencies;
   private int myWindowStartIndex;
   private int myWindowEndIndex;
   private int myTerminatedThroughIndex;
   private int myEndPartitionIndex;

   /**
    * Constructs an AnalyticContext consisting of the given
    * already-sorted List of AnalyticValues, sorted
    * according to the given PartitionAndOrderByComparator.  The
    * initial values of the starting and ending indexes of the sliding window
    * are -1, before the first value.  The initial values of the
    * terminated through index and the end of the partition index are also
    * -1, before the first value.
    * @param sortedValues An already sorted List of
    *    AnalyticValues.
    * @param comparator The PartitionAndOrderByComparator used to
    *    sort the values.
    */
   public AnalyticContext(List> sortedValues, PartitionAndOrderByComparator comparator)
   {
      mySortedValues = sortedValues;
      myComparator = comparator;
      myDependencies = null;
      // Initial empty window starts at 0 and "ends" at -1.
      myWindowStartIndex = 0;
      myWindowEndIndex = -1;
      myTerminatedThroughIndex = -1;
      myEndPartitionIndex = -1;
   }

   /**
    * Returns the List of AnalyticValues.
    * @return The List of AnalyticValues.
    */
   public List> getListOfValues()
   {
      return mySortedValues;
   }

   /**
    * Returns the PartitionAndOrderByComparator.
    * @return The PartitionAndOrderByComparator.
    */
   public PartitionAndOrderByComparator getComparator()
   {
      return myComparator;
   }

   /**
    * Returns the List of dependencies, if it was set previously.
    * Each element is an index into Analytic's list of
    * AnalyticAggregators.
    * @return The List of dependencies, or null if it
    *    wasn't set.
    */
   public List getDependencies()
   {
      return myDependencies;
   }

   /**
    * Sets the List of dependencies.  Each element is an index
    * into Analytic's list of AnalyticAggregators.
    * @param dependencies A List of dependencies.
    */
   public void setDependencies(List dependencies)
   {
      myDependencies = dependencies;
   }

   /**
    * Returns the 0-based index indicating the start of the window.
    * @return The 0-based index indicating the start of the window.
    */
   public int getWindowStartIndex()
   {
      return myWindowStartIndex;
   }

   /**
    * Slide the start of the window down by 1.
    */
   public void incrementWindowStartIndex()
   {
      myWindowStartIndex++;
   }

   /**
    * Advances the start of the window one past the last terminated index.
    */
   public void advanceWindowStartPastLastTerminated()
   {
      myWindowStartIndex = myTerminatedThroughIndex + 1;
   }

   /**
    * Returns the 0-based index indicating the end of the window.
    * @return The 0-based index indicating the end of the window.  A value of
    *    -1 indicates "before the start of the window".
    */
   public int getWindowEndIndex()
   {
      return myWindowEndIndex;
   }

   /**
    * Slide the end of the window down by 1.
    */
   public void incrementWindowEndIndex()
   {
      myWindowEndIndex++;
   }

   /**
    * Returns whether the current window is empty.
    * @return Whether the current window is empty.
    */
   public boolean isWindowEmpty()
   {
      return myWindowStartIndex > myWindowEndIndex;
   }

   /**
    * Returns the "terminated through" index, through which all analytic values
    * have been assigned a terminated value for this context.
    * @return The "terminated through" index, or -1 if no analytic
    *    values have any values yet.
    */
   public int getTerminatedThroughIndex()
   {
      return myTerminatedThroughIndex;
   }

   /**
    * Increments the "terminated through" index, when an analytic value has
    * been assigned a terminated value for this context.
    */
   public void incrementTerminatedThroughIndex()
   {
      myTerminatedThroughIndex++;
   }

   /**
    * Returns the 0-based index of the end of the current partition.
    * @return The 0-based index of the end of the current partition, or
    *    -1 if there is no current partition yet.
    */
   public int getEndOfPartitionIndex()
   {
      return myEndPartitionIndex;
   }

   /**
    * Sets the 0-based index of the end of the current partition.
    * @param index The 0-based index of the end of the current partition, or
    *    -1 if there is no current partition yet.
    */
   public void setEndOfPartitionIndex(int index)
   {
      myEndPartitionIndex = index;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy