Example usage for java.util.function IntPredicate test

List of usage examples for java.util.function IntPredicate test

Introduction

In this page you can find the example usage for java.util.function IntPredicate test.

Prototype

boolean test(int value);

Source Link

Document

Evaluates this predicate on the given argument.

Usage

From source file:gedi.util.ArrayUtils.java

/**
 * Projects only true entries from a. entries and a must have same size!
 * @param a//from  w  w  w  .  ja v  a2  s  .c  om
 * @param entries
 * @return
 */
public static int[] restrict(int[] a, IntPredicate use) {
    int s = 0;
    for (int i = 0; i < a.length; i++)
        if (use.test(i))
            s++;

    int[] re = new int[s];
    int index = 0;
    for (int i = 0; i < a.length; i++)
        if (use.test(i))
            re[index++] = a[i];
    return re;
}

From source file:gedi.util.ArrayUtils.java

/**
 * Projects only true entries from a. entries and a must have same size!
 * @param a//ww  w.j a  va 2s  . com
 * @param entries
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T[] restrict(T[] a, IntPredicate use) {
    int s = 0;
    for (int i = 0; i < a.length; i++)
        if (use.test(i))
            s++;

    T[] re = (T[]) Array.newInstance(a.getClass().getComponentType(), s);
    int index = 0;
    for (int i = 0; i < a.length; i++)
        if (use.test(i))
            re[index++] = a[i];
    return re;
}

From source file:org.briljantframework.array.AbstractIntArray.java

@Override
public IntArray filter(IntPredicate operator) {
    IntList builder = new IntList();
    for (int i = 0; i < size(); i++) {
        int value = get(i);
        if (operator.test(value)) {
            builder.add(value);/*from   ww w.  ja v a2s. co  m*/
        }
    }
    return factory.newIntVector(Arrays.copyOf(builder.elementData, builder.size()));
}

From source file:org.briljantframework.array.AbstractIntArray.java

@Override
public BooleanArray where(IntPredicate predicate) {
    BooleanArray bits = factory.newBooleanArray();
    for (int i = 0; i < size(); i++) {
        bits.set(i, predicate.test(get(i)));
    }//ww w.  ja  v  a2  s.  c o  m
    return bits;
}

From source file:org.eclipse.fx.core.text.TextUtil.java

/**
 * Strip characters matched by the filter
 *
 * @param content/* ww  w. j a va  2s.  com*/
 *            the content
 * @param filter
 *            the filter
 * @return string without the filtered characters
 * @since 2.4.0
 */
public static String stripOff(String content, IntPredicate filter) {
    char[] cs = content.toCharArray();
    char[] target = new char[cs.length];
    int j = 0;
    for (int i = 0; i < cs.length; i++) {
        if (!filter.test(cs[i])) {
            target[j++] = cs[i];
        }
    }

    if (j < cs.length) {
        return new String(target, 0, j);
    }

    return content;
}