Skip to content

Commit

Permalink
fix: sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Jun 9, 2024
1 parent 2481685 commit aaf829c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public List<NetworkNodeContainer> sortDeterministically(final Set<NetworkNodeCon
return containers
.stream()
.sorted(Comparator.comparingInt(allowed::indexOf))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

import com.mojang.logging.LogUtils;
Expand All @@ -27,17 +28,23 @@ public void save(final File file) {
compoundTag.put("data", this.save(new CompoundTag()));
NbtUtils.addCurrentDataVersion(compoundTag);
try {
// Write to temp file first.
NbtIo.writeCompressed(compoundTag, tempFile);
// Try atomic move
try {
Files.move(tempFile, targetPath, StandardCopyOption.ATOMIC_MOVE);
} catch (final AtomicMoveNotSupportedException ignored) {
Files.move(tempFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
doSave(compoundTag, tempFile, targetPath);
} catch (final IOException e) {
LOGGER.error("Could not save data {}", this, e);
}
setDirty(false);
}

private void doSave(final CompoundTag compoundTag,
final Path tempFile,
final Path targetPath) throws IOException {
// Write to temp file first.
NbtIo.writeCompressed(compoundTag, tempFile);
// Try atomic move
try {
Files.move(tempFile, targetPath, StandardCopyOption.ATOMIC_MOVE);
} catch (final AtomicMoveNotSupportedException ignored) {
Files.move(tempFile, targetPath, StandardCopyOption.REPLACE_EXISTING);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public Optional<String> getModName(final String modId) {
void setUp() {
viewBuilder = new GridViewBuilderImpl(
FACTORY,
(view) -> Comparator.comparing(GridResource::getName),
(view) -> Comparator.comparing(GridResource::getAmount)
view -> Comparator.comparing(GridResource::getName),
view -> Comparator.comparing(GridResource::getAmount)
);
dirt = new ItemResource(Items.DIRT, null);
stone = new ItemResource(Items.STONE, null);
Expand Down

0 comments on commit aaf829c

Please sign in to comment.