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

net.sf.jagg.DenseRankAnalytic 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;

import net.sf.jagg.model.WindowClause;

/**
 * This class represents the "dense rank" analytic function over no values.
 * It returns the rank within the partition given the ordering.  Ties are
 * given the same rank number, but this does not result in "gaps" in the
 * rankings.
 *
 * @author Randy Gettman
 * @since 0.9.0
 */
public class DenseRankAnalytic extends NoPropAnalytic
{
   private long myCount;
   private boolean doIStartRunOver;

   /**
    * Constructs a RankAnalytic, with no property.
    *
    * @param property Should be an empty string or null.
    */
   public DenseRankAnalytic(String property)
   {
      setProperty(property);
   }

   /**
    * Constructs an RankAnalytic, with no property.
    */
   public DenseRankAnalytic()
   {
      setProperty(null);
   }

   /**
    * Returns an uninitialized copy of this Aggregator object,
    * with the same property(ies) to analyze.
    * @return An uninitialized copy of this Aggregator object.
    */
   public DenseRankAnalytic replicate()
   {
      return new DenseRankAnalytic();
   }

   /**
    * Initialize the count to zero.
    */
   public void init()
   {
      myCount = 0;
      doIStartRunOver = true;
   }

   /**
    * Count the value.
    *
    * @param value The value to aggregate.
    */
   public void iterate(Object value)
   {
      if (value != null)
      {
         if (doIStartRunOver)
            myCount++;
         doIStartRunOver = false;
      }
   }

   /**
    * Uncount the value.
    *
    * @param value The value to delete.
    */
   public void delete(Object value)
   {
      if (value != null)
      {
         doIStartRunOver = true;
      }
   }

   /**
    * The dense rank analytic doesn't take a window clause.
    * @return false.
    */
   public boolean takesWindowClause()
   {
      return false;
   }

   /**
    * The row number analytic supplies its own window clause: range(0, 0).
    * @return A WindowClause.
    */
   public WindowClause getWindowClause()
   {
      return new WindowClause(WindowClause.Type.RANGE, 0, 0);
   }

   /**
    * Merge the given Aggregator into this one by adding the
    * counts.
    *
    * @param agg The Aggregator to merge into this one.
    */
   public void merge(AggregateFunction agg)
   {
      // TODO: Decide how to implement this when adding parallel support for analytics.
      throw new UnsupportedOperationException("Merge not implemented!");
   }

   /**
    * Return the count.
    *
    * @return The count as a Long.
    */
   public Long terminate()
   {
      return myCount;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy