org.expasy.jpl.commons.collection
Class PartitionList<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<List<T>>
          extended by org.expasy.jpl.commons.collection.PartitionList<T>
Type Parameters:
T - the list element object.
All Implemented Interfaces:
Iterable<List<T>>, Collection<List<T>>, List<List<T>>

public final class PartitionList<T>
extends AbstractList<List<T>>

This object is a partition of a List that proposes a view of smaller split Lists.

Based on article:

http://www.vogella.de/articles/JavaAlgorithmsPartitionCollection/article.html

Version:
1.0
Author:
Lars Vogel, Nikitin

Nested Class Summary
static interface PartitionList.IndexingAlgo<T>
           
static interface PartitionList.LastIndexingAlgo<T>
           
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Method Summary
 void checkBounds(int i)
          Get the indices of T-objects int the ith partition.
 List<T> get(int i)
           
 IntegerSequence getIndices(int i)
          Get the indices of T-objects of partition i.
 int[] getInterval(int i)
          Get the indices of T-objects of partition i.
 List<T> getList()
           
 int getMaxBucketCapacity()
           
 int indexOf(Object value)
           
 int indexOf(Object value, PartitionList.IndexingAlgo<T> algo)
           
 boolean isEmpty()
           
 int lastIndexOf(Object value)
           
 int lastIndexOf(Object value, PartitionList.LastIndexingAlgo<T> algo)
           
 int size()
           
static
<T> PartitionList<T>
withBucketCapacity(List<T> list, int maxBucketCapacity)
          Make a partition from a given list and a partition capacity.
static
<T> PartitionList<T>
withBucketNumber(List<T> list, int bucketNumber)
          Make a partition from a given list and a bucket number.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, iterator, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 

Method Detail

withBucketCapacity

public static <T> PartitionList<T> withBucketCapacity(List<T> list,
                                                      int maxBucketCapacity)
Make a partition from a given list and a partition capacity.

Parameters:
list - the list to partition.
maxBucketCapacity - the max partition capacity.
Returns:
a partition list.

withBucketNumber

public static <T> PartitionList<T> withBucketNumber(List<T> list,
                                                    int bucketNumber)
Make a partition from a given list and a bucket number.

Parameters:
list - the list to divide.
bucketNumber - the number of partitions.
Returns:
a partition list.

get

public final List<T> get(int i)
Specified by:
get in interface List<List<T>>
Specified by:
get in class AbstractList<List<T>>

getList

public final List<T> getList()
Returns:
the whole list.

getInterval

public int[] getInterval(int i)
Get the indices of T-objects of partition i.

Parameters:
i - the partition index.
Returns:
a list of indices.

getIndices

public IntegerSequence getIndices(int i)
Get the indices of T-objects of partition i.

Parameters:
i - the partition index.
Returns:
a list of indices.

checkBounds

public void checkBounds(int i)
Get the indices of T-objects int the ith partition.

Parameters:
i - the partition index.

size

public int size()
Specified by:
size in interface Collection<List<T>>
Specified by:
size in interface List<List<T>>
Specified by:
size in class AbstractCollection<List<T>>

getMaxBucketCapacity

public int getMaxBucketCapacity()
Returns:
the maxBucketSize

indexOf

public int indexOf(Object value)
Specified by:
indexOf in interface List<List<T>>
Overrides:
indexOf in class AbstractList<List<T>>

indexOf

public int indexOf(Object value,
                   PartitionList.IndexingAlgo<T> algo)

lastIndexOf

public int lastIndexOf(Object value)
Specified by:
lastIndexOf in interface List<List<T>>
Overrides:
lastIndexOf in class AbstractList<List<T>>

lastIndexOf

public int lastIndexOf(Object value,
                       PartitionList.LastIndexingAlgo<T> algo)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<List<T>>
Specified by:
isEmpty in interface List<List<T>>
Overrides:
isEmpty in class AbstractCollection<List<T>>


Copyright (c) 2012 Swiss Institute of Bioinformatics. All rights reserved.