summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
blob: 13132eda1373f9829619d4724beca8ead952cabe (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
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
package bjc.utils.components;

/**
 * Generic implementation of a description for a component
 *
 * @author ben
 *
 */
public class ComponentDescription implements IDescribedComponent {
	private static void sanityCheckArgs(String name, String author, String description, int version) {
		if(name == null)
			throw new NullPointerException("Component name can't be null");
		else if(version <= 0) throw new IllegalArgumentException("Component version must be greater than 0");
	}

	/**
	 * The author of the component
	 */
	private String	author;
	/**
	 * The description of the component
	 */
	private String	description;
	/**
	 * The name of the component
	 */
	private String	name;

	/**
	 * The version of the component
	 */
	private int version;

	/**
	 * Create a new component description
	 *
	 * @param name
	 *                The name of the component
	 * @param author
	 *                The author of the component
	 * @param description
	 *                The description of the component
	 * @param version
	 *                The version of the component
	 * @throws IllegalArgumentException
	 *                 thrown if version is less than 1
	 */
	public ComponentDescription(String name, String author, String description, int version) {
		sanityCheckArgs(name, author, description, version);

		this.name = name;
		this.author = author;
		this.description = description;
		this.version = version;
	}

	@Override
	public String getAuthor() {
		if(author == null) return IDescribedComponent.super.getAuthor();

		return author;
	}

	@Override
	public String getDescription() {
		if(description == null) return IDescribedComponent.super.getDescription();

		return description;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public int getVersion() {
		return version;
	}

	@Override
	public String toString() {
		return name + " component v" + version + ", written by " + author;
	}
}