Moti Asayag has uploaded a new change for review.

Change subject: core: Introduce BusinessEntityMap
......................................................................

core: Introduce BusinessEntityMap

The map allows to identify a Nameable business entity
within the map either by its name or by its id.
The map will be useful when certain entities provided
by the clients either by their ID or by name and that
entity should be resolved by those identifiers, i.e.
NetworkAttachment or Bond.

Change-Id: I4540f813f8a787a38ba3e692b6ddd3fcc6be536a
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntityMap.java
1 file changed, 47 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/33329/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntityMap.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntityMap.java
new file mode 100644
index 0000000..ab7767a
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/BusinessEntityMap.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.core.common.businessentities;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class BusinessEntityMap<E extends BusinessEntity<Guid> & Nameable> {
+    private Map<String, E> entitiesByName;
+    private Map<Guid, E> entitiesById;
+
+    public BusinessEntityMap(Collection<E> entities) {
+        entitiesByName = new HashMap<String, E>();
+        entitiesById = new HashMap<Guid, E>();
+
+        for (E e : entities) {
+            if (e.getName() != null) {
+                entitiesByName.put(e.getName(), e);
+            }
+
+            if (e.getId() != null) {
+                entitiesById.put(e.getId(), e);
+            }
+        }
+    }
+
+    public E get(String name) {
+        return entitiesByName.get(name);
+    }
+
+    public E get(Guid id) {
+        return entitiesById.get(id);
+    }
+
+    public boolean containsKey(String name) {
+        return entitiesByName.containsKey(name);
+    }
+
+    public boolean containsKey(Guid id) {
+        return entitiesById.containsKey(id);
+    }
+
+    public E get(Guid id, String name) {
+        return id == null ? get(name) : get(id);
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/33329
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4540f813f8a787a38ba3e692b6ddd3fcc6be536a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Moti Asayag <masa...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to