/* * Copyright (C) 2012 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; import java.util.Map; import java.util.NoSuchElementException; import javax.annotation.Nullable; import com.google.common.annotations.Beta; /** * A mapping from disjoint nonempty ranges to non-null values. Queries look up * the value associated with the range (if any) that contains a specified key. * *
* In contrast to {@link RangeSet}, no "coalescing" is done of
* {@linkplain Range#isConnected(Range) connected} ranges, even if they are
* mapped to the same value.
*
* @author Louis Wasserman
* @since 14.0
*/
@Beta
public interface RangeMap
* Specifically, if any range in this range map contains the specified key, the
* value associated with that range is returned.
*/
@Nullable
V get(K key);
/**
* Returns the range containing this key and its associated value, if such a
* range is present in the range map, or {@code null} otherwise.
*/
@Nullable
Map.Entry
* Specifically, after a call to {@code put(range, value)}, if
* {@link Range#contains(Comparable) range.contains(k)}, then
* {@link #get(Comparable) get(k)} will return {@code value}.
*
*
* If {@code range} {@linkplain Range#isEmpty() is empty}, then this is a no-op.
*/
void put(Range
* If {@code !range.contains(k)}, {@link #get(Comparable) get(k)} will return
* the same result before and after a call to {@code remove(range)}. If
* {@code range.contains(k)}, then after a call to {@code remove(range)},
* {@code get(k)} will return {@code null}.
*/
void remove(Range
* It is guaranteed that no empty ranges will be in the returned {@code Map}.
*/
Map
* For example, if {@code rangeMap} had the entries
* {@code [1, 5] => "foo", (6, 8) => "bar", (10, \u2025) => "baz"} then
* {@code rangeMap.subRangeMap(Range.open(3, 12))} would return a range map with
* the entries {@code (3, 5) => "foo", (6, 8) => "bar", (10, 12) => "baz"}.
*
*
* The returned range map supports all optional operations that this range map
* supports, except for {@code asMapOfRanges().iterator().remove()}.
*
*
* The returned range map will throw an {@link IllegalArgumentException} on an
* attempt to insert a range not {@linkplain Range#encloses(Range) enclosed} by
* {@code range}.
*/
RangeMap