-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #134 : Switch mpgstats API to new mlnstats API
- Loading branch information
Showing
16 changed files
with
95,239 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/org/blondin/mpg/root/model/StatsDayOrPositionPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
package org.blondin.mpg.root.model; | ||
|
||
import java.util.Map; | ||
|
||
import org.blondin.mpg.stats.model.Position; | ||
import org.blondin.mpg.stats.model.StatsDay; | ||
|
||
public class StatsDayOrPositionPlayer { | ||
|
||
private Map<Integer, StatsDay> statsDay; | ||
private Position position; | ||
|
||
public Map<Integer, StatsDay> getStatsDay() { | ||
return statsDay; | ||
} | ||
|
||
public void setStatsDay(Map<Integer, StatsDay> statsDay) { | ||
this.statsDay = statsDay; | ||
} | ||
|
||
public Position getPosition() { | ||
return position; | ||
} | ||
|
||
public void setPosition(Position position) { | ||
this.position = position; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/blondin/mpg/stats/io/ListPlayerDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.blondin.mpg.stats.io; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.blondin.mpg.stats.model.Player; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
|
||
public class ListPlayerDeserializer extends StdDeserializer<List<Player>> { | ||
|
||
private static final long serialVersionUID = -7012195953299512960L; | ||
|
||
public ListPlayerDeserializer() { | ||
this(List.class); | ||
} | ||
|
||
protected ListPlayerDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@Override | ||
public List<Player> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
ObjectMapper mapper = (ObjectMapper) jp.getCodec(); | ||
JsonNode root = mapper.readTree(jp); | ||
if (root.get(0) instanceof ArrayNode) { | ||
List<Player> list = new ArrayList<>(); | ||
for (JsonNode node : root) { | ||
list.add(mapper.readValue(node.get(1).traverse(), Player.class)); | ||
} | ||
return list; | ||
} | ||
return Arrays.asList(mapper.readValue(root.traverse(), Player[].class)); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/blondin/mpg/stats/io/StatsDayOrPositionPlayerDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.blondin.mpg.stats.io; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.blondin.mpg.root.model.StatsDayOrPositionPlayer; | ||
import org.blondin.mpg.stats.model.Position; | ||
import org.blondin.mpg.stats.model.StatsDay; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
public class StatsDayOrPositionPlayerDeserializer extends StdDeserializer<StatsDayOrPositionPlayer> { | ||
|
||
private static final long serialVersionUID = -3878716532565320657L; | ||
|
||
public StatsDayOrPositionPlayerDeserializer() { | ||
this(StatsDayOrPositionPlayer.class); | ||
} | ||
|
||
protected StatsDayOrPositionPlayerDeserializer(Class<?> vc) { | ||
super(vc); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public StatsDayOrPositionPlayer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
Object o = ctxt.readValue(jp, Object.class); | ||
StatsDayOrPositionPlayer sop = new StatsDayOrPositionPlayer(); | ||
if (o instanceof String) { | ||
sop.setPosition(Position.getNameByValue((String) o)); | ||
} else if (o instanceof ArrayList<?>) { | ||
Map<Integer, StatsDay> statsDay = new HashMap<>(); | ||
for (ArrayList<?> e : (ArrayList<ArrayList<?>>) o) { | ||
Integer day = (Integer) e.get(0); | ||
Map<String, Object> values = (Map<String, Object>) e.get(1); | ||
statsDay.put(day, new StatsDay(Double.valueOf(ObjectUtils.defaultIfNull(values.get("n"), 0).toString()), | ||
Integer.valueOf(ObjectUtils.defaultIfNull(values.get("g"), 0).toString()))); | ||
} | ||
sop.setStatsDay(statsDay); | ||
} else { | ||
throw new UnsupportedOperationException("Object is not a 'Position' or 'StatsDay' array"); | ||
} | ||
return sop; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.