Skip to content

Commit d58b63e

Browse files
committed
Replace some classes with records
1 parent fff4f0f commit d58b63e

File tree

4 files changed

+10
-56
lines changed

4 files changed

+10
-56
lines changed

src/main/java/oakbot/command/define/DefineCommand.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ public ChatActions onMessage(ChatCommand chatCommand, IBot bot) {
8888

8989
var cb = new ChatBuilder();
9090
for (var definition : definitions) {
91-
cb.append(word).append(" (").append(definition.getWordType()).append("):").nl();
92-
cb.append(definition.getDefinition());
93-
var example = definition.getExample();
91+
cb.append(word).append(" (").append(definition.wordType()).append("):").nl();
92+
cb.append(definition.definition());
93+
var example = definition.example();
9494
if (example != null) {
95-
cb.append(" (").append(definition.getExample()).append(")");
95+
cb.append(" (").append(definition.example()).append(")");
9696
}
9797
cb.nl().nl();
9898
}
@@ -133,11 +133,7 @@ private List<Definition> parseResponse(String word, Leaf response) {
133133
continue;
134134
}
135135

136-
Definition definition = new Definition();
137-
definition.setWordType(type);
138-
definition.setDefinition(definitionText);
139-
definition.setExample(getExample(dtNode));
140-
136+
var definition = new Definition(type, definitionText, getExample(dtNode));
141137
definitions.add(definition);
142138
}
143139
}

src/main/java/oakbot/command/define/Definition.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,5 @@
44
* A dictionary definition for a word.
55
* @author Michael Angstadt
66
*/
7-
public class Definition {
8-
private String wordType;
9-
private String definition;
10-
private String example;
11-
12-
public String getWordType() {
13-
return wordType;
14-
}
15-
16-
public void setWordType(String wordType) {
17-
this.wordType = wordType;
18-
}
19-
20-
public String getDefinition() {
21-
return definition;
22-
}
23-
24-
public void setDefinition(String definition) {
25-
this.definition = definition;
26-
}
27-
28-
public String getExample() {
29-
return example;
30-
}
31-
32-
public void setExample(String example) {
33-
this.example = example;
34-
}
7+
public record Definition(String wordType, String definition, String example) {
358
}

src/main/java/oakbot/command/stands4/ExplainCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public ChatActions onMessage(ChatCommand chatCommand, IBot bot) {
6060
if (result == null) {
6161
cb.append("No explanation found.");
6262
} else {
63-
cb.append(result.getExplanation());
63+
cb.append(result.explanation());
6464

65-
var example = result.getExample();
65+
var example = result.example();
6666
if (example != null) {
67-
cb.append(" ").italic(result.getExample());
67+
cb.append(" ").italic(result.example());
6868
}
6969
}
7070

src/main/java/oakbot/command/stands4/Explanation.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,5 @@
55
* @author Michael Angstadt
66
* @see Stands4Client#explain
77
*/
8-
public class Explanation {
9-
private final String explanation;
10-
private final String example;
11-
12-
public Explanation(String explanation, String example) {
13-
this.explanation = explanation;
14-
this.example = example;
15-
}
16-
17-
public String getExplanation() {
18-
return explanation;
19-
}
20-
21-
public String getExample() {
22-
return example;
23-
}
8+
public record Explanation(String explanation, String example) {
249
}

0 commit comments

Comments
 (0)