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.rib.impl;
10 import com.google.common.base.Preconditions;
11 import java.util.IdentityHashMap;
13 import javax.annotation.concurrent.NotThreadSafe;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 * A caching decorator for {@link AbstractImportPolicy}. Performs caching of effective
18 * attributes using an {@link IdentityHashMap} for fast lookup and reuse of resulting
22 final class CachingImportPolicy extends AbstractImportPolicy {
23 private final Map<ContainerNode, ContainerNode> cache = new IdentityHashMap<>();
24 private final AbstractImportPolicy delegate;
26 CachingImportPolicy(final AbstractImportPolicy delegate) {
27 this.delegate = Preconditions.checkNotNull(delegate);
31 ContainerNode effectiveAttributes(final ContainerNode attributes) {
32 ContainerNode ret = this.cache.get(attributes);
34 ret = this.delegate.effectiveAttributes(attributes);
36 this.cache.put(attributes, ret);