1 24 package org.objectweb.jalisto.se.query.result; 25 26 import org.objectweb.jalisto.se.impl.LogicalOid; 27 import org.objectweb.jalisto.se.api.Session; 28 29 import java.util.*; 30 31 public class WrapperSet { 32 33 public WrapperSet() { 34 this.readedWrappers = new HashMap(); 35 this.noneReadedWrappers = new HashMap(); 36 } 37 38 public int size() { 39 return readedWrappers.size() + noneReadedWrappers.size(); 40 } 41 42 public boolean isEmpty() { 43 return readedWrappers.isEmpty() && noneReadedWrappers.isEmpty(); 44 } 45 46 public boolean contains(QueryResultWrapper w) { 47 return readedWrappers.containsKey(w.getLogicalOid()) || noneReadedWrappers.containsKey(w.getLogicalOid()); 48 } 49 50 public int containsIn(QueryResultWrapper w) { 54 if (readedWrappers.containsKey(w.getLogicalOid())) 55 return -1; 56 if (noneReadedWrappers.containsKey(w.getLogicalOid())) 57 return 1; 58 return 0; 59 } 60 61 public Iterator iterator() { 62 ArrayList list = new ArrayList(); 63 list.addAll(readedWrappers.values()); 64 list.addAll(noneReadedWrappers.values()); 65 return list.iterator(); 66 } 67 68 public void add(QueryResultWrapper w) { 69 if (w.getValue() == null) { 70 noneReadedWrappers.put(w.getLogicalOid(), w); 71 } else { 72 readedWrappers.put(w.getLogicalOid(), w); 73 } 74 } 75 76 public void addToUnread(QueryResultWrapper w) { 77 noneReadedWrappers.put(w.getLogicalOid(), w); 78 } 79 80 public void addToRead(QueryResultWrapper w) { 81 readedWrappers.put(w.getLogicalOid(), w); 82 } 83 84 public void addAll(Collection collection) { 85 Iterator iterator = collection.iterator(); 86 while (iterator.hasNext()) { 87 add((QueryResultWrapper) iterator.next()); 88 } 89 } 90 91 public void addAll(WrapperSet wSet) { 92 readedWrappers.putAll(wSet.readedWrappers); 93 noneReadedWrappers.putAll(wSet.noneReadedWrappers); 94 } 95 96 public QueryResultWrapper get(Object key) { 97 if (readedWrappers.containsKey(key)) { 98 return (QueryResultWrapper) readedWrappers.get(key); 99 } else { 100 return (QueryResultWrapper) noneReadedWrappers.get(key); 101 } 102 } 103 104 public Set getCopyInSet() { 105 HashSet result = new HashSet(); 106 result.addAll(readedWrappers.values()); 107 result.addAll(noneReadedWrappers.values()); 108 return result; 109 } 110 111 public void remove(QueryResultWrapper w) { 112 Object loid = w.getLogicalOid(); 113 if (readedWrappers.remove(loid) == null) { 114 noneReadedWrappers.remove(loid); 115 } 116 } 117 118 public void clear() { 119 readedWrappers.clear(); 120 noneReadedWrappers.clear(); 121 } 122 123 public void readAll(Session session, Map valueMap) { 124 Iterator none = noneReadedWrappers.values().iterator(); 125 while (none.hasNext()) { 126 QueryResultWrapper wrapper = (QueryResultWrapper) none.next(); 127 LogicalOid loid = wrapper.getLogicalOid(); 128 if (valueMap.containsKey(loid)) { 129 wrapper.setValue((Object []) valueMap.get(loid)); 130 } else { 131 Object [] value = session.readObjectByOid(loid); 132 wrapper.setValue(value); 133 valueMap.put(loid, value); 134 } 135 readedWrappers.put(loid, wrapper); 136 } 137 noneReadedWrappers.clear(); 138 } 139 140 private Map readedWrappers; 141 private Map noneReadedWrappers; 142 } 143 | Popular Tags |