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

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

import java.math.BigInteger;

/**
 * A BigIntegerDiscriminator discriminates Lists of
 * BigIntegers.
 *
 * @author Randy Gettman
 * @since 0.5.0
 */
public class BigIntegerDiscriminator extends NumberDiscriminator
{
   /**
    * Returns a portion extractor appropriate for BigIntegers.
    * @param e An Extractor that returns appropriate labels.
    * @return An appropriate PortionExtractor.
    */
   protected  PortionExtractor getPortionExtractor(Extractor e)
   {
      return new PortionExtractor(e) {
         /**
          * The label is the specific portion of the element, cast as an
          * integer, taken from the byte array of the BigInteger.
          * @param element The element.
          * @return The specific portion of the element, cast as an integer.
          */
         public int getLabel(E element)
         {
            return myExtractor.getLabel(element).toByteArray()[myIndex] & PORTION_MASK;
         }

         /**
          * Complete after the end of the byte array representation.
          * @param element The element.
          * @return true if we are off the end of the byte array,
          *    representation, false otherwise.
          */
         public boolean isComplete(E element)
         {
            return myExtractor.isComplete(element) || myIndex >= myExtractor.getLabel(element).toByteArray().length;
         }
      };
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy