@Override public URL validateURLAccess( URL url ) throws URLAccessValidationError { return urlValidator.apply( url ); }
@Override public OUT next() throws IOException { if ( !hasNext() ) { throw new IllegalStateException(); } return converter.apply( items[cursor++] ); }
@Override public TO next() throws EX { FROM from = fromIterator.next(); return function.apply( from ); }
return throwing.apply( input );
/** * Map current instances to some other type using the converter function. * Even called on instances that haven't been instantiated yet. * Mapping is preserved in returned {@link EnumMap}. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ <R,E extends Exception> EnumMap<IndexSlot,R> map( ThrowingFunction<T,R,E> converter ) throws E { EnumMap<IndexSlot,R> result = new EnumMap<>( IndexSlot.class ); for ( IndexSlot slot : IndexSlot.values() ) { result.put( slot, converter.apply( select( slot ) ) ); } return result; }
/** * Map current instances to some other type using the converter function, * without preserving the mapping. * Even called on instances that haven't been instantiated yet. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ @SuppressWarnings( "unchecked" ) <R,E extends Exception> Iterable<R> transform( ThrowingFunction<T,R,E> converter ) throws E { List<R> result = new ArrayList<>(); for ( IndexSlot slot : IndexSlot.values() ) { result.add( converter.apply( select( slot ) ) ); } return result; }
private static <FROM, TO, EX extends Exception> Callable<TO> task( final ThrowingFunction<FROM,TO,EX> function, String name, final FROM parameter, final FailableConsumer<Thread> threadConsumer ) { return () -> { Thread thread = Thread.currentThread(); String previousName = thread.getName(); thread.setName( name ); threadConsumer.accept( thread ); try { return function.apply( parameter ); } catch ( Exception failure ) { threadConsumer.fail( failure ); throw failure; } finally { thread.setName( previousName ); } }; }
@Override public boolean next() throws IOException { while ( currentLogTransactionCursor == null || !currentLogTransactionCursor.next() ) { // We've run out of transactions in this log version, back up to a previous one currentVersion--; if ( currentVersion < backToPosition.getLogVersion() ) { return false; } closeCurrent(); LogPosition position = currentVersion > backToPosition.getLogVersion() ? start( currentVersion ) : backToPosition; currentLogTransactionCursor = cursorFactory.apply( position ); } return true; }
private ThrowingFunction<LogPosition,TransactionCursor,IOException> log( int... transactionCounts ) throws IOException { long baseOffset = LogPosition.start( 0 ).getByteOffset(); @SuppressWarnings( "unchecked" ) ThrowingFunction<LogPosition,TransactionCursor,IOException> result = mock( ThrowingFunction.class ); AtomicLong txId = new AtomicLong( 0 ); CommittedTransactionRepresentation[][] logs = new CommittedTransactionRepresentation[transactionCounts.length][]; for ( int logVersion = 0; logVersion < transactionCounts.length; logVersion++ ) { logs[logVersion] = transactions( transactionCounts[logVersion], txId ); } when( result.apply( any( LogPosition.class ) ) ).thenAnswer( invocation -> { LogPosition position = invocation.getArgument( 0 ); if ( position == null ) { // A mockito issue when calling the "when" methods, I believe return null; } // For simplicity the offset means, in this test, the array offset CommittedTransactionRepresentation[] transactions = logs[toIntExact( position.getLogVersion() )]; CommittedTransactionRepresentation[] subset = copyOfRange( transactions, toIntExact( position.getByteOffset() - baseOffset ), transactions.length ); ArrayUtil.reverse( subset ); return given( subset ); } ); return result; }
private int mapToken( ThrowingFunction<Token, Integer, KernelException> f ) { try ( Transaction tx = beginTransaction() ) { return f.apply( tx.token() ); } catch ( KernelException e ) { fail( "Unwanted exception: " + e.getMessage() ); return -1; // unreachable } }
@Override public URL validateURLAccess( URL url ) throws URLAccessValidationError { return urlValidator.apply( url ); }
@Override public OUT next() throws IOException { if ( !hasNext() ) { throw new IllegalStateException(); } return converter.apply( items[cursor++] ); }
@Override public TO next() throws EX { FROM from = fromIterator.next(); return function.apply( from ); }
/** * Map current instances to some other type using the converter function. * Even called on instances that haven't been instantiated yet. * Mapping is preserved in returned {@link EnumMap}. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ <R,E extends Exception> EnumMap<IndexSlot,R> map( ThrowingFunction<T,R,E> converter ) throws E { EnumMap<IndexSlot,R> result = new EnumMap<>( IndexSlot.class ); for ( IndexSlot slot : IndexSlot.values() ) { result.put( slot, converter.apply( select( slot ) ) ); } return result; }
/** * Map current instances to some other type using the converter function, * without preserving the mapping. * Even called on instances that haven't been instantiated yet. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ @SuppressWarnings( "unchecked" ) <R,E extends Exception> Iterable<R> transform( ThrowingFunction<T,R,E> converter ) throws E { List<R> result = new ArrayList<>(); for ( IndexSlot slot : IndexSlot.values() ) { result.add( converter.apply( select( slot ) ) ); } return result; }
return throwing.apply( input );
@Override public boolean next() throws IOException { while ( currentLogTransactionCursor == null || !currentLogTransactionCursor.next() ) { // We've run out of transactions in this log version, back up to a previous one currentVersion--; if ( currentVersion < backToPosition.getLogVersion() ) { return false; } closeCurrent(); LogPosition position = currentVersion > backToPosition.getLogVersion() ? start( currentVersion ) : backToPosition; currentLogTransactionCursor = cursorFactory.apply( position ); } return true; }