Code smell cleanup in mutators

This commit is contained in:
Rsl1122 2018-08-12 10:35:56 +03:00
parent 2dcc69fc92
commit fc6c9399cf
11 changed files with 30 additions and 23 deletions

View File

@ -47,7 +47,7 @@ public class HookHandler implements SubSystem {
@Override
public void disable() {
// Nothing to disable
}
/**

View File

@ -26,7 +26,6 @@ public abstract class PluginData {
private final String sourcePlugin;
private Icon pluginIcon;
private String iconColor;
private String helpText;

View File

@ -22,4 +22,14 @@ public class PlaceholderKey<T> extends Key<T> {
public String getPlaceholder() {
return placeholder;
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@ -201,14 +201,12 @@ public class AnalysisContainer extends DataContainer {
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).uniqueJoinsPerDay());
putSupplier(AnalysisKeys.NEW_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).newPerDay());
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () ->
new AbstractLineGraph(MutatorFunctions.toPoints(
getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> new AbstractLineGraph(
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))
).toHighChartsSeries()
);
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () ->
new AbstractLineGraph(MutatorFunctions.toPoints(
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> new AbstractLineGraph(
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))
).toHighChartsSeries()
);

View File

@ -23,12 +23,7 @@ public class PlayerContainer extends DataContainer {
}
public ActivityIndex getActivityIndex(long date) {
ActivityIndex index = activityIndexCache.get(date);
if (index == null) {
index = new ActivityIndex(this, date);
activityIndexCache.put(date, index);
}
return index;
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time));
}
public boolean playedBetween(long after, long before) {

View File

@ -5,6 +5,7 @@ import com.djrapitops.plugin.api.TimeAmount;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
public class DateHoldersMutator<T extends DateHolder> {
@ -15,11 +16,11 @@ public class DateHoldersMutator<T extends DateHolder> {
this.dateHolders = dateHolders;
}
public TreeMap<Long, List<T>> groupByStartOfMinute() {
public SortedMap<Long, List<T>> groupByStartOfMinute() {
return groupByStartOfSections(TimeAmount.MINUTE.ms());
}
private TreeMap<Long, List<T>> groupByStartOfSections(long sectionLength) {
private SortedMap<Long, List<T>> groupByStartOfSections(long sectionLength) {
TreeMap<Long, List<T>> map = new TreeMap<>();
if (dateHolders.isEmpty()) {
@ -37,9 +38,9 @@ public class DateHoldersMutator<T extends DateHolder> {
return map;
}
public TreeMap<Long, List<T>> groupByStartOfDay() {
public SortedMap<Long, List<T>> groupByStartOfDay() {
long twentyFourHours = 24L * TimeAmount.HOUR.ms();
TreeMap<Long, List<T>> map = groupByStartOfSections(twentyFourHours);
SortedMap<Long, List<T>> map = groupByStartOfSections(twentyFourHours);
// Empty map firstKey attempt causes NPE if not checked.
if (!map.isEmpty()) {

View File

@ -21,4 +21,8 @@ public class MutatorFunctions {
.average().orElse(0);
}
private MutatorFunctions() {
// Static method class.
}
}

View File

@ -6,7 +6,7 @@ import com.djrapitops.plan.data.store.keys.CommonKeys;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import java.util.SortedMap;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -33,7 +33,7 @@ public class PingMutator {
public PingMutator mutateToByMinutePings() {
DateHoldersMutator<Ping> dateMutator = new DateHoldersMutator<>(pings);
TreeMap<Long, List<Ping>> byStartOfMinute = dateMutator.groupByStartOfMinute();
SortedMap<Long, List<Ping>> byStartOfMinute = dateMutator.groupByStartOfMinute();
return new PingMutator(byStartOfMinute.entrySet().stream()
.map(entry -> {

View File

@ -157,7 +157,7 @@ public class PlayersMutator {
List<DateObj> registerDates = registerDates().stream()
.map(value -> new DateObj<>(value, value))
.collect(Collectors.toList());
TreeMap<Long, List<DateObj>> byDay = new DateHoldersMutator<>(registerDates).groupByStartOfDay();
SortedMap<Long, List<DateObj>> byDay = new DateHoldersMutator<>(registerDates).groupByStartOfDay();
TreeMap<Long, Integer> byDayCounts = new TreeMap<>();
for (Map.Entry<Long, List<DateObj>> entry : byDay.entrySet()) {

View File

@ -156,7 +156,7 @@ public class SessionsMutator {
}
public TreeMap<Long, Integer> uniqueJoinsPerDay() {
TreeMap<Long, List<Session>> byStartOfDay = toDateHoldersMutator().groupByStartOfDay();
SortedMap<Long, List<Session>> byStartOfDay = toDateHoldersMutator().groupByStartOfDay();
TreeMap<Long, Integer> uniqueJoins = new TreeMap<>();
for (Map.Entry<Long, List<Session>> entry : byStartOfDay.entrySet()) {

View File

@ -64,7 +64,7 @@ public class ServerCalendar {
private void appendSessionRelatedData(StringBuilder series) {
SessionsMutator sessionsMutator = new SessionsMutator(mutator.getSessions());
TreeMap<Long, List<Session>> byStartOfDay = sessionsMutator.toDateHoldersMutator().groupByStartOfDay();
SortedMap<Long, List<Session>> byStartOfDay = sessionsMutator.toDateHoldersMutator().groupByStartOfDay();
for (Map.Entry<Long, Integer> entry : uniquePerDay.entrySet()) {
if (entry.getValue() <= 0) {