public class Utilities extends Object
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static Number |
extractFieldAsNumber(String field,
com.yahoo.bullet.record.BulletRecord record)
Extracts the field from the given (@link BulletRecord} as a
Number , if possible. |
static double[] |
generatePoints(double start,
Function<Double,Double> generator,
int numberOfPoints,
int rounding)
Generates an array of points from the given arguments.
|
static <U> U |
getCasted(Map<String,Object> map,
String key,
Class<U> clazz)
Tries to get a key from a map as the target type.
|
static <U> U |
getCasted(Object entry,
Class<U> clazz)
Tries to get the object casted as the target type.
|
static boolean |
isEmpty(Collection collection)
Checks to see if the
Collection contains any items. |
static boolean |
isEmpty(Map map)
Checks to see if the
Map contains any mappings. |
static boolean |
isEmpty(String string)
Checks to see if the
String is present. |
static <S> S |
loadConfiguredClass(String name,
BulletConfig config)
This method loads a given class name with the class name key and creates an instance of it by using a constructor
that has a single argument for a
BulletConfig . |
static <K,V> Map<K,V> |
putNotNull(Map<K,V> map,
K key,
V value)
Adds the given mapping to the given
Map if the value is not null. |
static <T> List<T> |
requireNonNull(List<T> list)
Throws a
NullPointerException if the List is null or contains any null elements. |
static <K,V> Map<K,V> |
requireNonNull(Map<K,V> map)
Throws a
NullPointerException if the Map is null or contains any null keys or null values. |
static <T> Set<T> |
requireNonNull(Set<T> set)
Throws a
NullPointerException if the Set is null or contains any null elements. |
static double |
round(double value,
int places)
Rounds a double up to the specified number of places.
|
public static <U> U getCasted(Object entry, Class<U> clazz)
U
- The type to get the object as.entry
- The object to cast.clazz
- The class of the U.public static <U> U getCasted(Map<String,Object> map, String key, Class<U> clazz)
U
- The type to get the object as.map
- The non-null map that possibly contains the key.key
- The String key to get the value for from the map.clazz
- The class of the U.NullPointerException
- if the map was null.public static boolean isEmpty(Map map)
Map
contains any mappings.map
- The map to check.public static boolean isEmpty(Collection collection)
Collection
contains any items.collection
- The collection to check.public static boolean isEmpty(String string)
String
is present.string
- The string to check.public static <T> List<T> requireNonNull(List<T> list)
NullPointerException
if the List
is null or contains any null elements.T
- The type of the list.list
- The list to check.public static <T> Set<T> requireNonNull(Set<T> set)
NullPointerException
if the Set
is null or contains any null elements.T
- The type of the set.set
- The set to check.public static <K,V> Map<K,V> requireNonNull(Map<K,V> map)
NullPointerException
if the Map
is null or contains any null keys or null values.K
- The type of the map key.V
- The type of the map value.map
- The map to check.public static <K,V> Map<K,V> putNotNull(Map<K,V> map, K key, V value)
Map
if the value is not null.K
- The type of the map key.V
- The type of the map value.map
- The map to check.key
- The key to add.value
- The value to add if not null.public static double round(double value, int places)
value
- The number to round.places
- The number of maximum decimal places to round up to.public static double[] generatePoints(double start, Function<Double,Double> generator, int numberOfPoints, int rounding)
start
- The first point to begin with.generator
- A function that returns the next point given the previous.numberOfPoints
- The size of the resulting array.rounding
- The number of maximum decimal places to round up to.public static Number extractFieldAsNumber(String field, com.yahoo.bullet.record.BulletRecord record)
Number
, if possible.field
- The field to get as a number.record
- The record containing the field.Number
or null if it cannot be forced to one.public static <S> S loadConfiguredClass(String name, BulletConfig config)
BulletConfig
. It then passes in the provided config and returns the
constructed instance.S
- The type of the class.name
- The name of class name to load.config
- The BulletConfig
to use to create an instance of the class.RuntimeException
- if there were issues creating an instance. It wraps the real exception.Copyright © 2021. All rights reserved.