d@9624: /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde d@9624: * Software engineering by d@9624: * Björnsen Beratende Ingenieure GmbH d@9624: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt d@9624: * d@9624: * This file is Free Software under the GNU AGPL (>=v3) d@9624: * and comes with ABSOLUTELY NO WARRANTY! Check out the d@9624: * documentation coming with Dive4Elements River for details. d@9624: */ d@9624: package org.dive4elements.river.client.shared.model; d@9624: d@9624: import java.util.ArrayList; d@9624: import java.util.List; d@9624: d@9624: /** d@9624: * @author Domenico Nardi Tironi d@9624: * d@9624: */ d@9624: public class InfrastructureServerClientXChange { d@9624: d@9624: // IMMER ABGLEICHEN MIT InfrastructureServerClientXChange.class IM SERVER d@9624: d@9624: private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; d@9624: d@9624: private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; d@9624: d@9624: private final List m_objects = new ArrayList(); d@9624: d@9624: public static class Element { d@9624: d@9624: private final String m_groupId; d@9624: private final String m_groupLabel; d@9624: private final String m_typeId; d@9624: private final String m_typeLabel; d@9624: d@9624: public Element(final String groupId, final String groupLabel, final String typeId, final String typeLabel) { d@9624: this.m_groupId = groupId; d@9624: this.m_groupLabel = groupLabel; d@9624: this.m_typeId = typeId; d@9624: this.m_typeLabel = typeLabel; d@9624: } d@9624: d@9624: @Override d@9624: public boolean equals(final Object o) { d@9624: if (o == this) d@9624: return true; d@9624: d@9624: if (!(o instanceof Element)) d@9624: return false; d@9624: d@9624: final Element compare = (Element) o; d@9624: d@9624: return this.toKey().equals(compare.toKey()); d@9624: } d@9624: d@9624: @Override d@9624: public int hashCode() { d@9624: return toKey().hashCode(); d@9624: } d@9624: d@9624: private String toKey() { d@9624: return "" + this.m_groupId + '#' + this.m_typeId; d@9624: } d@9624: d@9624: public String getGroupId() { d@9624: return this.m_groupId; d@9624: } d@9624: d@9624: public String getTypeLabel() { d@9624: return this.m_typeLabel; d@9624: } d@9624: d@9624: public Object getTypeId() { d@9624: return this.m_typeId; d@9624: } d@9624: d@9624: public Object getGroupLabel() { d@9624: return this.m_groupLabel; d@9624: } d@9624: } d@9624: d@9624: public void parseAndAdd(final String raw) { d@9624: this.m_objects.addAll(parse(raw)); d@9624: } d@9624: d@9624: public static List parse(final String raw) { d@9624: final List objects = new ArrayList(); d@9624: if (raw.contains(TABLE_ROW_SEPARATOR)) { d@9624: final String[] rows = raw.split(TABLE_ROW_SEPARATOR); d@9624: for (final String row : rows) { d@9624: if (row.contains(TABLE_CELL_SEPARATOR)) { d@9624: final String[] result = row.split(TABLE_CELL_SEPARATOR); d@9624: objects.add(new Element(result[0], result[1], result[2], result[3])); d@9624: } d@9624: } d@9624: } d@9624: return objects; d@9624: } d@9624: d@9624: public boolean containsObject(final Element infrastr) { d@9624: return this.m_objects.contains(infrastr); d@9624: } d@9624: d@9624: public InfrastructureServerClientXChange() { d@9624: } d@9624: d@9624: public final String parseListToDataString() { d@9624: d@9624: // java.util.Collections.sort(list); d@9624: final StringBuilder builder = new StringBuilder(); d@9624: for (final Element object : this.m_objects) { d@9624: builder.append(object.getGroupId()); d@9624: builder.append(TABLE_CELL_SEPARATOR); d@9624: builder.append(object.getGroupLabel()); d@9624: builder.append(TABLE_CELL_SEPARATOR); d@9624: builder.append(object.getTypeId()); d@9624: builder.append(TABLE_CELL_SEPARATOR); d@9624: builder.append(object.getTypeLabel()); d@9624: builder.append(TABLE_ROW_SEPARATOR); d@9624: } d@9624: return builder.toString(); d@9624: d@9624: } d@9624: d@9624: public void addObject(final Element infrastr) { d@9624: this.m_objects.add(infrastr); d@9624: } d@9624: d@9624: public void removeObject(final Element infrastr) { d@9624: this.m_objects.remove(infrastr); d@9624: } d@9624: d@9624: public List getItems() { d@9624: return this.m_objects; // doof, dass es jetzt doch öffentlich ist :-( d@9624: } d@9624: d@9624: }