DATAGEODE-188 - Refactor and simplify codebase.

This commit is contained in:
John Blum
2019-05-12 23:25:07 -07:00
parent ad0ad251a1
commit ef4e32e43d
7 changed files with 47 additions and 64 deletions

View File

@@ -1350,6 +1350,7 @@ public class CacheFactoryBean extends AbstractFactoryBeanSupport<GemFireCache>
* @see org.apache.geode.cache.CacheFactory
* @see org.apache.geode.cache.client.ClientCacheFactory
*/
@FunctionalInterface
public interface CacheFactoryInitializer<T> {
/**

View File

@@ -14,7 +14,6 @@
* limitations under the License.
*
*/
package org.springframework.data.gemfire.config.annotation;
import java.lang.annotation.Documented;

View File

@@ -19,6 +19,7 @@ package org.springframework.data.gemfire.snapshot;
import static java.util.Arrays.stream;
import static org.apache.geode.cache.snapshot.SnapshotOptions.SnapshotFormat;
import static org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.SnapshotServiceAdapter;
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
@@ -88,11 +89,6 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
private SnapshotServiceAdapter<K, V> snapshotServiceAdapter;
@SuppressWarnings("unchecked")
static <K, V> SnapshotMetadata<K, V>[] nullSafeArray(SnapshotMetadata<K, V>[] configurations) {
return configurations != null ? configurations : EMPTY_ARRAY;
}
static boolean nullSafeIsDirectory(File file) {
return file != null && file.isDirectory();
}
@@ -210,8 +206,9 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
* @return an array of snapshot meta-data used for each export.
* @see SnapshotServiceFactoryBean.SnapshotMetadata
*/
@SuppressWarnings("unchecked")
protected SnapshotMetadata<K, V>[] getExports() {
return nullSafeArray(exports);
return nullSafeArray(exports, SnapshotMetadata.class);
}
/**
@@ -232,8 +229,9 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
* @return an array of snapshot meta-data used for each import.
* @see SnapshotServiceFactoryBean.SnapshotMetadata
*/
@SuppressWarnings("unchecked")
protected SnapshotMetadata<K, V>[] getImports() {
return nullSafeArray(imports);
return nullSafeArray(imports, SnapshotMetadata.class);
}
/**
@@ -455,7 +453,7 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
@SuppressWarnings("unchecked")
public void doExport(SnapshotMetadata<K, V>... configurations) {
stream(nullSafeArray(configurations)).forEach(configuration ->
stream(nullSafeArray(configurations, SnapshotMetadata.class)).forEach(configuration ->
save(configuration.getLocation(), configuration.getFormat(), createOptions(configuration)));
}
@@ -463,7 +461,7 @@ public class SnapshotServiceFactoryBean<K, V> extends AbstractFactoryBeanSupport
@SuppressWarnings("unchecked")
public void doImport(SnapshotMetadata<K, V>... configurations) {
stream(nullSafeArray(configurations)).forEach(configuration ->
stream(nullSafeArray(configurations, SnapshotMetadata.class)).forEach(configuration ->
load(configuration.getFormat(), createOptions(configuration), handleLocation(configuration)));
}

View File

@@ -16,6 +16,8 @@
package org.springframework.data.gemfire.snapshot.filter;
import static org.springframework.data.gemfire.util.ArrayUtils.nullSafeArray;
import java.util.Map;
import org.apache.geode.cache.snapshot.SnapshotFilter;
@@ -69,17 +71,12 @@ public class ComposableSnapshotFilter<K, V> implements SnapshotFilter<K, V> {
* @see org.apache.geode.cache.snapshot.SnapshotFilter
*/
private ComposableSnapshotFilter(SnapshotFilter<K, V> leftOperand, Operator operator, SnapshotFilter<K, V> rightOperand) {
this.leftOperand = leftOperand;
this.operator = operator;
this.rightOperand = rightOperand;
}
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
static <K, V> SnapshotFilter<K, V>[] nullSafeArray(SnapshotFilter<K, V>... array) {
return (array != null ? array : new SnapshotFilter[0]);
}
/**
* Composes the array of SnapshotFilters into a logical boolean expression using the specified Operator.
*
@@ -92,10 +89,12 @@ public class ComposableSnapshotFilter<K, V> implements SnapshotFilter<K, V> {
* @see ComposableSnapshotFilter.Operator
* @see org.apache.geode.cache.snapshot.SnapshotFilter
*/
@SuppressWarnings("unchecked")
protected static <K, V> SnapshotFilter<K, V> compose(Operator operator, SnapshotFilter<K, V>... snapshotFilters) {
SnapshotFilter<K, V> composedSnapshotFilter = null;
for (SnapshotFilter<K, V> snapshotFilter : nullSafeArray(snapshotFilters)) {
for (SnapshotFilter<K, V> snapshotFilter : nullSafeArray(snapshotFilters, SnapshotFilter.class)) {
composedSnapshotFilter = (composedSnapshotFilter == null ? snapshotFilter
: new ComposableSnapshotFilter<K, V>(snapshotFilter, operator, composedSnapshotFilter));
}
@@ -144,7 +143,7 @@ public class ComposableSnapshotFilter<K, V> implements SnapshotFilter<K, V> {
*/
@Override
public boolean accept(final Map.Entry<K, V> entry) {
return operator.operate(leftOperand.accept(entry), rightOperand.accept(entry));
return this.operator.operate(this.leftOperand.accept(entry), this.rightOperand.accept(entry));
}
}