2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.mode.impl.add;
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.Comparator;
15 import org.opendaylight.protocol.bgp.mode.impl.AbstractOffsetMap;
18 * A map of {@link RouteKey} to an offset.
20 * @see AbstractOffsetMap
22 final class RouteKeyOffsets extends AbstractOffsetMap<RouteKey, RouteKeyOffsets> {
23 private static final LoadingCache<ImmutableSet<RouteKey>, RouteKeyOffsets> OFFSETMAPS = CacheBuilder.newBuilder()
24 .weakValues().build(new CacheLoader<ImmutableSet<RouteKey>, RouteKeyOffsets>() {
26 public RouteKeyOffsets load(final ImmutableSet<RouteKey> key) {
27 return new RouteKeyOffsets(key);
30 private static final Comparator<RouteKey> COMPARATOR = RouteKey::compareTo;
31 private static final RouteKey[] EMPTY_KEYS = new RouteKey[0];
33 static final RouteKeyOffsets EMPTY = new RouteKeyOffsets(ImmutableSet.of());
35 private RouteKeyOffsets(final ImmutableSet<RouteKey> routeKeys) {
36 super(EMPTY_KEYS, COMPARATOR, routeKeys);
40 protected Comparator<RouteKey> comparator() {
45 protected RouteKey[] emptyKeys() {
50 protected RouteKeyOffsets instanceForKeys(final ImmutableSet<RouteKey> newKeys) {
51 return OFFSETMAPS.getUnchecked(newKeys);