comparison artifacts/src/main/java/org/dive4elements/river/artifacts/common/EpochYearAccessHelper.java @ 9155:9b4f5e61c02e

Changed to list of DateRange, added methods in DateRange to support year ranges
author mschaefer
date Tue, 19 Jun 2018 14:15:32 +0200
parents 611a523fc42f
children 2f5052835b76
comparison
equal deleted inserted replaced
9154:cd24db77f044 9155:9b4f5e61c02e
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.common; 10 package org.dive4elements.river.artifacts.common;
11 11
12 import java.util.ArrayList;
13 import java.util.List;
14
12 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
13 import org.dive4elements.artifacts.Artifact; 16 import org.dive4elements.artifacts.Artifact;
14 import org.dive4elements.river.artifacts.D4EArtifact; 17 import org.dive4elements.river.artifacts.D4EArtifact;
15 import org.dive4elements.river.artifacts.access.Access; 18 import org.dive4elements.river.artifacts.access.Access;
19 import org.dive4elements.river.artifacts.model.DateRange;
20 import org.dive4elements.river.backend.utils.DateUtil;
16 21
17 import gnu.trove.TIntArrayList; 22 import gnu.trove.TIntArrayList;
18 23
19 /** 24 /**
20 * @author Domenico Nardi Tironi 25 * @author Domenico Nardi Tironi
66 return years; 71 return years;
67 } 72 }
68 return null; 73 return null;
69 } 74 }
70 75
71 public int[][] getEpochs(final String epochSelectedValue, final String epochKey) { 76 public List<DateRange> getEpochs(final String epochSelectedValue, final String epochKey) {
72 int epochs[][] = null; 77 final List<DateRange> epochs = new ArrayList<>();
73 // if (epochs != null) { 78 // if (epochs != null) {
74 // return epochs; 79 // return epochs;
75 // } 80 // }
76 81
77 if (!getYearEpoch().equals(epochSelectedValue)) { 82 if (!getYearEpoch().equals(epochSelectedValue)) {
78 return null; 83 return null;
79 } 84 }
80 85
81 final String data = getString(epochKey); 86 final String data = getString(epochKey);
82
83 if (data == null) { 87 if (data == null) {
84 log.warn("No 'epochs' parameter specified!"); 88 log.warn("No 'epochs' parameter specified!");
85 return null; 89 return null;
86 } 90 }
87 91
88 final String[] parts = data.split(";"); 92 for (final String part : data.split(";")) {
89 93 final String[] values = part.split(",");
90 epochs = new int[parts.length][];
91
92 for (int i = 0; i < parts.length; i++) {
93 final String[] values = parts[i].split(",");
94 final TIntArrayList ints = new TIntArrayList();
95 try { 94 try {
96 ints.add(Integer.parseInt(values[0])); 95 epochs.add(new DateRange(DateUtil.getStartDateFromYear(Integer.parseInt(values[0])), DateUtil.getEndDateFromYear(Integer.parseInt(values[1]))));
97 ints.add(Integer.parseInt(values[1]));
98 epochs[i] = ints.toNativeArray();
99 } 96 }
100 catch (final NumberFormatException nfe) { 97 catch (final NumberFormatException nfe) {
101 log.warn("Cannot parse int from string: '" + values + "'"); 98 log.warn("Cannot parse int from string: '" + values + "'");
102 } 99 }
103 } 100 }

http://dive4elements.wald.intevation.org