
javadoc.com.google.common.collect.SortedMaps.html Maven / Gradle / Ivy
SortedMaps (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.collect
Class SortedMaps
java.lang.Object
com.google.common.collect.SortedMaps
Deprecated. Use the identical methods in Maps
. This class is
scheduled for deletion from Guava in Guava release 12.0.
@Beta
@Deprecated
@GwtCompatible
public final class SortedMaps
- extends Object
Static utility methods pertaining to SortedMap
instances.
- Since:
- 8.0
- Author:
- Louis Wasserman
Method Summary | ||
---|---|---|
static
|
difference(SortedMap<K,? extends V> left,
Map<? extends K,? extends V> right)
Deprecated. Use Maps.difference(SortedMap, Map) |
|
static
|
filterEntries(SortedMap<K,V> unfiltered,
Predicate<? super Map.Entry<K,V>> entryPredicate)
Deprecated. Returns a sorted map containing the mappings in unfiltered that
satisfy a predicate. |
|
static
|
filterKeys(SortedMap<K,V> unfiltered,
Predicate<? super K> keyPredicate)
Deprecated. Returns a sorted map containing the mappings in unfiltered whose
keys satisfy a predicate. |
|
static
|
filterValues(SortedMap<K,V> unfiltered,
Predicate<? super V> valuePredicate)
Deprecated. Returns a sorted map containing the mappings in unfiltered whose
values satisfy a predicate. |
|
static
|
transformEntries(SortedMap<K,V1> fromMap,
Maps.EntryTransformer<? super K,? super V1,V2> transformer)
Deprecated. Use Maps.transformEntries(SortedMap, EntryTransformer) |
|
static
|
transformValues(SortedMap<K,V1> fromMap,
Function<? super V1,V2> function)
Deprecated. Use Maps.transformValues(SortedMap, Function) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
transformValues
@Deprecated public static <K,V1,V2> SortedMap<K,V2> transformValues(SortedMap<K,V1> fromMap, Function<? super V1,V2> function)
- Deprecated. Use
Maps.transformValues(SortedMap, Function)
- Returns a view of a sorted map where each value is transformed by a function. All other properties of the map, such as iteration order, are left intact. For example, the code:
SortedMap<String, Integer> map = ImmutableSortedMap.of("a", 4, "b", 9); Function<Integer, Double> sqrt = new Function<Integer, Double>() { public Double apply(Integer in) { return Math.sqrt((int) in); } }; SortedMap<String, Double> transformed = Maps.transformSortedValues(map, sqrt); System.out.println(transformed);
{a=2.0, b=3.0}
.Changes in the underlying map are reflected in this view. Conversely, this view supports removal operations, and these are reflected in the underlying map.
It's acceptable for the underlying map to contain null keys, and even null values provided that the function is capable of accepting null input. The transformed map might contain null values, if the function sometimes gives a null result.
The returned map is not thread-safe or serializable, even if the underlying map is.
The function is applied lazily, invoked when needed. This is necessary for the returned map to be a view, but it means that the function will be applied many times for bulk operations like
Map.containsValue(java.lang.Object)
andMap.toString()
. For this to perform well,function
should be fast. To avoid lazy evaluation when the returned map doesn't need to be a view, copy the returned map into a new map of your choosing. - Returns a view of a sorted map where each value is transformed by a function. All other properties of the map, such as iteration order, are left intact. For example, the code:
transformEntries
@Deprecated public static <K,V1,V2> SortedMap<K,V2> transformEntries(SortedMap<K,V1> fromMap, Maps.EntryTransformer<? super K,? super V1,V2> transformer)
- Deprecated. Use
Maps.transformEntries(SortedMap, EntryTransformer)
- Returns a view of a sorted map whose values are derived from the original sorted map's entries. In contrast to
transformValues(java.util.SortedMap
, this method's entry-transformation logic may depend on the key as well as the value., com.google.common.base.Function super V1, V2>) All other properties of the transformed map, such as iteration order, are left intact. For example, the code:
Map<String, Boolean> options = ImmutableSortedMap.of("verbose", true, "sort", false); EntryTransformer<String, Boolean, String> flagPrefixer = new EntryTransformer<String, Boolean, String>() { public String transformEntry(String key, Boolean value) { return value ? key : "yes" + key; } }; SortedMap<String, String> transformed = LabsMaps.transformSortedEntries(options, flagPrefixer); System.out.println(transformed);
{sort=yessort, verbose=verbose}
.Changes in the underlying map are reflected in this view. Conversely, this view supports removal operations, and these are reflected in the underlying map.
It's acceptable for the underlying map to contain null keys and null values provided that the transformer is capable of accepting null inputs. The transformed map might contain null values if the transformer sometimes gives a null result.
The returned map is not thread-safe or serializable, even if the underlying map is.
The transformer is applied lazily, invoked when needed. This is necessary for the returned map to be a view, but it means that the transformer will be applied many times for bulk operations like
Map.containsValue(java.lang.Object)
andObject.toString()
. For this to perform well,transformer
should be fast. To avoid lazy evaluation when the returned map doesn't need to be a view, copy the returned map into a new map of your choosing.Warning: This method assumes that for any instance
k
ofEntryTransformer
key typeK
,k.equals(k2)
implies thatk2
is also of typeK
. Using anEntryTransformer
key type for which this may not hold, such asArrayList
, may risk aClassCastException
when calling methods on the transformed map. - Returns a view of a sorted map whose values are derived from the original sorted map's entries. In contrast to
difference
@Deprecated public static <K,V> SortedMapDifference<K,V> difference(SortedMap<K,? extends V> left, Map<? extends K,? extends V> right)
- Deprecated. Use
Maps.difference(SortedMap, Map)
- Computes the difference between two sorted maps, using the comparator of the left map, or
Ordering.natural()
if the left map uses the natural ordering of its elements. This difference is an immutable snapshot of the state of the maps at the time this method is called. It will never change, even if the maps change at a later time.Since this method uses
TreeMap
instances internally, the keys of the right map must all compare as distinct according to the comparator of the left map.Note:If you only need to know whether two sorted maps have the same mappings, call
left.equals(right)
instead of this method.- Parameters:
left
- the map to treat as the "left" map for purposes of comparisonright
- the map to treat as the "right" map for purposes of comparison- Returns:
- the difference between the two maps
- Computes the difference between two sorted maps, using the comparator of the left map, or
filterKeys
@GwtIncompatible(value="untested") public static <K,V> SortedMap<K,V> filterKeys(SortedMap<K,V> unfiltered, Predicate<? super K> keyPredicate)
- Deprecated.
- Returns a sorted map containing the mappings in
unfiltered
whose keys satisfy a predicate. The returned map is a live view ofunfiltered
; changes to one affect the other.The resulting map's
keySet()
,entrySet()
, andvalues()
views have iterators that don't supportremove()
, but all other methods are supported by the map and its views. When given a key that doesn't satisfy the predicate, the map'sput()
andputAll()
methods throw anIllegalArgumentException
.When methods such as
removeAll()
andclear()
are called on the filtered map or its views, only mappings whose keys satisfy the filter will be removed from the underlying map.The returned map isn't threadsafe or serializable, even if
unfiltered
is.Many of the filtered map's methods, such as
size()
, iterate across every key/value mapping in the underlying map and determine which satisfy the filter. When a live view is not needed, it may be faster to copy the filtered map and use the copy.Warning:
keyPredicate
must be consistent with equals, as documented atPredicate.apply(T)
. Do not provide a predicate such asPredicates.instanceOf(ArrayList.class)
, which is inconsistent with equals. - Returns a sorted map containing the mappings in
filterValues
@GwtIncompatible(value="untested") public static <K,V> SortedMap<K,V> filterValues(SortedMap<K,V> unfiltered, Predicate<? super V> valuePredicate)
- Deprecated.
- Returns a sorted map containing the mappings in
unfiltered
whose values satisfy a predicate. The returned map is a live view ofunfiltered
; changes to one affect the other.The resulting map's
keySet()
,entrySet()
, andvalues()
views have iterators that don't supportremove()
, but all other methods are supported by the map and its views. When given a value that doesn't satisfy the predicate, the map'sput()
,putAll()
, andMap.Entry.setValue(V)
methods throw anIllegalArgumentException
.When methods such as
removeAll()
andclear()
are called on the filtered map or its views, only mappings whose values satisfy the filter will be removed from the underlying map.The returned map isn't threadsafe or serializable, even if
unfiltered
is.Many of the filtered map's methods, such as
size()
, iterate across every key/value mapping in the underlying map and determine which satisfy the filter. When a live view is not needed, it may be faster to copy the filtered map and use the copy.Warning:
valuePredicate
must be consistent with equals, as documented atPredicate.apply(T)
. Do not provide a predicate such asPredicates.instanceOf(ArrayList.class)
, which is inconsistent with equals. - Returns a sorted map containing the mappings in
filterEntries
@GwtIncompatible(value="untested") public static <K,V> SortedMap<K,V> filterEntries(SortedMap<K,V> unfiltered, Predicate<? super Map.Entry<K,V>> entryPredicate)
- Deprecated.
- Returns a sorted map containing the mappings in
unfiltered
that satisfy a predicate. The returned map is a live view ofunfiltered
; changes to one affect the other.The resulting map's
keySet()
,entrySet()
, andvalues()
views have iterators that don't supportremove()
, but all other methods are supported by the map and its views. When given a key/value pair that doesn't satisfy the predicate, the map'sput()
andputAll()
methods throw anIllegalArgumentException
. Similarly, the map's entries have aMap.Entry.setValue(V)
method that throws anIllegalArgumentException
when the existing key and the provided value don't satisfy the predicate.When methods such as
removeAll()
andclear()
are called on the filtered map or its views, only mappings that satisfy the filter will be removed from the underlying map.The returned map isn't threadsafe or serializable, even if
unfiltered
is.Many of the filtered map's methods, such as
size()
, iterate across every key/value mapping in the underlying map and determine which satisfy the filter. When a live view is not needed, it may be faster to copy the filtered map and use the copy.Warning:
entryPredicate
must be consistent with equals, as documented atPredicate.apply(T)
. - Returns a sorted map containing the mappings in
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.