1 10 11 package org.mmbase.bridge.util; 12 13 import java.util.*; 14 import org.mmbase.bridge.*; 15 16 26 27 public class NodeMap extends NodeWrapper implements Map { 28 29 32 public NodeMap(Node node) { 33 super(node); 34 } 35 36 public void clear() { 38 throw new UnsupportedOperationException ("You cannot remove fields from a Node."); 40 } 41 42 public boolean containsKey(Object key) { 44 return getNodeManager().hasField((String ) key); 45 } 46 47 public boolean containsValue(Object value) { 50 Iterator i = entrySet().iterator(); 51 if (value==null) { 52 while (i.hasNext()) { 53 Entry e = (Entry) i.next(); 54 if (e.getValue()==null) { 55 return true; 56 } 57 } 58 } else { 59 while (i.hasNext()) { 60 Entry e = (Entry) i.next(); 61 if (value.equals(e.getValue())) { 62 return true; 63 } 64 } 65 } 66 return false; 67 } 68 69 public Object remove(Object key) { 71 throw new UnsupportedOperationException ("You cannot remove fields from a Node."); 72 } 73 74 public Set entrySet() { 76 return new AbstractSet() { 77 FieldList fields = getNodeManager().getFields(); 78 public Iterator iterator() { 79 return new Iterator() { 80 FieldIterator i = fields.fieldIterator(); 81 public boolean hasNext() { return i.hasNext();} 82 public Object next() { 83 return new Map.Entry() { 84 Field field = i.nextField(); 85 public Object getKey() { 86 return field.getName(); 87 } 88 public Object getValue() { 89 return NodeMap.this.getValue(field.getName()); 90 } 91 public Object setValue(Object value) { 92 Object r = getValue(); 93 NodeMap.this.setValue(field.getName(), value); 94 return r; 95 } 96 }; 97 } 98 public void remove() { 99 throw new UnsupportedOperationException ("You cannot remove fields from a Node."); 100 } 101 }; 102 } 103 public int size() { 104 return fields.size(); 105 } 106 }; 107 } 108 109 public Collection values() { 112 return new AbstractCollection() { 113 FieldList fields = getNodeManager().getFields(); 114 public Iterator iterator() { 115 return new Iterator() { 116 FieldIterator i = fields.fieldIterator(); 117 public boolean hasNext() { return i.hasNext();} 118 public Object next() { 119 Field field = i.nextField(); 120 return NodeMap.this.getValue(field.getName()); 121 } 122 public void remove() { 123 throw new UnsupportedOperationException ("You cannot remove fields from a Node."); 124 } 125 }; 126 } 127 public int size() { 128 return fields.size(); 129 } 130 }; 131 } 132 133 public Set keySet() { 135 return new AbstractSet() { 136 FieldList fields = getNodeManager().getFields(); 137 public Iterator iterator() { 138 return new Iterator() { 139 FieldIterator i = fields.fieldIterator(); 140 public boolean hasNext() { return i.hasNext();} 141 public Object next() { 142 Field field = i.nextField(); 143 return field.getName(); 144 } 145 public void remove() { 146 throw new UnsupportedOperationException ("You cannot remove fields from a Node."); 147 } 148 }; 149 } 150 public int size() { 151 return fields.size(); 152 } 153 }; 154 } 155 156 public void putAll(Map map) { 158 Iterator i = map.entrySet().iterator(); 159 while (i.hasNext()) { 160 Entry e = (Entry) i.next(); 161 setValue((String ) e.getKey(), e.getValue()); 162 } 163 } 164 165 public Object put(Object key, Object value) { 167 Object r = getValue((String ) key); 168 setValue((String ) key, value); 169 return r; 170 } 171 172 public Object get(Object key) { 174 return getValue((String ) key); 175 } 176 177 public boolean isEmpty() { 179 return false; 180 } 181 182 public int size() { 184 return getNodeManager().getFields().size(); 185 } 186 } 187 188
| Popular Tags
|