First version after introduction of meaningful ids and Identifiable interface.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / CompositeConfig.java
index b378052c207b05015b78d427870070c733e7dcbf..5166315e7640504643c80307c42ea782a0902a9c 100644 (file)
  */
 package org.wamblee.xmlrouter.impl;
 
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.wamblee.xmlrouter.common.Id;
 import org.wamblee.xmlrouter.config.Config;
 
 public class CompositeConfig<T> implements ExtendedConfig<T> {
 
-    private Map<Id<T>, T> configs;
+    private Id<Config> id;
+    private List<T> configs;
 
-    public CompositeConfig() {
-        configs = new LinkedHashMap<Id<T>, T>();
+    public CompositeConfig(Id<Config> aId) {
+        id = aId;
+        configs = new ArrayList<T>();
+    }
+
+    @Override
+    public Id<Config> getId() {
+        // TODO test id.
+        return id;
     }
 
     public void add(Config<T> aConfig) {
-        for (Id<T> id : aConfig.map().keySet()) {
-            configs.put(id, aConfig.map().get(id));
+        // TODO check duplicate config.
+        for (T item : aConfig.values()) {
+            configs.add(item);
         }
     }
 
     @Override
-    public Map<Id<T>, T> map() {
+    public List<T> values() {
         return configs;
     }
 
@@ -46,13 +55,12 @@ public class CompositeConfig<T> implements ExtendedConfig<T> {
         return false;
     }
 
-    private void notSupported() {
-        throw new RuntimeException("readonly instance");
-    }
-
     @Override
-    public Id<T> add(T aT) {
+    public void add(T aT) {
         notSupported();
-        return null;
+    }
+
+    private void notSupported() {
+        throw new RuntimeException("readonly instance");
     }
 }