Example usage for com.google.common.collect ImmutableSortedMap lastKey

List of usage examples for com.google.common.collect ImmutableSortedMap lastKey

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedMap lastKey.

Prototype

public K lastKey() 

Source Link

Usage

From source file:google.registry.model.common.TimedTransitionProperty.java

/**
 * Returns a new immutable {@code TimedTransitionProperty} containing the same transitions as the
 * current object, plus the additional specified transition.
 *
 * @param transitionTime the time of the new transition
 * @param transitionValue the value of the new transition
 * @param transitionClass the class of transitions in this map
 * @param allowedTransitions map of all possible state-to-state transitions
 * @param allowedTransitionMapName transition map description string for error messages
 *///from  w w w  .j av  a2  s . c o m
public TimedTransitionProperty<V, T> copyWithAddedTransition(DateTime transitionTime, V transitionValue,
        Class<T> transitionClass, ImmutableMultimap<V, V> allowedTransitions, String allowedTransitionMapName) {
    ImmutableSortedMap<DateTime, V> currentMap = toValueMap();
    checkArgument(transitionTime.isAfter(currentMap.lastKey()),
            "New transitions can only be appended after the last previous transition.");
    Map<DateTime, V> newInnerMap = new HashMap<>(currentMap);
    newInnerMap.put(transitionTime, transitionValue);
    ImmutableSortedMap<DateTime, V> newMap = ImmutableSortedMap.<DateTime, V>copyOf(newInnerMap);
    validateTimedTransitionMap(newMap, allowedTransitions, allowedTransitionMapName);
    return fromValueMap(newMap, transitionClass);
}