org.archive.wayback.util.partition
Class Partitioner<T>

java.lang.Object
  extended by org.archive.wayback.util.partition.Partitioner<T>
Type Parameters:
T - generic class type to use with this Partitioner

public class Partitioner<T>
extends Object

Class which divides a set of date-related objects into sub-sets by time ranges. This class provides methods for: 1) determining the smallest PartitionSize that can be used to cover a time range, using at most a set number of partitions 2) creating a List of Partition objects covering a span of time, each having a specified size 3) efficiently populating an iterator of date-related objects into List of Partition objects

Author:
brad

Field Summary
static PartitionSize daySize
          PartitionSize based on Day intervals
static PartitionSize hourSize
          PartitionSize based on Hour intervals
static PartitionSize monthSize
          PartitionSize based on Month intervals
static PartitionSize twoMonthSize
          PartitionSize based on Two Month intervals
static PartitionSize twoYearSize
          PartitionSize based on Two Year intervals
static PartitionSize weekSize
          PartitionSize based on Week intervals
static PartitionSize yearSize
          PartitionSize based on Year intervals
 
Constructor Summary
Partitioner(ElementPartitionMap<T> map)
           
 
Method Summary
 void dumpPartitions(List<Partition<T>> partitions)
          Debugging method
 List<Partition<T>> getRange(PartitionSize size, Date start, Date end)
          Create a List of Partition objects of the specified size, which span the date range specified.
 PartitionSize getSize(Date first, Date last, int maxP)
          Attempt to find the smallest PartitionSize implementation which, spanning the range first and last specified, produces at most maxP partitions.
static PartitionSize getSize(String name)
          Get a PartitionSize object by it's name
 void populate(List<Partition<T>> partitions, Iterator<T> itr)
          Add elements from itr into the appropriate partitions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hourSize

public static PartitionSize hourSize
PartitionSize based on Hour intervals


daySize

public static PartitionSize daySize
PartitionSize based on Day intervals


weekSize

public static PartitionSize weekSize
PartitionSize based on Week intervals


monthSize

public static PartitionSize monthSize
PartitionSize based on Month intervals


twoMonthSize

public static PartitionSize twoMonthSize
PartitionSize based on Two Month intervals


yearSize

public static PartitionSize yearSize
PartitionSize based on Year intervals


twoYearSize

public static PartitionSize twoYearSize
PartitionSize based on Two Year intervals

Constructor Detail

Partitioner

public Partitioner(ElementPartitionMap<T> map)
Parameters:
map - that converts from the Generic type used in this instance to a Date, and adds a Generic type used to a Partition
Method Detail

getSize

public static PartitionSize getSize(String name)
Get a PartitionSize object by it's name

Parameters:
name - of the PartitionSize
Returns:
PartitionSize matching the name, or a TwoYearPartionSize if name is unknown

getSize

public PartitionSize getSize(Date first,
                             Date last,
                             int maxP)
Attempt to find the smallest PartitionSize implementation which, spanning the range first and last specified, produces at most maxP partitions.

Parameters:
first - Date of beginning of time range
last - Date of end of time range
maxP - maximum number of Partitions to use
Returns:
a PartitionSize object which will divide the range into at most maxP Partitions

getRange

public List<Partition<T>> getRange(PartitionSize size,
                                   Date start,
                                   Date end)
Create a List of Partition objects of the specified size, which span the date range specified.

Parameters:
size - of Partitions to create
start - Date of beginning of time range to cover
end - Date of end of time range to cover
Returns:
List of Partitions spanning start and end, sized size, in date- ascending order.

populate

public void populate(List<Partition<T>> partitions,
                     Iterator<T> itr)
Add elements from itr into the appropriate partitions. Assumes that all elements fit in one of the argument Partitions, that the partitions are in ascending order by time, and that elements returned from the Iterator are in ascending time order.

Parameters:
partitions - to populate with objects
itr - ascending Iterator of objects to place into the partitions

dumpPartitions

public void dumpPartitions(List<Partition<T>> partitions)
Debugging method

Parameters:
partitions - to dump


Copyright © 2005-2011 Internet Archive. All Rights Reserved.