Remove unnecessary use of java.util.Optional.
This commit is contained in:
@@ -108,20 +108,23 @@ public class DurableClientConfiguration extends AbstractAnnotationConfigSupport
|
||||
|
||||
protected Integer getDurableClientTimeout() {
|
||||
|
||||
return Optional.ofNullable(this.durableClientTimeout)
|
||||
.orElse(DEFAULT_DURABLE_CLIENT_TIMEOUT);
|
||||
return this.durableClientTimeout != null
|
||||
? this.durableClientTimeout
|
||||
: DEFAULT_DURABLE_CLIENT_TIMEOUT;
|
||||
}
|
||||
|
||||
protected Boolean getKeepAlive() {
|
||||
|
||||
return Optional.ofNullable(this.keepAlive)
|
||||
.orElse(DEFAULT_KEEP_ALIVE);
|
||||
return this.keepAlive != null
|
||||
? this.keepAlive
|
||||
: DEFAULT_KEEP_ALIVE;
|
||||
}
|
||||
|
||||
protected Boolean getReadyForEvents() {
|
||||
|
||||
return Optional.ofNullable(this.readyForEvents)
|
||||
.orElse(DEFAULT_READY_FOR_EVENTS);
|
||||
return this.readyForEvents != null
|
||||
? this.readyForEvents
|
||||
: DEFAULT_READY_FOR_EVENTS;
|
||||
}
|
||||
|
||||
protected Logger getLogger() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.core.env.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
@@ -256,8 +255,8 @@ public class CloudCacheService extends Service {
|
||||
int index = String.valueOf(value).trim().indexOf("[");
|
||||
|
||||
return index > 0 ? value.trim().substring(0, index).trim()
|
||||
: (index != 0 && StringUtils.hasText(value) ? value.trim()
|
||||
: DEFAULT_LOCATOR_HOST);
|
||||
: index != 0 && StringUtils.hasText(value) ? value.trim()
|
||||
: DEFAULT_LOCATOR_HOST;
|
||||
}
|
||||
|
||||
private static int parsePort(String value) {
|
||||
@@ -281,6 +280,7 @@ public class CloudCacheService extends Service {
|
||||
* @param port {@link Integer} specifying the port number on which this {@link Locator} is listening.
|
||||
*/
|
||||
private Locator(String host, Integer port) {
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
}
|
||||
@@ -293,10 +293,7 @@ public class CloudCacheService extends Service {
|
||||
* @return the {@link String name} of the host on which this {@link Locator} is running.
|
||||
*/
|
||||
public String getHost() {
|
||||
|
||||
return Optional.ofNullable(this.host)
|
||||
.filter(StringUtils::hasText)
|
||||
.orElse(DEFAULT_LOCATOR_HOST);
|
||||
return StringUtils.hasText(this.host) ? this.host : DEFAULT_LOCATOR_HOST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,9 +304,7 @@ public class CloudCacheService extends Service {
|
||||
* @return the {@link Integer port} on which this {@link Locator} is listening.
|
||||
*/
|
||||
public int getPort() {
|
||||
|
||||
return Optional.ofNullable(this.port)
|
||||
.orElse(DEFAULT_LOCATOR_PORT);
|
||||
return this.port != null ? this.port : DEFAULT_LOCATOR_PORT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -190,11 +190,17 @@ public abstract class ObjectUtils extends org.springframework.util.ObjectUtils {
|
||||
Assert.notNull(obj, "Object is required");
|
||||
Assert.hasText(fieldName, String.format("Field name [%s] is required", fieldName));
|
||||
|
||||
return Optional.ofNullable(ReflectionUtils.findField(obj.getClass(), fieldName))
|
||||
.map(ObjectUtils::makeAccessible)
|
||||
.map(field -> ObjectUtils.<T>get(obj, field))
|
||||
.orElseThrow(() -> newIllegalArgumentException("No field with name [%s] exists on object of type [%s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj)));
|
||||
Field field = ReflectionUtils.findField(obj.getClass(), fieldName);
|
||||
|
||||
if (field != null) {
|
||||
|
||||
field = makeAccessible(field);
|
||||
|
||||
return get(obj, field);
|
||||
}
|
||||
|
||||
throw newIllegalArgumentException("No field with name [%s] exists on object of type [%s]",
|
||||
fieldName, ObjectUtils.nullSafeClassName(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,17 +246,23 @@ public abstract class ObjectUtils extends org.springframework.util.ObjectUtils {
|
||||
}
|
||||
|
||||
public static Constructor makeAccessible(Constructor<?> constructor) {
|
||||
|
||||
ReflectionUtils.makeAccessible(constructor);
|
||||
|
||||
return constructor;
|
||||
}
|
||||
|
||||
public static Field makeAccessible(Field field) {
|
||||
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Method makeAccessible(Method method) {
|
||||
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.core.type.StandardAnnotationMetadata;
|
||||
import org.springframework.data.gemfire.function.config.AbstractFunctionExecutionConfigurationSource;
|
||||
import org.springframework.data.gemfire.function.config.AnnotationFunctionExecutionConfigurationSource;
|
||||
import org.springframework.data.gemfire.function.config.FunctionExecutionBeanDefinitionRegistrar;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The {@link AbstractFunctionExecutionAutoConfigurationExtension} class extends SDG's {@link FunctionExecutionBeanDefinitionRegistrar}
|
||||
@@ -60,8 +61,9 @@ public abstract class AbstractFunctionExecutionAutoConfigurationExtension
|
||||
@SuppressWarnings("all")
|
||||
protected BeanFactory getBeanFactory() {
|
||||
|
||||
return Optional.ofNullable(this.beanFactory)
|
||||
.orElseThrow(() -> newIllegalStateException("BeanFactory was not properly configured"));
|
||||
Assert.state(this.beanFactory != null, "BeanFactory was not properly configured");
|
||||
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
protected abstract Class<?> getConfiguration();
|
||||
|
||||
@@ -13,12 +13,8 @@
|
||||
* or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.geode.security.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -84,8 +80,11 @@ public class SecurityManagerProxy extends LazyWiringDeclarableSupport
|
||||
*/
|
||||
public static SecurityManagerProxy getInstance() {
|
||||
|
||||
return Optional.ofNullable(INSTANCE.get())
|
||||
.orElseThrow(() -> newIllegalStateException("SecurityManagerProxy was not configured"));
|
||||
SecurityManagerProxy securityManagerProxy = INSTANCE.get();
|
||||
|
||||
Assert.state(securityManagerProxy != null, "SecurityManagerProxy was not configured");
|
||||
|
||||
return securityManagerProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user