Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 22-39
Link Here
|
22 |
protected HashMap internal = new HashMap(); |
22 |
protected HashMap internal = new HashMap(); |
23 |
|
23 |
|
24 |
public void put(Object key, Object value) { |
24 |
public void put(Object key, Object value) { |
25 |
Object[] existing = (Object[]) internal.get(key); |
25 |
Object existing = internal.get(key); |
26 |
if (existing == null) { |
26 |
if (existing == null) { |
27 |
existing = new Object[1]; // be optimistic; start small |
27 |
internal.put(key, value); |
28 |
existing[0] = value; |
|
|
29 |
internal.put(key, existing); |
30 |
} else { |
28 |
} else { |
|
|
29 |
Object[] existingValues = existing.getClass().isArray() ? (Object[]) existing : new Object[] {existing}; |
31 |
// insert the new value |
30 |
// insert the new value |
32 |
int index = insertionIndex(existing, value); |
31 |
int index = insertionIndex(existingValues, value); |
33 |
Object[] newValues = new Object[existing.length + 1]; |
32 |
Object[] newValues = new Object[existingValues.length + 1]; |
34 |
System.arraycopy(existing, 0, newValues, 0, index); |
33 |
System.arraycopy(existingValues, 0, newValues, 0, index); |
35 |
newValues[index] = value; |
34 |
newValues[index] = value; |
36 |
System.arraycopy(existing, index, newValues, index + 1, existing.length - index); |
35 |
System.arraycopy(existingValues, index, newValues, index + 1, existingValues.length - index); |
37 |
internal.put(key, newValues); // overwrite the old values in the map |
36 |
internal.put(key, newValues); // overwrite the old values in the map |
38 |
} |
37 |
} |
39 |
} |
38 |
} |
Lines 56-63
Link Here
|
56 |
|
55 |
|
57 |
// gets all values with the specified and optionally removes them |
56 |
// gets all values with the specified and optionally removes them |
58 |
private Object[] get(Object key, boolean remove) { |
57 |
private Object[] get(Object key, boolean remove) { |
59 |
Object[] result = (Object[]) (remove ? internal.remove(key) : internal.get(key)); |
58 |
Object result = remove ? internal.remove(key) : internal.get(key); |
60 |
return result == null ? new Object[0] : result; |
59 |
if (result != null && result.getClass().isArray()) |
|
|
60 |
return (Object[]) result; |
61 |
return result == null ? new Object[0] : new Object[] {result}; |
61 |
} |
62 |
} |
62 |
|
63 |
|
63 |
// returns the number of keyed lists |
64 |
// returns the number of keyed lists |
Lines 72-80
Link Here
|
72 |
ArrayList results = new ArrayList(getSize()); |
73 |
ArrayList results = new ArrayList(getSize()); |
73 |
Iterator iter = internal.values().iterator(); |
74 |
Iterator iter = internal.values().iterator(); |
74 |
while (iter.hasNext()) { |
75 |
while (iter.hasNext()) { |
75 |
Object[] values = (Object[]) iter.next(); |
76 |
Object value = iter.next(); |
76 |
for (int i = 0; i < values.length; i++) |
77 |
if (value.getClass().isArray()) { |
77 |
results.add(values[i]); |
78 |
Object[] values = (Object[]) iter.next(); |
|
|
79 |
for (int i = 0; i < values.length; i++) |
80 |
results.add(values[i]); |
81 |
} else |
82 |
results.add(value); |
78 |
} |
83 |
} |
79 |
return results.toArray(); |
84 |
return results.toArray(); |
80 |
} |
85 |
} |