Skip to content

Commit

Permalink
Clean up of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed May 7, 2024
1 parent 20155f0 commit a5ee027
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Arrays;
import java.util.Objects;

public class LoadReplay {
public class Replay {

private static ReplayContainer loadSCFAReplayFromMemory(ReplayMetadata metadata, ReplayBinaryFormat.BinarySCFA bytes) {
return new ReplayContainer(metadata, bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ public sealed interface ReplayBinaryFormat {

record WithContext (byte[] bytes) implements ReplayBinaryFormat {}

record CompressedSCFA (byte[] bytes) implements ReplayBinaryFormat {}

record BinarySCFA(byte[] bytes) implements ReplayBinaryFormat {}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package com.faforever.commons.replay;

import ch.qos.logback.classic.encoder.JsonEncoder;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.LittleEndianDataInputStream;
import org.apache.commons.compress.compressors.CompressorException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -38,7 +29,7 @@ public void parseBinary01() throws CompressorException, IOException {
() -> {
Path fafReplayFile = temporaryFolder.resolve("TestCommands01.fafreplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/TestCommands01.fafreplay")), fafReplayFile);
ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
}
);
}
Expand All @@ -49,7 +40,7 @@ public void parseBinary02() throws CompressorException, IOException {
() -> {
Path fafReplayFile = temporaryFolder.resolve("TestModeratorEvents.fafreplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/TestModeratorEvents.fafreplay")), fafReplayFile);
ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
}
);
}
Expand All @@ -60,7 +51,7 @@ public void parseBinary03() throws CompressorException, IOException {
() -> {
Path fafReplayFile = temporaryFolder.resolve("zstd_reference.fafreplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/zstd_reference.fafreplay")), fafReplayFile);
ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
}
);
}
Expand All @@ -71,7 +62,7 @@ public void parseBinary04() throws CompressorException, IOException {
() -> {
Path fafReplayFile = temporaryFolder.resolve("test.fafreplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/test.fafreplay")), fafReplayFile);
ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
}
);
}
Expand All @@ -84,8 +75,8 @@ public void compareBinary01() throws CompressorException, IOException {
Path scfaReplayFile = temporaryFolder.resolve("22338092.scfareplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/load/22338092.scfareplay")), scfaReplayFile);

ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = LoadReplay.loadSCFAReplayFromDisk(scfaReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = Replay.loadSCFAReplayFromDisk(scfaReplayFile);

assertEquals(scfaReplayContainer.replay().bytes().length, fafReplayContainer.replay().bytes().length);
assertEquals(Arrays.hashCode(scfaReplayContainer.replay().bytes()), Arrays.hashCode(fafReplayContainer.replay().bytes()));
Expand All @@ -100,8 +91,8 @@ public void compareBinary02() throws CompressorException, IOException {
Path scfaReplayFile = temporaryFolder.resolve("22373098.scfareplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/load/22373098.scfareplay")), scfaReplayFile);

ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = LoadReplay.loadSCFAReplayFromDisk(scfaReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = Replay.loadSCFAReplayFromDisk(scfaReplayFile);

assertEquals(scfaReplayContainer.replay().bytes().length, fafReplayContainer.replay().bytes().length);
assertEquals(Arrays.hashCode(scfaReplayContainer.replay().bytes()), Arrays.hashCode(fafReplayContainer.replay().bytes()));
Expand All @@ -117,8 +108,8 @@ public void compareBinary03() throws CompressorException, IOException {
Path scfaReplayFile = temporaryFolder.resolve("22425616.scfareplay");
Files.copy(Objects.requireNonNull(getClass().getResourceAsStream("/replay/load/22425616.scfareplay")), scfaReplayFile);

ReplayContainer fafReplayContainer = LoadReplay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = LoadReplay.loadSCFAReplayFromDisk(scfaReplayFile);
ReplayContainer fafReplayContainer = Replay.loadFAFReplayFromDisk(fafReplayFile);
ReplayContainer scfaReplayContainer = Replay.loadSCFAReplayFromDisk(scfaReplayFile);

assertEquals(scfaReplayContainer.replay().bytes().length, fafReplayContainer.replay().bytes().length);
assertEquals(Arrays.hashCode(scfaReplayContainer.replay().bytes()), Arrays.hashCode(fafReplayContainer.replay().bytes()));
Expand Down

0 comments on commit a5ee027

Please sign in to comment.