1 package fr.jayasoft.ivy.version; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import fr.jayasoft.ivy.ModuleRevisionId; 10 import fr.jayasoft.ivy.matcher.Matcher; 11 import fr.jayasoft.ivy.version.AbstractVersionMatcher; 12 13 17 public class PatternVersionMatcher extends AbstractVersionMatcher { 18 19 private List _matches = new ArrayList (); 20 private Map _RevisionMatches = new HashMap (); private boolean _init = false; 22 23 public void addMatch(Match match) { 24 _matches.add(match); 25 } 26 27 private void init() { 28 if (!_init) { 29 for (Iterator it = _matches.iterator(); it.hasNext(); ) { 30 Match match = (Match) it.next(); 31 List matches = (List ) _RevisionMatches.get(match.getRevision()); 32 if (matches == null) { 33 matches = new ArrayList (); 34 _RevisionMatches.put(match.getRevision(), matches); 35 } 36 matches.add(match); 37 } 38 _init = true; 39 } 40 } 41 42 45 public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) { 46 init(); 47 boolean accept = false; 48 49 String revision = askedMrid.getRevision(); 50 int bracketIndex = revision.indexOf('('); 51 if (bracketIndex > 0) { 52 revision = revision.substring(0, bracketIndex); 53 } 54 55 List matches = (List ) _RevisionMatches.get(revision); 56 57 if (matches != null) { 58 Iterator it = matches.iterator(); 59 while (!accept && it.hasNext()) { 60 Match match = (Match) it.next(); 61 Matcher matcher = match.getPatternMatcher(askedMrid); 62 accept = matcher.matches(foundMrid.getRevision()); 63 } 64 } 65 66 return accept; 67 } 68 69 72 public boolean isDynamic(ModuleRevisionId askedMrid) { 73 init(); 74 String revision = askedMrid.getRevision(); 75 int bracketIndex = revision.indexOf('('); 76 if (bracketIndex > 0) { 77 revision = revision.substring(0, bracketIndex); 78 } 79 return _RevisionMatches.containsKey(revision); 80 } 81 82 } 83 | Popular Tags |