Cleanup of map package.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1361799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-07-15 21:13:23 +00:00
parent a24baccfc6
commit db3e08d2b7
36 changed files with 107 additions and 211 deletions

View File

@ -53,11 +53,7 @@ import org.apache.commons.collections.iterators.EmptyMapIterator;
* This extends clause will be removed in v4.0.
*
* @since 3.0
* @version $Revision$
*
* @author java util HashMap
* @author Stephen Colebourne
* @author Christian Siefkes
* @version $Id$
*/
public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements IterableMap<K, V> {

View File

@ -40,9 +40,7 @@ import org.apache.commons.collections.set.AbstractSetDecorator;
* versions of Commons Collections.
*
* @since 3.1
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
abstract class AbstractInputCheckedMapDecorator<K, V>
extends AbstractMapDecorator<K, V> {

View File

@ -57,10 +57,7 @@ import org.apache.commons.collections.iterators.EmptyOrderedMapIterator;
* methods exposed.
*
* @since 3.0
* @version $Revision$
*
* @author java util LinkedHashMap
* @author Stephen Colebourne
* @version $Id$
*/
public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> implements OrderedMap<K, V> {

View File

@ -36,10 +36,7 @@ import java.util.Set;
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since 3.0
* @version $Revision$
*
* @author Daniel Rall
* @author Stephen Colebourne
* @version $Id$
*/
public abstract class AbstractMapDecorator<K, V> extends AbstractIterableMap<K, V> {

View File

@ -32,9 +32,7 @@ import org.apache.commons.collections.OrderedMapIterator;
* But, you might want that loophole, so this class is kept simple.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public abstract class AbstractOrderedMapDecorator<K, V> extends AbstractMapDecorator<K, V>
implements OrderedMap<K, V> {

View File

@ -77,10 +77,7 @@ import org.apache.commons.collections.keyvalue.DefaultMapEntry;
*
* @see java.lang.ref.Reference
* @since 3.1 (extracted from ReferenceMap in 3.0)
* @version $Revision$
*
* @author Paul Jack
* @author Stephen Colebourne
* @version $Id$
*/
public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V> {

View File

@ -42,9 +42,7 @@ import org.apache.commons.collections.iterators.ListIteratorWrapper;
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public abstract class AbstractSortedMapDecorator<K, V> extends AbstractMapDecorator<K, V> implements
IterableSortedMap<K, V> {

View File

@ -58,9 +58,7 @@ import java.util.Map;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author Commons-Collections team
* @version $Id$
*/
public class CaseInsensitiveMap<K, V> extends AbstractHashedMap<K, V> implements Serializable, Cloneable {

View File

@ -40,9 +40,7 @@ import org.apache.commons.collections.set.CompositeSet;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author Brian McCallister
* @version $Id$
*/
public class CompositeMap<K, V> extends AbstractIterableMap<K, V> implements Serializable {

View File

@ -57,10 +57,8 @@ import org.apache.commons.collections.functors.FactoryTransformer;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.2
* @version $Revision$
* @version $Id$
*
* @author Stephen Colebourne
* @author Rafael U.C. Afonso
* @see LazyMap
*/
public class DefaultedMap<K, V> extends AbstractMapDecorator<K, V> implements Serializable {

View File

@ -50,10 +50,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class FixedSizeMap<K, V>
extends AbstractMapDecorator<K, V>

View File

@ -52,10 +52,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class FixedSizeSortedMap<K, V>
extends AbstractSortedMapDecorator<K, V>

View File

@ -68,9 +68,7 @@ import org.apache.commons.collections.iterators.EmptyMapIterator;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneable {

View File

@ -37,9 +37,7 @@ import java.util.Map;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class HashedMap<K, V>
extends AbstractHashedMap<K, V> implements Serializable, Cloneable {

View File

@ -38,10 +38,7 @@ import java.util.Map;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author java util HashMap
* @author Stephen Colebourne
* @version $Id$
*/
public class IdentityMap<K, V>
extends AbstractHashedMap<K, V> implements Serializable, Cloneable {

View File

@ -55,13 +55,7 @@ import org.apache.commons.collections.BoundedMap;
* <code>NullPointerException</code>'s when accessed by concurrent threads.
*
* @since 3.0 (previously in main package v1.0)
* @version $Revision$
*
* @author James Strachan
* @author Morgan Delagrange
* @author Stephen Colebourne
* @author Mike Pettypiece
* @author Mario Ivankovits
* @version $Id$
*/
public class LRUMap<K, V>
extends AbstractLinkedMap<K, V> implements BoundedMap<K, V>, Serializable, Cloneable {

View File

@ -35,16 +35,16 @@ import org.apache.commons.collections.functors.FactoryTransformer;
* <p>
* For instance:
* <pre>
* Factory factory = new Factory() {
* public Object create() {
* Factory&lt;Date&gt; factory = new Factory&lt;Date&gt;() {
* public Date create() {
* return new Date();
* }
* }
* Map lazy = Lazy.map(new HashMap(), factory);
* Object obj = lazy.get("NOW");
* Map&lt;String, Date&gt; lazy = LazyMap.lazyMap(new HashMap&lt;String, Date&gt;(), factory);
* Date date = lazy.get("NOW");
* </pre>
*
* After the above code is executed, <code>obj</code> will contain
* After the above code is executed, <code>date</code> will refer to
* a new <code>Date</code> instance. Furthermore, that <code>Date</code>
* instance is mapped to the "NOW" key in the map.
* <p>
@ -57,10 +57,7 @@ import org.apache.commons.collections.functors.FactoryTransformer;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Map<K, V>, Serializable {
@ -155,7 +152,8 @@ public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Map<K,
public V get(Object key) {
// create value for key if key is not currently in the map
if (map.containsKey(key) == false) {
K castKey = cast(key);
@SuppressWarnings("unchecked")
K castKey = (K) key;
V value = factory.transform(castKey);
map.put(castKey, value);
return value;
@ -163,17 +161,6 @@ public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Map<K,
return map.get(key);
}
/**
* Method just to cast {@link Object}s to K where necessary. This is done to ensure that the SuppressWarnings does not
* cover other stuff that it shouldn't
* @param key .
* @return the cast key.
*/
@SuppressWarnings("unchecked")
private K cast(Object key) {
return (K) key;
}
// no need to wrap keySet, entrySet or values as they are views of
// existing map entries - you can't do a map-style get on them.
}

View File

@ -31,16 +31,17 @@ import org.apache.commons.collections.Transformer;
* <p>
* For instance:
* <pre>
* Factory factory = new Factory() {
* public Object create() {
* Factory&lt;Date&gt; factory = new Factory&lt;Date&gt;() {
* public Date create() {
* return new Date();
* }
* }
* SortedMap lazy = Lazy.sortedMap(new HashMap(), factory);
* Object obj = lazy.get("NOW");
* SortedMap&lt;String, Date&gt; lazy =
* LazySortedMap.lazySortedMap(new HashMap&lt;String, Date&gt;(), factory);
* Date date = lazy.get("NOW");
* </pre>
*
* After the above code is executed, <code>obj</code> will contain
* After the above code is executed, <code>date</code> will refer to
* a new <code>Date</code> instance. Furthermore, that <code>Date</code>
* instance is mapped to the "NOW" key in the map.
* <p>
@ -53,10 +54,7 @@ import org.apache.commons.collections.Transformer;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class LazySortedMap<K,V>
extends LazyMap<K,V>

View File

@ -58,9 +58,7 @@ import org.apache.commons.collections.list.UnmodifiableList;
* exceptions when accessed by concurrent threads without synchronization.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class LinkedMap<K, V> extends AbstractLinkedMap<K, V> implements Serializable, Cloneable {

View File

@ -72,11 +72,7 @@ import org.apache.commons.collections.list.UnmodifiableList;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Matt Benson
* @author Dave Meikle
* @version $Id$
*/
public class ListOrderedMap<K, V>
extends AbstractMapDecorator<K, V>

View File

@ -52,7 +52,7 @@ import org.apache.commons.collections.keyvalue.MultiKey;
* As an example, consider a least recently used cache that uses a String airline code
* and a Locale to lookup the airline's name:
* <pre>
* private MultiKeyMap cache = MultiKeyMap.decorate(new LRUMap(50));
* private MultiKeyMap cache = MultiKeyMap.multiKeyMap(new LRUMap(50));
*
* public String getAirlineName(String code, String locale) {
* String name = (String) cache.get(code, locale);
@ -70,9 +70,7 @@ import org.apache.commons.collections.keyvalue.MultiKey;
* by concurrent threads without synchronization.
*
* @since 3.1
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K>, V>
implements IterableMap<MultiKey<? extends K>, V>, Serializable {
@ -133,7 +131,8 @@ public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K
*/
public V get(Object key1, Object key2) {
int hashCode = hash(key1, key2);
AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry = decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
AbstractHashedMap.HashEntry<MultiKey<? extends K>, V> entry =
decorated().data[decorated().hashIndex(hashCode, decorated().data.length)];
while (entry != null) {
if (entry.hashCode == hashCode && isEqualKey(entry, key1, key2)) {
return entry.getValue();

View File

@ -57,15 +57,8 @@ import org.apache.commons.collections.iterators.IteratorChain;
* appropriate synchronization. This class may throw exceptions when accessed
* by concurrent threads without synchronization.
*
* @author James Carman
* @author Christopher Berry
* @author James Strachan
* @author Steve Downey
* @author Stephen Colebourne
* @author Julien Buret
* @author Serhiy Yevtushenko
* @version $Revision$
* @since 3.2
* @version $Id$
*/
public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> implements MultiMap<K, V>, Serializable {

View File

@ -45,10 +45,7 @@ import org.apache.commons.collections.Predicate;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class PredicatedMap<K, V>
extends AbstractInputCheckedMapDecorator<K, V>

View File

@ -41,10 +41,7 @@ import org.apache.commons.collections.Predicate;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @author Paul Jack
* @version $Id$
*/
public class PredicatedSortedMap<K, V> extends PredicatedMap<K, V> implements SortedMap<K, V> {

View File

@ -66,9 +66,7 @@ import java.lang.ref.Reference;
* @see java.lang.ref.Reference
*
* @since 3.0 (previously in main package v2.1)
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class ReferenceIdentityMap<K, V> extends AbstractReferenceMap<K, V> implements Serializable {

View File

@ -68,10 +68,7 @@ import java.io.Serializable;
* @see java.lang.ref.Reference
*
* @since 3.0 (previously in main package v2.1)
* @version $Revision$
*
* @author Paul Jack
* @author Stephen Colebourne
* @version $Id$
*/
public class ReferenceMap<K, V> extends AbstractReferenceMap<K, V> implements Serializable {

View File

@ -54,9 +54,7 @@ import org.apache.commons.collections.keyvalue.TiedMapEntry;
* </ul>
*
* @since 3.1
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class SingletonMap<K, V>
implements OrderedMap<K, V>, BoundedMap<K, V>, KeyValue<K, V>, Serializable, Cloneable {

View File

@ -91,15 +91,7 @@ import org.apache.commons.collections.KeyValue;
* operations will affect the map.<p>
*
* @since 3.0 (previously in main package v2.1)
* @version $Revision$
*
* @author Berin Loritsch
* @author Gerhard Froehlich
* @author Michael A. Smith
* @author Paul Jack
* @author Leo Sutic
* @author Janek Bogucki
* @author Kazuya Ujihara
* @version $Id$
*/
public final class StaticBucketMap<K, V> extends AbstractIterableMap<K, V> {

View File

@ -43,9 +43,7 @@ import org.apache.commons.collections.Transformer;
* @see org.apache.commons.collections.splitmap.TransformedMap
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class TransformedMap<K, V>
extends AbstractInputCheckedMapDecorator<K, V>

View File

@ -39,9 +39,7 @@ import org.apache.commons.collections.Transformer;
* This class is Serializable from Commons Collections 3.1.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public class TransformedSortedMap<K, V>
extends TransformedMap<K, V>

View File

@ -33,9 +33,7 @@ import org.apache.commons.collections.set.AbstractSetDecorator;
* Attempts to modify it will result in an UnsupportedOperationException.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public final class UnmodifiableEntrySet<K, V>
extends AbstractSetDecorator<Map.Entry<K, V>> implements Unmodifiable {

View File

@ -40,9 +40,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* Attempts to modify it will result in an UnsupportedOperationException.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public final class UnmodifiableMap<K, V>
extends AbstractMapDecorator<K, V>

View File

@ -39,9 +39,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* Attempts to modify it will result in an UnsupportedOperationException.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public final class UnmodifiableOrderedMap<K, V> extends AbstractOrderedMapDecorator<K, V> implements
Unmodifiable, Serializable {

View File

@ -38,9 +38,7 @@ import org.apache.commons.collections.set.UnmodifiableSet;
* Attempts to modify it will result in an UnsupportedOperationException.
*
* @since 3.0
* @version $Revision$
*
* @author Stephen Colebourne
* @version $Id$
*/
public final class UnmodifiableSortedMap<K, V>
extends AbstractSortedMapDecorator<K, V>

View File

@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This package contains implementations of the {@link java.util.Map Map},
* {@link org.apache.commons.collections.IterableMap IterableMap},
* {@link org.apache.commons.collections.OrderedMap OrderedMap} and
* {@link java.util.SortedMap SortedMap} interfaces.
* A Map provides a lookup from a key to a value.
* A number of implementations also support the new MapIterator interface that enables
* simple iteration of map keys and values.
* <p>
* The following implementations are provided:
* <ul>
* <li>CaseInsensitiveMap - map that compares keys in a case insensitive way
* <li>CompositeMap - map that combines multiple maps into a single view
* <li>HashedMap - general purpose HashMap replacement supporting MapIterator
* <li>IdentityMap - map that uses == for comparison instead of equals()
* <li>Flat3Map - designed for good performance at size 3 or less
* <li>LinkedMap - a hash map that maintains insertion order, supporting OrderedMapIterator
* <li>LRUMap - a hash map that maintains a maximum size by removing the least recently used entries
* <li>MultiKeyMap - map that provides special methods for using more than one key to access the value
* <li>ReferenceMap - allows the garbage collector to collect keys and values using equals() for comparison
* <li>ReferenceIdentityMap - allows the garbage collector to collect keys and values using == for comparison
* <li>SingletonMap - a fully featured map to hold one key-value pair
* <li>StaticBucketMap - internally synchronized and designed for thread-contentious environments
* </ul>
* <p>
* The following decorators are provided:
* <ul>
* <li>Unmodifiable - ensures the collection cannot be altered
* <li>Predicated - ensures that only elements that are valid according to a predicate can be added
* <li>Typed - ensures that only elements that are of a specific type can be added
* <li>Transformed - transforms each element added
* <li>FixedSize - ensures that the size of the map cannot change
* <li>Defaulted - provides default values for non-existing keys
* <li>Lazy - creates objects in the map on demand
* <li>ListOrdered - ensures that insertion order is retained
* </ul>
*
* @version $Id$
*/
package org.apache.commons.collections.map;

View File

@ -1,55 +0,0 @@
<!-- $Id$ -->
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<BODY>
<p>
This package contains implementations of the
{@link java.util.Map Map},
{@link org.apache.commons.collections.IterableMap IterableMap},
{@link org.apache.commons.collections.OrderedMap OrderedMap} and
{@link java.util.SortedMap SortedMap} interfaces.
A Map provides a lookup from a key to a value.
A number of implementations also support the new MapIterator interface that enables
simple iteration of map keys and values.
<p>
The following implementations are provided:
<ul>
<li>CaseInsensitiveMap - map that compares keys in a case insensitive way
<li>CompositeMap - map that combines multiple maps into a single view
<li>HashedMap - general purpose HashMap replacement supporting MapIterator
<li>IdentityMap - map that uses == for comparison instead of equals()
<li>Flat3Map - designed for good performance at size 3 or less
<li>LinkedMap - a hash map that maintains insertion order, supporting OrderedMapIterator
<li>MultiKeyMap - map that provides special methods for using more than one key to access the value
<li>ReferenceMap - allows the garbage collector to collect keys and values using equals() for comparison
<li>ReferenceIdentityMap - allows the garbage collector to collect keys and values using == for comparison
<li>SingletonMap - a fully featured map to hold one key-value pair
<li>StaticBucketMap - internally synchronized and designed for thread-contentious environments
</ul>
<p>
The following decorators are provided:
<ul>
<li>Unmodifiable - ensures the collection cannot be altered
<li>Predicated - ensures that only elements that are valid according to a predicate can be added
<li>Typed - ensures that only elements that are of a specific type can be added
<li>Transformed - transforms each element added
<li>FixedSize - ensures that the size of the map cannot change
<li>Lazy - creates objects in the map on demand
<li>ListOrdered - ensures that insertion order is retained
</ul>
</pre>
</BODY>