View | Details | Raw Unified | Return to bug 269185 | Differences between
and this patch

Collapse All | Expand All

(-)resolver/src/org/eclipse/osgi/internal/module/MappedList.java (-14 / +19 lines)
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
	}
(-)resolver/src/org/eclipse/osgi/internal/module/VersionHashMap.java (-13 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 IBM Corporation and others.
2
 * Copyright (c) 2004, 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 42-61 Link Here
42
	}
42
	}
43
43
44
	private VersionSupplier contains(VersionSupplier vs, boolean remove) {
44
	private VersionSupplier contains(VersionSupplier vs, boolean remove) {
45
		Object[] existing = (Object[]) internal.get(vs.getName());
45
		Object existing = internal.get(vs.getName());
46
		if (existing == null)
46
		if (existing == null)
47
			return null;
47
			return null;
48
		for (int i = 0; i < existing.length; i++)
48
		if (existing == vs) {
49
			if (existing[i] == vs) {
49
			if (remove)
50
				internal.remove(vs.getName());
51
			return vs;
52
		}
53
		if (!existing.getClass().isArray())
54
			return null;
55
		Object[] existingValues = (Object[]) existing;
56
		for (int i = 0; i < existingValues.length; i++)
57
			if (existingValues[i] == vs) {
50
				if (remove) {
58
				if (remove) {
51
					if (existing.length == 1) {
59
					if (existingValues.length == 2) {
52
						internal.remove(vs.getName());
60
						internal.put(vs.getName(), existingValues[i == 0 ? 1 : 0]);
53
						return vs;
61
						return vs;
54
					}
62
					}
55
					Object[] newExisting = new Object[existing.length - 1];
63
					Object[] newExisting = new Object[existingValues.length - 1];
56
					System.arraycopy(existing, 0, newExisting, 0, i);
64
					System.arraycopy(existingValues, 0, newExisting, 0, i);
57
					if (i + 1 < existing.length)
65
					if (i + 1 < existingValues.length)
58
						System.arraycopy(existing, i + 1, newExisting, i, existing.length - i - 1);
66
						System.arraycopy(existingValues, i + 1, newExisting, i, existingValues.length - i - 1);
59
					internal.put(vs.getName(), newExisting);
67
					internal.put(vs.getName(), newExisting);
60
				}
68
				}
61
				return vs;
69
				return vs;
Lines 76-85 Link Here
76
	// from the resolved bundles are ahead of those from unresolved bundles
84
	// from the resolved bundles are ahead of those from unresolved bundles
77
	void reorder() {
85
	void reorder() {
78
		for (Iterator it = internal.values().iterator(); it.hasNext();) {
86
		for (Iterator it = internal.values().iterator(); it.hasNext();) {
79
			Object[] existing = (Object[]) it.next();
87
			Object existing = it.next();
80
			if (existing.length <= 1)
88
			if (!existing.getClass().isArray())
81
				continue;
89
				continue;
82
			Arrays.sort(existing, this);
90
			Arrays.sort((Object[]) existing, this);
83
		}
91
		}
84
	}
92
	}
85
93

Return to bug 269185