blob: 06d0f66d85485eb56b4f0889dad89ef741eece68 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Mathew Inwood5c0d3542018-08-14 13:54:31 +010019import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Parcel;
21import android.os.Parcelable;
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060022import android.util.ArrayMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.util.Log;
24
Jeff Sharkey32b947e2018-08-08 13:42:25 -060025import com.android.internal.util.Preconditions;
26
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import java.util.ArrayList;
28import java.util.HashMap;
29import java.util.Map;
Jeff Sharkey32b947e2018-08-08 13:42:25 -060030import java.util.Objects;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import java.util.Set;
32
33/**
34 * This class is used to store a set of values that the {@link ContentResolver}
35 * can process.
36 */
37public final class ContentValues implements Parcelable {
38 public static final String TAG = "ContentValues";
39
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060040 /**
41 * @hide
42 * @deprecated kept around for lame people doing reflection
43 */
44 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +010045 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 private HashMap<String, Object> mValues;
47
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060048 private final ArrayMap<String, Object> mMap;
49
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 /**
51 * Creates an empty set of values using the default initial size
52 */
53 public ContentValues() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060054 mMap = new ArrayMap<>();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 }
56
57 /**
58 * Creates an empty set of values using the given initial size
Fred Quintanabda88742010-02-19 13:13:04 -080059 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 * @param size the initial size of the set of values
61 */
62 public ContentValues(int size) {
Jeff Sharkey32b947e2018-08-08 13:42:25 -060063 Preconditions.checkArgumentNonnegative(size);
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060064 mMap = new ArrayMap<>(size);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 }
66
67 /**
68 * Creates a set of values copied from the given set
Fred Quintanabda88742010-02-19 13:13:04 -080069 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 * @param from the values to copy
71 */
72 public ContentValues(ContentValues from) {
Jeff Sharkey32b947e2018-08-08 13:42:25 -060073 Objects.requireNonNull(from);
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060074 mMap = new ArrayMap<>(from.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 }
76
77 /**
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060078 * @hide
79 * @deprecated kept around for lame people doing reflection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 */
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060081 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +010082 @UnsupportedAppUsage
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060083 private ContentValues(HashMap<String, Object> from) {
84 mMap = new ArrayMap<>();
85 mMap.putAll(from);
86 }
87
88 /** {@hide} */
89 private ContentValues(Parcel in) {
90 mMap = new ArrayMap<>(in.readInt());
91 in.readArrayMap(mMap, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 }
93
94 @Override
95 public boolean equals(Object object) {
96 if (!(object instanceof ContentValues)) {
97 return false;
98 }
Jeff Sharkey6adc98c2018-07-12 19:47:49 -060099 return mMap.equals(((ContentValues) object).mMap);
100 }
101
102 /** {@hide} */
103 public ArrayMap<String, Object> getValues() {
104 return mMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 }
106
107 @Override
108 public int hashCode() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600109 return mMap.hashCode();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 }
111
112 /**
113 * Adds a value to the set.
114 *
115 * @param key the name of the value to put
116 * @param value the data for the value to put
117 */
118 public void put(String key, String value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600119 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 }
121
122 /**
123 * Adds all values from the passed in ContentValues.
124 *
125 * @param other the ContentValues from which to copy
126 */
127 public void putAll(ContentValues other) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600128 mMap.putAll(other.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 }
130
131 /**
132 * Adds a value to the set.
133 *
134 * @param key the name of the value to put
135 * @param value the data for the value to put
136 */
137 public void put(String key, Byte value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600138 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140
141 /**
142 * Adds a value to the set.
143 *
144 * @param key the name of the value to put
145 * @param value the data for the value to put
146 */
147 public void put(String key, Short value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600148 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 }
150
151 /**
152 * Adds a value to the set.
153 *
154 * @param key the name of the value to put
155 * @param value the data for the value to put
156 */
157 public void put(String key, Integer value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600158 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 }
160
161 /**
162 * Adds a value to the set.
163 *
164 * @param key the name of the value to put
165 * @param value the data for the value to put
166 */
167 public void put(String key, Long value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600168 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 }
170
171 /**
172 * Adds a value to the set.
173 *
174 * @param key the name of the value to put
175 * @param value the data for the value to put
176 */
177 public void put(String key, Float value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600178 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 }
180
181 /**
182 * Adds a value to the set.
183 *
184 * @param key the name of the value to put
185 * @param value the data for the value to put
186 */
187 public void put(String key, Double value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600188 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 }
190
191 /**
192 * Adds a value to the set.
193 *
194 * @param key the name of the value to put
195 * @param value the data for the value to put
196 */
197 public void put(String key, Boolean value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600198 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 }
Fred Quintanabda88742010-02-19 13:13:04 -0800200
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 /**
202 * Adds a value to the set.
203 *
204 * @param key the name of the value to put
205 * @param value the data for the value to put
206 */
207 public void put(String key, byte[] value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600208 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 }
210
211 /**
212 * Adds a null value to the set.
Fred Quintanabda88742010-02-19 13:13:04 -0800213 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 * @param key the name of the value to make null
215 */
216 public void putNull(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600217 mMap.put(key, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 }
219
220 /**
221 * Returns the number of values.
Fred Quintanabda88742010-02-19 13:13:04 -0800222 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 * @return the number of values
224 */
225 public int size() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600226 return mMap.size();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 }
228
229 /**
Mike Tsaoc74ee2f2017-03-24 14:56:34 -0700230 * Indicates whether this collection is empty.
231 *
232 * @return true iff size == 0
233 * {@hide}
234 * TODO: consider exposing this new method publicly
235 */
236 public boolean isEmpty() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600237 return mMap.isEmpty();
Mike Tsaoc74ee2f2017-03-24 14:56:34 -0700238 }
239
240 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 * Remove a single value.
242 *
243 * @param key the name of the value to remove
244 */
245 public void remove(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600246 mMap.remove(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 }
248
249 /**
250 * Removes all values.
251 */
252 public void clear() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600253 mMap.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 }
255
256 /**
257 * Returns true if this object has the named value.
258 *
259 * @param key the value to check for
Fred Quintanabda88742010-02-19 13:13:04 -0800260 * @return {@code true} if the value is present, {@code false} otherwise
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 */
262 public boolean containsKey(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600263 return mMap.containsKey(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 }
265
266 /**
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400267 * Gets a value. Valid value types are {@link String}, {@link Boolean},
268 * {@link Number}, and {@code byte[]} implementations.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 *
270 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400271 * @return the data for the value, or {@code null} if the value is missing or if {@code null}
272 * was previously added with the given {@code key}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 */
274 public Object get(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600275 return mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 }
277
278 /**
279 * Gets a value and converts it to a String.
Fred Quintanabda88742010-02-19 13:13:04 -0800280 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 * @param key the value to get
282 * @return the String for the value
283 */
284 public String getAsString(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600285 Object value = mMap.get(key);
Daniel Lehmann1c4027b2010-03-22 20:35:02 -0700286 return value != null ? value.toString() : null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
288
289 /**
290 * Gets a value and converts it to a Long.
Fred Quintanabda88742010-02-19 13:13:04 -0800291 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400293 * @return the Long value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 */
295 public Long getAsLong(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600296 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 try {
298 return value != null ? ((Number) value).longValue() : null;
299 } catch (ClassCastException e) {
300 if (value instanceof CharSequence) {
301 try {
302 return Long.valueOf(value.toString());
303 } catch (NumberFormatException e2) {
304 Log.e(TAG, "Cannot parse Long value for " + value + " at key " + key);
305 return null;
306 }
307 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800308 Log.e(TAG, "Cannot cast value for " + key + " to a Long: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 return null;
310 }
311 }
312 }
313
314 /**
315 * Gets a value and converts it to an Integer.
Fred Quintanabda88742010-02-19 13:13:04 -0800316 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400318 * @return the Integer value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 */
320 public Integer getAsInteger(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600321 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 try {
323 return value != null ? ((Number) value).intValue() : null;
324 } catch (ClassCastException e) {
325 if (value instanceof CharSequence) {
326 try {
327 return Integer.valueOf(value.toString());
328 } catch (NumberFormatException e2) {
329 Log.e(TAG, "Cannot parse Integer value for " + value + " at key " + key);
330 return null;
331 }
332 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800333 Log.e(TAG, "Cannot cast value for " + key + " to a Integer: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 return null;
335 }
336 }
337 }
338
339 /**
340 * Gets a value and converts it to a Short.
Fred Quintanabda88742010-02-19 13:13:04 -0800341 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400343 * @return the Short value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 */
345 public Short getAsShort(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600346 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 try {
348 return value != null ? ((Number) value).shortValue() : null;
349 } catch (ClassCastException e) {
350 if (value instanceof CharSequence) {
351 try {
352 return Short.valueOf(value.toString());
353 } catch (NumberFormatException e2) {
354 Log.e(TAG, "Cannot parse Short value for " + value + " at key " + key);
355 return null;
356 }
357 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800358 Log.e(TAG, "Cannot cast value for " + key + " to a Short: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 return null;
360 }
361 }
362 }
363
364 /**
365 * Gets a value and converts it to a Byte.
Fred Quintanabda88742010-02-19 13:13:04 -0800366 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400368 * @return the Byte value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 */
370 public Byte getAsByte(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600371 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 try {
373 return value != null ? ((Number) value).byteValue() : null;
374 } catch (ClassCastException e) {
375 if (value instanceof CharSequence) {
376 try {
377 return Byte.valueOf(value.toString());
378 } catch (NumberFormatException e2) {
379 Log.e(TAG, "Cannot parse Byte value for " + value + " at key " + key);
380 return null;
381 }
382 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800383 Log.e(TAG, "Cannot cast value for " + key + " to a Byte: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 return null;
385 }
386 }
387 }
388
389 /**
390 * Gets a value and converts it to a Double.
Fred Quintanabda88742010-02-19 13:13:04 -0800391 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400393 * @return the Double value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 */
395 public Double getAsDouble(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600396 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 try {
398 return value != null ? ((Number) value).doubleValue() : null;
399 } catch (ClassCastException e) {
400 if (value instanceof CharSequence) {
401 try {
402 return Double.valueOf(value.toString());
403 } catch (NumberFormatException e2) {
404 Log.e(TAG, "Cannot parse Double value for " + value + " at key " + key);
405 return null;
406 }
407 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800408 Log.e(TAG, "Cannot cast value for " + key + " to a Double: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 return null;
410 }
411 }
412 }
413
414 /**
415 * Gets a value and converts it to a Float.
Fred Quintanabda88742010-02-19 13:13:04 -0800416 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400418 * @return the Float value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 */
420 public Float getAsFloat(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600421 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 try {
423 return value != null ? ((Number) value).floatValue() : null;
424 } catch (ClassCastException e) {
425 if (value instanceof CharSequence) {
426 try {
427 return Float.valueOf(value.toString());
428 } catch (NumberFormatException e2) {
429 Log.e(TAG, "Cannot parse Float value for " + value + " at key " + key);
430 return null;
431 }
432 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800433 Log.e(TAG, "Cannot cast value for " + key + " to a Float: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 return null;
435 }
436 }
437 }
438
439 /**
440 * Gets a value and converts it to a Boolean.
Fred Quintanabda88742010-02-19 13:13:04 -0800441 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400443 * @return the Boolean value, or {@code null} if the value is missing or cannot be converted
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 */
445 public Boolean getAsBoolean(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600446 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 try {
448 return (Boolean) value;
449 } catch (ClassCastException e) {
450 if (value instanceof CharSequence) {
Michael Wright794cf192017-01-18 18:12:53 +0000451 // Note that we also check against 1 here because SQLite's internal representation
452 // for booleans is an integer with a value of 0 or 1. Without this check, boolean
453 // values obtained via DatabaseUtils#cursorRowToContentValues will always return
454 // false.
455 return Boolean.valueOf(value.toString()) || "1".equals(value);
Jeff Hamiltond208c3a2010-09-17 08:12:19 -0500456 } else if (value instanceof Number) {
457 return ((Number) value).intValue() != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458 } else {
Fred Quintanabda88742010-02-19 13:13:04 -0800459 Log.e(TAG, "Cannot cast value for " + key + " to a Boolean: " + value, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 return null;
461 }
462 }
463 }
464
465 /**
466 * Gets a value that is a byte array. Note that this method will not convert
467 * any other types to byte arrays.
Fred Quintanabda88742010-02-19 13:13:04 -0800468 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 * @param key the value to get
Steve Pomeroy1276b5f2012-10-09 15:37:34 -0400470 * @return the {@code byte[]} value, or {@code null} is the value is missing or not a
471 * {@code byte[]}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 */
473 public byte[] getAsByteArray(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600474 Object value = mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 if (value instanceof byte[]) {
476 return (byte[]) value;
477 } else {
478 return null;
479 }
480 }
481
482 /**
483 * Returns a set of all of the keys and values
Fred Quintanabda88742010-02-19 13:13:04 -0800484 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 * @return a set of all of the keys and values
486 */
487 public Set<Map.Entry<String, Object>> valueSet() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600488 return mMap.entrySet();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 }
Fred Quintanabda88742010-02-19 13:13:04 -0800490
Vasu Nori532abb62010-08-02 16:45:47 -0700491 /**
492 * Returns a set of all of the keys
493 *
494 * @return a set of all of the keys
495 */
496 public Set<String> keySet() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600497 return mMap.keySet();
Vasu Nori532abb62010-08-02 16:45:47 -0700498 }
499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 public static final Parcelable.Creator<ContentValues> CREATOR =
501 new Parcelable.Creator<ContentValues>() {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600502 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 public ContentValues createFromParcel(Parcel in) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600504 return new ContentValues(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 }
506
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600507 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 public ContentValues[] newArray(int size) {
509 return new ContentValues[size];
510 }
511 };
512
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600513 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 public int describeContents() {
515 return 0;
516 }
517
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600518 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600520 parcel.writeInt(mMap.size());
521 parcel.writeArrayMap(mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 }
523
524 /**
525 * Unsupported, here until we get proper bulk insert APIs.
526 * {@hide}
527 */
528 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100529 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 public void putStringArrayList(String key, ArrayList<String> value) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600531 mMap.put(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
533
534 /**
535 * Unsupported, here until we get proper bulk insert APIs.
536 * {@hide}
537 */
538 @SuppressWarnings("unchecked")
539 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100540 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 public ArrayList<String> getStringArrayList(String key) {
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600542 return (ArrayList<String>) mMap.get(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 }
544
Jeff Hamiltonf924a512010-08-25 10:19:36 -0500545 /**
546 * Returns a string containing a concise, human-readable description of this object.
547 * @return a printable representation of this object.
548 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 @Override
550 public String toString() {
551 StringBuilder sb = new StringBuilder();
Jeff Sharkey6adc98c2018-07-12 19:47:49 -0600552 for (String name : mMap.keySet()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 String value = getAsString(name);
554 if (sb.length() > 0) sb.append(" ");
555 sb.append(name + "=" + value);
556 }
557 return sb.toString();
558 }
559}