/** * Attempts to find the index of a specified column's mapped parameter in a list of column names * * @param paramName the name of the parameter to search for * @param columnNames list of column names to search in * @param columnNameMatchers {@link ColumnNameMatcher}s to map {@code paramName} to the column names * @param debugName name of the parameter to use for debugging purposes (ie: when throwing exceptions) * @return {@link OptionalInt} with the found index, {@link OptionalInt#empty()} otherwise. */ public static OptionalInt findColumnIndex(String paramName, List<String> columnNames, List<ColumnNameMatcher> columnNameMatchers, Supplier<String> debugName) { OptionalInt result = OptionalInt.empty(); for (int i = 0; i < columnNames.size(); i++) { String columnName = columnNames.get(i); for (ColumnNameMatcher strategy : columnNameMatchers) { if (strategy.columnNameMatches(columnName, paramName)) { if (result.isPresent()) { throw new IllegalArgumentException(String.format( "'%s' (%s) matches multiple columns: '%s' (%d) and '%s' (%d)", debugName.get(), paramName, columnNames.get(result.getAsInt()), result.getAsInt(), columnNames.get(i), i)); } result = OptionalInt.of(i); break; } } } return result; }
/** * Returns whether any of the given column names begin with the given prefix, according to the list of column name * matchers. * * @param columnNames the column names to search * @param prefix the prefix to search for * @param columnNameMatchers list of column name matchers * @return whether any of the column names begin with the prefix * @since 3.5.0 */ public static boolean anyColumnsStartWithPrefix(Collection<String> columnNames, String prefix, List<ColumnNameMatcher> columnNameMatchers) { return columnNames.stream().anyMatch( columnName -> columnNameMatchers.stream().anyMatch( matcher -> matcher.columnNameStartsWith(columnName, prefix))); } }
private Optional<PropertyDescriptor> descriptorForColumn(String columnName, List<ColumnNameMatcher> columnNameMatchers) { for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) { String paramName = paramName(descriptor); for (ColumnNameMatcher strategy : columnNameMatchers) { if (strategy.columnNameMatches(columnName, paramName)) { return Optional.of(descriptor); } } } return Optional.empty(); }
private Optional<Field> fieldByColumn(String columnName, List<ColumnNameMatcher> columnNameMatchers) { Class<?> aClass = type; while(aClass != null) { for (Field field : aClass.getDeclaredFields()) { String paramName = paramName(field); for (ColumnNameMatcher strategy : columnNameMatchers) { if (strategy.columnNameMatches(columnName, paramName)) { return Optional.of(field); } } } aClass = aClass.getSuperclass(); } return Optional.empty(); }
if (strategy.columnNameMatches(columnName, parameterName)) { if (result >= 0) { throw new IllegalArgumentException(String.format(