@ SuppressWarnings ( "unchecked" ) public static < K , V > ImmutableSortedMap < K , V > copyOfSorted ( SortedMap < K , ? extends V > map ) { Comparator < ? super K > comparator = map . comparator ( ) ; if ( comparator == null ) { // If map has a null comparator, the keys should have a natural ordering, // even though K doesn't explicitly implement Comparable. comparator = ( Comparator < ? super K > ) NATURAL_ORDER ; } if ( map instanceof ImmutableSortedMap ) { // TODO(kevinb): Prove that this cast is safe, even though // Collections.unmodifiableSortedMap requires the same key type. @ SuppressWarnings ( "unchecked" ) ImmutableSortedMap < K , V > kvMap = ( ImmutableSortedMap < K , V > ) map ; if ( ! kvMap . isPartialView ( ) ) { return kvMap ; } } return fromEntries ( comparator , true , map . entrySet ( ) ) ; }
Returns an immutable map containing the same entries as the provided sorted map with the same ordering .