Author: mbrohl
Date: Mon Dec 11 06:34:02 2017 New Revision: 1817743 URL: http://svn.apache.org/viewvc?rev=1817743&view=rev Log: Improved: General refactoring and code improvements, package org.apache.ofbiz.base.util.collections. (OFBIZ-9860) Thanks Dennis Balkir for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapCollection.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntrySet.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapSet.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/IteratorWrapper.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/LifoSet.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapComparator.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapStack.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/PagedList.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java Mon Dec 11 06:34:02 2017 @@ -52,7 +52,9 @@ public abstract class GenericMap<K, V> i } public final void clear() { - if (isEmpty()) return; + if (isEmpty()) { + return; + } incrementModCount(); clearInternal(); } @@ -65,11 +67,19 @@ public abstract class GenericMap<K, V> i @Override public boolean equals(Object o) { - if (!(o instanceof Map<?, ?>)) return false; - if (this == o) return true; + if (!(o instanceof Map<?, ?>)) { + return false; + } + if (this == o) { + return true; + } Map<?, ?> map = (Map<?, ?>) o; - if (size() != map.size()) return false; - if (o instanceof GenericMap<?, ?>) return equalsGenericMap((GenericMap<?, ?>) o); + if (size() != map.size()) { + return false; + } + if (o instanceof GenericMap<?, ?>) { + return equalsGenericMap((GenericMap<?, ?>) o); + } return equalsMap(map); } @@ -80,11 +90,17 @@ public abstract class GenericMap<K, V> i K key = entry.getKey(); V value = entry.getValue(); if (value != null) { - if (!value.equals(map.get(key, false))) return false; + if (!value.equals(map.get(key, false))) { + return false; + } } else { Object otherValue = map.get(key, false); - if (otherValue != null) return false; - if (!map.containsKey(key)) return false; + if (otherValue != null) { + return false; + } + if (!map.containsKey(key)) { + return false; + } } } return true; @@ -97,11 +113,17 @@ public abstract class GenericMap<K, V> i K key = entry.getKey(); V value = entry.getValue(); if (value != null) { - if (!value.equals(map.get(key))) return false; + if (!value.equals(map.get(key))) { + return false; + } } else { Object otherValue = map.get(key); - if (otherValue != null) return false; - if (!map.containsKey(key)) return false; + if (otherValue != null) { + return false; + } + if (!map.containsKey(key)) { + return false; + } } } return true; @@ -121,7 +143,9 @@ public abstract class GenericMap<K, V> i } protected boolean isValid(Map.Entry<K, V> src) { - if (currentModCount != getModCount()) throw new ConcurrentModificationException(); + if (currentModCount != getModCount()) { + throw new ConcurrentModificationException(); + } return true; } } @@ -214,7 +238,9 @@ public abstract class GenericMap<K, V> i } private <KE extends K, VE extends V> void putAllInternal(Map<KE, VE> map) { - if (map.isEmpty()) return; + if (map.isEmpty()) { + return; + } incrementModCount(); Iterator<Map.Entry<KE, VE>> it; if (map instanceof GenericMap<?, ?>) { @@ -239,7 +265,9 @@ public abstract class GenericMap<K, V> i while (it.hasNext()) { Map.Entry<K, V> entry = it.next(); sb.append(entry.getKey()).append("=").append(entry.getValue()); - if (it.hasNext()) sb.append(","); + if (it.hasNext()) { + sb.append(","); + } } return sb.append("}"); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapCollection.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapCollection.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapCollection.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapCollection.java Mon Dec 11 06:34:02 2017 @@ -45,7 +45,9 @@ public abstract class GenericMapCollecti public boolean containsAll(Collection<?> collection) { for (Object item: collection) { - if (!contains(item)) return false; + if (!contains(item)) { + return false; + } } return true; } @@ -63,7 +65,9 @@ public abstract class GenericMapCollecti public boolean removeAll(Collection<?> collection) { int count = 0; for (Object item: collection) { - if (remove(item)) count++; + if (remove(item)) { + count++; + } } return count > 0; } @@ -86,7 +90,7 @@ public abstract class GenericMapCollecti } public Object[] toArray() { - List<I> list = new LinkedList<I>(); + List<I> list = new LinkedList<>(); Iterator<I> it = iterator(false); while (it.hasNext()) { list.add(it.next()); @@ -95,7 +99,7 @@ public abstract class GenericMapCollecti } public <T> T[] toArray(T[] array) { - List<Object> list = new LinkedList<Object>(); + List<Object> list = new LinkedList<>(); Iterator<I> it = iterator(false); while (it.hasNext()) { list.add(it.next()); @@ -113,7 +117,9 @@ public abstract class GenericMapCollecti Iterator<I> it = iterator(false); while (it.hasNext()) { sb.append(it.next()); - if (it.hasNext()) sb.append(", "); + if (it.hasNext()) { + sb.append(", "); + } } return sb.append("]"); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java Mon Dec 11 06:34:02 2017 @@ -47,8 +47,12 @@ public class GenericMapEntry<K, V> imple @Override public boolean equals(Object o) { - if (!(o instanceof Map.Entry<?, ?>)) return false; - if (this == o) return true; + if (!(o instanceof Map.Entry<?, ?>)) { + return false; + } + if (this == o) { + return true; + } Map.Entry<?, ?> other = (Map.Entry<?, ?>) o; return UtilObject.equalsHelper(getKey(), other.getKey()) && UtilObject.equalsHelper(getValue(), other.getValue()); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntrySet.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntrySet.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntrySet.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntrySet.java Mon Dec 11 06:34:02 2017 @@ -26,8 +26,12 @@ public abstract class GenericMapEntrySet } public boolean contains(Object item) { - if (item == null) return false; - if (!(item instanceof Map.Entry<?, ?>)) return false; + if (item == null) { + return false; + } + if (!(item instanceof Map.Entry<?, ?>)) { + return false; + } Map.Entry<?, ?> other = (Map.Entry<?, ?>) item; return contains(other.getKey(), other.getValue()); } @@ -35,11 +39,17 @@ public abstract class GenericMapEntrySet protected abstract boolean contains(Object key, Object value); public boolean remove(Object item) { - if (item == null) return false; - if (!(item instanceof Map.Entry<?, ?>)) return false; + if (item == null) { + return false; + } + if (!(item instanceof Map.Entry<?, ?>)) { + return false; + } Map.Entry<?, ?> other = (Map.Entry<?, ?>) item; Object key = other.getKey(); - if (!source.containsKey(key)) return false; + if (!source.containsKey(key)) { + return false; + } source.remove(key); return true; } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapSet.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapSet.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapSet.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapSet.java Mon Dec 11 06:34:02 2017 @@ -28,11 +28,17 @@ public abstract class GenericMapSet<K, V @Override public final boolean equals(Object o) { - if (!(o instanceof Set<?>)) return false; + if (!(o instanceof Set<?>)) { + return false; + } Set<?> other = (Set<?>) o; - if (source.size() != other.size()) return false; + if (source.size() != other.size()) { + return false; + } for (I item: this) { - if (!other.contains(item)) return false; + if (!other.contains(item)) { + return false; + } } return true; } @@ -41,7 +47,9 @@ public abstract class GenericMapSet<K, V public final int hashCode() { int h = 0; for (I item: this) { - if (item == null) continue; + if (item == null) { + continue; + } h += item.hashCode(); } return h; Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java Mon Dec 11 06:34:02 2017 @@ -34,21 +34,31 @@ public abstract class GenericMapValues<K public boolean contains(Object item) { Iterator<V> it = iterator(false); while (it.hasNext()) { - if (UtilObject.equalsHelper(item, it.next())) return true; + if (UtilObject.equalsHelper(item, it.next())) { + return true; + } } return false; } @Override public boolean equals(Object o) { - if (!(o instanceof Collection<?>)) return false; - if (o instanceof List<?> || o instanceof Set<?>) return false; + if (!(o instanceof Collection<?>)) { + return false; + } + if (o instanceof List<?> || o instanceof Set<?>) { + return false; + } Collection<?> other = (Collection<?>) o; - if (source.size() != other.size()) return false; + if (source.size() != other.size()) { + return false; + } Iterator<V> it = iterator(false); while (it.hasNext()) { V item = it.next(); - if (!other.contains(item)) return false; + if (!other.contains(item)) { + return false; + } } return true; } @@ -59,7 +69,9 @@ public abstract class GenericMapValues<K Iterator<V> it = iterator(false); while (it.hasNext()) { V item = it.next(); - if (item == null) continue; + if (item == null) { + continue; + } h += item.hashCode(); } return h; Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/IteratorWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/IteratorWrapper.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/IteratorWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/IteratorWrapper.java Mon Dec 11 06:34:02 2017 @@ -32,8 +32,12 @@ public abstract class IteratorWrapper<DE } public boolean hasNext() { - if (nextCalled) return true; - if (!it.hasNext()) return false; + if (nextCalled) { + return true; + } + if (!it.hasNext()) { + return false; + } do { lastSrc = it.next(); DEST nextDest = convert(lastSrc); @@ -48,7 +52,9 @@ public abstract class IteratorWrapper<DE public DEST next() { if (!nextCalled) { - if (!hasNext()) throw new NoSuchElementException(); + if (!hasNext()) { + throw new NoSuchElementException(); + } } nextCalled = false; return lastDest; Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/LifoSet.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/LifoSet.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/LifoSet.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/LifoSet.java Mon Dec 11 06:34:02 2017 @@ -79,8 +79,9 @@ public class LifoSet<V> extends Abstract if (index == -1) { backedList.addFirst(obj); - while (size() > maxCapacity) + while (size() > maxCapacity) { backedList.removeLast(); + } } else { backedList.remove(index); backedList.addFirst(obj); Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapComparator.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapComparator.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapComparator.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapComparator.java Mon Dec 11 06:34:02 2017 @@ -53,7 +53,7 @@ public class MapComparator implements Co } return obj.equals(this); } - + public int hashCode() { return super.hashCode(); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapContext.java Mon Dec 11 06:34:02 2017 @@ -53,11 +53,10 @@ public class MapContext<K, V> implements return newValue; } - @SuppressWarnings("unchecked") public static <K, V> MapContext<K, V> createMapContext(Map<K, V> baseMap) { MapContext<K, V> newValue = MapContext.getMapContext(); if (baseMap instanceof MapContext) { - newValue.stackList.addAll(((MapContext) baseMap).stackList); + newValue.stackList.addAll(((MapContext<K, V>) baseMap).stackList); } else { newValue.stackList.add(0, baseMap); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapStack.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapStack.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapStack.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/MapStack.java Mon Dec 11 06:34:02 2017 @@ -32,7 +32,7 @@ public class MapStack<K> extends MapCont public static final String module = MapStack.class.getName(); public static <K> MapStack<K> create() { - MapStack<K> newValue = new MapStack<K>(); + MapStack<K> newValue = new MapStack<>(); // initialize with a single entry newValue.push(); return newValue; @@ -40,9 +40,9 @@ public class MapStack<K> extends MapCont @SuppressWarnings("unchecked") public static <K> MapStack<K> create(Map<K, Object> baseMap) { - MapStack<K> newValue = new MapStack<K>(); + MapStack<K> newValue = new MapStack<>(); if (baseMap instanceof MapStack) { - newValue.stackList.addAll(((MapStack) baseMap).stackList); + newValue.stackList.addAll(((MapStack<K>) baseMap).stackList); } else { newValue.stackList.add(0, baseMap); } @@ -51,7 +51,7 @@ public class MapStack<K> extends MapCont /** Does a shallow copy of the internal stack of the passed MapStack; enables simultaneous stacks that share common parent Maps */ public static <K> MapStack<K> create(MapStack<K> source) { - MapStack<K> newValue = new MapStack<K>(); + MapStack<K> newValue = new MapStack<>(); newValue.stackList.addAll(source.stackList); return newValue; } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/PagedList.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/PagedList.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/PagedList.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/PagedList.java Mon Dec 11 06:34:02 2017 @@ -60,7 +60,7 @@ public class PagedList<E> implements Ite */ public static <E> PagedList<E> empty(int viewIndex, int viewSize) { List<E> emptyList = Collections.emptyList(); - return new PagedList<E>(0, 0, 0, viewIndex, viewSize, emptyList); + return new PagedList<>(0, 0, 0, viewIndex, viewSize, emptyList); } /** @@ -78,7 +78,7 @@ public class PagedList<E> implements Ite } /** - * @return the size of the full list, this can be the + * @return the size of the full list, this can be the * result of <code>EntityListIterator.getResultsSizeAfterPartialList()</code> */ public int getSize() { Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java Mon Dec 11 06:34:02 2017 @@ -48,8 +48,12 @@ public class ReadOnlyMapEntry<K, V> impl @Override public boolean equals(Object o) { - if (!(o instanceof Map.Entry<?, ?>)) return false; - if (this == o) return true; + if (!(o instanceof Map.Entry<?, ?>)) { + return false; + } + if (this == o) { + return true; + } Map.Entry<?, ?> other = (Map.Entry<?, ?>) o; return UtilObject.equalsHelper(getKey(), other.getKey()) && UtilObject.equalsHelper(getValue(), other.getValue()); } Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ResourceBundleMapWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ResourceBundleMapWrapper.java?rev=1817743&r1=1817742&r2=1817743&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ResourceBundleMapWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ResourceBundleMapWrapper.java Mon Dec 11 06:34:02 2017 @@ -221,7 +221,7 @@ public class ResourceBundleMapWrapper im } } else { try { - //the following will just be executed to check if arg0 is null, + //the following will just be executed to check if arg0 is null, //if so the thrown exception will be caught, if not true will be returned this.resourceBundle.getObject((String) arg0); return true; |
Free forum by Nabble | Edit this page |