comparison 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
comparison
equal deleted inserted replaced
9623:677ff7ed9a60 9624:02ca823ec9c6
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.client.shared.model;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 /**
16 * @author Domenico Nardi Tironi
17 *
18 */
19 public class InfrastructureServerClientXChange {
20
21 // IMMER ABGLEICHEN MIT InfrastructureServerClientXChange.class IM SERVER
22
23 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
24
25 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
26
27 private final List<Element> m_objects = new ArrayList<Element>();
28
29 public static class Element {
30
31 private final String m_groupId;
32 private final String m_groupLabel;
33 private final String m_typeId;
34 private final String m_typeLabel;
35
36 public Element(final String groupId, final String groupLabel, final String typeId, final String typeLabel) {
37 this.m_groupId = groupId;
38 this.m_groupLabel = groupLabel;
39 this.m_typeId = typeId;
40 this.m_typeLabel = typeLabel;
41 }
42
43 @Override
44 public boolean equals(final Object o) {
45 if (o == this)
46 return true;
47
48 if (!(o instanceof Element))
49 return false;
50
51 final Element compare = (Element) o;
52
53 return this.toKey().equals(compare.toKey());
54 }
55
56 @Override
57 public int hashCode() {
58 return toKey().hashCode();
59 }
60
61 private String toKey() {
62 return "" + this.m_groupId + '#' + this.m_typeId;
63 }
64
65 public String getGroupId() {
66 return this.m_groupId;
67 }
68
69 public String getTypeLabel() {
70 return this.m_typeLabel;
71 }
72
73 public Object getTypeId() {
74 return this.m_typeId;
75 }
76
77 public Object getGroupLabel() {
78 return this.m_groupLabel;
79 }
80 }
81
82 public void parseAndAdd(final String raw) {
83 this.m_objects.addAll(parse(raw));
84 }
85
86 public static List<Element> parse(final String raw) {
87 final List<Element> objects = new ArrayList<Element>();
88 if (raw.contains(TABLE_ROW_SEPARATOR)) {
89 final String[] rows = raw.split(TABLE_ROW_SEPARATOR);
90 for (final String row : rows) {
91 if (row.contains(TABLE_CELL_SEPARATOR)) {
92 final String[] result = row.split(TABLE_CELL_SEPARATOR);
93 objects.add(new Element(result[0], result[1], result[2], result[3]));
94 }
95 }
96 }
97 return objects;
98 }
99
100 public boolean containsObject(final Element infrastr) {
101 return this.m_objects.contains(infrastr);
102 }
103
104 public InfrastructureServerClientXChange() {
105 }
106
107 public final String parseListToDataString() {
108
109 // java.util.Collections.sort(list);
110 final StringBuilder builder = new StringBuilder();
111 for (final Element object : this.m_objects) {
112 builder.append(object.getGroupId());
113 builder.append(TABLE_CELL_SEPARATOR);
114 builder.append(object.getGroupLabel());
115 builder.append(TABLE_CELL_SEPARATOR);
116 builder.append(object.getTypeId());
117 builder.append(TABLE_CELL_SEPARATOR);
118 builder.append(object.getTypeLabel());
119 builder.append(TABLE_ROW_SEPARATOR);
120 }
121 return builder.toString();
122
123 }
124
125 public void addObject(final Element infrastr) {
126 this.m_objects.add(infrastr);
127 }
128
129 public void removeObject(final Element infrastr) {
130 this.m_objects.remove(infrastr);
131 }
132
133 public List<Element> getItems() {
134 return this.m_objects; // doof, dass es jetzt doch öffentlich ist :-(
135 }
136
137 }

http://dive4elements.wald.intevation.org