public NameItemPathSegment clone() { NameItemPathSegment clone = new NameItemPathSegment(this.name); clone.setWildcard(this.isWildcard()); return clone; }
/** * Less strict version of comparison: it allows unqualified names to match fully qualified ones (e.g. x:xyz and xyz are the same). * * @param obj * @return */ @Override public boolean equivalent(Object obj) { return equals(obj, true, true); }
@Override public ItemName lastName() { NameItemPathSegment lastNamed = lastNamed(); return lastNamed != null ? lastNamed.getName() : null; }
public static ItemPathSegment createSegment(QName qname, boolean variable) { if (ParentPathSegment.QNAME.equals(qname)) { return new ParentPathSegment(); } else if (ObjectReferencePathSegment.QNAME.equals(qname)) { return new ObjectReferencePathSegment(); } else if (IdentifierPathSegment.QNAME.equals(qname)) { return new IdentifierPathSegment(); } else if (variable) { return new VariableItemPathSegment(qname); } else { return new NameItemPathSegment(qname); } }
public boolean equals(Object obj, boolean allowUnqualified, boolean allowDifferentPrefixes) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } NameItemPathSegment other = (NameItemPathSegment) obj; if (allowUnqualified) { if (!allowDifferentPrefixes) { throw new UnsupportedOperationException("It is not possible to disallow different prefixes while allowing unqualified names"); } return QNameUtil.match(name, other.name); } else { if (!name.equals(other.name)) { // compares namespace and local part return false; } // in order to differentiate between x:name and name (when x is undefined) we will compare the prefixes as well if (!allowDifferentPrefixes && !normalizedPrefix(name).equals(normalizedPrefix(other.name))) { return false; } return true; } }
@NotNull public UniformItemPath namedSegmentsOnly() { UniformItemPathImpl rv = new UniformItemPathImpl(); for (ItemPathSegment segment : segments) { if (segment instanceof NameItemPathSegment) { rv.add(((NameItemPathSegment) segment).getName()); } } return rv; }
static ItemName toName(Object segment, boolean failOnError) { if (segment instanceof NameItemPathSegment) { return ((NameItemPathSegment) segment).getName(); } else if (segment instanceof ItemName) { return (ItemName) segment; } else if (segment instanceof QName) { return ItemName.fromQName((QName) segment); } else { if (failOnError) { throw new IllegalArgumentException("Not a name: " + getStringInformation(segment)); } else { return null; } } }
/** * More strict version of comparison: it requires exact matching of QNames (e.g. x:xyz and xyz are different in this respect). * * @param obj * @return */ @Override public boolean equals(Object obj) { return equals(obj, false, false); }
PathHolderSegment xsegment; if (segment instanceof NameItemPathSegment) { QName name = ((NameItemPathSegment) segment).getName(); xsegment = new PathHolderSegment(name); if (forceExplicitNamespaceDeclarations && StringUtils.isNotEmpty(name.getPrefix())) {