1 11 package org.eclipse.osgi.internal.module; 12 13 import java.util.*; 14 15 20 public class MappedList { 21 protected HashMap internal = new HashMap(); 23 24 public void put(Object key, Object value) { 25 Object [] existing = (Object []) internal.get(key); 26 if (existing == null) { 27 existing = new Object [1]; existing[0] = value; 29 internal.put(key, existing); 30 } else { 31 Object [] newValues = new Object [existing.length + 1]; 33 System.arraycopy(existing, 0, newValues, 0, existing.length); 34 newValues[existing.length] = value; 35 sort(newValues); internal.put(key, newValues); } 38 } 39 40 protected void sort(Object [] values) { 41 } 44 45 public Object [] remove(Object key) { 47 return get(key, true); 48 } 49 50 public Object [] get(Object key) { 52 return get(key, false); 53 } 54 55 private Object [] get(Object key, boolean remove) { 57 Object [] result = (Object []) (remove ? internal.remove(key) : internal.get(key)); 58 return result == null ? new Object [0] : result; 59 } 60 61 public int getSize() { 63 return internal.size(); 64 } 65 66 public Object [] getAllValues() { 68 if (getSize() == 0) 69 return new Object [0]; 70 ArrayList results = new ArrayList(getSize()); 71 Iterator iter = internal.values().iterator(); 72 while (iter.hasNext()) { 73 Object [] values = (Object []) iter.next(); 74 for (int i = 0; i < values.length; i++) 75 results.add(values[i]); 76 } 77 return results.toArray(); 78 } 79 80 public void clear() { 82 internal.clear(); 83 } 84 85 } 86 | Popular Tags |