summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java
blob: a946cae206709de1e19d63baa1bd7b41228a4569 (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
86
87
88
89
90
91
92
93
package bjc.utils.components;

/**
 * Generic implementation of a description for a component
 * 
 * @author ben
 *
 */
public class ComponentDescription implements IDescribedComponent {
	/**
	 * 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 name, author or description is null, or 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;
	}

	private static void sanityCheckArgs(String name, String author,
			String description, int version) {
		if (name == null) {
			throw new IllegalArgumentException(
					"Component name can't be null");
		} else if (author == null) {
			throw new IllegalArgumentException(
					"Component author can't be null");
		} else if (description == null) {
			throw new IllegalArgumentException(
					"Component description can't be null");
		} else if (version < 0) {
			throw new IllegalArgumentException(
					"Component version must be greater than 0");
		}
	}

	@Override
	public String getAuthor() {
		return author;
	}

	@Override
	public String 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;
	}
}