blob: 607cb3f4d841e0408d3f94fbb89bcd25ab5b98fd [file] [log] [blame]
Fred Quintana6a8d5332009-05-07 17:35:38 -07001/*
2 * Copyright (C) 2009 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
Fred Quintana03d94902009-05-22 14:23:31 -070019import android.net.Uri;
Fred Quintana03d94902009-05-22 14:23:31 -070020
21import java.util.ArrayList;
Fred Quintana6a8d5332009-05-07 17:35:38 -070022
23/**
Fred Quintana2ec6c562009-12-09 16:00:31 -080024 * A representation of a item using ContentValues. It contains one top level ContentValue
25 * plus a collection of Uri, ContentValues tuples as subvalues. One example of its use
26 * is in Contacts, where the top level ContentValue contains the columns from the RawContacts
27 * table and the subvalues contain a ContentValues object for each row from the Data table that
28 * corresponds to that RawContact. The uri refers to the Data table uri for each row.
Fred Quintana6a8d5332009-05-07 17:35:38 -070029 */
Fred Quintana2ec6c562009-12-09 16:00:31 -080030public final class Entity {
Fred Quintana03d94902009-05-22 14:23:31 -070031 final private ContentValues mValues;
32 final private ArrayList<NamedContentValues> mSubValues;
33
34 public Entity(ContentValues values) {
35 mValues = values;
36 mSubValues = new ArrayList<NamedContentValues>();
37 }
38
39 public ContentValues getEntityValues() {
40 return mValues;
41 }
42
43 public ArrayList<NamedContentValues> getSubValues() {
44 return mSubValues;
45 }
46
47 public void addSubValue(Uri uri, ContentValues values) {
48 mSubValues.add(new Entity.NamedContentValues(uri, values));
49 }
50
Fred Quintana03d94902009-05-22 14:23:31 -070051 public static class NamedContentValues {
52 public final Uri uri;
53 public final ContentValues values;
54
55 public NamedContentValues(Uri uri, ContentValues values) {
56 this.uri = uri;
57 this.values = values;
58 }
59 }
60
61 public String toString() {
62 final StringBuilder sb = new StringBuilder();
63 sb.append("Entity: ").append(getEntityValues());
64 for (Entity.NamedContentValues namedValue : getSubValues()) {
65 sb.append("\n ").append(namedValue.uri);
66 sb.append("\n -> ").append(namedValue.values);
67 }
68 return sb.toString();
69 }
Fred Quintana6a8d5332009-05-07 17:35:38 -070070}