Refine search
@SuppressWarnings("unchecked") @Override public <A> A[] toArray(IntFunction<A[]> generator) { requireNonNull(generator); final A[] result = generator.apply(1); result[0] = (A) element; return result; }
protected Entry(IntFunction<MessageBatch> creator) { batch_creator=creator; batch=batch_creator.apply(max_buffer_size > 0? max_buffer_size : 16); // initial capacity }
public static <T> void setAll(T[] array, IntFunction<? extends T> generator) { for (int i = 0; i < array.length; ++i) { array[i] = generator.apply(i); } }
default VALUE computeIfAbsent( int key, IntFunction<VALUE> function ) { requireNonNull( function ); VALUE value = get( key ); if ( value == null ) { value = function.apply( key ); put( key, value ); } return value; } }
@Override public T readObject(ObjectInput input) throws IOException, ClassNotFoundException { return this.reader.apply(input.readInt()); }
default String[] entityTokensGetNames( EntityType type, int[] entityTokenIds ) { IntFunction<String> mapper; switch ( type ) { case NODE: mapper = this::labelGetName; break; case RELATIONSHIP: mapper = this::relationshipTypeGetName; break; default: throw new IllegalArgumentException( "Cannot lookup names for tokens of type: " + type ); } String[] tokenNames = new String[entityTokenIds.length]; for ( int i = 0; i < entityTokenIds.length; i++ ) { tokenNames[i] = mapper.apply( entityTokenIds[i] ); } return tokenNames; } }
@Override public T next() { return mapFunction.apply( source.next() ); }
private static <OUTPUT, INPUT extends Comparable<INPUT>, RESULT extends Collection<OUTPUT>> RESULT executeLargeInputs(Collection<INPUT> input, Function<List<INPUT>, RESULT> function, java.util.function.IntFunction<RESULT> outputInitializer, IntFunction<Integer> partitionSizeManipulations) { if (input.isEmpty()) { return outputInitializer.apply(0); } RESULT results = outputInitializer.apply(input.size()); for (List<INPUT> partition : toUniqueAndSortedPartitions(input, partitionSizeManipulations)) { RESULT subResults = function.apply(partition); if (subResults != null) { results.addAll(subResults); } } return results; }
private static void emit( PrintWriter out, List<Integer> lengths, IntFunction<Value> valueLookup, int values ) { for ( int i = 0; i < values; i++ ) { if ( i > 0 ) { out.append( ' ' ); } String name = shortName( valueLookup.apply( i ).toString() ); for ( int pad = lengths.get( i ) - name.length(); pad-- > 0; ) { out.append( ' ' ); } out.append( name ); } }
public long hashPosition(int position, IntFunction<Block> blockProvider) { long result = HashGenerationOptimizer.INITIAL_HASH_VALUE; for (int i = 0; i < hashChannels.length; i++) { Type type = hashChannelTypes.get(i); result = CombineHashFunction.getHash(result, TypeUtils.hashPosition(type, blockProvider.apply(hashChannels[i]), position)); } return result; }
private void writeLeafBlockPackedValuesRange(DataOutput out, int[] commonPrefixLengths, int start, int end, IntFunction<BytesRef> packedValues) throws IOException { for (int i = start; i < end; ++i) { BytesRef ref = packedValues.apply(i); assert ref.length == packedBytesLength; for(int dim=0;dim<numDataDims;dim++) { int prefix = commonPrefixLengths[dim]; out.writeBytes(ref.bytes, ref.offset + dim*bytesPerDim + prefix, bytesPerDim-prefix); } } }
public ByteBuffer allocate(int size) { while (!reuse.isEmpty()) { ByteBuffer bb = reuse.removeFirst(); // If we don't have a buffer of exactly the requested size, discard it. if (bb.remaining() == size) { return bb; } } return delegate.apply(size); }
private static int runLen(IntFunction<BytesRef> packedValues, int start, int end, int byteOffset) { BytesRef first = packedValues.apply(start); byte b = first.bytes[first.offset + byteOffset]; for (int i = start + 1; i < end; ++i) { BytesRef ref = packedValues.apply(i); byte b2 = ref.bytes[ref.offset + byteOffset]; assert Byte.toUnsignedInt(b2) >= Byte.toUnsignedInt(b); if (b != b2) { return i - start; } } return end - start; }
@Override public boolean next(Predicate<? super T> consumer) { return source.next(e -> consumer.test(mapper.apply(e))); }
/** * Deparse an action bit set, using the given function to map action bits to strings. If the bits are all clear, * the empty string {@code ""} is returned. * * @param actionBits the action bit set * @param mappingFunction the mapping function (must not be {@code null}) * @return the actions string (not {@code null}) */ public static String toActionsString(int actionBits, IntFunction<String> mappingFunction) { Assert.checkNotNullParam("mappingFunction", mappingFunction); final StringBuilder sb = new StringBuilder(); if (actionBits == 0) return ""; int lb = Integer.highestOneBit(actionBits); sb.append(mappingFunction.apply(lb)); actionBits &= ~lb; while (actionBits != 0) { lb = Integer.highestOneBit(actionBits); sb.append(',').append(mappingFunction.apply(lb)); actionBits &= ~lb; } return sb.toString(); }
public Partition( int consumersCount, int partitionNumber, IntFunction<ListenableFuture<T>> loader, ListenableFuture<?> previousReleased, IntConsumer disposer) { this.partitionNumber = partitionNumber; this.requested = SettableFuture.create(); this.loaded = Futures.transformAsync( allAsList(requested, previousReleased), ignored -> loader.apply(partitionNumber), directExecutor()); this.released = SettableFuture.create(); released.addListener(() -> disposer.accept(partitionNumber), directExecutor()); this.pendingReleases = consumersCount; }
/** * @param in * @param factory a factory for creating the returned collection, parameterized by size * @return Collection of Address objects * @throws Exception */ public static <T extends Collection<Address>> T readAddresses(DataInput in, IntFunction<T> factory) throws Exception { short length=in.readShort(); if(length < 0) return null; T retval = factory.apply(length); Address addr; for(int i=0; i < length; i++) { addr=Util.readAddress(in); retval.add(addr); } return retval; }
@Override Value asValue( GenericKey state ) { T[] array = arrayCreator.apply( state.arrayLength ); for ( int i = 0; i < state.arrayLength; i++ ) { array[i] = valueFactory.from( state, i ); } return Values.of( array ); }
private void appendBlock() { if (blocks.size() >= MAX_BLOCKS_BEFORE_BLOCK_EXPANSION && blockBits < maxBitsPerBlock) { rewriteToBlockSize(blockBits + 1); if (blocks.getLast().hasRemaining()) { return; } } final int requiredBlockSize = 1 << blockBits; currentBlock = blockAllocate.apply(requiredBlockSize); assert currentBlock.capacity() == requiredBlockSize; blocks.add(currentBlock); }
/** * Converts this to a Java array having an accurate component type. * * <pre>{@code * // = [] of type String[] * Future.<String> of(() -> { throw new Error(); }) * .toJavaArray(String[]::new) * * // = [ok] of type String[] * Try.of(() -> "ok") * .toJavaArray(String[]::new) * * // = [1, 2, 3] of type Integer[] * List.of(1, 2, 3) * .toJavaArray(Integer[]::new) * }</pre> * * @param arrayFactory an <code>int</code> argument function that * creates an array of the correct component * type with the specified size * @return The array provided by the factory filled with the values from this <code>Value</code>. * @throws NullPointerException if componentType is null */ default T[] toJavaArray(IntFunction<T[]> arrayFactory) { java.util.List<T> javaList = toJavaList(); return javaList.toArray(arrayFactory.apply(javaList.size())); }