9119
|
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 |
|
11 package org.dive4elements.river.client.shared.model; |
|
12 |
|
13 import java.util.ArrayList; |
|
14 import java.util.List; |
|
15 |
|
16 /** |
|
17 * @author Domenico Nardi Tironi |
|
18 * |
|
19 */ |
|
20 public class VegetationZone implements Comparable<VegetationZone> { |
|
21 |
|
22 // IMMER ABGLEICHEN MIT VegetationZone.class IM SERVER |
|
23 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; |
|
24 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; |
|
25 private final String zoneName; |
|
26 private final int min_day_overflow; |
|
27 private final int max_day_overflow; |
|
28 |
|
29 public static List<VegetationZone> parse(final String zonesRaw) { |
|
30 final List<VegetationZone> resultList = new ArrayList<VegetationZone>(); |
|
31 |
|
32 final List<String[]> results = new ArrayList<String[]>(); |
|
33 if (zonesRaw.contains(TABLE_ROW_SEPARATOR)) { |
|
34 final String[] rows = zonesRaw.split(TABLE_ROW_SEPARATOR); |
|
35 for (final String row : rows) { |
|
36 if (row.contains(TABLE_CELL_SEPARATOR)) { |
|
37 final String[] result = row.split(TABLE_CELL_SEPARATOR); |
|
38 results.add(result); |
|
39 } |
|
40 } |
|
41 } |
|
42 for (final String[] zone : results) { |
|
43 |
|
44 final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2])); |
|
45 resultList.add(helper); |
|
46 } |
|
47 |
|
48 return resultList; |
|
49 } |
|
50 |
|
51 public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow) { |
|
52 return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow)); // Error-Handling? |
|
53 } |
|
54 |
|
55 private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow) { |
|
56 this.zoneName = zone; |
|
57 this.min_day_overflow = min_day_overflow; |
|
58 this.max_day_overflow = max_day_overflow; |
|
59 } |
|
60 |
|
61 public int getMax_day_overflow() { |
|
62 return this.max_day_overflow; |
|
63 } |
|
64 |
|
65 public String getZoneName() { |
|
66 return this.zoneName; |
|
67 } |
|
68 |
|
69 public int getMin_day_overflow() { |
|
70 return this.min_day_overflow; |
|
71 } |
|
72 |
|
73 public static final List<VegetationZone> getStandardList() { |
|
74 |
|
75 final List<VegetationZone> list = new ArrayList<VegetationZone>(); |
|
76 list.add(new VegetationZone("Zonaler Wald", 0, 5)); |
|
77 list.add(new VegetationZone("Hartholzaue, trocken", 5, 40)); |
|
78 list.add(new VegetationZone("Hartholzaue, feucht", 40, 80)); |
|
79 list.add(new VegetationZone("Silberweidenwald", 80, 140)); |
|
80 list.add(new VegetationZone("Weidengebüsch", 140, 200)); |
|
81 list.add(new VegetationZone("Uferröhricht", 200, 260)); |
|
82 list.add(new VegetationZone("Uferpioniere", 260, 320)); |
|
83 list.add(new VegetationZone("Vegetationslos", 320, 365)); |
|
84 list.add(new VegetationZone("Wasserfläche", 365, 365)); |
|
85 |
|
86 return list; |
|
87 } |
|
88 |
|
89 public static final String parseListToDataString(final List<VegetationZone> list) { |
|
90 |
|
91 java.util.Collections.sort(list); |
|
92 final StringBuilder builder = new StringBuilder(); |
|
93 for (final VegetationZone zone : list) { |
|
94 builder.append(zone.getZoneName()); |
|
95 builder.append(TABLE_CELL_SEPARATOR); |
|
96 builder.append(zone.getMin_day_overflow()); |
|
97 builder.append(TABLE_CELL_SEPARATOR); |
|
98 builder.append(zone.getMax_day_overflow()); |
|
99 builder.append(TABLE_ROW_SEPARATOR); |
|
100 } |
|
101 return builder.toString(); |
|
102 |
|
103 } |
|
104 |
|
105 @Override |
|
106 public int compareTo(final VegetationZone o) { |
|
107 final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); |
|
108 if (basicCompare == 0) |
|
109 return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? |
|
110 return basicCompare; |
|
111 } |
|
112 |
|
113 } |