Browse Source

code cleanup

Shinsuke Sugaya 2 năm trước cách đây
mục cha
commit
197fa76743

+ 8 - 4
src/main/java/org/codelibs/fess/helper/CrawlerStatsHelper.java

@@ -189,9 +189,11 @@ public class CrawlerStatsHelper {
         }
         }
         if (keyObj instanceof final StatsKeyObject statsKey) {
         if (keyObj instanceof final StatsKeyObject statsKey) {
             return escapeValue(statsKey.getUrl());
             return escapeValue(statsKey.getUrl());
-        } else if (keyObj instanceof final String key) {
+        }
+        if (keyObj instanceof final String key) {
             return escapeValue(key);
             return escapeValue(key);
-        } else if (keyObj instanceof final Number key) {
+        }
+        if (keyObj instanceof final Number key) {
             return key.toString();
             return key.toString();
         }
         }
         return "-";
         return "-";
@@ -203,9 +205,11 @@ public class CrawlerStatsHelper {
         }
         }
         if (keyObj instanceof final StatsKeyObject statsKey) {
         if (keyObj instanceof final StatsKeyObject statsKey) {
             return OptionalThing.of(statsKey.getId());
             return OptionalThing.of(statsKey.getId());
-        } else if (keyObj instanceof final String key) {
+        }
+        if (keyObj instanceof final String key) {
             return OptionalThing.of(key);
             return OptionalThing.of(key);
-        } else if (keyObj instanceof final Number key) {
+        }
+        if (keyObj instanceof final Number key) {
             return OptionalThing.of(key.toString());
             return OptionalThing.of(key.toString());
         }
         }
         return OptionalThing.empty();
         return OptionalThing.empty();

+ 22 - 18
src/main/java/org/codelibs/fess/helper/CrawlingConfigHelper.java

@@ -107,19 +107,21 @@ public class CrawlingConfigHelper {
                 if (id == null) {
                 if (id == null) {
                     return null;
                     return null;
                 }
                 }
-                switch (configType) {
-                case WEB:
+                return switch (configType) {
+                case WEB -> {
                     final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
                     final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
-                    return webConfigService.getWebConfig(id).get();
-                case FILE:
+                    yield webConfigService.getWebConfig(id).get();
+                }
+                case FILE -> {
                     final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
                     final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
-                    return fileConfigService.getFileConfig(id).get();
-                case DATA:
+                    yield fileConfigService.getFileConfig(id).get();
+                }
+                case DATA -> {
                     final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
                     final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
-                    return dataConfigService.getDataConfig(id).get();
-                default:
-                    return null;
+                    yield dataConfigService.getDataConfig(id).get();
                 }
                 }
+                default -> null;
+                };
             });
             });
         } catch (final ExecutionException e) {
         } catch (final ExecutionException e) {
             logger.warn("Failed to access a crawling config cache: {}", configId, e);
             logger.warn("Failed to access a crawling config cache: {}", configId, e);
@@ -278,18 +280,20 @@ public class CrawlingConfigHelper {
     public OptionalEntity<CrawlingConfig> getDefaultConfig(final ConfigType configType) {
     public OptionalEntity<CrawlingConfig> getDefaultConfig(final ConfigType configType) {
         final String name = ComponentUtil.getFessConfig().getFormAdminDefaultTemplateName();
         final String name = ComponentUtil.getFessConfig().getFormAdminDefaultTemplateName();
 
 
-        switch (configType) {
-        case WEB:
+        return switch (configType) {
+        case WEB -> {
             final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
             final WebConfigService webConfigService = ComponentUtil.getComponent(WebConfigService.class);
-            return webConfigService.getWebConfigByName(name).map(o -> (CrawlingConfig) o);
-        case FILE:
+            yield webConfigService.getWebConfigByName(name).map(o -> (CrawlingConfig) o);
+        }
+        case FILE -> {
             final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
             final FileConfigService fileConfigService = ComponentUtil.getComponent(FileConfigService.class);
-            return fileConfigService.getFileConfigByName(name).map(o -> (CrawlingConfig) o);
-        case DATA:
+            yield fileConfigService.getFileConfigByName(name).map(o -> (CrawlingConfig) o);
+        }
+        case DATA -> {
             final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
             final DataConfigService dataConfigService = ComponentUtil.getComponent(DataConfigService.class);
-            return dataConfigService.getDataConfigByName(name).map(o -> (CrawlingConfig) o);
-        default:
-            return OptionalEntity.empty();
+            yield dataConfigService.getDataConfigByName(name).map(o -> (CrawlingConfig) o);
         }
         }
+        default -> OptionalEntity.empty();
+        };
     }
     }
 }
 }

