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

Optimize helidon optionals - io.helidon.common.mapper.OptionalValue #505

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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 @@ -202,7 +202,11 @@ private void writeClassStart() {

if (reader.isIncludeValidator()) {
writer.append(" private String language(ServerRequest req) {").eol();
writer.append(" return req.headers().first(HEADER_ACCEPT_LANGUAGE).orElse(null);").eol();
writer.append(" var headers = req.headers();").eol();
writer.append(" if (headers.contains(HEADER_ACCEPT_LANGUAGE)) {").eol();
writer.append(" return headers.get(HEADER_ACCEPT_LANGUAGE).get();").eol();
writer.append(" }").eol();
writer.append(" return null;").eol();
writer.append(" }").eol().eol();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ private void addRoleImports(List<String> roles, ControllerReader controller) {
@Override
public void writeReadParameter(Append writer, ParamType paramType, String paramName) {
switch (paramType) {
case PATHPARAM -> writer.append("pathParams.first(\"%s\").get()", paramName);
case PATHPARAM -> writer.append("pathParams.contains(\"%s\") ? pathParams.get(\"%s\") : null", paramName, paramName);

case QUERYPARAM -> writer.append("req.query().first(\"%s\").orElse(null)", paramName);
case QUERYPARAM -> writer.append("req.query().contains(\"%s\") ? req.query().get(\"%s\") : null", paramName, paramName);

case FORMPARAM -> writer.append("formParams.first(\"%s\").orElse(null)", paramName);
case FORMPARAM -> writer.append("formParams.contains(\"%s\") ? formParams.get(\"%s\") : null", paramName, paramName);

case HEADER -> writer.append(
"req.headers().value(HeaderNames.create(\"%s\")).orElse(null)", paramName);

case COOKIE -> writer.append("req.headers().cookies().first(\"%s\").orElse(null)", paramName);
case COOKIE -> writer.append("req.headers().cookies().contains(\"%s\") ? req.headers().cookies().get(\"%s\") : null", paramName, paramName);

default -> writer.append("null // TODO req.%s().param(\"%s\")", paramType.type(), paramName);
}
Expand All @@ -86,19 +86,19 @@ public void writeReadParameter(Append writer, ParamType paramType, String paramN
public void writeReadParameter(Append writer, ParamType paramType, String paramName, String paramDefault) {
switch (paramType) {
case PATHPARAM -> writer.append(
"pathParams.first(\"%s\").orElse(\"%s\")", paramName, paramDefault);
"pathParams.contains(\"%s\") ? pathParams.get(\"%s\") : \"%s\"", paramName, paramName, paramDefault);

case QUERYPARAM -> writer.append(
"req.query().first(\"%s\").orElse(\"%s\")", paramName, paramDefault);
"req.query().contains(\"%s\") ? req.query().get(\"%s\") : \"%s\"", paramName, paramName, paramDefault);

case FORMPARAM -> writer.append(
"formParams.first(\"%s\").orElse(\"%s\")", paramName, paramDefault);
"formParams.contains(\"%s\") ? formParams.get(\"%s\") : \"%s\"", paramName, paramName, paramDefault);

case HEADER -> writer.append(
"req.headers().value(Http.Header.create(\"%s\").orElse(\"%s\")", paramName, paramDefault);

case COOKIE -> writer.append(
"req.headers().cookies().first(\"%s\").orElse(\"%s\")", paramName, paramDefault);
"req.headers().cookies().contains(\"%s\") ? req.headers().cookies().get(\"%s\") : \"%s\"", paramName, paramName, paramDefault);

default -> writer.append("null // TODO req.%s().param(\"%s\")", paramType.type(), paramName);
}
Expand Down