public class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static com.google.common.base.Predicate<com.google.common.collect.Range<org.joda.time.DateTime>> |
isDateTimeRangeNotEmpty |
static com.google.common.base.Predicate<com.google.common.collect.Range<java.math.BigDecimal>> |
isDecimalRangeNotEmpty |
static com.google.common.base.Predicate<com.google.common.collect.Range<java.lang.Double>> |
isDoubleRangeNotEmpty |
static com.google.common.base.Predicate<java.lang.String> |
isNotEmpty
Returns true if given string is not null or empty.
|
static com.google.common.base.Predicate<java.lang.Object> |
isNotNull
Returns true if given object is not null.
|
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static <T extends java.lang.Comparable> |
closedRange(T from,
T to)
Creates a range based on (nullable) bounds.
|
static java.lang.String |
debugPrintRequestHolder(TestableRequestHolder request)
Serializes a TestableRequestHolder, usually for logging or debugging purposes.
|
static java.lang.String |
emptyIfNull(java.lang.String s)
Returns empty string if given null, original string otherwise.
|
static java.util.Locale |
fromLanguageTag(java.lang.String s) |
static java.lang.String |
getDecodedUrl(com.ning.http.client.Request request)
Gets full decoded URL including query string.
|
static <T extends SphereError> |
getError(SphereBackendException e,
java.lang.Class<T> errorClass)
If the exception contains an one error of given type, returns it.
|
static <T extends SphereError> |
getSingleError(SphereBackendException e,
java.lang.Class<T> errorClass)
If the exception contains exactly one error and it is of given type, returns it.
|
static <T> T |
getValueOrThrow(SphereResult<T> result)
If successful, gets the value.
|
static <T extends java.lang.Comparable> |
isRangeNotEmpty()
Returns true if given range is not null and has at least one endpoint.
|
static java.lang.String |
prettyPrintJsonStringSecure(java.lang.String json)
Pretty prints given JSON string, replacing passwords by
'xxxxx' . |
static java.lang.String |
requestResponseToString(com.ning.http.client.Request request,
com.ning.http.client.Response response)
Serializes request and response, usually for logging or debugging purposes.
|
static java.lang.String |
requestToString(com.ning.http.client.Request request)
Serializes request, usually for logging or debugging purposes.
|
static <T> T |
sync(com.google.common.util.concurrent.ListenableFuture<T> future)
Blocks, wraps exceptions as
SphereExceptions . |
static <T> T |
syncResult(com.google.common.util.concurrent.ListenableFuture<SphereResult<T>> future)
Blocks, extracts success value, converts Sphere errors to exceptions.
|
static java.lang.String |
toLanguageTag(java.util.Locale l)
Encodes a Locale to a BCP-47-conformant language tag.
|
static SphereClientException |
toSphereException(java.lang.Throwable t) |
static java.lang.String |
urlEncode(java.lang.String s)
Encodes urls with US-ASCII.
|
public static final com.google.common.base.Predicate<java.lang.String> isNotEmpty
public static final com.google.common.base.Predicate<java.lang.Object> isNotNull
public static final com.google.common.base.Predicate<com.google.common.collect.Range<java.lang.Double>> isDoubleRangeNotEmpty
public static final com.google.common.base.Predicate<com.google.common.collect.Range<java.math.BigDecimal>> isDecimalRangeNotEmpty
public static final com.google.common.base.Predicate<com.google.common.collect.Range<org.joda.time.DateTime>> isDateTimeRangeNotEmpty
public static java.lang.String emptyIfNull(java.lang.String s)
public static <T extends java.lang.Comparable> com.google.common.collect.Range<T> closedRange(@Nullable T from, @Nullable T to)
public static java.lang.String urlEncode(java.lang.String s)
public static java.lang.String toLanguageTag(java.util.Locale l)
public static java.util.Locale fromLanguageTag(@Nonnull java.lang.String s)
public static <T> T sync(com.google.common.util.concurrent.ListenableFuture<T> future)
SphereExceptions
.public static SphereClientException toSphereException(java.lang.Throwable t)
public static <T> T syncResult(com.google.common.util.concurrent.ListenableFuture<SphereResult<T>> future)
public static <T> T getValueOrThrow(SphereResult<T> result)
public static <T extends SphereError> T getSingleError(SphereBackendException e, java.lang.Class<T> errorClass)
public static <T extends SphereError> T getError(SphereBackendException e, java.lang.Class<T> errorClass)
public static java.lang.String requestToString(com.ning.http.client.Request request)
public static java.lang.String getDecodedUrl(com.ning.http.client.Request request)
public static java.lang.String requestResponseToString(com.ning.http.client.Request request, com.ning.http.client.Response response)
public static java.lang.String debugPrintRequestHolder(TestableRequestHolder request)
public static java.lang.String prettyPrintJsonStringSecure(java.lang.String json) throws java.io.IOException
'xxxxx'
.java.io.IOException
public static <T extends java.lang.Comparable> com.google.common.base.Predicate<com.google.common.collect.Range<T>> isRangeNotEmpty()