Skip to content

Commit

Permalink
Remove StringBuilder/Buffer.append(StringTemplate)
Browse files Browse the repository at this point in the history
  • Loading branch information
JimLaskey committed Mar 8, 2024
1 parent b0262a7 commit 3a6fd91
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 57 deletions.
42 changes: 1 addition & 41 deletions src/java.base/share/classes/java/lang/AbstractStringBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,11 +31,9 @@
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;
import jdk.internal.javac.PreviewFeature;
import jdk.internal.util.ArraysSupport;
import jdk.internal.util.Preconditions;

Expand Down Expand Up @@ -551,41 +549,6 @@ public void setCharAt(int index, char ch) {
}
}

/**
* Appends the specified {@link StringTemplate} to this character sequence.
* <p>
* The fragments and values of the {@link StringTemplate} argument are appended, in
* order, increasing the length of this sequence by the length of the
* argument. If {@code stringTemplate} is {@code null}, then the four
* characters {@code "null"} are appended.
*
* @param stringTemplate a {@link StringTemplate}.
*
* @return a reference to this object.
*
* @since 23
*/
@PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
public AbstractStringBuilder append(StringTemplate stringTemplate) {
if (stringTemplate == null) {
return appendNull();
}
List<String> fragments = stringTemplate.fragments();
List<Object> values = stringTemplate.values();
int n = values.size();
for (int i = 0; i < n; i++) {
append(fragments.get(i));
Object value = values.get(i);
if (value instanceof StringTemplate st) {
append(st);
} else {
append(value);
}
}
append(fragments.get(n));
return this;
}

/**
* Appends the string representation of the {@code Object} argument.
* <p>
Expand All @@ -598,9 +561,6 @@ public AbstractStringBuilder append(StringTemplate stringTemplate) {
* @return a reference to this object.
*/
public AbstractStringBuilder append(Object obj) {
if (obj instanceof StringTemplate st) {
return append(st);
}
return append(String.valueOf(obj));
}

Expand Down
9 changes: 1 addition & 8 deletions src/java.base/share/classes/java/lang/StringBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,7 @@ public synchronized void setCharAt(int index, char ch) {
@Override
public synchronized StringBuffer append(Object obj) {
toStringCache = null;
super.append(obj);
return this;
}

@Override
public synchronized StringBuffer append(StringTemplate stringTemplate) {
toStringCache = null;
super.append(stringTemplate);
super.append(String.valueOf(obj));
return this;
}

Expand Down
9 changes: 1 addition & 8 deletions src/java.base/share/classes/java/lang/StringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,7 @@ public int compareTo(StringBuilder another) {

@Override
public StringBuilder append(Object obj) {
super.append(obj);
return this;
}

@Override
public StringBuilder append(StringTemplate stringTemplate) {
super.append(stringTemplate);
return this;
return append(String.valueOf(obj));
}

@Override
Expand Down

0 comments on commit 3a6fd91

Please sign in to comment.