summaryrefslogtreecommitdiff
path: root/src/com/google/wireless/gdata/spreadsheets/data/ListEntry.java
blob: c3e169f33caf1c7fed3d4bdcbea507ea0efd06e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);
    }
}