+ 6 - 4
src/main/java/org/codelibs/fess/helper/WebFsIndexHelper.java

@@ -50,6 +50,8 @@ public class WebFsIndexHelper {
 
 
     private static final Logger logger = LogManager.getLogger(WebFsIndexHelper.class);
     private static final Logger logger = LogManager.getLogger(WebFsIndexHelper.class);
 
 
+    private static final String DISABLE_URL_ENCODE = "#DISABLE_URL_ENCODE";
+
     protected long maxAccessCount = Long.MAX_VALUE;
     protected long maxAccessCount = Long.MAX_VALUE;
 
 
     protected long crawlingExecutionInterval = Constants.DEFAULT_CRAWLING_EXECUTION_INTERVAL;
     protected long crawlingExecutionInterval = Constants.DEFAULT_CRAWLING_EXECUTION_INTERVAL;
@@ -176,7 +178,7 @@ public class WebFsIndexHelper {
                     if (logger.isInfoEnabled()) {
                     if (logger.isInfoEnabled()) {
                         logger.info("Included URL: {}", urlValue);
                         logger.info("Included URL: {}", urlValue);
                     }
                     }
-                } else if (line.startsWith("#DISABLE_URL_ENCODE")) {
+                } else if (line.startsWith(DISABLE_URL_ENCODE)) {
                     urlEncodeDisabled.set(true);
                     urlEncodeDisabled.set(true);
                 }
                 }
             }));
             }));
@@ -196,7 +198,7 @@ public class WebFsIndexHelper {
                     if (logger.isInfoEnabled()) {
                     if (logger.isInfoEnabled()) {
                         logger.info("Excluded URL: {}", urlValue);
                         logger.info("Excluded URL: {}", urlValue);
                     }
                     }
-                } else if (line.startsWith("#DISABLE_URL_ENCODE")) {
+                } else if (line.startsWith(DISABLE_URL_ENCODE)) {
                     urlEncodeDisabled.set(true);
                     urlEncodeDisabled.set(true);
                 }
                 }
             }));
             }));
@@ -309,7 +311,7 @@ public class WebFsIndexHelper {
                     if (logger.isInfoEnabled()) {
                     if (logger.isInfoEnabled()) {
                         logger.info("Included Path: {}", urlValue);
                         logger.info("Included Path: {}", urlValue);
                     }
                     }
-                } else if (line.startsWith("#DISABLE_URL_ENCODE")) {
+                } else if (line.startsWith(DISABLE_URL_ENCODE)) {
                     urlEncodeDisabled.set(true);
                     urlEncodeDisabled.set(true);
                 }
                 }
             }));
             }));
@@ -329,7 +331,7 @@ public class WebFsIndexHelper {
                     if (logger.isInfoEnabled()) {
                     if (logger.isInfoEnabled()) {
                         logger.info("Excluded Path: {}", urlValue);
                         logger.info("Excluded Path: {}", urlValue);
                     }
                     }
-                } else if (line.startsWith("#DISABLE_URL_ENCODE")) {
+                } else if (line.startsWith(DISABLE_URL_ENCODE)) {
                     urlEncodeDisabled.set(true);
                     urlEncodeDisabled.set(true);
                 }
                 }
             }));
             }));

