Introduce Object Cache API and no-op implementation
[yangtools.git] / common / object-cache-api / src / main / java / org / opendaylight / yangtools / objcache / spi / NoopObjectCache.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.spi;
9
10 import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
11 import org.opendaylight.yangtools.objcache.ObjectCache;
12
13 /**
14  * No-operation implementation of an Object Cache. This implementation
15  * does not do any caching, so it only returns the request object.
16  */
17 public final class NoopObjectCache implements ObjectCache {
18         private static final NoopObjectCache INSTANCE = new NoopObjectCache();
19
20         private NoopObjectCache() {
21
22         }
23
24         /**
25          * Get the cache instance. Since the cache does not have any state,
26          * this method always returns a singleton instance.
27          *
28          * @return Cache instance.
29          */
30         public static NoopObjectCache getInstance() {
31                 return INSTANCE;
32         }
33
34         @Override
35         public <T> T getReference(final T object) {
36                 return object;
37         }
38
39         @Override
40         public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
41                 return builder.toInstance();
42         }
43 }