List of usage examples for java.util.function IntFunction apply
R apply(int value);
From source file:org.eclipse.fx.core.text.TextUtil.java
/** * Apply the consumer for each matched char * * @param content/*w w w . jav a 2 s . c o m*/ * the content * @param c * the character to find * @param consumer * the function who gets passed the position of the matched char * @return stream with objects produced by the function * @since 2.4.0 */ public static <R> Stream<R> foreachCharPosition(String content, char c, IntFunction<R> consumer) { // TODO We should not precreate the list List<R> list = new ArrayList<>(); char[] cs = content.toCharArray(); for (int i = 0; i < cs.length; i++) { if (cs[i] == c) { list.add(consumer.apply(i)); } } return list.stream(); }
From source file:org.eclipse.packagedrone.utils.rpm.app.Dumper.java
public static String dumpFlag(final int value, final IntFunction<Optional<?>> func) { final Optional<?> flag = func.apply(value); if (flag.isPresent()) { return String.format("%s (%s)", flag.get(), value); } else {/*from w ww. ja v a 2 s . co m*/ return String.format("%s", value); } }
From source file:sadl.models.TauPTA.java
private void insertPerLevelAnomaly(IntFunction<List<Transition>> possibleTransitionFunction, ToIntFunction<List<Transition>> insertAnomaly) { for (int height = 0; height < getTreeHeight(); height++) { final TIntList states = getStates(height); final List<Transition> allLevelTransitions = new ArrayList<>(); for (int i = 0; i < states.size(); i++) { allLevelTransitions.addAll(getOutTransitions(states.get(i), true)); }/*from www .ja v a2 s. co m*/ int result = 0; final List<Transition> possibleTransitions = possibleTransitionFunction.apply(height); if (possibleTransitions.size() > 0) { // sort for determinism Collections.sort(possibleTransitions); result = insertAnomaly.applyAsInt(possibleTransitions); } if (possibleTransitions.size() == 0 || result != 1) { logger.warn("It is not possible to insert anomalies on height {}", height); } } }