Merge "Update Statement Service" into mnc-dev

This commit is contained in:
Joseph Wen
2015-05-26 15:11:08 +00:00
committed by Android (Google) Code Review

View File

@@ -30,16 +30,12 @@ import java.util.regex.Pattern;
* <p> We may add other kinds in the future. * <p> We may add other kinds in the future.
* *
* <p> The detail field is a lowercase alphanumeric string with underscores and periods allowed * <p> The detail field is a lowercase alphanumeric string with underscores and periods allowed
* (matching the regex [a-z0-9_.]+), but otherwise unstructured. It is also possible to specify '*' * (matching the regex [a-z0-9_.]+), but otherwise unstructured.
* (the wildcard character) as the detail if the relation applies to any detail in the specified
* kind.
*/ */
public final class Relation { public final class Relation {
private static final Pattern KIND_PATTERN = Pattern.compile("^[a-z0-9_.]+$"); private static final Pattern KIND_PATTERN = Pattern.compile("^[a-z0-9_.]+$");
private static final Pattern DETAIL_PATTERN = Pattern.compile("^([a-z0-9_.]+|[*])$"); private static final Pattern DETAIL_PATTERN = Pattern.compile("^([a-z0-9_.]+)$");
private static final String MATCH_ALL_DETAILS = "*";
private final String mKind; private final String mKind;
private final String mDetail; private final String mDetail;
@@ -92,12 +88,10 @@ public final class Relation {
} }
/** /**
* Returns true if {@code relation} has the same kind and detail. If {@code * Returns true if {@code relation} has the same kind and detail.
* relation.getDetail()} is wildcard (*) then returns true if the kind is the same.
*/ */
public boolean matches(Relation relation) { public boolean matches(Relation relation) {
return getKind().equals(relation.getKind()) && (getDetail().equals(MATCH_ALL_DETAILS) return getKind().equals(relation.getKind()) && getDetail().equals(relation.getDetail());
|| getDetail().equals(relation.getDetail()));
} }
/** /**