Top Description Fields Constructors Methods
org.apache.commons.collections4.iterators

public Class EntrySetMapIterator<K, V>

extends Object
implements MapIterator<K, V>, ResettableIterator<K>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.ResettableIterator, java.util.Iterator, org.apache.commons.collections4.MapIterator
Type Parameters
<K>
the type of keys
<V>
the type of mapped values
Imports
java.util.Iterator, .Map, org.apache.commons.collections4.MapIterator, .ResettableIterator

Implements a MapIterator using a Map entrySet. Reverse iteration is not supported.
MapIterator it = map.mapIterator();
while (it.hasNext()) {
  Object key = it.next();
  Object value = it.getValue();
  it.setValue(newValue);
}
Since
3.0

Field Summary

Modifier and TypeField and Description
private boolean
private Iterator<Map.Entry<K, V>>
private Map.Entry<K, V>
private final Map<K, V>

Constructor Summary

AccessConstructor and Description
public
EntrySetMapIterator(final Map<K, V>
the map to iterate over
map
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public K

Returns:

the current key
getKey
()

Implements org.apache.commons.collections4.MapIterator.getKey.

Gets the current key, which is the key returned by the last call to next().
public V

Returns:

the current value
getValue
()

Implements org.apache.commons.collections4.MapIterator.getValue.

Gets the current value, which is the value associated with the last key returned by next().
public boolean

Returns:

true if the iterator has more elements
hasNext
()

Implements org.apache.commons.collections4.MapIterator.hasNext, java.util.Iterator.hasNext.

Checks to see if there are more entries still to be iterated.
public K

Returns:

the next key in the iteration
next
()

Implements org.apache.commons.collections4.MapIterator.next, java.util.Iterator.next.

Gets the next key from the Map.
public void
remove()

Overrides default java.util.Iterator.remove.

Implements org.apache.commons.collections4.MapIterator.remove.

Removes the last returned key from the underlying Map.
public void
reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the state of the iterator.
public V

Returns:

the previous value
setValue
(final V
the new value
value
)

Implements org.apache.commons.collections4.MapIterator.setValue.

Sets the value associated with the current key.
public String

Returns:

a string version of the iterator
toString
()

Overrides java.lang.Object.toString.

Gets the iterator as a String.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

canRemoveback to summary
private boolean canRemove
iteratorback to summary
private Iterator<Map.Entry<K, V>> iterator
lastback to summary
private Map.Entry<K, V> last
mapback to summary
private final Map<K, V> map

Constructor Detail

EntrySetMapIteratorback to summary
public EntrySetMapIterator(final Map<K, V> map)

Constructor.

Parameters
map:Map<K, V>

the map to iterate over

Method Detail

getKeyback to summary
public K getKey()

Implements org.apache.commons.collections4.MapIterator.getKey.

Gets the current key, which is the key returned by the last call to next().

Returns:K

the current key

Annotations
@Override
Exceptions
IllegalStateException:
if next() has not yet been called
getValueback to summary
public V getValue()

Implements org.apache.commons.collections4.MapIterator.getValue.

Gets the current value, which is the value associated with the last key returned by next().

Returns:V

the current value

Annotations
@Override
Exceptions
IllegalStateException:
if next() has not yet been called
hasNextback to summary
public boolean hasNext()

Implements org.apache.commons.collections4.MapIterator.hasNext, java.util.Iterator.hasNext.

Checks to see if there are more entries still to be iterated.

Returns:boolean

true if the iterator has more elements

Annotations
@Override
nextback to summary
public K next()

Implements org.apache.commons.collections4.MapIterator.next, java.util.Iterator.next.

Gets the next key from the Map.

Returns:K

the next key in the iteration

Annotations
@Override
Exceptions
NoSuchElementException:
if the iteration is finished
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Implements org.apache.commons.collections4.MapIterator.remove.

Removes the last returned key from the underlying Map.

This method can be called once per call to next().

Annotations
@Override
Exceptions
UnsupportedOperationException:
if remove is not supported by the map
IllegalStateException:
  • if next() has not yet been called
  • if remove() has already been called since the last call to next()
resetback to summary
public void reset()

Implements org.apache.commons.collections4.ResettableIterator.reset.

Resets the state of the iterator.

Annotations
@Override
setValueback to summary
public V setValue(final V value)

Implements org.apache.commons.collections4.MapIterator.setValue.

Sets the value associated with the current key.

Parameters
value:V

the new value

Returns:V

the previous value

Annotations
@Override
Exceptions
UnsupportedOperationException:
if setValue is not supported by the map
IllegalStateException:
  • if next() has not yet been called
  • if remove() has been called since the last call to next()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Gets the iterator as a String.

Returns:String

a string version of the iterator

Annotations
@Override