Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6db0332a1fff67158dfe99722ac4f4eb1eac6e25 (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
/*******************************************************************************
 * Copyright (c) 2013 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0, which accompanies this distribution
 * and is available at https://www.eclipse.org/legal/epl-2.0/.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.utility.internal.closure;

import org.eclipse.jpt.common.utility.closure.Closure;
import org.eclipse.jpt.common.utility.factory.Factory;
import org.eclipse.jpt.common.utility.internal.ObjectTools;

/**
 * Adapt a {@link Factory} to the {@link Closure} interface.
 * The closure's argument and the factory's output are ignored.
 * This really only useful for a factory that has side-effects.
 * 
 * @param <A> the type of the object passed to the closure;
 *     ignored
 * 
 * @see org.eclipse.jpt.common.utility.internal.factory.ClosureFactory
 */
public class FactoryClosure<A>
	implements Closure<A>
{
	private final Factory<?> factory;


	public FactoryClosure(Factory<?> factory) {
		super();
		if (factory == null) {
			throw new NullPointerException();
		}
		this.factory = factory;
	}

	public void execute(A argument) {
		this.factory.create();
	}

	@Override
	public String toString() {
		return ObjectTools.toString(this, this.factory);
	}
}

Back to the top