From 7b9c6bd5d13cf9c004d1cb2d544683ed3e7b17e5 Mon Sep 17 00:00:00 2001 From: Aleksi Hietanen Date: Wed, 4 Jan 2017 11:22:13 +0200 Subject: [PATCH] Avoid redundant autoboxing in BackEndDataProvider's size callback (#8127) --- .../data/provider/BackEndDataProvider.java | 7 ++-- .../server/SerializableToIntFunction.java | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 server/src/main/java/com/vaadin/server/SerializableToIntFunction.java 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 extends AbstractDataProvider { private final SerializableFunction, Stream> request; - private final SerializableFunction, Integer> sizeCallback; + private final SerializableToIntFunction> sizeCallback; /** * Constructs a new DataProvider to request data from an arbitrary back end @@ -47,7 +48,7 @@ public class BackEndDataProvider extends AbstractDataProvider { */ public BackEndDataProvider( SerializableFunction, Stream> request, - SerializableFunction, Integer> sizeCallback) { + SerializableToIntFunction> 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 extends AbstractDataProvider { @Override public int size(Query 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 + * the type of the input for this function + */ +@FunctionalInterface +public interface SerializableToIntFunction + extends ToIntFunction, Serializable { + +} -- 2.39.5