Remove jacoco overrides
[yangtools.git] / common / object-cache-api / src / main / java / org / opendaylight / yangtools / objcache / ObjectCache.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.objcache;
9
10 import javax.annotation.Nonnull;
11 import javax.annotation.Nullable;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
14
15 /**
16  * A cache of objects. Caches are useful for reducing memory overhead
17  * stemming from multiple copies of identical objects -- by putting
18  * a cache in the instantiation path, one can expend some memory on
19  * indexes and spend some CPU cycles on walking the index to potentially
20  * end up with a reused object.
21  *
22  * <p>
23  * Note that the cached objects should really be semantically {@link Immutable}.
24  * This interface does not enforce that interface contract simply because
25  * there are third-party objects which fulfill this contract.
26  */
27 public interface ObjectCache {
28     /**
29      * Get a reference for an object which is equal to specified object.
30      * The cache is free return either a cached instance, or retain the
31      * object and return it back.
32      *
33      * @param <T> object type
34      * @param object Requested object, may be null
35      * @return Reference to an object which is equal to the one passed in.
36      *         If @object was @null, this method returns @null.
37      */
38     <T> T getReference(@Nullable T object);
39
40     /**
41      * Get a reference to an object equal to the product of a builder.
42      * The builder is expected to remain constant while this method
43      * executes. Unlike {@link #getReference(Object)}, this method has
44      * the potential of completely eliding the product instantiation.
45      *
46      * @param <P> produced object type
47      * @param <B> builder type
48      * @param builder Builder instance, may not be null
49      * @return Result of builder's toInstance() product, or an equal
50      *         object.
51      */
52     <B extends ProductAwareBuilder<P>, P> P getProduct(@Nonnull B builder);
53 }