Skip to content

Commit

Permalink
use isEmpty() in more places
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1918535 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Jun 24, 2024
1 parent 1abd8e1 commit a3864e9
Show file tree
Hide file tree
Showing 39 changed files with 140 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/apache/xmlbeans/QNameSetBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static boolean isSpace(char ch)

private static String[] splitList(String s)
{
if (s.length() == 0)
if (s.isEmpty())
return EMPTY_STRINGARRAY;

List<String> result = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/xmlbeans/SchemaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public interface SchemaType extends SchemaComponent, SchemaAnnotated {
String getFullJavaName();

/**
* The short unqualfiied Java name for the class.
* The short unqualified Java name for the class.
*/
String getShortJavaName();

Expand All @@ -208,7 +208,7 @@ public interface SchemaType extends SchemaComponent, SchemaAnnotated {
String getFullJavaImplName();

/**
* The short unqualfiied Java name for the implementation class.
* The short unqualified Java name for the implementation class.
*/
String getShortJavaImplName();

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/xmlbeans/XmlValidationError.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public String getMessage()

sb.append(" in element ");
sb.append(_fieldQName.getLocalPart());
if (_fieldQName.getNamespaceURI() != null && _fieldQName.getNamespaceURI().length() != 0)
if (_fieldQName.getNamespaceURI() != null && !_fieldQName.getNamespaceURI().isEmpty())
sb.append('@').append(_fieldQName.getNamespaceURI());

return sb.toString();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/xmlbeans/impl/common/NameUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public static String getPackageFromNamespace(String uri) {

public static String getPackageFromNamespace(String uri, boolean useJaxRpcRules) {
// special case: no namespace -> package "noNamespace"
if (uri == null || uri.length() == 0) {
if (uri == null || uri.isEmpty()) {
return "noNamespace";
}

Expand Down Expand Up @@ -510,7 +510,7 @@ public static String getPackageFromNamespace(String uri, boolean useJaxRpcRules)
StringBuilder buf = new StringBuilder();
for (String s : result) {
String part = nonJavaKeyword(lowerCamelCase(s, useJaxRpcRules, true));
if (part.length() > 0) {
if (!part.isEmpty()) {
buf.append(part);
buf.append('.');
}
Expand Down Expand Up @@ -643,7 +643,7 @@ public static String upperCaseFirstLetter(String s) {
* ncname is xml ncname (i.e. no colons).
*/
private static void addCapped(List<String> list, String str) {
if (str.length() > 0) {
if (!str.isEmpty()) {
list.add(upperCaseFirstLetter(str));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static String pretty(QName name)
if (name == null)
return "null";

if (name.getNamespaceURI() == null || name.getNamespaceURI().length() == 0)
if (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty())
return name.getLocalPart();

return name.getLocalPart() + "@" + name.getNamespaceURI();
Expand Down Expand Up @@ -173,7 +173,7 @@ public static String hexsafe(String s)

public static String hexsafedir(QName name)
{
if (name.getNamespaceURI() == null || name.getNamespaceURI().length() == 0)
if (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty())
return "_nons/" + hexsafe(name.getLocalPart());
return hexsafe(name.getNamespaceURI()) + "/" + hexsafe(name.getLocalPart());
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public static String readable(QName name)

public static String readable(QName name, Map<String, String> prefixes)
{
if (name.getNamespaceURI().length() == 0)
if (name.getNamespaceURI().isEmpty())
return name.getLocalPart();
String prefix = prefixes.get(name.getNamespaceURI());
if (prefix != null)
Expand Down Expand Up @@ -366,7 +366,7 @@ public static String namespace(SchemaType sType)
{
if (sType.getName() != null)
return sType.getName().getNamespaceURI();
if (sType.getContainerField() != null && sType.getContainerField().getName().getNamespaceURI().length() > 0)
if (sType.getContainerField() != null && !sType.getContainerField().getName().getNamespaceURI().isEmpty())
return sType.getContainerField().getName().getNamespaceURI();
sType = sType.getOuterType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static String extractXmlDeclEncoding(char[] buf, int offset, int size) {
}

private static int firstIndexOf(String s, char[] buf, int startAt, int limit) {
assert (s.length() > 0);
assert (!s.isEmpty());
char[] lookFor = s.toCharArray();

char firstchar = lookFor[0];
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/xmlbeans/impl/common/XMLChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public static boolean isPubid(int c) {
* @return true if name is a valid Name
*/
public static boolean isValidName(String name) {
if (name.length() == 0)
if (name.isEmpty())
return false;
char ch = name.charAt(0);
if( isNameStart(ch) == false)
Expand All @@ -542,7 +542,7 @@ public static boolean isValidName(String name) {
* @return true if name is a valid NCName
*/
public static boolean isValidNCName(String ncName) {
if (ncName.length() == 0)
if (ncName.isEmpty())
return false;
char ch = ncName.charAt(0);
if( isNCNameStart(ch) == false)
Expand All @@ -567,7 +567,7 @@ public static boolean isValidNCName(String ncName) {
* @return true if nmtoken is a valid Nmtoken
*/
public static boolean isValidNmtoken(String nmtoken) {
if (nmtoken.length() == 0)
if (nmtoken.isEmpty())
return false;
for (int i = 0; i < nmtoken.length(); i++ ) {
char ch = nmtoken.charAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static String pretty(XMLName name)
if (name == null)
return "null";

if (name.getNamespaceUri() == null || name.getNamespaceUri().length() == 0)
if (name.getNamespaceUri() == null || name.getNamespaceUri().isEmpty())
return name.getLocalName();

return name.getLocalName() + "@" + name.getNamespaceUri();
Expand Down Expand Up @@ -109,7 +109,7 @@ public static String hexsafe(String s)

public static String hexsafedir(XMLName name)
{
if (name.getNamespaceUri() == null || name.getNamespaceUri().length() == 0)
if (name.getNamespaceUri() == null || name.getNamespaceUri().isEmpty())
return "_nons/" + hexsafe(name.getLocalName());
return hexsafe(name.getNamespaceUri()) + "/" + hexsafe(name.getLocalName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setLocalName(String localName) {
public void setPrefix(String prefix) { this.prefix = prefix; }

public String getQualifiedName() {
if (prefix != null && prefix.length() > 0)
if (prefix != null && !prefix.isEmpty())
return prefix + ":" + localName;
else
return localName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void write(XMLStreamReader xmlr, XMLStreamWriter writer)
case XMLEvent.START_ELEMENT:
final String localName = xmlr.getLocalName();
final String namespaceURI = xmlr.getNamespaceURI();
if (namespaceURI != null && namespaceURI.length() > 0) {
if (namespaceURI != null && !namespaceURI.isEmpty()) {
final String prefix = xmlr.getPrefix();
if (prefix != null)
writer.writeStartElement(prefix, localName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static class MethodSignatureImpl implements InterfaceExtension.MethodSignature {

_name = method.getName().asString();
String typeParams = method.getTypeParameters().stream().map(TypeParameter::toString).collect(Collectors.joining(", "));
_return = ( typeParams.length() == 0 ? "" : ( " <" + typeParams + "> ") ) +
_return = (typeParams.isEmpty() ? "" : ( " <" + typeParams + "> ") ) +
replaceInner(method.getType().resolve().describe());

_params = method.getParameters().stream().map(p -> p.getType().resolve().describe())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected Element processElement(XmlCursor xc, String comment,

if (!children.isEmpty()) {
// complex content
if (collapsedText.length() > 0) {
if (!collapsedText.isEmpty()) {
elemType.setContentType(Type.COMPLEX_TYPE_MIXED_CONTENT);
} else {
elemType.setContentType(Type.COMPLEX_TYPE_COMPLEX_CONTENT);
Expand Down Expand Up @@ -743,7 +743,7 @@ protected void combineElementsOfTypes(Type into, Type from, Inst2XsdOptions opti
}

protected void combineElementComments(Element into, Element with) {
if (with.getComment() != null && with.getComment().length() > 0) {
if (with.getComment() != null && !with.getComment().isEmpty()) {
if (into.getComment() == null) {
into.setComment(with.getComment());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected void fillUpLocalElement(Element element, org.apache.xmlbeans.impl.xb.x
if (!element.isRef())
{
assert element.getName().getNamespaceURI().equals(tns) ||
element.getName().getNamespaceURI().length() == 0;
element.getName().getNamespaceUri().isEmpty();
fillUpTypeOnElement(element.getType(), localSElement, tns);
localSElement.setName(element.getName().getLocalPart());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/xmlbeans/impl/regex/REUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static void main(String[] argv) {
System.exit( 0 );
}
for (int i = 0; i < argv.length; i ++) {
if (argv[i].length() == 0 || argv[i].charAt(0) != '-') {
if (argv[i].isEmpty() || argv[i].charAt(0) != '-') {
if (pattern == null)
pattern = argv[i];
else if (target == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static List<String> splitPath(String path, char separator) {
path = path.substring(i + 1);
}

if (path.length() > 0) {
if (!path.isEmpty()) {
components.add(path);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int fileTypeFromComponentType(int componentType) {
}

void readHandlePool(XsbReader reader) {
if (_handlesToRefs.size() != 0 || _started) {
if (!_handlesToRefs.isEmpty() || _started) {
throw new IllegalStateException("Nonempty handle set before read");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void writeTo(LongUTFDataOutputStream output) {
}

void readFrom(LongUTFDataInputStream input) {
if (intsToStrings.size() != 1 || stringsToInts.size() != 0) {
if (intsToStrings.size() != 1 || !stringsToInts.isEmpty()) {
throw new IllegalStateException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private static boolean isStringType(SchemaType type) {
static String pickConstantName(Set<String> usedNames, String words) {
String base = NameUtil.upperCaseUnderbar(words);

if (base.length() == 0) {
if (base.isEmpty()) {
base = "X";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public int getRecovered() {
*/
private QName compatName(QName name, String chameleonNamespace) {
// first check for a chameleonNamespace namespace
if (name.getNamespaceURI().length() == 0 && chameleonNamespace != null && chameleonNamespace.length() > 0) {
if (name.getNamespaceUri().isEmpty() && chameleonNamespace != null && chameleonNamespace.length() > 0) {
name = new QName(chameleonNamespace, name.getLocalPart());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ static SchemaLocalAttributeImpl translateAttribute(
state.error(XmlErrorCodes.NO_XSI, new Object[]{"http://www.w3.org/2001/XMLSchema-instance"}, xsdAttr.xgetName());
}

if (qname.getNamespaceURI().length() == 0 && qname.getLocalPart().equals("xmlns")) {
if (qname.getNamespaceUri().isEmpty() && qname.getLocalPart().equals("xmlns")) {
state.error(XmlErrorCodes.NO_XMLNS, null, xsdAttr.xgetName());
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/xmlbeans/impl/store/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void validateLocalName(String name) {
throw new IllegalArgumentException("Name is null");
}

if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("Name is empty");
}

Expand All @@ -123,7 +123,7 @@ static void validatePrefix(String name) {
throw new IllegalArgumentException("Prefix is null");
}

if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("Prefix is empty");
}

Expand Down Expand Up @@ -790,7 +790,7 @@ public String _namespaceForPrefix(String prefix) {
}

public String _prefixForNamespace(String ns) {
if (ns == null || ns.length() == 0) {
if (ns == null || ns.isEmpty()) {
throw new IllegalArgumentException("Must specify a namespace");
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/apache/xmlbeans/impl/store/DomImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private static String validatePrefix(
uri = "";
}

if (prefix.length() > 0 && uri.length() == 0) {
if (!prefix.isEmpty() && uri.isEmpty()) {
throw new NamespaceErr("Attempt to give a prefix for no namespace");
}

Expand Down Expand Up @@ -372,7 +372,7 @@ private static void validateName(String name) {
throw new IllegalArgumentException("Name is null");
}

if (name.length() == 0) {
if (name.isEmpty()) {
throw new IllegalArgumentException("Name is empty");
}

Expand Down Expand Up @@ -415,7 +415,7 @@ private static void validateQualifiedName(String name, String uri, boolean isAtt

validateNcName(prefix);

if (uri.length() == 0) {
if (uri.isEmpty()) {
throw new NamespaceErr("Attempt to give a prefix for no namespace");
}

Expand All @@ -432,7 +432,7 @@ private static void validateQualifiedName(String name, String uri, boolean isAtt
}
}

if (local.length() == 0) {
if (local.isEmpty()) {
throw new NamespaceErr("Invalid qualified name, no local part specified");
}
}
Expand Down Expand Up @@ -752,7 +752,7 @@ public static ProcessingInstruction document_createProcessingInstruction(Dom d,
throw new IllegalArgumentException("Target is null");
}

if (target.length() == 0) {
if (target.isEmpty()) {
throw new IllegalArgumentException("Target is empty");
}

Expand Down Expand Up @@ -894,14 +894,14 @@ public static Node document_importNode(Dom d, Node n, boolean deep) {
case ELEMENT: {
String local = n.getLocalName();

if (local == null || local.length() == 0) {
if (local == null || local.isEmpty()) {
i = document_createElement(d, n.getNodeName());
} else {
String prefix = n.getPrefix();
String name = prefix == null || prefix.length() == 0 ? local : prefix + ":" + local;
String name = prefix == null || prefix.isEmpty() ? local : prefix + ":" + local;
String uri = n.getNamespaceURI();

if (uri == null || uri.length() == 0) {
if (uri == null || uri.isEmpty()) {
i = document_createElement(d, name);
} else {
i = document_createElementNS(d, uri, name);
Expand All @@ -922,14 +922,14 @@ public static Node document_importNode(Dom d, Node n, boolean deep) {
case ATTR: {
String local = n.getLocalName();

if (local == null || local.length() == 0) {
if (local == null || local.isEmpty()) {
i = document_createAttribute(d, n.getNodeName());
} else {
String prefix = n.getPrefix();
String name = prefix == null || prefix.length() == 0 ? local : prefix + ":" + local;
String name = prefix == null || prefix.isEmpty() ? local : prefix + ":" + local;
String uri = n.getNamespaceURI();

if (uri == null || uri.length() == 0) {
if (uri == null || uri.isEmpty()) {
i = document_createAttribute(d, name);
} else {
i = document_createAttributeNS(d, uri, name);
Expand Down Expand Up @@ -1965,7 +1965,7 @@ public static String _node_getNodeName(Dom n) {
case ELEMENT: {
QName name = n.getQName();
String prefix = name.getPrefix();
return prefix.length() == 0 ? name.getLocalPart() : prefix + ":" + name.getLocalPart();
return prefix.isEmpty() ? name.getLocalPart() : prefix + ":" + name.getLocalPart();
}

case DOCTYPE:
Expand Down Expand Up @@ -2938,7 +2938,7 @@ public static void _characterData_appendData(Dom cd, String arg) {
// TODO - fix this *really* cheesy/bad/lousy perf impl
// also fix all the funcitons which follow

if (arg != null && arg.length() != 0) {
if (arg != null && !arg.isEmpty()) {
_node_setNodeValue(cd, _node_getNodeValue(cd) + arg);
}
}
Expand Down
Loading

0 comments on commit a3864e9

Please sign in to comment.