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