FileDocCategorySizeDatePackage
ContentValues.javaAPI DocAndroid 5.1 API15141Thu Mar 12 22:22:10 GMT 2015android.content

ContentValues

public final class ContentValues extends Object implements android.os.Parcelable
This class is used to store a set of values that the {@link ContentResolver} can process.

Fields Summary
public static final String
TAG
private HashMap
mValues
Holds the actual values
public static final Parcelable.Creator
CREATOR
Constructors Summary
public ContentValues()
Creates an empty set of values using the default initial size


                    
      
        // Choosing a default size of 8 based on analysis of typical
        // consumption by applications.
        mValues = new HashMap<String, Object>(8);
    
public ContentValues(int size)
Creates an empty set of values using the given initial size

param
size the initial size of the set of values

        mValues = new HashMap<String, Object>(size, 1.0f);
    
public ContentValues(ContentValues from)
Creates a set of values copied from the given set

param
from the values to copy

        mValues = new HashMap<String, Object>(from.mValues);
    
private ContentValues(HashMap values)
Creates a set of values copied from the given HashMap. This is used by the Parcel unmarshalling code.

param
values the values to start with {@hide}

        mValues = values;
    
Methods Summary
public voidclear()
Removes all values.

        mValues.clear();
    
public booleancontainsKey(java.lang.String key)
Returns true if this object has the named value.

param
key the value to check for
return
{@code true} if the value is present, {@code false} otherwise

        return mValues.containsKey(key);
    
public intdescribeContents()


       
        return 0;
    
public booleanequals(java.lang.Object object)

        if (!(object instanceof ContentValues)) {
            return false;
        }
        return mValues.equals(((ContentValues) object).mValues);
    
public java.lang.Objectget(java.lang.String key)
Gets a value. Valid value types are {@link String}, {@link Boolean}, and {@link Number} implementations.

param
key the value to get
return
the data for the value

        return mValues.get(key);
    
public java.lang.BooleangetAsBoolean(java.lang.String key)
Gets a value and converts it to a Boolean.

param
key the value to get
return
the Boolean value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return (Boolean) value;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                return Boolean.valueOf(value.toString());
            } else if (value instanceof Number) {
                return ((Number) value).intValue() != 0;
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Boolean: " + value, e);
                return null;
            }
        }
    
public java.lang.BytegetAsByte(java.lang.String key)
Gets a value and converts it to a Byte.

param
key the value to get
return
the Byte value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).byteValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Byte.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Byte value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Byte: " + value, e);
                return null;
            }
        }
    
public byte[]getAsByteArray(java.lang.String key)
Gets a value that is a byte array. Note that this method will not convert any other types to byte arrays.

param
key the value to get
return
the byte[] value, or null is the value is missing or not a byte[]

        Object value = mValues.get(key);
        if (value instanceof byte[]) {
            return (byte[]) value;
        } else {
            return null;
        }
    
public java.lang.DoublegetAsDouble(java.lang.String key)
Gets a value and converts it to a Double.

param
key the value to get
return
the Double value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).doubleValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Double.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Double value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Double: " + value, e);
                return null;
            }
        }
    
public java.lang.FloatgetAsFloat(java.lang.String key)
Gets a value and converts it to a Float.

param
key the value to get
return
the Float value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).floatValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Float.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Float value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Float: " + value, e);
                return null;
            }
        }
    
public java.lang.IntegergetAsInteger(java.lang.String key)
Gets a value and converts it to an Integer.

param
key the value to get
return
the Integer value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).intValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Integer.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Integer value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Integer: " + value, e);
                return null;
            }
        }
    
public java.lang.LonggetAsLong(java.lang.String key)
Gets a value and converts it to a Long.

param
key the value to get
return
the Long value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).longValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Long.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Long value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Long: " + value, e);
                return null;
            }
        }
    
public java.lang.ShortgetAsShort(java.lang.String key)
Gets a value and converts it to a Short.

param
key the value to get
return
the Short value, or null if the value is missing or cannot be converted

        Object value = mValues.get(key);
        try {
            return value != null ? ((Number) value).shortValue() : null;
        } catch (ClassCastException e) {
            if (value instanceof CharSequence) {
                try {
                    return Short.valueOf(value.toString());
                } catch (NumberFormatException e2) {
                    Log.e(TAG, "Cannot parse Short value for " + value + " at key " + key);
                    return null;
                }
            } else {
                Log.e(TAG, "Cannot cast value for " + key + " to a Short: " + value, e);
                return null;
            }
        }
    
public java.lang.StringgetAsString(java.lang.String key)
Gets a value and converts it to a String.

param
key the value to get
return
the String for the value

        Object value = mValues.get(key);
        return value != null ? value.toString() : null;
    
public java.util.ArrayListgetStringArrayList(java.lang.String key)
Unsupported, here until we get proper bulk insert APIs. {@hide}

        return (ArrayList<String>) mValues.get(key);
    
public inthashCode()

        return mValues.hashCode();
    
public java.util.SetkeySet()
Returns a set of all of the keys

return
a set of all of the keys

        return mValues.keySet();
    
public voidput(java.lang.String key, java.lang.Short value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Integer value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Long value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Float value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Double value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Boolean value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, byte[] value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.String value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidput(java.lang.String key, java.lang.Byte value)
Adds a value to the set.

param
key the name of the value to put
param
value the data for the value to put

        mValues.put(key, value);
    
public voidputAll(android.content.ContentValues other)
Adds all values from the passed in ContentValues.

param
other the ContentValues from which to copy

        mValues.putAll(other.mValues);
    
public voidputNull(java.lang.String key)
Adds a null value to the set.

param
key the name of the value to make null

        mValues.put(key, null);
    
public voidputStringArrayList(java.lang.String key, java.util.ArrayList value)
Unsupported, here until we get proper bulk insert APIs. {@hide}

        mValues.put(key, value);
    
public voidremove(java.lang.String key)
Remove a single value.

param
key the name of the value to remove

        mValues.remove(key);
    
public intsize()
Returns the number of values.

return
the number of values

        return mValues.size();
    
public java.lang.StringtoString()
Returns a string containing a concise, human-readable description of this object.

return
a printable representation of this object.

        StringBuilder sb = new StringBuilder();
        for (String name : mValues.keySet()) {
            String value = getAsString(name);
            if (sb.length() > 0) sb.append(" ");
            sb.append(name + "=" + value);
        }
        return sb.toString();
    
public java.util.SetvalueSet()
Returns a set of all of the keys and values

return
a set of all of the keys and values

        return mValues.entrySet();
    
public voidwriteToParcel(android.os.Parcel parcel, int flags)

        parcel.writeMap(mValues);