From d127a93ed795ed4cca6e1ddb8251065b8a35d3eb Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 17 Sep 2016 17:21:39 +0200 Subject: [PATCH] [Minor] SimpleStrolchElementListener now stores as map --- .../xml/SimpleStrolchElementListener.java | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java b/li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java index c339f2725..8cdb3cedc 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/SimpleStrolchElementListener.java @@ -17,69 +17,78 @@ package li.strolch.model.xml; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import li.strolch.model.Order; import li.strolch.model.Resource; +import li.strolch.model.StrolchRootElement; import li.strolch.model.activity.Activity; /** + * {@link StrolchElementListener} to store the {@link StrolchRootElement} in {@link Map} objects when parsing an object + * model from an external source + * * @author Robert von Burg */ public class SimpleStrolchElementListener implements StrolchElementListener { - private List resources; - private List orders; - private List activities; + private Map resources; + private Map orders; + private Map activities; @Override public void notifyResource(Resource resource) { if (this.resources == null) { - this.resources = new ArrayList<>(); + this.resources = new HashMap<>(); } - this.resources.add(resource); + this.resources.put(resource.getId(), resource); } @Override public void notifyOrder(Order order) { if (this.orders == null) { - this.orders = new ArrayList<>(); + this.orders = new HashMap<>(); } - this.orders.add(order); + this.orders.put(order.getId(), order); } @Override public void notifyActivity(Activity activity) { if (this.activities == null) { - this.activities = new ArrayList<>(); + this.activities = new HashMap<>(); } - this.activities.add(activity); + this.activities.put(activity.getId(), activity); + } + + public Resource getResource(String id) { + return this.resources.get(id); + } + + public Order getOrder(String id) { + return this.orders.get(id); + } + + public Activity getActivity(String id) { + return this.activities.get(id); } - /** - * @return the resources - */ public List getResources() { if (this.resources == null) return Collections.emptyList(); - return this.resources; + return new ArrayList<>(this.resources.values()); } - /** - * @return the orders - */ public List getOrders() { if (this.orders == null) return Collections.emptyList(); - return this.orders; + return new ArrayList<>(this.orders.values()); } - /** - * @return the activities - */ public List getActivities() { if (this.activities == null) return Collections.emptyList(); - return this.activities; + return new ArrayList<>(this.activities.values()); } }