Skip to content

Commit

Permalink
ARTEMIS-5281 use isEmpty() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jbertram authored and gemmellr committed Jan 30, 2025
1 parent 29e800f commit d54c771
Show file tree
Hide file tree
Showing 149 changed files with 259 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ public boolean isHa() {

@Override
public boolean hasAuthentication() {
return getUsername() != null && getUsername().length() > 0;
return getUsername() != null && !getUsername().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected ManagementContextDTO getManagementDTO() throws Exception {
}

protected String getConfiguration() {
if (configuration == null || configuration.equals("")) {
if (configuration == null || configuration.isEmpty()) {
File xmlFile = new File(new File(getBrokerEtc()), "bootstrap.xml");
configuration = "xml:" + xmlFile.toURI().toString().substring("file:".length());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public Object run(ActionContext context) throws Exception {

filters.put("${global-max-messages}", Long.toString(globalMaxMessages));

if (globalMaxSize == null || globalMaxSize.trim().equals("")) {
if (globalMaxSize == null || globalMaxSize.trim().isEmpty()) {
filters.put("${global-max-section}", readTextFile(ETC_GLOBAL_MAX_DEFAULT_TXT, filters));
} else {
filters.put("${global-max-size}", globalMaxSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public int inputInteger(String propertyName, String prompt, String silentDefault
Integer value = null;
do {
String input = input(propertyName, prompt, silentDefault);
if (input == null || input.trim().equals("")) {
if (input == null || input.trim().isEmpty()) {
input = "0";
}

Expand Down Expand Up @@ -106,7 +106,7 @@ protected String input(String propertyName, String prompt, String silentDefault,
getActionContext().out.println(propertyName + ":");
getActionContext().out.println(prompt);
inputStr = scanner.nextLine();
if (!acceptNull && inputStr.trim().equals("")) {
if (!acceptNull && inputStr.trim().isEmpty()) {
getActionContext().out.println("Invalid Entry!");
} else {
valid = true;
Expand Down Expand Up @@ -138,7 +138,7 @@ protected String inputPassword(String propertyName, String prompt, String silent

inputStr = new String(chars);

if (inputStr.trim().equals("")) {
if (inputStr.trim().isEmpty()) {
getActionContext().out.println("Invalid Entry!");
} else {
valid = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected CheckTask[] getCheckTasks() {
}
}

if (up || checkTasks.size() == 0) {
if (up || checkTasks.isEmpty()) {
checkTasks.add(0, new CheckTask("the node is started", this::checkNodeUp));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected CheckTask[] getCheckTasks() {
}
}

if (up || checkTasks.size() == 0) {
if (up || checkTasks.isEmpty()) {
checkTasks.add(0, new CheckTask(String.format("the queue %s exists and is not paused",
getName()), this::checkQueueUp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected Message createMessage(long i, String threadName) throws Exception {
answer.setLongProperty("count", i);
answer.setStringProperty("ThreadSent", threadName);

if (properties != null && properties.length() != 0) {
if (properties != null && !properties.isEmpty()) {
applyProperties(answer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private StringBuilder paddingString(StringBuilder value, int maxColumnSize) {
}

//would expect to have some data
if (value.length() == 0) {
if (value.isEmpty()) {
value.append("NO DATA");
}

Expand All @@ -450,12 +450,12 @@ private String createFilter() {

Map<String, Object> filterMap = new HashMap<>();

if (((fieldName != null) && (fieldName.trim().length() > 0)) && ((queueName != null && queueName.trim().length() > 0))) {
if (((fieldName != null) && (!fieldName.trim().isEmpty())) && ((queueName != null && !queueName.trim().isEmpty()))) {
getActionContext().err.println("'--field' and '--queueName' cannot be specified together.");
return null;
}

if ((fieldName != null) && (fieldName.trim().length() > 0)) {
if ((fieldName != null) && (!fieldName.trim().isEmpty())) {
try {
FIELD field = FIELD.valueOfJsonId(fieldName);

Expand All @@ -471,7 +471,7 @@ private String createFilter() {
}

//full filter being set ensure value is set
if (value == null || value.trim().length() == 0) {
if (value == null || value.trim().isEmpty()) {
getActionContext().err.println("'--value' needs to be set when '--field' is specified");
return null;
}
Expand All @@ -490,7 +490,7 @@ private String createFilter() {
return null;
}

} else if (queueName != null && queueName.trim().length() > 0) {
} else if (queueName != null && !queueName.trim().isEmpty()) {
filterMap.put("field", FIELD.NAME.toString());
filterMap.put("value", queueName);
filterMap.put("operation", OPERATION.CONTAINS.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static void importJournal(final String directory,

JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1);

if (journal.orderFiles().size() != 0) {
if (!journal.orderFiles().isEmpty()) {
throw new IllegalStateException("Import needs to create a brand new journal");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private void getMessageBodyBytes(MessageBodyBytesProcessor processor, boolean de
currentEventType = reader.getEventType();
if (currentEventType == XMLStreamConstants.END_ELEMENT) {
break;
} else if (currentEventType == XMLStreamConstants.CHARACTERS && reader.isWhiteSpace() && cdata.length() > 0) {
} else if (currentEventType == XMLStreamConstants.CHARACTERS && reader.isWhiteSpace() && !cdata.isEmpty()) {
/* when we hit a whitespace CHARACTERS event we know that the entire CDATA is complete so decode, pass back to
* the processor, and reset the cdata for the next event(s)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private void removeAcked(List<RecordInfo> acks) {
Map<Long, ReferenceDescribe> referenceDescribeHashMap = messageRefs.get(info.id);
if (referenceDescribeHashMap != null) {
referenceDescribeHashMap.remove(ack.refEncoding.queueID);
if (referenceDescribeHashMap.size() == 0) {
if (referenceDescribeHashMap.isEmpty()) {
messages.remove(info.id);
messageRefs.remove(info.id);
}
Expand Down Expand Up @@ -472,7 +472,7 @@ private void printPagedMessagesAsXML() {
}
}

if (queueNames.size() > 0 && (message.getTransactionID() == -1 || pgTXs.contains(message.getTransactionID()))) {
if (!queueNames.isEmpty() && (message.getTransactionID() == -1 || pgTXs.contains(message.getTransactionID()))) {
printSingleMessageAsXML(message.getMessage().toCore(), queueNames);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private class BlowfishAlgorithm extends CodecAlgorithm {
updateKey(key);
} else {
key = System.getProperty(KEY_SYSTEM_PROPERTY);
if (key != null && key.trim().length() > 0) {
if (key != null && !key.trim().isEmpty()) {
logger.trace("Set key from system property {}", KEY_SYSTEM_PROPERTY);
updateKey(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static byte[] textToNumericFormatV6(String ipString) {
// This indicates that a run of zeroes has been skipped.
int skipIndex = -1;
for (int i = 1; i < parts.length - 1; i++) {
if (parts[i].length() == 0) {
if (parts[i].isEmpty()) {
if (skipIndex >= 0) {
return null; // Can't have more than one ::
}
Expand All @@ -233,10 +233,10 @@ private static byte[] textToNumericFormatV6(String ipString) {
// If we found a "::", then check if it also covers the endpoints.
partsHi = skipIndex;
partsLo = parts.length - skipIndex - 1;
if (parts[0].length() == 0 && --partsHi != 0) {
if (parts[0].isEmpty() && --partsHi != 0) {
return null; // ^: requires ^::
}
if (parts[parts.length - 1].length() == 0 && --partsLo != 0) {
if (parts[parts.length - 1].isEmpty() && --partsLo != 0) {
return null; // :$ requires ::$
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class ListUtil {
public static List<String> toList(final String commaSeparatedString) {
List<String> list = new ArrayList<>();
if (commaSeparatedString == null || commaSeparatedString.trim().length() == 0) {
if (commaSeparatedString == null || commaSeparatedString.trim().isEmpty()) {
return list;
}
String[] values = commaSeparatedString.split(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void print(PrintStream stream, List<String>[] splitColumns, boolean[] cen
cellString = "";
}

if (centralize != null && centralize[column] && cellString.length() > 0) {
if (centralize != null && centralize[column] && !cellString.isEmpty()) {
int centralAdd = (columnSizes[column] - cellString.length()) / 2;
for (int i = 0; i < centralAdd; i++) {
cell.append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static byte[] getHardwareAddress() {
try {
List<NetworkInterface> ifaces = getAllNetworkInterfaces();

if (ifaces.size() == 0) {
if (ifaces.isEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Set<Entry<K, V>> entrySet() {

@Override
public boolean equals(Object o) {
return (o instanceof Map m) && m.size() == 0;
return (o instanceof Map m) && m.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private URI normalise(String uri) throws URISyntaxException {
String[] connectorURIS = split[0].substring(split[0].indexOf('(') + 1).split(",");
String factoryQuery = split.length > 1 ? split[1] : "";
StringBuilder builder = new StringBuilder(connectorURIS[0]);
if (factoryQuery != null && factoryQuery.length() > 0) {
if (factoryQuery != null && !factoryQuery.isEmpty()) {
if (connectorURIS[0].contains("?")) {
builder.append("&").append(factoryQuery.substring(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public URI toURI() throws URISyntaxException {
sb.append(':');
}

if (host != null && host.length() != 0) {
if (host != null && !host.isEmpty()) {
sb.append(host);
} else {
sb.append('(');
Expand Down Expand Up @@ -215,7 +215,7 @@ public static URI applyParameters(URI uri,
StringBuilder newQuery = uri.getRawQuery() != null ? new StringBuilder(uri.getRawQuery()) : new StringBuilder();
for (Map.Entry<String, String> param : queryParameters.entrySet()) {
if (param.getKey().startsWith(optionPrefix)) {
if (newQuery.length() != 0) {
if (!newQuery.isEmpty()) {
newQuery.append('&');
}
final String key = param.getKey().substring(optionPrefix.length());
Expand Down Expand Up @@ -261,7 +261,7 @@ public static URI createURIWithQuery(URI uri, String query) throws URISyntaxExce
if (questionMark > 0) {
schemeSpecificPart = schemeSpecificPart.substring(0, questionMark);
}
if (query != null && query.length() > 0) {
if (query != null && !query.isEmpty()) {
schemeSpecificPart += "?" + query;
}
return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment());
Expand Down Expand Up @@ -393,7 +393,7 @@ private static void parseComposite(URI uri, CompositeData rc, String ssp) throws
}
rc.parameters = parseQuery(params.substring(p + 1));
} else {
if (params.length() > 0) {
if (!params.isEmpty()) {
rc.path = stripPrefix(params, "/");
}
rc.parameters = emptyMap();
Expand Down Expand Up @@ -433,7 +433,7 @@ private static String[] splitComponents(String str) {
}

String s = str.substring(last);
if (s.length() != 0) {
if (!s.isEmpty()) {
l.add(s);
}

Expand Down Expand Up @@ -475,7 +475,7 @@ public static URI stripScheme(URI uri) throws URISyntaxException {
* @return a URI formatted query string.
*/
public static String createQueryString(Map<String, ? extends Object> options) {
if (options.size() > 0) {
if (!options.isEmpty()) {
StringBuilder rc = new StringBuilder();
boolean first = true;
List<String> keys = new ArrayList<>();
Expand Down Expand Up @@ -513,7 +513,7 @@ public static String createQueryString(Map<String, ? extends Object> options) {
*/
public static URI createRemainingURI(URI originalURI, Map<String, String> params) throws URISyntaxException {
String s = createQueryString(params);
if (s.length() == 0) {
if (s.isEmpty()) {
s = null;
}
return createURIWithQuery(originalURI, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private static class NullableJsonString implements JsonValue, JsonString {
private String escape;

NullableJsonString(String value) {
if (value == null || value.length() == 0) {
if (value == null || value.isEmpty()) {
this.value = null;
} else {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ private void checkCloseConnection() {
RemotingConnection connectionInUse = connection;
Connector connectorInUse = connector;

if (connectionInUse != null && sessions.size() == 0) {
if (connectionInUse != null && sessions.isEmpty()) {
cancelScheduledTasks();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ private void internalUpdateArray(long time) {
synchronized (topologyArrayGuard) {
Collection<TopologyMemberImpl> membersCopy = topology.getMembers();

if (membersCopy.size() == 0) {
if (membersCopy.isEmpty()) {
//it could happen when primary is down, in that case we keeps the old copy
//and don't update
return;
Expand Down Expand Up @@ -1960,7 +1960,7 @@ private String fromInterceptors(final List<Interceptor> interceptors) {
private void feedInterceptors(final List<Interceptor> interceptors, final String interceptorList) {
interceptors.clear();

if (interceptorList == null || interceptorList.trim().equals("")) {
if (interceptorList == null || interceptorList.trim().isEmpty()) {
return;
}
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private void sendMemberUp(final String nodeId, final TopologyMemberImpl memberTo
logger.trace("{}::prepare to send {} to {} elements", this, nodeId, copy.size());
}

if (copy.size() > 0) {
if (!copy.isEmpty()) {
executor.execute(() -> {
for (ClusterTopologyListener listener : copy) {
if (logger.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static TransformerConfiguration fromJSON(String jsonString) {

public JsonObjectBuilder createJsonObjectBuilder() {
JsonObjectBuilder tcBuilder = JsonLoader.createObjectBuilder().add(TransformerConfiguration.CLASS_NAME, getClassName());
if (getProperties() != null && getProperties().size() > 0) {
if (getProperties() != null && !getProperties().isEmpty()) {
JsonObjectBuilder propBuilder = JsonLoader.createObjectBuilder();
getProperties().forEach(propBuilder::add);
tcBuilder.add(TransformerConfiguration.PROPERTIES, propBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private boolean isTrustedType(Class<?> clazz) {

// Failing outright rejection or allow from above
// reject only if the allowList is not empty.
return allowList.size() == 0;
return allowList.isEmpty();
}

private boolean isClassOrPackageMatch(String className, String listEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static String getTextContent(final Node n) {
}

String s = sb.toString();
if (s.length() != 0) {
if (!s.isEmpty()) {
return s;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ protected void buildFromProperties(Properties props) {
throw new IllegalArgumentException(Context.PROVIDER_URL + " or " + "brokerURL is required");
}
try {
if (url != null && url.length() > 0) {
if (url != null && !url.isEmpty()) {
url = updateBrokerURL(url, props);
setBrokerURL(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private void checkName(String name) {
if (name == null) {
throw ActiveMQJMSClientBundle.BUNDLE.nameCannotBeNull();
}
if (name.equals("")) {
if (name.isEmpty()) {
throw ActiveMQJMSClientBundle.BUNDLE.nameCannotBeEmpty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private void checkName(final String name) throws JMSException {
if (name == null) {
throw ActiveMQJMSClientBundle.BUNDLE.nameCannotBeNull();
}
if (name.equals("")) {
if (name.isEmpty()) {
throw ActiveMQJMSClientBundle.BUNDLE.nameCannotBeEmpty();
}
}
Expand Down
Loading

0 comments on commit d54c771

Please sign in to comment.