aboutsummaryrefslogtreecommitdiffstats
path: root/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository
diff options
context:
space:
mode:
Diffstat (limited to 'evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository')
-rw-r--r--evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespository.java21
-rw-r--r--evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespositoryInMem.java91
2 files changed, 112 insertions, 0 deletions
diff --git a/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespository.java b/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespository.java
new file mode 100644
index 0000000..80bebc7
--- /dev/null
+++ b/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespository.java
@@ -0,0 +1,21 @@
+package com.cablelabs.vcpe.evc.evcbase.repository;
+
+import com.cablelabs.vcpe.evc.evcbase.model.Evc;
+
+import java.util.List;
+
+/**
+ * Created by steve on 5/25/15.
+ */
+public interface EvcRespository
+{
+ // TODO add exceptions
+
+ Evc add(Evc evc); // returns null if already exists, otherwise returns stored evc
+ Evc get(String evcId); // returns null if not found, otherwise stored evc
+ Evc update(Evc evc); // returns null if did not exit, otherwise evc as it was previous to update (put in any case)
+ Evc delete(String evcId); // returns null if not found, otherwise evc as it was previous to delete
+ int count(); // number of Evc stored in the repo
+ public void dump(int tab); // print out contents of the repo
+ List<Evc> getAll();
+}
diff --git a/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespositoryInMem.java b/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespositoryInMem.java
new file mode 100644
index 0000000..158ae3f
--- /dev/null
+++ b/evc/evcbase/src/main/java/com/cablelabs/vcpe/evc/evcbase/repository/EvcRespositoryInMem.java
@@ -0,0 +1,91 @@
+package com.cablelabs.vcpe.evc.evcbase.repository;
+
+import com.cablelabs.vcpe.common.Dbg;
+import com.cablelabs.vcpe.evc.evcbase.model.Evc;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+
+/*
+ Singleton that contains a hashmap which holds instances of Evc objects, indexed by CiS ID
+ */
+
+public enum EvcRespositoryInMem implements EvcRespository {
+ INSTANCE; // Singleton
+
+ private Map<String, Evc> evcDB = new ConcurrentHashMap<>();
+
+ @Override
+ //--------------------------------------------------------
+ public Evc add(Evc evc)
+ //--------------------------------------------------------
+ {
+ if ( this.get(evc.getId()) != null ) {
+ return null;
+ }
+ evcDB.put(evc.getId(), evc );
+ return evc;
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public Evc get(String evcId) {
+ return evcDB.get(evcId);
+ }
+ //--------------------------------------------------------
+
+ @Override
+ //--------------------------------------------------------
+ public Evc update(Evc evc)
+ //--------------------------------------------------------
+ {
+ // put returns null if evc did not exist, other returns evc as it stood prior to put
+ return evcDB.put(evc.getId(), evc);
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public Evc delete(String evcId)
+ //--------------------------------------------------------
+ {
+ // remove returns null if evc did not exist, other returns evc as it stood prior to remove
+ return evcDB.remove(evcId);
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public int count() {
+ return evcDB.size();
+ }
+ //--------------------------------------------------------
+
+ @Override
+ //--------------------------------------------------------
+ public List<Evc> getAll()
+ //--------------------------------------------------------
+ {
+ List<Evc> evcList = new ArrayList<Evc>(evcDB.values());
+ return evcList;
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public void dump(int tab)
+ //--------------------------------------------------------
+ {
+ Dbg.p(tab, "Evc Repo: " + evcDB.size() + " entrie(s)");
+ int numEvc = 0;
+ for (Evc curEvc : evcDB.values()) {
+ numEvc++;
+ Dbg.p(tab+1, "<Entry " + numEvc+">");
+ curEvc.dump(tab+2);
+ }
+ }
+}