Mercurial > dive4elements > river
changeset 2563:59c920e73d8a
FixingsOverview: Added a filter mechanism for generating output.
flys-artifacts/trunk@4089 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 20 Feb 2012 16:41:45 +0000 |
parents | ba35dfb7c09a |
children | 3f038d54bc87 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java |
diffstat | 2 files changed, 207 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Feb 20 14:36:28 2012 +0000 +++ b/flys-artifacts/ChangeLog Mon Feb 20 16:41:45 2012 +0000 @@ -1,3 +1,25 @@ +2012-02-20 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java: + Added a filter mechanism for generating output. + + There are two kinds of filters: + + 1 - A range. Defaults to [-Double.MAX_VALUE, Double.MAX_VALUE] + The resulting sectors are cut to this range. Sectors outside + this range are omitted. + + 2 - column filters: Given a fixing column they can decide to keep + or not to keep it. Following filters exist: + + - IdFilter: Keep column if column id matches. + - DateFilter: Keep column if column date matches. + - DateRangeFilter: Keep column if column date is in range. + - SectorRangeFilter: Keep colum if one of its q sectors is in given range. + - NotFilter: Negates another nested filter. + - AndFilter: Keep column if all nested filters accept column. + - OrFilter: Keep column if at least one of the nested filters accepts it. + 2012-02-20 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java Mon Feb 20 14:36:28 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java Mon Feb 20 16:41:45 2012 +0000 @@ -381,6 +381,12 @@ } }; + public interface Filter { + + boolean accept(Column column); + + } // interface Filter + public class Column extends Range { protected int columnId; @@ -400,14 +406,41 @@ sectors = new ArrayList<SectorRange>(); } + public int getId() { + return columnId; + } + public Fixing getFixing() { return Fixing.this; } + public Date getStartTime() { + return startTime; + } + + public String getName() { + return name; + } + public List<SectorRange> getSectors() { return sectors; } + public List<SectorRange> getSectors(Range range) { + + List<SectorRange> result = + new ArrayList<SectorRange>(sectors.size()); + + for (SectorRange src: sectors) { + SectorRange dst = new SectorRange(src); + if (dst.clip(range)) { + result.add(dst); + } + } + + return result; + } + public void buildSectors(GaugeRange gauge, List<QRange> qRanges) { for (QRange qRange: qRanges) { @@ -473,6 +506,14 @@ public Fixing() { } + public int getId() { + return wstId; + } + + public String getDescription() { + return description; + } + public Fixing(int wstId, String description) { this.wstId = wstId; this.description = description; @@ -505,9 +546,13 @@ } } - public void addAllColumns(List<Column> allColumns, Range range) { + public void addAllColumns( + List<Column> allColumns, + Range range, + Filter filter + ) { for (Column column: columns) { - if (column.intersects(range)) { + if (column.intersects(range) && filter.accept(column)) { allColumns.add(column); } } @@ -680,19 +725,151 @@ return true; } - private static final Range FULL_EXTENT = + public static final Range FULL_EXTENT = new Range(-Double.MAX_VALUE, Double.MAX_VALUE); + public static final Fixing.Filter ACCEPT = new Fixing.Filter() { + @Override + public boolean accept(Fixing.Column column) { + return true; + } + }; + + public static class NotFilter implements Fixing.Filter { + protected Fixing.Filter child; + + public NotFilter(Fixing.Filter child) { + this.child = child; + } + + @Override + public boolean accept(Fixing.Column column) { + return !child.accept(column); + } + } // class NotFilter + + public static abstract class ComponentFilter implements Fixing.Filter { + protected List<Fixing.Filter> children; + + public ComponentFilter(List<Fixing.Filter> children) { + this.children = children; + } + } // class ComponentFilter + + public static class OrFilter extends ComponentFilter { + + public OrFilter(List<Fixing.Filter> children) { + super(children); + } + + @Override + public boolean accept(Fixing.Column column) { + for (Fixing.Filter child: children) { + if (child.accept(column)) { + return true; + } + } + return false; + } + } // class OrFilter + + public static class AndFilter extends ComponentFilter { + + public AndFilter(List<Fixing.Filter> children) { + super(children); + } + + @Override + public boolean accept(Fixing.Column column) { + for (Fixing.Filter child: children) { + if (!child.accept(column)) { + return false; + } + } + return true; + } + } // class AndFilter + + public static class IdFilter implements Fixing.Filter { + + protected int columnId; + + public IdFilter(int columnId) { + this.columnId = columnId; + } + + @Override + public boolean accept(Fixing.Column column) { + return column.getId() == columnId; + } + } // class IdFilter + + public static class DateFilter implements Fixing.Filter { + + protected Date date; + + public DateFilter(Date date) { + this.date = date; + } + + @Override + public boolean accept(Fixing.Column column) { + return date.equals(column.getStartTime()); + } + } // class DateFilter + + public static class DateRangeFilter implements Fixing.Filter { + + protected Date start; + protected Date end; + + public DateRangeFilter(Date start, Date end) { + this.start = start; + this.end = end; + } + + @Override + public boolean accept(Fixing.Column column) { + Date date = column.getStartTime(); + return start.compareTo(date) <= 0 && end.compareTo(date) >= 0; + } + } // class DateRangeFilter + + public static class SectorRangeFilter implements Fixing.Filter { + + protected int min; + protected int max; + + public SectorRangeFilter(int min, int max) { + this.min = Math.min(min, max); + this.max = Math.max(min, max); + } + + @Override + public boolean accept(Fixing.Column column) { + for (SectorRange s: column.getSectors()) { + int v = s.getSector(); + if (v >= min && v <= max) { + return true; + } + } + return false; + } + } // class SectorRangeFilter + public void generateOverview(Document document) { - generateOverview(document, FULL_EXTENT); + generateOverview(document, FULL_EXTENT, ACCEPT); } - public void generateOverview(Document document, Range range) { - + public void generateOverview( + Document document, + Range range, + Fixing.Filter filter + ) { List<Fixing.Column> allColumns = new ArrayList<Fixing.Column>(); for (Fixing fixing: fixings) { - fixing.addAllColumns(allColumns, range); + fixing.addAllColumns(allColumns, range, filter); } Collections.sort(allColumns, Fixing.DATE_CMP); @@ -713,8 +890,7 @@ for (Fixing.Column column: allColumns) { - // TODO: Apply additional filters here. - List<SectorRange> sectors = column.getSectors(); + List<SectorRange> sectors = column.getSectors(range); if (!sectors.isEmpty()) { Element eE = document.createElement("event");