1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.units;
\r
14 import java.util.HashMap;
\r
15 import java.util.HashSet;
\r
16 import java.util.Map;
\r
17 import java.util.Set;
\r
19 import org.simantics.databoard.accessor.reference.ChildReference;
\r
20 import org.simantics.databoard.binding.ArrayBinding;
\r
21 import org.simantics.databoard.binding.Binding;
\r
24 * This utility class contains a toolkit for synchronization of objects.
\r
26 * @author toni.kalajainen
\r
28 public class SynchronizationUtil {
\r
33 * @param arrayBinding
\r
36 * @param idRef reference identifier in item
\r
37 * @return Compare raport
\r
39 public <T> CompareRaport<T> compareArrays(ArrayBinding arrayBinding, T oldArray, T newArray, ChildReference idRef)
\r
41 Binding cb = arrayBinding.componentBinding;
\r
43 CompareRaport<T> result = new CompareRaport<T>();
\r
45 //Set<T> oldIds = new HashSet<T>( )
\r
50 // public <T> CompareRaport<T> compareMaps(MapBinding mapBinding, T oldMap, T newMap, ChildReference idRef)
\r
55 static class CompareRaport<T> {
\r
57 public Set<T> addedItems = new HashSet<T>();
\r
58 public Set<T> removedItems = new HashSet<T>();
\r
59 public Map<T, T> correspondences = new HashMap<T, T>();
\r
61 public T[] addedIndices;
\r
62 public T[] removedIndices;
\r
63 public Map<Integer, Integer> indiceCorrespondence;
\r