From fd7772a9b031f839d4c2b13743175b5fa5f45f71 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Sat, 30 May 2020 10:52:37 -0700 Subject: [PATCH] Improve implementation of flag methods. --- .../com/github/steveice10/packetlib/tcp/TcpSession.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java index c801b341..e0d2e037 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpSession.java @@ -25,6 +25,7 @@ import io.netty.handler.timeout.WriteTimeoutHandler; import java.net.ConnectException; import java.net.SocketAddress; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -93,12 +94,12 @@ public abstract class TcpSession extends SimpleChannelInboundHandler imp @Override public Map getFlags() { - return new HashMap(this.flags); + return Collections.unmodifiableMap(this.flags); } @Override public boolean hasFlag(String key) { - return this.getFlags().containsKey(key); + return this.flags.containsKey(key); } @SuppressWarnings("unchecked") @@ -109,7 +110,7 @@ public abstract class TcpSession extends SimpleChannelInboundHandler imp @Override public T getFlag(String key, T def) { - Object value = this.getFlags().get(key); + Object value = this.flags.get(key); if(value == null) { return def; }