Top Description Inners Fields Constructors Methods
org.jruby.util

public abstract Class GenericMap

extends Object
implements Map
Class Inheritance
All Implemented Interfaces
java.util.Map
Known Direct Subclasses
org.jruby.util.WeakIdentityHashMap
Imports
java.util.AbstractCollection, .AbstractSet, .Collection, .Iterator, .Map, .Set

A GenericMap is simply an abstract java.util.Map implementation for which subclasses really only need to implement the method entryIterator.
Author
Kresten Krab Thorup ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
pack-priv class
pack-priv abstract class
pack-priv class

Field Summary

Modifier and TypeField and Description
protected int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

return the element with the given key

protected abstract Iterator<E>
public Set<E>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
equals(Object
object to be compared for equality with this map
other
)

Overrides java.lang.Object.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

protected boolean
keyEquals(Object containedKey, Object givenKey)

protected int
protected Iterator<E>
public Set<E>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public void
putAll(Map<K, V>
mappings to be stored in this map
other
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

private static Object[]
toArray(Object[] arr, int size, Iterator<E> it)

I don't quite understand why we need to replace this method from AbstractCollection, but it has been observed that toArray returns the *reverse* order of elements.

protected boolean
valueEquals(Object value1, Object value2)

protected int
protected Iterator<E>
public Collection<E>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

sizeback to summary
protected int size

Constructor Detail

GenericMapback to summary
public GenericMap()

Method Detail

containsKeyback to summary
public boolean containsKey(Object key)

Implements java.util.Map.containsKey.

Doc from java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that Objects.equals(key, k). (There can be at most one such mapping.)

Parameters
key:Object

key whose presence in this map is to be tested

Returns:boolean

true if this map contains a mapping for the specified key

containsValueback to summary
public boolean containsValue(Object value)

Implements java.util.Map.containsValue.

return the element with the given key

Parameters
value:Object

Doc from java.util.Map.containsValue.

value whose presence in this map is to be tested

Returns:boolean

Doc from java.util.Map.containsValue.

true if this map maps one or more keys to the specified value

entryIteratorback to summary
protected abstract Iterator<E> entryIterator()
entrySetback to summary
public Set<E> entrySet()

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<E>

a set view of the mappings contained in this map

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implements java.util.Map.equals.

Doc from java.util.Map.equals.

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.

Parameters
other:Object

object to be compared for equality with this map

Returns:boolean

true if the specified object is equal to this map

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.hashCode.

Doc from java.util.Map.hashCode.

Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this map

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

keyEqualsback to summary
protected boolean keyEquals(Object containedKey, Object givenKey)
keyHashback to summary
protected int keyHash(Object key)
keyIteratorback to summary
protected Iterator<E> keyIterator()
keySetback to summary
public Set<E> keySet()

Implements java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<E>

a set view of the keys contained in this map

putAllback to summary
public void putAll(Map<K, V> other)

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
other:Map<K, V>

mappings to be stored in this map

sizeback to summary
public int size()

Implements java.util.Map.size.

Doc from java.util.Map.size.

Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of key-value mappings in this map

toArrayback to summary
private static Object[] toArray(Object[] arr, int size, Iterator<E> it)

I don't quite understand why we need to replace this method from AbstractCollection, but it has been observed that toArray returns the *reverse* order of elements. --Kresten

valueEqualsback to summary
protected boolean valueEquals(Object value1, Object value2)
valueHashback to summary
protected int valueHash(Object value)
valueIteratorback to summary
protected Iterator<E> valueIterator()
valuesback to summary
public Collection<E> values()

Implements java.util.Map.values.

Doc from java.util.Map.values.

Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<E>

a collection view of the values contained in this map

org.jruby.util back to summary

pack-priv abstract Class GenericMap.Entry

extends Object
implements Entry
Class Inheritance
All Implemented Interfaces
java.util.Map.Entry

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
object to be compared for equality with this map entry
other
)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Compares the specified object with this entry for equality.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Entryback to summary
pack-priv Entry()

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Implements java.util.Map.Entry.equals.

Doc from java.util.Map.Entry.equals.

Compares the specified object with this entry for equality. Returns true if the given object is also a map entry and the two entries represent the same mapping. More formally, two entries e1 and e2 represent the same mapping if

    (e1.getKey()==null ?
     e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
    (e1.getValue()==null ?
     e2.getValue()==null : e1.getValue().equals(e2.getValue()))
This ensures that the equals method works properly across different implementations of the Map.Entry interface.
Parameters
other:Object

object to be compared for equality with this map entry

Returns:boolean

true if the specified object is equal to this map entry

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Map.Entry.hashCode.

Doc from java.util.Map.Entry.hashCode.

Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:

    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.
Returns:int

the hash code value for this map entry

Annotations
@Override
org.jruby.util back to summary

pack-priv Class GenericMap.KeyIterator

extends KeyOrValueIterator
Class Inheritance

Field Summary

Inherited from org.jruby.util.GenericMap.KeyOrValueIterator:
iter

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Object
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from org.jruby.util.GenericMap.KeyOrValueIterator:
hasNextnextEntryremove

Constructor Detail

KeyIteratorback to summary
pack-priv KeyIterator()

Method Detail

nextback to summary
public Object next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Object

the next element in the iteration

org.jruby.util back to summary

pack-priv abstract Class GenericMap.KeyOrValueIterator

extends Object
implements Iterator
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Known Direct Subclasses
org.jruby.util.GenericMap.KeyIterator, org.jruby.util.GenericMap.ValueIterator

Field Summary

Modifier and TypeField and Description
pack-priv final Iterator<E>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

protected Map.Entry<K, V>
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iterback to summary
pack-priv final Iterator<E> iter

Constructor Detail

KeyOrValueIteratorback to summary
pack-priv KeyOrValueIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

nextEntryback to summary
protected Map.Entry<K, V> nextEntry()
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

org.jruby.util back to summary

pack-priv Class GenericMap.ValueIterator

extends KeyOrValueIterator
Class Inheritance

Field Summary

Inherited from org.jruby.util.GenericMap.KeyOrValueIterator:
iter

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Object
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from org.jruby.util.GenericMap.KeyOrValueIterator:
hasNextnextEntryremove

Constructor Detail

ValueIteratorback to summary
pack-priv ValueIterator()

Method Detail

nextback to summary
public Object next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Object

the next element in the iteration