From 1a066f263ac4fa8de381c086ba872881ecbcdc3a Mon Sep 17 00:00:00 2001
From: Yassin Hajaj <yassin.hajaj@bosa.fgov.be>
Date: Mon, 8 Jan 2024 02:29:43 +0100
Subject: [PATCH] Replaced String#length == 0 by String#isEmpty

---
 .../java/io/smallrye/config/inject/ConfigInjectionBean.java | 2 +-
 .../main/java/io/smallrye/config/ConfigMappingContext.java  | 6 +++---
 .../src/main/java/io/smallrye/config/EnvConfigSource.java   | 4 ++--
 .../io/smallrye/config/ProfileConfigSourceInterceptor.java  | 2 +-
 .../src/main/java/io/smallrye/config/SmallRyeConfig.java    | 6 +++---
 .../main/java/io/smallrye/config/SmallRyeConfigBuilder.java | 2 +-
 6 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java
index 26cb60b2f..d9d3c81fc 100644
--- a/cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java
+++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigInjectionBean.java
@@ -96,7 +96,7 @@ public T create(CreationalContext<T> context) {
             }
         } else {
             Class<?> annotatedTypeClass = (Class<?>) annotated.getBaseType();
-            if (defaultValue.length() == 0) {
+            if (defaultValue.isEmpty()) {
                 return (T) getConfig().getValue(key, annotatedTypeClass);
             } else {
                 Optional<T> optionalValue = (Optional<T>) getConfig().getOptionalValue(key, annotatedTypeClass);
diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java
index 213986952..2990e548a 100644
--- a/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java
+++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java
@@ -304,7 +304,7 @@ public <K, V> ObjectCreator<T> map(
                 creator.accept(new Function<String, Object>() {
                     @Override
                     public Object apply(final String path) {
-                        Map<String, String> mapKeys = getMapKeys(path.length() > 0 && path.charAt(path.length() - 1) == '.'
+                        Map<String, String> mapKeys = getMapKeys(!path.isEmpty() && path.charAt(path.length() - 1) == '.'
                                 ? path.substring(0, path.length() - 1)
                                 : path);
                         Map<K, V> map = defaultValue != null ? new MapWithDefault<>(defaultValue.get())
@@ -617,10 +617,10 @@ private Map<String, String> getMapKeys(final String name) {
             Map<String, String> mapKeys = new HashMap<>();
             for (String propertyName : config.getPropertyNames()) {
                 if (propertyName.length() > name.length() + 1
-                        && (name.length() == 0 || propertyName.charAt(name.length()) == '.')
+                        && (name.isEmpty() || propertyName.charAt(name.length()) == '.')
                         && propertyName.startsWith(name)) {
                     // Start at the map root name
-                    NameIterator key = name.length() > 0 ? new NameIterator(unindexed(propertyName), name.length())
+                    NameIterator key = !name.isEmpty() ? new NameIterator(unindexed(propertyName), name.length())
                             : new NameIterator(unindexed(propertyName));
                     // Move to the next key
                     key.next();
diff --git a/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java b/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java
index 16baebe59..83cc22e44 100644
--- a/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java
+++ b/implementation/src/main/java/io/smallrye/config/EnvConfigSource.java
@@ -265,11 +265,11 @@ static boolean equals(final String name, final String other) {
                 return true;
             }
 
-            if (name.length() == 0 && other.length() == 0) {
+            if (name.isEmpty() && other.isEmpty()) {
                 return true;
             }
 
-            if (name.length() == 0 || other.length() == 0) {
+            if (name.isEmpty() || other.isEmpty()) {
                 return false;
             }
 
diff --git a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java
index 280d35a42..deb6ad00e 100644
--- a/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java
+++ b/implementation/src/main/java/io/smallrye/config/ProfileConfigSourceInterceptor.java
@@ -83,7 +83,7 @@ public String[] getProfiles() {
     }
 
     public String normalizeName(final String name) {
-        if (name.length() > 0 && name.charAt(0) == '%') {
+        if (!name.isEmpty() && name.charAt(0) == '%') {
             int profilesEnd = name.indexOf('.', 1);
             int multipleSplit = -1;
             for (int i = 1; i < profilesEnd; i++) {
diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
index 532c1a272..dc9534788 100644
--- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
+++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
@@ -266,9 +266,9 @@ public Map<String, String> getMapKeys(final String name) {
         Map<String, String> mapKeys = new HashMap<>();
         for (String propertyName : getPropertyNames()) {
             if (propertyName.length() > name.length() + 1
-                    && (name.length() == 0 || propertyName.charAt(name.length()) == '.')
+                    && (name.isEmpty() || propertyName.charAt(name.length()) == '.')
                     && propertyName.startsWith(name)) {
-                String key = unquoted(unindexed(propertyName), name.length() == 0 ? 0 : name.length() + 1);
+                String key = unquoted(unindexed(propertyName), name.isEmpty() ? 0 : name.length() + 1);
                 mapKeys.put(key, unindexed(propertyName));
             }
         }
@@ -354,7 +354,7 @@ public <T> T convertValue(ConfigValue configValue, Converter<T> converter) {
         if (converted == null) {
             if (configValue.getValue() == null) {
                 throw new NoSuchElementException(ConfigMessages.msg.propertyNotFound(configValue.getNameProfiled())); // 2
-            } else if (configValue.getValue().length() == 0) {
+            } else if (configValue.getValue().isEmpty()) {
                 throw ConfigMessages.msg.propertyEmptyString(configValue.getNameProfiled(), converter.getClass().getTypeName()); // 3
             } else {
                 throw ConfigMessages.msg.converterReturnedNull(configValue.getNameProfiled(), configValue.getValue(),
diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java
index ad368b137..f2a709c89 100644
--- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java
+++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java
@@ -248,7 +248,7 @@ public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorConte
                 Iterator<String> names = context.iterateNames();
                 while (names.hasNext()) {
                     String name = names.next();
-                    if (name.length() > 0 && name.charAt(0) == '%') {
+                    if (!name.isEmpty() && name.charAt(0) == '%') {
                         NameIterator ni = new NameIterator(name);
                         String profileSegment = ni.getNextSegment();
                         List<String> profiles = convertProfile(profileSegment.substring(1));