import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.UnmodifiableIterator;
+import java.util.ArrayList;
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;
@Override
protected SchemaPath createInstance(final SchemaPath parent, final QName qname) {
- return new AbsoluteSchemaPath(parent, qname);
+ return new AbsoluteSchemaPath(parent, Preconditions.checkNotNull(qname));
}
}
@Override
protected SchemaPath createInstance(final SchemaPath parent, final QName qname) {
- return new RelativeSchemaPath(parent, qname);
+ return new RelativeSchemaPath(parent, Preconditions.checkNotNull(qname));
}
}
*/
private volatile ImmutableList<QName> legacyPath;
+ /**
+ * @deprecated This constructor will be hidden in a future release.
+ * @param parent
+ * @param qname
+ */
+ @Deprecated
protected SchemaPath(final SchemaPath parent, final QName qname) {
this.parent = parent;
this.qname = qname;
- int h = parent == null ? 0 : parent.hashCode();
+ int h = Objects.hashCode(parent);
if (qname != null) {
h = h * 31 + qname.hashCode();
}
private ImmutableList<QName> getLegacyPath() {
ImmutableList<QName> ret = legacyPath;
if (ret == null) {
- ret = ImmutableList.copyOf(getPathTowardsRoot()).reverse();
+ final List<QName> tmp = new ArrayList<>();
+ for (QName qname : getPathTowardsRoot()) {
+ tmp.add(qname);
+ }
+ ret = ImmutableList.copyOf(Lists.reverse(tmp));
LEGACYPATH_UPDATER.lazySet(this, ret);
}
return new Iterable<QName>() {
@Override
public Iterator<QName> iterator() {
- return new Iterator<QName>() {
+ return new UnmodifiableIterator<QName>() {
private SchemaPath current = SchemaPath.this;
@Override
throw new NoSuchElementException("No more elements available");
}
}
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Component removal not supported");
- }
};
}
};
return false;
}
final SchemaPath other = (SchemaPath) obj;
-
- if (qname != null) {
- if (!qname.equals(other.qname)) {
- return false;
- }
- } else {
- if (other.qname != null) {
- return false;
- }
- }
-
- if (parent == null) {
- return other.parent == null;
- }
- return parent.equals(other.parent);
+ return Objects.equals(qname, other.qname) && Objects.equals(parent, other.parent);
}
@Override