Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: acbd89f9ca38c0a51986d530154d324138dda511 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2007, 2008 Matthew Hall and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Matthew Hall - initial API and implementation (bug 208858)
 ******************************************************************************/

package org.eclipse.core.databinding.observable.list;

import java.util.List;

/**
 * A visitor for processing differences in a ListDiff.
 * 
 * @see ListDiff#accept(ListDiffVisitor)
 * @since 1.1
 */
public abstract class ListDiffVisitor {
	/**
	 * Notifies the visitor that <code>element</code> was added to the list at
	 * position <code>index</code>.
	 * 
	 * @param index
	 *            the index where the element was added
	 * @param element
	 *            the element that was added
	 */
	public abstract void handleAdd(int index, Object element);

	/**
	 * Notifies the visitor that <code>element</code> was removed from the
	 * list at position <code>index</code>.
	 * 
	 * @param index
	 *            the index where the element was removed
	 * @param element
	 *            the element that was removed
	 */
	public abstract void handleRemove(int index, Object element);

	/**
	 * Notifies the visitor that <code>element</code> was moved in the list
	 * from position <code>oldIndex</code> to position <code>newIndex</code>.
	 * <p>
	 * The default implementation of this method calls
	 * {@link #handleRemove(int, Object)} with the old position, then
	 * {@link #handleAdd(int, Object)} with the new position. Clients which are
	 * interested in recognizing "moves" in a list (i.e. calls to
	 * {@link IObservableList#move(int, int)}) should override this method.
	 * 
	 * @param oldIndex
	 *            the index that the element was moved from.
	 * @param newIndex
	 *            the index that the element was moved to.
	 * @param element
	 *            the element that was moved
	 * @see IObservableList#move(int, int)
	 */
	public void handleMove(int oldIndex, int newIndex, Object element) {
		handleRemove(oldIndex, element);
		handleAdd(newIndex, element);
	}

	/**
	 * Notifies the visitor that <code>oldElement</code>, located at position
	 * <code>index</code> in the list, was replaced by <code>newElement</code>.
	 * <p>
	 * The default implementation of this method calls
	 * {@link #handleRemove(int, Object)} with the old element, then
	 * {@link #handleAdd(int, Object)} with the new element. Clients which are
	 * interested in recognizing "replaces" in a list (i.e. calls to
	 * {@link List#set(int, Object)}) should override this method.
	 * 
	 * @param index
	 *            the index where the element was replaced.
	 * @param oldElement
	 *            the element being replaced.
	 * @param newElement
	 *            the element that replaced oldElement.
	 * @see List#set(int, Object)
	 */
	public void handleReplace(int index, Object oldElement, Object newElement) {
		handleRemove(index, oldElement);
		handleAdd(index, newElement);
	}
}

Back to the top