/** * Returns a map of default values of attributes associated with this bindable. A * shortcut for: * <pre> * for (AttributeDescriptor d : only(Input.class).flatten().attributeDescriptors.values()) * { * if (d.defaultValue != null || d.requiredAttribute) * values.put(d.key, d.defaultValue); * } * </pre> */ public HashMap<String, Object> getDefaultValues() { final HashMap<String, Object> values = new HashMap<>(); for (AttributeDescriptor d : only(Input.class).flatten().attributeDescriptors.values()) { if (d.defaultValue != null || d.requiredAttribute) { values.put(d.key, d.defaultValue); } } return values; }
/** * Returns a grouped structure of attribute descriptors. Notice that * {@link BindableDescriptor}s are immutable, so the grouped descriptor set is * returned rather than grouping being applied to the receiver. * * @param groupingMethod the grouping method to be used * @return grouped descriptors */ public BindableDescriptor group(GroupingMethod groupingMethod) { if (this.groupedBy.equals(groupingMethod)) { return this; } else { return new BindableDescriptor(this.type, this.metadata, this.bindableDescriptorsInternal, this.attributeDescriptorsInternal, groupingMethod); } }
private static <T> void addGroups(BindableDescriptor sourceBindableDescriptor, Map<String, AttributeDescriptor> newAttributeDescriptors, Map<Object, Map<String, AttributeDescriptor>> newAttributeGroups, IGrouper<T> grouper) { // Run through direct attribute descriptors first for (AttributeDescriptor attributeDescriptor1 : sourceBindableDescriptor.attributeDescriptorsInternal .values()) { addToMaps(newAttributeDescriptors, newAttributeGroups, attributeDescriptor1, grouper.getGroupingObject(sourceBindableDescriptor, attributeDescriptor1)); } // Recursively run through nested attribute descriptors for (Entry<Field, BindableDescriptor> entry : sourceBindableDescriptor.bindableDescriptorsInternal .entrySet()) { addGroups(entry.getValue(), newAttributeDescriptors, newAttributeGroups, grouper); } }
.entrySet()) filteredBindableDescriptors.put(entry.getKey(), entry.getValue().only( predicate)); return new BindableDescriptor(this.type, this.metadata, filteredBindableDescriptors, filteredAttributeDescriptors, this.groupedBy);
/** * Preserves descriptors that have <strong>all</strong> of the specified annotations. * Notice that {@link BindableDescriptor}s are immutable, so the filtered descriptor * set is returned rather than filtering being applied to the receiver. * * @param annotationClasses binding time and direction annotation classes to be * matched. * @return a new {@link BindableDescriptor} with the descriptors filtered. */ @SafeVarargs public final BindableDescriptor only(final Class<? extends Annotation>... annotationClasses) { if (annotationClasses.length == 0) { return this; } return only(new AnnotationsPredicate(true, annotationClasses)); }
/** * Returns a flattened structure of attribute descriptors. After flattening, * {@link #attributeDescriptors} contains descriptors of all attributes and * {@link #attributeGroups} is empty. Notice that {@link BindableDescriptor}s are * immutable, so the flattened descriptor set is returned rather than flattening being * applied to the receiver. * * @return flattened descriptor */ public BindableDescriptor flatten() { return group(GroupingMethod.NONE); }
/** * An internal constructor. */ BindableDescriptor(Class<?> bindableType, BindableMetadata metadata, Map<Field, BindableDescriptor> bindableDescriptors, Map<String, AttributeDescriptor> attributeDescriptors, GroupingMethod groupBy) { this.type = bindableType; this.prefix = BindableUtils.getPrefix(bindableType); this.metadata = metadata; this.bindableDescriptorsInternal = bindableDescriptors; this.attributeDescriptorsInternal = attributeDescriptors; this.groupedBy = groupBy; final LinkedHashMap<String, AttributeDescriptor> newAttributeDescriptors = Maps .newLinkedHashMap(); final LinkedHashMap<Object, Map<String, AttributeDescriptor>> newAttributeGroups = Maps .newLinkedHashMap(); buildAttributeGroups(newAttributeDescriptors, newAttributeGroups, this, groupedBy); this.attributeDescriptors = Collections.unmodifiableMap(newAttributeDescriptors); this.attributeGroups = Collections.unmodifiableMap(newAttributeGroups); }
addGroups(bindableDescriptor, newAttributeDescriptors, unsortedGroups, GROUPER_BY_STRUCTURE); addGroups(bindableDescriptor, newAttributeDescriptors, unsortedGroups, GROUPER_BY_LEVEL); addGroups(bindableDescriptor, newAttributeDescriptors, unsortedGroups, GROUPER_BY_GROUP); addGroups(bindableDescriptor, newAttributeDescriptors, unsortedGroups, GROUPER_BY_NONE); sortedGroupKeys = Collections.EMPTY_LIST;
/** * Preserves descriptors that have <strong>none</strong> of the specified * annotations. Notice that {@link BindableDescriptor}s are immutable, so the * filtered descriptor set is returned rather than filtering being applied to the * receiver. * * @param annotationClasses binding time and direction annotation classes to be * matched. * @return a new {@link BindableDescriptor} with the descriptors filtered. */ @SafeVarargs public final BindableDescriptor not(final Class<? extends Annotation>... annotationClasses) { if (annotationClasses.length == 0) { return this; } return only(Predicates.<AttributeDescriptor> not(new AnnotationsPredicate(false, annotationClasses))); }
return new BindableDescriptor(clazz, bindableMetadata, bindableDescriptors, attributeDescriptors);