KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > version > PatternVersionMatcher


1 package fr.jayasoft.ivy.version;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import fr.jayasoft.ivy.ModuleRevisionId;
10 import fr.jayasoft.ivy.matcher.Matcher;
11 import fr.jayasoft.ivy.version.AbstractVersionMatcher;
12
13 /**
14  *
15  * @author Maarten Coene
16  */

17 public class PatternVersionMatcher extends AbstractVersionMatcher {
18
19     private List JavaDoc _matches = new ArrayList JavaDoc();
20     private Map JavaDoc _RevisionMatches = new HashMap JavaDoc(); // revision -> list of Match instances
21
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 JavaDoc it = _matches.iterator(); it.hasNext(); ) {
30                 Match match = (Match) it.next();
31                 List JavaDoc matches = (List JavaDoc) _RevisionMatches.get(match.getRevision());
32                 if (matches == null) {
33                     matches = new ArrayList JavaDoc();
34                     _RevisionMatches.put(match.getRevision(), matches);
35                 }
36                 matches.add(match);
37             }
38             _init = true;
39         }
40     }
41
42     /**
43      * {@inheritDoc}
44      */

45     public boolean accept(ModuleRevisionId askedMrid, ModuleRevisionId foundMrid) {
46         init();
47         boolean accept = false;
48
49         String JavaDoc revision = askedMrid.getRevision();
50         int bracketIndex = revision.indexOf('(');
51         if (bracketIndex > 0) {
52             revision = revision.substring(0, bracketIndex);
53         }
54         
55         List JavaDoc matches = (List JavaDoc) _RevisionMatches.get(revision);
56         
57         if (matches != null) {
58             Iterator JavaDoc 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     /**
70      * {@inheritDoc}
71      */

72     public boolean isDynamic(ModuleRevisionId askedMrid) {
73         init();
74         String JavaDoc 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