Skip to content

Commit 6c0eb61

Browse files
committed
Use ModeStatus.Action in relevant places
1 parent bc11e7e commit 6c0eb61

File tree

10 files changed

+79
-76
lines changed

10 files changed

+79
-76
lines changed

src/main/java/org/kitteh/irc/client/library/command/AwayCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public AwayCommand(@NonNull Client client) {
5252
* @return this command
5353
* @throws IllegalArgumentException for invalid message
5454
*/
55-
public @NonNull AwayCommand message(@Nullable String message) {
55+
public @NonNull AwayCommand away(@Nullable String message) {
5656
this.message = (message == null) ? null : Sanity.safeMessageCheck(message);
5757
return this;
5858
}
@@ -63,7 +63,7 @@ public AwayCommand(@NonNull Client client) {
6363
*
6464
* @return this command
6565
*/
66-
public @NonNull AwayCommand messageRemove() {
66+
public @NonNull AwayCommand notAway() {
6767
this.message = null;
6868
return this;
6969
}

src/main/java/org/kitteh/irc/client/library/command/ChannelModeCommand.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,53 +62,53 @@ public ChannelModeCommand(@NonNull Client client, @NonNull String channel) {
6262
/**
6363
* Adds a mode change without a parameter.
6464
*
65-
* @param add true if adding, false if removing
65+
* @param action adding or removing
6666
* @param mode the mode to be changed
6767
* @return this ModeCommand
6868
* @throws IllegalArgumentException if mode invalid
6969
*/
70-
public @NonNull ChannelModeCommand add(boolean add, @NonNull ChannelMode mode) {
71-
return this.addChange(add, mode, null);
70+
public @NonNull ChannelModeCommand add(ModeStatus.Action action, @NonNull ChannelMode mode) {
71+
return this.addChange(action, mode, null);
7272
}
7373

7474
/**
7575
* Adds a mode change.
7676
*
77-
* @param add true if adding, false if removing
77+
* @param action adding or removing
7878
* @param mode the mode to be changed
7979
* @param parameter mode parameter
8080
* @return this ModeCommand
8181
* @throws IllegalArgumentException if mode invalid comes from a
8282
* different client or parameter is null
8383
*/
84-
public @NonNull ChannelModeCommand add(boolean add, @NonNull ChannelMode mode, @NonNull String parameter) {
85-
return this.addChange(add, mode, Sanity.nullCheck(parameter, "Parameter cannot be null"));
84+
public @NonNull ChannelModeCommand add(ModeStatus.Action action, @NonNull ChannelMode mode, @NonNull String parameter) {
85+
return this.addChange(action, mode, Sanity.nullCheck(parameter, "Parameter cannot be null"));
8686
}
8787

8888
/**
8989
* Adds a mode change.
9090
*
91-
* @param add true if adding, false if removing
91+
* @param action adding or removing
9292
* @param mode the mode to be changed
9393
* @param parameter user whose nick will be sent
9494
* @return this ModeCommand
9595
* @throws IllegalArgumentException if mode invalid or either mode or
9696
* user comes from a different client or parameter is null
9797
*/
98-
public @NonNull ChannelModeCommand add(boolean add, @NonNull ChannelUserMode mode, @NonNull User parameter) {
98+
public @NonNull ChannelModeCommand add(ModeStatus.Action action, @NonNull ChannelUserMode mode, @NonNull User parameter) {
9999
Sanity.nullCheck(parameter, "User cannot be null");
100100
Sanity.truthiness(parameter.getClient() == this.getClient(), "User comes from a different Client");
101-
return this.addChange(add, mode, parameter.getNick());
101+
return this.addChange(action, mode, parameter.getNick());
102102
}
103103

104-
private synchronized @NonNull ChannelModeCommand addChange(boolean add, @NonNull ChannelMode mode, @Nullable String parameter) {
104+
private synchronized @NonNull ChannelModeCommand addChange(ModeStatus.Action action, @NonNull ChannelMode mode, @Nullable String parameter) {
105105
Sanity.nullCheck(mode, "Mode cannot be null");
106106
Sanity.truthiness(mode.getClient() == this.getClient(), "Mode comes from a different Client");
107107
if (parameter != null) {
108108
Sanity.safeMessageCheck(parameter, "Parameter");
109-
this.changes.add(new DefaultModeStatus<>(add, mode, parameter));
109+
this.changes.add(new DefaultModeStatus<>(action, mode, parameter));
110110
} else {
111-
this.changes.add(new DefaultModeStatus<>(add, mode));
111+
this.changes.add(new DefaultModeStatus<>(action, mode));
112112
}
113113
return this;
114114
}

src/main/java/org/kitteh/irc/client/library/command/UserModeCommand.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,37 @@ public UserModeCommand(@NonNull Client client) {
5555
/**
5656
* Adds a mode change without a parameter.
5757
*
58-
* @param add true if adding, false if removing
58+
* @param action adding or removing
5959
* @param mode the mode to be changed
6060
* @return this ModeCommand
6161
* @throws IllegalArgumentException if mode invalid
6262
*/
63-
public @NonNull UserModeCommand add(boolean add, @NonNull UserMode mode) {
64-
return this.addChange(add, mode, null);
63+
public @NonNull UserModeCommand add(ModeStatus.Action action, @NonNull UserMode mode) {
64+
return this.addChange(action, mode, null);
6565
}
6666

6767
/**
6868
* Adds a mode change.
6969
*
70-
* @param add true if adding, false if removing
70+
* @param action adding or removing
7171
* @param mode the mode to be changed
7272
* @param parameter mode parameter
7373
* @return this ModeCommand
7474
* @throws IllegalArgumentException if mode invalid comes from a
7575
* different client or parameter is null
7676
*/
77-
public @NonNull UserModeCommand add(boolean add, @NonNull UserMode mode, @NonNull String parameter) {
78-
return this.addChange(add, mode, Sanity.nullCheck(parameter, "Parameter cannot be null"));
77+
public @NonNull UserModeCommand add(ModeStatus.Action action, @NonNull UserMode mode, @NonNull String parameter) {
78+
return this.addChange(action, mode, Sanity.nullCheck(parameter, "Parameter cannot be null"));
7979
}
8080

81-
private synchronized @NonNull UserModeCommand addChange(boolean add, @NonNull UserMode mode, @Nullable String parameter) {
81+
private synchronized @NonNull UserModeCommand addChange(ModeStatus.Action action, @NonNull UserMode mode, @Nullable String parameter) {
8282
Sanity.nullCheck(mode, "Mode cannot be null");
8383
Sanity.truthiness(mode.getClient() == this.getClient(), "Mode comes from a different Client");
8484
if (parameter != null) {
8585
Sanity.safeMessageCheck(parameter, "Parameter");
86-
this.changes.add(new DefaultModeStatus<>(add, mode, parameter));
86+
this.changes.add(new DefaultModeStatus<>(action, mode, parameter));
8787
} else {
88-
this.changes.add(new DefaultModeStatus<>(add, mode));
88+
this.changes.add(new DefaultModeStatus<>(action, mode));
8989
}
9090
return this;
9191
}

src/main/java/org/kitteh/irc/client/library/defaults/element/mode/DefaultModeStatus.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ public class DefaultModeStatus<ModeType extends Mode> implements ModeStatus<Mode
4444
/**
4545
* Creates a status without a parameter.
4646
*
47-
* @param setting true for setting mode, false for removing
47+
* @param action adding or removing
4848
* @param mode mode to set
4949
*/
50-
public DefaultModeStatus(boolean setting, @NonNull ModeType mode) {
50+
public DefaultModeStatus(Action action, @NonNull ModeType mode) {
5151
this.mode = Sanity.nullCheck(mode, "Mode cannot be null");
5252
this.parameter = null;
53-
this.action = setting ? Action.ADD : Action.REMOVE;
53+
this.action = action;
5454
}
5555

5656
/**
5757
* Creates a status.
5858
*
59-
* @param setting true for setting mode, false for removing
59+
* @param action adding or removing
6060
* @param mode mode to set
6161
* @param parameter parameter
6262
*/
63-
public DefaultModeStatus(boolean setting, @NonNull ModeType mode, @NonNull String parameter) {
63+
public DefaultModeStatus(Action action, @NonNull ModeType mode, @NonNull String parameter) {
6464
this.mode = Sanity.nullCheck(mode, "Mode cannot be null");
6565
this.parameter = Sanity.safeMessageCheck(parameter, "Parameter");
66-
this.action = setting ? Action.ADD : Action.REMOVE;
66+
this.action = action;
6767
}
6868

6969
@Override

src/main/java/org/kitteh/irc/client/library/defaults/element/mode/DefaultModeStatusList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,25 @@ public class DefaultModeStatusList<ModeType extends Mode> implements ModeStatusL
8686
if (!((changes.charAt(0) == '+') || (changes.charAt(0) == '-'))) {
8787
throw new IllegalArgumentException("Mode change does not start with + or -");
8888
}
89-
boolean add = true;
89+
ModeStatus.Action action = null; // Immediately changed because of lines immediately above and the switch below.
9090
for (char modeChar : changes.toCharArray()) {
9191
switch (modeChar) {
9292
case '+':
93-
add = true;
93+
action = ModeStatus.Action.ADD;
9494
break;
9595
case '-':
96-
add = false;
96+
action = ModeStatus.Action.REMOVE;
9797
break;
9898
default:
9999
ModeType mode = modes.get(modeChar);
100100
if (mode == null) {
101101
throw new IllegalArgumentException("Contains non-registered mode: " + modeChar);
102102
}
103103
String target = null;
104-
if ((mode instanceof ChannelMode) && ((mode instanceof ChannelUserMode) || (add ? ((ChannelMode) mode).getType().isParameterRequiredOnSetting() : ((ChannelMode) mode).getType().isParameterRequiredOnRemoval()))) {
104+
if ((mode instanceof ChannelMode) && ((mode instanceof ChannelUserMode) || ((action == ModeStatus.Action.ADD) ? ((ChannelMode) mode).getType().isParameterRequiredOnSetting() : ((ChannelMode) mode).getType().isParameterRequiredOnRemoval()))) {
105105
target = args[++currentArg];
106106
}
107-
list.add((target == null) ? new DefaultModeStatus<>(add, mode) : new DefaultModeStatus<>(add, mode, target));
107+
list.add((target == null) ? new DefaultModeStatus<>(action, mode) : new DefaultModeStatus<>(action, mode, target));
108108
}
109109
}
110110
}

src/main/java/org/kitteh/irc/client/library/defaults/feature/DefaultActorTracker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void setTopic(long time, @NonNull Actor actor) {
207207

208208
void trackMode(@NonNull ChannelMode mode, boolean track) {
209209
if (track && this.trackedModes.add(mode.getChar())) {
210-
new ChannelModeCommand(DefaultActorTracker.this.client, this.getName()).add(true, mode).execute();
210+
// Request the mode list (bans, quiets, etc)
211+
new ChannelModeCommand(DefaultActorTracker.this.client, this.getName()).add(ModeStatus.Action.ADD, mode).execute();
211212
} else if (!track) {
212213
this.trackedModes.remove(mode.getChar());
213214
}

src/main/java/org/kitteh/irc/client/library/element/mode/ModeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ public interface ModeInfo extends ClientLinked {
7676
* Attempts to remove this item from the channel.
7777
*/
7878
default void remove() {
79-
new ChannelModeCommand(this.getClient(), this.getChannel().getName()).add(false, this.getMode(), this.getMask().asString()).execute();
79+
new ChannelModeCommand(this.getClient(), this.getChannel().getName()).add(ModeStatus.Action.REMOVE, this.getMode(), this.getMask().asString()).execute();
8080
}
8181
}

src/test/java/org/kitteh/irc/client/library/command/AwayCommandTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void testRemoveNull() {
3232
Client client = Mockito.mock(Client.class);
3333

3434
AwayCommand awayCommand = new AwayCommand(client);
35-
awayCommand.message("meow");
36-
awayCommand.message(null);
35+
awayCommand.away("meow");
36+
awayCommand.away(null);
3737
awayCommand.execute();
3838

3939
Mockito.verify(client, Mockito.times(1)).sendRawLine("AWAY");
@@ -47,8 +47,8 @@ public void testNoNewAnymore() {
4747
Client client = Mockito.mock(Client.class);
4848

4949
AwayCommand awayCommand = new AwayCommand(client);
50-
awayCommand.message(MESSAGE);
51-
awayCommand.messageRemove();
50+
awayCommand.away(MESSAGE);
51+
awayCommand.notAway();
5252
awayCommand.execute();
5353

5454
Mockito.verify(client, Mockito.times(1)).sendRawLine("AWAY");
@@ -62,7 +62,7 @@ public void testToString() {
6262
Client client = Mockito.mock(Client.class);
6363

6464
AwayCommand awayCommand = new AwayCommand(client);
65-
awayCommand.message(MESSAGE);
65+
awayCommand.away(MESSAGE);
6666
awayCommand.execute();
6767

6868
Assert.assertTrue(awayCommand.toString().contains(MESSAGE));
@@ -76,7 +76,7 @@ public void testSet() {
7676
Client client = Mockito.mock(Client.class);
7777

7878
AwayCommand awayCommand = new AwayCommand(client);
79-
awayCommand.message(MESSAGE);
79+
awayCommand.away(MESSAGE);
8080
awayCommand.execute();
8181

8282
Mockito.verify(client, Mockito.times(1)).sendRawLine("AWAY :" + MESSAGE);

0 commit comments

Comments
 (0)