All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.topicus.jdbc.shaded.com.google.common.collect.TreeMultimap Maven / Gradle / Ivy

There is a newer version: 1.1.6
Show newest version
/*
 * Copyright (C) 2007 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in nl.topicus.jdbc.shaded.com.liance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.nl.topicus.jdbc.shaded.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 nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.collect;

import static nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Preconditions.checkNotNull;

import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.annotations.GwtCompatible;
import nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.annotations.GwtIncompatible;
import java.nl.topicus.jdbc.shaded.io.IOException;
import java.nl.topicus.jdbc.shaded.io.ObjectInputStream;
import java.nl.topicus.jdbc.shaded.io.ObjectOutputStream;
import java.util.Collection;
import java.util.Comparator;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import nl.topicus.jdbc.shaded.javax.annotation.Nullable;

/**
 * Implementation of {@code Multimap} whose keys and values are ordered by
 * their natural ordering or by supplied nl.topicus.jdbc.shaded.com.arators. In all cases, this
 * implementation uses {@link Comparable#nl.topicus.jdbc.shaded.com.areTo} or {@link
 * Comparator#nl.topicus.jdbc.shaded.com.are} instead of {@link Object#equals} to determine
 * equivalence of instances.
 *
 * 

Warning: The nl.topicus.jdbc.shaded.com.arators or nl.topicus.jdbc.shaded.com.arables used must be consistent * with equals as explained by the {@link Comparable} class specification. * Otherwise, the resulting multiset will violate the general contract of {@link * SetMultimap}, which it is specified in terms of {@link Object#equals}. * *

The collections returned by {@code keySet} and {@code asMap} iterate * through the keys according to the key nl.topicus.jdbc.shaded.com.arator ordering or the natural * ordering of the keys. Similarly, {@code get}, {@code removeAll}, and {@code * replaceValues} return collections that iterate through the values according * to the value nl.topicus.jdbc.shaded.com.arator ordering or the natural ordering of the values. The * collections generated by {@code entries}, {@code keys}, and {@code values} * iterate across the keys according to the above key ordering, and for each * key they iterate across the values according to the value ordering. * *

The multimap does not store duplicate key-value pairs. Adding a new * key-value pair equal to an existing key-value pair has no effect. * *

Null keys and values are permitted (provided, of course, that the * respective nl.topicus.jdbc.shaded.com.arators support them). All optional multimap methods are * supported, and all returned views are modifiable. * *

This class is not threadsafe when any concurrent operations update the * multimap. Concurrent read operations will work correctly. To allow concurrent * update operations, wrap your multimap with a call to {@link * Multimaps#synchronizedSortedSetMultimap}. * *

See the Guava User Guide article on * {@code Multimap}. * * @author Jared Levy * @author Louis Wasserman * @since 2.0 */ @GwtCompatible(serializable = true, emulated = true) public class TreeMultimap extends AbstractSortedKeySortedSetMultimap { private transient Comparator keyComparator; private transient Comparator valueComparator; /** * Creates an empty {@code TreeMultimap} ordered by the natural ordering of * its keys and values. */ public static TreeMultimap create() { return new TreeMultimap(Ordering.natural(), Ordering.natural()); } /** * Creates an empty {@code TreeMultimap} instance using explicit nl.topicus.jdbc.shaded.com.arators. * Neither nl.topicus.jdbc.shaded.com.arator may be null; use {@link Ordering#natural()} to specify * natural order. * * @param keyComparator the nl.topicus.jdbc.shaded.com.arator that determines the key ordering * @param valueComparator the nl.topicus.jdbc.shaded.com.arator that determines the value ordering */ public static TreeMultimap create( Comparator keyComparator, Comparator valueComparator) { return new TreeMultimap(checkNotNull(keyComparator), checkNotNull(valueComparator)); } /** * Constructs a {@code TreeMultimap}, ordered by the natural ordering of its * keys and values, with the same mappings as the specified multimap. * * @param multimap the multimap whose contents are copied to this multimap */ public static TreeMultimap create( Multimap multimap) { return new TreeMultimap(Ordering.natural(), Ordering.natural(), multimap); } TreeMultimap(Comparator keyComparator, Comparator valueComparator) { super(new TreeMap>(keyComparator)); this.keyComparator = keyComparator; this.valueComparator = valueComparator; } private TreeMultimap( Comparator keyComparator, Comparator valueComparator, Multimap multimap) { this(keyComparator, valueComparator); putAll(multimap); } /** * {@inheritDoc} * *

Creates an empty {@code TreeSet} for a collection of values for one key. * * @return a new {@code TreeSet} containing a collection of values for one * key */ @Override SortedSet createCollection() { return new TreeSet(valueComparator); } @Override Collection createCollection(@Nullable K key) { if (key == null) { keyComparator().nl.topicus.jdbc.shaded.com.are(key, key); } return super.createCollection(key); } /** * Returns the nl.topicus.jdbc.shaded.com.arator that orders the multimap keys. */ public Comparator keyComparator() { return keyComparator; } @Override public Comparator valueComparator() { return valueComparator; } /* * The following @GwtIncompatible methods override the methods in * AbstractSortedKeySortedSetMultimap, so GWT will fall back to the ASKSSM implementations, * which return SortedSets and SortedMaps. */ @Override @GwtIncompatible // NavigableMap NavigableMap> backingMap() { return (NavigableMap>) super.backingMap(); } /** * @since 14.0 (present with return type {@code SortedSet} since 2.0) */ @Override @GwtIncompatible // NavigableSet public NavigableSet get(@Nullable K key) { return (NavigableSet) super.get(key); } @Override @GwtIncompatible // NavigableSet Collection unmodifiableCollectionSubclass(Collection collection) { return Sets.unmodifiableNavigableSet((NavigableSet) collection); } @Override @GwtIncompatible // NavigableSet Collection wrapCollection(K key, Collection collection) { return new WrappedNavigableSet(key, (NavigableSet) collection, null); } /** * {@inheritDoc} * *

Because a {@code TreeMultimap} has unique sorted keys, this method * returns a {@link NavigableSet}, instead of the {@link java.util.Set} specified * in the {@link Multimap} interface. * * @since 14.0 (present with return type {@code SortedSet} since 2.0) */ @Override @GwtIncompatible // NavigableSet public NavigableSet keySet() { return (NavigableSet) super.keySet(); } @Override @GwtIncompatible // NavigableSet NavigableSet createKeySet() { return new NavigableKeySet(backingMap()); } /** * {@inheritDoc} * *

Because a {@code TreeMultimap} has unique sorted keys, this method * returns a {@link NavigableMap}, instead of the {@link java.util.Map} specified * in the {@link Multimap} interface. * * @since 14.0 (present with return type {@code SortedMap} since 2.0) */ @Override @GwtIncompatible // NavigableMap public NavigableMap> asMap() { return (NavigableMap>) super.asMap(); } @Override @GwtIncompatible // NavigableMap NavigableMap> createAsMap() { return new NavigableAsMap(backingMap()); } /** * @serialData key nl.topicus.jdbc.shaded.com.arator, value nl.topicus.jdbc.shaded.com.arator, number of distinct keys, and * then for each distinct key: the key, number of values for that key, and * key values */ @GwtIncompatible // java.nl.topicus.jdbc.shaded.io.ObjectOutputStream private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(keyComparator()); stream.writeObject(valueComparator()); Serialization.writeMultimap(this, stream); } @GwtIncompatible // java.nl.topicus.jdbc.shaded.io.ObjectInputStream @SuppressWarnings("unchecked") // reading data stored by writeObject private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); keyComparator = checkNotNull((Comparator) stream.readObject()); valueComparator = checkNotNull((Comparator) stream.readObject()); setMap(new TreeMap>(keyComparator)); Serialization.populateMultimap(this, stream); } @GwtIncompatible // not needed in emulated source private static final long serialVersionUID = 0; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy