Skip to main content
summaryrefslogtreecommitdiffstats
blob: b98c42303a84684db2dee68369685690fb36ffa2 (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
91
92
/*******************************************************************************
 * Copyright (c) 2009 Oracle. 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:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.utility.internal.iterables;

import org.eclipse.jpt.common.utility.internal.iterators.CloneListIterator;

/**
 * Pull together mutator state and behavior for subclasses.
 * 
 * @param <E> the type of elements returned by the list iterable's list iterator
 * 
 * @see SnapshotCloneListIterable
 * @see LiveCloneListIterable
 */
public abstract class CloneListIterable<E>
	implements ListIterable<E>
{
	final CloneListIterator.Mutator<E> mutator;


	// ********** constructors **********

	protected CloneListIterable() {
		super();
		this.mutator = this.buildDefaultMutator();
	}

	protected CloneListIterable(CloneListIterator.Mutator<E> mutator) {
		super();
		this.mutator = mutator;
	}

	protected CloneListIterator.Mutator<E> buildDefaultMutator() {
		return new DefaultMutator();
	}


	// ********** default mutations **********

	/**
	 * At the specified index, add the specified element to the original list.
	 * <p>
	 * This method can be overridden by a subclass as an
	 * alternative to building a {@link CloneListIterator.Mutator}.
	 */
	protected void add(@SuppressWarnings("unused") int index, @SuppressWarnings("unused") E element) {
		throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
	}

	/**
	 * Remove the element at the specified index from the original list.
	 * <p>
	 * This method can be overridden by a subclass as an
	 * alternative to building a {@link CloneListIterator.Mutator}.
	 */
	protected void remove(@SuppressWarnings("unused") int index) {
		throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
	}

	/**
	 * At the specified index, set the specified element in the original list.
	 * <p>
	 * This method can be overridden by a subclass as an
	 * alternative to building a {@link CloneListIterator.Mutator}.
	 */
	protected void set(@SuppressWarnings("unused") int index, @SuppressWarnings("unused") E element) {
		throw new RuntimeException("This method was not overridden."); //$NON-NLS-1$
	}


	//********** default mutator **********

	protected class DefaultMutator implements CloneListIterator.Mutator<E> {
		public void add(int index, E element) {
			CloneListIterable.this.add(index, element);
		}
		public void remove(int index) {
			CloneListIterable.this.remove(index);
		}
		public void set(int index, E element) {
			CloneListIterable.this.set(index, element);
		}
	}

}

Back to the top