changeset 8051:9dce39cffab3

Sediment load access: Cache values.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 11:05:34 +0200
parents 9e79e384aa8b
children 1dae69eff79d
files artifacts/src/main/java/org/dive4elements/river/artifacts/access/SedimentLoadAccess.java
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SedimentLoadAccess.java	Thu Jul 17 18:22:16 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/SedimentLoadAccess.java	Fri Jul 18 11:05:34 2014 +0200
@@ -23,6 +23,10 @@
     private String time;
     private String unit;
 
+    private int [][] epochs;
+
+    private int [] period;
+
     public SedimentLoadAccess(D4EArtifact artifact) {
         super(artifact);
     }
@@ -46,6 +50,9 @@
 
     /** [startyear, endyear] if its about years. */
     public int[] getPeriod() {
+        if (period != null) {
+            return period;
+        }
         if (getYearEpoch().equals("year") ) {
             Integer start = getInteger("start");
             Integer end = getInteger("end");
@@ -54,12 +61,17 @@
                 return null;
             }
 
-            return new int[]{start.intValue(), end.intValue()};
+            period = new int[]{start.intValue(), end.intValue()};
         }
         return null;
     }
 
     public int[][] getEpochs() {
+
+        if (epochs != null) {
+            return epochs;
+        }
+
         if (!getYearEpoch().equals("epoch") &&
             !getYearEpoch().equals("off_epoch")) {
             return null;
@@ -74,7 +86,7 @@
 
         String[] parts = data.split(";");
 
-        int[][] list = new int[parts.length][];
+        epochs = new int[parts.length][];
 
         for (int i = 0; i < parts.length; i++) {
             String[] values = parts[i].split(",");
@@ -82,13 +94,13 @@
             try {
                 ints.add(Integer.parseInt(values[0]));
                 ints.add(Integer.parseInt(values[1]));
-                list[i] = ints.toNativeArray();
+                epochs[i] = ints.toNativeArray();
             }
             catch (NumberFormatException nfe) {
                 logger.warn("Cannot parse int from string: '" + values + "'");
             }
         }
-        return list;
+        return epochs;
     }
 
     /** Returns the selected unit (t/a or m3/a). */

http://dive4elements.wald.intevation.org