1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\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.db.common.procedure.single;
\r
14 import java.util.Collection;
\r
15 import java.util.HashSet;
\r
17 import org.simantics.db.Disposable;
\r
18 import org.simantics.db.procedure.Listener;
\r
19 import org.simantics.db.procedure.SetListener;
\r
21 abstract public class SingleSetListener<T> implements Listener<Collection<T>>, SetListener<T>, Disposable {
\r
23 private boolean disposed = false;
\r
25 private Collection<T> previous = null;
\r
27 public void add(T result) {};
\r
28 public void remove(T result) {};
\r
31 public void execute(Collection<T> result) {
\r
33 if(result == null) result = new HashSet<T>();
\r
35 if(previous == null) {
\r
37 for(T t : result) add(t);
\r
41 HashSet<T> added = new HashSet<T>(result);
\r
42 added.removeAll(previous);
\r
43 HashSet<T> removed = new HashSet<T>(previous);
\r
44 removed.removeAll(result);
\r
46 for(T t : added) add(t);
\r
47 for(T t : removed) remove(t);
\r
55 public void dispose() {
\r
60 public boolean isDisposed() {
\r