Jian Li
Committed by Gerrit Code Review

Refactor getIntegerProperty and isPropertyEnabled methods into Tools

- Add getIntegerProperty and isPropertyEnabled methods which take
  default value as third parameter
- Remove all duplicated code from RefactiveForwarding, GroupManager,
  FlowRuleManager, CoreManager, HostLocationProvider and ProxyArp

Change-Id: Ifc93aa813acfdd4cbac0166497d7b526b08b2090
......@@ -81,7 +81,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -252,153 +251,143 @@ public class ReactiveForwarding {
*/
private void readComponentConfiguration(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
boolean packetOutOnlyEnabled =
isPropertyEnabled(properties, "packetOutOnly");
if (packetOutOnly != packetOutOnlyEnabled) {
Boolean packetOutOnlyEnabled =
Tools.isPropertyEnabled(properties, "packetOutOnly");
if (packetOutOnlyEnabled == null) {
log.info("Packet-out is not configured, " +
"using current value of {}", packetOutOnly);
} else {
packetOutOnly = packetOutOnlyEnabled;
log.info("Configured. Packet-out only forwarding is {}",
packetOutOnly ? "enabled" : "disabled");
packetOutOnly ? "enabled" : "disabled");
}
boolean packetOutOfppTableEnabled =
isPropertyEnabled(properties, "packetOutOfppTable");
if (packetOutOfppTable != packetOutOfppTableEnabled) {
Boolean packetOutOfppTableEnabled =
Tools.isPropertyEnabled(properties, "packetOutOfppTable");
if (packetOutOfppTableEnabled == null) {
log.info("OFPP_TABLE port is not configured, " +
"using current value of {}", packetOutOfppTable);
} else {
packetOutOfppTable = packetOutOfppTableEnabled;
log.info("Configured. Forwarding using OFPP_TABLE port is {}",
packetOutOfppTable ? "enabled" : "disabled");
packetOutOfppTable ? "enabled" : "disabled");
}
boolean ipv6ForwardingEnabled =
isPropertyEnabled(properties, "ipv6Forwarding");
if (ipv6Forwarding != ipv6ForwardingEnabled) {
Boolean ipv6ForwardingEnabled =
Tools.isPropertyEnabled(properties, "ipv6Forwarding");
if (ipv6ForwardingEnabled == null) {
log.info("IPv6 forwarding is not configured, " +
"using current value of {}", ipv6Forwarding);
} else {
ipv6Forwarding = ipv6ForwardingEnabled;
log.info("Configured. IPv6 forwarding is {}",
ipv6Forwarding ? "enabled" : "disabled");
ipv6Forwarding ? "enabled" : "disabled");
}
boolean matchDstMacOnlyEnabled =
isPropertyEnabled(properties, "matchDstMacOnly");
if (matchDstMacOnly != matchDstMacOnlyEnabled) {
Boolean matchDstMacOnlyEnabled =
Tools.isPropertyEnabled(properties, "matchDstMacOnly");
if (matchDstMacOnlyEnabled == null) {
log.info("Match Dst MAC is not configured, " +
"using current value of {}", matchDstMacOnly);
} else {
matchDstMacOnly = matchDstMacOnlyEnabled;
log.info("Configured. Match Dst MAC Only is {}",
matchDstMacOnly ? "enabled" : "disabled");
matchDstMacOnly ? "enabled" : "disabled");
}
boolean matchVlanIdEnabled =
isPropertyEnabled(properties, "matchVlanId");
if (matchVlanId != matchVlanIdEnabled) {
Boolean matchVlanIdEnabled =
Tools.isPropertyEnabled(properties, "matchVlanId");
if (matchVlanIdEnabled == null) {
log.info("Matching Vlan ID is not configured, " +
"using current value of {}", matchVlanId);
} else {
matchVlanId = matchVlanIdEnabled;
log.info("Configured. Matching Vlan ID is {}",
matchVlanId ? "enabled" : "disabled");
matchVlanId ? "enabled" : "disabled");
}
boolean matchIpv4AddressEnabled =
isPropertyEnabled(properties, "matchIpv4Address");
if (matchIpv4Address != matchIpv4AddressEnabled) {
Boolean matchIpv4AddressEnabled =
Tools.isPropertyEnabled(properties, "matchIpv4Address");
if (matchIpv4AddressEnabled == null) {
log.info("Matching IPv4 Address is not configured, " +
"using current value of {}", matchIpv4Address);
} else {
matchIpv4Address = matchIpv4AddressEnabled;
log.info("Configured. Matching IPv4 Addresses is {}",
matchIpv4Address ? "enabled" : "disabled");
matchIpv4Address ? "enabled" : "disabled");
}
boolean matchIpv4DscpEnabled =
isPropertyEnabled(properties, "matchIpv4Dscp");
if (matchIpv4Dscp != matchIpv4DscpEnabled) {
Boolean matchIpv4DscpEnabled =
Tools.isPropertyEnabled(properties, "matchIpv4Dscp");
if (matchIpv4DscpEnabled == null) {
log.info("Matching IPv4 DSCP and ECN is not configured, " +
"using current value of {}", matchIpv4Dscp);
} else {
matchIpv4Dscp = matchIpv4DscpEnabled;
log.info("Configured. Matching IPv4 DSCP and ECN is {}",
matchIpv4Dscp ? "enabled" : "disabled");
matchIpv4Dscp ? "enabled" : "disabled");
}
boolean matchIpv6AddressEnabled =
isPropertyEnabled(properties, "matchIpv6Address");
if (matchIpv6Address != matchIpv6AddressEnabled) {
Boolean matchIpv6AddressEnabled =
Tools.isPropertyEnabled(properties, "matchIpv6Address");
if (matchIpv6AddressEnabled == null) {
log.info("Matching IPv6 Address is not configured, " +
"using current value of {}", matchIpv6Address);
} else {
matchIpv6Address = matchIpv6AddressEnabled;
log.info("Configured. Matching IPv6 Addresses is {}",
matchIpv6Address ? "enabled" : "disabled");
matchIpv6Address ? "enabled" : "disabled");
}
boolean matchIpv6FlowLabelEnabled =
isPropertyEnabled(properties, "matchIpv6FlowLabel");
if (matchIpv6FlowLabel != matchIpv6FlowLabelEnabled) {
Boolean matchIpv6FlowLabelEnabled =
Tools.isPropertyEnabled(properties, "matchIpv6FlowLabel");
if (matchIpv6FlowLabelEnabled == null) {
log.info("Matching IPv6 FlowLabel is not configured, " +
"using current value of {}", matchIpv6FlowLabel);
} else {
matchIpv6FlowLabel = matchIpv6FlowLabelEnabled;
log.info("Configured. Matching IPv6 FlowLabel is {}",
matchIpv6FlowLabel ? "enabled" : "disabled");
matchIpv6FlowLabel ? "enabled" : "disabled");
}
boolean matchTcpUdpPortsEnabled =
isPropertyEnabled(properties, "matchTcpUdpPorts");
if (matchTcpUdpPorts != matchTcpUdpPortsEnabled) {
Boolean matchTcpUdpPortsEnabled =
Tools.isPropertyEnabled(properties, "matchTcpUdpPorts");
if (matchTcpUdpPortsEnabled == null) {
log.info("Matching TCP/UDP fields is not configured, " +
"using current value of {}", matchTcpUdpPorts);
} else {
matchTcpUdpPorts = matchTcpUdpPortsEnabled;
log.info("Configured. Matching TCP/UDP fields is {}",
matchTcpUdpPorts ? "enabled" : "disabled");
matchTcpUdpPorts ? "enabled" : "disabled");
}
boolean matchIcmpFieldsEnabled =
isPropertyEnabled(properties, "matchIcmpFields");
if (matchIcmpFields != matchIcmpFieldsEnabled) {
Boolean matchIcmpFieldsEnabled =
Tools.isPropertyEnabled(properties, "matchIcmpFields");
if (matchIcmpFieldsEnabled == null) {
log.info("Matching ICMP (v4 and v6) fields is not configured, " +
"using current value of {}", matchIcmpFields);
} else {
matchIcmpFields = matchIcmpFieldsEnabled;
log.info("Configured. Matching ICMP (v4 and v6) fields is {}",
matchIcmpFields ? "enabled" : "disabled");
}
Integer flowTimeoutConfigured =
getIntegerProperty(properties, "flowTimeout");
if (flowTimeoutConfigured == null) {
flowTimeout = DEFAULT_TIMEOUT;
log.info("Flow Timeout is not configured, default value is {}",
flowTimeout);
} else {
flowTimeout = flowTimeoutConfigured;
log.info("Configured. Flow Timeout is configured to {}",
flowTimeout, " seconds");
}
Integer flowPriorityConfigured =
getIntegerProperty(properties, "flowPriority");
if (flowPriorityConfigured == null) {
flowPriority = DEFAULT_PRIORITY;
log.info("Flow Priority is not configured, default value is {}",
flowPriority);
} else {
flowPriority = flowPriorityConfigured;
log.info("Configured. Flow Priority is configured to {}",
flowPriority);
matchIcmpFields ? "enabled" : "disabled");
}
boolean ignoreIpv4McastPacketsEnabled =
isPropertyEnabled(properties, "ignoreIpv4McastPackets");
if (ignoreIpv4McastPackets != ignoreIpv4McastPacketsEnabled) {
Boolean ignoreIpv4McastPacketsEnabled =
Tools.isPropertyEnabled(properties, "ignoreIpv4McastPackets");
if (ignoreIpv4McastPacketsEnabled == null) {
log.info("Ignore IPv4 multi-cast packet is not configured, " +
"using current value of {}", ignoreIpv4McastPackets);
} else {
ignoreIpv4McastPackets = ignoreIpv4McastPacketsEnabled;
log.info("Configured. Ignore IPv4 multicast packets is {}",
ignoreIpv4McastPackets ? "enabled" : "disabled");
ignoreIpv4McastPackets ? "enabled" : "disabled");
}
}
flowTimeout = Tools.getIntegerProperty(properties, "flowTimeout", DEFAULT_TIMEOUT);
log.info("Configured. Flow Timeout is configured to {}", flowTimeout, " seconds");
/**
* Get Integer property from the propertyName
* Return null if propertyName is not found.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Integer getIntegerProperty(Dictionary<?, ?> properties,
String propertyName) {
Integer value = null;
try {
String s = Tools.get(properties, propertyName);
value = isNullOrEmpty(s) ? value : Integer.parseInt(s);
} catch (NumberFormatException | ClassCastException e) {
value = null;
}
return value;
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return true when the propertyName is defined and set to true
*/
private static boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
boolean enabled = false;
try {
String flag = Tools.get(properties, propertyName);
enabled = isNullOrEmpty(flag) ? enabled : flag.equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
enabled = false;
}
return enabled;
flowPriority = Tools.getIntegerProperty(properties, "flowPriority", DEFAULT_PRIORITY);
log.info("Configured. Flow Priority is configured to {}", flowPriority);
}
/**
......
......@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.Ethernet;
import org.onlab.packet.ICMP6;
import org.onlab.packet.IPv6;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -40,7 +41,6 @@ import org.slf4j.Logger;
import java.util.Dictionary;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onlab.packet.Ethernet.TYPE_ARP;
import static org.onlab.packet.Ethernet.TYPE_IPV6;
import static org.onlab.packet.ICMP6.NEIGHBOR_ADVERTISEMENT;
......@@ -173,7 +173,7 @@ public class ProxyArp {
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery");
flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery");
if (flag == null) {
log.info("IPv6 Neighbor Discovery is not configured, " +
"using current value of {}", ipv6NeighborDiscovery);
......@@ -185,26 +185,6 @@ public class ProxyArp {
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
Boolean value = null;
try {
String s = (String) properties.get(propertyName);
value = isNullOrEmpty(s) ? null : s.trim().equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
value = null;
}
return value;
}
/**
* Packet processor responsible for forwarding packets along their paths.
*/
private class ProxyArpProcessor implements PacketProcessor {
......
......@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.metrics.MetricsService;
import org.onlab.util.SharedExecutors;
import org.onlab.util.Tools;
import org.onosproject.app.ApplicationService;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
......@@ -48,9 +49,9 @@ import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.onosproject.security.AppPermission.Type.*;
import static org.onosproject.security.AppPermission.Type.APP_READ;
import static org.onosproject.security.AppPermission.Type.APP_WRITE;
/**
......@@ -172,7 +173,7 @@ public class CoreManager implements CoreService {
@Modified
public void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
Integer poolSize = getIntegerProperty(properties, "sharedThreadPoolSize");
Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize");
if (poolSize != null && poolSize > 1) {
sharedThreadPoolSize = poolSize;
......@@ -181,7 +182,7 @@ public class CoreManager implements CoreService {
log.warn("sharedThreadPoolSize must be greater than 1");
}
Integer timeLimit = getIntegerProperty(properties, "maxEventTimeLimit");
Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit");
if (timeLimit != null && timeLimit > 1) {
maxEventTimeLimit = timeLimit;
eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit);
......@@ -189,7 +190,7 @@ public class CoreManager implements CoreService {
log.warn("maxEventTimeLimit must be greater than 1");
}
Boolean performanceCheck = isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
if (performanceCheck != null) {
calculatePoolPerformance = performanceCheck;
SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService);
......@@ -198,48 +199,4 @@ public class CoreManager implements CoreService {
log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}",
sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance);
}
/**
* Get Integer property from the propertyName
* Return null if propertyName is not found.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Integer getIntegerProperty(Dictionary<?, ?> properties,
String propertyName) {
Integer value;
try {
String s = (String) properties.get(propertyName);
value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim());
} catch (NumberFormatException | ClassCastException e) {
value = null;
}
return value;
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
Boolean value = null;
try {
String s = (String) properties.get(propertyName);
value = isNullOrEmpty(s) ? null : s.trim().equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
value = null;
}
return value;
}
}
......
......@@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -190,7 +191,7 @@ public class FlowRuleManager
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = isPropertyEnabled(properties, "allowExtraneousRules");
flag = Tools.isPropertyEnabled(properties, "allowExtraneousRules");
if (flag == null) {
log.info("AllowExtraneousRules is not configured, " +
"using current value of {}", allowExtraneousRules);
......@@ -200,7 +201,7 @@ public class FlowRuleManager
allowExtraneousRules ? "enabled" : "disabled");
}
flag = isPropertyEnabled(properties, "purgeOnDisconnection");
flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
if (flag == null) {
log.info("PurgeOnDisconnection is not configured, " +
"using current value of {}", purgeOnDisconnection);
......@@ -218,24 +219,6 @@ public class FlowRuleManager
}
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
try {
String s = (String) properties.get(propertyName);
return isNullOrEmpty(s) ? null : s.trim().equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
return null;
}
}
@Override
public int getFlowRuleCount() {
checkPermission(FLOWRULE_READ);
......
......@@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
......@@ -45,6 +45,7 @@ import org.onosproject.net.group.GroupService;
import org.onosproject.net.group.GroupStore;
import org.onosproject.net.group.GroupStore.UpdateType;
import org.onosproject.net.group.GroupStoreDelegate;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
......@@ -53,10 +54,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.onosproject.security.AppPermission.Type.GROUP_READ;
import static org.onosproject.security.AppPermission.Type.GROUP_WRITE;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppPermission.Type.*;
......@@ -129,7 +130,7 @@ public class GroupManager
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = isPropertyEnabled(properties, "purgeOnDisconnection");
flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
if (flag == null) {
log.info("PurgeOnDisconnection is not configured, " +
"using current value of {}", purgeOnDisconnection);
......@@ -141,26 +142,6 @@ public class GroupManager
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
Boolean value = null;
try {
String s = (String) properties.get(propertyName);
value = isNullOrEmpty(s) ? null : s.trim().equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
value = null;
}
return value;
}
/**
* Create a group in the specified device with the provided parameters.
*
* @param groupDesc group creation parameters
......
......@@ -35,6 +35,7 @@ import org.onlab.packet.ndp.NeighborAdvertisement;
import org.onlab.packet.ndp.NeighborSolicitation;
import org.onlab.packet.ndp.RouterAdvertisement;
import org.onlab.packet.ndp.RouterSolicitation;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
......@@ -69,7 +70,6 @@ import java.util.Dictionary;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -228,7 +228,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
flag = isPropertyEnabled(properties, "hostRemovalEnabled");
flag = Tools.isPropertyEnabled(properties, "hostRemovalEnabled");
if (flag == null) {
log.info("Host removal on port/device down events is not configured, " +
"using current value of {}", hostRemovalEnabled);
......@@ -238,7 +238,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
hostRemovalEnabled ? "enabled" : "disabled");
}
flag = isPropertyEnabled(properties, "ipv6NeighborDiscovery");
flag = Tools.isPropertyEnabled(properties, "ipv6NeighborDiscovery");
if (flag == null) {
log.info("Using IPv6 Neighbor Discovery is not configured, " +
"using current value of {}", ipv6NeighborDiscovery);
......@@ -248,7 +248,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
ipv6NeighborDiscovery ? "enabled" : "disabled");
}
flag = isPropertyEnabled(properties, "requestInterceptsEnabled");
flag = Tools.isPropertyEnabled(properties, "requestInterceptsEnabled");
if (flag == null) {
log.info("Request intercepts is not configured, " +
"using current value of {}", requestInterceptsEnabled);
......@@ -259,26 +259,6 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid
}
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
Boolean value = null;
try {
String s = (String) properties.get(propertyName);
value = isNullOrEmpty(s) ? null : s.trim().equals("true");
} catch (ClassCastException e) {
// No propertyName defined.
value = null;
}
return value;
}
@Override
public void triggerProbe(Host host) {
log.info("Triggering probe on device {}", host);
......
......@@ -275,6 +275,84 @@ public abstract class Tools {
}
/**
* Get Integer property from the propertyName
* Return null if propertyName is not found.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
public static Integer getIntegerProperty(Dictionary<?, ?> properties,
String propertyName) {
Integer value;
try {
String s = get(properties, propertyName);
value = Strings.isNullOrEmpty(s) ? null : Integer.valueOf(s);
} catch (NumberFormatException | ClassCastException e) {
value = null;
}
return value;
}
/**
* Get Integer property from the propertyName
* Return default value if propertyName is not found.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @param defaultValue the default value that to be assigned
* @return value when the propertyName is defined or return default value
*/
public static int getIntegerProperty(Dictionary<?, ?> properties,
String propertyName,
int defaultValue) {
try {
String s = get(properties, propertyName);
return Strings.isNullOrEmpty(s) ? defaultValue : Integer.valueOf(s);
} catch (NumberFormatException | ClassCastException e) {
return defaultValue;
}
}
/**
* Check property name is defined and set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @return value when the propertyName is defined or return null
*/
public static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName) {
Boolean value;
try {
String s = get(properties, propertyName);
value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s);
} catch (ClassCastException e) {
value = null;
}
return value;
}
/**
* Check property name is defined as set to true.
*
* @param properties properties to be looked up
* @param propertyName the name of the property to look up
* @param defaultValue the default value that to be assigned
* @return value when the propertyName is defined or return the default value
*/
public static boolean isPropertyEnabled(Dictionary<?, ?> properties,
String propertyName,
boolean defaultValue) {
try {
String s = get(properties, propertyName);
return Strings.isNullOrEmpty(s) ? defaultValue : Boolean.valueOf(s);
} catch (ClassCastException e) {
return defaultValue;
}
}
/**
* Suspends the current thread for a specified number of millis.
*
* @param ms number of millis
......