refactor: fixing codestyle and improving codequality
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package uulm.teamname.marvelous.gamelibrary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Provides various tools for Arrays. */
|
||||
public class ArrayTools {
|
||||
@ -13,9 +14,7 @@ public class ArrayTools {
|
||||
*/
|
||||
public static <E> ArrayList<E> toArrayList(E[] a) {
|
||||
ArrayList<E> l = new ArrayList<>(a.length);
|
||||
for(E e: a) {
|
||||
l.add(e);
|
||||
}
|
||||
l.addAll(Arrays.asList(a));
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,8 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Represents properties of a character in the {@link CharacterConfig} */
|
||||
@JsonPropertyOrder({"characterID", "name", "HP", "MP", "AP", "meleeDamage", "rangeCombatDamage", "rangeCombatReach"})
|
||||
/**
|
||||
* Represents properties of a character in the {@link CharacterConfig}.
|
||||
*/
|
||||
public class CharacterProperties {
|
||||
public int characterID;
|
||||
public String name;
|
||||
|
@ -27,7 +27,7 @@ public class ScenarioConfig {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hash(author, name);
|
||||
result = 31 * result + Arrays.hashCode(scenario);
|
||||
result = 31 * result + Arrays.deepHashCode(scenario);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,7 @@ package uulm.teamname.marvelous.gamelibrary.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonNodeUnwrapper {
|
||||
|
||||
|
@ -55,20 +55,16 @@ public class EntityDeserializer extends JsonDeserializer<Entity> {
|
||||
((Character) result).inventory.addStone(StoneType.valueOf(i));
|
||||
}
|
||||
}
|
||||
case InfinityStone -> {
|
||||
result = new InfinityStone(
|
||||
new EntityID(EntityType.InfinityStones, node.get("ID").asInt()),
|
||||
codec.treeToValue(node.get("position"), IntVector2.class),
|
||||
StoneType.valueOf(node.get("ID").asInt())
|
||||
);
|
||||
}
|
||||
case Rock -> {
|
||||
result = new Rock(
|
||||
new EntityID(EntityType.Rocks, node.get("ID").asInt()),
|
||||
codec.treeToValue(node.get("position"), IntVector2.class),
|
||||
node.get("HP").asInt()
|
||||
);
|
||||
}
|
||||
case InfinityStone -> result = new InfinityStone(
|
||||
new EntityID(EntityType.InfinityStones, node.get("ID").asInt()),
|
||||
codec.treeToValue(node.get("position"), IntVector2.class),
|
||||
StoneType.valueOf(node.get("ID").asInt())
|
||||
);
|
||||
case Rock -> result = new Rock(
|
||||
new EntityID(EntityType.Rocks, node.get("ID").asInt()),
|
||||
codec.treeToValue(node.get("position"), IntVector2.class),
|
||||
node.get("HP").asInt()
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
@ -28,7 +28,7 @@ public class EventDeserializer extends JsonDeserializer<Event> {
|
||||
JsonNode currentNode = null;
|
||||
|
||||
EventBuilder builder;
|
||||
EventType eventType = null;
|
||||
EventType eventType;
|
||||
|
||||
if (!node.has("eventType")) {
|
||||
throw new IOException("Event had wrong format: no EventType found");
|
||||
|
@ -1,12 +1,8 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -15,7 +11,6 @@ public class IntVector2Deserializer extends JsonDeserializer<IntVector2> {
|
||||
@Override
|
||||
public IntVector2 deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
var values = p.readValueAs(Integer[].class);
|
||||
IntVector2 result = new IntVector2(values[0], values[1]);
|
||||
return result;
|
||||
return new IntVector2(values[0], values[1]);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.json.ingame.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
@ -39,7 +38,7 @@ public class RequestDeserializer extends JsonDeserializer<Request> {
|
||||
.withTargetField(unwrap(node.get("targetField"), IntVector2.class, codec))
|
||||
.withStoneType(Optional.ofNullable(unwrap(node.get("stoneType"), EntityID.class, codec))
|
||||
.map(x -> StoneType.valueOf(x.id))
|
||||
.orElseGet(() -> null));
|
||||
.orElse(null));
|
||||
|
||||
switch (requestType) {
|
||||
case DisconnectRequest,
|
||||
|
@ -39,6 +39,7 @@ public class RequestSerializer extends StdSerializer<Request> {
|
||||
}
|
||||
|
||||
/** Method invoked after writing the RequestType, and used to write any additional values required */
|
||||
@SuppressWarnings({"EmptyMethod", "UnnecessaryReturnStatement"})
|
||||
private void serializeGameRequest(GameRequest value, JsonGenerator gen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
return; // does nothing, but still there for consistency
|
||||
|
@ -3,8 +3,6 @@ package uulm.teamname.marvelous.gamelibrary.messages;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonTypeResolver;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -13,7 +11,7 @@ import java.util.Objects;
|
||||
* messageType, as fields that aren't sent are null. Note that most messages are not deserialized into the {@link
|
||||
* BasicMessage}, but instead into messages such as the {@link EventMessage} or {@link GameAssignmentMessage}.
|
||||
*/
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "messageType")
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "messageType")
|
||||
@JsonSubTypes({
|
||||
@Type(value = HelloClientMessage.class, name = "HELLO_CLIENT"),
|
||||
@Type(value = HelloServerMessage.class, name = "HELLO_SERVER"),
|
||||
|
@ -1,7 +1,6 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.messages;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.messages;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -6,7 +6,6 @@ import uulm.teamname.marvelous.gamelibrary.config.CharacterProperties;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
||||
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
Reference in New Issue
Block a user