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

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

Introduction

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

Prototype

ImmutableSortedMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) 

Source Link

Usage

From source file:google.registry.model.translators.CommitLogRevisionsTranslatorFactory.java

/**
 * Add a reference to the current commit log to the resource's revisions map.
 *
 * <p>This method also prunes the revisions map. It guarantees to keep enough data so that floor
 * will work going back N days. It does this by making sure one entry exists before that duration,
 * and pruning everything after it. The size of the map is guaranteed to never exceed N+2.
 *
 * <p>We store a maximum of one entry per day. It will be the last transaction that happened on
 * that day./*from   ww  w .  j a va  2 s.  c o m*/
 *
 * @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention()
 */
@Override
ImmutableSortedMap<DateTime, Key<CommitLogManifest>> transformBeforeSave(
        ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions) {
    DateTime now = ofy().getTransactionTime();
    DateTime threshold = now.minus(getCommitLogDatastoreRetention());
    DateTime preThresholdTime = firstNonNull(revisions.floorKey(threshold), START_OF_TIME);
    return new ImmutableSortedMap.Builder<DateTime, Key<CommitLogManifest>>(Ordering.natural())
            .putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false))
            .put(now, ofy().getCommitLogManifestKey()).build();
}