diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/SeConfig.java b/config/config-mp/src/main/java/io/helidon/config/mp/SeConfig.java index 3586a82399c..5d22b93e322 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/SeConfig.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/SeConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023 Oracle and/or its affiliates. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,8 +84,8 @@ class SeConfig implements Config { this.stringKey = prefix.child(key).toString(); this.stringPrefix = prefix.toString(); - if (delegate instanceof MpConfigImpl) { - this.delegateImpl = (MpConfigImpl) delegate; + if (delegate instanceof MpConfigImpl mpConfig) { + this.delegateImpl = mpConfig; } else { this.delegateImpl = null; } diff --git a/config/config/src/main/java/io/helidon/config/ConfigDiff.java b/config/config/src/main/java/io/helidon/config/ConfigDiff.java index 13126dbf629..156c5652121 100644 --- a/config/config/src/main/java/io/helidon/config/ConfigDiff.java +++ b/config/config/src/main/java/io/helidon/config/ConfigDiff.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. + * Copyright (c) 2017, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,8 +86,8 @@ private static boolean notEqual(Config left, Config right) { } private static Optional value(Config node) { - if (node instanceof AbstractConfigImpl) { - return ((AbstractConfigImpl) node).value(); + if (node instanceof AbstractConfigImpl abstractConfig) { + return abstractConfig.value(); } return node.asString().asOptional(); } diff --git a/config/config/src/main/java/io/helidon/config/ConfigKeyImpl.java b/config/config/src/main/java/io/helidon/config/ConfigKeyImpl.java index 6a00929344e..4afc251d020 100644 --- a/config/config/src/main/java/io/helidon/config/ConfigKeyImpl.java +++ b/config/config/src/main/java/io/helidon/config/ConfigKeyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,8 +109,8 @@ ConfigKeyImpl child(String key) { @Override public ConfigKeyImpl child(Config.Key key) { final List path; - if (key instanceof ConfigKeyImpl) { - path = ((ConfigKeyImpl) key).path; + if (key instanceof ConfigKeyImpl configKey) { + path = configKey.path; } else { path = new LinkedList<>(); while (!key.isRoot()) { diff --git a/config/config/src/main/java/io/helidon/config/ConfigSourceRuntimeImpl.java b/config/config/src/main/java/io/helidon/config/ConfigSourceRuntimeImpl.java index 1db11f18fe0..18e11381976 100644 --- a/config/config/src/main/java/io/helidon/config/ConfigSourceRuntimeImpl.java +++ b/config/config/src/main/java/io/helidon/config/ConfigSourceRuntimeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022 Oracle and/or its affiliates. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,16 +83,15 @@ class ConfigSourceRuntimeImpl implements ConfigSourceRuntime { // content source AtomicReference lastStamp = new AtomicReference<>(); - if (configSource instanceof ParsableSource) { + if (configSource instanceof ParsableSource parsableSource) { // eager parsable config source - reloader = new ParsableConfigSourceReloader(configContext, (ParsableSource) source, lastStamp); + reloader = new ParsableConfigSourceReloader(configContext, parsableSource, lastStamp); singleNodeFunction = objectNodeToSingleNode(); - } else if (configSource instanceof NodeConfigSource) { + } else if (configSource instanceof NodeConfigSource nodeConfigSource) { // eager node config source - reloader = new NodeConfigSourceReloader((NodeConfigSource) source, lastStamp); + reloader = new NodeConfigSourceReloader(nodeConfigSource, lastStamp); singleNodeFunction = objectNodeToSingleNode(); - } else if (configSource instanceof LazyConfigSource) { - LazyConfigSource lazySource = (LazyConfigSource) source; + } else if (configSource instanceof LazyConfigSource lazySource) { // lazy config source reloader = Optional::empty; singleNodeFunction = lazySource::node; @@ -143,8 +142,7 @@ class ConfigSourceRuntimeImpl implements ConfigSourceRuntime { } } - if (!changesSupported && (configSource instanceof EventConfigSource)) { - EventConfigSource event = (EventConfigSource) source; + if (!changesSupported && (configSource instanceof EventConfigSource event)) { changesSupported = true; changesRunnable = () -> event.onChange((key, config) -> listeners.forEach(it -> it.accept(key, config))); } @@ -222,8 +220,8 @@ private synchronized void initialLoad() { } // we may have media type mapping per node configured as well - if (configSource instanceof AbstractConfigSource) { - loadedData = loadedData.map(it -> ((AbstractConfigSource) configSource) + if (configSource instanceof AbstractConfigSource abstractConfigSource) { + loadedData = loadedData.map(it -> abstractConfigSource .processNodeMapping(configContext::findParser, ConfigKeyImpl.of(), it)); } diff --git a/config/config/src/main/java/io/helidon/config/UrlConfigSource.java b/config/config/src/main/java/io/helidon/config/UrlConfigSource.java index 5e8db59e02d..e34c3457963 100644 --- a/config/config/src/main/java/io/helidon/config/UrlConfigSource.java +++ b/config/config/src/main/java/io/helidon/config/UrlConfigSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -139,8 +139,8 @@ public Optional load() throws ConfigException { try { URLConnection urlConnection = url.openConnection(); - if (urlConnection instanceof HttpURLConnection) { - return httpContent((HttpURLConnection) urlConnection); + if (urlConnection instanceof HttpURLConnection httpURLConnection) { + return httpContent(httpURLConnection); } else { return genericContent(urlConnection); } diff --git a/config/config/src/main/java/io/helidon/config/UrlHelper.java b/config/config/src/main/java/io/helidon/config/UrlHelper.java index 2810fc5079d..c4b610e98e1 100644 --- a/config/config/src/main/java/io/helidon/config/UrlHelper.java +++ b/config/config/src/main/java/io/helidon/config/UrlHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,7 @@ static Optional dataStamp(URL url) { // the URL may not be an HTTP URL try { URLConnection urlConnection = url.openConnection(); - if (urlConnection instanceof HttpURLConnection) { - HttpURLConnection connection = (HttpURLConnection) urlConnection; + if (urlConnection instanceof HttpURLConnection connection) { try { connection.setRequestMethod(HEAD_METHOD); if (STATUS_NOT_FOUND == connection.getResponseCode()) {