sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Replace `String.regionMatches(…)` by the simpler `String.startsWith(…)` when applicable.
Date Sat, 21 Nov 2020 21:58:44 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d3c0c2a15e8d9b8e06a10638d931f870e94befe6
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Nov 20 11:29:38 2020 +0100

    Replace `String.regionMatches(…)` by the simpler `String.startsWith(…)` when applicable.
---
 .../src/main/java/org/apache/sis/internal/book/CodeColorizer.java   | 6 +++---
 .../src/main/java/org/apache/sis/feature/StringJoinOperation.java   | 2 +-
 .../java/org/apache/sis/internal/metadata/sql/ScriptRunner.java     | 6 +++---
 .../src/test/java/org/apache/sis/test/xml/SchemaCompliance.java     | 5 ++---
 .../src/main/java/org/apache/sis/io/wkt/Element.java                | 2 +-
 .../org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java | 3 +--
 .../src/main/java/org/apache/sis/internal/util/DefinitionURI.java   | 2 +-
 .../src/main/java/org/apache/sis/measure/RangeFormat.java           | 6 +++---
 .../java/org/apache/sis/storage/earthobservation/LandsatReader.java | 2 +-
 .../main/java/org/apache/sis/internal/netcdf/RasterResource.java    | 2 +-
 .../main/java/org/apache/sis/internal/storage/io/IOUtilities.java   | 2 +-
 11 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/CodeColorizer.java
