List of usage examples for java.util.function ToIntFunction applyAsInt
int applyAsInt(T value);
From source file:Main.java
public static void main(String[] args) { ToIntFunction<String> i = (x) -> Integer.parseInt(x); System.out.println(i.applyAsInt("2")); }
From source file:Main.java
/** * Garbage free sum function.//from w ww . java 2s . c om * * @param values the list of input values * @param function function that map each value to an int * @param <V> the value to add up * @return the sum of all the int values returned for each member of the list. */ public static <V> int sum(final List<V> values, final ToIntFunction<V> function) { int total = 0; final int size = values.size(); for (int i = 0; i < size; i++) { final V value = values.get(i); total += function.applyAsInt(value); } return total; }
From source file:at.gridtec.lambda4j.function.bi.to.ToIntBiFunction2.java
/** * Creates a {@link ToIntBiFunction2} which uses the {@code first} parameter of this one as argument for the given * {@link ToIntFunction}.//from ww w . j a v a 2s .c o m * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param function The function which accepts the {@code first} parameter of this one * @return Creates a {@code ToIntBiFunction2} which uses the {@code first} parameter of this one as argument for the * given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> ToIntBiFunction2<T, U> onlyFirst(@Nonnull final ToIntFunction<? super T> function) { Objects.requireNonNull(function); return (t, u) -> function.applyAsInt(t); }
From source file:at.gridtec.lambda4j.function.bi.to.ToIntBiFunction2.java
/** * Creates a {@link ToIntBiFunction2} which uses the {@code second} parameter of this one as argument for the given * {@link ToIntFunction}.//from w w w. j a v a 2 s . co m * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param function The function which accepts the {@code second} parameter of this one * @return Creates a {@code ToIntBiFunction2} which uses the {@code second} parameter of this one as argument for * the given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U> ToIntBiFunction2<T, U> onlySecond(@Nonnull final ToIntFunction<? super U> function) { Objects.requireNonNull(function); return (t, u) -> function.applyAsInt(u); }
From source file:at.gridtec.lambda4j.function.tri.to.ToIntTriFunction.java
/** * Creates a {@link ToIntTriFunction} which uses the {@code first} parameter of this one as argument for the given * {@link ToIntFunction}./*from w w w.jav a 2 s .co m*/ * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param <V> The type of the third argument to the function * @param function The function which accepts the {@code first} parameter of this one * @return Creates a {@code ToIntTriFunction} which uses the {@code first} parameter of this one as argument for the * given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> ToIntTriFunction<T, U, V> onlyFirst(@Nonnull final ToIntFunction<? super T> function) { Objects.requireNonNull(function); return (t, u, v) -> function.applyAsInt(t); }
From source file:at.gridtec.lambda4j.function.tri.to.ToIntTriFunction.java
/** * Creates a {@link ToIntTriFunction} which uses the {@code second} parameter of this one as argument for the given * {@link ToIntFunction}./* w w w . j a v a 2 s . co m*/ * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param <V> The type of the third argument to the function * @param function The function which accepts the {@code second} parameter of this one * @return Creates a {@code ToIntTriFunction} which uses the {@code second} parameter of this one as argument for * the given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> ToIntTriFunction<T, U, V> onlySecond(@Nonnull final ToIntFunction<? super U> function) { Objects.requireNonNull(function); return (t, u, v) -> function.applyAsInt(u); }
From source file:at.gridtec.lambda4j.function.tri.to.ToIntTriFunction.java
/** * Creates a {@link ToIntTriFunction} which uses the {@code third} parameter of this one as argument for the given * {@link ToIntFunction}./*from w w w. j av a 2 s. co m*/ * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param <V> The type of the third argument to the function * @param function The function which accepts the {@code third} parameter of this one * @return Creates a {@code ToIntTriFunction} which uses the {@code third} parameter of this one as argument for the * given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V> ToIntTriFunction<T, U, V> onlyThird(@Nonnull final ToIntFunction<? super V> function) { Objects.requireNonNull(function); return (t, u, v) -> function.applyAsInt(v); }
From source file:at.gridtec.lambda4j.function.bi.obj.ObjIntToIntFunction.java
/** * Creates a {@link ObjIntToIntFunction} which uses the {@code first} parameter of this one as argument for the * given {@link ToIntFunction}./*from ww w . ja v a 2 s. c o m*/ * * @param <T> The type of the first argument to the function * @param function The function which accepts the {@code first} parameter of this one * @return Creates a {@code ObjIntToIntFunction} which uses the {@code first} parameter of this one as argument for * the given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T> ObjIntToIntFunction<T> onlyFirst(@Nonnull final ToIntFunction<? super T> function) { Objects.requireNonNull(function); return (t, value) -> function.applyAsInt(t); }
From source file:at.gridtec.lambda4j.function.bi.obj.ObjByteToIntFunction.java
/** * Creates a {@link ObjByteToIntFunction} which uses the {@code first} parameter of this one as argument for the * given {@link ToIntFunction}.//from w ww . ja v a 2 s . com * * @param <T> The type of the first argument to the function * @param function The function which accepts the {@code first} parameter of this one * @return Creates a {@code ObjByteToIntFunction} which uses the {@code first} parameter of this one as argument for * the given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T> ObjByteToIntFunction<T> onlyFirst(@Nonnull final ToIntFunction<? super T> function) { Objects.requireNonNull(function); return (t, value) -> function.applyAsInt(t); }
From source file:at.gridtec.lambda4j.function.bi.obj.ObjCharToIntFunction.java
/** * Creates a {@link ObjCharToIntFunction} which uses the {@code first} parameter of this one as argument for the * given {@link ToIntFunction}.//from www . j a va 2s .c o m * * @param <T> The type of the first argument to the function * @param function The function which accepts the {@code first} parameter of this one * @return Creates a {@code ObjCharToIntFunction} which uses the {@code first} parameter of this one as argument for * the given {@code ToIntFunction}. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T> ObjCharToIntFunction<T> onlyFirst(@Nonnull final ToIntFunction<? super T> function) { Objects.requireNonNull(function); return (t, value) -> function.applyAsInt(t); }