@Test(expected = RuntimeException.class) public void testNonPrimitiveConstructor() throws Exception { FileFilter f = build("*test*.java~*~", DelegateFileFilter.class.getCanonicalName()); }
public static FileFilter build(String filterExpression, String filterImpl) { FileFilter result = null; try { if (isEmpty(filterExpression)) { result = (file) -> true; } else { Class filterClass = Class.forName(filterImpl); for (Map.Entry<Class, Function<String, Object>> converter : SUPPORTED_CNST_ARGS.entrySet()) { if (hasConstructor(converter.getKey(), filterClass)) { Object constructorArg = converter.getValue().apply(filterExpression); Constructor constructor = filterClass.getDeclaredConstructor(new Class[] {converter.getKey()}); result = (FileFilter) constructor.newInstance(new Object[] {constructorArg}); break; } } } if (result == null) { throw new InstantiationException(filterImpl + " could not be created with [" + filterExpression + "]"); } } catch (Exception e) { throw new RuntimeException(e); } return result; }
FileFilterBuilder { public static FileFilter build(String filterExpression, String filterImpl) { FileFilter result = null; try { if (isEmpty(filterExpression)) { result = (file) -> true; } else { Class filterClass = Class.forName(filterImpl); for (Map.Entry<Class, Function<String, Object>> converter : SUPPORTED_CNST_ARGS.entrySet()) { if (hasConstructor(converter.getKey(), filterClass)) { Object constructorArg = converter.getValue().apply(filterExpression); Constructor constructor = filterClass.getDeclaredConstructor(new Class[] {converter.getKey()}); result = (FileFilter) constructor.newInstance(new Object[] {constructorArg}); break; } } } if (result == null) { throw new InstantiationException(filterImpl + " could not be created with [" + filterExpression + "]"); } } catch (Exception e) { throw new RuntimeException(e); } return result; } }
FileFilterBuilder { public static FileFilter build(String filterExpression, String filterImpl) { FileFilter result = null; try { if (isEmpty(filterExpression)) { result = (file) -> true; } else { Class filterClass = Class.forName(filterImpl); for (Map.Entry<Class, Function<String, Object>> converter : SUPPORTED_CNST_ARGS.entrySet()) { if (hasConstructor(converter.getKey(), filterClass)) { Object constructorArg = converter.getValue().apply(filterExpression); Constructor constructor = filterClass.getDeclaredConstructor(new Class[] {converter.getKey()}); result = (FileFilter) constructor.newInstance(new Object[] {constructorArg}); break; } } } if (result == null) { throw new InstantiationException(filterImpl + " could not be created with [" + filterExpression + "]"); } } catch (Exception e) { throw new RuntimeException(e); } return result; }  }
FileFilterBuilder { public static FileFilter build(String filterExpression, String filterImpl) { FileFilter result = null; try { if (isEmpty(filterExpression)) { result = (file) -> true; } else { Class filterClass = Class.forName(filterImpl); for (Map.Entry<Class, Function<String, Object>> converter : SUPPORTED_CNST_ARGS.entrySet()) { if (hasConstructor(converter.getKey(), filterClass)) { Object constructorArg = converter.getValue().apply(filterExpression); Constructor constructor = filterClass.getDeclaredConstructor(new Class[] {converter.getKey()}); result = (FileFilter) constructor.newInstance(new Object[] {constructorArg}); break; } } } if (result == null) { throw new InstantiationException(filterImpl + " could not be created with [" + filterExpression + "]"); } } catch (Exception e) { throw new RuntimeException(e); } return result; }  static FileFilter build(String filterExpression, String filterImpl); }
FileFilterBuilder { public static FileFilter build(String filterExpression, String filterImpl) { FileFilter result = null; try { if (isEmpty(filterExpression)) { result = (file) -> true; } else { Class filterClass = Class.forName(filterImpl); for (Map.Entry<Class, Function<String, Object>> converter : SUPPORTED_CNST_ARGS.entrySet()) { if (hasConstructor(converter.getKey(), filterClass)) { Object constructorArg = converter.getValue().apply(filterExpression); Constructor constructor = filterClass.getDeclaredConstructor(new Class[] {converter.getKey()}); result = (FileFilter) constructor.newInstance(new Object[] {constructorArg}); break; } } } if (result == null) { throw new InstantiationException(filterImpl + " could not be created with [" + filterExpression + "]"); } } catch (Exception e) { throw new RuntimeException(e); } return result; }  static FileFilter build(String filterExpression, String filterImpl);  }