01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.type;
10:
11: import java.util.ArrayList;
12: import java.util.Collection;
13:
14: /**
15: * @author Gennady Krizhevsky
16: */
17: public class ArrayListCollectionFactory extends
18: AbstractListCollectionFactory {
19:
20: public static final NullArrayListFactory NULL_ARRAY_LIST_FACTORY = new NullArrayListFactory();
21:
22: public ArrayListCollectionFactory() {
23: }
24:
25: public Collection newCollection() {
26: return new ArrayList();
27: }
28:
29: private static final ArrayListCollectionFactory FACTORY = new ArrayListCollectionFactory();
30:
31: public static ArrayListCollectionFactory factory() {
32: return FACTORY;
33: }
34:
35: public CollectionFactory nullCollectionFactory() {
36: return NULL_ARRAY_LIST_FACTORY;
37: }
38:
39: private static class NullArrayListFactory implements
40: CollectionFactory {
41: public Collection newCollection() {
42: return NULL_ARRAY_LIST;
43: }
44:
45: public CollectionFactory nullCollectionFactory() {
46: return this ;
47: }
48: }
49:
50: public static final NullArrayList NULL_ARRAY_LIST = new NullArrayList();
51:
52: private static final class NullArrayList extends ArrayList {
53:
54: public NullArrayList(int initialCapacity) {
55: }
56:
57: public NullArrayList() {
58: }
59:
60: public NullArrayList(Collection collection) {
61: }
62:
63: public Object get(int index) {
64: return null;
65: }
66:
67: public int size() {
68: return 0;
69: }
70:
71: public boolean add(Object o) {
72: return false;
73: }
74:
75: public boolean contains(Object obj) {
76: return false;
77: }
78:
79: // Preserves singleton property
80: private Object readResolve() {
81: return NULL_ARRAY_LIST;
82: }
83: }
84:
85: public static void main(String[] args) {
86: NULL_ARRAY_LIST.remove("");
87: }
88:
89: }
|