private static PropertyName toPropertyName(Cell cell, String name) { assert cell != null; assert name != null; String[] words = name.split("(_|-)+"); //$NON-NLS-1$ return PropertyName.newInstance(words); }
String toJsName(PropertyName name) { assert name != null; StringBuilder buf = new StringBuilder(); Iterator<String> iterator = name.getWords().iterator(); assert iterator.hasNext(); buf.append(iterator.next()); while (iterator.hasNext()) { buf.append('_'); buf.append(iterator.next()); } return buf.toString(); }
/** * Creates a new instance. * @param words the words which consists this name * @return the created instance * @throws IllegalArgumentException if some parameters were {@code null} */ public static PropertyName newInstance(List<String> words) { if (words == null) { throw new IllegalArgumentException("words must not be null"); //$NON-NLS-1$ } if (words.isEmpty()) { throw new IllegalArgumentException("words must not be empty"); //$NON-NLS-1$ } List<String> work = new ArrayList<>(words.size()); for (String w : words) { work.add(normalize(w)); } return new PropertyName(work); }
@Override public GroupLoader<T> group(String... terms) { List<PropertyName> names = new ArrayList<>(); for (String term : terms) { PropertyName name = PropertyName.parse(term); Util.checkProperty(definition, name); names.add(name); } return new BasicGroupLoader<>(context, definition, factory, names, refComparator); }
/** * Creates a new instance. * @param words the words which consists this name * @throws IllegalArgumentException if some parameters were {@code null} */ private PropertyName(List<String> words) { this.originalWords = words; this.normalized = normalize(words); }
void createHeaderRow(Row row) { assert row != null; int columnIndex = 0; for (PropertyName name : properties) { Cell cell = row.createCell(columnIndex++); cell.setCellStyle(info.titleStyle); cell.setCellValue(name.toString()); } }
static Ordering parseOrder(String expression) { Matcher matcher = PATTERN_ORDER.matcher(expression); if (matcher.matches() == false) { throw new IllegalArgumentException(MessageFormat.format( "invalid group ordering expression: {0}", expression)); } String name = null; Direction direction = null; for (Map.Entry<Integer, Direction> entry : ORDER_GROUP_DIRECTIONS.entrySet()) { int index = entry.getKey(); String s = matcher.group(index); if (s != null) { name = s; direction = entry.getValue(); break; } } assert name != null; assert direction != null; return new Ordering(PropertyName.parse(name), direction); }
/** * Creates a new instance. * @param words the words which consists this name * @return the created instance * @throws IllegalArgumentException if some parameters were {@code null} */ public static PropertyName newInstance(String... words) { if (words == null) { throw new IllegalArgumentException("words must not be null"); //$NON-NLS-1$ } return newInstance(Arrays.asList(words)); }
/** * Returns property type kind corresponded to the property name and type. * @param name property name * @param type property type * @return property type kind, or {@code null} without suitable corresponded kind * @throws IllegalArgumentException if some parameters were {@code null} */ public static PropertyType getType(PropertyName name, Class<?> type) { if (name == null) { throw new IllegalArgumentException("name must not be null"); //$NON-NLS-1$ } if (type == null) { throw new IllegalArgumentException("type must not be null"); //$NON-NLS-1$ } PropertyType kind = TYPES.get(type); if (kind == null) { return null; } if (kind.getRepresentation() == Calendar.class) { List<String> words = name.getWords(); if (words.contains(PropertyType.DATE.name().toLowerCase())) { return PropertyType.DATE; } else if (words.contains(PropertyType.TIME.name().toLowerCase())) { return PropertyType.TIME; } else if (words.contains(PropertyType.DATETIME.name().toLowerCase())) { return PropertyType.DATETIME; } } return kind; }
private PropertyName getPropertyNameIfAccessor(Method method) { assert method != null; Matcher matcher = PROPERTY_ACCESSOR.matcher(method.getName()); if (matcher.matches() == false) { return null; } String name = matcher.group(1); List<String> words = new ArrayList<>(); int start = 0; for (int i = 1, n = name.length(); i < n; i++) { char c = name.charAt(i); if ('A' <= c && c <= 'Z') { words.add(name.substring(start, i)); start = i; } } words.add(name.substring(start)); return PropertyName.newInstance(words); }
/** * Parses a property name term and creates a new instance. * @param term the property name term * @return the created instance * @since 0.9.1 */ public static PropertyName parse(String term) { Objects.requireNonNull(term); if (term.isEmpty()) { throw new IllegalArgumentException(); } else if (term.indexOf('_') >= 0 || term.toUpperCase(Locale.ENGLISH).equals(term)) { String[] segments = term.split("_"); //$NON-NLS-1$ return newInstance(segments); } else { List<String> segments = new ArrayList<>(); int start = 0; for (int i = 1, n = term.length(); i < n; i++) { if (Character.isUpperCase(term.charAt(i))) { segments.add(term.substring(start, i)); start = i; } } segments.add(term.substring(start)); return newInstance(segments); } }
private PropertyName extract(Field field) { assert field != null; if (Modifier.isPublic(field.getModifiers()) == false) { return null; } if (TYPES.containsKey(field.getType()) == false) { return null; } String name = field.getName(); if (NAME.matcher(name).matches() == false) { return null; } List<String> words = new ArrayList<>(); int start = 0; for (int i = 1, n = name.length(); i < n; i++) { char c = name.charAt(i); if ('A' <= c && c <= 'Z') { words.add(name.substring(start, i)); start = i; } } words.add(name.substring(start)); return PropertyName.newInstance(words); }
for (String name : annotation.value()) { String[] words = name.split("(_|-)+"); //$NON-NLS-1$ PropertyName propertyName = PropertyName.newInstance(words); Method method = results.remove(propertyName); if (method == null) {
/** * Returns the sub rule builder for the specified property. * Note that this model will be only accepted if all properties are accepted. * @param name the property name * @return the rule builder for the property * @throws IllegalArgumentException if the property does not exist, * or if some parameters were {@code null} */ public Property property(String name) { if (name == null) { throw new IllegalArgumentException("name must not be null"); //$NON-NLS-1$ } String[] words = name.split("_|-|\\s+"); //$NON-NLS-1$ PropertyName propertyName = PropertyName.newInstance(words); PropertyType type = definition.getType(propertyName); if (type == null) { throw new IllegalArgumentException(MessageFormat.format( Messages.getString("VerifyRuleBuilder.errorUndefinedProperty"), //$NON-NLS-1$ definition.getModelClass().getName(), propertyName)); } Property subBuilder = propertyConditions.get(propertyName); if (subBuilder == null) { subBuilder = new Property(propertyName, type); propertyConditions.put(propertyName, subBuilder); } return subBuilder; }
private Difference createDifference(long actual) { PropertyName name = PropertyName.newInstance("count"); return new Difference( new DataModelReflection(Collections.singletonMap(name, expected)), new DataModelReflection(Collections.singletonMap(name, actual)), "count verification was failed"); }
private Difference createDifference(long actual) { PropertyName name = PropertyName.newInstance("count"); return new Difference( new DataModelReflection(Collections.singletonMap(name, expected)), new DataModelReflection(Collections.singletonMap(name, actual)), "count verification was failed"); }
private Difference createDifference(long actual) { PropertyName name = PropertyName.newInstance("count"); return new Difference( new DataModelReflection(Collections.singletonMap(name, expected)), new DataModelReflection(Collections.singletonMap(name, actual)), "count verification was failed"); }
private Difference createDifference(long actual) { PropertyName name = PropertyName.newInstance("count"); return new Difference( new DataModelReflection(Collections.singletonMap(name, expected)), new DataModelReflection(Collections.singletonMap(name, actual)), "count verification was failed"); }