Apache Solr open-source search software
IDE suggested cleanups (#2934)
Eric Pughaf2c0b381583
diff --git a/solr/core/src/java/org/apache/solr/handler/designer/DefaultSampleDocumentsLoader.java b/solr/core/src/java/org/apache/solr/handler/designer/DefaultSampleDocumentsLoader.javaindex d35a76a75c6..611cea3d58f 100644--- a/solr/core/src/java/org/apache/solr/handler/designer/DefaultSampleDocumentsLoader.java+++ b/solr/core/src/java/org/apache/solr/handler/designer/DefaultSampleDocumentsLoader.java@@ -117,14 +117,14 @@ public class DefaultSampleDocumentsLoader implements SampleDocumentsLoader {List<SolrInputDocument> docs = null;if (stream.getSize() > 0) {if (contentType.contains(JSON_MIME)) {- docs = loadJsonDocs(params, byteStream, maxDocsToLoad);+ docs = loadJsonDocs(byteStream, maxDocsToLoad);} else if (contentType.contains("text/xml") || contentType.contains("application/xml")) {- docs = loadXmlDocs(params, byteStream, maxDocsToLoad);+ docs = loadXmlDocs(byteStream, maxDocsToLoad);} else if (contentType.contains("text/csv") || contentType.contains("application/csv")) {docs = loadCsvDocs(params, fileSource, uploadedBytes, charset, maxDocsToLoad);} else if (contentType.contains("text/plain")|| contentType.contains("application/octet-stream")) {- docs = loadJsonLines(params, byteStream, maxDocsToLoad);+ docs = loadJsonLines(byteStream, maxDocsToLoad);} else {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, contentType + " not supported yet!");@@ -157,8 +157,7 @@ public class DefaultSampleDocumentsLoader implements SampleDocumentsLoader {@SuppressWarnings("unchecked")protected List<SolrInputDocument> loadJsonLines(- SolrParams params, ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad)- throws IOException {+ ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad) throws IOException {List<Map<String, Object>> docs = new ArrayList<>();try (Reader r = stream.getReader()) {BufferedReader br = new BufferedReader(r);@@ -182,8 +181,7 @@ public class DefaultSampleDocumentsLoader implements SampleDocumentsLoader {@SuppressWarnings("unchecked")protected List<SolrInputDocument> loadJsonDocs(- SolrParams params, ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad)- throws IOException {+ ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad) throws IOException {Object json;try (Reader r = stream.getReader()) {json = ObjectBuilder.getVal(new JSONParser(r));@@ -231,8 +229,7 @@ public class DefaultSampleDocumentsLoader implements SampleDocumentsLoader {}protected List<SolrInputDocument> loadXmlDocs(- SolrParams params, ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad)- throws IOException {+ ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad) throws IOException {String xmlString = new String(readAllBytes(stream), StandardCharsets.UTF_8).trim();List<SolrInputDocument> docs;if (xmlString.contains("<add>") && xmlString.contains("<doc>")) {diff --git a/solr/core/src/java/org/apache/solr/handler/designer/DefaultSchemaSuggester.java b/solr/core/src/java/org/apache/solr/handler/designer/DefaultSchemaSuggester.javaindex d3dc4acaf5b..543b7a77af1 100644--- a/solr/core/src/java/org/apache/solr/handler/designer/DefaultSchemaSuggester.java+++ b/solr/core/src/java/org/apache/solr/handler/designer/DefaultSchemaSuggester.java@@ -163,7 +163,7 @@ public class DefaultSchemaSuggester implements SchemaSuggester {Locale locale = Locale.ROOT;boolean isMV = isMultiValued(sampleValues);- String fieldTypeName = guessFieldType(fieldName, sampleValues, schema, isMV, locale);+ String fieldTypeName = guessFieldType(sampleValues, isMV, locale);FieldType fieldType = schema.getFieldTypeByName(fieldTypeName);if (fieldType == null) {// TODO: construct this field type on-the-fly ...@@ -222,12 +222,7 @@ public class DefaultSchemaSuggester implements SchemaSuggester {return mapByField;}- protected String guessFieldType(- String fieldName,- final List<Object> sampleValues,- IndexSchema schema,- boolean isMV,- Locale locale) {+ protected String guessFieldType(final List<Object> sampleValues, boolean isMV, Locale locale) {String type = null;// flatten values to a single stream for easier analysis; also remove nulls@@ -361,7 +356,7 @@ public class DefaultSchemaSuggester implements SchemaSuggester {}// if all values are less than some smallish threshold, then it's likely this field holds small- // numbers but be very conservative here as it's simply an optimization and we can always fall+ // numbers but be very conservative here as it's simply an optimization, and we can always fall// back to longreturn maxLong < 10000 ? "pint" : "plong";}diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SampleDocuments.java b/solr/core/src/java/org/apache/solr/handler/designer/SampleDocuments.javaindex e1794913beb..b98c5995db2 100644--- a/solr/core/src/java/org/apache/solr/handler/designer/SampleDocuments.java+++ b/solr/core/src/java/org/apache/solr/handler/designer/SampleDocuments.java@@ -17,8 +17,6 @@package org.apache.solr.handler.designer;-import static org.apache.solr.common.params.CommonParams.JSON_MIME;-import java.util.ArrayList;import java.util.List;import java.util.Objects;@@ -42,15 +40,6 @@ public class SampleDocuments {return fileSource != null ? fileSource : "paste";}- private boolean isTextContentType() {- if (contentType == null) {- return false;- }- return contentType.contains(JSON_MIME)- || contentType.startsWith("text/")- || contentType.contains("application/xml");- }-public List<SolrInputDocument> appendDocs(String idFieldName, List<SolrInputDocument> add, int maxDocsToLoad) {if (add != null && !add.isEmpty()) {@@ -65,7 +54,7 @@ public class SampleDocuments {doc -> {Object id = doc.getFieldValue(idFieldName);return id != null- && !ids.contains(id); // doc has ID and it's not already in the set+ && !ids.contains(id); // doc has ID, and it's not already in the set}).collect(Collectors.toList());parsed.addAll(toAdd);diff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.javaindex 1370c775540..e1589c192c0 100644--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerAPI.java@@ -22,7 +22,6 @@ import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;import static org.apache.solr.client.solrj.SolrRequest.METHOD.PUT;import static org.apache.solr.common.params.CommonParams.JSON_MIME;import static org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;-import static org.apache.solr.schema.ManagedIndexSchemaFactory.DEFAULT_MANAGED_SCHEMA_RESOURCE_NAME;import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;import static org.apache.solr.security.PermissionNameProvider.Name.CONFIG_READ_PERM;@@ -85,7 +84,7 @@ import org.noggit.ObjectBuilder;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-/** All V2 APIs that have a prefix of /api/schema-designer/ */+/** All V2 APIs have a prefix of /api/schema-designer/ */public class SchemaDesignerAPI implements SchemaDesignerConstants {private static final Set<String> excludeConfigSetNames =@@ -103,8 +102,8 @@ public class SchemaDesignerAPI implements SchemaDesignerConstants {public SchemaDesignerAPI(CoreContainer coreContainer) {this(coreContainer,- SchemaDesignerAPI.newSchemaSuggester(coreContainer),- SchemaDesignerAPI.newSampleDocumentsLoader(coreContainer));+ SchemaDesignerAPI.newSchemaSuggester(),+ SchemaDesignerAPI.newSampleDocumentsLoader());}SchemaDesignerAPI(@@ -119,13 +118,13 @@ public class SchemaDesignerAPI implements SchemaDesignerConstants {this.settingsDAO = new SchemaDesignerSettingsDAO(coreContainer, configSetHelper);}- public static SchemaSuggester newSchemaSuggester(CoreContainer coreContainer) {+ public static SchemaSuggester newSchemaSuggester() {DefaultSchemaSuggester suggester = new DefaultSchemaSuggester();suggester.init(new NamedList<>());return suggester;}- public static SampleDocumentsLoader newSampleDocumentsLoader(CoreContainer coreContainer) {+ public static SampleDocumentsLoader newSampleDocumentsLoader() {SampleDocumentsLoader loader = new DefaultSampleDocumentsLoader();loader.init(new NamedList<>());return loader;@@ -520,7 +519,8 @@ public class SchemaDesignerAPI implements SchemaDesignerConstants {final String configSet = getRequiredParam(CONFIG_SET_PARAM, req);final String mutableId = checkMutable(configSet, req);- // verify the configSet we're going to apply changes to has not changed since being loaded for+ // verify the configSet we're going to apply changes to hasn't been changed since being loaded+ // for// editing by the schema designerSchemaDesignerSettings settings = settingsDAO.getSettings(mutableId);final Optional<Integer> publishedVersion = settings.getPublishedVersion();@@ -845,7 +845,7 @@ public class SchemaDesignerAPI implements SchemaDesignerConstants {latestSchema.getUniqueKeyField().getName(), stored, MAX_SAMPLE_DOCS);}- // store in the blob store so we always have access to these docs+ // store in the blob store so that we always have access to these docsconfigSetHelper.storeSampleDocs(configSet, docs);}}@@ -892,10 +892,6 @@ public class SchemaDesignerAPI implements SchemaDesignerConstants {return schema;}- protected String getManagedSchemaZkPath(final String configSet) {- return getConfigSetZkPath(configSet, DEFAULT_MANAGED_SCHEMA_RESOURCE_NAME);- }-protected SchemaDesignerSettings getMutableSchemaForConfigSet(final String configSet, final int schemaVersion, String copyFrom) throws IOException {// The designer works with mutable config sets stored in a "temp" znode in ZK instead of thediff --git a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.javaindex 955aa1d98a9..b6afd8a4f11 100644--- a/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java+++ b/solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java@@ -1052,7 +1052,7 @@ class SchemaDesignerConfigSetHelper implements SchemaDesignerConstants {}}- // if we fall thru to here, then the file should be excluded+ // if we fall through to here, then the file should be excludedreturn false;}diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.javaindex 983d0fa3ab1..2e50d6abc82 100644--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java@@ -740,7 +740,7 @@ public class TestSchemaDesignerAPI extends SolrCloudTestCase implements SchemaDeString mutableId = getMutableId(configSet);SchemaDesignerConfigSetHelper configSetHelper =- new SchemaDesignerConfigSetHelper(cc, SchemaDesignerAPI.newSchemaSuggester(cc));+ new SchemaDesignerConfigSetHelper(cc, SchemaDesignerAPI.newSchemaSuggester());ManagedIndexSchema schema = schemaDesignerAPI.loadLatestSchema(mutableId);// make it requireddiff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.javaindex af6412da947..7d94f185e44 100644--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java@@ -78,7 +78,7 @@ public class TestSchemaDesignerConfigSetHelper extends SolrCloudTestCaseassertNotNull(cluster);cc = cluster.getJettySolrRunner(0).getCoreContainer();assertNotNull(cc);- helper = new SchemaDesignerConfigSetHelper(cc, SchemaDesignerAPI.newSchemaSuggester(cc));+ helper = new SchemaDesignerConfigSetHelper(cc, SchemaDesignerAPI.newSchemaSuggester());}@Test