Improve poor/legacy code.

This commit is contained in:
Ryley Kimmel
2015-03-04 15:51:07 -05:00
parent 76b5f6deb5
commit 500c513e28
13 changed files with 13 additions and 26 deletions
+1 -3
View File
@@ -176,9 +176,7 @@ public final class IndexedFileSystem implements Closeable {
int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF; int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF;
int nextType = header[7] & 0xFF; int nextType = header[7] & 0xFF;
if (i != curChunk) { Preconditions.checkArgument(i == curChunk, "Chunk id mismatch.");
Preconditions.checkArgument(i == curChunk, "Chunk id mismatch.");
}
int chunkSize = size - read; int chunkSize = size - read;
if (chunkSize > FileSystemConstants.CHUNK_SIZE) { if (chunkSize > FileSystemConstants.CHUNK_SIZE) {
@@ -124,8 +124,6 @@ public final class ObjectDefinitionDecoder {
definition.setObstructive(true); definition.setObstructive(true);
} else if (opcode == 75) { } else if (opcode == 75) {
data.get(); data.get();
} else {
continue;
} }
} }
} }
@@ -23,7 +23,7 @@ public final class BankMessageHandler extends MessageHandler<ItemActionMessage>
* @return The amount. * @return The amount.
* @throws IllegalArgumentException If the option is invalid. * @throws IllegalArgumentException If the option is invalid.
*/ */
private static final int optionToAmount(int option) { private static int optionToAmount(int option) {
switch (option) { switch (option) {
case 1: case 1:
return 1; return 1;
@@ -161,8 +161,7 @@ public final class CollisionMatrix {
@Override @Override
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)) return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)).toString();
.toString();
} }
/** /**
@@ -89,8 +89,7 @@ public final class GameObject extends Entity {
@Override @Override
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this).add("id", getId()).add("type", getType()).add("orientation", getOrientation()) return MoreObjects.toStringHelper(this).add("id", getId()).add("type", getType()).add("orientation", getOrientation()).toString();
.toString();
} }
} }
@@ -209,7 +209,7 @@ public final class SkillSet {
* @return The total level. * @return The total level.
*/ */
public int getTotalLevel() { public int getTotalLevel() {
return Arrays.stream(skills).map(skill -> skill.getMaximumLevel()).reduce(0, (total, level) -> total + level); return Arrays.stream(skills).map(Skill::getMaximumLevel).reduce(0, (total, level) -> total + level);
} }
/** /**
@@ -121,9 +121,7 @@ public final class WalkingQueue {
points.clear(); points.clear();
oldPoints.clear(); oldPoints.clear();
for (Position travelBackPosition : travelBackQueue) { travelBackQueue.forEach(this::addStep);
addStep(travelBackPosition);
}
addStep(clientPosition); addStep(clientPosition);
return true; return true;
@@ -15,7 +15,7 @@ public final class NumericalAttribute extends Attribute<Number> {
* @param value The value of this attribute. * @param value The value of this attribute.
* @return The type. * @return The type.
*/ */
private static final AttributeType typeOf(Number value) { private static AttributeType typeOf(Number value) {
return value instanceof Double ? AttributeType.DOUBLE : AttributeType.LONG; return value instanceof Double ? AttributeType.DOUBLE : AttributeType.LONG;
} }
@@ -24,7 +24,7 @@ public final class EventListenerChainSet {
public <E extends Event> boolean notify(E event) { public <E extends Event> boolean notify(E event) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
EventListenerChain<E> chain = (EventListenerChain<E>) chains.get(event.getClass()); EventListenerChain<E> chain = (EventListenerChain<E>) chains.get(event.getClass());
return (chain == null) ? true : chain.notify(event); return (chain == null) || chain.notify(event);
} }
/** /**
@@ -79,10 +79,7 @@ public final class InterfaceSet {
* @return {@code true} if the message handler chain should be broken. * @return {@code true} if the message handler chain should be broken.
*/ */
public boolean buttonClicked(int button) { public boolean buttonClicked(int button) {
if (dialogueListener.isPresent()) { return dialogueListener.isPresent() && dialogueListener.get().buttonClicked(button);
return dialogueListener.get().buttonClicked(button);
}
return false;
} }
/** /**
@@ -33,8 +33,7 @@ public final class PlayerLoaderResponse {
* {@link LoginConstants#STATUS_RECONNECTION_OK}. * {@link LoginConstants#STATUS_RECONNECTION_OK}.
*/ */
public PlayerLoaderResponse(int status) { public PlayerLoaderResponse(int status) {
Preconditions.checkArgument(status != LoginConstants.STATUS_OK && status != LoginConstants.STATUS_RECONNECTION_OK, Preconditions.checkArgument(status != LoginConstants.STATUS_OK && status != LoginConstants.STATUS_RECONNECTION_OK, "Player required for this status code.");
"Player required for this status code.");
this.status = status; this.status = status;
player = Optional.empty(); player = Optional.empty();
} }
@@ -48,8 +47,7 @@ public final class PlayerLoaderResponse {
* @throws NullPointerException If the specified player is null. * @throws NullPointerException If the specified player is null.
*/ */
public PlayerLoaderResponse(int status, Player player) { public PlayerLoaderResponse(int status, Player player) {
Preconditions.checkArgument(status == LoginConstants.STATUS_OK || status == LoginConstants.STATUS_RECONNECTION_OK, Preconditions.checkArgument(status == LoginConstants.STATUS_OK || status == LoginConstants.STATUS_RECONNECTION_OK, "Player not required for this status code.");
"Player not required for this status code.");
this.status = status; this.status = status;
this.player = Optional.of(player); this.player = Optional.of(player);
} }
@@ -32,7 +32,7 @@ public final class PrivateChatMessageDecoder extends MessageDecoder<PrivateChatM
byte[] recompressed = new byte[length]; byte[] recompressed = new byte[length];
TextUtil.compress(decompressed, recompressed); TextUtil.compress(decompressed, recompressed);
return new PrivateChatMessage(username, new String(decompressed), recompressed); return new PrivateChatMessage(username, decompressed, recompressed);
} }
} }