Skip to content

Commit 3a0f675

Browse files
committed
Get rid of long constructors
1 parent 8222de4 commit 3a0f675

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

src/main/java/scorekeep/Move.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,53 +21,48 @@ public class Move {
2121
public Move() {
2222
}
2323

24-
public Move(String id, String session, String game, String user, String move) {
25-
this.id = id;
26-
this.session = session;
27-
this.game = game;
28-
this.user = user;
29-
this.move = move;
30-
}
31-
3224
@DynamoDBHashKey(attributeName="id")
3325
public String getId() {
3426
return id;
3527
}
36-
public void setId(String id){
28+
public Move setId(String id){
3729
this.id = id;
30+
return this;
3831
}
3932

4033
@DynamoDBIndexHashKey(globalSecondaryIndexName="game-index",attributeName="game")
4134
public String getGame() {
4235
return game;
4336
}
44-
public void setGame(String gameId){
37+
public Move setGame(String gameId){
4538
this.game = gameId;
39+
return this;
4640
}
4741

4842
@DynamoDBAttribute(attributeName="session")
4943
public String getSession() {
5044
return session;
5145
}
52-
public void setSession(String sessionId) {
46+
public Move setSession(String sessionId) {
5347
this.session = sessionId;
48+
return this;
5449
}
5550

5651
@DynamoDBAttribute(attributeName="user")
5752
public String getUser() {
5853
return user;
5954
}
60-
public void setUser(String userId) {
55+
public Move setUser(String userId) {
6156
this.user = userId;
57+
return this;
6258
}
6359

6460
@DynamoDBAttribute(attributeName="move")
6561
public String getMove() {
6662
return move;
6763
}
68-
public void setMove(String moveId) {
64+
public Move setMove(String moveId) {
6965
this.move = moveId;
66+
return this;
7067
}
71-
72-
7368
}

src/main/java/scorekeep/MoveFactory.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public MoveFactory(){
2424
public Move newMove(String sessionId, String gameId, String userId, String moveText) throws SessionNotFoundException, GameNotFoundException, StateNotFoundException, RulesException {
2525
String moveId = Identifiers.random();
2626
String stateId = Identifiers.random();
27-
Move move = new Move(moveId, sessionId, gameId, userId, moveText);
27+
Move move = new Move().setId(moveId)
28+
.setSession(sessionId)
29+
.setGame(gameId)
30+
.setUser(userId)
31+
.setMove(moveText);
2832
String newStateText = "";
2933
// load game state
3034
Game game = gameController.getGame(sessionId, gameId);

src/main/java/scorekeep/Rules.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,79 @@
22

33
public class Rules {
44

5-
private final String id;
6-
private final String name;
7-
private final String[] categories;
8-
private final Integer[] users;
9-
private final Integer teams;
10-
private final String[] phases;
11-
private final String[] moves;
12-
private final String initialState;
13-
14-
public Rules(String id, String name, String[] categories, Integer[] users, Integer teams, String[] phases, String[] moves, String initialState) {
15-
this.id = id;
16-
this.name = name;
17-
this.categories = categories;
18-
this.users = users;
19-
this.teams = teams;
20-
this.phases = phases;
21-
this.moves = moves;
22-
this.initialState = initialState;
23-
}
5+
private String id;
6+
private String name;
7+
private String[] categories;
8+
private Integer[] users;
9+
private Integer teams;
10+
private String[] phases;
11+
private String[] moves;
12+
private String initialState;
13+
14+
public Rules() {
15+
};
2416

2517
public String getId() {
2618
return id;
2719
}
20+
public Rules setId(String id){
21+
this.id = id;
22+
return this;
23+
}
2824

2925
public String getName() {
3026
return name;
3127
}
28+
public Rules setName(String name){
29+
this.name = name;
30+
return this;
31+
}
3232

3333
public String[] getCategories() {
3434
return categories;
3535
}
36+
public Rules setCategories(String[] categories){
37+
this.categories = categories;
38+
return this;
39+
}
3640

3741
public Integer[] getUsers() {
3842
return users;
3943
}
44+
public Rules setUsers(Integer[] users){
45+
this.users = users;
46+
return this;
47+
}
4048

4149
public Integer getTeams() {
4250
return teams;
4351
}
52+
public Rules setTeams(Integer teams){
53+
this.teams = teams;
54+
return this;
55+
}
4456

4557
public String[] getPhases() {
4658
return phases;
4759
}
60+
public Rules setPhases(String[] phases){
61+
this.phases = phases;
62+
return this;
63+
}
4864

4965
public String[] getMoves() {
5066
return moves;
5167
}
68+
public Rules setMoves(String[] moves){
69+
this.moves = moves;
70+
return this;
71+
}
5272

5373
public String getInitialState() {
5474
return initialState;
5575
}
76+
public Rules setInitialState(String initialState){
77+
this.initialState = initialState;
78+
return this;
79+
}
5680
}

src/main/java/scorekeep/TicTacToe.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ public static Rules getRules() {
1717
String[] phases = { "Move" };
1818
String[] moves = { "Roll" };
1919
String initialState = "X ";
20-
Rules tictactoe = new Rules(id, name, categories, users, teams, phases, moves, initialState);
20+
Rules tictactoe = new Rules().setId(id)
21+
.setName(name)
22+
.setCategories(categories)
23+
.setUsers(users)
24+
.setTeams(teams)
25+
.setPhases(phases)
26+
.setMoves(moves)
27+
.setInitialState(initialState);
2128
return tictactoe;
2229
}
2330
/* State is a string with one character that indicates the current turn

0 commit comments

Comments
 (0)