From 411bf8f0dae524d70a0754049b5494182ade4a05 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 12 Jan 2020 22:12:09 +0100 Subject: Set owner of ZMIs on our path --- .../pl/edu/mimuw/cloudatlas/model/ValueUtils.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/model') 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 prefixComponents = prefix.getComponents(); + List pathComponents = path.getComponents(); + + if (prefixComponents.size() > pathComponents.size()) { + return false; + } + + Iterator prefixIterator = prefixComponents.iterator(); + Iterator pathIterator = pathComponents.iterator(); + + while (prefixIterator.hasNext()) { + if (!prefixIterator.next().equals(pathIterator.next())) { + return false; + } + } + return true; + } } -- cgit v1.2.3