1 11 package org.eclipse.team.internal.ccvs.core.util; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.Assert; 18 19 22 public class FileNameMatcher { 23 24 private List matchers = new ArrayList (); 25 private List results = new ArrayList (); 26 private static final String TRUE = "true"; 28 public FileNameMatcher() { 29 } 30 31 public FileNameMatcher(String [] patterns) { 32 register(patterns); 33 } 34 35 void register(String [] patterns) { 36 for (int i = 0; i < patterns.length; i++) { 37 register(patterns[i],TRUE); 38 } 39 } 40 41 public void register(String pattern, String result) { 42 43 Assert.isTrue(matchers.size() == results.size()); 44 45 pattern = pattern.trim(); 46 47 if (pattern.length() == 0) { 50 return; 51 } 52 53 matchers.add(new StringMatcher(pattern,false,false)); 54 results.add(result); 55 56 } 57 58 public String getMatch(String name) { 59 StringMatcher stringMatcher; 60 61 for (int i = 0; i < matchers.size(); i++) { 62 stringMatcher = (StringMatcher) matchers.get(i); 63 if (stringMatcher.match(name)) { 64 return (String )results.get(i); 65 } 66 } 67 68 return null; 69 } 70 71 public boolean match(String name) { 72 return getMatch(name) != null; 73 } 74 } 75 | Popular Tags |