當前位置: 首頁>>代碼示例>>Java>>正文


Java IntFunction.apply方法代碼示例

本文整理匯總了Java中java.util.function.IntFunction.apply方法的典型用法代碼示例。如果您正苦於以下問題:Java IntFunction.apply方法的具體用法?Java IntFunction.apply怎麽用?Java IntFunction.apply使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.function.IntFunction的用法示例。


在下文中一共展示了IntFunction.apply方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: flatMap

import java.util.function.IntFunction; //導入方法依賴的package包/類
@Override
public final IntStream flatMap(IntFunction<? extends IntStream> mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(int t) {
                    try (IntStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:IntPipeline.java

示例2: flatMap

import java.util.function.IntFunction; //導入方法依賴的package包/類
@Override
public final IntStream flatMap(IntFunction<? extends IntStream> mapper) {
    return new StatelessOp<Integer>(this, StreamShape.INT_VALUE,
                                    StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT | StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
            return new Sink.ChainedInt<Integer>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(int t) {
                    try (IntStream result = mapper.apply(t)) {
                        // We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
                        if (result != null)
                            result.sequential().forEach(i -> downstream.accept(i));
                    }
                }
            };
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:IntPipeline.java

示例3: asArray

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Create a new array using the specified array factory, and copy the
 * elements into it.
 */
public E[] asArray(IntFunction<E[]> arrayFactory) {
    long size = count();
    if (size >= Nodes.MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(Nodes.BAD_SIZE);
    E[] result = arrayFactory.apply((int) size);
    copyInto(result, 0);
    return result;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:SpinedBuffer.java

示例4: readArray

import java.util.function.IntFunction; //導入方法依賴的package包/類
public <T> T[] readArray(Writeable.Reader<T> reader, IntFunction<T[]> arraySupplier) throws IOException {
    int length = readArraySize();
    T[] values = arraySupplier.apply(length);
    for (int i = 0; i < length; i++) {
        values[i] = reader.read(this);
    }
    return values;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:StreamInput.java

示例5: asArray

import java.util.function.IntFunction; //導入方法依賴的package包/類
@Override
public T[] asArray(IntFunction<T[]> generator) {
    long size = count();
    if (size >= MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(BAD_SIZE);
    T[] array = generator.apply((int) size);
    copyInto(array, 0);
    return array;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:Nodes.java

示例6: asArray

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * @implSpec the default implementation invokes the generator to create
 * an instance of a boxed primitive array with a length of
 * {@link #count()} and then invokes {@link #copyInto(T[], int)} with
 * that array at an offset of 0.
 */
@Override
default T[] asArray(IntFunction<T[]> generator) {
    if (java.util.stream.Tripwire.ENABLED)
        java.util.stream.Tripwire.trip(getClass(), "{0} calling Node.OfPrimitive.asArray");

    long size = count();
    if (size >= Nodes.MAX_ARRAY_SIZE)
        throw new IllegalArgumentException(Nodes.BAD_SIZE);
    T[] boxed = generator.apply((int) count());
    copyInto(boxed, 0);
    return boxed;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:Node.java

示例7: readSliceFrom

import java.util.function.IntFunction; //導入方法依賴的package包/類
public static Bytes readSliceFrom(InputStream streamToDrain, int offset, int len, IntFunction<Bytes.BuilderStream> builderFactory) throws IOException {
    // the implementation is based on commons-io IOUtils.copyLarge

    if (len == 0) {
        return Bytes.empty();
    }

    if (offset > 0) {
        final long skipped = streamToDrain.skip(offset);
        if (skipped < offset) return Bytes.empty();
    }

    byte[] readBuffer = new byte[len > 4096 ? 4096 : len];

    final int bufferLength = readBuffer.length;
    int bytesToRead = bufferLength;
    if (len > 0 && len < bufferLength) {
        bytesToRead = len;
    }

    final Bytes.BuilderStream builder = builderFactory.apply(len);

    int read;
    long totalRead = 0;
    while (bytesToRead > 0 && -1 != (read = streamToDrain.read(readBuffer, 0, bytesToRead))) {
        builder.write(readBuffer, 0, read);
        totalRead += read;
        if (len > 0) { // only adjust length if not reading to the end
            // Note the cast must work because buffer.length is an integer
            bytesToRead = (int) Math.min(len - totalRead, bufferLength);
        }
    }

    return builder.toBytes();
}
 
開發者ID:avast,項目名稱:bytes,代碼行數:36,代碼來源:StreamReader.java

示例8: fromInteger

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Creates an INTEGER function that wraps to function provided
 * @param function  the function to wrap
 * @param <O>       the output type
 * @return          the newly created function wrapper
 */
public static <O> Function2<Integer,O> fromInteger(IntFunction<O> function) {
    return new Function2<Integer,O>(FunctionStyle.INTEGER) {
        @Override
        public final O apply(int input) {
            return function.apply(input);
        }
    };
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:15,代碼來源:Function2.java

示例9: forInt

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Creates an INTEGER Printer that wraps the function provided
 * @param function  the function to wrap
 * @return          the newly created function Printer
 */
public static Printer<Integer> forInt(IntFunction<String> function) {
    return new Printer<Integer>(FunctionStyle.INTEGER, DEFAULT_NULL) {
        @Override
        public final String apply(int input) {
            return function.apply(input);
        }
    };
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:14,代碼來源:Printer.java

示例10: create

import java.util.function.IntFunction; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static <T> T create(Map<Class<?>, IntFunction<?>> map, Class<T> clazz, int size)
{
    IntFunction<?> intFunction = map.get(clazz);
    if (intFunction != null)
    {
        return (T) intFunction.apply(size);
    }
    if ((! Modifier.isAbstract(clazz.getModifiers())) && (Map.class.isAssignableFrom(clazz) || Collection.class.isAssignableFrom(clazz)))
    {
        ConstructorInvoker<T> constructor = DioriteReflectionUtils.getConstructor(clazz, false);
        if (constructor != null)
        {
            constructor.ensureAccessible();
            IntFunction<T> creator = constructor::invokeWith;
            map.put(clazz, creator);
            return creator.apply(size);
        }
    }
    for (Entry<Class<?>, IntFunction<?>> entry : map.entrySet())
    {
        if (clazz.isAssignableFrom(entry.getKey()))
        {
            IntFunction<?> function = entry.getValue();
            map.put(clazz, function);
            return (T) function.apply(size);
        }
    }
    throw new YAMLException("Can't create collection: " + clazz);
}
 
開發者ID:GotoFinal,項目名稱:diorite-configs-java8,代碼行數:31,代碼來源:YamlCollectionCreator.java

示例11: flatten

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Flatten, in parallel, a {@link Node}.  A flattened node is one that has
 * no children.  If the node is already flat, it is simply returned.
 *
 * @implSpec
 * If a new node is to be created, the generator is used to create an array
 * whose length is {@link Node#count()}.  Then the node tree is traversed
 * and leaf node elements are placed in the array concurrently by leaf tasks
 * at the correct offsets.
 *
 * @param <T> type of elements contained by the node
 * @param node the node to flatten
 * @param generator the array factory used to create array instances
 * @return a flat {@code Node}
 */
public static <T> Node<T> flatten(Node<T> node, IntFunction<T[]> generator) {
    if (node.getChildCount() > 0) {
        long size = node.count();
        if (size >= MAX_ARRAY_SIZE)
            throw new IllegalArgumentException(BAD_SIZE);
        T[] array = generator.apply((int) size);
        new ToArrayTask.OfRef<>(node, array, 0).invoke();
        return node(array);
    } else {
        return node;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Nodes.java

示例12: setAll

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Set all elements of the specified array, using the provided
 * generator function to compute each element.
 *
 * <p>If the generator function throws an exception, it is relayed to
 * the caller and the array is left in an indeterminate state.
 *
 * @apiNote
 * Setting a subrange of an array, using a generator function to compute
 * each element, can be written as follows:
 * <pre>{@code
 * IntStream.range(startInclusive, endExclusive)
 *          .forEach(i -> array[i] = generator.apply(i));
 * }</pre>
 *
 * @param <T> type of elements of the array
 * @param array array to be initialized
 * @param generator a function accepting an index and producing the desired
 *        value for that position
 * @throws NullPointerException if the generator is null
 * @since 1.8
 */
public static <T> void setAll(T[] array, IntFunction<? extends T> generator) {
    Objects.requireNonNull(generator);
    for (int i = 0; i < array.length; i++)
        array[i] = generator.apply(i);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Arrays.java

示例13: setAll

import java.util.function.IntFunction; //導入方法依賴的package包/類
/**
 * Set all elements of the specified array, using the provided
 * generator function to compute each element.
 *
 * <p>If the generator function throws an exception, it is relayed to
 * the caller and the array is left in an indeterminate state.
 *
 * @param <T> type of elements of the array
 * @param array array to be initialized
 * @param generator a function accepting an index and producing the desired
 *        value for that position
 * @throws NullPointerException if the generator is null
 * @since 1.8
 */
public static <T> void setAll(T[] array, IntFunction<? extends T> generator) {
    Objects.requireNonNull(generator);
    for (int i = 0; i < array.length; i++)
        array[i] = generator.apply(i);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:Arrays.java


注:本文中的java.util.function.IntFunction.apply方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。