com.github.davidmoten.guavamini.Preconditions Java Examples
The following examples show how to use
com.github.davidmoten.guavamini.Preconditions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemberSingle.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") MemberSingle(NonBlockingPool<T> pool) { Preconditions.checkNotNull(pool); this.initializedAvailable = new MpscLinkedQueue<DecoratingMember<T>>(); this.notInitialized = new MpscLinkedQueue<DecoratingMember<T>>(); this.toBeReleased = new MpscLinkedQueue<DecoratingMember<T>>(); this.toBeChecked = new MpscLinkedQueue<DecoratingMember<T>>(); this.members = createMembersArray(pool.maxSize, pool.checkinDecorator); for (DecoratingMember<T> m : members) { notInitialized.offer(m); } this.scheduler = pool.scheduler; this.createRetryIntervalMs = pool.createRetryIntervalMs; this.observers = new AtomicReference<>(EMPTY); this.pool = pool; }
Example #2
Source File: ConnectionProvider.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
static ConnectionProvider from(@Nonnull String url, Properties properties) { Preconditions.checkNotNull(url, "url cannot be null"); Preconditions.checkNotNull(properties, "properties cannot be null"); return new ConnectionProvider() { @Override public Connection get() { try { return DriverManager.getConnection(url, properties); } catch (SQLException e) { throw new SQLRuntimeException(e); } } @Override public void close() { // do nothing as closure will be handle by pool } }; }
Example #3
Source File: ConnectionProvider.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
static ConnectionProvider from(@Nonnull String url, String username, String password) { Preconditions.checkNotNull(url, "url cannot be null"); return new ConnectionProvider() { @Override public Connection get() { try { return DriverManager.getConnection(url, username, password); } catch (SQLException e) { throw new SQLRuntimeException(e); } } @Override public void close() { // do nothing as closure will be handle by pool } }; }
Example #4
Source File: Tuples.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
public static <T1, T2, T3, T4, T5, T6, T7> ResultSetMapper<Tuple7<T1, T2, T3, T4, T5, T6, T7>> tuple( final Class<T1> cls1, final Class<T2> cls2, final Class<T3> cls3, final Class<T4> cls4, final Class<T5> cls5, final Class<T6> cls6, final Class<T7> cls7) { Preconditions.checkNotNull(cls1, "cls1 cannot be null"); Preconditions.checkNotNull(cls2, "cls2 cannot be null"); Preconditions.checkNotNull(cls3, "cls3 cannot be null"); Preconditions.checkNotNull(cls4, "cls4 cannot be null"); Preconditions.checkNotNull(cls5, "cls5 cannot be null"); Preconditions.checkNotNull(cls6, "cls6 cannot be null"); Preconditions.checkNotNull(cls7, "cls7 cannot be null"); return new ResultSetMapper<Tuple7<T1, T2, T3, T4, T5, T6, T7>>() { @Override public Tuple7<T1, T2, T3, T4, T5, T6, T7> apply(ResultSet rs) { return new Tuple7<T1, T2, T3, T4, T5, T6, T7>(mapObject(rs, cls1, 1), mapObject(rs, cls2, 2), mapObject(rs, cls3, 3), mapObject(rs, cls4, 4), mapObject(rs, cls5, 5), mapObject(rs, cls6, 6), mapObject(rs, cls7, 7)); } }; }
Example #5
Source File: Tuples.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
public static <T1, T2, T3, T4, T5, T6> ResultSetMapper<Tuple6<T1, T2, T3, T4, T5, T6>> tuple( final Class<T1> cls1, final Class<T2> cls2, final Class<T3> cls3, final Class<T4> cls4, final Class<T5> cls5, final Class<T6> cls6) { Preconditions.checkNotNull(cls1, "cls1 cannot be null"); Preconditions.checkNotNull(cls2, "cls2 cannot be null"); Preconditions.checkNotNull(cls3, "cls3 cannot be null"); Preconditions.checkNotNull(cls4, "cls4 cannot be null"); Preconditions.checkNotNull(cls5, "cls5 cannot be null"); Preconditions.checkNotNull(cls6, "cls6 cannot be null"); return new ResultSetMapper<Tuple6<T1, T2, T3, T4, T5, T6>>() { @Override public Tuple6<T1, T2, T3, T4, T5, T6> apply(ResultSet rs) { return new Tuple6<T1, T2, T3, T4, T5, T6>(mapObject(rs, cls1, 1), mapObject(rs, cls2, 2), mapObject(rs, cls3, 3), mapObject(rs, cls4, 4), mapObject(rs, cls5, 5), mapObject(rs, cls6, 6)); } }; }
Example #6
Source File: Tuples.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
public static <T1, T2, T3, T4, T5> ResultSetMapper<Tuple5<T1, T2, T3, T4, T5>> tuple( final Class<T1> cls1, final Class<T2> cls2, final Class<T3> cls3, final Class<T4> cls4, final Class<T5> cls5) { Preconditions.checkNotNull(cls1, "cls1 cannot be null"); Preconditions.checkNotNull(cls2, "cls2 cannot be null"); Preconditions.checkNotNull(cls3, "cls3 cannot be null"); Preconditions.checkNotNull(cls4, "cls4 cannot be null"); Preconditions.checkNotNull(cls5, "cls5 cannot be null"); return new ResultSetMapper<Tuple5<T1, T2, T3, T4, T5>>() { @Override public Tuple5<T1, T2, T3, T4, T5> apply(ResultSet rs) { return new Tuple5<T1, T2, T3, T4, T5>(mapObject(rs, cls1, 1), mapObject(rs, cls2, 2), mapObject(rs, cls3, 3), mapObject(rs, cls4, 4), mapObject(rs, cls5, 5)); } }; }
Example #7
Source File: Tuples.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
public static <T1, T2, T3, T4> ResultSetMapper<Tuple4<T1, T2, T3, T4>> tuple( final Class<T1> cls1, final Class<T2> cls2, final Class<T3> cls3, final Class<T4> cls4) { Preconditions.checkNotNull(cls1, "cls1 cannot be null"); Preconditions.checkNotNull(cls2, "cls2 cannot be null"); Preconditions.checkNotNull(cls3, "cls3 cannot be null"); Preconditions.checkNotNull(cls4, "cls4 cannot be null"); return new ResultSetMapper<Tuple4<T1, T2, T3, T4>>() { @Override public Tuple4<T1, T2, T3, T4> apply(ResultSet rs) { return new Tuple4<T1, T2, T3, T4>(mapObject(rs, cls1, 1), mapObject(rs, cls2, 2), mapObject(rs, cls3, 3), mapObject(rs, cls4, 4)); } }; }
Example #8
Source File: NonBlockingPool.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
NonBlockingPool(Callable<? extends T> factory, Predicate<? super T> healthCheck, Consumer<? super T> disposer, int maxSize, long idleTimeBeforeHealthCheckMs, long maxIdleTimeMs, long createRetryIntervalMs, BiFunction<? super T, ? super Checkin, ? extends T> checkinDecorator, Scheduler scheduler, Action closeAction) { Preconditions.checkNotNull(factory); Preconditions.checkNotNull(healthCheck); Preconditions.checkNotNull(disposer); Preconditions.checkArgument(maxSize > 0); Preconditions.checkNotNull(checkinDecorator); Preconditions.checkNotNull(scheduler); Preconditions.checkArgument(createRetryIntervalMs >= 0, "createRetryIntervalMs must be >=0"); Preconditions.checkNotNull(closeAction); Preconditions.checkArgument(maxIdleTimeMs >= 0, "maxIdleTime must be >=0"); this.factory = factory; this.healthCheck = healthCheck; this.disposer = disposer; this.maxSize = maxSize; this.idleTimeBeforeHealthCheckMs = idleTimeBeforeHealthCheckMs; this.maxIdleTimeMs = maxIdleTimeMs; this.createRetryIntervalMs = createRetryIntervalMs; this.checkinDecorator = checkinDecorator; this.scheduler = scheduler;// schedules retries this.closeAction = closeAction; }
Example #9
Source File: ConnectionProvider.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
static ConnectionProvider from(@Nonnull String url) { Preconditions.checkNotNull(url, "url cannot be null"); return new ConnectionProvider() { @Override public Connection get() { try { return DriverManager.getConnection(url); } catch (SQLException e) { throw new SQLRuntimeException(e); } } @Override public void close() { // do nothing as closure will be handle by pool } }; }
Example #10
Source File: Transformers.java From rxjava2-extras with Apache License 2.0 | 6 votes |
public static <T> FlowableTransformer<T, T> rebatchRequests(final int minRequest, final long maxRequest, final boolean constrainFirstRequestMin) { Preconditions.checkArgument(minRequest <= maxRequest, "minRequest cannot be greater than maxRequest"); return new FlowableTransformer<T, T>() { @Override public Publisher<T> apply(Flowable<T> source) { if (minRequest == maxRequest && constrainFirstRequestMin) { return source.rebatchRequests(minRequest); } else { return source .compose(Transformers.<T>minRequest(constrainFirstRequestMin ? minRequest : 1, minRequest)) .compose(Transformers.<T>maxRequest(maxRequest)); } } }; }
Example #11
Source File: TransactedReturnGeneratedKeysBuilder.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
/** * Transforms the results using the given function. * * @param mapper * maps the query results to an object * @return the results of the query as an Observable */ @Override public <T> Flowable<Tx<T>> get(@Nonnull ResultSetMapper<? extends T> mapper) { Preconditions.checkNotNull(mapper, "mapper cannot be null"); return Flowable.defer(() -> { AtomicReference<Connection> connection = new AtomicReference<Connection>(); Flowable<T> o = Update.<T>createReturnGeneratedKeys( // update.updateBuilder.connections // .map(c -> Util.toTransactedConnection(connection, c)), update.parameterGroupsToFlowable(), update.updateBuilder.sql, mapper, false); return o.materialize() // .flatMap(n -> Tx.toTx(n, connection.get(), db)) // .doOnNext(tx -> { if (tx.isComplete()) { ((TxImpl<T>) tx).connection().commit(); } }); }); }
Example #12
Source File: ParametersBuilder.java From rxjava2-jdbc with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private final T parameterList(Object[] values) { Preconditions.checkNotNull(values); if (values.length == 0) { // no effect return (T) this; } Preconditions.checkArgument(sqlInfo.numParameters() == 0 || values.length % sqlInfo.numParameters() == 0, "number of values should be a multiple of number of parameters in sql: " + sqlInfo.sql()); Preconditions.checkArgument(Arrays.stream(values) .allMatch(o -> sqlInfo.names().isEmpty() || (o instanceof Parameter && ((Parameter) o).hasName()))); for (Object val : values) { if (val == null) { parameterBuffer.add(Parameter.NULL); } else { parameterBuffer.add(val); } } return (T) this; }
Example #13
Source File: FlowableStateMachine.java From rxjava2-extras with Apache License 2.0 | 6 votes |
public FlowableStateMachine(Flowable<In> source, // Callable<? extends State> initialState, // Function3<? super State, ? super In, ? super Emitter<Out>, ? extends State> transition, // BiConsumer<? super State, ? super Emitter<Out>> completionAction, // Consumer3<? super State, ? super Throwable, ? super Emitter<Out>> errorAction, // BackpressureStrategy backpressureStrategy, // int requestBatchSize) { Preconditions.checkNotNull(initialState); Preconditions.checkNotNull(transition); Preconditions.checkNotNull(backpressureStrategy); Preconditions.checkArgument(requestBatchSize > 0, "initialRequest must be greater than zero"); this.source = source; this.initialState = initialState; this.transition = transition; this.completionAction = completionAction; this.errorAction = errorAction; this.backpressureStrategy = backpressureStrategy; this.requestBatchSize = requestBatchSize; }
Example #14
Source File: PagedQueue.java From rxjava2-extras with Apache License 2.0 | 6 votes |
private void write(byte[] bytes, int offset, int length, int padding, final MessageType messageType, int totalLength) { Preconditions.checkArgument(length != 0); pages.markForRewriteAndAdvance4Bytes();// messageSize left as 0 // storeFence not required at this point like Aeron uses. // UnsafeAccess.unsafe().storeFence(); // TODO optimize for BigEndian as well if (padding == 2 && isLittleEndian) { pages.putInt(((messageType.value() & 0xFF) << 0) | (((byte) padding)) << 8); } else { pages.putByte(messageType.value()); // message type pages.putByte((byte) padding); if (padding > 0) { pages.moveWritePosition(padding); } } if (messageType == MessageType.FRAGMENT && offset == 0) { // first fragment only of a sequence of fragments pages.putInt(totalLength); } pages.put(bytes, offset, length); // now that the message bytes are written we can set the length field in // the header to indicate that the message is ready to be read pages.putIntOrderedAtRewriteMark(length); }
Example #15
Source File: FlowableWindowMinMax.java From rxjava2-extras with Apache License 2.0 | 5 votes |
public FlowableWindowMinMax(Flowable<T> source, int windowSize, Comparator<? super T> comparator, Metric metric) { Preconditions.checkArgument(windowSize > 0, "windowSize must be greater than zero"); Preconditions.checkNotNull(comparator, "comparator cannot be null"); Preconditions.checkNotNull(metric, "metric cannot be null"); this.source = source; this.windowSize = windowSize; this.comparator = comparator; this.metric = metric; }
Example #16
Source File: Options.java From rxjava2-extras with Apache License 2.0 | 5 votes |
@VisibleForTesting Options(Callable<File> filefactory, int pageSizeBytes, Scheduler scheduler) { Preconditions.checkNotNull(filefactory); Preconditions.checkArgument(pageSizeBytes > 0, "bufferSizeBytes must be greater than 0"); Preconditions.checkNotNull(scheduler); this.fileFactory = filefactory; this.pageSizeBytes = pageSizeBytes; this.scheduler = scheduler; }
Example #17
Source File: StateMachineDefinition.java From state-machine with Apache License 2.0 | 5 votes |
public <R extends Event<? super T>> State<T, R> createState(String name, Class<R> eventClass) { Preconditions.checkArgument(!eventClass.isAnnotationPresent(GenerateImmutable.class), "cannot base a state on an event that is annotated with @GenerateImmutable, use the generated immutable class instead"); Preconditions.checkNotNull(name); if (name.equals("Initial")) { name = name.concat("_1"); } State<T, R> state = new State<T, R>(this, name, eventClass); states.add(state); return state; }
Example #18
Source File: FlowableStringSplitSimple.java From rxjava2-extras with Apache License 2.0 | 5 votes |
public FlowableStringSplitSimple(Flowable<String> source, String delimiter) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(delimiter); Preconditions.checkArgument(delimiter.length() > 0); this.source = source; this.delimiter = delimiter; }
Example #19
Source File: TransformerStateMachine.java From rxjava2-extras with Apache License 2.0 | 5 votes |
private TransformerStateMachine(Callable<? extends State> initialState, Function3<? super State, ? super In, ? super FlowableEmitter<Out>, ? extends State> transition, BiPredicate<? super State, ? super FlowableEmitter<Out>> completion, BackpressureStrategy backpressureStrategy, int requestBatchSize) { Preconditions.checkNotNull(initialState); Preconditions.checkNotNull(transition); Preconditions.checkNotNull(completion); Preconditions.checkNotNull(backpressureStrategy); Preconditions.checkArgument(requestBatchSize > 0, "initialRequest must be greater than zero"); this.initialState = initialState; this.transition = transition; this.completion = completion; this.backpressureStrategy = backpressureStrategy; this.requestBatchSize = requestBatchSize; }
Example #20
Source File: NonBlockingConnectionPool.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
/** * Sets the provider of {@link Connection} objects to be used by the pool. * * @param cp * connection provider * @return this */ public Builder<T> connectionProvider(ConnectionProvider cp) { Preconditions.checkArgument(!(cp instanceof SingletonConnectionProvider), // "connection provider should not return a singleton connection because " // + "a pool needs control over the creation and closing of connections. " // + "Use ConnectionProvider.from(url,...) instead."); this.cp = cp; return this; }
Example #21
Source File: FlowableMaxRequest.java From rxjava2-extras with Apache License 2.0 | 5 votes |
public FlowableMaxRequest(Flowable<T> source, long[] maxRequests) { Preconditions.checkArgument(maxRequests.length > 0, "maxRequests length must be greater than 0"); for (int i = 0; i < maxRequests.length; i++) { Preconditions.checkArgument(maxRequests[i] > 0, "maxRequests items must be greater than zero"); } this.source = source; this.maxRequests = maxRequests; }
Example #22
Source File: Processor.java From state-machine with Apache License 2.0 | 5 votes |
public Processor<Id> build() { Preconditions.checkArgument(behaviourFactory != null || !behaviours.isEmpty(), "one of behaviourFactory or multiple calls to behaviour must be made (behaviour must be specified)"); Preconditions.checkArgument(behaviourFactory == null || behaviours.isEmpty(), "cannot specify both behaviourFactory and behaviour"); if (!behaviours.isEmpty()) { behaviourFactory = cls -> behaviours.get(cls); } return new Processor<Id>(behaviourFactory, processingScheduler, signalScheduler, signals, entityTransform, preGroupBy, mapFactory, preTransitionAction, postTransitionAction); }
Example #23
Source File: MemberSingle.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
Observers(MemberSingleObserver<T>[] observers, boolean[] active, int activeCount, int index, int requested) { Preconditions.checkArgument(observers.length > 0 || index == 0, "index must be -1 for zero length array"); Preconditions.checkArgument(observers.length == active.length); this.observers = observers; this.index = index; this.active = active; this.activeCount = activeCount; this.requested = requested; }
Example #24
Source File: Strings.java From rxjava2-extras with Apache License 2.0 | 5 votes |
public static Flowable<String> fromClasspath(final Class<?> cls, final String resource, final Charset charset) { Preconditions.checkNotNull(resource); Preconditions.checkNotNull(charset); Callable<Reader> resourceFactory = new Callable<Reader>() { @Override public Reader call() { return new InputStreamReader(cls.getResourceAsStream(resource), charset); } }; return from(resourceFactory); }
Example #25
Source File: SelectBuilder.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
@Override public <T> Flowable<T> get(@Nonnull ResultSetMapper<? extends T> mapper) { Preconditions.checkNotNull(mapper, "mapper cannot be null"); Flowable<List<Object>> pg = super.parameterGroupsToFlowable(); Flowable<T> f = Select.<T>create(connection, pg, sql, fetchSize, mapper, true, queryTimeoutSec); if (dependsOn != null) { return dependsOn.ignoreElements().andThen(f); } else { return f; } }
Example #26
Source File: SelectBuilder.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
SelectBuilder(String sql, Single<Connection> connection, Database db) { super(sql); Preconditions.checkNotNull(sql); Preconditions.checkNotNull(connection); this.sql = sql; this.connection = connection; this.db = db; }
Example #27
Source File: Processor.java From state-machine with Apache License 2.0 | 5 votes |
private Processor(Function<Class<?>, EntityBehaviour<?, Id>> behaviourFactory, Scheduler processingScheduler, Scheduler signalScheduler, Flowable<Signal<?, Id>> signals, Function<GroupedFlowable<ClassId<?, Id>, EntityStateMachine<?, Id>>, Flowable<EntityStateMachine<?, Id>>> entityTransform, FlowableTransformer<Signal<?, Id>, Signal<?, Id>> preGroupBy, Function<Consumer<Object>, Map<ClassId<?, Id>, Object>> mapFactory, Action3<? super EntityStateMachine<?, Id>, ? super Event<?>, ? super EntityState<?>> preTransitionAction, Consumer<? super EntityStateMachine<?, Id>> postTransitionAction) { Preconditions.checkNotNull(behaviourFactory); Preconditions.checkNotNull(signalScheduler); Preconditions.checkNotNull(signals); Preconditions.checkNotNull(entityTransform); Preconditions.checkNotNull(preGroupBy); Preconditions.checkNotNull(preTransitionAction); Preconditions.checkNotNull(postTransitionAction); // mapFactory is nullable this.behaviourFactory = behaviourFactory; this.signalScheduler = signalScheduler; this.processingScheduler = processingScheduler; this.subject = PublishSubject.create(); this.signals = signals; this.entityTransform = entityTransform; this.preGroupBy = preGroupBy; this.mapFactory = mapFactory; this.signallerClock = Clock.from(signalScheduler); this.preTransitionAction = preTransitionAction; this.postTransitionAction = postTransitionAction; }
Example #28
Source File: Persistence.java From state-machine with Apache License 2.0 | 5 votes |
@JsonCreator public EntityWithId(@JsonProperty("entity") T entity, @JsonProperty("id") String id) { Preconditions.checkNotNull(entity); Preconditions.checkNotNull(id); this.entity = entity; this.id = id; this.className = entity.getClass().getName(); }
Example #29
Source File: Database.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
public static Database from(@Nonnull String url, int maxPoolSize) { Preconditions.checkNotNull(url, "url cannot be null"); Preconditions.checkArgument(maxPoolSize > 0, "maxPoolSize must be greater than 0"); NonBlockingConnectionPool pool = Pools.nonBlocking() // .url(url) // .maxPoolSize(maxPoolSize) // .build(); return Database.from( // pool, // () -> { pool.close(); }); }
Example #30
Source File: Database.java From rxjava2-jdbc with Apache License 2.0 | 5 votes |
public static Database test(int maxPoolSize) { Preconditions.checkArgument(maxPoolSize > 0, "maxPoolSize must be greater than 0"); return Database.from( // Pools.nonBlocking() // .connectionProvider(testConnectionProvider()) // .maxPoolSize(maxPoolSize) // .build()); }