import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import com.google.common.collect.UnmodifiableIterator;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
/**
- * Represents unique path to the every schema node inside the schema node identifier
- * namespace.
- *
+ * Represents unique path to the every schema node inside the schema node identifier namespace.
*/
public abstract class SchemaNodeIdentifier implements Immutable {
@Override
protected SchemaNodeIdentifier createInstance(final SchemaNodeIdentifier parent, final QName qname) {
- return new Absolute(parent, qname);
+ return new Absolute(parent, Preconditions.checkNotNull(qname));
}
}
@Override
protected SchemaNodeIdentifier createInstance(final SchemaNodeIdentifier parent, final QName qname) {
- return new Relative(parent, qname);
+ return new Relative(parent, Preconditions.checkNotNull(qname));
}
}
@SuppressWarnings("rawtypes")
private static final AtomicReferenceFieldUpdater<SchemaNodeIdentifier, ImmutableList> LEGACYPATH_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(SchemaNodeIdentifier.class, ImmutableList.class, "legacyPath");
-
+ private static final AtomicReferenceFieldUpdater<SchemaNodeIdentifier, SchemaPath> SCHEMAPATH_UPDATER =
+ AtomicReferenceFieldUpdater.newUpdater(SchemaNodeIdentifier.class, SchemaPath.class, "schemaPath");
/**
* Shared instance of the conceptual root schema node.
*/
*/
private volatile ImmutableList<QName> legacyPath;
+ /**
+ * Cached SchemaPath.
+ */
+ private volatile SchemaPath schemaPath;
+
protected SchemaNodeIdentifier(final SchemaNodeIdentifier parent, final QName qname) {
this.parent = parent;
this.qname = qname;
return ret;
}
- /**
- * Returns the complete path to schema node.
- *
- * @return list of <code>QName</code> instances which represents complete
- * path to schema node
- *
- * @deprecated Use {@link #getPathFromRoot()} instead.
- */
- @Deprecated
- public List<QName> getPath() {
- return getLegacyPath();
- }
-
/**
* Constructs new instance of this class with the concrete path.
*
return new Iterable<QName>() {
@Override
public Iterator<QName> iterator() {
- return new Iterator<QName>() {
+ return new UnmodifiableIterator<QName>() {
private SchemaNodeIdentifier current = SchemaNodeIdentifier.this;
@Override
throw new NoSuchElementException("No more elements available");
}
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Component removal not supported");
- }
};
}
};
return qname;
}
+ private SchemaPath createSchemaPath() {
+ final SchemaPath newPath;
+ if (parent == null) {
+ final SchemaPath parentPath = isAbsolute() ? SchemaPath.ROOT : SchemaPath.SAME;
+ newPath = qname == null ? parentPath : parentPath.createChild(qname);
+ } else {
+ newPath = parent.asSchemaPath().createChild(qname);
+ }
+
+ return SCHEMAPATH_UPDATER.compareAndSet(this, null, newPath) ? newPath : schemaPath;
+ }
+
+ /**
+ * Create the {@link SchemaPath} equivalent of this identifier.
+ *
+ * @return SchemaPath equivalent.
+ */
+ public final SchemaPath asSchemaPath() {
+ final SchemaPath ret = schemaPath;
+ return ret != null ? ret : createSchemaPath();
+ }
+
/**
* Describes whether schema node identifier is|isn't absolute.
*
import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.firstAttributeOf;
import com.google.common.base.CharMatcher;
+import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
private static void addQNamesFromSchemaNodeIdentifierToList(final List<QName> qNamesFromRoot,
final SchemaNodeIdentifier augmentTargetPath) {
- Iterator<QName> augmentTargetPathIterator = augmentTargetPath.getPathFromRoot().iterator();
- while (augmentTargetPathIterator.hasNext()) {
- qNamesFromRoot.add(augmentTargetPathIterator.next());
+ for (QName qname : augmentTargetPath.getPathFromRoot()) {
+ qNamesFromRoot.add(qname);
}
}
// Yang constants should be lowercase so we have throw if value does not
// suit this
String deviateUpper = deviate.toUpperCase();
- if (Objects.equals(deviate, deviateUpper)) {
- throw new IllegalArgumentException(String.format("String %s is not valid deviate argument", deviate));
- }
+ Preconditions.checkArgument(!Objects.equals(deviate, deviateUpper),
+ "String %s is not valid deviate argument", deviate);
// but Java enum is uppercase so we cannot use lowercase here
try {
return status;
}
- public static SchemaPath SchemaNodeIdentifierToSchemaPath(final SchemaNodeIdentifier identifier) {
- return SchemaPath.create(identifier.getPathFromRoot(), identifier.isAbsolute());
- }
-
public static Date getLatestRevision(final RootStatementContext<?, ?, ?> root) {
return getLatestRevision(root.declaredSubstatements());
}
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
public class AugmentEffectiveStatementImpl
- extends
- AbstractEffectiveDocumentedDataNodeContainer<SchemaNodeIdentifier, AugmentStatement>
+ extends AbstractEffectiveDocumentedDataNodeContainer<SchemaNodeIdentifier, AugmentStatement>
implements AugmentationSchema, NamespaceRevisionAware, Comparable<AugmentEffectiveStatementImpl> {
private final SchemaPath targetPath;
private final URI namespace;
final StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> ctx) {
super(ctx);
- SchemaNodeIdentifier schemaNodeIdentifier = ctx.getStatementArgument();
- this.targetPath = SchemaPath.create(
- schemaNodeIdentifier.getPathFromRoot(),
- schemaNodeIdentifier.isAbsolute());
-
+ this.targetPath = ctx.getStatementArgument().asSchemaPath();
QNameModule rootModuleQName = Utils.getRootModuleQName(ctx);
this.namespace = rootModuleQName.getNamespace();
this.revision = rootModuleQName.getRevision();
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(
- AugmentEffectiveStatementImpl.class.getSimpleName());
+ StringBuilder sb = new StringBuilder(AugmentEffectiveStatementImpl.class.getSimpleName());
sb.append("[");
sb.append("targetPath=").append(targetPath);
sb.append(", when=").append(whenCondition);