comparison artifacts/src/main/java/org/dive4elements/river/artifacts/access/SedimentLoadAccess.java @ 8051:9dce39cffab3

Sediment load access: Cache values.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 11:05:34 +0200
parents b60485a58d73
children 306a16d3ac2e
comparison
equal deleted inserted replaced
8050:9e79e384aa8b 8051:9dce39cffab3
21 private static final Logger logger = Logger.getLogger(SedimentLoadAccess.class); 21 private static final Logger logger = Logger.getLogger(SedimentLoadAccess.class);
22 22
23 private String time; 23 private String time;
24 private String unit; 24 private String unit;
25 25
26 private int [][] epochs;
27
28 private int [] period;
29
26 public SedimentLoadAccess(D4EArtifact artifact) { 30 public SedimentLoadAccess(D4EArtifact artifact) {
27 super(artifact); 31 super(artifact);
28 } 32 }
29 33
30 public Double getLowerKM() { 34 public Double getLowerKM() {
44 return time; 48 return time;
45 } 49 }
46 50
47 /** [startyear, endyear] if its about years. */ 51 /** [startyear, endyear] if its about years. */
48 public int[] getPeriod() { 52 public int[] getPeriod() {
53 if (period != null) {
54 return period;
55 }
49 if (getYearEpoch().equals("year") ) { 56 if (getYearEpoch().equals("year") ) {
50 Integer start = getInteger("start"); 57 Integer start = getInteger("start");
51 Integer end = getInteger("end"); 58 Integer end = getInteger("end");
52 if (start == null || end == null) { 59 if (start == null || end == null) {
53 logger.warn("No 'start' or 'end' parameter specified!"); 60 logger.warn("No 'start' or 'end' parameter specified!");
54 return null; 61 return null;
55 } 62 }
56 63
57 return new int[]{start.intValue(), end.intValue()}; 64 period = new int[]{start.intValue(), end.intValue()};
58 } 65 }
59 return null; 66 return null;
60 } 67 }
61 68
62 public int[][] getEpochs() { 69 public int[][] getEpochs() {
70
71 if (epochs != null) {
72 return epochs;
73 }
74
63 if (!getYearEpoch().equals("epoch") && 75 if (!getYearEpoch().equals("epoch") &&
64 !getYearEpoch().equals("off_epoch")) { 76 !getYearEpoch().equals("off_epoch")) {
65 return null; 77 return null;
66 } 78 }
67 79
72 return null; 84 return null;
73 } 85 }
74 86
75 String[] parts = data.split(";"); 87 String[] parts = data.split(";");
76 88
77 int[][] list = new int[parts.length][]; 89 epochs = new int[parts.length][];
78 90
79 for (int i = 0; i < parts.length; i++) { 91 for (int i = 0; i < parts.length; i++) {
80 String[] values = parts[i].split(","); 92 String[] values = parts[i].split(",");
81 TIntArrayList ints = new TIntArrayList(); 93 TIntArrayList ints = new TIntArrayList();
82 try { 94 try {
83 ints.add(Integer.parseInt(values[0])); 95 ints.add(Integer.parseInt(values[0]));
84 ints.add(Integer.parseInt(values[1])); 96 ints.add(Integer.parseInt(values[1]));
85 list[i] = ints.toNativeArray(); 97 epochs[i] = ints.toNativeArray();
86 } 98 }
87 catch (NumberFormatException nfe) { 99 catch (NumberFormatException nfe) {
88 logger.warn("Cannot parse int from string: '" + values + "'"); 100 logger.warn("Cannot parse int from string: '" + values + "'");
89 } 101 }
90 } 102 }
91 return list; 103 return epochs;
92 } 104 }
93 105
94 /** Returns the selected unit (t/a or m3/a). */ 106 /** Returns the selected unit (t/a or m3/a). */
95 public String getUnit () { 107 public String getUnit () {
96 if (unit == null) { 108 if (unit == null) {

http://dive4elements.wald.intevation.org