K - Key typeC - Some content obtainable from KV - Value typepublic final class ContentMap<K,C,V> extends Object implements Map<K,V>
Object.equals(Object). When using the usual Map that has an
interface as a key type, there is no sane way to treat instances of
different types as equal, because then we'd have to:
Object.equals(Object) in every type (which would
be a lot of duplicated code);Object.equals(Object) using methods of that
interface (which would still be duplicating code, not per interface
implementation but per interface).K"
For example, if PersonWithoutEquals and PersonFromStream
don't implement equals but have method Person#name() that returns
String, we could map Persons to something else like this:
Map map =
new ContentMap(Person::name);
map.put(new PersonWithoutEquals("Jeff"), 1);
map.get(new PersonFromStream(streamWithNameJeff)); // 1
This map has deterministic ordering.
This map doesn't support methods Map.keySet() and
Map.entrySet() because it doesn't store the keys of type
K, it just uses those to obtain the "hidden" keys of type C.| Constructor and Description |
|---|
ContentMap(Map<K,V> base,
java.util.function.Function<K,C> function)
Ctor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Deprecated.
|
boolean |
containsKey(Object o) |
boolean |
containsValue(Object o) |
Set<Map.Entry<K,V>> |
entrySet()
Deprecated.
|
V |
get(Object o) |
boolean |
isEmpty() |
Set<K> |
keySet()
Deprecated.
|
V |
put(K k,
V v)
Deprecated.
|
void |
putAll(Map<? extends K,? extends V> map)
Deprecated.
|
V |
remove(Object o)
Deprecated.
|
int |
size() |
Collection<V> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic boolean containsKey(Object o)
containsKey in interface Map<K,V>public boolean containsValue(Object o)
containsValue in interface Map<K,V>@Deprecated public void putAll(Map<? extends K,? extends V> map)
@Deprecated public void clear()
Copyright © 2012–2015 jcabi.com. All rights reserved.