1 package com.puppycrawl.tools.checkstyle.filters; 20 21 import java.util.HashSet ; 22 import java.util.Iterator ; 23 import java.util.Set ; 24 import java.util.StringTokenizer ; 25 26 34 class CSVFilter implements IntFilter 35 { 36 37 private final Set mFilters = new HashSet (); 38 39 43 public void addFilter(IntFilter aFilter) 44 { 45 mFilters.add(aFilter); 46 } 47 48 52 protected Set getFilters() 53 { 54 return mFilters; 55 } 56 57 66 public CSVFilter(String aPattern) 67 throws NumberFormatException 68 { 69 final StringTokenizer tokenizer = new StringTokenizer (aPattern, ","); 70 while (tokenizer.hasMoreTokens()) { 71 final String token = tokenizer.nextToken().trim(); 72 final int index = token.indexOf("-"); 73 if (index == -1) { 74 final int matchValue = Integer.parseInt(token); 75 addFilter(new IntMatchFilter(matchValue)); 76 } 77 else { 78 final int lowerBound = 79 Integer.parseInt(token.substring(0, index)); 80 final int upperBound = 81 Integer.parseInt(token.substring(index + 1)); 82 addFilter(new IntRangeFilter(lowerBound, upperBound)); 83 } 84 } 85 } 86 87 92 public boolean accept(Integer aInt) 93 { 94 final Iterator it = getFilters().iterator(); 95 while (it.hasNext()) { 96 final IntFilter filter = (IntFilter) it.next(); 97 if (filter.accept(aInt)) { 98 return true; 99 } 100 } 101 return false; 102 } 103 104 105 public String toString() 106 { 107 return mFilters.toString(); 108 } 109 110 111 public int hashCode() 112 { 113 return mFilters.hashCode(); 114 } 115 116 117 public boolean equals(Object aObject) 118 { 119 if (aObject instanceof CSVFilter) { 120 final CSVFilter other = (CSVFilter) aObject; 121 return this.mFilters.equals(other.mFilters); 122 } 123 return false; 124 } 125 } 126 | Popular Tags |