changeset 3281:3c61d9e64ca0

SQ: Added sieve flys-artifacts/trunk@4941 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 11 Jul 2012 15:13:01 +0000
parents 4a70525c5b0d
children 424a14255303
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java
diffstat 2 files changed, 57 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jul 11 11:25:42 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jul 11 15:13:01 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-10	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java:
+	  Simulates a sieve to separate the differen fractions from each other.
+
 2012-07-10	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DateRange.java,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/Sieve.java	Wed Jul 11 15:13:01 2012 +0000
@@ -0,0 +1,52 @@
+package de.intevation.flys.artifacts.model.sq;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class Sieve
+{
+    public double [] fractionSizes;
+
+    protected List<List<SQ>> fractions;
+
+    public Sieve() {
+    }
+
+    public Sieve(double [] fractionSizes) {
+        this.fractionSizes = fractionSizes;
+        fractions = new ArrayList<List<SQ>>(fractionSizes.length+1);
+        for (int i = fractionSizes.length; i >= 0; --i) {
+            fractions.add(new ArrayList<SQ>());
+        }
+    }
+
+    public void sieve(Iterator<SQ> sqs) {
+        OUTER: while (sqs.hasNext()) {
+            SQ sq = sqs.next();
+            double q = sq.getQ();
+            for (int i = 0; i < fractionSizes.length; ++i) {
+                if (q < fractionSizes[i]) {
+                    fractions.get(i).add(sq);
+                    continue OUTER;
+                }
+            }
+            fractions.get(fractions.size()-1).add(sq);
+        }
+    }
+
+    public int numFractions() {
+        return fractions.size();
+    }
+
+    public List<SQ> getFraction(int idx) {
+        return fractions.get(idx);
+    }
+
+    public void reset() {
+        for (List<SQ> fraction: fractions) {
+            fraction.clear();
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org