summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2017-01-04 11:22:13 +0200
committerGitHub <noreply@github.com>2017-01-04 11:22:13 +0200
commit7b9c6bd5d13cf9c004d1cb2d544683ed3e7b17e5 (patch)
tree8d7d717286f4f4eec4ea17b3082a7c647f116ca9
parent451161461bf240e4fd25211ed997d96e565a211b (diff)
downloadvaadin-framework-7b9c6bd5d13cf9c004d1cb2d544683ed3e7b17e5.tar.gz
vaadin-framework-7b9c6bd5d13cf9c004d1cb2d544683ed3e7b17e5.zip
Avoid redundant autoboxing in BackEndDataProvider's size callback (#8127)
-rw-r--r--server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java7
-rw-r--r--server/src/main/java/com/vaadin/server/SerializableToIntFunction.java35
2 files changed, 39 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
index 2ceebc995a..5f789e8a55 100644
--- a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
@@ -21,6 +21,7 @@ import java.util.Objects;
import java.util.stream.Stream;
import com.vaadin.server.SerializableFunction;
+import com.vaadin.server.SerializableToIntFunction;
import com.vaadin.shared.Registration;
/**
@@ -34,7 +35,7 @@ import com.vaadin.shared.Registration;
public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {
private final SerializableFunction<Query<T, F>, Stream<T>> request;
- private final SerializableFunction<Query<T, F>, Integer> sizeCallback;
+ private final SerializableToIntFunction<Query<T, F>> sizeCallback;
/**
* Constructs a new DataProvider to request data from an arbitrary back end
@@ -47,7 +48,7 @@ public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {
*/
public BackEndDataProvider(
SerializableFunction<Query<T, F>, Stream<T>> request,
- SerializableFunction<Query<T, F>, Integer> sizeCallback) {
+ SerializableToIntFunction<Query<T, F>> sizeCallback) {
Objects.requireNonNull(request, "Request function can't be null");
Objects.requireNonNull(sizeCallback, "Size callback can't be null");
this.request = request;
@@ -61,7 +62,7 @@ public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {
@Override
public int size(Query<T, F> query) {
- return sizeCallback.apply(query);
+ return sizeCallback.applyAsInt(query);
}
/**
diff --git a/server/src/main/java/com/vaadin/server/SerializableToIntFunction.java b/server/src/main/java/com/vaadin/server/SerializableToIntFunction.java
new file mode 100644
index 0000000000..e94c350f4e
--- /dev/null
+++ b/server/src/main/java/com/vaadin/server/SerializableToIntFunction.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server;
+
+import java.io.Serializable;
+import java.util.function.ToIntFunction;
+
+/**
+ * A {@link ToIntFunction} that is also {@link Serializable}.
+ *
+ * @see ToIntFunction
+ * @author Vaadin Ltd
+ * @since 8.0
+ *
+ * @param <T>
+ * the type of the input for this function
+ */
+@FunctionalInterface
+public interface SerializableToIntFunction<T>
+ extends ToIntFunction<T>, Serializable {
+
+}