+ /**
+ * Compare the elements contained in <tt>this</tt> with those in the given
+ * {@link List}. It will return TRUE in case of equality, will return FALSE
+ * if not.
+ *
+ * If not equals, the differences will be represented by the given
+ * {@link List}s if they are not NULL.
+ * <ul>
+ * <li><tt>added</tt>will represent the elements in <tt>list</tt> but not in
+ * <tt>this</tt></li>
+ * <li><tt>removed</tt> will represent the elements in <tt>this</tt> but not
+ * in <tt>list</tt></li>
+ * <li><tt>from<tt> will represent the elements in <tt>list</tt> that are
+ * already contained in <tt>this</tt> but are not equals to them (the
+ * original element from <tt>this</tt> is stored here)</li>
+ * <li><tt>to<tt> will represent the elements in <tt>list</tt> that are
+ * already contained in <tt>this</tt> but are not equals to them (the
+ * changed element from <tt>list</tt> is stored here)</li>
+ * </ul>
+ *
+ * @param list
+ * the list of new elements
+ * @param added
+ * the list to add the <tt>added</tt> elements to, or NULL
+ * @param removed
+ * the list to add the <tt>removed</tt> elements to, or NULL
+ * @param from
+ * the map to add the <tt>from</tt> elements, or NULL
+ * @param to
+ * the map to add the <tt>to</tt> elements, or NULL
+ *
+ * @return TRUE if the elements are identical
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public boolean compare(List<E> list, List<E> added, List<E> removed,
+ List<E> from, List<E> to) {
+ Collections.sort(this.list, comparator);
+
+ List<E> mine = new LinkedList<E>(this.list);
+ List<E> other = new LinkedList<E>(list);
+
+ Collections.sort(other, comparator);
+
+ boolean equ = true;
+ while (mine.size() > 0 || other.size() > 0) {
+ E here = (mine.size() > 0) ? mine.remove(0) : null;
+ E there = (other.size() > 0) ? other.remove(0) : null;
+
+ if (here == null || comparator.compare(here, there) > 0) {
+ if (added != null)
+ added.add(there);
+ equ = false;
+ } else if (there == null || comparator.compare(here, there) < 0) {
+ if (removed != null)
+ removed.add(here);
+ equ = false;
+ } else {
+ // they represent the same item
+ if (!((BaseClass) here).isEquals(there, false)) {
+ if (from != null)
+ from.add(here);
+ if (to != null)
+ to.add(there);
+ equ = false;
+ }