edu.stanford.nlp.util.CollectionFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-parser Show documentation
Show all versions of stanford-parser Show documentation
Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.
package edu.stanford.nlp.util;
import java.io.Serializable;
import java.util.*;
/**
* Factory for vending Collections. It's a class instead of an interface because I guessed that it'd primarily be used for its inner classes.
*
* @author Dan Klein ([email protected])
*/
public abstract class CollectionFactory implements Serializable {
private static final long serialVersionUID = 3711321773145894069L;
@SuppressWarnings("unchecked")
public static final CollectionFactory ARRAY_LIST_FACTORY = new ArrayListFactory();
@SuppressWarnings("unchecked")
public static final CollectionFactory LINKED_LIST_FACTORY = new LinkedListFactory();
@SuppressWarnings("unchecked")
public static final CollectionFactory HASH_SET_FACTORY = new HashSetFactory();
@SuppressWarnings("unchecked")
public static final CollectionFactory TREE_SET_FACTORY = new TreeSetFactory();
public abstract Collection newCollection();
public abstract Collection newEmptyCollection();
/** Return a factory for making ArrayList Collections.
* This method allows type safety in calling code.
*
* @return A factory for ArrayList collections.
*/
public static CollectionFactory arrayListFactory() {
return ErasureUtils.uncheckedCast(ARRAY_LIST_FACTORY);
}
public static CollectionFactory arrayListFactory(int size) {
return ErasureUtils.uncheckedCast(new SizedArrayListFactory(size));
}
public static CollectionFactory linkedListFactory() {
return ErasureUtils.uncheckedCast(LINKED_LIST_FACTORY);
}
public static CollectionFactory hashSetFactory() {
return ErasureUtils.uncheckedCast(HASH_SET_FACTORY);
}
public static CollectionFactory treeSetFactory() {
return ErasureUtils.uncheckedCast(TREE_SET_FACTORY);
}
public static class ArrayListFactory extends CollectionFactory {
private static final long serialVersionUID = 1L;
@Override
public Collection newCollection() {
return new ArrayList();
}
@Override
public Collection newEmptyCollection() {
return Collections.emptyList();
}
}
public static class SizedArrayListFactory extends CollectionFactory {
private static final long serialVersionUID = 1L;
private int defaultSize = 1;
public SizedArrayListFactory(int size)
{
this.defaultSize = size;
}
@Override
public Collection newCollection() {
return new ArrayList(defaultSize);
}
@Override
public Collection newEmptyCollection() {
return Collections.emptyList();
}
}
public static class LinkedListFactory extends CollectionFactory {
private static final long serialVersionUID = -4236184979948498000L;
@Override
public Collection newCollection() {
return new LinkedList();
}
@Override
public Collection newEmptyCollection() {
return Collections.emptyList();
}
}
public static class HashSetFactory extends CollectionFactory {
private static final long serialVersionUID = -6268401669449458602L;
@Override
public Collection newCollection() {
return Generics.newHashSet();
}
@Override
public Collection newEmptyCollection() {
return Collections.emptySet();
}
}
public static class TreeSetFactory extends CollectionFactory {
private static final long serialVersionUID = -3451920268219478134L;
@Override
public Collection newCollection() {
return new TreeSet();
}
@Override
public Collection newEmptyCollection() {
return Collections.emptySet();
}
}
}