Skip to content

Commit

Permalink
Use LinkedHashMap over TreeMap everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
stelar7 committed Sep 17, 2022
1 parent 87c01e7 commit 8d2d9a2
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void store(URLEndpoint type, Map<String, Object> obj)
}

// inject api key so cache still works in v4
vals.add(0, DataCall.getCredentials() == null ? "STATIC_DATA" : DataCall.getCredentials().getUniqueKeyCombination());
vals.add(DataCall.getCredentials() == null ? "STATIC_DATA" : DataCall.getCredentials().getUniqueKeyCombination());

Path storePath = resolvePath(type, vals);
Files.createDirectories(storePath.getParent());
Expand Down Expand Up @@ -125,7 +125,6 @@ private Path resolvePath(URLEndpoint type, List<Object> obj)
Path storePath = home.resolve(type.toString());

List<Object> pathData = new ArrayList<>(obj);
Collections.reverse(pathData);

for (Object datum : pathData)
{
Expand Down Expand Up @@ -155,7 +154,7 @@ public void update(URLEndpoint type, Map<String, Object> obj)
return;
}

vals.add(0, DataCall.getCredentials().getUniqueKeyCombination());
vals.add(DataCall.getCredentials().getUniqueKeyCombination());

Path storePath = resolvePath(type, vals);
if (Files.exists(storePath))
Expand All @@ -177,7 +176,7 @@ public Optional<?> get(URLEndpoint type, Map<String, Object> obj)
List<Object> vals = new ArrayList<>(obj.values());

// inject api key so cache still works in v4
vals.add(0, DataCall.getCredentials() == null ? "STATIC_DATA" : DataCall.getCredentials().getUniqueKeyCombination());
vals.add(DataCall.getCredentials() == null ? "STATIC_DATA" : DataCall.getCredentials().getUniqueKeyCombination());
Path filepath = resolvePath(type, vals);

try
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/no/stelar7/api/r4j/basic/calling/DataCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public final class DataCall
private static long maxSleep = 10000;
private static int globalTimeout = 0;

private final Map<String, String> urlParams = new TreeMap<>();
private final Map<String, String> urlData = new TreeMap<>();
private final Map<String, String> urlHeaders = new TreeMap<>();
private final Map<String, String> urlParams = new LinkedHashMap<>();
private final Map<String, String> urlData = new LinkedHashMap<>();
private final Map<String, String> urlHeaders = new LinkedHashMap<>();

private Enum platform;
private URLEndpoint endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ChampionRotationInfo getFreeToPlayRotation()
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", this.platform);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Integer getMasteryScore()
.withEndpoint(URLEndpoint.V4_MASTERY_SCORE)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", this.platform);
data.put("id", summonerId);

Expand Down Expand Up @@ -96,7 +96,7 @@ public List<ChampionMastery> getChampionMasteries()
.withEndpoint(URLEndpoint.V4_MASTERY_BY_ID)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", summonerId);

Expand Down Expand Up @@ -149,7 +149,7 @@ public ChampionMastery getChampionMastery()
.withEndpoint(URLEndpoint.V4_MASTERY_BY_CHAMPION)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", summonerId);
data.put("champion", championId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<LeagueEntry> getLeagueEntries()
.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, this.summonerId)
.withEndpoint(URLEndpoint.V4_LEAGUE_ENTRY)
.withPlatform(this.platform);
Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", summonerId);

