This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
forked from Slimefun/Slimefun4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new flags for timings (Slimefun#3246)
Co-authored-by: JustAHuman-xD <[email protected]> Co-authored-by: qwertyuioplkjhgfd <[email protected]> Co-authored-by: TheBusyBiscuit <[email protected]> Co-authored-by: J3fftw <[email protected]> Co-authored-by: Jeffrey <[email protected]>
- Loading branch information
1 parent
16313ef
commit 8bcf073
Showing
6 changed files
with
175 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/SummaryOrderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.github.thebusybiscuit.slimefun4.core.services.profiler; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Holds the different types of ordering for summaries. | ||
* | ||
* @author Walshy | ||
*/ | ||
public enum SummaryOrderType { | ||
|
||
/** | ||
* Sort by highest to the lowest total timings | ||
*/ | ||
HIGHEST, | ||
/** | ||
* Sort by lowest to the highest total timings | ||
*/ | ||
LOWEST, | ||
/** | ||
* Sort by average timings (highest to lowest) | ||
*/ | ||
AVERAGE; | ||
|
||
@ParametersAreNonnullByDefault | ||
List<Map.Entry<String, Long>> sort(SlimefunProfiler profiler, Set<Map.Entry<String, Long>> entrySet) { | ||
switch(this) { | ||
case HIGHEST: | ||
return entrySet.stream() | ||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) | ||
.collect(Collectors.toList()); | ||
case LOWEST: | ||
return entrySet.stream() | ||
.sorted(Comparator.comparingLong(Map.Entry::getValue)) | ||
.collect(Collectors.toList()); | ||
default: | ||
final Map<String, Long> map = new HashMap<>(); | ||
for (Map.Entry<String, Long> entry : entrySet) { | ||
int count = profiler.getBlocksOfId(entry.getKey()); | ||
long avg = count > 0 ? entry.getValue() / count : entry.getValue(); | ||
|
||
map.put(entry.getKey(), avg); | ||
} | ||
return map.entrySet().stream() | ||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters