summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/components/MemoryComponentRepository.java
blob: bba0867a4d00244f0ecdff58d61558d5efcd1e55 (plain)
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
package bjc.utils.components;

import bjc.funcdata.IMap;

/**
 * A repository of components stored in memory.
 *
 * @author bjculkin
 *
 * @param <ComponentType>
 *                        The type of component stored in the repository.
 */
public class MemoryComponentRepository<ComponentType extends IDescribedComponent>
		implements IComponentRepository<ComponentType> {
	private final IMap<String, ComponentType> repo;

	private final String source;

	/**
	 * Create a new memory component repository.
	 *
	 * @param repo
	 *             The set of components to use.
	 */
	public MemoryComponentRepository(IMap<String, ComponentType> repo) {
		this(repo, "memory");
	}

	/**
	 * Create a new memory component repository.
	 *
	 * @param repo
	 *               The set of components to use.
	 * @param source
	 *               Where the components came from.
	 */
	public MemoryComponentRepository(IMap<String, ComponentType> repo, String source) {
		this.repo = repo;

		this.source = source;
	}

	@Override
	public IMap<String, ComponentType> getAll() {
		return repo;
	}

	@Override
	public ComponentType getByName(String name) {
		return repo.get(name).get();
	}

	@Override
	public String getSource() {
		return source;
	}
}