b/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/CodeColorizer.java
index 7a25df6..c9be9ab 100644
--- a/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/CodeColorizer.java
+++ b/core/sis-build-helper/src/main/java/org/apache/sis/internal/book/CodeColorizer.java
@@ -306,15 +306,15 @@ public final class CodeColorizer {
                             if (c == '"') {
                                 stopCondition = "\"";
                                 syntacticElement = document.createElement("i");
-                            } else if (isJava && text.regionMatches(lower, "/*",
0, 2)) {
+                            } else if (isJava && text.startsWith("/*", lower)) {
                                 stopCondition = "*/";
                                 syntacticElement = document.createElement("code");
                                 syntacticElement.setAttribute("class", "comment");
-                            } else if (isJava && text.regionMatches(lower, "//",
0, 2)) {
+                            } else if (isJava && text.startsWith("//", lower)) {
                                 stopCondition = "\n";
                                 syntacticElement = document.createElement("code");
                                 syntacticElement.setAttribute("class", "comment");
-                            } else if (isXML && text.regionMatches(lower, "<!--",
0, 4)) {
+                            } else if (isXML && text.startsWith("<!--", lower))
{
                                 stopCondition = "-->";
                                 syntacticElement = document.createElement("code");
                                 syntacticElement.setAttribute("class", "comment");
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
b/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
index 29bf49d..91913c3 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/StringJoinOperation.java
@@ -445,7 +445,7 @@ final class StringJoinOperation extends AbstractOperation {
                         if (element.charAt(i) == ESCAPE) {
                             i++;
                         } else {
-                            assert element.regionMatches(i, delimiter, 0, delimiter.length())
: element;
+                            assert element.startsWith(delimiter, i) : element;
                             i += delimiter.length();
                         }
                     }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
index 3e6b8b7..dccd2d9 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
@@ -480,7 +480,7 @@ public class ScriptRunner implements AutoCloseable {
              */
             if (buffer.length() == 0) {
                 final int s = CharSequences.skipLeadingWhitespaces(line, 0, line.length());
-                if (s >= line.length() || line.regionMatches(s, COMMENT, 0, COMMENT.length()))
{
+                if (s >= line.length() || line.startsWith(COMMENT, s)) {
                     continue;
                 }
                 if (in instanceof LineNumberReader) {
@@ -734,8 +734,8 @@ parseLine:  while (pos < length) {
                 if (maxRowsPerInsert == 0) {
                     subSQL = null;              // Skip completely the "INSERT INTO" statement.
                 } else {
-                    int endOfLine = subSQL.indexOf('\n', 11);                    // 11 is
the length of "INSERT INTO".
-                    if (subSQL.regionMatches(endOfLine - 6, "VALUES", 0, 6)) {   //  6 is
the length of "VALUES".
+                    int endOfLine = subSQL.indexOf('\n', 11);           // 11 is the length
of "INSERT INTO".
+                    if (subSQL.startsWith("VALUES", endOfLine - 6)) {
                         /*
                          * The following code is very specific to the syntax of the scripts
generated by SIS.
                          * This code fetches the "INSERT INTO" part, which is expected to
be on its own line.
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
index 64b4e36..0389c97 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/xml/SchemaCompliance.java
@@ -165,9 +165,8 @@ public final strictfp class SchemaCompliance extends SchemaInformation
{
         if (type.endsWith(suffix)) {
             int nameStart = name.indexOf(PREFIX_SEPARATOR) + 1;        // Skip "mdb:" or
similar prefix.
             int typeStart = type.indexOf(PREFIX_SEPARATOR) + 1;
-            final int plg = ABSTRACT_PREFIX.length();
-            if (name.regionMatches(nameStart, ABSTRACT_PREFIX, 0, plg)) nameStart += plg;
-            if (type.regionMatches(typeStart, ABSTRACT_PREFIX, 0, plg)) typeStart += plg;
+            if (name.startsWith(ABSTRACT_PREFIX, nameStart)) nameStart += ABSTRACT_PREFIX.length();
+            if (type.startsWith(ABSTRACT_PREFIX, typeStart)) typeStart += ABSTRACT_PREFIX.length();
             final int length = name.length() - nameStart;
             if (type.length() - typeStart - suffix.length() == length &&
                     type.regionMatches(typeStart, name, nameStart, length))
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Element.java b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Element.java
index 192df2d..68c309c 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Element.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Element.java
@@ -353,7 +353,7 @@ final class Element {
              * search for another element. Otherwise verify that the closing bracket is present.
              */
             lower = skipLeadingWhitespaces(text, lower, length);
-            if (text.regionMatches(lower, separator, 0, separator.length())) {
+            if (text.startsWith(separator, lower)) {
                 lower = skipLeadingWhitespaces(text, lower + separator.length(), length);
             } else {
                 if (lower >= length) break;
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
index 62a7f78..371276a 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/MultiAuthoritiesFactory.java
@@ -830,8 +830,7 @@ public class MultiAuthoritiesFactory extends GeodeticAuthorityFactory
implements
             int afterVersion = code.indexOf(Constants.DEFAULT_SEPARATOR, ++afterAuthority);
             start = CharSequences.skipLeadingWhitespaces(code, afterAuthority, afterVersion);
             end = CharSequences.skipTrailingWhitespaces(code, start, afterVersion);
-            version = (start < end && !code.regionMatches(start, DefinitionURI.NO_VERSION,
0,
-                    DefinitionURI.NO_VERSION.length())) ? code.substring(start, end) : null;
+            version = (start < end && !code.startsWith(DefinitionURI.NO_VERSION,
start)) ? code.substring(start, end) : null;
             if (version != null && !Character.isUnicodeIdentifierPart(version.codePointAt(0)))
{
                 throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.InvalidVersionIdentifier_1,
version), authority, code);
             }
diff --git a/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
b/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
index d70e12c..5e5423f 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/internal/util/DefinitionURI.java
@@ -336,7 +336,7 @@ public final class DefinitionURI {
                         if (codeForGML(null, null, uri, ++upper, result) != null) {
                             return result;
                         }
-                        if (!uri.regionMatches(upper, "//", 0, 2)) {
+                        if (!uri.startsWith("//", upper)) {
                             return null;                                // Prefix is never
optional for HTTP.
                         }
                         upper++;
diff --git a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
index b2a51f7..50e2796 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/measure/RangeFormat.java
@@ -896,7 +896,7 @@ public class RangeFormat extends Format implements Localized {
                     if (c == minusSign || c == '−') {
                         index += Character.charCount(c);
                     }
-                    if (!source.regionMatches(index, infinity, 0, infinity.length())) {
+                    if (!source.startsWith(infinity, index)) {
                         return null;
                     }
                     pos.setIndex(index += infinity.length());
@@ -918,7 +918,7 @@ public class RangeFormat extends Format implements Localized {
                     if (!Character.isWhitespace(c)) break;
                 }
                 final String separator = this.separator;
-                if (source.regionMatches(index, separator, 0, separator.length())) {
+                if (source.startsWith(separator, index)) {
                     index += separator.length();
                     for (;; index += Character.charCount(c)) {
                         if (index >= length) {
@@ -935,7 +935,7 @@ public class RangeFormat extends Format implements Localized {
                     pos.setIndex(index);
                     value = elementFormat.parseObject(source, pos);
                     if (value == null) {
-                        if (!source.regionMatches(index, infinity, 0, infinity.length()))
{
+                        if (!source.startsWith(infinity, index)) {
                             return null;
                         }
                         pos.setIndex(index += infinity.length());
diff --git a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
index 58983f1..4fe53b6 100644
--- a/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
+++ b/storage/sis-earth-observation/src/main/java/org/apache/sis/storage/earthobservation/LandsatReader.java
@@ -346,7 +346,7 @@ final class LandsatReader extends MetadataBuilder {
                     final char c = key.charAt(i);
                     if (c < '0' || c > '9') {
                         if (c == '_') {
-                            if (key.regionMatches(i - BAND_SUFFIX.length(), BAND_SUFFIX,
0, BAND_SUFFIX.length())) try {
+                            if (key.startsWith(BAND_SUFFIX, i - BAND_SUFFIX.length())) try
{
                                 band = Integer.parseInt(key.substring(++i));
                                 key = key.substring(0, i);
                             } catch (NumberFormatException e) {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
index 43f524d..7751946 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/RasterResource.java
@@ -282,7 +282,7 @@ public final class RasterResource extends AbstractGridResource implements
Resour
                                  * is the case, then we consider that those two variables
should be kept together.
                                  */
                                 for (final String k : VECTOR_COMPONENT_NAMES) {
-                                    if (cn.regionMatches(prefixLength, k, 0, k.length()))
{
+                                    if (cn.startsWith(k, prefixLength)) {
                                         siblings.add(candidate);
                                         variables[j] = null;
                                         break;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/IOUtilities.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/IOUtilities.java
index 4d95e78..ea5f894 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/IOUtilities.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/IOUtilities.java
@@ -418,7 +418,7 @@ public final class IOUtilities extends Static {
              * except in the particular case where there is just one letter before ':'. In
such
              * case, it may be the drive letter of a Windows file.
              */
-            if (s<0 || (s==1 && Character.isLetter(path.charAt(0)) &&
!path.regionMatches(2, "//", 0, 2))) {
+            if (s<0 || (s==1 && Character.isLetter(path.charAt(0)) &&
!path.startsWith("//", 2))) {
                 return new File(path);
             }
         }


Mime
View raw message