mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fix a code smell
This commit is contained in:
parent
e3f344b1c6
commit
e0b05cc169
@ -10,6 +10,7 @@ import com.djrapitops.plugin.api.TimeAmount;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.OptionalDouble;
|
import java.util.OptionalDouble;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,12 +36,16 @@ public class TPSMutator {
|
|||||||
return new TPSMutator(new ArrayList<>(mutator.tpsData));
|
return new TPSMutator(new ArrayList<>(mutator.tpsData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TPSMutator filterDataBetween(long after, long before) {
|
public TPSMutator filterBy(Predicate<TPS> filter) {
|
||||||
return new TPSMutator(tpsData.stream()
|
return new TPSMutator(tpsData.stream()
|
||||||
.filter(tps -> tps.getDate() >= after && tps.getDate() <= before)
|
.filter(filter)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TPSMutator filterDataBetween(long after, long before) {
|
||||||
|
return filterBy(tps -> tps.getDate() >= after && tps.getDate() <= before);
|
||||||
|
}
|
||||||
|
|
||||||
public List<TPS> all() {
|
public List<TPS> all() {
|
||||||
return tpsData;
|
return tpsData;
|
||||||
}
|
}
|
||||||
|
@ -64,25 +64,29 @@ public class IPAnonPatch extends Patch {
|
|||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
for (List<GeoInfo> geoInfos : allGeoInfo.values()) {
|
for (List<GeoInfo> geoInfos : allGeoInfo.values()) {
|
||||||
for (GeoInfo geoInfo : geoInfos) {
|
for (GeoInfo geoInfo : geoInfos) {
|
||||||
try {
|
addToBatch(statement, geoInfo);
|
||||||
String oldIP = geoInfo.getIp();
|
}
|
||||||
if (oldIP.endsWith(".xx.xx") || oldIP.endsWith("xx..")) {
|
}
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
GeoInfo updatedInfo = new GeoInfo(
|
private void addToBatch(PreparedStatement statement, GeoInfo geoInfo) throws SQLException {
|
||||||
InetAddress.getByName(oldIP),
|
try {
|
||||||
geoInfo.getGeolocation(),
|
String oldIP = geoInfo.getIp();
|
||||||
geoInfo.getDate()
|
if (oldIP.endsWith(".xx.xx") || oldIP.endsWith("xx..")) {
|
||||||
);
|
return;
|
||||||
statement.setString(1, updatedInfo.getIp());
|
}
|
||||||
statement.setString(2, updatedInfo.getIpHash());
|
GeoInfo updatedInfo = new GeoInfo(
|
||||||
statement.setString(3, geoInfo.getIp());
|
InetAddress.getByName(oldIP),
|
||||||
statement.addBatch();
|
geoInfo.getGeolocation(),
|
||||||
} catch (UnknownHostException | UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
geoInfo.getDate()
|
||||||
if (Settings.DEV_MODE.isTrue()) {
|
);
|
||||||
Log.toLog(this.getClass(), e);
|
statement.setString(1, updatedInfo.getIp());
|
||||||
}
|
statement.setString(2, updatedInfo.getIpHash());
|
||||||
}
|
statement.setString(3, geoInfo.getIp());
|
||||||
|
statement.addBatch();
|
||||||
|
} catch (UnknownHostException | UnsupportedEncodingException | NoSuchAlgorithmException e) {
|
||||||
|
if (Settings.DEV_MODE.isTrue()) {
|
||||||
|
Log.toLog(this.getClass(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user