m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/model
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2020-01-12 22:32:59 +0100
committerGitHub <noreply@github.com>2020-01-12 22:32:59 +0100
commit0f31d1f5c267f893d765ccd848b95fc111009de5 (patch)
treecf54497163b95e32fc8932b0ba13acc3fe2ca503 /src/main/java/pl/edu/mimuw/cloudatlas/model
parent32bfe8f7efc1f4fb99ddf827a19ab466724dac06 (diff)
parentcd247e8d64b2ef0aed7f0afdccd711008cd60fcd (diff)
Merge pull request #116 from m-chrzan/required-attributes
Required attributes
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/model')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
index 866349f..20d6600 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueUtils.java
@@ -1,5 +1,8 @@
package pl.edu.mimuw.cloudatlas.model;
+import java.util.List;
+import java.util.Iterator;
+
public class ValueUtils {
public static boolean valueNonNullOfType(Value value, Type type) {
return value != null && !value.isNull() && value.getType().isCompatible(type);
@@ -16,4 +19,23 @@ public class ValueUtils {
public static ValueTime addToTime(ValueTime time, long millis) {
return time.addValue(new ValueDuration(millis));
}
+
+ public static boolean isPrefix(PathName prefix, PathName path) {
+ List<String> prefixComponents = prefix.getComponents();
+ List<String> pathComponents = path.getComponents();
+
+ if (prefixComponents.size() > pathComponents.size()) {
+ return false;
+ }
+
+ Iterator<String> prefixIterator = prefixComponents.iterator();
+ Iterator<String> pathIterator = pathComponents.iterator();
+
+ while (prefixIterator.hasNext()) {
+ if (!prefixIterator.next().equals(pathIterator.next())) {
+ return false;
+ }
+ }
+ return true;
+ }
}