org.yangcentral.yangkit.model.impl.schema.AbsoluteSchemaPath Maven / Gradle / Ivy
package org.yangcentral.yangkit.model.impl.schema;
import org.yangcentral.yangkit.common.api.QName;
import org.yangcentral.yangkit.model.api.schema.SchemaPath;
import java.util.ArrayList;
import java.util.List;
public class AbsoluteSchemaPath extends SchemaPathImpl implements SchemaPath.Absolute {
public AbsoluteSchemaPath(List steps) {
super(steps);
}
public AbsoluteSchemaPath() {
}
public boolean isAbsolute() {
return true;
}
public boolean contains(SchemaPath.Absolute path) {
List steps = this.getPath();
List anotherSteps = path.getPath();
if (steps.size() < anotherSteps.size()) {
return false;
} else {
for(int i = 0; i < anotherSteps.size(); ++i) {
QName step = steps.get(i);
QName anotherStep = anotherSteps.get(i);
if (!step.equals(anotherStep)) {
return false;
}
}
return true;
}
}
public List getRelativeSchemaPath(SchemaPath.Absolute path) {
if (null == path) {
return null;
} else if (!path.contains(this)) {
return null;
} else {
List steps = new ArrayList<>();
int thisSize = this.getPath().size();
int descendentSie = path.getPath().size();
for(int i = thisSize; i < descendentSie; ++i) {
steps.add( path.getPath().get(i));
}
return steps;
}
}
}