diff --git a/code/common/model/java/nu/marginalia/model/EdgeDomain.java b/code/common/model/java/nu/marginalia/model/EdgeDomain.java index 6de01711..c6900a7c 100644 --- a/code/common/model/java/nu/marginalia/model/EdgeDomain.java +++ b/code/common/model/java/nu/marginalia/model/EdgeDomain.java @@ -60,10 +60,6 @@ public class EdgeDomain implements Serializable { this.topDomain = topDomain; } - public static EdgeDomainBuilder builder() { - return new EdgeDomainBuilder(); - } - private boolean looksLikeGovTld(String host) { if (host.length() < 8) return false; @@ -197,30 +193,4 @@ public class EdgeDomain implements Serializable { public String getTopDomain() { return this.topDomain; } - - public static class EdgeDomainBuilder { - private String subDomain; - private String topDomain; - - EdgeDomainBuilder() { - } - - public EdgeDomainBuilder subDomain(String subDomain) { - this.subDomain = subDomain; - return this; - } - - public EdgeDomainBuilder topDomain(String topDomain) { - this.topDomain = topDomain; - return this; - } - - public EdgeDomain build() { - return new EdgeDomain(this.subDomain, this.topDomain); - } - - public String toString() { - return "EdgeDomain.EdgeDomainBuilder(subDomain=" + this.subDomain + ", topDomain=" + this.topDomain + ")"; - } - } } diff --git a/code/common/model/java/nu/marginalia/model/EdgeUrl.java b/code/common/model/java/nu/marginalia/model/EdgeUrl.java index c962ac1b..04638c24 100644 --- a/code/common/model/java/nu/marginalia/model/EdgeUrl.java +++ b/code/common/model/java/nu/marginalia/model/EdgeUrl.java @@ -154,10 +154,6 @@ public class EdgeUrl implements Serializable { return port; } - public static EdgeUrlBuilder builder() { - return new EdgeUrlBuilder(); - } - public String toString() { StringBuilder sb = new StringBuilder(256); @@ -242,67 +238,8 @@ public class EdgeUrl implements Serializable { return new URI(this.proto, this.domain.toString(), this.path, this.param, null); } - public String getProto() { - return this.proto; - } - public EdgeDomain getDomain() { return this.domain; } - public Integer getPort() { - return this.port; - } - - public String getPath() { - return this.path; - } - - public String getParam() { - return this.param; - } - - public static class EdgeUrlBuilder { - private String proto; - private EdgeDomain domain; - private Integer port; - private String path; - private String param; - - EdgeUrlBuilder() { - } - - public EdgeUrlBuilder proto(String proto) { - this.proto = proto; - return this; - } - - public EdgeUrlBuilder domain(EdgeDomain domain) { - this.domain = domain; - return this; - } - - public EdgeUrlBuilder port(Integer port) { - this.port = port; - return this; - } - - public EdgeUrlBuilder path(String path) { - this.path = path; - return this; - } - - public EdgeUrlBuilder param(String param) { - this.param = param; - return this; - } - - public EdgeUrl build() { - return new EdgeUrl(this.proto, this.domain, this.port, this.path, this.param); - } - - public String toString() { - return "EdgeUrl.EdgeUrlBuilder(proto=" + this.proto + ", domain=" + this.domain + ", port=" + this.port + ", path=" + this.path + ", param=" + this.param + ")"; - } - } } diff --git a/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryEntry.java b/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryEntry.java index d5d6a952..d76ff763 100644 --- a/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryEntry.java +++ b/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryEntry.java @@ -1,29 +1,3 @@ package nu.marginalia.api.math.model; -public class DictionaryEntry { - public final String type; - public final String word; - public final String definition; - - public DictionaryEntry(String type, String word, String definition) { - this.type = type; - this.word = word; - this.definition = definition; - } - - public String getType() { - return this.type; - } - - public String getWord() { - return this.word; - } - - public String getDefinition() { - return this.definition; - } - - public String toString() { - return "DictionaryEntry(type=" + this.getType() + ", word=" + this.getWord() + ", definition=" + this.getDefinition() + ")"; - } -} +public record DictionaryEntry(String type, String word, String definition) { } diff --git a/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryResponse.java b/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryResponse.java index e7dbe52f..b158730e 100644 --- a/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryResponse.java +++ b/code/functions/math/api/java/nu/marginalia/api/math/model/DictionaryResponse.java @@ -2,27 +2,9 @@ package nu.marginalia.api.math.model; import java.util.List; -public class DictionaryResponse { - public String word; - public List entries; - +public record DictionaryResponse(String word, List entries) { public DictionaryResponse(String word, List entries) { this.word = word; - this.entries = entries; - } - - public DictionaryResponse() { - } - - public String getWord() { - return this.word; - } - - public List getEntries() { - return this.entries; - } - - public String toString() { - return "DictionaryResponse(word=" + this.getWord() + ", entries=" + this.getEntries() + ")"; + this.entries = entries.stream().toList(); // Make an immutable copy } } diff --git a/code/functions/math/java/nu/marginalia/functions/math/MathGrpcService.java b/code/functions/math/java/nu/marginalia/functions/math/MathGrpcService.java index bdc39e29..2a200d89 100644 --- a/code/functions/math/java/nu/marginalia/functions/math/MathGrpcService.java +++ b/code/functions/math/java/nu/marginalia/functions/math/MathGrpcService.java @@ -39,12 +39,12 @@ public class MathGrpcService .newBuilder() .setWord(request.getWord()); - for (var def : definition.entries) { + for (var def : definition.entries()) { responseBuilder.addEntries( RpcDictionaryEntry.newBuilder() - .setWord(def.word) - .setDefinition(def.definition) - .setType(def.type) + .setWord(def.word()) + .setDefinition(def.definition()) + .setType(def.type()) ); } diff --git a/code/functions/math/java/nu/marginalia/functions/math/dict/DictionaryService.java b/code/functions/math/java/nu/marginalia/functions/math/dict/DictionaryService.java index 630e9035..85a72a36 100644 --- a/code/functions/math/java/nu/marginalia/functions/math/dict/DictionaryService.java +++ b/code/functions/math/java/nu/marginalia/functions/math/dict/DictionaryService.java @@ -8,7 +8,8 @@ import nu.marginalia.api.math.model.DictionaryResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.List; @Singleton public class DictionaryService { @@ -25,8 +26,7 @@ public class DictionaryService { } public DictionaryResponse define(String word) { - DictionaryResponse response = new DictionaryResponse(); - response.entries = new ArrayList<>(); + List entries = new ArrayList<>(); try (var connection = dataSource.getConnection()) { var stmt = connection.prepareStatement("SELECT TYPE,WORD,DEFINITION FROM REF_DICTIONARY WHERE WORD=?"); @@ -34,14 +34,14 @@ public class DictionaryService { var rsp = stmt.executeQuery(); while (rsp.next()) { - response.entries.add(new DictionaryEntry(rsp.getString(1), rsp.getString(2), rsp.getString(3))); + entries.add(new DictionaryEntry(rsp.getString(1), rsp.getString(2), rsp.getString(3))); } } catch (Exception ex) { throw new RuntimeException(ex); } - return response; + return new DictionaryResponse(word, entries); } public List spellCheck(String word) { diff --git a/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/query/SearchQuery.java b/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/query/SearchQuery.java index 3efe01c3..7eb4ac0f 100644 --- a/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/query/SearchQuery.java +++ b/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/query/SearchQuery.java @@ -2,6 +2,7 @@ package nu.marginalia.api.searchquery.model.query; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class SearchQuery { @@ -35,17 +36,13 @@ public class SearchQuery { */ public final List phraseConstraints; - @Deprecated // why does this exist? - private double value = 0; - - public SearchQuery(String compiledQuery, List searchTermsInclude, List searchTermsExclude, List searchTermsAdvice, List searchTermsPriority, List phraseConstraints, double value) { + public SearchQuery(String compiledQuery, List searchTermsInclude, List searchTermsExclude, List searchTermsAdvice, List searchTermsPriority, List phraseConstraints) { this.compiledQuery = compiledQuery; this.searchTermsInclude = searchTermsInclude; this.searchTermsExclude = searchTermsExclude; this.searchTermsAdvice = searchTermsAdvice; this.searchTermsPriority = searchTermsPriority; this.phraseConstraints = phraseConstraints; - this.value = value; } public static SearchQueryBuilder builder() { @@ -61,30 +58,6 @@ public class SearchQuery { this.phraseConstraints = new ArrayList<>(); } - public SearchQuery(String compiledQuery, - List searchTermsInclude, - List searchTermsExclude, - List searchTermsAdvice, - List searchTermsPriority, - List phraseConstraints) { - this.compiledQuery = compiledQuery; - this.searchTermsInclude = searchTermsInclude; - this.searchTermsExclude = searchTermsExclude; - this.searchTermsAdvice = searchTermsAdvice; - this.searchTermsPriority = searchTermsPriority; - this.phraseConstraints = phraseConstraints; - } - - @Deprecated // why does this exist? - public SearchQuery setValue(double value) { - if (Double.isInfinite(value) || Double.isNaN(value)) { - this.value = Double.MAX_VALUE; - } else { - this.value = value; - } - return this; - } - @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -125,94 +98,28 @@ public class SearchQuery { return this.phraseConstraints; } - @Deprecated - public double getValue() { - return this.value; - } - - public SearchQuery withCompiledQuery(String compiledQuery) { - return this.compiledQuery == compiledQuery ? this : new SearchQuery(compiledQuery, this.searchTermsInclude, this.searchTermsExclude, this.searchTermsAdvice, this.searchTermsPriority, this.phraseConstraints, this.value); - } - - public SearchQuery withSearchTermsInclude(List searchTermsInclude) { - return this.searchTermsInclude == searchTermsInclude ? this : new SearchQuery(this.compiledQuery, searchTermsInclude, this.searchTermsExclude, this.searchTermsAdvice, this.searchTermsPriority, this.phraseConstraints, this.value); - } - - public SearchQuery withSearchTermsExclude(List searchTermsExclude) { - return this.searchTermsExclude == searchTermsExclude ? this : new SearchQuery(this.compiledQuery, this.searchTermsInclude, searchTermsExclude, this.searchTermsAdvice, this.searchTermsPriority, this.phraseConstraints, this.value); - } - - public SearchQuery withSearchTermsAdvice(List searchTermsAdvice) { - return this.searchTermsAdvice == searchTermsAdvice ? this : new SearchQuery(this.compiledQuery, this.searchTermsInclude, this.searchTermsExclude, searchTermsAdvice, this.searchTermsPriority, this.phraseConstraints, this.value); - } - - public SearchQuery withSearchTermsPriority(List searchTermsPriority) { - return this.searchTermsPriority == searchTermsPriority ? this : new SearchQuery(this.compiledQuery, this.searchTermsInclude, this.searchTermsExclude, this.searchTermsAdvice, searchTermsPriority, this.phraseConstraints, this.value); - } - - public SearchQuery withPhraseConstraints(List phraseConstraints) { - return this.phraseConstraints == phraseConstraints ? this : new SearchQuery(this.compiledQuery, this.searchTermsInclude, this.searchTermsExclude, this.searchTermsAdvice, this.searchTermsPriority, phraseConstraints, this.value); - } - - public SearchQuery withValue(double value) { - return this.value == value ? this : new SearchQuery(this.compiledQuery, this.searchTermsInclude, this.searchTermsExclude, this.searchTermsAdvice, this.searchTermsPriority, this.phraseConstraints, value); - } - - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof SearchQuery)) return false; - final SearchQuery other = (SearchQuery) o; - if (!other.canEqual((Object) this)) return false; - final Object this$compiledQuery = this.getCompiledQuery(); - final Object other$compiledQuery = other.getCompiledQuery(); - if (this$compiledQuery == null ? other$compiledQuery != null : !this$compiledQuery.equals(other$compiledQuery)) - return false; - final Object this$searchTermsInclude = this.getSearchTermsInclude(); - final Object other$searchTermsInclude = other.getSearchTermsInclude(); - if (this$searchTermsInclude == null ? other$searchTermsInclude != null : !this$searchTermsInclude.equals(other$searchTermsInclude)) - return false; - final Object this$searchTermsExclude = this.getSearchTermsExclude(); - final Object other$searchTermsExclude = other.getSearchTermsExclude(); - if (this$searchTermsExclude == null ? other$searchTermsExclude != null : !this$searchTermsExclude.equals(other$searchTermsExclude)) - return false; - final Object this$searchTermsAdvice = this.getSearchTermsAdvice(); - final Object other$searchTermsAdvice = other.getSearchTermsAdvice(); - if (this$searchTermsAdvice == null ? other$searchTermsAdvice != null : !this$searchTermsAdvice.equals(other$searchTermsAdvice)) - return false; - final Object this$searchTermsPriority = this.getSearchTermsPriority(); - final Object other$searchTermsPriority = other.getSearchTermsPriority(); - if (this$searchTermsPriority == null ? other$searchTermsPriority != null : !this$searchTermsPriority.equals(other$searchTermsPriority)) - return false; - final Object this$phraseConstraints = this.getPhraseConstraints(); - final Object other$phraseConstraints = other.getPhraseConstraints(); - if (this$phraseConstraints == null ? other$phraseConstraints != null : !this$phraseConstraints.equals(other$phraseConstraints)) - return false; - if (Double.compare(this.getValue(), other.getValue()) != 0) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof SearchQuery; + + @Override + public final boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SearchQuery that)) return false; + + return Objects.equals(compiledQuery, that.compiledQuery) + && Objects.equals(searchTermsInclude, that.searchTermsInclude) + && Objects.equals(searchTermsExclude, that.searchTermsExclude) + && Objects.equals(searchTermsAdvice, that.searchTermsAdvice) + && Objects.equals(searchTermsPriority, that.searchTermsPriority) + && Objects.equals(phraseConstraints, that.phraseConstraints); } + @Override public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $compiledQuery = this.getCompiledQuery(); - result = result * PRIME + ($compiledQuery == null ? 43 : $compiledQuery.hashCode()); - final Object $searchTermsInclude = this.getSearchTermsInclude(); - result = result * PRIME + ($searchTermsInclude == null ? 43 : $searchTermsInclude.hashCode()); - final Object $searchTermsExclude = this.getSearchTermsExclude(); - result = result * PRIME + ($searchTermsExclude == null ? 43 : $searchTermsExclude.hashCode()); - final Object $searchTermsAdvice = this.getSearchTermsAdvice(); - result = result * PRIME + ($searchTermsAdvice == null ? 43 : $searchTermsAdvice.hashCode()); - final Object $searchTermsPriority = this.getSearchTermsPriority(); - result = result * PRIME + ($searchTermsPriority == null ? 43 : $searchTermsPriority.hashCode()); - final Object $phraseConstraints = this.getPhraseConstraints(); - result = result * PRIME + ($phraseConstraints == null ? 43 : $phraseConstraints.hashCode()); - final long $value = Double.doubleToLongBits(this.getValue()); - result = result * PRIME + (int) ($value >>> 32 ^ $value); - return result; + return Objects.hash(compiledQuery, + searchTermsInclude, + searchTermsExclude, + searchTermsAdvice, + searchTermsPriority, + phraseConstraints); } public static class SearchQueryBuilder { diff --git a/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/results/ResultRankingParameters.java b/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/results/ResultRankingParameters.java index 41a944f7..5efa1e16 100644 --- a/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/results/ResultRankingParameters.java +++ b/code/functions/search-query/api/java/nu/marginalia/api/searchquery/model/results/ResultRankingParameters.java @@ -1,5 +1,7 @@ package nu.marginalia.api.searchquery.model.results; +import java.util.Objects; + public class ResultRankingParameters { /** @@ -141,66 +143,30 @@ public class ResultRankingParameters { return this.exportDebugData; } - public boolean equals(final Object o) { - if (o == this) return true; - if (!(o instanceof ResultRankingParameters)) return false; - final ResultRankingParameters other = (ResultRankingParameters) o; - if (!other.canEqual((Object) this)) return false; - final Object this$bm25Params = this.getBm25Params(); - final Object other$bm25Params = other.getBm25Params(); - if (this$bm25Params == null ? other$bm25Params != null : !this$bm25Params.equals(other$bm25Params)) - return false; - if (this.getShortDocumentThreshold() != other.getShortDocumentThreshold()) return false; - if (Double.compare(this.getShortDocumentPenalty(), other.getShortDocumentPenalty()) != 0) return false; - if (Double.compare(this.getDomainRankBonus(), other.getDomainRankBonus()) != 0) return false; - if (Double.compare(this.getQualityPenalty(), other.getQualityPenalty()) != 0) return false; - if (this.getShortSentenceThreshold() != other.getShortSentenceThreshold()) return false; - if (Double.compare(this.getShortSentencePenalty(), other.getShortSentencePenalty()) != 0) return false; - if (Double.compare(this.getBm25Weight(), other.getBm25Weight()) != 0) return false; - if (Double.compare(this.getTcfFirstPosition(), other.getTcfFirstPosition()) != 0) return false; - if (Double.compare(this.getTcfVerbatim(), other.getTcfVerbatim()) != 0) return false; - if (Double.compare(this.getTcfProximity(), other.getTcfProximity()) != 0) return false; - final Object this$temporalBias = this.getTemporalBias(); - final Object other$temporalBias = other.getTemporalBias(); - if (this$temporalBias == null ? other$temporalBias != null : !this$temporalBias.equals(other$temporalBias)) - return false; - if (Double.compare(this.getTemporalBiasWeight(), other.getTemporalBiasWeight()) != 0) return false; - if (this.isExportDebugData() != other.isExportDebugData()) return false; - return true; - } - - protected boolean canEqual(final Object other) { - return other instanceof ResultRankingParameters; + @Override + public final boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ResultRankingParameters that)) return false; + + return shortDocumentThreshold == that.shortDocumentThreshold && Double.compare(shortDocumentPenalty, that.shortDocumentPenalty) == 0 && Double.compare(domainRankBonus, that.domainRankBonus) == 0 && Double.compare(qualityPenalty, that.qualityPenalty) == 0 && shortSentenceThreshold == that.shortSentenceThreshold && Double.compare(shortSentencePenalty, that.shortSentencePenalty) == 0 && Double.compare(bm25Weight, that.bm25Weight) == 0 && Double.compare(tcfFirstPosition, that.tcfFirstPosition) == 0 && Double.compare(tcfVerbatim, that.tcfVerbatim) == 0 && Double.compare(tcfProximity, that.tcfProximity) == 0 && Double.compare(temporalBiasWeight, that.temporalBiasWeight) == 0 && exportDebugData == that.exportDebugData && Objects.equals(bm25Params, that.bm25Params) && temporalBias == that.temporalBias; } + @Override public int hashCode() { - final int PRIME = 59; - int result = 1; - final Object $bm25Params = this.getBm25Params(); - result = result * PRIME + ($bm25Params == null ? 43 : $bm25Params.hashCode()); - result = result * PRIME + this.getShortDocumentThreshold(); - final long $shortDocumentPenalty = Double.doubleToLongBits(this.getShortDocumentPenalty()); - result = result * PRIME + (int) ($shortDocumentPenalty >>> 32 ^ $shortDocumentPenalty); - final long $domainRankBonus = Double.doubleToLongBits(this.getDomainRankBonus()); - result = result * PRIME + (int) ($domainRankBonus >>> 32 ^ $domainRankBonus); - final long $qualityPenalty = Double.doubleToLongBits(this.getQualityPenalty()); - result = result * PRIME + (int) ($qualityPenalty >>> 32 ^ $qualityPenalty); - result = result * PRIME + this.getShortSentenceThreshold(); - final long $shortSentencePenalty = Double.doubleToLongBits(this.getShortSentencePenalty()); - result = result * PRIME + (int) ($shortSentencePenalty >>> 32 ^ $shortSentencePenalty); - final long $bm25Weight = Double.doubleToLongBits(this.getBm25Weight()); - result = result * PRIME + (int) ($bm25Weight >>> 32 ^ $bm25Weight); - final long $tcfFirstPosition = Double.doubleToLongBits(this.getTcfFirstPosition()); - result = result * PRIME + (int) ($tcfFirstPosition >>> 32 ^ $tcfFirstPosition); - final long $tcfVerbatim = Double.doubleToLongBits(this.getTcfVerbatim()); - result = result * PRIME + (int) ($tcfVerbatim >>> 32 ^ $tcfVerbatim); - final long $tcfProximity = Double.doubleToLongBits(this.getTcfProximity()); - result = result * PRIME + (int) ($tcfProximity >>> 32 ^ $tcfProximity); - final Object $temporalBias = this.getTemporalBias(); - result = result * PRIME + ($temporalBias == null ? 43 : $temporalBias.hashCode()); - final long $temporalBiasWeight = Double.doubleToLongBits(this.getTemporalBiasWeight()); - result = result * PRIME + (int) ($temporalBiasWeight >>> 32 ^ $temporalBiasWeight); - result = result * PRIME + (this.isExportDebugData() ? 79 : 97); + int result = Objects.hashCode(bm25Params); + result = 31 * result + shortDocumentThreshold; + result = 31 * result + Double.hashCode(shortDocumentPenalty); + result = 31 * result + Double.hashCode(domainRankBonus); + result = 31 * result + Double.hashCode(qualityPenalty); + result = 31 * result + shortSentenceThreshold; + result = 31 * result + Double.hashCode(shortSentencePenalty); + result = 31 * result + Double.hashCode(bm25Weight); + result = 31 * result + Double.hashCode(tcfFirstPosition); + result = 31 * result + Double.hashCode(tcfVerbatim); + result = 31 * result + Double.hashCode(tcfProximity); + result = 31 * result + Objects.hashCode(temporalBias); + result = 31 * result + Double.hashCode(temporalBiasWeight); + result = 31 * result + Boolean.hashCode(exportDebugData); return result; }