Skip to content

Commit c9cb4fb

Browse files
committed
DATAGEODE-302 - Edit Javadoc.
Format source code. Optimize imports.
1 parent 1ec7dd0 commit c9cb4fb

5 files changed

+76
-62
lines changed

spring-data-geode/src/main/java/org/springframework/data/gemfire/function/config/AbstractFunctionExecutionConfigurationSource.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.springframework.data.gemfire.function.config;
1818

19-
import static org.springframework.data.gemfire.util.CollectionUtils.nullSafeIterable;
20-
2119
import java.lang.annotation.Annotation;
2220
import java.util.Collection;
2321
import java.util.Collections;
@@ -26,9 +24,6 @@
2624
import java.util.stream.Collectors;
2725
import java.util.stream.StreamSupport;
2826

29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
31-
3227
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
3328
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
3429
import org.springframework.core.io.ResourceLoader;
@@ -37,15 +32,13 @@
3732
import org.springframework.data.gemfire.function.annotation.OnRegion;
3833
import org.springframework.data.gemfire.function.annotation.OnServer;
3934
import org.springframework.data.gemfire.function.annotation.OnServers;
35+
import org.springframework.data.gemfire.util.CollectionUtils;
36+
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
4039

4140
/**
42-
<<<<<<< Updated upstream
43-
* Annotation based configuration source for function executions
44-
*
45-
* @author David Turanski
46-
=======
4741
* Abstract base class and configuration source for Function Executions.
48-
>>>>>>> Stashed changes
4942
*
5043
* @author David Turanski
5144
* @author John Blum
@@ -73,7 +66,10 @@ public static Set<Class<? extends Annotation>> getFunctionExecutionAnnotationTyp
7366
}
7467

7568
public static Set<String> getFunctionExecutionAnnotationTypeNames() {
76-
return getFunctionExecutionAnnotationTypes().stream().map(Class::getName).collect(Collectors.toSet());
69+
70+
return getFunctionExecutionAnnotationTypes().stream()
71+
.map(Class::getName)
72+
.collect(Collectors.toSet());
7773
}
7874

7975
protected Logger logger = LoggerFactory.getLogger(getClass());
@@ -85,19 +81,19 @@ public Collection<ScannedGenericBeanDefinition> getCandidates(ResourceLoader loa
8581

8682
scanner.setResourceLoader(loader);
8783

88-
StreamSupport.stream(nullSafeIterable(getExcludeFilters()).spliterator(), false)
84+
StreamSupport.stream(CollectionUtils.nullSafeIterable(getExcludeFilters()).spliterator(), false)
8985
.forEach(scanner::addExcludeFilter);
9086

9187
Set<ScannedGenericBeanDefinition> result = new HashSet<>();
9288

9389
for (String basePackage : getBasePackages()) {
9490

95-
if (logger.isDebugEnabled()) {
96-
logger.debug("scanning package " + basePackage);
91+
if (this.logger.isDebugEnabled()) {
92+
this.logger.debug("Scanning Package [{}]", basePackage);
9793
}
9894

9995
scanner.findCandidateComponents(basePackage).stream()
100-
.map(beanDefinition -> (ScannedGenericBeanDefinition) beanDefinition)
96+
.map(ScannedGenericBeanDefinition.class::cast)
10197
.forEach(result::add);
10298
}
10399

spring-data-geode/src/main/java/org/springframework/data/gemfire/function/config/AnnotationFunctionExecutionConfigurationSource.java

+27-22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.springframework.data.gemfire.function.config;
1414

1515
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
16+
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
1617

1718
import java.lang.annotation.Annotation;
1819
import java.util.ArrayList;
@@ -48,12 +49,13 @@ public class AnnotationFunctionExecutionConfigurationSource extends AbstractFunc
4849
private final AnnotationMetadata metadata;
4950
private final AnnotationAttributes attributes;
5051

51-
5252
/**
53-
* Creates a new {@link AnnotationFunctionExecutionConfigurationSource} from the given {@link AnnotationMetadata} and
54-
* annotation.
53+
* Creates a new instance of {@link AnnotationFunctionExecutionConfigurationSource} from
54+
* the given {@link AnnotationMetadata} and {@link EnableGemfireFunctionExecutions} annotation.
5555
*
56-
* @param metadata must not be {@literal null}.
56+
* @param metadata {@link AnnotationMetadata} for the {@link EnableGemfireFunctionExecutions} annotation;
57+
* must not be {@literal null}.
58+
* @see org.springframework.core.type.AnnotationMetadata
5759
*/
5860
public AnnotationFunctionExecutionConfigurationSource(AnnotationMetadata metadata) {
5961

@@ -65,8 +67,6 @@ public AnnotationFunctionExecutionConfigurationSource(AnnotationMetadata metadat
6567
this.metadata = metadata;
6668
}
6769

68-
69-
7070
/* (non-Javadoc)
7171
* @see org.springframework.data.gemfire.function.config.FunctionExecutionConfigurationSource#getSource()
7272
*/
@@ -108,7 +108,7 @@ public Iterable<String> getBasePackages() {
108108

109109
private boolean areAllEmpty(Object[]... arrays) {
110110

111-
for (Object[] array : arrays) {
111+
for (Object[] array : ArrayUtils.nullSafeArray(arrays, Object[].class)) {
112112
if (!ArrayUtils.isEmpty(array)) {
113113
return false;
114114
}
@@ -129,48 +129,53 @@ public Iterable<TypeFilter> getExcludeFilters() {
129129

130130
private Set<TypeFilter> parseFilters(String attributeName) {
131131

132-
Set<TypeFilter> result = new HashSet<TypeFilter>();
133-
AnnotationAttributes[] filters = attributes.getAnnotationArray(attributeName);
132+
Set<TypeFilter> result = new HashSet<>();
134133

135-
for (AnnotationAttributes filter : filters) {
136-
result.addAll(typeFiltersFor(filter));
137-
}
134+
AnnotationAttributes[] filters = this.attributes.getAnnotationArray(attributeName);
135+
136+
Arrays.stream(ArrayUtils.nullSafeArray(filters, AnnotationAttributes.class))
137+
.map(this::typeFiltersFor)
138+
.forEach(result::addAll);
138139

139140
return result;
140141
}
141142

142143
/**
143144
* Copy of {@code ComponentScanAnnotationParser#typeFiltersFor}.
144145
*
145-
* @param filterAttributes
146-
* @return
146+
* @param filterAttributes {@link AnnotationAttributes} for the {@literal include} and {@literal exclude} filters.
147+
* @return a {@link List} of {@link TypeFilter TypeFilters} based on the configuration of the {@literal include}
148+
* and {@literal exclude} attributes.
149+
* @see org.springframework.core.annotation.AnnotationAttributes
147150
*/
151+
@SuppressWarnings("unchecked")
148152
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
149-
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
153+
154+
List<TypeFilter> typeFilters = new ArrayList<>();
155+
150156
FilterType filterType = filterAttributes.getEnum("type");
151157

152158
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
153159
switch (filterType) {
154160
case ANNOTATION:
155-
Assert.isAssignable(Annotation.class, filterClass, "An error occured when processing a @ComponentScan "
156-
+ "ANNOTATION type filter: ");
157-
@SuppressWarnings("unchecked")
161+
String message = "An error occured when processing a @ComponentScan ANNOTATION type filter: ";
162+
Assert.isAssignable(Annotation.class, filterClass, message);
158163
Class<Annotation> annoClass = (Class<Annotation>) filterClass;
159164
typeFilters.add(new AnnotationTypeFilter(annoClass));
160165
break;
161166
case ASSIGNABLE_TYPE:
162167
typeFilters.add(new AssignableTypeFilter(filterClass));
163168
break;
164169
case CUSTOM:
165-
Assert.isAssignable(TypeFilter.class, filterClass, "An error occured when processing a @ComponentScan "
166-
+ "CUSTOM type filter: ");
170+
message = "An error occurred when processing a @ComponentScan CUSTOM type filter: ";
171+
Assert.isAssignable(TypeFilter.class, filterClass, message);
167172
typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
168173
break;
169174
default:
170-
throw new IllegalArgumentException("unknown filter type " + filterType);
175+
throw newIllegalArgumentException("Unknown filter type [%s]", filterType);
171176
}
172177
}
178+
173179
return typeFilters;
174180
}
175-
176181
}

spring-data-geode/src/main/java/org/springframework/data/gemfire/function/config/FunctionExecutionBeanDefinitionRegistrar.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
1515
* specific language governing permissions and limitations under the License.
1616
*/
17-
1817
package org.springframework.data.gemfire.function.config;
1918

2019
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
2120

2221
import java.util.Optional;
2322
import java.util.Set;
2423

25-
import org.w3c.dom.Element;
26-
2724
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
2825
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2926
import org.springframework.beans.factory.xml.ParserContext;
@@ -40,6 +37,8 @@
4037
import org.springframework.util.Assert;
4138
import org.springframework.util.StringUtils;
4239

40+
import org.w3c.dom.Element;
41+
4342
/**
4443
* {@link ImportBeanDefinitionRegistrar} for {@link EnableGemfireFunctionExecutions}, which scans for interfaces
4544
* annotated with one of {@link OnRegion}, {@link OnServer}, {@link OnServers}, {@link OnMember}, {@link OnMembers}.
@@ -101,8 +100,8 @@ void registerBeanDefinitions(AbstractFunctionExecutionConfigurationSource functi
101100

102101
String functionExecutionAnnotation =
103102
Optional.ofNullable(getFunctionExecutionAnnotation(beanDefinition, functionExecutionAnnotationTypeNames))
104-
.orElseThrow(() -> newIllegalStateException(String.format("No Function Execution Annotation [%1$s] found for type [%2$s]",
105-
functionExecutionAnnotationTypeNames, beanDefinition.getBeanClassName())));
103+
.orElseThrow(() -> newIllegalStateException("No Function Execution Annotation [%1$s] found for type [%2$s]",
104+
functionExecutionAnnotationTypeNames, beanDefinition.getBeanClassName()));
106105

107106
String beanName = Optional.of(beanDefinition.getMetadata())
108107
.map(annotationMetadata -> annotationMetadata.getAnnotationAttributes(functionExecutionAnnotation))

spring-data-geode/src/main/java/org/springframework/data/gemfire/function/config/FunctionExecutionComponentProvider.java

+32-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.core.type.classreading.MetadataReaderFactory;
2727
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
2828
import org.springframework.core.type.filter.TypeFilter;
29+
import org.springframework.data.gemfire.util.CollectionUtils;
2930
import org.springframework.util.Assert;
3031

3132
/**
@@ -36,7 +37,6 @@
3637
*/
3738
class FunctionExecutionComponentProvider extends ClassPathScanningCandidateComponentProvider {
3839

39-
4040
private final Set<Class<? extends Annotation>> functionExecutionAnnotationTypes;
4141

4242
/**
@@ -46,41 +46,48 @@ class FunctionExecutionComponentProvider extends ClassPathScanningCandidateCompo
4646
* @param includeFilters the {@link TypeFilter}s to select function execution interfaces to consider, must not be
4747
* {@literal null}.
4848
*/
49-
public FunctionExecutionComponentProvider(Iterable<? extends TypeFilter> includeFilters , Set<Class<? extends Annotation>> functionExecutionAnnotationTypes) {
49+
public FunctionExecutionComponentProvider(Iterable<? extends TypeFilter> includeFilters ,
50+
Set<Class<? extends Annotation>> functionExecutionAnnotationTypes) {
5051

5152
super(false);
5253

5354
this.functionExecutionAnnotationTypes = functionExecutionAnnotationTypes;
54-
Assert.notNull(includeFilters);
5555

56-
if (includeFilters.iterator().hasNext()) {
56+
if (!CollectionUtils.nullSafeIsEmpty(includeFilters)) {
5757
for (TypeFilter filter : includeFilters) {
5858
addIncludeFilter(filter);
5959
}
60-
} else {
61-
for (Class<? extends Annotation> annotation: this.functionExecutionAnnotationTypes) {
60+
}
61+
else {
62+
for (Class<? extends Annotation> annotation : this.functionExecutionAnnotationTypes) {
6263
super.addIncludeFilter(new AnnotationTypeFilter(annotation, true, true));
6364
}
6465
}
6566
}
6667

6768
/**
68-
* Custom extension of {@link #addIncludeFilter(TypeFilter)} to extend the added {@link TypeFilter}. For the
69-
* {@link TypeFilter} handed we'll have two filters registered: one additionally enforcing the
70-
* {@link FunctionExecutionDefinition} annotation, the other one forcing the extension of {@link AbstractFunctionExecution}.
69+
* Custom extension of {@link ClassPathScanningCandidateComponentProvider#addIncludeFilter(TypeFilter)}
70+
* to extend the added {@link TypeFilter}.
71+
*
72+
* For the {@link TypeFilter} handed, we will have two filters registered: one additionally enforcing the
73+
* annotation and the other one forcing the extension of {@literal AbstractFunctionExecution}.
7174
*
7275
* @see ClassPathScanningCandidateComponentProvider#addIncludeFilter(TypeFilter)
7376
*/
7477
@Override
7578
public void addIncludeFilter(TypeFilter includeFilter) {
7679

77-
List<TypeFilter> filterPlusInterface = new ArrayList<TypeFilter>();
80+
List<TypeFilter> filterPlusInterface = new ArrayList<>();
81+
82+
// TODO: What about the interface?
7883
filterPlusInterface.add(includeFilter);
7984

8085
super.addIncludeFilter(new AllTypeFilter(filterPlusInterface));
8186

82-
List<TypeFilter> filterPlusAnnotation = new ArrayList<TypeFilter>();
87+
List<TypeFilter> filterPlusAnnotation = new ArrayList<>();
88+
8389
filterPlusAnnotation.add(includeFilter);
90+
8491
for (Class<? extends Annotation> annotation: this.functionExecutionAnnotationTypes) {
8592
filterPlusAnnotation.add(new AnnotationTypeFilter(annotation, true, true));
8693
}
@@ -150,27 +157,34 @@ public AnnotationTypeFilter(Class<? extends Annotation> annotationType, boolean
150157
*/
151158
public AnnotationTypeFilter(Class<? extends Annotation> annotationType, boolean considerMetaAnnotations,
152159
boolean considerInterfaces) {
160+
153161
super(annotationType.isAnnotationPresent(Inherited.class), considerInterfaces);
162+
154163
this.annotationType = annotationType;
155164
this.considerMetaAnnotations = considerMetaAnnotations;
156165
}
157166

158167
@Override
159168
protected boolean matchSelf(MetadataReader metadataReader) {
169+
160170
AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
171+
161172
return metadata.hasAnnotation(this.annotationType.getName())
162173
|| (this.considerMetaAnnotations && metadata.hasMetaAnnotation(this.annotationType.getName()));
163174
}
164175

165176
@Override
166177
protected Boolean matchSuperClass(String superClassName) {
178+
167179
if (Object.class.getName().equals(superClassName)) {
168180
return Boolean.FALSE;
169-
} else if (superClassName.startsWith("java.")) {
181+
}
182+
else if (superClassName.startsWith("java.")) {
170183
try {
171-
Class<?> clazz = getClass().getClassLoader().loadClass(superClassName);
172-
return (clazz.getAnnotation(this.annotationType) != null);
173-
} catch (ClassNotFoundException ex) {
184+
Class<?> type = getClass().getClassLoader().loadClass(superClassName);
185+
return type.getAnnotation(this.annotationType) != null;
186+
}
187+
catch (ClassNotFoundException ignore) {
174188
// Class not found - can't determine a match that way.
175189
}
176190
}
@@ -194,7 +208,8 @@ private static class AllTypeFilter implements TypeFilter {
194208
*/
195209
public AllTypeFilter(List<TypeFilter> delegates) {
196210

197-
Assert.notNull(delegates);
211+
Assert.notNull(delegates, "Delegate TypeFilters must not be null");
212+
198213
this.delegates = delegates;
199214
}
200215

@@ -204,7 +219,7 @@ public AllTypeFilter(List<TypeFilter> delegates) {
204219
*/
205220
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
206221

207-
for (TypeFilter filter : delegates) {
222+
for (TypeFilter filter : this.delegates) {
208223
if (!filter.match(metadataReader, metadataReaderFactory)) {
209224
return false;
210225
}
@@ -214,4 +229,3 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
214229
}
215230
}
216231
}
217-

spring-data-geode/src/main/java/org/springframework/data/gemfire/function/config/FunctionExecutionConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FunctionExecutionConfiguration {
3535

3636
private final String annotationType;
3737

38-
/* constructor for testing purposes only */
38+
/* Constructor used for testing purposes only! */
3939
FunctionExecutionConfiguration() {
4040
this.annotationType = null;
4141
this.annotationAttributes = null;

0 commit comments

Comments
 (0)