Skip to content

Commit

Permalink
Use Java 9's takeWhile
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 24, 2021
1 parent 383ede3 commit 4661bcd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 52 deletions.
38 changes: 0 additions & 38 deletions src/main/java/world/bentobox/level/CustomSpliterator.java

This file was deleted.

15 changes: 1 addition & 14 deletions src/main/java/world/bentobox/level/LevelsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -444,18 +442,7 @@ public int getRank(@NonNull World world, UUID uuid) {
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
.filter(l -> l.getValue() > 0)
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
return takeWhile(stream, x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
}

/**
* Java 8's version of Java 9's takeWhile
* @param stream
* @param predicate
* @return stream
*/
public static <T> Stream<T> takeWhile(Stream<T> stream, Predicate<T> predicate) {
CustomSpliterator<T> customSpliterator = new CustomSpliterator<>(stream.spliterator(), predicate);
return StreamSupport.stream(customSpliterator, false);
return stream.takeWhile(x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
}

/**
Expand Down

0 comments on commit 4661bcd

Please sign in to comment.