/**
* Objective Database Abstraction Layer (ODAL)
* Copyright (c) 2004, The ODAL Development Group
* All rights reserved.
* For definition of the ODAL Development Group please refer to LICENCE.txt file
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package com.completex.objective.components.persistency.type;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.NoSuchElementException;
/**
* @author Gennady Krizhevsky
*/
public class LinkedHashSetCollectionFactory extends AbstractSetCollectionFactory implements CollectionFactory {
public static final NullLinkedHashSetFactory NULL_LINKED_HASH_SET_FACTORY = new NullLinkedHashSetFactory();
public Collection newCollection() {
return new LinkedHashSet();
}
private static final LinkedHashSetCollectionFactory FACTORY = new LinkedHashSetCollectionFactory();
public static LinkedHashSetCollectionFactory factory() {
return FACTORY;
}
public CollectionFactory nullCollectionFactory() {
return NULL_LINKED_HASH_SET_FACTORY;
}
private static class NullLinkedHashSetFactory implements CollectionFactory {
public Collection newCollection() {
return NULL_LINKED_HASH_SET;
}
public CollectionFactory nullCollectionFactory() {
return this;
}
}
public static final NullLinkedHashSet NULL_LINKED_HASH_SET = new NullLinkedHashSet();
private static class NullLinkedHashSet extends LinkedHashSet {
public NullLinkedHashSet() {
}
public NullLinkedHashSet(Collection collection) {
}
public NullLinkedHashSet(int initialCapacity, float loadFactor) {
}
public NullLinkedHashSet(int initialCapacity) {
}
public Iterator iterator() {
return new Iterator() {
public boolean hasNext() {
return false;
}
public Object next() {
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
public int size() {
return 0;
}
public boolean contains(Object obj) {
return false;
}
// Preserves singleton property
private Object readResolve() {
return NULL_LINKED_HASH_SET;
}
public boolean add(Object o) {
return false;
}
}
public static void main(String[] args) {
NULL_LINKED_HASH_SET.remove("");
}
}
|