Skip to content

Commit

Permalink
Avoid redundant autoboxing in BackEndDataProvider's size callback (#8127
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ahie committed Jan 4, 2017
1 parent 4511614 commit 7b9c6bd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.util.stream.Stream; import java.util.stream.Stream;


import com.vaadin.server.SerializableFunction; import com.vaadin.server.SerializableFunction;
import com.vaadin.server.SerializableToIntFunction;
import com.vaadin.shared.Registration; import com.vaadin.shared.Registration;


/** /**
Expand All @@ -34,7 +35,7 @@
public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> { public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {


private final SerializableFunction<Query<T, F>, Stream<T>> request; 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 * Constructs a new DataProvider to request data from an arbitrary back end
Expand All @@ -47,7 +48,7 @@ public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {
*/ */
public BackEndDataProvider( public BackEndDataProvider(
SerializableFunction<Query<T, F>, Stream<T>> request, 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(request, "Request function can't be null");
Objects.requireNonNull(sizeCallback, "Size callback can't be null"); Objects.requireNonNull(sizeCallback, "Size callback can't be null");
this.request = request; this.request = request;
Expand All @@ -61,7 +62,7 @@ public Stream<T> fetch(Query<T, F> query) {


@Override @Override
public int size(Query<T, F> query) { public int size(Query<T, F> query) {
return sizeCallback.apply(query); return sizeCallback.applyAsInt(query);
} }


/** /**
Expand Down
@@ -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 {

}

0 comments on commit 7b9c6bd

Please sign in to comment.