/** * Creates a new instance with given bandwidth. * * @param v bandwidth value * @param unit {@link DataRateUnit} of {@code v} * @return {@link Bandwidth} instance with given bandwidth */ static Bandwidth of(double v, DataRateUnit unit) { return new DoubleBandwidth(unit.toBitsPerSecond(v)); }
/** * Creates a new instance with given bandwidth. * * @param v bandwidth value * @param unit {@link DataRateUnit} of {@code v} * @return {@link Bandwidth} instance with given bandwidth */ static Bandwidth of(long v, DataRateUnit unit) { return new LongBandwidth(unit.toBitsPerSecond(v)); }
/** * Executes one-shot timer task on shared thread pool. * * @param task timer task to execute * @param delay before executing the task * @param unit of delay * @return a ScheduledFuture representing pending completion of the task * and whose get() method will return null upon completion */ public static ScheduledFuture<?> newTimeout(Runnable task, long delay, TimeUnit unit) { return SharedScheduledExecutors.getPoolThreadExecutor() .schedule(task, delay, unit); }
/** * Creates a new {@link KryoNamespace} builder. * * @return builder */ public static Builder newBuilder() { return new Builder(); }
/** * Convert a long number to colon-separated hex string. * Prepend zero padding until 8 bytes. * * @param val long number to be converted * @return converted colon-separated hex string, e.g. "0f:ca:fe:de:ad:be:ef" */ public static String toHexString(final long val) { return toHexString(val, 8); }
/** * Returns an instance representing the specified value in Hz. * * @param value frequency in Hz * @return instance representing the given frequency */ public static Frequency ofHz(long value) { return new Frequency(value); }
/** * Creates a new instance with given bandwidth in bps. * * @param bps bandwidth value to be assigned * @return {@link Bandwidth} instance with given bandwidth */ static Bandwidth bps(double bps) { return new DoubleBandwidth(bps); }
@Override public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) { return scheduleWithFixedDelay(command, initialDelay, delay, unit, false); }
/** * Returns an unmodifiable view of the specified Deque. * * @param <T> type * @param deque underlying {@link Deque} to use. * @return unmodifiable view of {@code deque} */ public static <T> Deque<T> unmodifiableDeque(Deque<T> deque) { return new UnmodifiableDeque<T>(deque); }
/** * Creates a new byte sequence that is prefixed with specified number of * zeros. * * @param size number of total bytes * @param prefixBits number of bits in prefix * @return new immutable byte sequence */ public static ImmutableByteSequence prefixZeros(int size, long prefixBits) { return prefix(size, prefixBits, (byte) 0); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof Bandwidth) { return this.compareTo((Bandwidth) obj) == 0; } return false; }
/** * Wraps the given {@link Callable} into {@link PickyCallable} returning supplied hint. * * @param callable {@link Callable} * @param hint hint value * @param <T> entity type * @return {@link PickyCallable} */ public static <T> PickyCallable<T> picky(Callable<T> callable, int hint) { return picky(callable, (c) -> hint); }
/** * Returns the number of occurrences per second. * * @return throughput in occurrences per second */ public synchronized double throughput() { return total / duration(); }
/** * Causes the current thread to wait until the boolean equals the specified * value unless the thread is {@linkplain Thread#interrupt interrupted}. * * @param value specified value * @throws InterruptedException if interrupted while waiting */ public void await(boolean value) throws InterruptedException { acquireSharedInterruptibly(value ? TRUE : FALSE); }
/** * Sets the value of the blocking boolean. * * @param value new value */ public void set(boolean value) { releaseShared(value ? TRUE : FALSE); }
@Override public boolean equals(Object that) { return super.equals(that); } }
/** * Returns a single-thread, bounded executor service. * * @param threadFactory thread factory for the worker thread. * @return the bounded thread pool */ public static BoundedThreadPool newSingleThreadExecutor(ThreadFactory threadFactory) { return new BoundedThreadPool(1, threadFactory); }
/** * Returns an instance representing the specified value in GHz. * * @param value frequency in GHz * @return instance representing the given frequency */ public static Frequency ofGHz(double value) { return new Frequency((long) (value * GHZ)); }
/** * Returns a Frequency whose value is (this * value). * * @param value value to be multiplied by this Frequency * @return this * value */ public Frequency multiply(long value) { return new Frequency(this.frequency * value); }