Refine search
public final int updateAndGet(IntUnaryOperator updateFunction) { int expectedVersion; int newValue; do { expectedVersion = version; newValue = updateFunction.applyAsInt(value); } while (expectedVersion != version); ++version; value = newValue; return newValue; }
public Iterator<Page> getSortedPages() { return new AbstractIterator<Page>() { private int currentPosition; private final PageBuilder pageBuilder = new PageBuilder(types); private final int[] outputChannels = new int[types.size()]; { Arrays.setAll(outputChannels, IntUnaryOperator.identity()); } @Override public Page computeNext() { currentPosition = buildPage(currentPosition, outputChannels, pageBuilder); if (pageBuilder.isEmpty()) { return endOfData(); } Page page = pageBuilder.build(); pageBuilder.reset(); return page; } }; } }
/** * Replaces the value to be returned by {@link TypeUsage#start()} by applying {@code mapper} to it * and using the result. * * @return this {@code Builder} object * @throws NullPointerException if {@code mapper} is null * @throws IllegalStateException if the field has not been set */ public TypeUsage.Builder mapStart(IntUnaryOperator mapper) { Objects.requireNonNull(mapper); return start(mapper.applyAsInt(start())); }
@Override protected void sliceUint8C(TypedArrayObject src, int srcPos, TypedArrayObject dest, int destPos, int length) { put(((IntUnaryOperator) asShortBuffer(src)::get).andThen(ElementType::ToUint8Clamp), srcPos, asByteBuffer(dest), destPos, length); }
/** * Replaces the value to be returned by {@link TypeUsage#end()} by applying {@code mapper} to it * and using the result. * * @return this {@code Builder} object * @throws NullPointerException if {@code mapper} is null * @throws IllegalStateException if the field has not been set */ public TypeUsage.Builder mapEnd(IntUnaryOperator mapper) { Objects.requireNonNull(mapper); return end(mapper.applyAsInt(end())); }
@Override protected void constructUint8C(TypedArrayObject typedArray, ArrayBufferObject target) { put(((IntUnaryOperator) asShortBuffer(typedArray)::get).andThen(ElementType::ToUint8Clamp), 0, asByteBuffer(target), 0, length(typedArray)); }
/** {@inheritDoc} */ @Override public int computeIfAbsent(final short k, final java.util.function.IntUnaryOperator mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final int newValue = mappingFunction.applyAsInt(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */
public static void setAll(int[] array, IntUnaryOperator generator) { for (int i = 0; i < array.length; ++i) { array[i] = generator.applyAsInt(i); } }
RemoteClientTransport(final Channel channel, final int version, final MarshallingConfiguration configuration) { configuration.setClassResolver(new ContextClassResolver()); this.channel = channel; this.configuration = configuration; this.version = version; tracker = new InvocationTracker(channel, version == 1 ? IntUnaryOperator.identity() : RemoteClientTransport::defaultFunction); }
@Override protected void setUint8C(ArrayBuffer srcBuffer, int srcIndex, TypedArrayObject dest, int destPos, int length) { put(((IntUnaryOperator) asIntBuffer(srcBuffer, srcIndex, length)::get).andThen(ElementType::ToUint8Clamp), 0, asByteBuffer(dest), destPos, length); }
/** {@inheritDoc} */ @Override public int computeIfAbsent(final char k, final java.util.function.IntUnaryOperator mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final int newValue = mappingFunction.applyAsInt(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */
public final int getAndUpdate(IntUnaryOperator updateFunction) { int expectedVersion; int result; int newValue; do { expectedVersion = version; result = value; newValue = updateFunction.applyAsInt(value); } while (expectedVersion != version); ++version; value = newValue; return result; }
@Test public void testMassive() { BlockBuilder inputBlockBuilder = BIGINT.createBlockBuilder(null, 5000); TypedHistogram typedHistogram = new SingleTypedHistogram(BIGINT, 1000); IntStream.range(1, 2000) .flatMap(i -> IntStream.iterate(i, IntUnaryOperator.identity()).limit(i)) .forEach(j -> BIGINT.writeLong(inputBlockBuilder, j)); Block inputBlock = inputBlockBuilder.build(); for (int i = 0; i < inputBlock.getPositionCount(); i++) { typedHistogram.add(i, inputBlock, 1); } MapType mapType = mapType(BIGINT, BIGINT); BlockBuilder out = mapType.createBlockBuilder(null, 1); typedHistogram.serialize(out); Block outputBlock = mapType.getObject(out, 0); for (int i = 0; i < outputBlock.getPositionCount(); i += 2) { assertEquals(BIGINT.getLong(outputBlock, i + 1), BIGINT.getLong(outputBlock, i)); } } }
@Override protected void sliceUint8C(TypedArrayObject src, int srcPos, TypedArrayObject dest, int destPos, int length) { put(((IntUnaryOperator) asByteBuffer(src)::get).andThen(ElementType::ToUint8Clamp), srcPos, asByteBuffer(dest), destPos, length); }
/** {@inheritDoc} */ @Override public int computeIfAbsent(final byte k, final java.util.function.IntUnaryOperator mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final int newValue = mappingFunction.applyAsInt(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */
import java.util.function.*; import static java.lang.System.out; // Tested with JDK 1.8.0-ea-b75 public class CurryingAndPartialFunctionApplication { public static void main(String[] args) { IntBinaryOperator simpleAdd = (a, b) -> a + b; IntFunction<IntUnaryOperator> curriedAdd = a -> b -> a + b; // Demonstrating simple add: out.println(simpleAdd.applyAsInt(4, 5)); // Demonstrating curried add: out.println(curriedAdd.apply(4).applyAsInt(5)); // Curried version lets you perform partial application: IntUnaryOperator adder5 = curriedAdd.apply(5); out.println(adder5.applyAsInt(4)); out.println(adder5.applyAsInt(6)); } }
/** * Creates a new instance of CharTokenizer with the supplied attribute factory using a custom predicate, supplied as method reference or lambda expression. * The predicate should return {@code true} for all valid token separator characters. * <p> * This factory is intended to be used with lambdas or method references. E.g., an elegant way * to create an instance which behaves exactly as {@link WhitespaceTokenizer} is: * <pre class="prettyprint lang-java"> * Tokenizer tok = CharTokenizer.fromSeparatorCharPredicate(factory, Character::isWhitespace); * </pre> */ public static CharTokenizer fromSeparatorCharPredicate(AttributeFactory factory, final IntPredicate separatorCharPredicate) { return fromSeparatorCharPredicate(factory, separatorCharPredicate, IntUnaryOperator.identity()); }
@Override protected void sliceUint8C(TypedArrayObject src, int srcPos, TypedArrayObject dest, int destPos, int length) { put(((IntUnaryOperator) asShortBuffer(src)::get).andThen(ElementType::ToUint8ClampUnsigned), srcPos, asByteBuffer(dest), destPos, length); }
/** {@inheritDoc} */ @Override public int computeIfAbsent(final int k, final java.util.function.IntUnaryOperator mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final int newValue = mappingFunction.applyAsInt(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */
@Override public ToIntNullable<T> mapIfPresent(IntUnaryOperator mapper) { return t -> isNull.test(t) ? null : mapper.applyAsInt(original.applyAsInt(t)); }