Home | History | Annotate | Download | only in content
      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.os.Parcelable;
     20 import android.os.Parcel;
     21 import android.net.Uri;
     22 import android.util.Log;
     23 
     24 import java.util.ArrayList;
     25 
     26 /**
     27  * A representation of a item using ContentValues. It contains one top level ContentValue
     28  * plus a collection of Uri, ContentValues tuples as subvalues. One example of its use
     29  * is in Contacts, where the top level ContentValue contains the columns from the RawContacts
     30  * table and the subvalues contain a ContentValues object for each row from the Data table that
     31  * corresponds to that RawContact. The uri refers to the Data table uri for each row.
     32  */
     33 public final class Entity {
     34     final private ContentValues mValues;
     35     final private ArrayList<NamedContentValues> mSubValues;
     36 
     37     public Entity(ContentValues values) {
     38         mValues = values;
     39         mSubValues = new ArrayList<NamedContentValues>();
     40     }
     41 
     42     public ContentValues getEntityValues() {
     43         return mValues;
     44     }
     45 
     46     public ArrayList<NamedContentValues> getSubValues() {
     47         return mSubValues;
     48     }
     49 
     50     public void addSubValue(Uri uri, ContentValues values) {
     51         mSubValues.add(new Entity.NamedContentValues(uri, values));
     52     }
     53 
     54     public static class NamedContentValues {
     55         public final Uri uri;
     56         public final ContentValues values;
     57 
     58         public NamedContentValues(Uri uri, ContentValues values) {
     59             this.uri = uri;
     60             this.values = values;
     61         }
     62     }
     63 
     64     public String toString() {
     65         final StringBuilder sb = new StringBuilder();
     66         sb.append("Entity: ").append(getEntityValues());
     67         for (Entity.NamedContentValues namedValue : getSubValues()) {
     68             sb.append("\n  ").append(namedValue.uri);
     69             sb.append("\n  -> ").append(namedValue.values);
     70         }
     71         return sb.toString();
     72     }
     73 }
     74