+ 4 - 7
src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java

@@ -334,13 +334,10 @@ public interface FessProp {
     }
     }
 
 
     default boolean isResultCollapsed() {
     default boolean isResultCollapsed() {
-        switch (getFesenType()) {
-        case Constants.FESEN_TYPE_CLOUD:
-        case Constants.FESEN_TYPE_AWS:
-            return false;
-        default:
-            return getSystemPropertyAsBoolean(Constants.RESULT_COLLAPSED_PROPERTY, false);
-        }
+        return switch (getFesenType()) {
+        case Constants.FESEN_TYPE_CLOUD, Constants.FESEN_TYPE_AWS -> false;
+        default -> getSystemPropertyAsBoolean(Constants.RESULT_COLLAPSED_PROPERTY, false);
+        };
     }
     }
 
 
     default void setLoginLinkEnabled(final boolean value) {
     default void setLoginLinkEnabled(final boolean value) {

+ 2 - 7
src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java

@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.util.Hashtable;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -171,9 +170,7 @@ public class FessMultipartRequestHandler implements MultipartRequestHandler {
 
 
     protected void mappingParameter(final HttpServletRequest request, final List<FileItem> items) {
     protected void mappingParameter(final HttpServletRequest request, final List<FileItem> items) {
         showFieldLoggingTitle();
         showFieldLoggingTitle();
-        final Iterator<FileItem> iter = items.iterator();
-        while (iter.hasNext()) {
-            final FileItem item = iter.next();
+        for (final FileItem item : items) {
             if (item.isFormField()) {
             if (item.isFormField()) {
                 showFormFieldParameter(item);
                 showFormFieldParameter(item);
                 addTextParameter(request, item);
                 addTextParameter(request, item);
@@ -235,9 +232,7 @@ public class FessMultipartRequestHandler implements MultipartRequestHandler {
     //                                                                           =========
     //                                                                           =========
     @Override
     @Override
     public void rollback() {
     public void rollback() {
-        final Iterator<MultipartFormFile> iter = elementsFile.values().iterator();
-        while (iter.hasNext()) {
-            final MultipartFormFile formFile = iter.next();
+        for (final MultipartFormFile formFile : elementsFile.values()) {
             formFile.destroy();
             formFile.destroy();
         }
         }
     }
     }

+ 5 - 8
src/main/java/org/codelibs/fess/sso/saml/SamlAuthenticator.java

@@ -210,14 +210,11 @@ public class SamlAuthenticator implements SsoAuthenticator {
 
 
     @Override
     @Override
     public ActionResponse getResponse(final SsoResponseType responseType) {
     public ActionResponse getResponse(final SsoResponseType responseType) {
-        switch (responseType) {
-        case METADATA:
-            return getMetadataResponse();
-        case LOGOUT:
-            return getLogoutResponse();
-        default:
-            return null;
-        }
+        return switch (responseType) {
+        case METADATA -> getMetadataResponse();
+        case LOGOUT -> getLogoutResponse();
+        default -> null;
+        };
     }
     }
 
 
     protected ActionResponse getMetadataResponse() {
     protected ActionResponse getMetadataResponse() {

+ 4 - 9
src/main/java/org/codelibs/fess/thumbnail/impl/HtmlTagBasedGenerator.java

@@ -133,15 +133,10 @@ public class HtmlTagBasedGenerator extends BaseThumbnailGenerator {
             return true;
             return true;
         }
         }
 
 
-        switch (mimeType) {
-        case "image/png":
-        case "image/gif":
-        case "image/jpeg":
-        case "image/bmp":
-            return true;
-        default:
-            return false;
-        }
+        return switch (mimeType) {
+        case "image/png", "image/gif", "image/jpeg", "image/bmp" -> true;
+        default -> false;
+        };
     }
     }
 
 
     protected Result saveImage(final ImageInputStream input, final File outputFile) throws IOException {
     protected Result saveImage(final ImageInputStream input, final File outputFile) throws IOException {