Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Core Java Code Examples

Find Numeric filter

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
Find Numeric filter class FindNumFilter { /** The value of this filter */ int num; /** Constants for the comparison operators. */ final int LE = -2, LT = -1, EQ = 0, GT = +1, GE = +2; /** The current comparison operator */ int mode = EQ; /** Constructor */ FindNumFilter(String input) { switch(input.charAt(0)) { case '+': mode = GT; break; case '-': mode = LT; break; case '=': mode = EQ; break; // No syntax for LE or GE yet. } num = Math.abs(Integer.parseInt(input)); } /** Construct a NumFilter when you know its mode and value */ FindNumFilter(int mode, int value) { this.mode = mode; num = value; } boolean accept(int n) { switch(mode) { case GT: return n > num; case EQ: return n == num; case LT: return n < num; default: System.err.println("UNEX CASE " + mode ); return false; } } }