Debian Codegraph @

src/dr/inference/trace/Filter.java

raw symbols SCIP
1 /*
2 * Filter.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.inference.trace;
27
28 /**
29 * @author Walter Xie
30 */
31 public class Filter {
32
33 final protected TraceType traceType; // for consistency matter
34 protected String[] in; // bound of double or integer filter, values of string filter
35
36 public Filter(String[] in, TraceType traceType) {
37 if (traceType.isNumber() && in.length != 2)
38 throw new IllegalArgumentException("Numeric filter must have both lower and upper ! trace type = " + traceType);
39 setIn(in);
40 this.traceType = traceType;
41 }
42
43 public boolean isIn(Object value) {
44 if (traceType.isNumber()) {
45 // double or integer
46 return ( (Double)value >= Double.parseDouble(in[0]) && (Double)value <= Double.parseDouble(in[1]));
47 }
48 // String
49 for (Object t : in) {
50 if (t.toString().equals(value.toString())) {
51 return true;
52 }
53 }
54 return false;
55 }
56
57 /**
58 * either lower and upper limits of double or integer filter, or values of string filter
59 * @return String[]
60 */
61 public String[] getIn() {
62 return this.in;
63 }
64
65 public void setIn(String[] in) {
66 this.in = in;
67 }
68
69 public String getStatusMessage() {
70 String message = /*traceName +*/ " is filtered";
71 // if (traceType == TraceFactory.TraceType.DOUBLE) {
72 // message += " into range [" + in[0] + ", " + in[1] + "]";
73 // } else {
74 // message += " by selecting {";
75 // for (Object t : in) {
76 // message += t.toString() + ", ";
77 // }
78 // message = message.substring(0, message.lastIndexOf(", ")); // remove ", " for last in[]
79 // message += "}";
80 // }
81 return message;
82 }
83 }