LimeWire Collection Component API

org.limewire.collection
Class ListPartitioner<E>

java.lang.Object
  extended by org.limewire.collection.ListPartitioner<E>

public class ListPartitioner<E>
extends Object

Partitions a list into sublists with equal size. The remainder items in the list are included with the last sublist. For example, list = {1,2,3,4,5} and 2 partitions makes subList1 = {1,2} and subList2 = {3,4,5}.

    LinkedList<String> list = new LinkedList<String>();
    for(int i = 1; i < 6; i++)
        list.add(String.valueOf(i));
    System.out.println(list);

    ListPartitioner<String> lp = new ListPartitioner<String>(list, 2);
    List<String> p1 = lp.getPartition(0);
    List<String> p2 = lp.getPartition(1);

    System.out.println("partition 1: " + p1);
    System.out.println("partition 2: " + p2);

    Output:
        [1, 2, 3, 4, 5]
        partition 1: [1, 2]
        partition 2: [3, 4, 5]


Constructor Summary
ListPartitioner(List<E> list, int numPartitions)
           
 
Method Summary
 List<E> getFirstPartition()
           
 List<E> getLastPartition()
           
 List<E> getPartition(int index)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListPartitioner

public ListPartitioner(List<E> list,
                       int numPartitions)
Method Detail

getPartition

public List<E> getPartition(int index)

getLastPartition

public List<E> getLastPartition()

getFirstPartition

public List<E> getFirstPartition()

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.