From 1408f0635a0641535296278c632437dbb57fc93b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 29 Dec 2003 15:08:15 +0000 Subject: [PATCH] Change to standard variable naming and braces style git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131477 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/map/PredicatedMap.java | 10 +-- .../commons/collections/map/ReferenceMap.java | 86 ++++++++++++------- .../collections/map/StaticBucketMap.java | 32 +++---- .../collections/map/UnmodifiableEntrySet.java | 6 +- 4 files changed, 79 insertions(+), 55 deletions(-) diff --git a/src/java/org/apache/commons/collections/map/PredicatedMap.java b/src/java/org/apache/commons/collections/map/PredicatedMap.java index 5e45f9341..c14086b7d 100644 --- a/src/java/org/apache/commons/collections/map/PredicatedMap.java +++ b/src/java/org/apache/commons/collections/map/PredicatedMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/PredicatedMap.java,v 1.3 2003/12/25 00:49:14 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/PredicatedMap.java,v 1.4 2003/12/29 15:08:15 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -75,7 +75,7 @@ import org.apache.commons.collections.keyvalue.AbstractMapEntryDecorator; * is thrown. * * @since Commons Collections 3.0 - * @version $Revision: 1.3 $ $Date: 2003/12/25 00:49:14 $ + * @version $Revision: 1.4 $ $Date: 2003/12/29 15:08:15 $ * * @author Stephen Colebourne * @author Paul Jack @@ -243,11 +243,11 @@ public class PredicatedMap extends AbstractMapDecorator { this.predicate = valuePredicate; } - public Object setValue(Object o) { - if (predicate != null && predicate.evaluate(o) == false) { + public Object setValue(Object obj) { + if (predicate != null && predicate.evaluate(obj) == false) { throw new IllegalArgumentException("Cannot set value - Predicate rejected it"); } - return entry.setValue(o); + return entry.setValue(obj); } } diff --git a/src/java/org/apache/commons/collections/map/ReferenceMap.java b/src/java/org/apache/commons/collections/map/ReferenceMap.java index 07c1b5cf0..e52ca212f 100644 --- a/src/java/org/apache/commons/collections/map/ReferenceMap.java +++ b/src/java/org/apache/commons/collections/map/ReferenceMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/ReferenceMap.java,v 1.5 2003/12/29 14:54:58 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/ReferenceMap.java,v 1.6 2003/12/29 15:08:15 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -119,7 +119,7 @@ import org.apache.commons.collections.keyvalue.DefaultMapEntry; * @see java.lang.ref.Reference * * @since Commons Collections 3.0 (previously in main package v2.1) - * @version $Revision: 1.5 $ $Date: 2003/12/29 14:54:58 $ + * @version $Revision: 1.6 $ $Date: 2003/12/29 15:08:15 $ * * @author Paul Jack */ @@ -373,16 +373,16 @@ public class ReferenceMap extends AbstractMap { * @throws IOException if the stream raises it * @throws ClassNotFoundException if the stream raises it */ - private void readObject(ObjectInputStream inp) throws IOException, ClassNotFoundException { - inp.defaultReadObject(); - table = new Entry[inp.readInt()]; + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + table = new Entry[in.readInt()]; threshold = (int)(table.length * loadFactor); queue = new ReferenceQueue(); - Object key = inp.readObject(); + Object key = in.readObject(); while (key != null) { - Object value = inp.readObject(); + Object value = in.readObject(); put(key, value); - key = inp.readObject(); + key = in.readObject(); } } @@ -416,7 +416,9 @@ public class ReferenceMap extends AbstractMap { * if the key is not in this map */ private Entry getEntry(Object key) { - if (key == null) return null; + if (key == null) { + return null; + } int hash = key.hashCode(); int index = indexFor(hash); for (Entry entry = table[index]; entry != null; entry = entry.next) { @@ -502,8 +504,11 @@ public class ReferenceMap extends AbstractMap { Entry entry = table[index]; while (entry != null) { if (entry.purge(ref)) { - if (previous == null) table[index] = entry.next; - else previous.next = entry.next; + if (previous == null) { + table[index] = entry.next; + } else { + previous.next = entry.next; + } this.size--; return; } @@ -544,7 +549,9 @@ public class ReferenceMap extends AbstractMap { public boolean containsKey(Object key) { purge(); Entry entry = getEntry(key); - if (entry == null) return false; + if (entry == null) { + return false; + } return entry.getValue() != null; } @@ -558,7 +565,9 @@ public class ReferenceMap extends AbstractMap { public Object get(Object key) { purge(); Entry entry = getEntry(key); - if (entry == null) return null; + if (entry == null) { + return null; + } return entry.getValue(); } @@ -575,11 +584,17 @@ public class ReferenceMap extends AbstractMap { * is null */ public Object put(Object key, Object value) { - if (key == null) throw new NullPointerException("null keys not allowed"); - if (value == null) throw new NullPointerException("null values not allowed"); + if (key == null) { + throw new NullPointerException("null keys not allowed"); + } + if (value == null) { + throw new NullPointerException("null values not allowed"); + } purge(); - if (size + 1 > threshold) resize(); + if (size + 1 > threshold) { + resize(); + } int hash = key.hashCode(); int index = indexFor(hash); @@ -609,7 +624,9 @@ public class ReferenceMap extends AbstractMap { * the key was not in the map */ public Object remove(Object key) { - if (key == null) return null; + if (key == null) { + return null; + } purge(); int hash = key.hashCode(); int index = indexFor(hash); @@ -617,8 +634,11 @@ public class ReferenceMap extends AbstractMap { Entry entry = table[index]; while (entry != null) { if ((hash == entry.hash) && key.equals(entry.getKey())) { - if (previous == null) table[index] = entry.next; - else previous.next = entry.next; + if (previous == null) { + table[index] = entry.next; + } else { + previous.next = entry.next; + } this.size--; modCount++; return entry.getValue(); @@ -636,7 +656,7 @@ public class ReferenceMap extends AbstractMap { public void clear() { Arrays.fill(table, null); size = 0; - while (queue.poll() != null); // drain the queue + while (queue.poll() != null) {}; // drain the queue } @@ -658,18 +678,22 @@ public class ReferenceMap extends AbstractMap { ReferenceMap.this.clear(); } - public boolean contains(Object o) { - if (o == null) return false; - if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + public boolean contains(Object obj) { + if (obj == null) { + return false; + } + if (obj instanceof Map.Entry == false) { + return false; + } + Map.Entry e = (Map.Entry) obj; Entry e2 = getEntry(e.getKey()); return (e2 != null) && e.equals(e2); } - public boolean remove(Object o) { - boolean r = contains(o); + public boolean remove(Object obj) { + boolean r = contains(obj); if (r) { - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry) obj; ReferenceMap.this.remove(e.getKey()); } return r; @@ -713,13 +737,13 @@ public class ReferenceMap extends AbstractMap { return new KeyIterator(); } - public boolean contains(Object o) { - return containsKey(o); + public boolean contains(Object obj) { + return containsKey(obj); } - public boolean remove(Object o) { - Object r = ReferenceMap.this.remove(o); + public boolean remove(Object obj) { + Object r = ReferenceMap.this.remove(obj); return r != null; } diff --git a/src/java/org/apache/commons/collections/map/StaticBucketMap.java b/src/java/org/apache/commons/collections/map/StaticBucketMap.java index 9f8071578..ab76d5643 100644 --- a/src/java/org/apache/commons/collections/map/StaticBucketMap.java +++ b/src/java/org/apache/commons/collections/map/StaticBucketMap.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java,v 1.4 2003/12/28 16:36:48 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/StaticBucketMap.java,v 1.5 2003/12/29 15:08:15 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -132,7 +132,7 @@ import org.apache.commons.collections.KeyValue; * operations will affect the map.

* * @since Commons Collections 3.0 (previously in main package v2.1) - * @version $Revision: 1.4 $ $Date: 2003/12/28 16:36:48 $ + * @version $Revision: 1.5 $ $Date: 2003/12/29 15:08:15 $ * * @author Berin Loritsch * @author Gerhard Froehlich @@ -498,23 +498,23 @@ public final class StaticBucketMap implements Map { (value == null ? 0 : value.hashCode())); } - public boolean equals(Object o) { - if (o == this) { + public boolean equals(Object obj) { + if (obj == this) { return true; } - if (o instanceof Map.Entry == false) { + if (obj instanceof Map.Entry == false) { return false; } - Map.Entry e2 = (Map.Entry) o; + Map.Entry e2 = (Map.Entry) obj; return ( (key == null ? e2.getKey() == null : key.equals(e2.getKey())) && (value == null ? e2.getValue() == null : value.equals(e2.getValue()))); } - public Object setValue(Object val) { + public Object setValue(Object obj) { Object retVal = value; - value = val; + value = obj; return retVal; } } @@ -600,8 +600,8 @@ public final class StaticBucketMap implements Map { return new EntryIterator(); } - public boolean contains(Object o) { - Map.Entry entry = (Map.Entry)o; + public boolean contains(Object obj) { + Map.Entry entry = (Map.Entry) obj; int hash = getHash(entry.getKey()); synchronized (m_locks[hash]) { for (Node n = m_buckets[hash]; n != null; n = n.next) { @@ -615,7 +615,7 @@ public final class StaticBucketMap implements Map { if (obj instanceof Map.Entry == false) { return false; } - Map.Entry entry = (Map.Entry)obj; + Map.Entry entry = (Map.Entry) obj; int hash = getHash(entry.getKey()); synchronized (m_locks[hash]) { for (Node n = m_buckets[hash]; n != null; n = n.next) { @@ -645,16 +645,16 @@ public final class StaticBucketMap implements Map { return new KeyIterator(); } - public boolean contains(Object o) { - return StaticBucketMap.this.containsKey(o); + public boolean contains(Object obj) { + return StaticBucketMap.this.containsKey(obj); } - public boolean remove(Object o) { - int hash = getHash(o); + public boolean remove(Object obj) { + int hash = getHash(obj); synchronized (m_locks[hash]) { for (Node n = m_buckets[hash]; n != null; n = n.next) { Object k = n.getKey(); - if ((k == o) || ((k != null) && k.equals(o))) { + if ((k == obj) || ((k != null) && k.equals(obj))) { StaticBucketMap.this.remove(k); return true; } diff --git a/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java b/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java index 3bce1f280..c3e3b8ff3 100644 --- a/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java +++ b/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java @@ -1,5 +1,5 @@ /* - * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java,v 1.2 2003/12/05 20:23:57 scolebourne Exp $ + * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/UnmodifiableEntrySet.java,v 1.3 2003/12/29 15:08:15 scolebourne Exp $ * ==================================================================== * * The Apache Software License, Version 1.1 @@ -72,7 +72,7 @@ import org.apache.commons.collections.set.AbstractSetDecorator; * Decorates a map entry Set to ensure it can't be altered. * * @since Commons Collections 3.0 - * @version $Revision: 1.2 $ $Date: 2003/12/05 20:23:57 $ + * @version $Revision: 1.3 $ $Date: 2003/12/29 15:08:15 $ * * @author Stephen Colebourne */ @@ -195,7 +195,7 @@ public final class UnmodifiableEntrySet extends AbstractSetDecorator implements super(entry); } - public Object setValue(Object o) { + public Object setValue(Object obj) { throw new UnsupportedOperationException(); } }