[Dive4elements-commits] [PATCH] Add sorting for discharge value

Wald Commits scm-commit at wald.intevation.org
Tue Jun 4 16:45:28 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1370357123 -7200
# Node ID 7573683925a371b422ddbf9ccf48a24de7275b35
# Parent  58e78e6662fa6cce151ba453ba0450084ef96680
Add sorting for discharge value

diff -r 58e78e6662fa -r 7573683925a3 artifacts/src/main/java/org/dive4elements/river/artifacts/states/DischargeState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/DischargeState.java	Tue Jun 04 16:07:33 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/DischargeState.java	Tue Jun 04 16:45:23 2013 +0200
@@ -9,6 +9,8 @@
 package org.dive4elements.river.artifacts.states;
 
 import java.util.List;
+import java.util.Collections;
+import java.util.Comparator;
 
 import org.apache.log4j.Logger;
 
@@ -68,9 +70,15 @@
 
         KVP[] kvp = new KVP[zones.size()];
 
-        for (int i = 0, Z = zones.size(); i < Z; i++) {
-            DischargeZone zone = zones.get(i);
+        Collections.sort(zones, new Comparator<DischargeZone>() {
+            public int compare(DischargeZone a, DischargeZone b) {
+                return a.getValue().compareTo(b.getValue());
+            }
+        });
 
+        int i = 0;
+
+        for (DischargeZone zone: zones) {
             String lower = zone.getLowerDischarge();
             String upper = zone.getUpperDischarge();
 
@@ -80,6 +88,7 @@
             else {
                 kvp[i] = new KVP(zone.getId(), lower + " - " + upper);
             }
+            i++;
         }
 
         return kvp;


More information about the Dive4elements-commits mailing list