import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
* An absolute schema node identifier.
*/
public static final class Absolute extends SchemaNodeIdentifier {
+ private static final Interner<Absolute> INTERNER = Interners.newWeakInterner();
+
Absolute(final QName qname) {
super(qname);
}
}
public static @NonNull Absolute of(final Collection<QName> nodeIdentifiers) {
- return new Absolute(ImmutableList.copyOf(nodeIdentifiers));
+ return new Absolute(nodeIdentifiers);
+ }
+
+ public @NonNull Absolute intern() {
+ return INTERNER.intern(this);
}
@Override
SchemaNodeIdentifier(final Collection<QName> qnames) {
final ImmutableList<QName> tmp = ImmutableList.copyOf(qnames);
- checkArgument(!tmp.isEmpty());
+ checkArgument(!tmp.isEmpty(), "SchemaNodeIdentifier has to have at least one node identifier");
this.qnames = tmp.size() == 1 ? tmp.get(0) : tmp;
}