OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 18... Line 18...
18
import java.beans.DefaultPersistenceDelegate;
18
import java.beans.DefaultPersistenceDelegate;
19
import java.beans.PersistenceDelegate;
19
import java.beans.PersistenceDelegate;
20
import java.util.Collection;
20
import java.util.Collection;
21
import java.util.Comparator;
21
import java.util.Comparator;
22
import java.util.LinkedHashSet;
22
import java.util.LinkedHashSet;
-
 
23
import java.util.Objects;
23
import java.util.Set;
24
import java.util.Set;
24
import java.util.regex.Pattern;
25
import java.util.regex.Pattern;
25
 
26
 
26
import net.jcip.annotations.Immutable;
27
import net.jcip.annotations.Immutable;
27
 
28
 
Line 50... Line 51...
50
            res.add(mref.getID());
51
            res.add(mref.getID());
51
        }
52
        }
52
        return res;
53
        return res;
53
    }
54
    }
54
 
55
 
-
 
56
    static String checkID(final String id, final boolean throwExn) {
-
 
57
        return checkMatch(idPatrn, id, "ID", throwExn);
-
 
58
    }
-
 
59
 
55
    static String checkMatch(final Pattern p, final String s, final String name) {
60
    static String checkMatch(final Pattern p, final String s, final String name) {
-
 
61
        return checkMatch(p, s, name, true);
-
 
62
    }
-
 
63
 
-
 
64
    static String checkMatch(final Pattern p, final String s, final String name, final boolean throwExn) {
-
 
65
        Objects.requireNonNull(s, "string");
56
        if (!p.matcher(s).matches())
66
        if (p.matcher(s).matches())
-
 
67
            return s;
-
 
68
        else if (throwExn)
57
            throw new IllegalArgumentException(name + " doesn't match " + p.pattern());
69
            throw new IllegalArgumentException(name + " doesn't match " + p.pattern());
-
 
70
        else
58
        return s;
71
            return null;
59
    }
72
    }
60
 
73
 
61
    static final Pattern javaIdentifiedPatrn = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*");
74
    static final Pattern javaIdentifiedPatrn = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*");
62
    static final Pattern qualifiedPatrn = Pattern.compile(javaIdentifiedPatrn.pattern() + "(\\." + javaIdentifiedPatrn.pattern() + ")*");
75
    static final Pattern qualifiedPatrn = Pattern.compile(javaIdentifiedPatrn.pattern() + "(\\." + javaIdentifiedPatrn.pattern() + ")*");
63
 
76
 
Line 73... Line 86...
73
     * @param version module version, can be <code>null</code>.
86
     * @param version module version, can be <code>null</code>.
74
     */
87
     */
75
    public ModuleReference(String id, ModuleVersion version) {
88
    public ModuleReference(String id, ModuleVersion version) {
76
        if (id == null)
89
        if (id == null)
77
            throw new NullPointerException();
90
            throw new NullPointerException();
78
        this.id = checkMatch(idPatrn, id.trim(), "ID");
91
        this.id = checkID(id.trim(), true);
79
        if (version != null)
92
        if (version != null)
80
            version.checkValidity();
93
            version.checkValidity();
81
        this.version = version;
94
        this.version = version;
82
    }
95
    }
83
 
96