@Test public void testTypedValue() { Colours redValue = Colours.RED; put(key, redValue); assertEquals(redValue, ConnectorOptions.extractOptionAsType(parameters, key, Colours.class)); assertNull(ConnectorOptions.extractOptionAsType(parameters, missingKey, Colours.class)); }
public static <T> T extractOptionAsType(Map<String, ?> options, String key, Class<T> requiredClass, T defaultValue) { if (options == null) { return defaultValue; } return Optional.ofNullable(options.get(key)) .filter(requiredClass::isInstance) .map(requiredClass::cast) .orElse(defaultValue); }
ConnectorOptions { public static <T> T extractOptionAsType(Map<String, ?> options, String key, Class<T> requiredClass, T defaultValue) { if (options == null) { return defaultValue; } return Optional.ofNullable(options.get(key)) .filter(requiredClass::isInstance) .map(requiredClass::cast) .orElse(defaultValue); } }
ConnectorOptions { public static <T> T extractOptionAsType(Map<String, ?> options, String key, Class<T> requiredClass, T defaultValue) { if (options == null) { return defaultValue; } return Optional.ofNullable(options.get(key)) .filter(requiredClass::isInstance) .map(requiredClass::cast) .orElse(defaultValue); } private  ConnectorOptions(); }
ConnectorOptions { public static <T> T extractOptionAsType(Map<String, ?> options, String key, Class<T> requiredClass, T defaultValue) { if (options == null) { return defaultValue; } return Optional.ofNullable(options.get(key)) .filter(requiredClass::isInstance) .map(requiredClass::cast) .orElse(defaultValue); } private  ConnectorOptions(); static String extractOption(Map<String, ?> options, String key, String defaultValue); static String extractOption(Map<String, ?> options, String key); static String popOption(Map<String, ?> options, String key); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn, T defaultValue); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn); static void extractOptionAndConsume(Map<String, ?> options, String key,
                                                                   Consumer<String> consumer); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass, T defaultValue); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass); }
ConnectorOptions { public static <T> T extractOptionAsType(Map<String, ?> options, String key, Class<T> requiredClass, T defaultValue) { if (options == null) { return defaultValue; } return Optional.ofNullable(options.get(key)) .filter(requiredClass::isInstance) .map(requiredClass::cast) .orElse(defaultValue); } private  ConnectorOptions(); static String extractOption(Map<String, ?> options, String key, String defaultValue); static String extractOption(Map<String, ?> options, String key); static String popOption(Map<String, ?> options, String key); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn, T defaultValue); static T extractOptionAndMap(Map<String, ?> options, String key,
                                                                    Function<? super String, T> mappingFn); static void extractOptionAndConsume(Map<String, ?> options, String key,
                                                                   Consumer<String> consumer); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass, T defaultValue); static T extractOptionAsType(Map<String, ?> options,
                                                            String key, Class<T> requiredClass);  }