You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:23:20 UTC
[sling-org-apache-sling-commons-osgi] 20/38: Add method for
handling integer properties.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.commons.osgi-2.0.2-incubator
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-osgi.git
commit ff7572e992ce2776afdd1586e83f23955b69dc4e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue May 27 14:38:31 2008 +0000
Add method for handling integer properties.
git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/commons/osgi@660533 13f79535-47bb-0310-9956-ffa450edef68
---
.../org/apache/sling/commons/osgi/OsgiUtil.java | 27 +++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java b/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
index d335c50..2b4ca43 100644
--- a/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
+++ b/src/main/java/org/apache/sling/commons/osgi/OsgiUtil.java
@@ -64,10 +64,10 @@ public class OsgiUtil {
}
/**
- * Returns the named service reference property as an integer or the
+ * Returns the named service reference property as a long or the
* <code>defaultValue</code> if no such reference property exists or if
* the property is not an <code>Integer</code> and cannot be converted to
- * an <code>Integer</code> from the property's string value.
+ * a <code>Long</code> from the property's string value.
*/
public static long toLong(Object propValue, long defaultValue) {
propValue = toObject(propValue);
@@ -85,6 +85,27 @@ public class OsgiUtil {
}
/**
+ * Returns the named service reference property as an integer or the
+ * <code>defaultValue</code> if no such reference property exists or if
+ * the property is not an <code>Integer</code> and cannot be converted to
+ * an <code>Integer</code> from the property's string value.
+ */
+ public static long toInteger(Object propValue, int defaultValue) {
+ propValue = toObject(propValue);
+ if (propValue instanceof Integer) {
+ return (Integer) propValue;
+ } else if (propValue != null) {
+ try {
+ return Integer.valueOf(String.valueOf(propValue));
+ } catch (NumberFormatException nfe) {
+ // don't care, fall through to default value
+ }
+ }
+
+ return defaultValue;
+ }
+
+ /**
* Returns the named service reference property as a double or the
* <code>defaultValue</code> if no such reference property exists or if
* the property is not an <code>Double</code> and cannot be converted to
@@ -140,7 +161,7 @@ public class OsgiUtil {
if (propValue == null) {
// no value at all
return null;
-
+
} else if (propValue instanceof String) {
// single string
return new String[] { (String) propValue };
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.