PageRenderTime 29ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/webportal/src/main/java/org/ala/spatial/util/SPLFilter.java

http://alageospatialportal.googlecode.com/
Java | 190 lines | 133 code | 30 blank | 27 comment | 39 complexity | 1b0a01d48d8d9a1b40c5f318526fb225 MD5 | raw file
  1package org.ala.spatial.util;
  2
  3import net.sf.json.JSONObject;
  4
  5/**
  6 *
  7 * @author ajay
  8 */
  9public class SPLFilter {
 10
 11    public SPLFilter() {
 12    }
 13
 14    public SPLFilter(JSONObject _layer,
 15            int[] _catagories, String[] _catagory_names,
 16            double _minimum, double _maximum) {
 17        layer = _layer;
 18        if (layer != null) {
 19            layername = _layer.getString("name");
 20        }
 21        catagories = _catagories;
 22        catagory_names = _catagory_names;
 23        minimum_value = _minimum;
 24        maximum_value = _maximum;
 25
 26        minimum_initial = _minimum;
 27        maximum_initial = _maximum;
 28    }
 29    public int count = 0;
 30    public JSONObject layer;
 31    public String layername = "";
 32    public int[] catagories = null;		//use to maintain Set validity
 33    public String[] catagory_names = null;
 34    public double minimum_value = 0;
 35    public boolean changed;
 36    public String filterString;
 37
 38    public JSONObject getLayer() {
 39        return layer;
 40    }
 41
 42    public String getLayername() {
 43        return layername;
 44    }
 45
 46    public int[] getCatagories() {
 47        return catagories;
 48    }
 49
 50    public String[] getCatagory_names() {
 51        return catagory_names;
 52    }
 53
 54    public double getMinimum_value() {
 55        return minimum_value;
 56    }
 57
 58    public double getMaximum_value() {
 59        return maximum_value;
 60    }
 61
 62    public double getMinimum_initial() {
 63        return minimum_initial;
 64    }
 65
 66    public double getMaximum_initial() {
 67        return maximum_initial;
 68    }
 69    public double maximum_value = 0;
 70    public double minimum_initial = 0;
 71    public double maximum_initial = 0;
 72
 73    /* only works if created with constructor and 'catagories' Set validity is maintained */
 74    public boolean isChanged() {
 75        if (minimum_value != minimum_initial
 76                || maximum_value != maximum_initial
 77                || (catagories != null && catagory_names != null
 78                && catagories.length != catagory_names.length)) {
 79            return true;
 80        }
 81        return false;
 82    }
 83
 84    public boolean equals(SPLFilter f) {
 85        if (layername != f.layername
 86                || (catagories != null && f.catagories != null
 87                && catagories.length != f.catagories.length)
 88                || minimum_value != f.minimum_value
 89                || maximum_value != f.maximum_value) {
 90            return false;
 91        }
 92        return true;
 93    }
 94
 95    public String getFilterString() {
 96        /* TODO finish */
 97
 98        /*
 99         * cases:
100         *
101         * catagorical
102         * - include all
103         * - include none
104         * - only; comma separated list of names
105         *
106         * continous
107         * - include all
108         * - include none
109         * - between x and y
110         *
111         */
112
113        if (catagory_names != null) {
114            if (catagories == null || catagories.length == 0) {
115                return "include none";
116            } else if (catagories.length == catagory_names.length) {
117                return "include all";
118            } else {
119                StringBuffer string = new StringBuffer();
120                for (int i : catagories) {
121                    if (string.length() == 0) {
122                        string.append("only; ");
123                        string.append(catagory_names[i]);
124                    } else {
125                        string.append(", ");
126                        string.append(catagory_names[i]);
127                    }
128                }
129                return string.toString();
130            }
131        } else {
132            /*if(minimum_value <= minimum_initial
133            && maximum_value >= maximum_initial){
134            return "include all";
135            }else if(minimum_value > maximum_value
136            || maximum_value < minimum_initial
137            || minimum_value > maximum_initial){
138            return "include none";
139            }else*/            {
140                return "between " + String.format("%.4f", ((float) minimum_value))
141                        + " and " + String.format("%.4f", ((float) maximum_value));
142            }
143        }
144
145    }
146
147    public void setCatagories(int[] catagories) {
148        this.catagories = catagories;
149    }
150
151    public void setCatagory_names(String[] catagory_names) {
152        this.catagory_names = catagory_names;
153    }
154
155    public void setCount(int count) {
156        this.count = count;
157    }
158
159    public void setLayer(JSONObject layer) {
160        this.layer = layer;
161    }
162
163    public void setLayername(String layername) {
164        this.layername = layername;
165    }
166
167    public void setMaximum_initial(double maximum_initial) {
168        this.maximum_initial = maximum_initial;
169    }
170
171    public void setMaximum_value(double maximum_value) {
172        this.maximum_value = maximum_value;
173    }
174
175    public void setMinimum_initial(double minimum_initial) {
176        this.minimum_initial = minimum_initial;
177    }
178
179    public void setMinimum_value(double minimum_value) {
180        this.minimum_value = minimum_value;
181    }
182
183    public void setChanged(boolean isChanged) {
184        this.changed = isChanged;
185    }
186
187    public void setFilterString(String filterString) {
188        this.filterString = filterString;
189    }
190}