Introduce Object Cache API and no-op implementation
[yangtools.git] / common / object-cache-api / src / main / java / org / opendaylight / yangtools / objcache / spi / NoopObjectCache.java
diff --git a/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java b/common/object-cache-api/src/main/java/org/opendaylight/yangtools/objcache/spi/NoopObjectCache.java
new file mode 100644 (file)
index 0000000..1163199
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.objcache.spi;
+
+import org.opendaylight.yangtools.concepts.ProductAwareBuilder;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+
+/**
+ * No-operation implementation of an Object Cache. This implementation
+ * does not do any caching, so it only returns the request object.
+ */
+public final class NoopObjectCache implements ObjectCache {
+       private static final NoopObjectCache INSTANCE = new NoopObjectCache();
+
+       private NoopObjectCache() {
+
+       }
+
+       /**
+        * Get the cache instance. Since the cache does not have any state,
+        * this method always returns a singleton instance.
+        *
+        * @return Cache instance.
+        */
+       public static NoopObjectCache getInstance() {
+               return INSTANCE;
+       }
+
+       @Override
+       public <T> T getReference(final T object) {
+               return object;
+       }
+
+       @Override
+       public <B extends ProductAwareBuilder<P>, P> P getProduct(final B builder) {
+               return builder.toInstance();
+       }
+}