Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Guava is a suite of core and expanded libraries that include
utility classes, Google's collections, I/O classes, and
much more.
This project includes GWT-friendly sources.
/*
* Copyright (C) 2009 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.google.common.collect;
importstatic com.google.common.base.Preconditions.checkArgument;
importstatic com.google.common.base.Preconditions.checkNotNull;
importstatic com.google.common.collect.CollectPreconditions.checkEntryNotNull;
importstatic com.google.common.collect.Maps.keyOrNull;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.j2objc.annotations.WeakOuter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.Spliterator;
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A {@link NavigableMap} whose contents will never change, with many other important properties
* detailed at {@link ImmutableCollection}.
*
*
Warning: as with any sorted collection, you are strongly advised not to use a {@link
* Comparator} or {@link Comparable} type whose comparison behavior is inconsistent with
* equals. That is, {@code a.compareTo(b)} or {@code comparator.compare(a, b)} should equal zero
* if and only if {@code a.equals(b)}. If this advice is not followed, the resulting map will
* not correctly obey its specification.
*
*
See the Guava User Guide article on immutable collections.
*
* @author Jared Levy
* @author Louis Wasserman
* @since 2.0 (implements {@code NavigableMap} since 12.0)
*/@GwtCompatible(serializable = true, emulated = true)
publicfinalclassImmutableSortedMapextendsImmutableSortedMapFauxverideShimimplementsNavigableMap{
/**
* Returns a {@link Collector} that accumulates elements into an {@code ImmutableSortedMap} whose
* keys and values are the result of applying the provided mapping functions to the input
* elements. The generated map is sorted by the specified comparator.
*
*
If the mapped keys contain duplicates (according to the specified comparator), an {@code
* IllegalArgumentException} is thrown when the collection operation is performed. (This differs
* from the {@code Collector} returned by {@link Collectors#toMap(Function, Function)}, which
* throws an {@code IllegalStateException}.)
*
* @since 21.0
*/@Betapublicstatic Collector> toImmutableSortedMap(
Comparator comparator,
Function keyFunction,
Function valueFunction) {
return CollectCollectors.toImmutableSortedMap(comparator, keyFunction, valueFunction);
}
/**
* Returns a {@link Collector} that accumulates elements into an {@code ImmutableSortedMap} whose
* keys and values are the result of applying the provided mapping functions to the input
* elements.
*
*
If the mapped keys contain duplicates (according to the comparator), the the values are
* merged using the specified merging function. Entries will appear in the encounter order of the
* first occurrence of the key.
*
* @since 21.0
*/@Betapublicstatic Collector> toImmutableSortedMap(
Comparator comparator,
Function keyFunction,
Function valueFunction,
BinaryOperator mergeFunction) {
checkNotNull(comparator);
checkNotNull(keyFunction);
checkNotNull(valueFunction);
checkNotNull(mergeFunction);
return Collectors.collectingAndThen(
Collectors.toMap(
keyFunction, valueFunction, mergeFunction, () -> new TreeMap(comparator)),
ImmutableSortedMap::copyOfSorted);
}
/*
* TODO(kevinb): Confirm that ImmutableSortedMap is faster to construct and
* uses less memory than TreeMap; then say so in the class Javadoc.
*/privatestaticfinal Comparator NATURAL_ORDER = Ordering.natural();
privatestaticfinal ImmutableSortedMap NATURAL_EMPTY_MAP =
new ImmutableSortedMap<>(
ImmutableSortedSet.emptySet(Ordering.natural()), ImmutableList.