diff options
author | Dave Bort <dbort@android.com> | 2009-04-28 18:38:45 -0700 |
---|---|---|
committer | Dave Bort <dbort@android.com> | 2009-04-29 17:09:56 -0700 |
commit | 4b0ebef18defefe6850360cf11498f262a71847d (patch) | |
tree | 2329e31438170720efe90af823c6e9acaa3f8f8e /core/java/com/android | |
parent | 5b6f8d865d03f37c8c3a9397ca693ac671f39df7 (diff) | |
download | frameworks_base-4b0ebef18defefe6850360cf11498f262a71847d.zip frameworks_base-4b0ebef18defefe6850360cf11498f262a71847d.tar.gz frameworks_base-4b0ebef18defefe6850360cf11498f262a71847d.tar.bz2 |
TypedProperties: add getStringInfo() to help deal with null strings
Signed-off-by: Dave Bort <dbort@android.com>
Diffstat (limited to 'core/java/com/android')
-rw-r--r-- | core/java/com/android/internal/util/TypedProperties.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/core/java/com/android/internal/util/TypedProperties.java b/core/java/com/android/internal/util/TypedProperties.java index 299108f..c2ce210 100644 --- a/core/java/com/android/internal/util/TypedProperties.java +++ b/core/java/com/android/internal/util/TypedProperties.java @@ -683,4 +683,32 @@ public class TypedProperties extends HashMap<String, Object> { public String getString(String property) { return getString(property, ""); } + + // Values returned by getStringInfo() + public static final int STRING_TYPE_MISMATCH = -2; + public static final int STRING_NOT_SET = -1; + public static final int STRING_NULL = 0; + public static final int STRING_SET = 1; + + /** + * Provides string type information about a property. + * + * @param property the property to check + * @return STRING_SET if the property is a string and is non-null. + * STRING_NULL if the property is a string and is null. + * STRING_NOT_SET if the property is not set (no type or value). + * STRING_TYPE_MISMATCH if the property is set but is not a string. + */ + public int getStringInfo(String property) { + Object value = super.get(property); + if (value == null) { + return STRING_NOT_SET; + } + if (value == NULL_STRING) { + return STRING_NULL; + } else if (value instanceof String) { + return STRING_SET; + } + return STRING_TYPE_MISMATCH; + } } |