From ea4789318932d359cb4de57e0cd055bf5622d937 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Fri, 3 Aug 2012 15:09:42 +0000 Subject: QPID-4189: Add unit tests for ConfiguredObjectToMapConverter git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1369015 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/server/model/Model.java | 62 ++++++++++++---------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'qpid/java/broker/src') diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java index fd429321c8..36179fc105 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java @@ -29,33 +29,20 @@ import java.util.Map; public class Model { - private static final Map, Collection>> - PARENTS = new HashMap, Collection>>(); + private static final Model MODEL_INSTANCE = new Model(); + private final Map, Collection>> + _parents = new HashMap, Collection>>(); - private static final Map, Collection>> - CHILDREN = new HashMap, Collection>>(); + private final Map, Collection>> + _children = new HashMap, Collection>>(); - static void addRelationship(Class parent, Class child) + public static Model getInstance() { - Collection> parents = PARENTS.get(child); - if(parents == null) - { - parents = new ArrayList>(); - PARENTS.put(child, parents); - } - parents.add(parent); - - Collection> children = CHILDREN.get(parent); - if(children == null) - { - children = new ArrayList>(); - CHILDREN.put(parent, children); - } - children.add(child); + return MODEL_INSTANCE; } - static + private Model() { addRelationship(Broker.class, VirtualHost.class); addRelationship(Broker.class, Port.class); @@ -78,20 +65,39 @@ public class Model addRelationship(Session.class, Consumer.class); addRelationship(Session.class, Publisher.class); - } - public static Collection> getParentTypes(Class child) + public Collection> getParentTypes(Class child) { - Collection> parentTypes = PARENTS.get(child); - return parentTypes == null ? Collections.EMPTY_LIST + Collection> parentTypes = _parents.get(child); + return parentTypes == null ? Collections.>emptyList() : Collections.unmodifiableCollection(parentTypes); } - public static Collection> getChildTypes(Class parent) + public Collection> getChildTypes(Class parent) { - Collection> childTypes = CHILDREN.get(parent); - return childTypes == null ? Collections.EMPTY_LIST + Collection> childTypes = _children.get(parent); + return childTypes == null ? Collections.>emptyList() : Collections.unmodifiableCollection(childTypes); } + + private void addRelationship(Class parent, Class child) + { + Collection> parents = _parents.get(child); + if(parents == null) + { + parents = new ArrayList>(); + _parents.put(child, parents); + } + parents.add(parent); + + Collection> children = _children.get(parent); + if(children == null) + { + children = new ArrayList>(); + _children.put(parent, children); + } + children.add(child); + } + } -- cgit v1.2.1