Package clarifai2.internal
Class InternalUtil
- java.lang.Object
-
- clarifai2.internal.InternalUtil
-
public final class InternalUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static okhttp3.MediaType
MEDIA_TYPE_JSON
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areNullsPresentInDictionaries(@NotNull com.google.gson.JsonElement json)
static @NotNull com.google.gson.JsonObject
asGeoPointJson(@NotNull PointF geoPoint)
static GeoOuterClass.GeoPoint
asGeoPointProto(@NotNull PointF geoPoint)
static <T extends com.google.gson.JsonElement>
TassertJsonIs(@Nullable com.google.gson.JsonElement json, @NotNull java.lang.Class<T> expectedType)
Asserts that the given JSON is of the type expected, and casts it to that type.static void
assertMetadataHasNoNulls(@NotNull com.google.gson.JsonObject json)
static <T> T
assertNotNull(T in)
static @NotNull ClarifaiClient
clientInstance(@NotNull com.google.gson.Gson gson)
static @NotNull com.google.gson.JsonElement
coerceJsonNull(@Nullable com.google.gson.JsonElement in)
static <T> @NotNull java.util.List<T>
copyArray(@NotNull com.google.gson.JsonArray in, @NotNull Func1<com.google.gson.JsonElement,T> mapper)
static <T> T
fromJson(@NotNull com.google.gson.Gson gson, @Nullable com.google.gson.JsonElement element, @NotNull com.google.gson.reflect.TypeToken<T> type)
static <T> T
fromJson(@NotNull com.google.gson.Gson gson, @Nullable com.google.gson.JsonElement element, @NotNull java.lang.Class<T> type)
static boolean
isJsonNull(@Nullable com.google.gson.JsonElement in)
static boolean
isRawType(@NotNull com.google.gson.reflect.TypeToken<?> token)
static <E extends com.google.gson.JsonElement>
EjsonDeepCopy(E in)
static <T> boolean
nullSafeEquals(T o1, T o2)
static @org.jetbrains.annotations.NotNull byte[]
read(java.io.File file)
static void
sleep(long millis)
static <T> @NotNull com.google.gson.JsonElement
toJson(@NotNull com.google.gson.Gson gson, T obj, @NotNull com.google.gson.reflect.TypeToken<T> type)
static <T> @NotNull com.google.gson.JsonElement
toJson(@NotNull com.google.gson.Gson gson, T obj, @NotNull java.lang.Class<T> type)
-
-
-
Method Detail
-
isRawType
public static boolean isRawType(@NotNull @NotNull com.google.gson.reflect.TypeToken<?> token)
-
assertNotNull
@Contract("null -> fail") @NotNull public static <T> T assertNotNull(@Nullable T in)
-
isJsonNull
@Contract("null -> true") public static boolean isJsonNull(@Nullable @Nullable com.google.gson.JsonElement in)
-
coerceJsonNull
@NotNull public static @NotNull com.google.gson.JsonElement coerceJsonNull(@Nullable @Nullable com.google.gson.JsonElement in)
-
assertJsonIs
@NotNull public static <T extends com.google.gson.JsonElement> T assertJsonIs(@Nullable @Nullable com.google.gson.JsonElement json, @NotNull @NotNull java.lang.Class<T> expectedType) throws com.google.gson.JsonParseException
Asserts that the given JSON is of the type expected, and casts it to that type.- Type Parameters:
T
- the type that we are asserting this JSON is- Parameters:
json
- the JSON in question. Ifnull
is passed, it is coerced toJsonNull.INSTANCE
expectedType
- the type that we are asserting this JSON is- Returns:
- this JSON, casted to the asserted type
- Throws:
com.google.gson.JsonParseException
- if the JSON was not of the asserted type
-
assertMetadataHasNoNulls
public static void assertMetadataHasNoNulls(@NotNull @NotNull com.google.gson.JsonObject json)
-
areNullsPresentInDictionaries
public static boolean areNullsPresentInDictionaries(@NotNull @NotNull com.google.gson.JsonElement json)
- Parameters:
json
- the JSON to check- Returns:
true
if this JSON is aJsonNull
or if any of the elements it contains, recursively, areJsonNull
s
-
copyArray
@NotNull public static <T> @NotNull java.util.List<T> copyArray(@NotNull @NotNull com.google.gson.JsonArray in, @NotNull @NotNull Func1<com.google.gson.JsonElement,T> mapper)
-
jsonDeepCopy
@NotNull public static <E extends com.google.gson.JsonElement> E jsonDeepCopy(@NotNull E in)
-
asGeoPointJson
@NotNull public static @NotNull com.google.gson.JsonObject asGeoPointJson(@NotNull @NotNull PointF geoPoint)
-
asGeoPointProto
@NotNull public static GeoOuterClass.GeoPoint asGeoPointProto(@NotNull @NotNull PointF geoPoint)
-
sleep
public static void sleep(long millis)
-
clientInstance
@NotNull public static @NotNull ClarifaiClient clientInstance(@NotNull @NotNull com.google.gson.Gson gson)
-
fromJson
@Nullable public static <T> T fromJson(@NotNull @NotNull com.google.gson.Gson gson, @Nullable @Nullable com.google.gson.JsonElement element, @NotNull @NotNull java.lang.Class<T> type)
-
toJson
@NotNull public static <T> @NotNull com.google.gson.JsonElement toJson(@NotNull @NotNull com.google.gson.Gson gson, @Nullable T obj, @NotNull @NotNull java.lang.Class<T> type)
-
fromJson
@Nullable public static <T> T fromJson(@NotNull @NotNull com.google.gson.Gson gson, @Nullable @Nullable com.google.gson.JsonElement element, @NotNull @NotNull com.google.gson.reflect.TypeToken<T> type)
-
toJson
@NotNull public static <T> @NotNull com.google.gson.JsonElement toJson(@NotNull @NotNull com.google.gson.Gson gson, @Nullable T obj, @NotNull @NotNull com.google.gson.reflect.TypeToken<T> type)
-
nullSafeEquals
@Contract("null, null -> true; null, !null -> false; !null, null -> false") public static <T> boolean nullSafeEquals(@Nullable T o1, @Nullable T o2)
-
read
@NotNull public static @org.jetbrains.annotations.NotNull byte[] read(java.io.File file)
-
-