1 /* 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 17 package android.content; 18 19 import android.net.Uri; 20 21 import java.util.ArrayList; 22 23 /** 24 * 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. 29 */ 30 public final class Entity { 31 final private ContentValues mValues; 32 final private ArrayList<NamedContentValues> mSubValues; 33 Entity(ContentValues values)34 public Entity(ContentValues values) { 35 mValues = values; 36 mSubValues = new ArrayList<NamedContentValues>(); 37 } 38 getEntityValues()39 public ContentValues getEntityValues() { 40 return mValues; 41 } 42 getSubValues()43 public ArrayList<NamedContentValues> getSubValues() { 44 return mSubValues; 45 } 46 addSubValue(Uri uri, ContentValues values)47 public void addSubValue(Uri uri, ContentValues values) { 48 mSubValues.add(new Entity.NamedContentValues(uri, values)); 49 } 50 51 public static class NamedContentValues { 52 public final Uri uri; 53 public final ContentValues values; 54 NamedContentValues(Uri uri, ContentValues values)55 public NamedContentValues(Uri uri, ContentValues values) { 56 this.uri = uri; 57 this.values = values; 58 } 59 } 60 toString()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 } 70 } 71