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