public class Utils
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
abbreviate(java.lang.String $receiver,
int maxWidth) |
static <T> rx.Observable<T> |
bufferUntilSubscribed(rx.Observable<T> $receiver)
Returns an Observable that buffers events until subscribed.
|
static <T> void |
catch(com.google.common.util.concurrent.SettableFuture<T> $receiver,
kotlin.jvm.functions.Function0<? extends T> block)
Executes the given block and sets the future to either the result, or any exception that was thrown.
|
static int |
checkedAdd(int $receiver,
int b)
Like the + operator but throws an exception in case of integer overflow.
|
static long |
checkedAdd(long $receiver,
long b)
Like the + operator but throws an exception in case of integer overflow.
|
static java.lang.String |
codePointsString(int codePoints) |
static long |
copyTo(java.io.InputStream $receiver,
java.nio.file.Path target,
java.nio.file.CopyOption options) |
static java.nio.file.Path |
createDirectories(java.nio.file.Path $receiver,
java.nio.file.attribute.FileAttribute attrs) |
static java.nio.file.Path |
createDirectory(java.nio.file.Path $receiver,
java.nio.file.attribute.FileAttribute attrs) |
static boolean |
deleteIfExists(java.nio.file.Path $receiver) |
static java.nio.file.Path |
div(java.nio.file.Path $receiver,
java.lang.String other)
Allows you to write code like: Paths.get("someDir") / "subdir" / "filename" but using the Paths API to avoid platform separator problems.
|
static java.time.Duration |
elapsedTime(kotlin.jvm.functions.Function0<kotlin.Unit> block) |
static boolean |
exists(java.nio.file.Path $receiver,
java.nio.file.LinkOption options) |
static void |
extractZipFile(java.nio.file.Path zipFile,
java.nio.file.Path toDirectory)
Given a path to a zip file, extracts it to the given directory.
|
static <T> void |
failure(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
java.util.concurrent.Executor executor,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> body) |
static <T> com.google.common.util.concurrent.ListenableFuture<T> |
failure(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> body) |
static <F,T> com.google.common.util.concurrent.ListenableFuture<T> |
flatMap(com.google.common.util.concurrent.ListenableFuture<F> $receiver,
kotlin.jvm.functions.Function1<? super F,? extends com.google.common.util.concurrent.ListenableFuture<T>> mapper) |
static <T> com.google.common.util.concurrent.ListenableFuture<T> |
future(kotlin.jvm.functions.Function0<? extends T> block) |
static java.math.BigDecimal |
getBd(int $receiver) |
static java.math.BigDecimal |
getBd(double $receiver) |
static java.math.BigDecimal |
getBd(java.lang.String $receiver) |
static java.math.BigDecimal |
getBd(long $receiver) |
static java.time.Duration |
getDays(int $receiver) |
static java.time.Duration |
getHours(int $receiver) |
static java.time.Duration |
getMillis(int $receiver) |
static java.time.Duration |
getMinutes(int $receiver) |
static <T> T |
getOrThrow(java.util.concurrent.Future<T> $receiver,
java.time.Duration timeout)
Same as Future.get but with a more descriptive name, and doesn't throw ExecutionException, instead throwing its cause
|
static java.lang.Throwable |
getRootCause(java.lang.Throwable $receiver) |
static java.util.concurrent.Executor |
getRunOnCallerThread() |
static java.time.Duration |
getSeconds(int $receiver) |
static long |
getSize(java.nio.file.Path $receiver) |
static <T> int |
indexOfOrThrow(java.util.List<? extends T> $receiver,
T item)
Returns the index of the given item or throws IllegalArgumentException if not found.
|
static boolean |
isDirectory(java.nio.file.Path $receiver,
java.nio.file.LinkOption options) |
static boolean |
isRegularFile(java.nio.file.Path $receiver,
java.nio.file.LinkOption options) |
static <R> R |
list(java.nio.file.Path $receiver,
kotlin.jvm.functions.Function1<? super java.util.stream.Stream<java.nio.file.Path>,? extends R> block) |
static <T> T |
logElapsedTime(java.lang.String label,
org.slf4j.Logger logger,
kotlin.jvm.functions.Function0<? extends T> body) |
static <T> T |
logElapsedTime(org.slf4j.Logger $receiver,
java.lang.String label,
kotlin.jvm.functions.Function0<? extends T> body) |
static <F,T> com.google.common.util.concurrent.ListenableFuture<T> |
map(com.google.common.util.concurrent.ListenableFuture<F> $receiver,
kotlin.jvm.functions.Function1<? super F,? extends T> mapper) |
static java.nio.file.Path |
moveTo(java.nio.file.Path $receiver,
java.nio.file.Path target,
java.nio.file.CopyOption options) |
static <T> T |
noneOrSingle(java.lang.Iterable<? extends T> $receiver,
kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Returns the single element matching the given predicate, or
null if element was not found,
or throws if more than one element was found. |
static <T> T |
noneOrSingle(java.lang.Iterable<? extends T> $receiver)
Returns single element, or
null if element was not found, or throws if more than one element was found. |
static long |
random63BitValue()
Returns a random positive long generated using a secure RNG. This function sacrifies a bit of entropy in order to
avoid potential bugs where the value is used in a context where negative numbers are not expected.
|
static <T> T |
randomOrNull(java.util.List<? extends T> $receiver)
Returns a random element in the list, or null if empty
|
static <T> T |
randomOrNull(java.util.List<? extends T> $receiver,
kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Returns a random element in the list matching the given predicate, or null if none found
|
static <R> R |
read(java.nio.file.Path $receiver,
java.nio.file.OpenOption[] options,
kotlin.jvm.functions.Function1<? super java.io.InputStream,? extends R> block) |
static byte[] |
readAll(java.nio.file.Path $receiver) |
static <R> R |
readLines(java.nio.file.Path $receiver,
java.nio.charset.Charset charset,
kotlin.jvm.functions.Function1<? super java.util.stream.Stream<java.lang.String>,? extends R> block) |
static <T> void |
success(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
java.util.concurrent.Executor executor,
kotlin.jvm.functions.Function1<? super T,kotlin.Unit> body) |
static <T> com.google.common.util.concurrent.ListenableFuture<T> |
success(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
kotlin.jvm.functions.Function1<? super T,kotlin.Unit> body) |
static java.math.BigDecimal |
sum(java.lang.Iterable<? extends java.math.BigDecimal> $receiver)
Return the sum of an Iterable of BigDecimals.
|
static <T> rx.Observer<T> |
tee(rx.Observer<T> $receiver,
rx.Observer teeTo)
Copy an Observer to multiple other Observers.
|
static <T> void |
then(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
java.util.concurrent.Executor executor,
kotlin.jvm.functions.Function0<kotlin.Unit> body) |
static <T> com.google.common.util.concurrent.ListenableFuture<T> |
then(com.google.common.util.concurrent.ListenableFuture<T> $receiver,
kotlin.jvm.functions.Function0<kotlin.Unit> body) |
static <T> com.google.common.util.concurrent.ListenableFuture<T> |
toFuture(rx.Observable<T> $receiver)
Returns a ListenableFuture bound to the first item emitted by this Observable. The future will complete with a
NoSuchElementException if no items are emitted or any other error thrown by the Observable. If it's cancelled then
it will unsubscribe from the observable.
|
static <A> rx.Observable<A> |
toObservable(com.google.common.util.concurrent.ListenableFuture<? extends A> $receiver) |
static java.time.Duration |
until(java.time.temporal.Temporal $receiver,
java.time.temporal.Temporal endExclusive) |
static void |
write(java.nio.file.Path $receiver,
boolean createDirs,
java.nio.file.OpenOption[] options,
kotlin.jvm.functions.Function1<? super java.io.OutputStream,kotlin.Unit> block) |
static java.nio.file.Path |
writeLines(java.nio.file.Path $receiver,
java.lang.Iterable<? extends java.lang.CharSequence> lines,
java.nio.charset.Charset charset,
java.nio.file.OpenOption options) |
public static java.time.Duration getDays(int $receiver)
public static java.time.Duration getHours(int $receiver)
public static java.time.Duration getMinutes(int $receiver)
public static java.time.Duration getSeconds(int $receiver)
public static java.time.Duration getMillis(int $receiver)
public static java.math.BigDecimal getBd(int $receiver)
public static java.math.BigDecimal getBd(double $receiver)
public static java.math.BigDecimal getBd(java.lang.String $receiver)
public static java.math.BigDecimal getBd(long $receiver)
public static java.lang.String abbreviate(java.lang.String $receiver, int maxWidth)
public static int checkedAdd(int $receiver, int b)
Like the + operator but throws an exception in case of integer overflow.
public static long checkedAdd(long $receiver, long b)
Like the + operator but throws an exception in case of integer overflow.
public static long random63BitValue()
Returns a random positive long generated using a secure RNG. This function sacrifies a bit of entropy in order to avoid potential bugs where the value is used in a context where negative numbers are not expected.
public static <T> T getOrThrow(java.util.concurrent.Future<T> $receiver, java.time.Duration timeout)
Same as Future.get but with a more descriptive name, and doesn't throw ExecutionException, instead throwing its cause
public static <T> com.google.common.util.concurrent.ListenableFuture<T> future(kotlin.jvm.functions.Function0<? extends T> block)
public static <T> void then(com.google.common.util.concurrent.ListenableFuture<T> $receiver, java.util.concurrent.Executor executor, kotlin.jvm.functions.Function0<kotlin.Unit> body)
public static <T> void success(com.google.common.util.concurrent.ListenableFuture<T> $receiver, java.util.concurrent.Executor executor, kotlin.jvm.functions.Function1<? super T,kotlin.Unit> body)
public static <T> void failure(com.google.common.util.concurrent.ListenableFuture<T> $receiver, java.util.concurrent.Executor executor, kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> body)
public static <T> com.google.common.util.concurrent.ListenableFuture<T> then(com.google.common.util.concurrent.ListenableFuture<T> $receiver, kotlin.jvm.functions.Function0<kotlin.Unit> body)
public static <T> com.google.common.util.concurrent.ListenableFuture<T> success(com.google.common.util.concurrent.ListenableFuture<T> $receiver, kotlin.jvm.functions.Function1<? super T,kotlin.Unit> body)
public static <T> com.google.common.util.concurrent.ListenableFuture<T> failure(com.google.common.util.concurrent.ListenableFuture<T> $receiver, kotlin.jvm.functions.Function1<? super java.lang.Throwable,kotlin.Unit> body)
public static <F,T> com.google.common.util.concurrent.ListenableFuture<T> map(com.google.common.util.concurrent.ListenableFuture<F> $receiver, kotlin.jvm.functions.Function1<? super F,? extends T> mapper)
public static <F,T> com.google.common.util.concurrent.ListenableFuture<T> flatMap(com.google.common.util.concurrent.ListenableFuture<F> $receiver, kotlin.jvm.functions.Function1<? super F,? extends com.google.common.util.concurrent.ListenableFuture<T>> mapper)
public static <T> void catch(com.google.common.util.concurrent.SettableFuture<T> $receiver, kotlin.jvm.functions.Function0<? extends T> block)
Executes the given block and sets the future to either the result, or any exception that was thrown.
public static <A> rx.Observable<A> toObservable(com.google.common.util.concurrent.ListenableFuture<? extends A> $receiver)
public static java.nio.file.Path div(java.nio.file.Path $receiver, java.lang.String other)
Allows you to write code like: Paths.get("someDir") / "subdir" / "filename" but using the Paths API to avoid platform separator problems.
public static java.nio.file.Path createDirectory(java.nio.file.Path $receiver, java.nio.file.attribute.FileAttribute attrs)
public static java.nio.file.Path createDirectories(java.nio.file.Path $receiver, java.nio.file.attribute.FileAttribute attrs)
public static boolean exists(java.nio.file.Path $receiver, java.nio.file.LinkOption options)
public static java.nio.file.Path moveTo(java.nio.file.Path $receiver, java.nio.file.Path target, java.nio.file.CopyOption options)
public static boolean isRegularFile(java.nio.file.Path $receiver, java.nio.file.LinkOption options)
public static boolean isDirectory(java.nio.file.Path $receiver, java.nio.file.LinkOption options)
public static long getSize(java.nio.file.Path $receiver)
public static <R> R list(java.nio.file.Path $receiver, kotlin.jvm.functions.Function1<? super java.util.stream.Stream<java.nio.file.Path>,? extends R> block)
public static boolean deleteIfExists(java.nio.file.Path $receiver)
public static byte[] readAll(java.nio.file.Path $receiver)
public static <R> R read(java.nio.file.Path $receiver, java.nio.file.OpenOption[] options, kotlin.jvm.functions.Function1<? super java.io.InputStream,? extends R> block)
public static void write(java.nio.file.Path $receiver, boolean createDirs, java.nio.file.OpenOption[] options, kotlin.jvm.functions.Function1<? super java.io.OutputStream,kotlin.Unit> block)
public static <R> R readLines(java.nio.file.Path $receiver, java.nio.charset.Charset charset, kotlin.jvm.functions.Function1<? super java.util.stream.Stream<java.lang.String>,? extends R> block)
public static java.nio.file.Path writeLines(java.nio.file.Path $receiver, java.lang.Iterable<? extends java.lang.CharSequence> lines, java.nio.charset.Charset charset, java.nio.file.OpenOption options)
public static long copyTo(java.io.InputStream $receiver, java.nio.file.Path target, java.nio.file.CopyOption options)
public static java.time.Duration until(java.time.temporal.Temporal $receiver, java.time.temporal.Temporal endExclusive)
public static <T> int indexOfOrThrow(java.util.List<? extends T> $receiver, T item)
Returns the index of the given item or throws IllegalArgumentException if not found.
public static <T> T noneOrSingle(java.lang.Iterable<? extends T> $receiver, kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Returns the single element matching the given predicate, or null
if element was not found,
or throws if more than one element was found.
public static <T> T noneOrSingle(java.lang.Iterable<? extends T> $receiver)
Returns single element, or null
if element was not found, or throws if more than one element was found.
public static <T> T randomOrNull(java.util.List<? extends T> $receiver)
Returns a random element in the list, or null if empty
public static <T> T randomOrNull(java.util.List<? extends T> $receiver, kotlin.jvm.functions.Function1<? super T,java.lang.Boolean> predicate)
Returns a random element in the list matching the given predicate, or null if none found
public static java.util.concurrent.Executor getRunOnCallerThread()
public static java.time.Duration elapsedTime(kotlin.jvm.functions.Function0<kotlin.Unit> block)
public static <T> T logElapsedTime(java.lang.String label, org.slf4j.Logger logger, kotlin.jvm.functions.Function0<? extends T> body)
public static <T> T logElapsedTime(org.slf4j.Logger $receiver, java.lang.String label, kotlin.jvm.functions.Function0<? extends T> body)
public static void extractZipFile(java.nio.file.Path zipFile, java.nio.file.Path toDirectory)
Given a path to a zip file, extracts it to the given directory.
public static java.lang.Throwable getRootCause(java.lang.Throwable $receiver)
public static <T> rx.Observable<T> bufferUntilSubscribed(rx.Observable<T> $receiver)
Returns an Observable that buffers events until subscribed.
public static <T> rx.Observer<T> tee(rx.Observer<T> $receiver, rx.Observer teeTo)
Copy an Observer to multiple other Observers.
public static <T> com.google.common.util.concurrent.ListenableFuture<T> toFuture(rx.Observable<T> $receiver)
Returns a ListenableFuture bound to the first item emitted by this Observable. The future will complete with a NoSuchElementException if no items are emitted or any other error thrown by the Observable. If it's cancelled then it will unsubscribe from the observable.
public static java.math.BigDecimal sum(java.lang.Iterable<? extends java.math.BigDecimal> $receiver)
Return the sum of an Iterable of BigDecimals.
public static java.lang.String codePointsString(int codePoints)