1 19 20 package org.netbeans.upgrade; 21 22 import java.io.*; 23 import java.util.*; 24 import java.util.jar.*; 25 import java.util.regex.*; 26 import org.openide.util.Union2; 27 28 29 30 34 final class IncludeExclude extends AbstractSet { 35 37 private List<Union2<Boolean , Pattern>> patterns = new ArrayList<Union2<Boolean , Pattern>> (); 38 39 private IncludeExclude () { 40 } 41 42 46 public static Set create (Reader r) throws IOException { 47 IncludeExclude set = new IncludeExclude (); 48 49 BufferedReader buf = new BufferedReader (r); 50 for (;;) { 51 String line = buf.readLine (); 52 if (line == null) break; 53 54 line = line.trim (); 55 if (line.length () == 0 || line.startsWith ("#")) { 56 continue; 57 } 58 59 Boolean plus; 60 if (line.startsWith ("include ")) { 61 line = line.substring (8); 62 plus = Boolean.TRUE; 63 } else { 64 if (line.startsWith ("exclude ")) { 65 line = line.substring (8); 66 plus = Boolean.FALSE; 67 } else { 68 throw new java.io.IOException ("Wrong line: " + line); 69 } 70 } 71 72 Pattern p = Pattern.compile (line); 73 74 set.patterns.add (Union2.<Boolean ,Pattern>createFirst(plus)); 75 set.patterns.add (Union2.<Boolean ,Pattern>createSecond(p)); 76 } 77 78 return set; 79 } 80 81 82 public Iterator iterator () { 83 return null; 84 } 85 86 public int size () { 87 return 0; 88 } 89 90 public boolean contains (Object o) { 91 String s = (String )o; 92 93 boolean yes = false; 94 95 Iterator<Union2<Boolean ,Pattern>> it = patterns.iterator (); 96 while (it.hasNext ()) { 97 Boolean include = it.next ().first(); 98 Pattern p = it.next ().second(); 99 100 Matcher m = p.matcher (s); 101 if (m.matches ()) { 102 yes = include.booleanValue (); 103 } 104 } 105 106 return yes; 107 } 108 109 } 110 | Popular Tags |