The following document contains the results of PMD's CPD 4.2.5.
File | Line |
---|---|
cz/cuni/amis/utils/astar/AStarHeap.java | 21 |
cz/cuni/amis/utils/heap/Heap.java | 16 |
public class Heap<NODE> implements IHeap<NODE> { /** * First element is always null, nodes are stored beginning with index [1]. */ private NODE[] nodes; private int count; private int items; private HashMap<NODE, Integer> references; private Comparator<NODE> cmp; private void grow(){ NODE[] tempNodes = (NODE[]) new Object[count*2]; for (int i = 0; i <= items; ++i){ tempNodes[i] = nodes[i]; } nodes = tempNodes; count = count * 2; } private int left(int reference){ return 2*reference; } private int right(int reference){ return 2*reference+1; } private int upRef(int reference){ return reference / 2; } private NODE getNode(int reference){ while (reference >= count) grow(); return nodes[reference]; } private int downNode(int reference){ NODE currentNode = getNode(reference); if (currentNode == null) { return reference; } NODE leftNode = null; NODE rightNode = null; int way = 0; while (true){ way = 0; leftNode = getNode(left(reference)); rightNode = getNode(right(reference)); if ((leftNode == null) && (rightNode == null)){ references.put(currentNode, reference); return reference; } if (rightNode == null) way = -1; else if (leftNode == null) way = 1; if (way == 0) way = cmp.compare(leftNode, rightNode); if (way < 0){ // we've got to ascend to the left if (cmp.compare(currentNode, leftNode) > 0){ nodes[reference] = leftNode; references.put(leftNode, new Integer(reference)); reference = left(reference); nodes[reference] = currentNode; } else { references.put(currentNode, reference); return reference; } } else { // we've got to ascend to the right if (cmp.compare(currentNode, rightNode) > 0){ nodes[reference] = rightNode; references.put(rightNode, new Integer(reference)); reference = right(reference); nodes[reference] = currentNode; } else { references.put(currentNode, reference); return reference; } } } } private int upNode(int reference){ if (reference == 1) return reference; NODE currentNode = getNode(reference); if (currentNode == null) return reference; NODE upNode = null; while (reference > 1){ upNode = getNode(upRef(reference)); if (cmp.compare(currentNode, upNode) < 0){ nodes[reference] = upNode; references.put(upNode, reference); reference = upRef(reference); } else { break; } } nodes[reference] = currentNode; references.put(currentNode, reference); return reference; } private void initHeap(int capacity){ if (capacity < 2) capacity = 2; nodes = (NODE[]) new Object[capacity]; count = capacity; items = 0; references = new HashMap(capacity); } public Heap(Comparator<NODE> comp, int capacity){ |
File | Line |
---|---|
cz/cuni/amis/utils/maps/HashTriMap.java | 37 |
cz/cuni/amis/utils/maps/WeakHashTriMap.java | 47 |
public WeakHashTriMap( int primaryCapacity, int secondaryCapacity, int tertiaryCapacity) { super(primaryCapacity); this.secondaryCapacity = secondaryCapacity; this.tertiaryCapacity = tertiaryCapacity; } /** * Returns a HashMap<SECONDARY_KEY,HashMap<TERTIARY_KEY,ITEM>> * Never returns null, if the map under primary key doesn't exist, an empty one is added and returned. * @param primaryKey * @return */ @SuppressWarnings("unchecked") @Override public Map<SECONDARY_KEY, Map<TERTIARY_KEY,ITEM>> get(Object primaryKey) { Map<SECONDARY_KEY, Map<TERTIARY_KEY,ITEM>> result = super.get(primaryKey); if (result != null) { return result; }; result = Collections.synchronizedMap( new HashMapMap<SECONDARY_KEY,TERTIARY_KEY,ITEM>(secondaryCapacity, tertiaryCapacity) ); super.put( (PRIMARY_KEY)primaryKey,result); return result; } /** * Returns the requested map, never returns null. * If the map does not exist an empty map is created and returned. * @param primaryKey * @param secondaryKey * @return */ public Map<TERTIARY_KEY,ITEM> get(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey) { Map<TERTIARY_KEY, ITEM> result = get(primaryKey).get(secondaryKey); if (result != null) { return result; }; result = Collections.synchronizedMap( new HashMap<TERTIARY_KEY,ITEM>( tertiaryCapacity )); get(primaryKey).put(secondaryKey, result); return result; } /** * Returns item specified, returns null if item does not appear in the map. * @param primaryKey * @param secondaryKey * @param tertiaryKey * @return */ public ITEM get(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, TERTIARY_KEY tertiaryKey) { return get(primaryKey,secondaryKey).get(tertiaryKey); } /** * Puts the item into the map. * @param primaryKey * @param secondaryKey * @param tertiaryKey * @param item */ public void put(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, TERTIARY_KEY tertiaryKey, ITEM item) { get(primaryKey,secondaryKey).put(tertiaryKey, item); } /** * Removes the requested map. If the map doesn't exist, returns an empty map. */ @Override public Map<SECONDARY_KEY, Map<TERTIARY_KEY,ITEM>> remove(Object primaryKey) { Map<SECONDARY_KEY, Map<TERTIARY_KEY,ITEM>> result = super.remove(primaryKey); if (result != null) { return result; }; return Collections.synchronizedMap( new HashMapMap<SECONDARY_KEY, TERTIARY_KEY,ITEM>(secondaryCapacity, tertiaryCapacity) ); } /** * removes the map under primary and secondary key, if the map does not exist, * the data structure is not changed and a new map is returned. * @param primaryKey * @param secondaryKey * @return */ public Map<TERTIARY_KEY,ITEM> remove(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey) { Map<TERTIARY_KEY,ITEM> result = get(primaryKey).remove(secondaryKey); if ( result != null) { return result; }; return Collections.synchronizedMap( new HashMap<TERTIARY_KEY, ITEM> (tertiaryCapacity)); } /** * Returns the item under specified keys and removes it from the map, * returns null if item is not present in the map. * @param primaryKey * @param secondaryKey * @param tertiaryKey * @return */ public ITEM remove(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, TERTIARY_KEY tertiaryKey) { return get(primaryKey,secondaryKey).remove(tertiaryKey); } } |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 223 |
cz/cuni/amis/utils/listener/Listeners.java | 262 |
public int removeListener(EventListener listener) { if (listener == null) return 0; int removed = 0; synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (listener == storedListener) { |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 384 |
cz/cuni/amis/utils/listener/Listeners.java | 423 |
public boolean isListening(EventListener listener) { if (listener == null) return false; synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (listener == storedListener) { |
File | Line |
---|---|
cz/cuni/amis/utils/astar/AStarHeap.java | 165 |
cz/cuni/amis/utils/heap/Heap.java | 188 |
public boolean add(NODE arg0) { Integer reference = (Integer)references.get(arg0); if (reference == null){ getNode(items+1); // ensure that capacity is sufficient nodes[items+1] = arg0; upNode(items+1); items = items + 1; return true; } else { int tempRef = upNode(reference.intValue()); if (tempRef == reference.intValue()) downNode(reference.intValue()); return true; } } @Override public boolean addAll(Collection arg0) { Iterator<NODE> iter = arg0.iterator(); while (iter.hasNext()) add(iter.next()); return true; } |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 226 |
cz/cuni/amis/utils/listener/Listeners.java | 386 |
synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (listener.equals(storedListener)) { |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 265 |
cz/cuni/amis/utils/listener/Listeners.java | 425 |
synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (listener == storedListener) { |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 226 |
cz/cuni/amis/utils/listener/Listeners.java | 425 |
synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (listener == storedListener) { |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 226 |
cz/cuni/amis/utils/listener/Listeners.java | 498 |
synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } if (remover.remove(storedListener)) { |
File | Line |
---|---|
cz/cuni/amis/utils/listener/Listeners.java | 226 |
cz/cuni/amis/utils/listener/Listeners.java | 303 |
synchronized(listeners) { boolean listenersIterationOriginal = listenersIteration; listenersIteration = true; try { Iterator<ListenerStore<Listener>> iterator = listeners.iterator(); while(iterator.hasNext()) { ListenerStore<Listener> store = iterator.next(); Listener storedListener = store.getListener(); if (storedListener == null) { if (!listenersIterationOriginal) { if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) { log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed."); } iterator.remove(); } continue; } |
File | Line |
---|---|
cz/cuni/amis/utils/maps/HashMapMap.java | 48 |
cz/cuni/amis/utils/maps/LazyMapMap.java | 46 |
}); super.put((PRIMARY_KEY)primaryKey, map); return map; } /** * Returns an item under primary and secondary key if exists (otherwise a null is returned). * @param primaryKey * @param secondaryKey * @return */ public ITEM get(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey) { return get(primaryKey).get(secondaryKey); } /** * Inserts an item under primary and then secondary key. * @param primaryKey * @param secondaryKey * @param item */ public void put(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, ITEM item) { get(primaryKey).put(secondaryKey, item); } /** * Remove returns the removed item, if item was non-existent, it returns empty map. * @param primaryKey * @return */ @Override public Map<SECONDARY_KEY, ITEM> remove(Object primaryKey) { Map<SECONDARY_KEY, ITEM> map = super.remove(primaryKey); if (map != null) return map; return Collections.synchronizedMap(new LazyMap<SECONDARY_KEY, ITEM>(){ |