Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private boolean isCombatRegion(ProtectedRegion region) {
@Nullable
private ProtectedRegion highestPriorityRegion(ApplicableRegionSet applicableRegions) {
return applicableRegions.getRegions().stream()
.min(Comparator.comparingInt(ProtectedRegion::getPriority))
.max(Comparator.comparingInt(ProtectedRegion::getPriority))
.orElse(null);
}
Comment on lines 85 to 90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This method can be improved by returning an Optional<ProtectedRegion> instead of using @Nullable. This change aligns with modern Java best practices for handling potentially absent values, making the code safer by leveraging the type system to enforce checks for presence and eliminating the risk of NullPointerException from an unchecked null return. It also enables callers, such as the getRegion method, to use a more fluent and declarative style with Optional chaining.

    private Optional<ProtectedRegion> highestPriorityRegion(ApplicableRegionSet applicableRegions) {
        return applicableRegions.getRegions().stream()
            .max(Comparator.comparingInt(ProtectedRegion::getPriority));
    }


Expand Down
Loading