This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
The following commit(s) were added to refs/heads/master by this push:
new f0da647d Add org.apache.commons.net.util.ListenerList.isEmpty()
f0da647d is described below
commit f0da647dd69093a8da0863df07726a8aeff36e31
Author: Gary D. Gregory <[email protected]>
AuthorDate: Wed Jul 16 08:51:16 2025 -0400
Add org.apache.commons.net.util.ListenerList.isEmpty()
---
src/changes/changes.xml | 3 ++-
.../apache/commons/net/ProtocolCommandSupport.java | 20 ++++++++++++--------
.../java/org/apache/commons/net/SocketClient.java | 8 ++------
src/main/java/org/apache/commons/net/imap/IMAP.java | 4 +---
.../org/apache/commons/net/util/ListenerList.java | 10 ++++++++++
5 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 15f54e98..6ab77216 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -103,7 +103,8 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
FTP.opts(String...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
FTP.setControlEncoding(Charset).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add --OPTS to
FTPClientExample.</action>
- <action type="add" dev="ggregory" due-to="Gary Gregory"
issue="NET-727">Add accessing options map for TFTP request packet and allow
using 'blksize' option #331.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory"
issue="NET-727">Add accessing options map for TFTP request packet and allow
using 'blksize' option #331.</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add
org.apache.commons.net.util.ListenerList.isEmpty().</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory,
Dependabot">Bump org.apache.commons:commons-parent from 70 to 85 #261, #278,
#280, #285, #298, #293, #300, #345.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory,
Dependabot">Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.18.0 #268,
#273, #281, #354.</action>
diff --git a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
index 523234fa..75c67085 100644
--- a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
+++ b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
@@ -71,10 +71,12 @@ public class ProtocolCommandSupport implements Serializable
{
* @param message The entire command string verbatim as sent to the
server, including all arguments.
*/
public void fireCommandSent(final String command, final String message) {
- final ProtocolCommandEvent event;
- event = new ProtocolCommandEvent(source, command, message);
- for (final EventListener listener : listeners) {
- ((ProtocolCommandListener) listener).protocolCommandSent(event);
+ if (!listeners.isEmpty()) {
+ final ProtocolCommandEvent event;
+ event = new ProtocolCommandEvent(source, command, message);
+ for (final EventListener listener : listeners) {
+ ((ProtocolCommandListener)
listener).protocolCommandSent(event);
+ }
}
}
@@ -88,10 +90,12 @@ public class ProtocolCommandSupport implements Serializable
{
* @param message The entire reply as received from the server.
*/
public void fireReplyReceived(final int replyCode, final String message) {
- final ProtocolCommandEvent event;
- event = new ProtocolCommandEvent(source, replyCode, message);
- for (final EventListener listener : listeners) {
- ((ProtocolCommandListener) listener).protocolReplyReceived(event);
+ if (!listeners.isEmpty()) {
+ final ProtocolCommandEvent event;
+ event = new ProtocolCommandEvent(source, replyCode, message);
+ for (final EventListener listener : listeners) {
+ ((ProtocolCommandListener)
listener).protocolReplyReceived(event);
+ }
}
}
diff --git a/src/main/java/org/apache/commons/net/SocketClient.java
b/src/main/java/org/apache/commons/net/SocketClient.java
index 0b24b923..50b7612e 100644
--- a/src/main/java/org/apache/commons/net/SocketClient.java
+++ b/src/main/java/org/apache/commons/net/SocketClient.java
@@ -343,9 +343,7 @@ public abstract class SocketClient {
* @since 3.0
*/
protected void fireCommandSent(final String command, final String message)
{
- if (getCommandSupport().getListenerCount() > 0) {
- getCommandSupport().fireCommandSent(command, message);
- }
+ getCommandSupport().fireCommandSent(command, message);
}
/**
@@ -356,9 +354,7 @@ public abstract class SocketClient {
* @since 3.0
*/
protected void fireReplyReceived(final int replyCode, final String reply) {
- if (getCommandSupport().getListenerCount() > 0) {
- getCommandSupport().fireReplyReceived(replyCode, reply);
- }
+ getCommandSupport().fireReplyReceived(replyCode, reply);
}
/**
diff --git a/src/main/java/org/apache/commons/net/imap/IMAP.java
b/src/main/java/org/apache/commons/net/imap/IMAP.java
index e255e155..32a4bf02 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAP.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAP.java
@@ -214,9 +214,7 @@ public class IMAP extends SocketClient {
*/
@Override
protected void fireReplyReceived(final int replyCode, final String
ignored) {
- if (getCommandSupport().getListenerCount() > 0) {
- getCommandSupport().fireReplyReceived(replyCode, getReplyString());
- }
+ getCommandSupport().fireReplyReceived(replyCode, getReplyString());
}
/**
diff --git a/src/main/java/org/apache/commons/net/util/ListenerList.java
b/src/main/java/org/apache/commons/net/util/ListenerList.java
index a532b9fb..423b3979 100644
--- a/src/main/java/org/apache/commons/net/util/ListenerList.java
+++ b/src/main/java/org/apache/commons/net/util/ListenerList.java
@@ -61,6 +61,16 @@ public class ListenerList implements Serializable,
Iterable<EventListener> {
return listeners.size();
}
+ /**
+ * Tests whether if this listener list is empty.
+ *
+ * @return whether if this listener list is empty.
+ * @since 3.12.0
+ */
+ public boolean isEmpty() {
+ return getListenerCount() == 0;
+ }
+
/**
* Return an {@link Iterator} for the {@link EventListener} instances.
*