@Test public void putAll() { MapPM<Integer, DummyPM> map = new MapPM<Integer, DummyPM>(); final int NUM = 10; populate(map, NUM); int MORE = 10; HashMap<Integer, DummyPM> hashmap = new HashMap<Integer, DummyPM>(); for (int i = NUM; i < NUM + MORE; ++i) { hashmap.put(i, new DummyPM()); } EventCounter counter = new EventCounter(); map.addListListener(counter); map.putAll(hashmap); assertEquals("map.size()", NUM + MORE, map.size()); assertEquals("map.getSelection().size()", 0, map.getSelectedKeys().size()); assertEquals("map.getSelection().getMaxIndex()", -1, map.getSelection().getMaxIndex()); assertEquals("map.getSelection().getMinIndex()", -1, map.getSelection().getMinIndex()); assertEquals("counter.elementsAdded", 1, counter.elementsAdded); assertEquals("counter.elementsRemoved", 0, counter.elementsRemoved); assertEquals("counter.elementReplaced", 0, counter.elementsReplaced); assertEquals("counter.elementsDeselected", 0, counter.elementsDeselected); assertEquals("counter.elementsSelected", 0, counter.elementsSelected); for (int i = 0; i < NUM; ++i) { assertFalse("map.containsValue(pM.getAt(i))", hashmap.containsValue(map.getAt(i))); } for (int i = NUM; i < NUM + MORE; ++i) { assertTrue("map.containsValue(pM.getAt(i))", hashmap.containsValue(map.getAt(i))); } }
public void putAll(Map<K, V> aMap) { HashSet<K> duplicateKeys = new HashSet<K>(aMap.keySet()); duplicateKeys.retainAll(this.entries.keySetReference()); int[] indices = indicesOfKeys(duplicateKeys); Interval[] aintv = Interval.createIntervals(indices); for (Interval intv : aintv) { LinkedList<V> replaced = new LinkedList<V>(); for (int index = intv.startIndex; index <= intv.endIndex; index++) { K key = getKey(index); V newValue = aMap.get(key); V old = this.entries.put(key, newValue); onRemove(old); replaced.add(old); onAdd(newValue); } support.fireElementsReplaced(intv.startIndex, intv.endIndex - intv.startIndex + 1, (Collection<PresentationModel>)replaced); } Map<K, V> newMap = new HashMap<K, V>(aMap); newMap.keySet().removeAll(duplicateKeys); if (newMap.size() > 0) { int beginIndex = entries.size(); entries.putAll(aMap); for (V element : newMap.values()) { onAdd(element); } support.fireElementsAdded(beginIndex, newMap.size()); } }
MapPM extends AbstractPM implements IMapPM<K, V> { public void putAll(Map<K, V> aMap) { HashSet<K> duplicateKeys = new HashSet<K>(aMap.keySet()); duplicateKeys.retainAll(this.entries.keySetReference()); int[] indices = indicesOfKeys(duplicateKeys); Interval[] aintv = Interval.createIntervals(indices); for (Interval intv : aintv) { LinkedList<V> replaced = new LinkedList<V>(); for (int index = intv.startIndex; index <= intv.endIndex; index++) { K key = getKey(index); V newValue = aMap.get(key); V old = this.entries.put(key, newValue); onRemove(old); replaced.add(old); onAdd(newValue); } support.fireElementsReplaced(intv.startIndex, intv.endIndex - intv.startIndex + 1, (Collection<PresentationModel>)replaced); } Map<K, V> newMap = new HashMap<K, V>(aMap); newMap.keySet().removeAll(duplicateKeys); if (newMap.size() > 0) { int beginIndex = entries.size(); entries.putAll(aMap); for (V element : newMap.values()) { onAdd(element); } support.fireElementsAdded(beginIndex, newMap.size()); } } }
MapPM extends AbstractPM implements IMapPM<K, V> { public void putAll(Map<K, V> aMap) { HashSet<K> duplicateKeys = new HashSet<K>(aMap.keySet()); duplicateKeys.retainAll(this.entries.keySetReference()); int[] indices = indicesOfKeys(duplicateKeys); Interval[] aintv = Interval.createIntervals(indices); for (Interval intv : aintv) { LinkedList<V> replaced = new LinkedList<V>(); for (int index = intv.startIndex; index <= intv.endIndex; index++) { K key = getKey(index); V newValue = aMap.get(key); V old = this.entries.put(key, newValue); onRemove(old); replaced.add(old); onAdd(newValue); } support.fireElementsReplaced(intv.startIndex, intv.endIndex - intv.startIndex + 1, (Collection<PresentationModel>)replaced); } Map<K, V> newMap = new HashMap<K, V>(aMap); newMap.keySet().removeAll(duplicateKeys); if (newMap.size() > 0) { int beginIndex = entries.size(); entries.putAll(aMap); for (V element : newMap.values()) { onAdd(element); } support.fireElementsAdded(beginIndex, newMap.size()); } } MapPM(); }
MapPM extends AbstractPM implements IMapPM<K, V> { public void putAll(Map<K, V> aMap) { HashSet<K> duplicateKeys = new HashSet<K>(aMap.keySet()); duplicateKeys.retainAll(this.entries.keySetReference()); int[] indices = indicesOfKeys(duplicateKeys); Interval[] aintv = Interval.createIntervals(indices); for (Interval intv : aintv) { LinkedList<V> replaced = new LinkedList<V>(); for (int index = intv.startIndex; index <= intv.endIndex; index++) { K key = getKey(index); V newValue = aMap.get(key); V old = this.entries.put(key, newValue); onRemove(old); replaced.add(old); onAdd(newValue); } support.fireElementsReplaced(intv.startIndex, intv.endIndex - intv.startIndex + 1, (Collection<PresentationModel>)replaced); } Map<K, V> newMap = new HashMap<K, V>(aMap); newMap.keySet().removeAll(duplicateKeys); if (newMap.size() > 0) { int beginIndex = entries.size(); entries.putAll(aMap); for (V element : newMap.values()) { onAdd(element); } support.fireElementsAdded(beginIndex, newMap.size()); } } MapPM(); Sorter getSorter(); void setSorter(Sorter sorter); boolean isRevalidateElementsOnChangeEnabled(); void setRevalidateElementsOnChangeEnabled(boolean enabled); void revalidateElements(); boolean isEmpty(); void clear(); V put(K key, V newElement); V put(K key, V newElement, int toIndex); void swap(int indexA, int indexB); void swap(V elemA, V elemB); void reverse(); void sortBy(boolean ascending, Path... paths); void sortBy(Collection<SortKey> newSortKeys); void sortBy(SortKey... newSortKeys); Collection<SortKey> getSortKeys(); int size(); Collection<V> getAll(int startIndex, int endIndex); Collection<V> getAll(int[] indices); V getAt(int index); V get(K key); V removeAt(int index); V removeKey(K key); boolean remove(V elem); boolean removeAll(Collection<? extends V> col); Collection<V> toCollection(); Map<K, V> toMap(); Object[] toArray(); Set<K> keySet(); boolean containsKey(K key); boolean contains(V element); int indexOfKey(K key); int indexOf(V element); int[] indicesOfKeys(Collection<K> keys); int[] indicesOf(Collection elements); K getKey(V element); K getKey(int index); List<K> getKeys(int beginIndex, int endIndex); Set<K> getKeys(int[] indices); Set<K> getKeys(Collection<?> col); SelectedKeys<K> getSelectedKeys(); Selection<V> getSelection(); void addListListener(ListListener l); void removeListListener(ListListener l); Iterator<V> iterator(); ListIterator<V> listIterator(final int index); Iterator<K> keyiterator(); Collection<V> removeAllKeys(Set<K> keySet); Collection<V> retainAllKeys(Set<K> keySet); Collection<V> removeAllIndices(int[] indices); void putAll(Map<K, V> aMap); void putAll(Collection<Entry<K, V>> aEntries); void setAll(Map<K, V> newMap); }
MapPM extends AbstractPM implements IMapPM<K, V> { public void putAll(Map<K, V> aMap) { HashSet<K> duplicateKeys = new HashSet<K>(aMap.keySet()); duplicateKeys.retainAll(this.entries.keySetReference()); int[] indices = indicesOfKeys(duplicateKeys); Interval[] aintv = Interval.createIntervals(indices); for (Interval intv : aintv) { LinkedList<V> replaced = new LinkedList<V>(); for (int index = intv.startIndex; index <= intv.endIndex; index++) { K key = getKey(index); V newValue = aMap.get(key); V old = this.entries.put(key, newValue); onRemove(old); replaced.add(old); onAdd(newValue); } support.fireElementsReplaced(intv.startIndex, intv.endIndex - intv.startIndex + 1, (Collection<PresentationModel>)replaced); } Map<K, V> newMap = new HashMap<K, V>(aMap); newMap.keySet().removeAll(duplicateKeys); if (newMap.size() > 0) { int beginIndex = entries.size(); entries.putAll(aMap); for (V element : newMap.values()) { onAdd(element); } support.fireElementsAdded(beginIndex, newMap.size()); } } MapPM(); Sorter getSorter(); void setSorter(Sorter sorter); boolean isRevalidateElementsOnChangeEnabled(); void setRevalidateElementsOnChangeEnabled(boolean enabled); void revalidateElements(); boolean isEmpty(); void clear(); V put(K key, V newElement); V put(K key, V newElement, int toIndex); void swap(int indexA, int indexB); void swap(V elemA, V elemB); void reverse(); void sortBy(boolean ascending, Path... paths); void sortBy(Collection<SortKey> newSortKeys); void sortBy(SortKey... newSortKeys); Collection<SortKey> getSortKeys(); int size(); Collection<V> getAll(int startIndex, int endIndex); Collection<V> getAll(int[] indices); V getAt(int index); V get(K key); V removeAt(int index); V removeKey(K key); boolean remove(V elem); boolean removeAll(Collection<? extends V> col); Collection<V> toCollection(); Map<K, V> toMap(); Object[] toArray(); Set<K> keySet(); boolean containsKey(K key); boolean contains(V element); int indexOfKey(K key); int indexOf(V element); int[] indicesOfKeys(Collection<K> keys); int[] indicesOf(Collection elements); K getKey(V element); K getKey(int index); List<K> getKeys(int beginIndex, int endIndex); Set<K> getKeys(int[] indices); Set<K> getKeys(Collection<?> col); SelectedKeys<K> getSelectedKeys(); Selection<V> getSelection(); void addListListener(ListListener l); void removeListListener(ListListener l); Iterator<V> iterator(); ListIterator<V> listIterator(final int index); Iterator<K> keyiterator(); Collection<V> removeAllKeys(Set<K> keySet); Collection<V> retainAllKeys(Set<K> keySet); Collection<V> removeAllIndices(int[] indices); void putAll(Map<K, V> aMap); void putAll(Collection<Entry<K, V>> aEntries); void setAll(Map<K, V> newMap);  }