Rename to encodedLength

This commit is contained in:
Liam Miller-Cushon 2026-02-25 18:26:39 +01:00
parent e04a5c1ae8
commit f9505f60c3
5 changed files with 15 additions and 15 deletions

View File

@ -2116,7 +2116,7 @@ public final class String
* @param cs The {@link Charset} used to the compute the length
* @since 27
*/
public int getEncodedLength(Charset cs) {
public int encodedLength(Charset cs) {
Objects.requireNonNull(cs);
if (cs == UTF_8.INSTANCE) {
return encodedLengthUTF8(coder, value);

View File

@ -106,9 +106,9 @@ public class Encodings {
if (!equals(bs, bytes))
throw new Exception(charset + ": String.getBytes failed");
/* String.getEncodedLength(Charset charset) */
if (bs.length != str.getEncodedLength(charset))
throw new Exception(charset + ": String.getEncodedLength failed");
/* String.encodedLength(Charset charset) */
if (bs.length != str.encodedLength(charset))
throw new Exception(charset + ": String.encodedLength failed");
// Calls to String.getBytes(Charset) shouldn't automatically
// use the cached thread-local encoder.

View File

@ -397,11 +397,11 @@ public class Exceptions {
}});
}
private static void getEncodedLength() {
System.out.println("getEncodedLength(Charset charset)");
private static void encodedLength() {
System.out.println("encodedLength(Charset charset)");
tryCatch(" null", NullPointerException.class, new Runnable() {
public void run() {
"foo".getEncodedLength((Charset)null);
"foo".encodedLength((Charset)null);
}});
}
@ -648,7 +648,7 @@ public class Exceptions {
// getBytes(Locale)
// getBytes(String)
// getBytes(Charset)
getEncodedLength(); // getEncodedLength(Charset)
encodedLength(); // encodedLength(Charset)
contentEquals(); // contentEquals(StringBuffer)
compareTo(); // compareTo(String), compareTo(Object)
compareToIgnoreCase();// compareToIgnoreCase(String)

View File

@ -169,11 +169,11 @@ public class TestStringCoding {
if (!Arrays.equals(baSC, baNIO)) {
throw new RuntimeException("getBytes(cs) failed -> " + cs.name());
}
//getEncodedLength(cs);
int getEncodedLength = str.getEncodedLength(cs);
if (baSC.length != getEncodedLength) {
throw new RuntimeException(String.format("getEncodedLength failed (%d != %d) -> %s",
baSC.length, getEncodedLength, cs.name()));
//encodedLength(cs);
int encodedLength = str.encodedLength(cs);
if (baSC.length != encodedLength) {
throw new RuntimeException(String.format("encodedLength failed (%d != %d) -> %s",
baSC.length, encodedLength, cs.name()));
}
return baSC;
}

View File

@ -116,7 +116,7 @@ public class StringLoopJmhBenchmark {
}
@Benchmark
public int getEncodedLength() throws Exception {
return stringData.getEncodedLength(StandardCharsets.UTF_8);
public int encodedLength() throws Exception {
return stringData.encodedLength(StandardCharsets.UTF_8);
}
}