Maps Package Method List:
Or generics create a map:
Public Static<k, v> hashmap<k, v>Newhashmap () {return NewHashmap<k, v>(); } Public Static<k, v> hashmap<k, v> newhashmapwithexpectedsize (intexpectedsize) { return NewHashmap<k, v>(Capacity (expectedsize)); } Public Static<k, v> hashmap<k, v> newhashmap (map<?extendsK?extendsV>map) {return NewHashmap<k, v>(map);} Public Static<k, v> linkedhashmap<k, v>Newlinkedhashmap () {return NewLinkedhashmap<k, v>();} Public Static<k, v> linkedhashmap<k, v> newlinkedhashmapwithexpectedsize (intexpectedsize) {return NewLinkedhashmap<k, v>(Capacity (expectedsize));} Public Static<k, v> linkedhashmap<k, v> newlinkedhashmap (map<?extendsK?extendsV>map) { return NewLinkedhashmap<k, v>(map); } Public Static<k, v> concurrentmap<k, v>Newconcurrentmap () {return NewMapMaker (). <k, v>Makemap (); } Public Static<kextendsComparable, v> treemap<k, v>Newtreemap () {return NewTreemap<k, v>(); }
There are some enummap, identitiymap and so on, but not often used, it is not affixed.
There are several other ways to do this in map, just stick to the most common one.
Public Static<k, v> mapdifference<k, v>difference (Map<?extendsK?extendsV> left, map<?extendsK?extendsV>Right ) { if(leftinstanceofSortedMap) {SortedMap<k, huh?extendsV> Sortedleft = (sortedmap<k,?extendsV>) left; Sortedmapdifference<k, v> result =difference (sortedleft, right); returnresult; } returndifference (left, right, equivalence.equals ()); }
Set and other content to map, this method in obtaining some object to map operation is more useful.
Public Static Super K, v> function){ifinstanceof SortedSet) { return asmap ( Sortedset<k>) set, function); Else { returnnew asmapview<k, V>(set, function); } }
Some objects go immutable map, as above, you just declare a guava function to overwrite the following its methods and then pass in:
Public static <k, v> immutablemap<k, v> tomap ( iterableSuper K, v> valuefunction) { return tomap (Keys.iterator (), valuefunction); }
The next one is a bit of a shot, and then never know where to use the method, anyway, I did not encounter this scenario:
/*** Returns A view of a map where each value are transformed by a function. All * Other properties of the map, such as iteration order, is left intact. For * example, the code: <pre> {@code* * map<string, integer> Map = Immutablemap.of ("A", 4, "B", 9); * Function<integer, double> sqrt = * New Function<integer, double> () {* Public Double app Ly (Integer in) {* return math.sqrt (int.) in); * } * }; * map<string, double> transformed = Maps.transformvalues (Map, sqrt); * SYSTEM.OUT.PRINTLN (transformed);} </pre> * * ... prints {@code{a=2.0, b=3.0}}. * public static <k, V1, v2> map<k, v2> transformvalues (map<k, v1> frommap, function<? Super V1 , v2> function) {return transformentries (Frommap, Asentrytransformer (function)); }
Basically each type of map will have several methods to deal with, not listed.
And then there's the incoming Prediction filter map:
@CheckReturnValue Public Static<k, v> map<k, v>FilterKeys (Map<k, v> unfiltered,Finalpredicate<?SuperK>keypredicate) { if(unfilteredinstanceofSortedMap) { returnFilterKeys (Sortedmap<k, v>) unfiltered, keypredicate); } Else if(unfilteredinstanceofBiMap) { returnFilterKeys (Bimap<k, v>) unfiltered, keypredicate); } checknotnull (KeyPredicate); predicate<entry<k,?>> entrypredicate =keypredicateonentries (keypredicate); return(unfilteredinstanceofAbstractfilteredmap)? Filterfiltered (Abstractfilteredmap<k, v>) unfiltered, entrypredicate):NewFilteredkeymap<k, v>(Checknotnull (unfiltered), keypredicate, entrypredicate); }
@CheckReturnValue Public Static<k, v> map<k, v>filtervalues (Map<k, v> unfiltered,Finalpredicate<?SuperV>valuepredicate) { if(unfilteredinstanceofSortedMap) { returnFiltervalues (Sortedmap<k, v>) unfiltered, valuepredicate); } Else if(unfilteredinstanceofBiMap) { returnFiltervalues (Bimap<k, v>) unfiltered, valuepredicate); } returnFilterentries (unfiltered, maps.<v>valuepredicateonentries (valuepredicate)); }
@CheckReturnValue Public Static<k, v> map<k, v>filterentries (Map<k, v> unfiltered, predicate<?SuperEntry<k, v>>entrypredicate) { if(unfilteredinstanceofSortedMap) { returnFilterentries (Sortedmap<k, v>) unfiltered, entrypredicate); } Else if(unfilteredinstanceofBiMap) { returnFilterentries (Bimap<k, v>) unfiltered, entrypredicate); } checknotnull (Entrypredicate); return(unfilteredinstanceofAbstractfilteredmap)? Filterfiltered (Abstractfilteredmap<k, v>) unfiltered, entrypredicate):NewFilteredentrymap<k, v>(Checknotnull (unfiltered), entrypredicate); }
Should I encounter too few scenes, list, set, map has a lot of code to deal with the Navigate type and immutable type of collection, feeling still too little. Need to study it further.
Guava Pack Learning---Maps