private void checkParallelizable(Converter<?, ?> converter) { if (converter.isParallelizable()) { Assert.isTrue(converter instanceof Cloneable, "Parallelizable converters must implement " + Cloneable.class); Assert.isTrue(BeanUtil.findMethod(converterClass, "clone", (Class[]) null) != null, "Parallelizable converters must have a public clone() method"); } }
@Override public void setValue(Object target, Object value) throws UpdateFailedException { try { Object convertedValue = converter.convert(value); realMutator.setValue(target, convertedValue); } catch (ConversionException e) { throw new UpdateFailedException(e); } }
@SuppressWarnings("unchecked") public static <BEAN, PROP_TYPE> PROP_TYPE[] extractProperties(BEAN[] beans, String propertyName, Class<PROP_TYPE> propertyType) { PROP_TYPE[] result = ArrayUtil.newInstance(propertyType, beans.length); for (int i = 0; i < beans.length; i++) { BEAN bean = beans[i]; result[i] = (PROP_TYPE) getPropertyValue(bean, propertyName); } return result; }
public static <T> T[] removeAll(T[] toRemove, T[] target) { Class<T> componentType = componentType(target); ArrayBuilder<T> builder = new ArrayBuilder<T>(componentType); for (T element : target) if (!contains(element, toRemove)) builder.add(element); return builder.toArray(); }
public LocalDiffType(DiffDetailType type, String locator) { if (StringUtil.isEmpty(locator) && type == null) throw new ConfigurationError("At least one of the argument 'locator' and 'type' must be not empty"); this.locator = locator; this.type = type; }
@Override public String getDescription() { return "Sub identity of (" + ArrayFormat.format(parentTableNames) + "):" + SystemInfo.getLineSeparator() + subNkPkQuery; }
public static <T> T findSingleMatch(Collection<T> candidates, Filter<T> filter) { T result = null; for (T candidate : candidates) if (filter.accept(candidate)) { if (result == null) result = candidate; else throw new ConfigurationError("Found multiple matches: " + candidates); } return result; }
@SuppressWarnings("rawtypes") public static <V> Map<String, V> readProperties( String filename, Converter<Map.Entry, Map.Entry> converter, String encoding) throws IOException { return readProperties(new OrderedMap<String, V>(), filename, converter, encoding); }
public static <T> T[] cloneAll(T[] input) { T[] output = ArrayUtil.newInstance(ArrayUtil.componentType(input), input.length); for (int i = 0; i < input.length; i++) output[i] = clone(input[i]); return output; }
public void assertNext(char c) { if (!hasNext()) throw new ParseException("Expected '" + c + "', but no more character is available", source, line, column); char next = next(); if (next != c) throw new ParseException("Expected '" + c + "', but found '" + next + "'", source, line, column); }
@Override public String toString() { String[] paramStrings = toStringArrayConverter.convert(params); // TODO v1.0 use DatabaseDialect to render arbitrary data types return "PreparedStatement (" + StringUtil.replaceTokens(sql, "?", paramStrings) + ")"; }
@Override public GregorianCalendar convert(String sourceValue) throws ConversionException { Date date = realConverter.convert(sourceValue); return TimeUtil.gregorianCalendar(date); }
public static PrintWriter getPrinterForURI(String uri, String encoding) throws FileNotFoundException, UnsupportedEncodingException { return getPrinterForURI(uri, encoding, false, SystemInfo.getLineSeparator(), false); }
public static void say(String text, ErrorHandler errorHandler) { if (!speechSupported()) errorHandler.handleError("Speech is not supported on this system"); ShellUtil.runShellCommand("say -v Alex \"" + text + "\"", new OutputStreamWriter(System.out), errorHandler); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Map<String, String> readProperties(String filename, String encoding) throws IOException { return readProperties(new OrderedMap(), filename, null, encoding); }