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