Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some style warnings #777

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'idea'
id 'maven-publish'
id 'signing'
id "com.diffplug.spotless" version "6.22.0"
id "com.diffplug.spotless" version "6.25.0"
id 'java-library'
id 'jacoco'
// Build docs locally by running "site" command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public static void initialize(NrtsearchConfig configuration, Iterable<Plugin> pl
SynonymV2GraphFilterFactory.NAME, SynonymV2GraphFilterFactory.class, builtInTokenFilters);

for (Plugin plugin : plugins) {
if (plugin instanceof AnalysisPlugin) {
AnalysisPlugin analysisPlugin = (AnalysisPlugin) plugin;
if (plugin instanceof AnalysisPlugin analysisPlugin) {
instance.registerAnalyzers(analysisPlugin.getAnalyzers());
instance.registerTokenFilters(analysisPlugin.getTokenFilters(), builtInTokenFilters);
instance.registerCharFilters(analysisPlugin.getCharFilters(), builtInCharFilters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class MappingV2CharFilterFactory extends CharFilterFactory {
/**
* Initialize this factory via a set of key-value pairs.
*
* @param args
* @param args filter arguments
*/
public MappingV2CharFilterFactory(Map<String, String> args) {
super(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ public void addInternal(String[] synonyms) throws IOException {
}

private static String[] split(String s, String separator) {
ArrayList<String> list = new ArrayList(2);
ArrayList<String> list = new ArrayList<>(2);
StringBuilder sb = new StringBuilder();
int pos = 0;
int end = s.length();

while (pos < end) {
if (s.startsWith(separator, pos)) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
list.add(sb.toString());
sb = new StringBuilder();
}
Expand All @@ -118,15 +118,15 @@ private static String[] split(String s, String separator) {
}
}

if (sb.length() > 0) {
if (!sb.isEmpty()) {
list.add(sb.toString());
}

return list.toArray(new String[list.size()]);
return list.toArray(new String[0]);
}

private String unescape(String s) {
if (s.indexOf("\\") < 0) {
if (!s.contains("\\")) {
return s;
} else {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PostingsFormat getPostingsFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof IndexableFieldDef indexableFieldDef) {
if (fd instanceof IndexableFieldDef<?> indexableFieldDef) {
PostingsFormat postingsFormat = indexableFieldDef.getPostingsFormat();
if (postingsFormat != null) {
return postingsFormat;
Expand All @@ -65,7 +65,7 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof IndexableFieldDef indexableFieldDef) {
if (fd instanceof IndexableFieldDef<?> indexableFieldDef) {
DocValuesFormat docValuesFormat = indexableFieldDef.getDocValuesFormat();
if (docValuesFormat != null) {
return docValuesFormat;
Expand All @@ -86,7 +86,7 @@ public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
IndexState state = stateManager.getCurrent();
try {
FieldDef fd = state.getFieldOrThrow(field);
if (fd instanceof VectorFieldDef vectorFieldDef) {
if (fd instanceof VectorFieldDef<?> vectorFieldDef) {
KnnVectorsFormat vectorsFormat = vectorFieldDef.getVectorsFormat();
if (vectorsFormat != null) {
return vectorsFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public long getMaxConnectionAgeGraceForReplication() {

private static List<String> getPluginSearchPath(Object o) {
List<String> paths = new ArrayList<>();
if (o instanceof List list) {
if (o instanceof List<?> list) {
for (Object item : list) {
paths.add(item.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public T apply(Object o) {
if (o instanceof String) {
return stringConverter.apply((String) o);
}
if (o instanceof Number) {
Number num = (Number) o;
if (o instanceof Number num) {
if (clazz.isInstance(num)) {
return clazz.cast(num);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ static long sizeStrToBytes(String sizeStr) {
long multiplier = 1;
if (baseStr.length() > 2) {
String suffix = baseStr.substring(baseStr.length() - 2).toLowerCase();
if ("kb".equals(suffix)) {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024;
} else if ("mb".equals(suffix)) {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024 * 1024;
} else if ("gb".equals(suffix)) {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024 * 1024 * 1024;
switch (suffix) {
case "kb" -> {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024;
}
case "mb" -> {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024 * 1024;
}
case "gb" -> {
baseStr = baseStr.substring(0, baseStr.length() - 2);
multiplier = 1024 * 1024 * 1024;
}
}
}
if (baseStr.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ public static ScriptCacheConfig fromConfig(YamlConfigReader configReader) {
* null
*/
public static TimeUnit getTimeUnitFromString(String timeUnitStr) {
TimeUnit timeUnit =
TimeUnit.valueOf(
Objects.requireNonNull(
timeUnitStr, "script cache expiration time unit cannot be null"));
return timeUnit;
return TimeUnit.valueOf(
Objects.requireNonNull(timeUnitStr, "script cache expiration time unit cannot be null"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
public class YamlConfigReader {
private static final Logger logger = LoggerFactory.getLogger(YamlConfigReader.class.getName());

private static Function<Object, String> STR_READER =
private static final Function<Object, String> STR_READER =
(node) -> {
if (!(node instanceof Collection) && !(node instanceof Map)) {
return node.toString();
}
return null;
};
private static Function<Object, Boolean> BOOL_READER =
private static final Function<Object, Boolean> BOOL_READER =
(node) -> {
if (node instanceof Boolean) {
return (Boolean) node;
Expand All @@ -83,16 +83,16 @@ public class YamlConfigReader {
}
return null;
};
private static Function<Object, Integer> INT_READER =
private static final Function<Object, Integer> INT_READER =
new NumberReaderFunc<>(Integer.class, Number::intValue, Integer::parseInt);
private static Function<Object, Long> LONG_READER =
private static final Function<Object, Long> LONG_READER =
new NumberReaderFunc<>(Long.class, Number::longValue, Long::parseLong);
private static Function<Object, Float> FLOAT_READER =
private static final Function<Object, Float> FLOAT_READER =
new NumberReaderFunc<>(Float.class, Number::floatValue, Float::parseFloat);
private static Function<Object, Double> DOUBLE_READER =
private static final Function<Object, Double> DOUBLE_READER =
new NumberReaderFunc<>(Double.class, Number::doubleValue, Double::parseDouble);

private static String SPLIT_REGEX = "[.]";
private static final String SPLIT_REGEX = "[.]";

private final Map<?, ?> configRoot;

Expand Down Expand Up @@ -496,7 +496,7 @@ public List<String> getKeys(String path) throws ConfigKeyNotFoundException {
throw new ConfigReadException("Not instance of Map, path: " + path);
}
List<String> keys = new ArrayList<>();
for (Object mapKey : ((Map) node).keySet()) {
for (Object mapKey : ((Map<?, ?>) node).keySet()) {
if (!(mapKey instanceof String)) {
throw new ConfigReadException("Map contain non String key: " + mapKey + ", path: " + path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean containsKey(Object key) {
String fieldName = key.toString();
try {
FieldDef field = fieldDefLookup.apply(fieldName);
return field instanceof IndexableFieldDef && ((IndexableFieldDef) field).hasDocValues();
return field instanceof IndexableFieldDef && ((IndexableFieldDef<?>) field).hasDocValues();
} catch (Exception ignored) {
return false;
}
Expand Down Expand Up @@ -112,10 +112,9 @@ public LoadedDocValues<?> get(Object key) {
if (fieldDef == null) {
throw new IllegalArgumentException("Field does not exist: " + fieldName);
}
if (!(fieldDef instanceof IndexableFieldDef)) {
if (!(fieldDef instanceof IndexableFieldDef<?> indexableFieldDef)) {
throw new IllegalArgumentException("Field cannot have doc values: " + fieldName);
}
IndexableFieldDef indexableFieldDef = (IndexableFieldDef) fieldDef;
try {
docValues = indexableFieldDef.getDocValues(context);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getScriptFacetResult(
}

private static com.yelp.nrtsearch.server.grpc.FacetResult getDocValuesFacetResult(
Facet facet, FacetsCollector drillDowns, IndexableFieldDef fieldDef) throws IOException {
Facet facet, FacetsCollector drillDowns, IndexableFieldDef<?> fieldDef) throws IOException {
Map<Object, Integer> countsMap = new HashMap<>();
int totalDocs = 0;
// get doc values for all match docs, and aggregate counts
Expand Down Expand Up @@ -270,7 +270,7 @@ public static com.yelp.nrtsearch.server.grpc.FacetResult buildFacetResultFromCou
builder.setValue(totalDocs);
builder.setChildCount(countsMap.size());

if (countsMap.size() > 0 && facet.getTopN() > 0) {
if (!countsMap.isEmpty() && facet.getTopN() > 0) {
// add all map entries into a priority queue, keeping only the top N
PriorityQueue<Map.Entry<Object, Integer>> priorityQueue =
new PriorityQueue<>(
Expand Down Expand Up @@ -390,8 +390,7 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getFieldFacetResult(
c = drillDowns;
}
DoubleRangeFacetCounts doubleRangeFacetCounts;
if (fieldDef instanceof VirtualFieldDef) {
VirtualFieldDef virtualFieldDef = (VirtualFieldDef) fieldDef;
if (fieldDef instanceof VirtualFieldDef virtualFieldDef) {
doubleRangeFacetCounts =
new DoubleRangeFacetCounts(
virtualFieldDef.getName(), virtualFieldDef.getValuesSource(), c, ranges);
Expand All @@ -407,8 +406,7 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getFieldFacetResult(
facet.getPathsList().toArray(new String[facet.getPathsCount()]));
} else {
throw new IllegalArgumentException(
String.format(
"numericRanges must be provided only on field type numeric e.g. int, double, flat"));
"numericRanges must be provided only on field type numeric e.g. int, double, flat");
}
} else if (fieldDef.getFacetValueType()
== IndexableFieldDef.FacetValueType.SORTED_SET_DOC_VALUES) {
Expand Down Expand Up @@ -486,8 +484,7 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getFieldFacetResult(
// counts for this indexFieldName:
String indexFieldName =
indexState.getFacetsConfig().getDimConfig(fieldDef.getName()).indexFieldName;
Map<String, Facets> facetsMap = indexFieldNameToFacets;
luceneFacets = facetsMap.get(indexFieldName);
luceneFacets = indexFieldNameToFacets.get(indexFieldName);
if (luceneFacets == null) {
if (useCachedOrds) {
luceneFacets =
Expand All @@ -504,7 +501,7 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getFieldFacetResult(
indexState.getFacetsConfig(),
drillDowns);
}
facetsMap.put(indexFieldName, luceneFacets);
indexFieldNameToFacets.put(indexFieldName, luceneFacets);
}
}
if (facet.getTopN() != 0) {
Expand All @@ -517,22 +514,16 @@ private static com.yelp.nrtsearch.server.grpc.FacetResult getFieldFacetResult(
}
facetResult =
new FacetResult(
fieldDef.getName(),
path,
-1,
results.toArray(new LabelAndValue[results.size()]),
-1);
fieldDef.getName(), path, -1, results.toArray(new LabelAndValue[0]), -1);
} else {
throw new IllegalArgumentException(
String.format("each facet request must have either topN or labels"));
throw new IllegalArgumentException("each facet request must have either topN or labels");
}
} else {
// if no facet type is enabled on the field, try using the field doc values
if (!(fieldDef instanceof IndexableFieldDef)) {
if (!(fieldDef instanceof IndexableFieldDef<?> indexableFieldDef)) {
throw new IllegalArgumentException(
"Doc values facet requires an indexable field : " + fieldName);
}
IndexableFieldDef indexableFieldDef = (IndexableFieldDef) fieldDef;
if (!indexableFieldDef.hasDocValues()) {
throw new IllegalArgumentException(
"Doc values facet requires doc values enabled : " + fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.search.IndexSearcher;
Expand Down Expand Up @@ -64,7 +63,7 @@ public static Iterable<FacetResult> facetTopDocsSample(
Diagnostics.Builder diagnostics)
throws IOException {
List<Facet> sampleFacets =
facets.stream().filter(facet -> facet.getSampleTopDocs() > 0).collect(Collectors.toList());
facets.stream().filter(facet -> facet.getSampleTopDocs() > 0).toList();
if (sampleFacets.isEmpty()) {
return Collections.emptyList();
}
Expand All @@ -83,11 +82,10 @@ private static FacetResult facetFromTopDocs(
TopDocs topDocs, Facet facet, IndexState indexState, IndexSearcher searcher)
throws IOException {
FieldDef fieldDef = indexState.getFieldOrThrow(facet.getDim());
if (!(fieldDef instanceof IndexableFieldDef)) {
if (!(fieldDef instanceof IndexableFieldDef<?> indexableFieldDef)) {
throw new IllegalArgumentException(
"Sampling facet field must be indexable: " + facet.getDim());
}
IndexableFieldDef indexableFieldDef = (IndexableFieldDef) fieldDef;
if (!indexableFieldDef.hasDocValues()) {
throw new IllegalArgumentException(
"Sampling facet field must have doc values enabled: " + facet.getDim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public void parseDocumentField(
*/
private void parseFieldValueToDocumentField(Document document, String fieldValue) {
ContextSuggestFieldData csfData = GSON.fromJson(fieldValue, ContextSuggestFieldData.class);
CharSequence[] contexts =
csfData.getContexts().toArray(new CharSequence[csfData.getContexts().size()]);
CharSequence[] contexts = csfData.getContexts().toArray(new CharSequence[0]);
ContextSuggestField csf =
new ContextSuggestField(getName(), csfData.getValue(), csfData.getWeight(), contexts);
document.add(csf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ private static DateTimeFormatter createDateTimeFormatter(String dateTimeFormat)
if (dateTimeFormat.equals(EPOCH_MILLIS)) {
return null;
} else if (dateTimeFormat.equals(STRICT_DATE_OPTIONAL_TIME)) {
/**
* This is a replication of {@link DateTimeFormatter#ISO_LOCAL_DATE_TIME} with time optional.
*/
// This is a replication of {@link DateTimeFormatter#ISO_LOCAL_DATE_TIME} with time optional.
return new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
Expand Down Expand Up @@ -271,8 +269,7 @@ private long getTimeFromEpochMillisString(String epochMillisString) {
"%s could not parse %s as date_time with format %s",
getName(), epochMillisString, dateTimeFormat);
try {
long epochMillis = Long.parseLong(epochMillisString);
return epochMillis;
return Long.parseLong(epochMillisString);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(format, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ private String getCustomFieldType(Map<String, ?> additionalProperties) {
public static void initialize(NrtsearchConfig configuration, Iterable<Plugin> plugins) {
instance = new FieldDefCreator(configuration);
for (Plugin plugin : plugins) {
if (plugin instanceof FieldTypePlugin) {
FieldTypePlugin fieldTypePlugin = (FieldTypePlugin) plugin;
if (plugin instanceof FieldTypePlugin fieldTypePlugin) {
instance.register(fieldTypePlugin.getFieldTypes());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected FacetValueType parseFacetValueType(Field requestField) {
/**
* Convert the string to number
*
* @param numberString
* @param numberString number string
* @return number value of the string
*/
protected Number parseNumberString(String numberString) {
Expand Down
Loading
Loading