Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 way to concatenate strings #882

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import com.google.api.server.spi.config.Nullable;
import com.google.api.server.spi.response.UnauthorizedException;

import java.util.Collections;
import java.util.List;

/**
* The Echo API which Endpoints will be exposing.
*/
Expand Down Expand Up @@ -109,17 +112,10 @@ public Message echoApiKey(Message message, @Named("n") @Nullable Integer n) {
// [END echo_api_key]

private Message doEcho(Message message, Integer n) {
if (n != null && n >= 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(message.getMessage());
}
message.setMessage(sb.toString());
}
return message;
List<String> elements = Collections.nCopies(n, message.getMessage());
Message response = new Message();
response.setMessage(String.join(" ", elements));
return response;
}

/**
Expand Down