comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java @ 9260:b570b6fcc052

VegetationZone color added and disabled
author gernotbelger
date Tue, 17 Jul 2018 10:59:27 +0200
parents 431f1c269be5
children e511eb935ccd
comparison
equal deleted inserted replaced
9259:66b003701546 9260:b570b6fcc052
9 */ 9 */
10 package org.dive4elements.river.artifacts.uinfo.vegetationzones; 10 package org.dive4elements.river.artifacts.uinfo.vegetationzones;
11 11
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.List; 13 import java.util.List;
14 import java.util.TreeSet;
14 15
15 /** 16 /**
16 * @author Domenico Nardi Tironi 17 * @author Domenico Nardi Tironi
17 * 18 *
18 */ 19 */
19 public class VegetationZone implements Comparable<VegetationZone> { 20 public class VegetationZone implements Comparable<VegetationZone> {
20 21
21 // IMMER ABGLEICHEN MIT VEGETATIONZONE IM CLIENT SuperVegZonesTablePanel.TABLE_CELL_SEPARATOR 22 // IMMER ABGLEICHEN MIT VegetationZone.class Server und Client
23 public static final boolean HAS_COLORS_EDITABLE = false;
24
22 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; 25 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
23 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; 26 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
24 private final String zoneName; 27 private final String zoneName;
25 private final int min_day_overflow; 28 private final int min_day_overflow;
26 private final int max_day_overflow; 29 private final int max_day_overflow;
30 private final String hexColor;
27 31
28 public static List<VegetationZone> parse(final String zonesRaw) { 32 public static List<VegetationZone> parse(final String zonesRaw) {
29 final List<VegetationZone> resultList = new ArrayList<>(); 33 final List<VegetationZone> resultList = new ArrayList<>();
30 34
31 final List<String[]> results = new ArrayList<>(); 35 final List<String[]> results = new ArrayList<>();
38 } 42 }
39 } 43 }
40 } 44 }
41 for (final String[] zone : results) { 45 for (final String[] zone : results) {
42 46
43 final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2])); 47 final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]);
44 resultList.add(helper); 48 resultList.add(helper);
45 } 49 }
46 50
47 return resultList; 51 return resultList;
48 } 52 }
49 53
50 public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow) { 54 public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) {
51 return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow)); // Error-Handling? 55 return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling?
52 } 56 }
53 57
54 private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow) { 58 private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) {
55 this.zoneName = zone; 59 this.zoneName = zone;
56 this.min_day_overflow = min_day_overflow; 60 this.min_day_overflow = min_day_overflow;
57 this.max_day_overflow = max_day_overflow; 61 this.max_day_overflow = max_day_overflow;
62 this.hexColor = hexColor;
58 } 63 }
59 64
60 public int getMax_day_overflow() { 65 public int getMax_day_overflow() {
61 return this.max_day_overflow; 66 return this.max_day_overflow;
62 } 67 }
63 68
64 public String getZoneName() { 69 public String getZoneName() {
70 if (this.zoneName == null || this.zoneName.equals("")) {
71 return "---";
72 }
65 return this.zoneName; 73 return this.zoneName;
74 }
75
76 public String getHexColor() {
77 try {
78 final int test = Integer.decode(this.hexColor);
79 return this.hexColor;
80 }
81 catch (final NumberFormatException e) {
82 return "#ffffff";
83 }
66 } 84 }
67 85
68 public int getMin_day_overflow() { 86 public int getMin_day_overflow() {
69 return this.min_day_overflow; 87 return this.min_day_overflow;
70 } 88 }
71 89
72 public static final List<VegetationZone> getStandardList() { 90 public static final List<VegetationZone> getStandardList() {
73 91
74 final List<VegetationZone> list = new ArrayList<>(); 92 final List<VegetationZone> list = new ArrayList<>();
75 list.add(new VegetationZone("Zonaler Wald", 0, 5)); 93 list.add(new VegetationZone("Zonaler Wald", 0, 5, "#336600"));
76 list.add(new VegetationZone("Hartholzaue, trocken", 5, 40)); 94 list.add(new VegetationZone("Hartholzaue, trocken", 6, 40, "#00cc00"));
77 list.add(new VegetationZone("Hartholzaue, feucht", 40, 80)); 95 list.add(new VegetationZone("Hartholzaue, feucht", 41, 80, "#66ff33"));
78 list.add(new VegetationZone("Silberweidenwald", 80, 140)); 96 list.add(new VegetationZone("Silberweidenwald", 81, 140, "#008080"));
79 list.add(new VegetationZone("Weidengebüsch", 140, 200)); 97 list.add(new VegetationZone("Weidengebüsch", 141, 200, "#33cccc"));
80 list.add(new VegetationZone("Uferröhricht", 200, 260)); 98 list.add(new VegetationZone("Uferröhricht", 201, 260, "#ffa8ff"));
81 list.add(new VegetationZone("Uferpioniere", 260, 320)); 99 list.add(new VegetationZone("Uferpioniere", 261, 320, "#ff0000"));
82 list.add(new VegetationZone("Vegetationslos", 320, 365)); 100 list.add(new VegetationZone("Vegetationslos", 321, 364, "#b2b2b2"));
83 list.add(new VegetationZone("Wasserfläche", 365, 365)); 101 list.add(new VegetationZone("Wasserfläche", 365, 365, "#0066ff"));
84 102
85 return list; 103 return list;
86 } 104 }
87 105
88 public static final String parseListToDataString(final List<VegetationZone> list) { 106 public static final String parseListToDataString(final List<VegetationZone> list) {
93 builder.append(zone.getZoneName()); 111 builder.append(zone.getZoneName());
94 builder.append(TABLE_CELL_SEPARATOR); 112 builder.append(TABLE_CELL_SEPARATOR);
95 builder.append(zone.getMin_day_overflow()); 113 builder.append(zone.getMin_day_overflow());
96 builder.append(TABLE_CELL_SEPARATOR); 114 builder.append(TABLE_CELL_SEPARATOR);
97 builder.append(zone.getMax_day_overflow()); 115 builder.append(zone.getMax_day_overflow());
116 builder.append(TABLE_CELL_SEPARATOR);
117 builder.append(zone.getHexColor());
98 builder.append(TABLE_ROW_SEPARATOR); 118 builder.append(TABLE_ROW_SEPARATOR);
99 } 119 }
100 return builder.toString(); 120 return builder.toString();
101 121
102 } 122 }
103 123
104 @Override 124 @Override
105 public int compareTo(final VegetationZone o) { 125 public int compareTo(final VegetationZone o) {
106 final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); 126 final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow());
107 if (basicCompare == 0) 127 if (basicCompare == 0)
108 return Integer.compare(this.getMax_day_overflow(), o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? 128 return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren?
129
130 if (basicCompare == 0) {
131 return 1; // for treeSet
132 }
133
109 return basicCompare; 134 return basicCompare;
110 } 135 }
111 136
137 public static final boolean zonesAreOverlapping(final List<VegetationZone> list) {
138 for (final VegetationZone zone : list) {
139 for (final VegetationZone zoneOther : list) {
140 if (zone != zoneOther) {
141 final boolean overlaps = zone.overlaps(zoneOther);
142 if (overlaps) {
143 return overlaps; // cancel. only one zone has to overlap
144 }
145 }
146 }
147 }
148
149 return false;
150 }
151
152 public static final boolean hasGaps(final List<VegetationZone> list, final int lower, final int upper) {
153
154 if ((upper - lower) == 0)
155 return true;
156
157 final TreeSet<VegetationZone> treeList = new TreeSet<>();
158 treeList.addAll(list);
159 int lowerCompare = lower;
160 for (final VegetationZone zone : treeList) {
161 if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv
162 return true;
163 }
164 lowerCompare = zone.getUpperFromTo();
165 }
166 if ((lowerCompare) < upper)
167 return true; // am Ende nicht geschlossen
168
169 return false;
170 }
171
172 private boolean overlaps(final VegetationZone otherZone) {
173 final int otherLower = otherZone.getLowerFromTo();
174 final int otherUpper = otherZone.getUpperFromTo();
175
176 final int upper = getUpperFromTo();
177 final int lower = getLowerFromTo();
178 final int otherSchwerpunkt = (otherLower + otherUpper) / 2;
179 if ((otherUpper <= upper && otherUpper >= lower)) {
180 return true;
181 } else if (otherLower >= lower && otherLower <= upper) {
182 return true;
183 } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) {
184 return true;
185 }
186 return false;
187 }
188
189 public Integer getLowerFromTo() {
190 return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-(
191 }
192
193 public Integer getUpperFromTo() {
194 return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-(
195 }
196
112 } 197 }

http://dive4elements.wald.intevation.org