diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java @ 8239:b207eeb66edd

(issue1448) Objectify sq_time_interval id.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 08 Sep 2014 19:47:01 +0200
parents 25c3a62863d2
children 61fd22f65bd4
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Mon Sep 08 19:01:26 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Mon Sep 08 19:47:01 2014 +0200
@@ -123,7 +123,7 @@
 
         private int id;
         private int kind;
-        private int sqTiId;
+        private Integer sqTiId;
 
         private String description;
 
@@ -152,14 +152,14 @@
             this.stopTime    = stopTime;
             this.sqStartTime = sqStartTime;
             this.sqStopTime  = sqStopTime;
-            this.sqTiId      = sqTiId == null ? 0 : sqTiId;
+            this.sqTiId      = sqTiId;
         }
 
         public int getId() {
             return id;
         }
 
-        public int getSQRelationTimeIntervalId() {
+        public Integer getSQRelationTimeIntervalId() {
             return sqTiId;
         }
 
@@ -437,20 +437,24 @@
     public static final Comparator<Load> LOAD_SQ_TI_CMP = new Comparator<Load>() {
         @Override
         public int compare(Load a, Load b) {
-            return a.getSQRelationTimeIntervalId() - b.getSQRelationTimeIntervalId();
-        }
-    };
-
-    public static final Comparator<Load> LOAD_ID_SQ_TI_CMP = new Comparator<Load>() {
-        @Override
-        public int compare(Load a, Load b) {
-            return LOAD_ID_CMP.compare(a, b) + LOAD_SQ_TI_CMP.compare(a,b);
+            Integer a_id = a.getSQRelationTimeIntervalId();
+            Integer b_id = b.getSQRelationTimeIntervalId();
+            if (a_id == null && b_id == null) {
+                return 0;
+            }
+            if (a_id == null) {
+                return -1;
+            }
+            if (b_id == null) {
+                return 1;
+            }
+            return a_id - b_id;
         }
     };
 
     /** Find all loads in the range a/b with the according sq_time_interval */
-    public Collection<Load> findLoads(double a, double b, int sqRelationTimeInterval) {
-        final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_SQ_TI_CMP);
+    public Collection<Load> findLoads(double a, double b, Integer sqRelationTimeInterval) {
+        final TreeSet<Load> loads = new TreeSet<Load>(LOAD_ID_CMP);
 
         findStations(a, b, new Visitor() {
             @Override

http://dive4elements.wald.intevation.org