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

use method reference #11329

Merged
merged 1 commit into from
Jun 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/play-java/src/test/java/play/mvc/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void testSetTransientLangFailure() {
// When trying to get the messages it does not work because en-NZ is not valid
assertThat(messagesApi(app).preferred(req).lang().code()).isEqualTo("en");
// However if you access the transient lang directly you will see it was set
assertThat(req.transientLang().map(l -> l.code())).isEqualTo(Optional.of("en-NZ"));
assertThat(req.transientLang().map(Lang::code)).isEqualTo(Optional.of("en-NZ"));
});
}

Expand Down Expand Up @@ -228,11 +228,11 @@ public void testRequestImplLang() {

// Make sure the new request correctly set its internal lang variable
assertThat(messagesApi(app).preferred(newReq).lang().code()).isEqualTo("en-US");
assertThat(newReq.transientLang().map(l -> l.code())).isEqualTo(Optional.of("en-US"));
assertThat(newReq.transientLang().map(Lang::code)).isEqualTo(Optional.of("en-US"));

// Also make sure the original request didn't change it's language
assertThat(messagesApi(app).preferred(req).lang().code()).isEqualTo("fr");
assertThat(req.transientLang().map(l -> l.code())).isEqualTo(Optional.of("fr"));
assertThat(req.transientLang().map(Lang::code)).isEqualTo(Optional.of("fr"));
});
}
}
4 changes: 2 additions & 2 deletions core/play-java/src/test/java/play/mvc/RequestBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void testAddALangCookieToRequestBuilder() {

assertEquals(
Optional.of(lang.code()),
request.getCookie(Helpers.stubMessagesApi().langCookieName()).map(c -> c.value()));
request.getCookie(Helpers.stubMessagesApi().langCookieName()).map(Http.Cookie::value));
assertFalse(request.transientLang().isPresent());
assertFalse(request.attrs().getOptional(Messages.Attrs.CurrentLang).isPresent());
}
Expand All @@ -256,7 +256,7 @@ public void testAddALangCookieByLocaleToRequestBuilder() {

assertEquals(
Optional.of(locale.toLanguageTag()),
request.getCookie(Helpers.stubMessagesApi().langCookieName()).map(c -> c.value()));
request.getCookie(Helpers.stubMessagesApi().langCookieName()).map(Http.Cookie::value));
assertFalse(request.transientLang().isPresent());
assertFalse(request.attrs().getOptional(Messages.Attrs.CurrentLang).isPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AccumulatorTest {
private Executor ec;

private Accumulator<Integer, Integer> sum =
Accumulator.fromSink(Sink.<Integer, Integer>fold(0, (a, b) -> a + b));
Accumulator.fromSink(Sink.<Integer, Integer>fold(0, Integer::sum));
private Source<Integer, ?> source = Source.from(Arrays.asList(1, 2, 3));

private <T> T await(CompletionStage<T> cs) throws Exception {
Expand Down
3 changes: 2 additions & 1 deletion core/play/src/main/java/play/http/DefaultHttpFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public DefaultHttpFilters(play.api.mvc.EssentialFilter... filters) {
}

public DefaultHttpFilters(List<? extends play.api.mvc.EssentialFilter> filters) {
this.filters = filters.stream().map(f -> f.asJava()).collect(Collectors.toList());
this.filters =
filters.stream().map(play.api.mvc.EssentialFilter::asJava).collect(Collectors.toList());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/play/src/main/java/play/mvc/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public Result discardingCookie(
path,
Option.apply(domain),
secure,
Option.apply(sameSite).map(ss -> ss.asScala()))
Option.apply(sameSite).map(Cookie.SameSite::asScala))
.toCookie()
.asJava());
}
Expand Down
7 changes: 2 additions & 5 deletions core/play/src/main/java/play/mvc/StatusHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ public Result sendFile(
return sendFile(
file,
inline,
Optional.ofNullable(file).map(f -> f.getName()),
Optional.ofNullable(file).map(File::getName),
fileMimeTypes,
onClose,
executor);
Expand Down Expand Up @@ -1943,9 +1943,6 @@ public Result sendEntity(
return new Result(
status(),
Results.contentDispositionHeader(inline, fileName),
entity.as(
fileName
.flatMap(name -> fileMimeTypes.forFileName(name))
.orElse(Http.MimeTypes.BINARY)));
entity.as(fileName.flatMap(fileMimeTypes::forFileName).orElse(Http.MimeTypes.BINARY)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import play.api.http.SessionConfiguration;
import play.api.libs.crypto.CSRFTokenSigner;
import play.api.mvc.Cookie;
import play.mvc.Action;
import play.mvc.Http;
import play.mvc.Http.RequestBody;
Expand Down Expand Up @@ -74,7 +75,9 @@ private Result placeToken(Http.Request req, final Result result, CSRF.Token toke
domain.isDefined() ? domain.get() : null,
config.secureCookie(),
config.httpOnlyCookie(),
OptionConverters.toJava(config.sameSiteCookie()).map(c -> c.asJava()).orElse(null));
OptionConverters.toJava(config.sameSiteCookie())
.map(Cookie.SameSite::asJava)
.orElse(null));
return result.withCookies(cookie);
}
return result.addingToSession(req, token.name(), token.value());
Expand Down
8 changes: 4 additions & 4 deletions web/play-java-forms/src/main/java/play/data/DynamicForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,14 @@ public Optional<Object> value(String key) {
public Map<String, String> rawData() {
return Collections.unmodifiableMap(
super.rawData().entrySet().stream()
.collect(Collectors.toMap(e -> asNormalKey(e.getKey()), e -> e.getValue())));
.collect(Collectors.toMap(e -> asNormalKey(e.getKey()), Map.Entry::getValue)));
}

@Override
public Map<String, Http.MultipartFormData.FilePart<?>> files() {
return Collections.unmodifiableMap(
super.files().entrySet().stream()
.collect(Collectors.toMap(e -> asNormalKey(e.getKey()), e -> e.getValue())));
.collect(Collectors.toMap(e -> asNormalKey(e.getKey()), Map.Entry::getValue)));
}

/**
Expand Down Expand Up @@ -316,9 +316,9 @@ public DynamicForm bind(
lang,
attrs,
data.entrySet().stream()
.collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())),
.collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), Map.Entry::getValue)),
files.entrySet().stream()
.collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())),
.collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), Map.Entry::getValue)),
allowedFields);
return new DynamicForm(
form.rawData(),
Expand Down
2 changes: 1 addition & 1 deletion web/play-java-forms/src/main/java/play/data/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ protected <A> Map<String, Http.MultipartFormData.FilePart<?>> resolveDuplicateFi
}));
final Map<String, Http.MultipartFormData.FilePart<?>> data = new HashMap<>();
resolvedDuplicateKeys.forEach(
(key, values) -> fillDataWith(key, data, values.size(), i -> values.get(i)));
(key, values) -> fillDataWith(key, data, values.size(), values::get));
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static List<Tuple<String, List<Object>>> displayableConstraint(
return constraints
.parallelStream()
.filter(c -> c.getAnnotation().annotationType().isAnnotationPresent(Display.class))
.map(c -> displayableConstraint(c))
.map(Constraints::displayableConstraint)
.collect(Collectors.toList());
}

Expand All @@ -155,7 +155,9 @@ public static List<Tuple<String, List<Object>>> displayableConstraint(
public static List<Tuple<String, List<Object>>> displayableConstraint(
Set<ConstraintDescriptor<?>> constraints, Annotation[] orderedAnnotations) {
final List<Annotation> constraintAnnot =
constraints.stream().map(c -> c.getAnnotation()).collect(Collectors.<Annotation>toList());
constraints.stream()
.map(ConstraintDescriptor::getAnnotation)
.collect(Collectors.<Annotation>toList());

return Stream.of(orderedAnnotations)
.filter(
Expand Down