diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-04-30 17:03:26 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-30 17:03:26 -0700 |
commit | 90b6abd83952e42fe2bb15af4fb117d427e640f0 (patch) | |
tree | cc777501e50a2a01ce7ab7d7dfee715cb0fefec9 /core/java | |
parent | 8790948583fa9734cf4a54800562cb668299c4ed (diff) | |
parent | 2bc9e139655666e3c6a58d8fa74a12111b06cafd (diff) | |
download | frameworks_base-90b6abd83952e42fe2bb15af4fb117d427e640f0.zip frameworks_base-90b6abd83952e42fe2bb15af4fb117d427e640f0.tar.gz frameworks_base-90b6abd83952e42fe2bb15af4fb117d427e640f0.tar.bz2 |
am 2bc9e13: Merge change 841 into donut
Merge commit '2bc9e139655666e3c6a58d8fa74a12111b06cafd'
* commit '2bc9e139655666e3c6a58d8fa74a12111b06cafd':
TypedProperties: add getStringInfo() to help deal with null strings
Diffstat (limited to 'core/java')
-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; + } } |