summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java')
-rwxr-xr-xsrc/com/google/wireless/gdata/spreadsheets/data/ListEntry.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java b/src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java
new file mode 100755
index 0000000..c3e169f
--- /dev/null
+++ b/src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java
@@ -0,0 +1,77 @@
+// Copyright 2007 The Android Open Source Project
+package com.google.wireless.gdata.spreadsheets.data;
+
+import com.google.wireless.gdata.data.Entry;
+import com.google.wireless.gdata.data.StringUtils;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
+
+/**
+ * Represents an entry in a GData Spreadsheets List feed.
+ */
+public class ListEntry extends Entry {
+ /** Map containing the values in the row. */
+ private Hashtable values = new Hashtable();
+
+ /** Caches the list of names, so they don't need to be recomputed. */
+ private Vector names = null;
+
+ /**
+ * Retrieves the column names present in this row.
+ *
+ * @return a Set of Strings, one per column where data exists
+ */
+ public Vector getNames() {
+ if (names != null) {
+ return names;
+ }
+ names = new Vector();
+ Enumeration e = values.keys();
+ while (e.hasMoreElements()) {
+ names.add(e.nextElement());
+ }
+ return names;
+ }
+
+ /**
+ * Fetches the value for a column. Equivalent to
+ * <code>getValue(name, null)</code>.
+ *
+ * @param name the name of the column whose row is to be fetched
+ * @return the value of the column, or null if the column is not present
+ */
+ public String getValue(String name) {
+ return getValue(name, null);
+ }
+
+ /**
+ * Fetches the value for a column.
+ *
+ * @param name the name of the column whose row is to be fetched
+ * @param defaultValue the value to return if the row has no value for the
+ * requested column; may be null
+ * @return the value of the column, or null if the column is not present
+ */
+ public String getValue(String name, String defaultValue) {
+ if (StringUtils.isEmpty(name)) {
+ return defaultValue;
+ }
+ String val = (String) values.get(name);
+ if (val == null) {
+ return defaultValue;
+ }
+ return val;
+ }
+
+ /**
+ * Sets the value of a column.
+ *
+ * @param name the name of the column
+ * @param value the value for the column
+ */
+ public void setValue(String name, String value) {
+ values.put(name, value == null ? "" : value);
+ }
+}