Skip to content

Commit

Permalink
3.x: Replace manual casts on pattern with instanceof in helidon/confi…
Browse files Browse the repository at this point in the history
…g modules (helidon-io#9237)
  • Loading branch information
Captain1653 authored Sep 4, 2024
1 parent 2e69f5d commit 5d3e1be
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions config/config/src/main/java/io/helidon/config/ConfigDiff.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -86,8 +86,8 @@ private static boolean notEqual(Config left, Config right) {
}

private static Optional<String> value(Config node) {
if (node instanceof AbstractConfigImpl) {
return ((AbstractConfigImpl) node).value();
if (node instanceof AbstractConfigImpl abstractConfig) {
return abstractConfig.value();
}
return node.asString().asOptional();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -109,8 +109,8 @@ ConfigKeyImpl child(String key) {
@Override
public ConfigKeyImpl child(Config.Key key) {
final List<String> path;
if (key instanceof ConfigKeyImpl) {
path = ((ConfigKeyImpl) key).path;
if (key instanceof ConfigKeyImpl configKey) {
path = configKey.path;
} else {
path = new LinkedList<>();
while (!key.isRoot()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -83,16 +83,15 @@ class ConfigSourceRuntimeImpl implements ConfigSourceRuntime {

// content source
AtomicReference<Object> 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;
Expand Down Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -139,8 +139,8 @@ public Optional<Content> 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);
}
Expand Down
5 changes: 2 additions & 3 deletions config/config/src/main/java/io/helidon/config/UrlHelper.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -45,8 +45,7 @@ static Optional<Instant> 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()) {
Expand Down

0 comments on commit 5d3e1be

Please sign in to comment.