diff gwt-client/src/main/java/org/dive4elements/river/client/shared/model/InfrastructureServerClientXChange.java @ 9624:02ca823ec9c6

zu Pos 20 Nachtrag; infrastructureChoice
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Fri, 11 Oct 2019 18:30:36 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/InfrastructureServerClientXChange.java	Fri Oct 11 18:30:36 2019 +0200
@@ -0,0 +1,137 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.client.shared.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+public class InfrastructureServerClientXChange {
+
+    // IMMER ABGLEICHEN MIT InfrastructureServerClientXChange.class IM SERVER
+
+    private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
+
+    private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
+
+    private final List<Element> m_objects = new ArrayList<Element>();
+
+    public static class Element {
+
+        private final String m_groupId;
+        private final String m_groupLabel;
+        private final String m_typeId;
+        private final String m_typeLabel;
+
+        public Element(final String groupId, final String groupLabel, final String typeId, final String typeLabel) {
+            this.m_groupId = groupId;
+            this.m_groupLabel = groupLabel;
+            this.m_typeId = typeId;
+            this.m_typeLabel = typeLabel;
+        }
+
+        @Override
+        public boolean equals(final Object o) {
+            if (o == this)
+                return true;
+
+            if (!(o instanceof Element))
+                return false;
+
+            final Element compare = (Element) o;
+
+            return this.toKey().equals(compare.toKey());
+        }
+
+        @Override
+        public int hashCode() {
+            return toKey().hashCode();
+        }
+
+        private String toKey() {
+            return "" + this.m_groupId + '#' + this.m_typeId;
+        }
+
+        public String getGroupId() {
+            return this.m_groupId;
+        }
+
+        public String getTypeLabel() {
+            return this.m_typeLabel;
+        }
+
+        public Object getTypeId() {
+            return this.m_typeId;
+        }
+
+        public Object getGroupLabel() {
+            return this.m_groupLabel;
+        }
+    }
+
+    public void parseAndAdd(final String raw) {
+        this.m_objects.addAll(parse(raw));
+    }
+
+    public static List<Element> parse(final String raw) {
+        final List<Element> objects = new ArrayList<Element>();
+        if (raw.contains(TABLE_ROW_SEPARATOR)) {
+            final String[] rows = raw.split(TABLE_ROW_SEPARATOR);
+            for (final String row : rows) {
+                if (row.contains(TABLE_CELL_SEPARATOR)) {
+                    final String[] result = row.split(TABLE_CELL_SEPARATOR);
+                    objects.add(new Element(result[0], result[1], result[2], result[3]));
+                }
+            }
+        }
+        return objects;
+    }
+
+    public boolean containsObject(final Element infrastr) {
+        return this.m_objects.contains(infrastr);
+    }
+
+    public InfrastructureServerClientXChange() {
+    }
+
+    public final String parseListToDataString() {
+
+        // java.util.Collections.sort(list);
+        final StringBuilder builder = new StringBuilder();
+        for (final Element object : this.m_objects) {
+            builder.append(object.getGroupId());
+            builder.append(TABLE_CELL_SEPARATOR);
+            builder.append(object.getGroupLabel());
+            builder.append(TABLE_CELL_SEPARATOR);
+            builder.append(object.getTypeId());
+            builder.append(TABLE_CELL_SEPARATOR);
+            builder.append(object.getTypeLabel());
+            builder.append(TABLE_ROW_SEPARATOR);
+        }
+        return builder.toString();
+
+    }
+
+    public void addObject(final Element infrastr) {
+        this.m_objects.add(infrastr);
+    }
+
+    public void removeObject(final Element infrastr) {
+        this.m_objects.remove(infrastr);
+    }
+
+    public List<Element> getItems() {
+        return this.m_objects; // doof, dass es jetzt doch öffentlich ist :-(
+    }
+
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org