/** * Get a list of all methods which the given class declares, implements, * overrides or inherits. Methods are added by adding first all methods of * the class itself and its implemented interfaces, then the super class and * its interfaces, etc. * * @param clazz the class for which to retrieve the methods * * @return set of all methods of the given class */ public static List<Method> getAllMethods(Class<?> clazz) { Contracts.assertNotNull( clazz ); List<Method> methods = newArrayList(); for ( Class<?> hierarchyClass : ClassHierarchyHelper.getHierarchy( clazz ) ) { Collections.addAll( methods, run( GetMethods.action( hierarchyClass ) ) ); } return methods; }
public ValidationEnabledAnnotatedType(AnnotatedType<T> type, Set<AnnotatedCallable<? super T>> constrainedCallables) { this.wrappedType = type; this.wrappedMethods = CollectionHelper.newHashSet(); this.wrappedConstructors = CollectionHelper.newHashSet(); buildWrappedCallable( constrainedCallables ); }
public BeanDescriptorImpl(Type beanClass, Set<ConstraintDescriptorImpl<?>> classLevelConstraints, Map<String, PropertyDescriptor> constrainedProperties, Map<String, ExecutableDescriptorImpl> constrainedMethods, Map<String, ConstructorDescriptor> constrainedConstructors, boolean defaultGroupSequenceRedefined, List<Class<?>> defaultGroupSequence) { super( beanClass, classLevelConstraints, defaultGroupSequenceRedefined, defaultGroupSequence ); this.constrainedProperties = CollectionHelper.toImmutableMap( constrainedProperties ); this.constrainedMethods = CollectionHelper.toImmutableMap( constrainedMethods ); this.constrainedConstructors = CollectionHelper.toImmutableMap( constrainedConstructors ); }
private BootstrapConfigurationImpl() { this.defaultProviderClassName = null; this.constraintValidatorFactoryClassName = null; this.messageInterpolatorClassName = null; this.traversableResolverClassName = null; this.parameterNameProviderClassName = null; this.validatedExecutableTypes = DEFAULT_VALIDATED_EXECUTABLE_TYPES; this.isExecutableValidationEnabled = true; this.constraintMappingResourcePaths = newHashSet(); this.properties = newHashMap(); }
this.propertyMetaDataMap = newHashMap(); Set<PropertyMetaData> propertyMetaDataSet = newHashSet(); Set<ExecutableMetaData> executableMetaDataSet = newHashSet(); Set<String> tmpUnconstrainedExecutables = newHashSet(); Set<Cascadable> cascadedProperties = newHashSet(); Set<MetaConstraint<?>> allMetaConstraints = newHashSet(); this.cascadedProperties = CollectionHelper.toImmutableSet( cascadedProperties ); this.allMetaConstraints = CollectionHelper.toImmutableSet( allMetaConstraints ); this.classHierarchyWithoutInterfaces = CollectionHelper.toImmutableList( ClassHierarchyHelper.getHierarchy( beanClass, Filters.excludeInterfaces() this.defaultGroupSequence = CollectionHelper.toImmutableList( defaultGroupContext.defaultGroupSequence ); this.validationOrder = defaultGroupContext.validationOrder; this.executableMetaDataMap = CollectionHelper.toImmutableMap( bySignature( executableMetaDataSet ) ); this.unconstrainedExecutables = CollectionHelper.toImmutableSet( tmpUnconstrainedExecutables );
@Override public Map<String, String> getProperties() { return newHashMap( properties ); }
private Map<Class<?>, Class<?>> getGroupConversions(ConvertGroup groupConversion, ConvertGroup.List groupConversionList) { Map<Class<?>, Class<?>> groupConversions = newHashMap(); if ( groupConversion != null ) { groupConversions.put( groupConversion.from(), groupConversion.to() ); } if ( groupConversionList != null ) { for ( ConvertGroup conversion : groupConversionList.value() ) { if ( groupConversions.containsKey( conversion.from() ) ) { throw LOG.getMultipleGroupConversionsForSameSourceException( conversion.from(), CollectionHelper.<Class<?>>asSet( groupConversions.get( conversion.from() ), conversion.to() ) ); } groupConversions.put( conversion.from(), conversion.to() ); } } return groupConversions; }
@SuppressWarnings("unchecked") private static Set<Class<? extends Payload>> buildPayloadSet(ConstraintAnnotationDescriptor<?> annotationDescriptor) { Set<Class<? extends Payload>> payloadSet = newHashSet(); Class<? extends Payload>[] payloadFromAnnotation = annotationDescriptor.getPayload(); if ( payloadFromAnnotation != null ) { payloadSet.addAll( Arrays.asList( payloadFromAnnotation ) ); } return CollectionHelper.toImmutableSet( payloadSet ); }
private void addGroupConversions(Map<Class<?>, Class<?>> groupConversions) { for ( Entry<Class<?>, Class<?>> oneConversion : groupConversions.entrySet() ) { if ( this.groupConversions.containsKey( oneConversion.getKey() ) ) { throw log.getMultipleGroupConversionsForSameSourceException( oneConversion.getKey(), CollectionHelper.<Class<?>>asSet( groupConversions.get( oneConversion.getKey() ), oneConversion.getValue() ) ); } else { this.groupConversions.put( oneConversion.getKey(), oneConversion.getValue() ); } } }
@Override public Map<String, Object> run() { final Method[] declaredMethods = annotation.annotationType().getDeclaredMethods(); Map<String, Object> attributes = newHashMap( declaredMethods.length ); for ( Method m : declaredMethods ) { // HV-1184 Exclude synthetic methods potentially introduced by jacoco if ( m.isSynthetic() ) { continue; } m.setAccessible( true ); String attributeName = m.getName(); try { attributes.put( m.getName(), m.invoke( annotation ) ); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw LOG.getUnableToGetAnnotationAttributeException( annotation.getClass(), attributeName, e ); } } return CollectionHelper.toImmutableMap( attributes ); } }
/** * Builds an {@link Iterator} for a given array. It is (un)necessarily ugly because we have to deal with array of primitives. * * @param object a given array * @return an {@code Iterator} iterating over the array */ @SuppressWarnings({ "unchecked", "rawtypes" }) // Reflection is used to ensure the correct types are used public static Iterator<?> iteratorFromArray(Object object) { return new ArrayIterator( accessorFromArray( object ), object ); }
public static <K, V> HashMap<K, V> newHashMap(int size) { return new HashMap<K, V>( getInitialCapacityFromExpectedSize( size ) ); }
private Map<String, Object> getBindings(Object[] arguments, List<String> parameterNames) { Map<String, Object> bindings = newHashMap(); for ( int i = 0; i < arguments.length; i++ ) { bindings.put( parameterNames.get( i ), arguments[i] ); } return bindings; }
private Map<Class<?>, Class<?>> getGroupConversions(ConvertGroup groupConversion, ConvertGroup.List groupConversionList) { Map<Class<?>, Class<?>> groupConversions = newHashMap(); if ( groupConversion != null ) { groupConversions.put( groupConversion.from(), groupConversion.to() ); } if ( groupConversionList != null ) { for ( ConvertGroup conversion : groupConversionList.value() ) { if ( groupConversions.containsKey( conversion.from() ) ) { throw log.getMultipleGroupConversionsForSameSourceException( conversion.from(), CollectionHelper.<Class<?>>asSet( groupConversions.get( conversion.from() ), conversion.to() ) ); } groupConversions.put( conversion.from(), conversion.to() ); } } return groupConversions; }
private static Map<Class<?>, Class<?>> mergeGroupConversion(Map<Class<?>, Class<?>> groupConversions, Map<Class<?>, Class<?>> otherGroupConversions) { if ( groupConversions.isEmpty() && otherGroupConversions.isEmpty() ) { // this is a rather common case so let's optimize it return Collections.emptyMap(); } Map<Class<?>, Class<?>> mergedGroupConversions = new HashMap<>( groupConversions.size() + otherGroupConversions.size() ); for ( Entry<Class<?>, Class<?>> otherGroupConversionEntry : otherGroupConversions.entrySet() ) { if ( groupConversions.containsKey( otherGroupConversionEntry.getKey() ) ) { throw LOG.getMultipleGroupConversionsForSameSourceException( otherGroupConversionEntry.getKey(), CollectionHelper.<Class<?>>asSet( groupConversions.get( otherGroupConversionEntry.getKey() ), otherGroupConversionEntry.getValue() ) ); } } mergedGroupConversions.putAll( groupConversions ); mergedGroupConversions.putAll( otherGroupConversions ); return mergedGroupConversions; }
/** * Builds an {@link Iterable} for a given array. It is (un)necessarily ugly because we have to deal with array of primitives. * * @param object a given array * @return an {@code Iterable} providing iterators over the array */ @SuppressWarnings({ "unchecked", "rawtypes" }) // Reflection is used to ensure the correct types are used public static Iterable<?> iterableFromArray(Object object) { return new ArrayIterable( accessorFromArray( object ), object ); }
public static <T> HashSet<T> newHashSet(int size) { return new HashSet<T>( getInitialCapacityFromExpectedSize( size ) ); }
private List<String> getParameterNames(Parameter[] parameters) { List<String> parameterNames = newArrayList(); for ( Parameter parameter : parameters ) { // If '-parameters' is used at compile time, actual names will be returned. Otherwise, it will be arg0, arg1... parameterNames.add( parameter.getName() ); } return parameterNames; } }
public ValidatorFactoryBean(BeanManager beanManager, ValidationProviderHelper validationProviderHelper) { this.beanManager = beanManager; this.destructibleResources = newHashSet( 5 ); this.validationProviderHelper = validationProviderHelper; this.types = Collections.unmodifiableSet( CollectionHelper.<Type>newHashSet( ClassHierarchyHelper.getHierarchy( validationProviderHelper.getValidatorFactoryBeanClass() ) ) ); }
public MessageInterpolatorContext(ConstraintDescriptor<?> constraintDescriptor, Object validatedValue, Class<?> rootBeanType, Map<String, Object> messageParameters, Map<String, Object> expressionVariables) { this.constraintDescriptor = constraintDescriptor; this.validatedValue = validatedValue; this.rootBeanType = rootBeanType; this.messageParameters = toImmutableMap( messageParameters ); this.expressionVariables = toImmutableMap( expressionVariables ); }