public class Utils extends Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
addToMetricDictionary(MetricDictionary metricDictionary,
List<MetricInstance> metrics)
Create metrics from instance descriptors and store in the metric dictionary.
|
static <E> LinkedHashSet<E> |
asLinkedHashSet(E... e)
Easily turn a few instances of an object into a LinkedHashSet.
|
static void |
createParentDirectories(String path)
Create parent directories if they don't exist in a given file path.
|
static void |
deleteFiles(String path)
Delete files or directories in the specified path.
|
static <T extends Comparable> |
getMinValue(T one,
T two)
Find the minimum value between two comparable objects.
|
static <T,K extends T> |
getSubsetByType(Collection<T> set,
Class<K> type)
Given a collection of objects which share the same super class, return the subset of objects that share a common
sub class.
|
static javax.ws.rs.core.MultivaluedMap<String,String> |
headersToLowerCase(javax.ws.rs.core.MultivaluedMap<String,String> headers)
Helper method to return request headers as a map of the same type with its keys lower cased.
|
static <T> T |
insteadThrowRuntime(RuntimeException exception)
Helper method to throw an exception when a result is expected as a return value (e.g.
|
static void |
omitField(com.fasterxml.jackson.databind.JsonNode node,
String fieldName,
com.fasterxml.jackson.databind.ObjectMapper mapper)
Given a field name and a tree of json nodes, empty the contents of all the json nodes matching the field name.
|
static <T,U,V> org.apache.commons.lang3.tuple.ImmutablePair<T,V> |
withRight(org.apache.commons.lang3.tuple.ImmutablePair<T,U> pair,
V right)
Given an ImmutablePair, and a right value, returns a new ImmutablePair with the same left value,
and the specified right value.
|
public static <T,K extends T> LinkedHashSet<K> getSubsetByType(Collection<T> set, Class<K> type)
T
- Input set typeK
- sub class typeset
- Input settype
- sub class@SafeVarargs public static <E> LinkedHashSet<E> asLinkedHashSet(E... e)
LinkedHashSet<String> stooges = Utils.asLinkedHashSet("Larry", "Moe", "Curly");
E
- The element type for the linked hash sete
- The array from which the LinkedHashSet will be builtpublic static void createParentDirectories(String path)
path
- The pathnamepublic static void deleteFiles(String path)
path
- The pathnamepublic static <T> T insteadThrowRuntime(RuntimeException exception)
T
- The type of exception being returnedexception
- The exception to be thrownpublic static javax.ws.rs.core.MultivaluedMap<String,String> headersToLowerCase(javax.ws.rs.core.MultivaluedMap<String,String> headers)
headers
- The request headers.public static void omitField(com.fasterxml.jackson.databind.JsonNode node, String fieldName, com.fasterxml.jackson.databind.ObjectMapper mapper)
node
- The root of the tree of json nodes.fieldName
- The name of the node to be omitted.mapper
- The object mapper that creates and empty node.public static <T extends Comparable> T getMinValue(T one, T two)
T
- Type of object to compareone
- Item 1two
- Item 2public static <T,U,V> org.apache.commons.lang3.tuple.ImmutablePair<T,V> withRight(org.apache.commons.lang3.tuple.ImmutablePair<T,U> pair, V right)
T
- Left type of the pairU
- Right type of the pairV
- The right value to have new Immutable Pairpair
- Immutable Pair instanceright
- The right value, may be nullpublic static void addToMetricDictionary(MetricDictionary metricDictionary, List<MetricInstance> metrics)
metricDictionary
- The dictionary to store metrics inmetrics
- The list of metric descriptorsCopyright © 2016–2018 Yahoo! Inc.. All rights reserved.