Update to Java 16 + replace javatuples usage with records
This commit is contained in:
parent
29d036a13f
commit
918ab59b69
@ -13,7 +13,7 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
|
||||||
org.eclipse.jdt.core.compiler.compliance=11
|
org.eclipse.jdt.core.compiler.compliance=16
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=11
|
org.eclipse.jdt.core.compiler.source=16
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
|
||||||
org.eclipse.jdt.core.compiler.compliance=11
|
org.eclipse.jdt.core.compiler.compliance=16
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=11
|
org.eclipse.jdt.core.compiler.source=16
|
||||||
|
@ -27,16 +27,16 @@
|
|||||||
<version>${bungeecord.version}</version>
|
<version>${bungeecord.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!-- <dependency>
|
||||||
<groupId>org.javatuples</groupId>
|
<groupId>org.javatuples</groupId>
|
||||||
<artifactId>javatuples</artifactId>
|
<artifactId>javatuples</artifactId>
|
||||||
<version>1.2</version>
|
<version>1.2</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency> -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.classgraph</groupId>
|
<groupId>io.github.classgraph</groupId>
|
||||||
<artifactId>classgraph</artifactId>
|
<artifactId>classgraph</artifactId>
|
||||||
<version>4.8.90</version>
|
<version>4.8.108</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -5,8 +5,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public class ChatColorUtil {
|
public class ChatColorUtil {
|
||||||
@ -257,10 +255,12 @@ public class ChatColorUtil {
|
|||||||
|
|
||||||
|
|
||||||
public static class ChatValueGradient {
|
public static class ChatValueGradient {
|
||||||
List<Pair<Float, ChatColor>> colors = new ArrayList<>();
|
private record GradientValueColor(float value, ChatColor color) { }
|
||||||
|
|
||||||
|
List<GradientValueColor> colors = new ArrayList<>();
|
||||||
|
|
||||||
public synchronized ChatValueGradient add(float v, ChatColor col) {
|
public synchronized ChatValueGradient add(float v, ChatColor col) {
|
||||||
colors.add(Pair.with(v, col));
|
colors.add(new GradientValueColor(v, col));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,23 +268,23 @@ public class ChatColorUtil {
|
|||||||
if (colors.isEmpty())
|
if (colors.isEmpty())
|
||||||
throw new IllegalStateException("Must define at least one color in this ChatValueGradient instance.");
|
throw new IllegalStateException("Must define at least one color in this ChatValueGradient instance.");
|
||||||
if (colors.size() == 1)
|
if (colors.size() == 1)
|
||||||
return colors.get(0).getValue1();
|
return colors.get(0).color();
|
||||||
|
|
||||||
colors.sort((p1, p2) -> Float.compare(p1.getValue0(), p2.getValue0()));
|
colors.sort((p1, p2) -> Float.compare(p1.value(), p2.value()));
|
||||||
|
|
||||||
if (v <= colors.get(0).getValue0())
|
if (v <= colors.get(0).value())
|
||||||
return colors.get(0).getValue1();
|
return colors.get(0).color();
|
||||||
if (v >= colors.get(colors.size() - 1).getValue0())
|
if (v >= colors.get(colors.size() - 1).value())
|
||||||
return colors.get(colors.size() - 1).getValue1();
|
return colors.get(colors.size() - 1).color();
|
||||||
|
|
||||||
int p1 = 1;
|
int p1 = 1;
|
||||||
for (; p1 < colors.size(); p1++) {
|
for (; p1 < colors.size(); p1++) {
|
||||||
if (colors.get(p1).getValue0() >= v)
|
if (colors.get(p1).value() >= v)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int p0 = p1 - 1;
|
int p0 = p1 - 1;
|
||||||
float v0 = colors.get(p0).getValue0(), v1 = colors.get(p1).getValue0();
|
float v0 = colors.get(p0).value(), v1 = colors.get(p1).value();
|
||||||
ChatColor cc0 = colors.get(p0).getValue1(), cc1 = colors.get(p1).getValue1();
|
ChatColor cc0 = colors.get(p0).color(), cc1 = colors.get(p1).color();
|
||||||
|
|
||||||
return interpolateColor(v0, v1, v, cc0, cc1);
|
return interpolateColor(v0, v1, v, cc0, cc1);
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.core.util.Log;
|
import fr.pandacube.lib.core.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,12 +68,12 @@ public final class DB {
|
|||||||
Collection<SQLField<E, ?>> tableFields = elem.getFields().values();
|
Collection<SQLField<E, ?>> tableFields = elem.getFields().values();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (SQLField<E, ?> f : tableFields) {
|
for (SQLField<E, ?> f : tableFields) {
|
||||||
Pair<String, List<Object>> statementPart = f.forSQLPreparedStatement();
|
ParameterizedSQLString statementPart = f.forSQLPreparedStatement();
|
||||||
params.addAll(statementPart.getValue1());
|
params.addAll(statementPart.parameters());
|
||||||
|
|
||||||
if (!first) sql += ", ";
|
if (!first) sql += ", ";
|
||||||
first = false;
|
first = false;
|
||||||
sql += statementPart.getValue0();
|
sql += statementPart.sqlString();
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += ", PRIMARY KEY id(id))";
|
sql += ", PRIMARY KEY id(id))";
|
||||||
@ -197,9 +195,9 @@ public final class DB {
|
|||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
if (where != null) {
|
if (where != null) {
|
||||||
Pair<String, List<Object>> ret = where.toSQL();
|
ParameterizedSQLString ret = where.toSQL();
|
||||||
sql += " WHERE " + ret.getValue0();
|
sql += " WHERE " + ret.sqlString();
|
||||||
params.addAll(ret.getValue1());
|
params.addAll(ret.parameters());
|
||||||
}
|
}
|
||||||
if (orderBy != null) sql += " ORDER BY " + orderBy.toSQL();
|
if (orderBy != null) sql += " ORDER BY " + orderBy.toSQL();
|
||||||
if (limit != null) sql += " LIMIT " + limit;
|
if (limit != null) sql += " LIMIT " + limit;
|
||||||
@ -233,9 +231,9 @@ public final class DB {
|
|||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
if (where != null) {
|
if (where != null) {
|
||||||
Pair<String, List<Object>> ret = where.toSQL();
|
ParameterizedSQLString ret = where.toSQL();
|
||||||
sql += " WHERE " + ret.getValue0();
|
sql += " WHERE " + ret.sqlString();
|
||||||
params.addAll(ret.getValue1());
|
params.addAll(ret.parameters());
|
||||||
}
|
}
|
||||||
sql += ";";
|
sql += ";";
|
||||||
|
|
||||||
@ -302,12 +300,12 @@ public final class DB {
|
|||||||
return truncateTable(elemClass);
|
return truncateTable(elemClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<String, List<Object>> whereData = where.toSQL();
|
ParameterizedSQLString whereData = where.toSQL();
|
||||||
|
|
||||||
String sql = "DELETE FROM " + getTableName(elemClass)
|
String sql = "DELETE FROM " + getTableName(elemClass)
|
||||||
+ " WHERE " + whereData.getValue0()
|
+ " WHERE " + whereData.sqlString()
|
||||||
+ ";";
|
+ ";";
|
||||||
List<Object> params = new ArrayList<>(whereData.getValue1());
|
List<Object> params = new ArrayList<>(whereData.parameters());
|
||||||
|
|
||||||
return customUpdateStatement(sql, params);
|
return customUpdateStatement(sql, params);
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package fr.pandacube.lib.core.db;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record ParameterizedSQLString(String sqlString, List<Object> parameters) {
|
||||||
|
|
||||||
|
}
|
@ -4,13 +4,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereComp;
|
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereComp;
|
||||||
|
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereComp.SQLComparator;
|
||||||
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereIn;
|
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereIn;
|
||||||
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereLike;
|
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereLike;
|
||||||
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereNull;
|
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereNull;
|
||||||
import fr.pandacube.lib.core.db.SQLWhere.SQLWhereComp.SQLComparator;
|
|
||||||
|
|
||||||
public class SQLField<E extends SQLElement<E>, T> {
|
public class SQLField<E extends SQLElement<E>, T> {
|
||||||
|
|
||||||
@ -40,10 +38,10 @@ public class SQLField<E extends SQLElement<E>, T> {
|
|||||||
this(t, nul, false, deflt);
|
this(t, nul, false, deflt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ Pair<String, List<Object>> forSQLPreparedStatement() {
|
/* package */ ParameterizedSQLString forSQLPreparedStatement() {
|
||||||
List<Object> params = new ArrayList<>(1);
|
List<Object> params = new ArrayList<>(1);
|
||||||
if (defaultValue != null && !autoIncrement) params.add(defaultValue);
|
if (defaultValue != null && !autoIncrement) params.add(defaultValue);
|
||||||
return new Pair<>("`" + getName() + "` " + type.toString() + (canBeNull ? " NULL" : " NOT NULL")
|
return new ParameterizedSQLString("`" + getName() + "` " + type.toString() + (canBeNull ? " NULL" : " NOT NULL")
|
||||||
+ (autoIncrement ? " AUTO_INCREMENT" : "")
|
+ (autoIncrement ? " AUTO_INCREMENT" : "")
|
||||||
+ ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params);
|
+ ((defaultValue == null || autoIncrement) ? "" : " DEFAULT ?"), params);
|
||||||
}
|
}
|
||||||
@ -72,7 +70,7 @@ public class SQLField<E extends SQLElement<E>, T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return forSQLPreparedStatement().getValue0().replaceFirst("\\?",
|
return forSQLPreparedStatement().sqlString().replaceFirst("\\?",
|
||||||
(defaultValue != null && !autoIncrement) ? defaultValue.toString() : "");
|
(defaultValue != null && !autoIncrement) ? defaultValue.toString() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.core.util.Log;
|
import fr.pandacube.lib.core.util.Log;
|
||||||
|
|
||||||
public class SQLUpdate<E extends SQLElement<E>> {
|
public class SQLUpdate<E extends SQLElement<E>> {
|
||||||
@ -57,9 +55,9 @@ public class SQLUpdate<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (where != null) {
|
if (where != null) {
|
||||||
Pair<String, List<Object>> ret = where.toSQL();
|
ParameterizedSQLString ret = where.toSQL();
|
||||||
sql += " WHERE " + ret.getValue0();
|
sql += " WHERE " + ret.sqlString();
|
||||||
params.addAll(ret.getValue1());
|
params.addAll(ret.parameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += ";";
|
sql += ";";
|
||||||
|
@ -5,18 +5,16 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import fr.pandacube.lib.core.util.Log;
|
import fr.pandacube.lib.core.util.Log;
|
||||||
|
|
||||||
public abstract class SQLWhere<E extends SQLElement<E>> {
|
public abstract class SQLWhere<E extends SQLElement<E>> {
|
||||||
|
|
||||||
public abstract Pair<String, List<Object>> toSQL() throws DBException;
|
public abstract ParameterizedSQLString toSQL() throws DBException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
return toSQL().getValue0();
|
return toSQL().sqlString();
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
Log.warning(e);
|
Log.warning(e);
|
||||||
return "[SQLWhere.toString() error (see logs)]";
|
return "[SQLWhere.toString() error (see logs)]";
|
||||||
@ -66,7 +64,7 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<String, List<Object>> toSQL() throws DBException {
|
public ParameterizedSQLString toSQL() throws DBException {
|
||||||
if (conditions.isEmpty()) {
|
if (conditions.isEmpty()) {
|
||||||
throw new DBException("SQLWhereChain needs at least one element inside !");
|
throw new DBException("SQLWhereChain needs at least one element inside !");
|
||||||
}
|
}
|
||||||
@ -79,12 +77,12 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
if (!first) sql += " " + operator.sql + " ";
|
if (!first) sql += " " + operator.sql + " ";
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
Pair<String, List<Object>> ret = w.toSQL();
|
ParameterizedSQLString ret = w.toSQL();
|
||||||
sql += "(" + ret.getValue0() + ")";
|
sql += "(" + ret.sqlString() + ")";
|
||||||
params.addAll(ret.getValue1());
|
params.addAll(ret.parameters());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Pair<>(sql, params);
|
return new ParameterizedSQLString(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected enum SQLBoolOp {
|
protected enum SQLBoolOp {
|
||||||
@ -169,10 +167,10 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<String, List<Object>> toSQL() throws DBException {
|
public ParameterizedSQLString toSQL() throws DBException {
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
SQLElement.addValueToSQLObjectList(params, left, right);
|
SQLElement.addValueToSQLObjectList(params, left, right);
|
||||||
return new Pair<>("`" + left.getName() + "` " + comp.sql + " ? ", params);
|
return new ParameterizedSQLString("`" + left.getName() + "` " + comp.sql + " ? ", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ enum SQLComparator {
|
/* package */ enum SQLComparator {
|
||||||
@ -217,11 +215,11 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<String, List<Object>> toSQL() throws DBException {
|
public ParameterizedSQLString toSQL() throws DBException {
|
||||||
List<Object> params = new ArrayList<>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
if (values.isEmpty())
|
if (values.isEmpty())
|
||||||
return new Pair<>(" 1=0 ", params);
|
return new ParameterizedSQLString(" 1=0 ", params);
|
||||||
|
|
||||||
for (Object v : values)
|
for (Object v : values)
|
||||||
SQLElement.addValueToSQLObjectList(params, field, v);
|
SQLElement.addValueToSQLObjectList(params, field, v);
|
||||||
@ -230,7 +228,7 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
for (int i = 0; i < questions.length; i++)
|
for (int i = 0; i < questions.length; i++)
|
||||||
questions[i] = i % 2 == 0 ? '?' : ',';
|
questions[i] = i % 2 == 0 ? '?' : ',';
|
||||||
|
|
||||||
return new Pair<>("`" + field.getName() + "` IN (" + new String(questions) + ") ", params);
|
return new ParameterizedSQLString("`" + field.getName() + "` IN (" + new String(questions) + ") ", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -261,10 +259,10 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<String, List<Object>> toSQL() {
|
public ParameterizedSQLString toSQL() {
|
||||||
ArrayList<Object> params = new ArrayList<>();
|
ArrayList<Object> params = new ArrayList<>();
|
||||||
params.add(likeExpr);
|
params.add(likeExpr);
|
||||||
return new Pair<>("`" + field.getName() + "` LIKE ? ", params);
|
return new ParameterizedSQLString("`" + field.getName() + "` LIKE ? ", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -297,8 +295,8 @@ public abstract class SQLWhere<E extends SQLElement<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<String, List<Object>> toSQL() {
|
public ParameterizedSQLString toSQL() {
|
||||||
return new Pair<>("`" + fild.getName() + "` IS " + ((nulll) ? "NULL" : "NOT NULL"), new ArrayList<>());
|
return new ParameterizedSQLString("`" + fild.getName() + "` IS " + ((nulll) ? "NULL" : "NOT NULL"), new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.function.ToIntBiFunction;
|
import java.util.function.ToIntBiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.javatuples.Pair;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
@ -38,16 +36,17 @@ public class PlayerFinder {
|
|||||||
.expireAfterWrite(2, TimeUnit.MINUTES)
|
.expireAfterWrite(2, TimeUnit.MINUTES)
|
||||||
.maximumSize(1000)
|
.maximumSize(1000)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private static Cache<Pair<String, Boolean>, UUID> playerId = CacheBuilder.newBuilder()
|
record PlayerIdCacheKey(String pName, boolean old) { }
|
||||||
|
private static Cache<PlayerIdCacheKey, UUID> playerId = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(2, TimeUnit.MINUTES)
|
.expireAfterWrite(2, TimeUnit.MINUTES)
|
||||||
.maximumSize(1000)
|
.maximumSize(1000)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static void clearCacheEntry(UUID pId, String pName) {
|
public static void clearCacheEntry(UUID pId, String pName) {
|
||||||
playerLastKnownName.invalidate(pId);
|
playerLastKnownName.invalidate(pId);
|
||||||
playerId.invalidate(Pair.with(pName.toLowerCase(), true));
|
playerId.invalidate(new PlayerIdCacheKey(pName.toLowerCase(), true));
|
||||||
playerId.invalidate(Pair.with(pName.toLowerCase(), false));
|
playerId.invalidate(new PlayerIdCacheKey(pName.toLowerCase(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLastKnownName(UUID id) {
|
public static String getLastKnownName(UUID id) {
|
||||||
@ -88,7 +87,7 @@ public class PlayerFinder {
|
|||||||
return null; // évite une recherche inutile dans la base de donnée
|
return null; // évite une recherche inutile dans la base de donnée
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return playerId.get(Pair.with(exactName.toLowerCase(), old), () -> {
|
return playerId.get(new PlayerIdCacheKey(exactName.toLowerCase(), old), () -> {
|
||||||
try {
|
try {
|
||||||
SQLPlayer el = DB.getFirst(SQLPlayer.class,
|
SQLPlayer el = DB.getFirst(SQLPlayer.class,
|
||||||
SQLPlayer.playerName.like(exactName.replace("_", "\\_")),
|
SQLPlayer.playerName.like(exactName.replace("_", "\\_")),
|
||||||
@ -204,14 +203,15 @@ public class PlayerFinder {
|
|||||||
return DIFF_CHAR_DISTANCE;
|
return DIFF_CHAR_DISTANCE;
|
||||||
};
|
};
|
||||||
|
|
||||||
private static LoadingCache<String, List<Pair<String, UUID>>> namesCache = CacheBuilder.newBuilder()
|
record NamesCacheResult(String name, UUID id) { }
|
||||||
|
private static LoadingCache<String, List<NamesCacheResult>> namesCache = CacheBuilder.newBuilder()
|
||||||
.expireAfterWrite(2, TimeUnit.MINUTES)
|
.expireAfterWrite(2, TimeUnit.MINUTES)
|
||||||
.maximumSize(1)
|
.maximumSize(1)
|
||||||
.build(CacheLoader.from((String k) -> {
|
.build(CacheLoader.from((String k) -> {
|
||||||
List<Pair<String, UUID>> cached = new ArrayList<>();
|
List<NamesCacheResult> cached = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
DB.forEach(SQLPlayerNameHistory.class, el -> {
|
DB.forEach(SQLPlayerNameHistory.class, el -> {
|
||||||
cached.add(Pair.with(el.get(SQLPlayerNameHistory.playerName), el.get(SQLPlayerNameHistory.playerId)));
|
cached.add(new NamesCacheResult(el.get(SQLPlayerNameHistory.playerName), el.get(SQLPlayerNameHistory.playerId)));
|
||||||
});
|
});
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -226,12 +226,12 @@ public class PlayerFinder {
|
|||||||
List<FoundName> foundNames = new ArrayList<>();
|
List<FoundName> foundNames = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
namesCache.get("").forEach(el -> {
|
namesCache.get("").forEach(el -> {
|
||||||
String name = el.getValue0();
|
String name = el.name();
|
||||||
int dist = new LevenshteinDistance(name.toLowerCase(), query, SURPLUS_CHAR_DISTANCE, MISSING_CHAR_DISTANCE, CHAR_DISTANCE).getCurrentDistance();
|
int dist = new LevenshteinDistance(name.toLowerCase(), query, SURPLUS_CHAR_DISTANCE, MISSING_CHAR_DISTANCE, CHAR_DISTANCE).getCurrentDistance();
|
||||||
if (dist <= SEARCH_MAX_DISTANCE) {
|
if (dist <= SEARCH_MAX_DISTANCE) {
|
||||||
FoundName n = new FoundName();
|
FoundName n = new FoundName();
|
||||||
n.dist = dist;
|
n.dist = dist;
|
||||||
n.id = el.getValue1();
|
n.id = el.id();
|
||||||
n.name = name;
|
n.name = name;
|
||||||
foundNames.add(n);
|
foundNames.add(n);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-16">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=16
|
||||||
org.eclipse.jdt.core.compiler.compliance=11
|
org.eclipse.jdt.core.compiler.compliance=16
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
org.eclipse.jdt.core.compiler.release=disabled
|
||||||
org.eclipse.jdt.core.compiler.source=11
|
org.eclipse.jdt.core.compiler.source=16
|
||||||
|
14
pom.xml
14
pom.xml
@ -37,8 +37,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<build.number>unknown</build.number>
|
<build.number>unknown</build.number>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>16</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>16</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
<bungeecord.version>1.16-R0.4-SNAPSHOT</bungeecord.version>
|
<bungeecord.version>1.16-R0.4-SNAPSHOT</bungeecord.version>
|
||||||
@ -54,11 +54,11 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.12</version>
|
<version>5.7.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
Loading…
Reference in New Issue
Block a user