01: /**
02: *
03: */package org.drools.util;
04:
05: import java.io.Serializable;
06:
07: import org.drools.common.InternalFactHandle;
08: import org.drools.reteoo.FactHandleMemory;
09: import org.drools.reteoo.ReteTuple;
10:
11: public class FactList implements FactHandleMemory {
12: private static final long serialVersionUID = 400L;
13:
14: private final LinkedList list;
15:
16: public FactList() {
17: this .list = new LinkedList();
18: }
19:
20: public Iterator iterator(final ReteTuple tuple) {
21: return iterator();
22: }
23:
24: public boolean add(final InternalFactHandle handle) {
25: return add(handle, true);
26: }
27:
28: public boolean add(final InternalFactHandle handle,
29: final boolean checkExists) {
30: this .list.add(new FactEntryImpl(handle));
31: return true;
32: }
33:
34: public boolean contains(final InternalFactHandle handle) {
35: Iterator it = this .list.iterator();
36: for (Object object = it.next(); object != null; object = it
37: .next()) {
38: if (handle.equals(((LinkedListEntry) object).getObject())) {
39: return true;
40: }
41: }
42: return false;
43: }
44:
45: public boolean remove(final InternalFactHandle handle) {
46: Iterator it = this .list.iterator();
47: for (Object object = it.next(); object != null; object = it
48: .next()) {
49: if (handle.equals(((LinkedListEntry) object).getObject())) {
50: this .list.remove((LinkedListEntry) object);
51: return true;
52: }
53: }
54: return false;
55: }
56:
57: public Iterator iterator() {
58: return this .list.iterator();
59: }
60:
61: public int size() {
62: return this .list.size();
63: }
64:
65: public boolean isIndexed() {
66: return false;
67: }
68:
69: public static class FactEntryImpl extends LinkedListEntry implements
70: FactEntry, Serializable {
71: public FactEntryImpl(InternalFactHandle handle) {
72: super (handle);
73: }
74:
75: public InternalFactHandle getFactHandle() {
76: return (InternalFactHandle) getObject();
77: }
78:
79: }
80: }
|