/** * Create an {@link RawContactDeltaList} that contains the entities of the Iterator as before * values. This function can be passed an iterator of Entity objects or an iterator of * RawContact objects. */ public static RawContactDeltaList fromIterator(Iterator<?> iterator) { final RawContactDeltaList state = new RawContactDeltaList(); state.addAll(iterator); return state; }
@SuppressWarnings("unchecked") public void readFromParcel(Parcel source) { final ClassLoader loader = getClass().getClassLoader(); final int size = source.readInt(); for (int i = 0; i < size; i++) { this.add(source.<RawContactDelta> readParcelable(loader)); } mJoinWithRawContactIds = source.createLongArray(); mSplitRawContacts = source.readInt() != 0; }
/** * Builds {@link AggregationExceptions} to split all constituent raw contacts into * separate contacts. */ private void buildSplitContactDiff(final ArrayList<ContentProviderOperation> diff, int[] backRefs) { final int count = size(); for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { if (i == j) { continue; } final Builder builder = buildSplitContactDiffHelper(i, j, backRefs); if (builder != null) { diff.add(builder.build()); } } } }
Log.v(TAG, "buildDiff: list=" + toString()); final long rawContactId = this.findRawContactId(); int firstInsertRow = -1; int backRefs[] = new int[size()]; final Builder builder = beginKeepTogether(); builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, joinedRawContactId); if (rawContactId != -1) { final Builder builder = beginKeepTogether(); builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, rawContactId); builder.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID2, firstBatch); final Builder builder = beginKeepTogether(); builder.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID1, firstInsertRow); buildSplitContactDiff(diff, backRefs); Log.v(TAG, "buildDiff: ops=" + diffToString(diff));
Log.v(TAG, "buildDiffWrapper: list=" + toString()); final long rawContactId = this.findRawContactId(); int firstInsertRow = -1; int backRefs[] = new int[size()]; final Builder builder = beginKeepTogether(); builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, joinedRawContactId); if (rawContactId != -1) { final Builder builder = beginKeepTogether(); builder.withValue(AggregationExceptions.RAW_CONTACT_ID1, rawContactId); builder.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID2, firstBatch); final Builder builder = beginKeepTogether(); builder.withValueBackReference(AggregationExceptions.RAW_CONTACT_ID1, firstInsertRow); buildSplitContactDiffWrapper(diffWrapper, backRefs); Log.v(TAG, "buildDiff: ops=" + diffToStringWrapper(diffWrapper));
/** * Merge the "after" values from the given {@link RawContactDeltaList}, discarding any * previous "after" states. This is typically used when re-parenting user * edits onto an updated {@link RawContactDeltaList}. */ public static RawContactDeltaList mergeAfter(RawContactDeltaList local, RawContactDeltaList remote) { if (local == null) local = new RawContactDeltaList(); // For each entity in the remote set, try matching over existing for (RawContactDelta remoteEntity : remote) { final Long rawContactId = remoteEntity.getValues().getId(); // Find or create local match and merge final RawContactDelta localEntity = local.getByRawContactId(rawContactId); final RawContactDelta merged = RawContactDelta.mergeAfter(localEntity, remoteEntity); if (localEntity == null && merged != null) { // No local entry before, so insert local.add(merged); } } return local; }
/** * For compatibility purpose. */ private static String diffToStringWrapper(ArrayList<CPOWrapper> cpoWrappers) { ArrayList<ContentProviderOperation> ops = Lists.newArrayList(); for (CPOWrapper cpoWrapper : cpoWrappers) { ops.add(cpoWrapper.getOperation()); } return diffToString(ops); }
/** * For compatibility purpose, this method is copied from {@link #buildSplitContactDiff} and * takes an ArrayList of CPOWrapper as parameter. */ private void buildSplitContactDiffWrapper(final ArrayList<CPOWrapper> diff, int[] backRefs) { final int count = size(); for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { if (i == j) { continue; } final Builder builder = buildSplitContactDiffHelper(i, j, backRefs); if (builder != null) { diff.add(new CPOWrapper(builder.build(), CompatUtils.TYPE_UPDATE)); } } } }
public void addAll(Iterator<?> iterator) { // Perform background query to pull contact details while (iterator.hasNext()) { // Read all contacts into local deltas to prepare for edits Object nextObject = iterator.next(); final RawContact before = nextObject instanceof Entity ? RawContact.createFrom((Entity) nextObject) : (RawContact) nextObject; final RawContactDelta rawContactDelta = RawContactDelta.fromBefore(before); add(rawContactDelta); } }