From b8cafdd1c70b3fbb455ee6821c3dd0e5dc587188 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 4 May 2014 18:10:35 +0200 Subject: Use lombok and clean up --- .../wordpress/tipsforjava/swing/StretchIcon.java | 5 ++ src/esieequest/controller/Input.java | 17 +---- src/esieequest/controller/commands/Executable.java | 2 +- .../controller/utils/SerialisableObject.java | 5 +- src/esieequest/controller/utils/package-info.java | 1 + src/esieequest/model/Game.java | 21 ++----- src/esieequest/model/Player.java | 73 +++------------------- .../model/characters/MovingCharacter.java | 47 +------------- .../model/characters/SimpleCharacter.java | 9 +-- src/esieequest/model/doors/Door.java | 23 +------ src/esieequest/model/doors/LockedDoor.java | 21 +------ src/esieequest/model/items/SimpleItem.java | 31 ++------- src/esieequest/model/map/Side.java | 61 ++++-------------- src/esieequest/view/Viewable.java | 10 +-- src/esieequest/view/web/WebInterface.java | 2 +- src/org/json/simple/JSONStreamAware.java | 2 +- src/org/json/simple/parser/ContentHandler.java | 4 +- src/org/json/simple/parser/Yylex.java | 4 +- src/rejava/io/Writer.java | 4 +- 19 files changed, 62 insertions(+), 280 deletions(-) (limited to 'src') diff --git a/src/com/wordpress/tipsforjava/swing/StretchIcon.java b/src/com/wordpress/tipsforjava/swing/StretchIcon.java index d41bbfe..7c7181f 100644 --- a/src/com/wordpress/tipsforjava/swing/StretchIcon.java +++ b/src/com/wordpress/tipsforjava/swing/StretchIcon.java @@ -30,6 +30,11 @@ import javax.swing.ImageIcon; */ public class StretchIcon extends ImageIcon { + /** + * + */ + private static final long serialVersionUID = 6948448082634127156L; + /** * Determines whether the aspect ratio of the image is maintained. Set to * false to distort the image to fill the component. diff --git a/src/esieequest/controller/Input.java b/src/esieequest/controller/Input.java index 4b4ada5..784985e 100644 --- a/src/esieequest/controller/Input.java +++ b/src/esieequest/controller/Input.java @@ -1,5 +1,6 @@ package esieequest.controller; +import lombok.Getter; import esieequest.controller.commands.Command; /** @@ -9,7 +10,9 @@ import esieequest.controller.commands.Command; */ public class Input { + @Getter private Command command; + @Getter private final String argument; /** @@ -42,18 +45,4 @@ public class Input { } } - /** - * @return the command - */ - public Command getCommand() { - return this.command; - } - - /** - * @return the argument - */ - public String getArgument() { - return this.argument; - } - } diff --git a/src/esieequest/controller/commands/Executable.java b/src/esieequest/controller/commands/Executable.java index 36ec6be..156fc1c 100644 --- a/src/esieequest/controller/commands/Executable.java +++ b/src/esieequest/controller/commands/Executable.java @@ -20,6 +20,6 @@ public interface Executable { * @param view * the View */ - public void execute(String argument, Game game, Viewable view); + public void execute(final String argument, final Game game, final Viewable view); } diff --git a/src/esieequest/controller/utils/SerialisableObject.java b/src/esieequest/controller/utils/SerialisableObject.java index 30b9c19..334f408 100644 --- a/src/esieequest/controller/utils/SerialisableObject.java +++ b/src/esieequest/controller/utils/SerialisableObject.java @@ -19,8 +19,9 @@ public interface SerialisableObject { /** * Deserialises from a JSONObject. * - * @param o the JSONObject + * @param o + * the JSONObject */ - public void deserialise(JSONObject o); + public void deserialise(final JSONObject o); } diff --git a/src/esieequest/controller/utils/package-info.java b/src/esieequest/controller/utils/package-info.java index 088a127..2e6d871 100644 --- a/src/esieequest/controller/utils/package-info.java +++ b/src/esieequest/controller/utils/package-info.java @@ -2,3 +2,4 @@ * A general utility package. */ package esieequest.controller.utils; + diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 7f124e7..05fdcd2 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java @@ -1,5 +1,7 @@ package esieequest.model; +import lombok.Getter; +import lombok.Setter; import net.pacien.util.CleanJSONObject; import org.json.simple.JSONArray; @@ -33,6 +35,8 @@ public class Game implements SerialisableObject { private final boolean challenge; private static final String PLAYER_LABEL = "P"; + @Getter + @Setter private Player player; private static final String ROOMS_LABEL = "R"; @@ -71,23 +75,6 @@ public class Game implements SerialisableObject { } } - /** - * @return the player - */ - public Player getPlayer() { - return this.player; - } - - /** - * Sets the player - * - * @param player - * the Player to set - */ - public void setPlayer(final Player player) { - this.player = player; - } - /** * Connects Room-s together using Door-s. */ diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index 371de84..68930e2 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -3,6 +3,8 @@ package esieequest.model; import java.util.ArrayList; import java.util.Stack; +import lombok.Getter; +import lombok.Setter; import net.pacien.util.CleanJSONObject; import net.pacien.util.IntrinsicMap; @@ -26,18 +28,23 @@ import esieequest.model.map.Side; public class Player implements SerialisableObject { private static final String CURRENT_ROOM_LABEL = "R"; + @Getter + @Setter private Room currentRoom; private static final String PREVIOUS_ROOMS_LABEL = "H"; private final Stack previousRooms; private static final String CURRENT_DIRECTION_LABEL = "D"; + @Getter + @Setter private Direction currentDirection; private static final String ITEMS_LABEL = "I"; private final IntrinsicMap items; private static final String INVENTORY_WEIGHT_LIMIT_LABEL = "W"; + @Getter private int inventoryWeightLimit; private static final String NB_STEPS_LABEL = "S"; @@ -69,72 +76,6 @@ public class Player implements SerialisableObject { this.nbStepsLimit = nbStepsLimit; } - /** - * @return the current Room - */ - public Room getCurrentRoom() { - return this.currentRoom; - } - - /** - * @param currentRoom - * the current Room to set - */ - public void setCurrentRoom(final Room currentRoom) { - this.currentRoom = currentRoom; - } - - /** - * @return the previous Rooms Stack - */ - public Stack getPreviousRooms() { - return this.previousRooms; - } - - /** - * @return the current Direction - */ - public Direction getCurrentDirection() { - return this.currentDirection; - } - - /** - * @param currentDirection - * the current Direction to set - */ - public void setCurrentDirection(final Direction currentDirection) { - this.currentDirection = currentDirection; - } - - /** - * @return the inventory weight limit - */ - public int getInventoryWeightLimit() { - return this.inventoryWeightLimit; - } - - /** - * @return the number of steps - */ - public int getNbSteps() { - return this.nbSteps; - } - - /** - * @param nbSteps - * the number of steps to set - */ - public void setNbSteps(final int nbSteps) { - this.nbSteps = nbSteps; - } - - /** - * @return the maximum number of steps - */ - public int getNbStepsLimit() { - return this.nbStepsLimit; - } - /** * Sets the current room and stacks previous rooms. * diff --git a/src/esieequest/model/characters/MovingCharacter.java b/src/esieequest/model/characters/MovingCharacter.java index b8b3acb..4ac73e4 100644 --- a/src/esieequest/model/characters/MovingCharacter.java +++ b/src/esieequest/model/characters/MovingCharacter.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import lombok.Setter; import net.pacien.util.CleanJSONObject; import org.json.simple.JSONObject; @@ -40,6 +41,7 @@ public abstract class MovingCharacter extends SimpleCharacter { private Direction currentDirection; private static final String CAN_MOVE_LABEL = "M"; + @Setter private boolean canMove; /** @@ -61,51 +63,6 @@ public abstract class MovingCharacter extends SimpleCharacter { this.canMove = false; } - /** - * @return the current Room - */ - public Room getCurrentRoom() { - return this.currentRoom; - } - - /** - * @param currentRoom - * the current Room to set - */ - public void setCurrentRoom(final Room currentRoom) { - this.currentRoom = currentRoom; - } - - /** - * @return the current Direction - */ - public Direction getCurrentDirection() { - return this.currentDirection; - } - - /** - * @param currentDirection - * the current Direction to set - */ - public void setCurrentDirection(final Direction currentDirection) { - this.currentDirection = currentDirection; - } - - /** - * @return if the MovingCharacter is allowed to move - */ - public boolean canMove() { - return this.canMove; - } - - /** - * @param canMove - * the right for the MovingCharacter to move to set - */ - public void setCanMove(final boolean canMove) { - this.canMove = canMove; - } - /** * Moves the MovingCharacter to a randomly chosen adjacent Room, if he can * move and if the destination Room is not currently occupied by another diff --git a/src/esieequest/model/characters/SimpleCharacter.java b/src/esieequest/model/characters/SimpleCharacter.java index f81bf8b..b855089 100644 --- a/src/esieequest/model/characters/SimpleCharacter.java +++ b/src/esieequest/model/characters/SimpleCharacter.java @@ -1,5 +1,6 @@ package esieequest.model.characters; +import lombok.Getter; import net.pacien.util.CleanJSONObject; import org.json.simple.JSONObject; @@ -13,6 +14,7 @@ import esieequest.controller.utils.SerialisableObject; */ public abstract class SimpleCharacter implements SerialisableObject { + @Getter private final String name; /** @@ -32,13 +34,6 @@ public abstract class SimpleCharacter implements SerialisableObject { */ public abstract String talk(); - /** - * @return the name of the Character - */ - public String getName() { - return this.name; - } - @Override public JSONObject serialise() { return new CleanJSONObject(); diff --git a/src/esieequest/model/doors/Door.java b/src/esieequest/model/doors/Door.java index 9b67cda..67f3ca1 100644 --- a/src/esieequest/model/doors/Door.java +++ b/src/esieequest/model/doors/Door.java @@ -1,5 +1,6 @@ package esieequest.model.doors; +import lombok.Getter; import esieequest.model.Game; import esieequest.model.map.Room; import esieequest.view.Viewable; @@ -11,7 +12,8 @@ import esieequest.view.Viewable; */ public class Door { - private Room destination; + @Getter + private final Room destination; /** * Creates a new Door. @@ -23,25 +25,6 @@ public class Door { this.destination = destination; } - /** - * Returns the destination Room. - * - * @return the destination Room - */ - public Room getDestination() { - return this.destination; - } - - /** - * Sets the destination room. - * - * @param destination - * the destination room - */ - public void setDestination(final Room destination) { - this.destination = destination; - } - /** * Makes the Player cross the Door. * diff --git a/src/esieequest/model/doors/LockedDoor.java b/src/esieequest/model/doors/LockedDoor.java index 49f61be..20a453e 100644 --- a/src/esieequest/model/doors/LockedDoor.java +++ b/src/esieequest/model/doors/LockedDoor.java @@ -1,5 +1,6 @@ package esieequest.model.doors; +import lombok.Setter; import esieequest.model.Game; import esieequest.model.Player; import esieequest.model.Text; @@ -15,6 +16,7 @@ import esieequest.view.Viewable; */ public class LockedDoor extends Door { + @Setter private Item key; /** @@ -27,25 +29,6 @@ public class LockedDoor extends Door { super(destination); } - /** - * Returns the KeyCard that opens this door. - * - * @return the KeyCard - */ - public Item getKey() { - return this.key; - } - - /** - * Sets the KeyCard authorised to open this door. - * - * @param key - * the KeyCard to set - */ - public void setKey(final Item key) { - this.key = key; - } - @Override public boolean cross(final Game game, final Viewable view) { if (!this.isAuthorised(game.getPlayer())) { diff --git a/src/esieequest/model/items/SimpleItem.java b/src/esieequest/model/items/SimpleItem.java index d0ff387..e33820f 100644 --- a/src/esieequest/model/items/SimpleItem.java +++ b/src/esieequest/model/items/SimpleItem.java @@ -1,5 +1,6 @@ package esieequest.model.items; +import lombok.Getter; import net.pacien.util.CleanJSONObject; import org.json.simple.JSONObject; @@ -17,8 +18,11 @@ import esieequest.view.Viewable; */ public class SimpleItem implements SerialisableObject { + @Getter private final String name; + @Getter private final int weight; + @Getter private final boolean droppable; /** @@ -49,33 +53,6 @@ public class SimpleItem implements SerialisableObject { this(name, 0, droppable); } - /** - * Returns the description of the item. - * - * @return the description - */ - public String getName() { - return this.name; - } - - /** - * Returns the weight of the item. - * - * @return the weight - */ - public int getWeight() { - return this.weight; - } - - /** - * Tells whether the item is droppable. - * - * @return the droppability of the item. - */ - public boolean isDroppable() { - return this.droppable; - } - /** * Performs actions when the player uses the Item. * diff --git a/src/esieequest/model/map/Side.java b/src/esieequest/model/map/Side.java index 7d85b8d..9b3a489 100644 --- a/src/esieequest/model/map/Side.java +++ b/src/esieequest/model/map/Side.java @@ -1,5 +1,7 @@ package esieequest.model.map; +import lombok.Getter; +import lombok.Setter; import net.pacien.util.CleanJSONObject; import org.json.simple.JSONObject; @@ -17,12 +19,18 @@ import esieequest.model.items.Item; */ public class Side implements SerialisableObject { + @Getter + @Setter private Door door; private static final String ITEM_LABEL = "I"; + @Getter + @Setter private Item item; private static final String CHARACTER_LABEL = "C"; + @Getter + @Setter private Character character; private Side(final Door door, final Item item, final Character character) { @@ -35,51 +43,6 @@ public class Side implements SerialisableObject { this(null, null, null); } - /** - * @param door - * the door to set - */ - public void setDoor(final Door door) { - this.door = door; - } - - /** - * @return the door - */ - public Door getDoor() { - return this.door; - } - - /** - * @return the item - */ - public Item getItem() { - return this.item; - } - - /** - * @param item - * the item to set - */ - public void setItem(final Item item) { - this.item = item; - } - - /** - * @return the character - */ - public Character getCharacter() { - return this.character; - } - - /** - * @param character - * the character to set - */ - public void setCharacter(final Character character) { - this.character = character; - } - /** * @return if the Side has a Door */ @@ -115,10 +78,10 @@ public class Side implements SerialisableObject { * @param item * the Item to put */ - public void putItem(final Item item) { - if (!this.hasItem()) { - this.item = item; - } + public Item putItem(final Item item) { + final Item previousItem = this.item; + this.item = item; + return previousItem; } @Override diff --git a/src/esieequest/view/Viewable.java b/src/esieequest/view/Viewable.java index 5d2675f..d2aeaff 100644 --- a/src/esieequest/view/Viewable.java +++ b/src/esieequest/view/Viewable.java @@ -22,7 +22,7 @@ public interface Viewable { * @param gameEngine * the GameEngine controller */ - public void setController(GameEngine gameEngine); + public void setController(final GameEngine gameEngine); /** * Displays the user interface. @@ -40,7 +40,7 @@ public interface Viewable { * @param message * the message */ - public void echo(String message); + public void echo(final String message); /** * Disables the user interface. @@ -57,7 +57,7 @@ public interface Viewable { * @param side * the side of a room */ - public void updateLocation(Room room, Direction direction, Side side); + public void updateLocation(final Room room, final Direction direction, final Side side); /** * Updates the view to match the current quest. @@ -65,7 +65,7 @@ public interface Viewable { * @param quest * the current quest to display */ - public void updateQuest(Quest quest); + public void updateQuest(final Quest quest); /** * Updates the view to display the items contained in the inventory @@ -73,6 +73,6 @@ public interface Viewable { * @param items * the items */ - public void updateInventory(HashMap items); + public void updateInventory(final HashMap items); } diff --git a/src/esieequest/view/web/WebInterface.java b/src/esieequest/view/web/WebInterface.java index 69f3c4e..9ac7846 100644 --- a/src/esieequest/view/web/WebInterface.java +++ b/src/esieequest/view/web/WebInterface.java @@ -143,7 +143,7 @@ class WebInterface extends Composite implements Viewable { Event.addNativePreviewHandler(new NativePreviewHandler() { @Override public void onPreviewNativeEvent(final NativePreviewEvent event) { - //final int key = event.getNativeEvent().getKeyCode(); + // final int key = event.getNativeEvent().getKeyCode(); } }); } diff --git a/src/org/json/simple/JSONStreamAware.java b/src/org/json/simple/JSONStreamAware.java index 561634d..c0420fb 100644 --- a/src/org/json/simple/JSONStreamAware.java +++ b/src/org/json/simple/JSONStreamAware.java @@ -14,5 +14,5 @@ public interface JSONStreamAware { /** * write JSON string to out. */ - void writeJSONString(Writer out) throws IOException; + void writeJSONString(final Writer out) throws IOException; } diff --git a/src/org/json/simple/parser/ContentHandler.java b/src/org/json/simple/parser/ContentHandler.java index a704485..5ed233d 100644 --- a/src/org/json/simple/parser/ContentHandler.java +++ b/src/org/json/simple/parser/ContentHandler.java @@ -62,7 +62,7 @@ public interface ContentHandler { * * @see #endObjectEntry */ - boolean startObjectEntry(String key) throws ParseException, IOException; + boolean startObjectEntry(final String key) throws ParseException, IOException; /** * Receive notification of the end of the value of previous object entry. @@ -105,6 +105,6 @@ public interface ContentHandler { * @return false if the handler wants to stop parsing after return. * @throws ParseException */ - boolean primitive(Object value) throws ParseException, IOException; + boolean primitive(final Object value) throws ParseException, IOException; } diff --git a/src/org/json/simple/parser/Yylex.java b/src/org/json/simple/parser/Yylex.java index 1ccf1b4..10049c4 100644 --- a/src/org/json/simple/parser/Yylex.java +++ b/src/org/json/simple/parser/Yylex.java @@ -304,11 +304,11 @@ class Yylex { */ public final void yyreset(final rejava.io.Reader reader) { this.zzReader = reader; - //this.zzAtBOL = true; + // this.zzAtBOL = true; this.zzAtEOF = false; this.zzEndRead = this.zzStartRead = 0; this.zzCurrentPos = this.zzMarkedPos = 0; - //this.yyline = this.yychar = this.yycolumn = 0; + // this.yyline = this.yychar = this.yycolumn = 0; this.zzLexicalState = Yylex.YYINITIAL; } diff --git a/src/rejava/io/Writer.java b/src/rejava/io/Writer.java index 469924b..6774839 100644 --- a/src/rejava/io/Writer.java +++ b/src/rejava/io/Writer.java @@ -9,8 +9,8 @@ package rejava.io; */ public abstract class Writer { - public abstract void write(String str); + public abstract void write(final String str); - public abstract void write(char c); + public abstract void write(final char c); } \ No newline at end of file -- cgit v1.2.3