Skip to content

Commit

Permalink
Just some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mbax committed Jul 23, 2020
1 parent c3012ad commit 7151e69
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/kitteh/irc/client/library/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ enum SecurityType {
/**
* TLS disabled.
*/
INSECURE;
INSECURE
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public synchronized void execute() {
parameterModesPerLine = modes.get().getInteger();
}
if (parameterModesPerLine < 1) {
parameterModesPerLine = PARAMETER_MODES_PER_LINE;
parameterModesPerLine = ChannelModeCommand.PARAMETER_MODES_PER_LINE;
}
List<ModeStatus<ChannelMode>> queue = new ArrayList<>();
int currentParamModes = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public abstract class Command<C extends Command<C>> implements ClientLinked {
public class Tags {
private List<MessageTag> tags = new ArrayList<>();
private final List<MessageTag> tags = new ArrayList<>();

public Tags add(@NonNull MessageTag tag) {
this.tags.add(Sanity.nullCheck(tag, "Tag"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,19 @@ private class WebIrcImpl implements WebIrc, WebIrc.Hostname, WebIrc.Gateway, Web
private class ManagementImpl implements Management {
@Override
public @NonNull Management actorTracker(@Nullable Function<Client.WithManagement, ? extends ActorTracker> supplier) {
DefaultBuilder.this.actorTracker = (supplier != null) ? supplier : DEFAULT_ACTOR_TRACKER;
DefaultBuilder.this.actorTracker = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_ACTOR_TRACKER;
return this;
}

@Override
public @NonNull Management authManager(@Nullable Function<Client.WithManagement, ? extends AuthManager> supplier) {
DefaultBuilder.this.authManager = (supplier != null) ? supplier : DEFAULT_AUTH_MANAGER;
DefaultBuilder.this.authManager = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_AUTH_MANAGER;
return this;
}

@Override
public @NonNull Management capabilityManager(@Nullable Function<Client.WithManagement, ? extends CapabilityManager.WithManagement> supplier) {
DefaultBuilder.this.capabilityManager = (supplier != null) ? supplier : DEFAULT_CAPABILITY_MANAGER;
DefaultBuilder.this.capabilityManager = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_CAPABILITY_MANAGER;
return this;
}

Expand All @@ -272,19 +272,19 @@ private class ManagementImpl implements Management {

@Override
public @NonNull Management eventManager(@Nullable Function<Client.WithManagement, ? extends EventManager> supplier) {
DefaultBuilder.this.eventManager = (supplier != null) ? supplier : DEFAULT_EVENT_MANAGER;
DefaultBuilder.this.eventManager = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_EVENT_MANAGER;
return this;
}

@Override
public @NonNull Management eventListeners(@Nullable List<EventListenerSupplier> listenerSuppliers) {
DefaultBuilder.this.eventListeners = (listenerSuppliers != null) ? listenerSuppliers : DEFAULT_EVENT_LISTENERS;
DefaultBuilder.this.eventListeners = (listenerSuppliers != null) ? listenerSuppliers : DefaultBuilder.DEFAULT_EVENT_LISTENERS;
return this;
}

@Override
public @NonNull Management iSupportManager(@Nullable Function<Client.WithManagement, ? extends ISupportManager> supplier) {
DefaultBuilder.this.iSupportManager = (supplier != null) ? supplier : DEFAULT_ISUPPORT_MANAGER;
DefaultBuilder.this.iSupportManager = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_ISUPPORT_MANAGER;
return this;
}

Expand All @@ -296,7 +296,7 @@ private class ManagementImpl implements Management {

@Override
public @NonNull Management messageTagManager(@Nullable Function<Client.WithManagement, ? extends MessageTagManager> supplier) {
DefaultBuilder.this.messageTagManager = (supplier != null) ? supplier : DEFAULT_MESSAGE_TAG_MANAGER;
DefaultBuilder.this.messageTagManager = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_MESSAGE_TAG_MANAGER;
return this;
}

Expand All @@ -308,7 +308,7 @@ private class ManagementImpl implements Management {

@Override
public @NonNull Management serverInfo(@Nullable Function<Client.WithManagement, ? extends ServerInfo.WithManagement> supplier) {
DefaultBuilder.this.serverInfo = (supplier != null) ? supplier : DEFAULT_SERVER_INFO;
DefaultBuilder.this.serverInfo = (supplier != null) ? supplier : DefaultBuilder.DEFAULT_SERVER_INFO;
return this;
}

Expand Down Expand Up @@ -342,7 +342,7 @@ private class ManagementImpl implements Management {
private @Nullable String bindHost;
private int bindPort;

private HostWithPort serverHostWithPort = HostWithPort.of(DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT);
private HostWithPort serverHostWithPort = HostWithPort.of(DefaultBuilder.DEFAULT_SERVER_HOST, DefaultBuilder.DEFAULT_SERVER_PORT);
private @Nullable String serverPassword = null;
private boolean secure = true;
private @Nullable Path secureKeyCertChain = null;
Expand Down Expand Up @@ -371,17 +371,17 @@ private class ManagementImpl implements Management {
private @Nullable String webircGateway = null;

// Management
private Function<Client.WithManagement, ? extends ActorTracker> actorTracker = DEFAULT_ACTOR_TRACKER;
private Function<Client.WithManagement, ? extends AuthManager> authManager = DEFAULT_AUTH_MANAGER;
private Function<Client.WithManagement, ? extends CapabilityManager.WithManagement> capabilityManager = DEFAULT_CAPABILITY_MANAGER;
private Function<Client.WithManagement, ? extends ActorTracker> actorTracker = DefaultBuilder.DEFAULT_ACTOR_TRACKER;
private Function<Client.WithManagement, ? extends AuthManager> authManager = DefaultBuilder.DEFAULT_AUTH_MANAGER;
private Function<Client.WithManagement, ? extends CapabilityManager.WithManagement> capabilityManager = DefaultBuilder.DEFAULT_CAPABILITY_MANAGER;
private @Nullable DefaultMessageMap defaultMessageMap = null;
private Function<Client.WithManagement, ? extends EventManager> eventManager = DEFAULT_EVENT_MANAGER;
private List<EventListenerSupplier> eventListeners = DEFAULT_EVENT_LISTENERS;
private Function<Client.WithManagement, ? extends ISupportManager> iSupportManager = DEFAULT_ISUPPORT_MANAGER;
private Function<Client.WithManagement, ? extends MessageSendingQueue> messageSendingQueue = DEFAULT_MESSAGE_SENDING_QUEUE;
private Function<Client.WithManagement, ? extends MessageTagManager> messageTagManager = DEFAULT_MESSAGE_TAG_MANAGER;
private Function<Client.WithManagement, ? extends EventManager> eventManager = DefaultBuilder.DEFAULT_EVENT_MANAGER;
private List<EventListenerSupplier> eventListeners = DefaultBuilder.DEFAULT_EVENT_LISTENERS;
private Function<Client.WithManagement, ? extends ISupportManager> iSupportManager = DefaultBuilder.DEFAULT_ISUPPORT_MANAGER;
private Function<Client.WithManagement, ? extends MessageSendingQueue> messageSendingQueue = DefaultBuilder.DEFAULT_MESSAGE_SENDING_QUEUE;
private Function<Client.WithManagement, ? extends MessageTagManager> messageTagManager = DefaultBuilder.DEFAULT_MESSAGE_TAG_MANAGER;
private NetworkHandler networkHandler = NettyNetworkHandler.getInstance();
private Function<Client.WithManagement, ? extends ServerInfo.WithManagement> serverInfo = DEFAULT_SERVER_INFO;
private Function<Client.WithManagement, ? extends ServerInfo.WithManagement> serverInfo = DefaultBuilder.DEFAULT_SERVER_INFO;
private @Nullable StsStorageManager stsStorageManager = null;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DefaultISupportMaxList extends DefaultISupportParameterValueRequire
/**
* Default implementation of {@link MaxList.LimitData}.
*/
public class DefaultLimitData implements MaxList.LimitData {
public static class DefaultLimitData implements MaxList.LimitData {
private final int limit;
private final Set<Character> modes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class DefaultISupportPrefix extends DefaultISupportParameterValueRequired
*/
public DefaultISupportPrefix(@NonNull Client client, @NonNull String name, @Nullable String value) {
super(client, name, value);
Matcher matcher = PATTERN.matcher(value);
Matcher matcher = DefaultISupportPrefix.PATTERN.matcher(value);
if (!matcher.find()) {
throw new KittehServerISupportException(name, "Data does not match expected pattern");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class DefaultModeStatusList<ModeType extends Mode> implements ModeStatusL
Map<Character, ChannelMode> modes = new HashMap<>();
client.getServerInfo().getChannelModes().forEach(mode -> modes.put(mode.getChar(), mode));
client.getServerInfo().getChannelUserModes().forEach(mode -> modes.put(mode.getChar(), mode));
return from(string, modes);
return DefaultModeStatusList.from(string, modes);
}

/**
Expand All @@ -73,7 +73,7 @@ public class DefaultModeStatusList<ModeType extends Mode> implements ModeStatusL
* @return list
*/
public static @NonNull DefaultModeStatusList<UserMode> fromUser(@NonNull Client client, @NonNull String string) {
return from(string, client.getServerInfo().getUserModes().stream().collect(Collectors.toMap(UserMode::getChar, Function.identity())));
return DefaultModeStatusList.from(string, client.getServerInfo().getUserModes().stream().collect(Collectors.toMap(UserMode::getChar, Function.identity())));
}

private static <ModeType extends Mode> @NonNull DefaultModeStatusList<ModeType> from(@NonNull String string, @NonNull Map<Character, ModeType> modes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,14 @@ public DefaultActorTracker(Client.@NonNull WithManagement client) {
} else if (this.client.getServerInfo().isValidChannel(name)) {
return new IrcChannel(name).snapshot();
}
if (name.isEmpty() || SERVER_PATTERN.matcher(name).matches()) {
if (name.isEmpty() || DefaultActorTracker.SERVER_PATTERN.matcher(name).matches()) {
return new IrcServer(name).snapshot();
}
return new IrcActor(name).snapshot();
}

private IrcUser getUserByName(@NonNull String name) {
Matcher nickMatcher = NICK_PATTERN.matcher(name);
Matcher nickMatcher = DefaultActorTracker.NICK_PATTERN.matcher(name);
if (nickMatcher.matches()) {
String nick = nickMatcher.group(1);
IrcUser user = this.trackedUsers.get(nick);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public DefaultMessageTagManager(Client.WithManagement client) {
private @NonNull String getTagValue(@NonNull String tag) {
StringBuilder builder = new StringBuilder(tag.length());
int currentIndex = 0;
Matcher matcher = TAG_ESCAPE.matcher(tag);
Matcher matcher = DefaultMessageTagManager.TAG_ESCAPE.matcher(tag);
while (matcher.find()) {
if (matcher.start() > currentIndex) {
builder.append(tag, currentIndex, matcher.start());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void dispatch(MessagePublication publication, Object message, Iterable li
}
}

private final class FilterProcessorWrapper {
private static final class FilterProcessorWrapper {
private final Annotation[] annotations;
private final FilterProcessor filterProcessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
});

// Inbound
this.channel.pipeline().addLast("[INPUT] Line splitter", new DelimiterBasedFrameDecoder(MAX_LINE_LENGTH, Unpooled.wrappedBuffer(new byte[]{(byte) '\r', (byte) '\n'})));
this.channel.pipeline().addLast("[INPUT] Line splitter", new DelimiterBasedFrameDecoder(NettyConnection.MAX_LINE_LENGTH, Unpooled.wrappedBuffer(new byte[]{(byte) '\r', (byte) '\n'})));
this.channel.pipeline().addLast("[INPUT] String decoder", new StringDecoder(CharsetUtil.UTF_8));
this.channel.pipeline().addLast("[INPUT] Send to client", new SimpleChannelInboundHandler<String>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class NettyNetworkHandler implements NetworkHandler {
* @return instance
*/
public static @NonNull NettyNetworkHandler getInstance() {
return instance;
return NettyNetworkHandler.instance;
}

private @Nullable EventLoopGroup eventLoopGroup;
Expand All @@ -82,12 +82,12 @@ private NettyNetworkHandler() {
* @param client client for whom to remove the connection
*/
private synchronized void removeClientConnection(Client.@NonNull WithManagement client) {
clients.remove(client);
if (clients.isEmpty()) {
if (eventLoopGroup != null) {
eventLoopGroup.shutdownGracefully();
this.clients.remove(client);
if (this.clients.isEmpty()) {
if (this.eventLoopGroup != null) {
this.eventLoopGroup.shutdownGracefully();
}
eventLoopGroup = null;
this.eventLoopGroup = null;
}
}

Expand All @@ -104,13 +104,13 @@ private synchronized void removeClientConnection(Client.@NonNull WithManagement
}
}

if (eventLoopGroup == null) {
eventLoopGroup = new NioEventLoopGroup();
if (this.eventLoopGroup == null) {
this.eventLoopGroup = new NioEventLoopGroup();
}

final Bootstrap bootstrap = new Bootstrap()
.channel(NioSocketChannel.class)
.group(eventLoopGroup)
.group(this.eventLoopGroup)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel channel) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void initChannel(SocketChannel channel) {
}

NettyConnection clientConnection = new NettyConnection(client, bootstrap.connect(server, bind), this::removeClientConnection);
clients.add(client);
this.clients.add(client);
return clientConnection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public void cap(ClientReceiveCommandEvent event) {
}
CapabilityNegotiationResponseEvent responseEvent = null;
int capabilityListIndex;
if ("*".equals(event.getParameters().get(CAPABILITY_LIST_INDEX_DEFAULT))) {
if ("*".equals(event.getParameters().get(DefaultCapListener.CAPABILITY_LIST_INDEX_DEFAULT))) {
if (event.getParameters().size() < 4) {
this.trackException(event, "CAP message too short");
return;
}
capabilityListIndex = CAPABILITY_LIST_INDEX_DEFAULT + 1;
capabilityListIndex = DefaultCapListener.CAPABILITY_LIST_INDEX_DEFAULT + 1;
} else {
capabilityListIndex = CAPABILITY_LIST_INDEX_DEFAULT;
capabilityListIndex = DefaultCapListener.CAPABILITY_LIST_INDEX_DEFAULT;
}
List<CapabilityState> capabilityStateList = Arrays.stream(event.getParameters().get(capabilityListIndex).split(" ")).filter(string -> !string.isEmpty()).map(capability -> new DefaultCapabilityState(this.getClient(), capability)).collect(Collectors.toCollection(ArrayList::new));
switch (event.getParameters().get(1).toLowerCase()) {
Expand All @@ -96,7 +96,7 @@ public void cap(ClientReceiveCommandEvent event) {
break;
case "list":
this.capListMessages.add(event.getServerMessage());
if (capabilityListIndex != CAPABILITY_LIST_INDEX_DEFAULT) {
if (capabilityListIndex != DefaultCapListener.CAPABILITY_LIST_INDEX_DEFAULT) {
this.capList.addAll(capabilityStateList);
} else {
List<CapabilityState> states;
Expand All @@ -113,7 +113,7 @@ public void cap(ClientReceiveCommandEvent event) {
break;
case "ls":
this.capLsMessages.add(event.getServerMessage());
if (capabilityListIndex != CAPABILITY_LIST_INDEX_DEFAULT) {
if (capabilityListIndex != DefaultCapListener.CAPABILITY_LIST_INDEX_DEFAULT) {
this.capLs.addAll(capabilityStateList);
} else {
List<CapabilityState> states;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class ClientConnectionEndedEvent extends ClientEventBase impleme

private final boolean canReconnect;
private final @Nullable Throwable cause;
private int reconnectionDelayMillis = DEFAULT_RECONNECTION_DELAY_MILLIS;
private int reconnectionDelayMillis = ClientConnectionEndedEvent.DEFAULT_RECONNECTION_DELAY_MILLIS;
private boolean attemptReconnect;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ private Defaults() {
* @return all capability names
*/
public static List<String> getDefaults() {
return DEFAULTS;
return Defaults.DEFAULTS;
}

static {
DEFAULTS = Collections.unmodifiableList(Arrays.stream(Defaults.class.getDeclaredFields())
.filter(field -> Modifier.isPublic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers()))
.map(Defaults::getStringForCapabilityField).collect(Collectors.toCollection(SUPPLIER)));
.map(Defaults::getStringForCapabilityField).collect(Collectors.toCollection(Defaults.SUPPLIER)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public enum CaseMapping {
private static final Map<String, CaseMapping> nameMap = new HashMap<>();

static {
for (CaseMapping caseMapping : values()) {
nameMap.put(caseMapping.name().replace('_', '-'), caseMapping);
for (CaseMapping caseMapping : CaseMapping.values()) {
CaseMapping.nameMap.put(caseMapping.name().replace('_', '-'), caseMapping);
}
}

Expand All @@ -63,7 +63,7 @@ public enum CaseMapping {
* @return the matching CaseMapping if one exists
*/
public static @NonNull Optional<CaseMapping> getByName(@Nullable String name) {
return (name == null) ? Optional.empty() : Optional.ofNullable(nameMap.get(name.toUpperCase()));
return (name == null) ? Optional.empty() : Optional.ofNullable(CaseMapping.nameMap.get(name.toUpperCase()));
}

private final char upperbound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void authenticate(ClientReceiveCommandEvent event) {
} else {
String challenge = event.getParameters().get(0);
try {
base64 = sign(SaslEcdsaNist256PChallenge.this.privateKey, challenge);
base64 = SaslEcdsaNist256PChallenge.sign(SaslEcdsaNist256PChallenge.this.privateKey, challenge);
} catch (Exception e) {
throw new RuntimeException(e); // TODO make this better
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class StsHandler {
* Draft prepend for capability.
*/
public static final String DRAFT = "draft/";
private static final Predicate<CapabilityState> STS_CAPABILITY_PREDICATE = c -> c.getName().equals(DRAFT + "sts") || c.getName().equals("sts");
private static final Predicate<CapabilityState> STS_CAPABILITY_PREDICATE = c -> c.getName().equals(StsHandler.DRAFT + "sts") || c.getName().equals("sts");
private final StsMachine machine;
private final Client.WithManagement client;
private boolean isSecure;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void onCapLs(CapabilitiesSupportedListEvent event) {
public void onCapNew(CapabilitiesNewSupportedEvent event) {
// stability not a concern, only one or zero result(s)
final Optional<CapabilityState> potentialStsCapability = event.getNewCapabilities().stream()
.filter(STS_CAPABILITY_PREDICATE).findAny();
.filter(StsHandler.STS_CAPABILITY_PREDICATE).findAny();

if (!potentialStsCapability.isPresent()) {
// get out if we can't do anything useful here
Expand Down
Loading

0 comments on commit 7151e69

Please sign in to comment.