Package com.google.genai.gaos.utils
Class Utils
java.lang.Object
com.google.genai.gaos.utils.Utils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic enumstatic final class -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallowIntrospection(Class<?> cls) static <T> TasType(EventStreamMessage x, com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) static <N> Nstatic voidcheckArgument(boolean expression, String message) static <T> TcheckNotNull(T object, String name) static voidstatic HTTPRequestconfigureSecurity(HTTPRequest request, Object security, String... allowedFields) static booleancontentTypeMatches(String contentType, String pattern) static ObjectconvertToShape(Object o, Utils.JsonShape shape, com.fasterxml.jackson.core.type.TypeReference<?> typeReference) static com.fasterxml.jackson.databind.JavaTypeconvertToStringShape(com.fasterxml.jackson.databind.type.TypeFactory f, com.fasterxml.jackson.databind.JavaType a) static HTTPClientcreateTestHTTPClient(SpeakeasyHTTPClient client, String testName) static HTTPClientcreateTestHTTPClient(String testName) static Stringstatic <K,V> Map<K, V> emptyMapIfNull(Map<K, V> map) static booleanenhancedDeepEquals(Object a, Object b) Returns true if and only if the two objects are deeply equal, uses mathematical equivalence for Number subclasses (2 == 2.0) instead ofNumber.equals.static intenhancedHash(Object... objects) Returns a combined hash code (applyingenhancedHashCode(java.lang.Object)) for the given objects (usually the fields of an object whose hashCode we want to be calculated).static intReturns a hash code that complies with the equals/hashCode contract when equals is implemented byenhancedDeepEquals(Object, Object).static StringenvironmentVariable(String name, String defaultValue) Internal use.static byte[]extractByteArrayFromBody(HttpResponse<InputStream> response) static <T> StringgenerateURL(Class<T> type, String baseURL, String path, Optional<? extends T> params, Globals globals) static <T> StringgenerateURL(Class<T> type, String baseURL, String path, T params, Globals globals) static StringgenerateURL(String baseURL, String path) getHeadersFromMetadata(Object headers, Globals globals) static <T> List<QueryParameter>getQueryParams(Class<T> type, Optional<? extends T> params, Globals globals) static <T> List<QueryParameter>getQueryParams(Class<T> type, T params, Globals globals) static booleanisPresentAndNotNull(Optional<?> x) static Stringjson(EventStreamMessage m, com.fasterxml.jackson.databind.ObjectMapper mapper, boolean dataIsPlainText) static com.fasterxml.jackson.databind.ObjectMappermapper()static ObjectpopulateGlobal(Object value, String fieldName, String paramType, Globals globals) static StringprefixBearer(String authHeaderValue) static byte[]static byte[]readBytes(InputStream in) static byte[]static byte[]static <T> TreadDefaultOrConstValue(String name, String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) static StringreadString(File file) static StringreadString(String filename) static voidrecordTest(String id) static booleanreferenceEquals(Object a, Object b) static Objectstatic SerializedBodyserializeRequestBody(Object request, String requestField, String serializationMethod, boolean nullable) static StringsessionKey(String... items) static voidsetSseSentinel(Object o, String value) static StringsortJSONObjectKeys(String json, String... fields) static StringReturns an equivalent url with query parameters sorted by name.static ObjectsortSerializedMaps(Object input, String regex, String delim) static booleanstatusCodeMatches(int statusCode, String... expectedStatusCodes) static booleanstatusCodeMatchesOne(int statusCode, String expectedStatusCode) static <T> Stream<T>stream(Callable<Optional<T>> first, Utils.Function<T, Optional<T>> next) static StringtemplateUrl(String url, Map<String, String> params) static byte[]static StringtoHex(byte[] bytes) static List<?>static <T> Stream<T>static Stringstatic Stringstatic <I,O> Iterator<O> transform(Iterator<I> iterator, Utils.Function<I, O> mapper) static <T> Tunmarshal(HttpResponse<InputStream> response, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) static StringvalToString(Object value) static <T> TvalueOrElse(Optional<T> value, T valueIfNotPresent) static <T> TvalueOrElse(T value, T valueIfNotPresent) static <T> TvalueOrNull(Optional<T> value) static <T> TvalueOrNull(T value)
-
Method Details
-
referenceEquals
-
generateURL
- Throws:
IllegalArgumentException
-
generateURL
public static <T> String generateURL(Class<T> type, String baseURL, String path, Optional<? extends T> params, Globals globals) throws com.fasterxml.jackson.core.JsonProcessingException, IllegalArgumentException, IllegalAccessException - Throws:
com.fasterxml.jackson.core.JsonProcessingExceptionIllegalArgumentExceptionIllegalAccessException
-
generateURL
public static <T> String generateURL(Class<T> type, String baseURL, String path, T params, Globals globals) throws IllegalArgumentException, IllegalAccessException, com.fasterxml.jackson.core.JsonProcessingException - Throws:
IllegalArgumentExceptionIllegalAccessExceptioncom.fasterxml.jackson.core.JsonProcessingException
-
contentTypeMatches
-
allowIntrospection
-
serializeRequestBody
public static SerializedBody serializeRequestBody(Object request, String requestField, String serializationMethod, boolean nullable) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, UnsupportedOperationException, IOException -
getQueryParams
public static <T> List<QueryParameter> getQueryParams(Class<T> type, Optional<? extends T> params, Globals globals) throws Exception - Throws:
Exception
-
getQueryParams
public static <T> List<QueryParameter> getQueryParams(Class<T> type, T params, Globals globals) throws Exception - Throws:
Exception
-
configureSecurity
public static HTTPRequest configureSecurity(HTTPRequest request, Object security, String... allowedFields) throws Exception - Throws:
Exception
-
templateUrl
-
getHeadersFromMetadata
public static Map<String,List<String>> getHeadersFromMetadata(Object headers, Globals globals) throws Exception - Throws:
Exception
-
valToString
-
prefixBearer
-
populateGlobal
-
checkNotNull
-
checkArgument
-
emptyMapIfNull
-
toString
-
resolveOptionals
-
toList
-
readDefaultOrConstValue
-
extractByteArrayFromBody
public static byte[] extractByteArrayFromBody(HttpResponse<InputStream> response) throws IOException - Throws:
IOException
-
toByteArrayAndClose
- Throws:
IOException
-
closeQuietly
-
toUtf8AndClose
- Throws:
IOException
-
convertToShape
public static Object convertToShape(Object o, Utils.JsonShape shape, com.fasterxml.jackson.core.type.TypeReference<?> typeReference) -
convertToStringShape
public static com.fasterxml.jackson.databind.JavaType convertToStringShape(com.fasterxml.jackson.databind.type.TypeFactory f, com.fasterxml.jackson.databind.JavaType a) -
stream
-
toStream
-
statusCodeMatches
-
statusCodeMatchesOne
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper() -
asType
public static <T> T asType(EventStreamMessage x, com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) -
json
public static String json(EventStreamMessage m, com.fasterxml.jackson.databind.ObjectMapper mapper, boolean dataIsPlainText) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
readBytes
-
readString
-
readBytes
-
readString
-
readBytesAndClose
-
readBytes
-
toHex
-
discriminatorToString
-
recordTest
-
sortQueryParameters
Returns an equivalent url with query parameters sorted by name. Sort is stable in that parameters with the same name will not be reordered.- Parameters:
url- input- Returns:
- url with query parameters sorted by name
-
sortSerializedMaps
-
isPresentAndNotNull
-
setSseSentinel
-
sessionKey
-
createTestHTTPClient
-
createTestHTTPClient
-
environmentVariable
Internal use. Returns the system property withkey = "env." + nameand if doesn't exist returns the value of the environment variable with the given name of if it doesn't exist returnsdefaultValue.- Parameters:
name- variable namedefaultValue- default value if system property and environment variable don't exist- Returns:
- system property with name prepended with ".env" or environment variable of given name or default value
-
sortJSONObjectKeys
-
valueOrElse
public static <T> T valueOrElse(T value, T valueIfNotPresent) -
valueOrElse
-
valueOrNull
public static <T> T valueOrNull(T value) -
valueOrNull
-
castLong
-
transform
-
enhancedDeepEquals
Returns true if and only if the two objects are deeply equal, uses mathematical equivalence for Number subclasses (2 == 2.0) instead ofNumber.equals.Should be paired with
enhancedHashCode(Object)to ensure the equals/hashCode contract.- Parameters:
a- the first object to compareb- the second object to compare- Returns:
- true if the objects are deeply equal bearing in mind mathematical equivalence, false otherwise
-
enhancedHash
Returns a combined hash code (applyingenhancedHashCode(java.lang.Object)) for the given objects (usually the fields of an object whose hashCode we want to be calculated).- Parameters:
objects-- Returns:
- combined hash code for the objects, 0 if the objects are null
-
enhancedHashCode
Returns a hash code that complies with the equals/hashCode contract when equals is implemented byenhancedDeepEquals(Object, Object).- Parameters:
o- object to calculate the hash code for (can be null)- Returns:
- hash code for the object, 0 if the object is null
-
unmarshal
public static <T> T unmarshal(HttpResponse<InputStream> response, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
-