/** * Returns the default value of the configuration, cast to the expected type. * * @param clazz The class of the expected type of the configuration value. * @param <T> The expected type of the configuration value. */ public <T> T getDefault(Class<T> clazz) { return defaultValue == null ? null: ConversionUtils.convert(defaultValue, clazz); }
/** * Get sublist starting at index and convert types */ private List<HyperLogLogPlus> getEstimatorsFromIndex(List<Object> args, int index) { return ConversionUtils.convertList(args.subList(index, args.size()), HyperLogLogPlus.class); } }
/** * @return The default value of the property. */ public <T> T getDefault(Class<T> clazz) { return ConversionUtils.convert(defaultValue, clazz); }
public <T> T getDefault(Class<T> clazz) { return defaultValue == null?null:ConversionUtils.convert(defaultValue, clazz); }
private static <T> T getParam(Map<String, Object> config, String key, T defaultVal, Class<T> clazz) { Object o = config.get(key); if(o == null) { return defaultVal; } T ret = ConversionUtils.convert(o, clazz); return ret == null?defaultVal:ret; } }
/** * Performs naive List type conversion. * * @param from Source list * @param clazz Class type to cast the List elements to * @param <T> Source element type * @param <U> Desired element type * @return New List with the elements cast to the desired type */ public static <T, U> List<U> convertList(List<T> from, Class<U> clazz) { return Lists.transform(from, s -> convert(s, clazz)); }
/** * Retrieves the property value from a map of properties. * @param properties A map of properties. * @return The value of the property within the map. */ public <T> T get(Map<Object, Object> properties, Class<T> clazz) { Object o = properties.getOrDefault(key, defaultValue); return o == null ? null : ConversionUtils.convert(o, clazz); }
public static <T> T getAs(String key, Map<String, Object> map, T defaultValue, Class<T> clazz) { return map == null ? defaultValue : ConversionUtils.convert(map.getOrDefault(key, defaultValue), clazz); }
/** * Performs naive Map type conversion on values. Key types remain unchanged. * * @param from Source map * @param clazz Class type to cast the Map values to * @param <K> Map key type * @param <V1> Source value type * @param <V2> Desired value type * @return New Map with the values cast to the desired type */ public static <K, V1, V2> Map<K, V2> convertMap(Map<K, V1> from, Class<V2> clazz) { return Maps.transformValues(from, s -> convert(s, clazz)); }
private static boolean doNegativeValuesTrump(Map<String, Object> config) { boolean negativeValuesTrump = true; Object negValuesObj = config.get(NEGATIVE_VALUES_TRUMP_CONF); if(negValuesObj != null) { Boolean b = ConversionUtils.convert(negValuesObj, Boolean.class); if(b != null) { negativeValuesTrump = b; } } return negativeValuesTrump; } private static double accumulate(double initial, BinaryOperator<Number> op, List<Number> list, Map<String, Object> config) {
public <T> T getOrDefault(Map<String, Object> profilerConfig, Object defaultValue, Class<T> clazz) { Object o = profilerConfig.getOrDefault(key, defaultValue); return o == null?null:ConversionUtils.convert(o, clazz); }
/** * Return the max wait time setting. * * @param properties The function configuration properties. * @return The mex wait time in milliseconds. */ private static int getMaxWait(Properties properties) { int maxWait = DEFAULT_MAX_WAIT; Object value = properties.get(MAX_WAIT_PROPERTY); if(value != null) { maxWait = ConversionUtils.convert(value, Integer.class); } return maxWait; }
@Override public Object apply(List<Object> strings ) { return strings.get(0) == null?null: ConversionUtils.convert(strings.get(0), clazz); } }
/** * Returns the poll timeout setting. * * <p>The maximum amount of time waited each time that Kafka is polled * for messages. * * @param properties The function configuration properties. * @return */ private static int getPollTimeout(Properties properties) { int pollTimeout = DEFAULT_POLL_TIMEOUT; Object value = properties.get(POLL_TIMEOUT_PROPERTY); if(value != null) { pollTimeout = ConversionUtils.convert(value, Integer.class); } return pollTimeout; }
/** * Determines how Kafka messages should be rendered for the user. * * @param properties The properties. * @return How the Kafka messages should be rendered. */ private static String getMessageView(Properties properties) { // defaults to the simple view String messageView = MESSAGE_VIEW_SIMPLE; if(properties.containsKey(MESSAGE_VIEW_PROPERTY)) { messageView = ConversionUtils.convert(properties.get(MESSAGE_VIEW_PROPERTY), String.class); } return messageView; }
/** * Returns the configuration value, cast to the expected type, from a map of configuration values. * If the value is not specified, the default value is returned. * * @param config A map containing configuration values. * @param defaultValue The default value to return, if one is not defined. * @param clazz The class of the expected type of the configuration value. * @param <T> The expected type of the configuration value. * @return The configuration value or the specified default, if one is not defined. */ private <T> T getOrDefault(Map<String, String> config, Object defaultValue, Class<T> clazz) { Object value = config.getOrDefault(key, defaultValue.toString()); return value == null ? null : ConversionUtils.convert(value, clazz); }
public Config(Map<String, Object> config) { hBaseTable = (String) config.get(PERSISTENT_BLOOM_TABLE); hBaseCF = (String) config.get(PERSISTENT_BLOOM_CF); Object fpObj = config.get(PERSISTENT_BLOOM_FP); if (fpObj != null) { falsePositiveRate = ConversionUtils.convert(fpObj, Double.class); } Object eiObj = config.get(PERSISTENT_BLOOM_EI); if (eiObj != null) { expectedInsertions = ConversionUtils.convert(eiObj, Integer.class); } Object msObj = config.get(PERSISTENT_BLOOM_MS_BETWEEN_PERSISTS); if(msObj != null) { millisecondsBetweenPersists = ConversionUtils.convert(msObj, Long.class); } }
@Override public Object apply(List<Object> objects, Context context) throws ParseException { Object keyObj = objects.get(0); if(keyObj == null) { return keyObj; } Integer key = ConversionUtils.convert(keyObj, Integer.class); if(key == null ) { return keyObj; } Object ret = PROTOCOLS.get(key); if(ret == null ) { return keyObj; } return ret; }
@Override public Object apply(List<Object> args) { StatisticsProvider stats = convert(args.get(0), StatisticsProvider.class); Double p = convert(args.get(1), Double.class); Double result; if(stats == null || p == null) { result = Double.NaN; } else { result = stats.getPercentile(p); } return result; } }