Expand Down Expand Up @@ -112,7 +112,7 @@ public LeagueList getLeague()
.withEndpoint(URLEndpoint.V4_LEAGUE)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", leagueId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public GAMHSMatch getMatchRAW()
.withEndpoint(URLEndpoint.V5_MATCH)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", this.platform);
data.put("gameid", this.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<String> get()
builder.withQueryParameter(Constants.ENDTIME_PLACEHOLDER_DATA, String.valueOf(this.endTime));
}

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("puuid", puuid);
data.put("queue", queue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public GAMHSMatch getTimelineRAW()
.withEndpoint(URLEndpoint.V5_TIMELINE)
.withPlatform(this.platform);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("matchId", this.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<SpectatorGameInfo> getFeaturedGames()
return Collections.emptyList();
}

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V4_SPECTATOR_FEATURED, data);
Expand Down Expand Up @@ -82,7 +82,7 @@ public SpectatorGameInfo getCurrentGame()
return null;
}

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);
data.put("id", this.summonerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Summoner get()
URLEndpoint endpoint = null;


Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", platform);

if (accId.length() > 0)
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/no/stelar7/api/r4j/impl/lol/raw/ChallengeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ChallengeConfigInfoList getChallengesList(LeagueShard server)
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V1_CHALLENGES_CONFIG)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_CHALLENGES_CONFIG, data);
Expand Down Expand Up @@ -55,7 +55,7 @@ public MultiChallengePercentileMap getAllChallengePercentiles(LeagueShard server
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V1_CHALLENGES_PERCENTILES)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_CHALLENGES_PERCENTILES, data);
Expand Down Expand Up @@ -84,7 +84,7 @@ public ChallengeConfigInfo getChallengeInfo(LeagueShard server, Long challengeId
.withURLParameter(Constants.CHALLENGE_ID_PLACEHOLDER, String.valueOf(challengeId))
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("challenge", challengeId);

Expand Down Expand Up @@ -120,7 +120,7 @@ public ChallengeLeaderboardInfoList getChallengeLeaderboard(LeagueShard server,
builder = builder.withQueryParameter(Constants.LIMIT_PLACEHOLDER_DATA, String.valueOf(limit));
}

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("challenge", challengeId);
data.put("level", level);
Expand Down Expand Up @@ -152,7 +152,7 @@ public MultiChallengePercentileMap getChallengePercentiles(LeagueShard server, L
.withURLParameter(Constants.CHALLENGE_ID_PLACEHOLDER, String.valueOf(challengeId))
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("challenge", challengeId);

Expand Down Expand Up @@ -182,7 +182,7 @@ public ChallengePlayerInfo getChallengePlayerInfo(LeagueShard server, String puu
.withURLParameter(Constants.PUUID_ID_PLACEHOLDER, puuid)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("puuid", puuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ChampionRotationInfo getFreeToPlayRotation(LeagueShard server)
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V3_CHAMPION_ROTATIONS)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V3_CHAMPION_ROTATIONS, data);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/no/stelar7/api/r4j/impl/lol/raw/ClashAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<ClashPlayer> getPlayerInfo(final LeagueShard server, String summoner
.withURLParameter(Constants.SUMMONER_ID_PLACEHOLDER, summonerId)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("summonerId", summonerId);

Expand Down Expand Up @@ -63,7 +63,7 @@ public ClashTeam getTeam(final LeagueShard server, String teamId)
.withURLParameter(Constants.TEAM_ID_PLACEHOLDER, teamId)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("teamId", teamId);

Expand Down Expand Up @@ -95,7 +95,7 @@ public List<ClashTournament> getTournaments(final LeagueShard server)
DataCallBuilder builder = new DataCallBuilder().withEndpoint(URLEndpoint.V1_CLASH_TOURNAMENTS)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);

Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_CLASH_TOURNAMENTS, data);
Expand Down Expand Up @@ -127,7 +127,7 @@ public ClashTournament getTournamentByTeam(final LeagueShard server, String team
.withURLParameter(Constants.TEAM_ID_PLACEHOLDER, teamId)
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("teamId", teamId);

Expand Down Expand Up @@ -160,7 +160,7 @@ public ClashTournament getTournamentById(final LeagueShard server, int tournamen
.withURLParameter(Constants.TOURNAMENT_ID_PLACEHOLDER, String.valueOf(tournamentId))
.withPlatform(server);

Map<String, Object> data = new TreeMap<>();
Map<String, Object> data = new LinkedHashMap<>();
data.put("platform", server);
data.put("tournamentId", tournamentId);

Expand Down
Loading

0 comments on commit 8d2d9a2

Please sign in to comment.