Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/sinfo/WaterlevelSoundingYearFilter.java @ 9227:84397da33d17
Allow to control specific behaviour in TwinDatacagePanel
Implemented client logic of 'intelligent datacage filtering' for SINFO
author | gernotbelger |
---|---|
date | Wed, 04 Jul 2018 18:28:08 +0200 |
parents | |
children | 082e8e808902 |
comparison
equal
deleted
inserted
replaced
9226:83aee0942eae | 9227:84397da33d17 |
---|---|
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.client.ui.sinfo; | |
11 | |
12 import org.dive4elements.river.client.client.ui.DatacageWidget.DatacageFilter; | |
13 import org.dive4elements.river.client.shared.model.AttrList; | |
14 import org.dive4elements.river.client.shared.model.DataCageNode; | |
15 | |
16 /** | |
17 * @author Gernot Belger | |
18 */ | |
19 final class WaterlevelSoundingYearFilter implements DatacageFilter { | |
20 | |
21 private final int soundingYear; | |
22 | |
23 public WaterlevelSoundingYearFilter(final int soundingYear) { | |
24 this.soundingYear = soundingYear; | |
25 } | |
26 | |
27 @Override | |
28 public boolean accept(final DataCageNode node) { | |
29 | |
30 final AttrList attributes = node.getAttributes(); | |
31 if (attributes == null) | |
32 return true; | |
33 | |
34 if (!attributes.hasAttribute("factory")) | |
35 return true; | |
36 | |
37 final Integer waterlevelYear = getYear(attributes); | |
38 if (waterlevelYear == null) { | |
39 // should never happen, we should only show waterlevels that have a year | |
40 return false; | |
41 } | |
42 | |
43 final int diff = Math.abs(this.soundingYear - waterlevelYear); | |
44 | |
45 return diff <= getMaxYearDifference(); | |
46 } | |
47 | |
48 private int getMaxYearDifference() { | |
49 | |
50 if (this.soundingYear < 1918) | |
51 return 25; | |
52 | |
53 if (1918 <= this.soundingYear && this.soundingYear < 1958) | |
54 return 12; | |
55 | |
56 if (1958 <= this.soundingYear && this.soundingYear < 1998) | |
57 return 6; | |
58 | |
59 // > 1998 | |
60 return 3; | |
61 } | |
62 | |
63 private static Integer getYear(final AttrList attributes) { | |
64 | |
65 final String year = attributes.getValue(WaterlevelSoundingSelectionController.ATTRIBUTE_YEAR); | |
66 if (year == null || year.trim().isEmpty()) | |
67 return null; | |
68 | |
69 try { | |
70 return Integer.valueOf(year); | |
71 } | |
72 catch (final NumberFormatException e) { | |
73 e.printStackTrace(); | |
74 return null; | |
75 } | |
76 } | |
77 } |