diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-30 09:34:34 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-30 09:34:34 -0400 |
| commit | 3a80c78e801cb6227f058db22e87dc58fd0fd7f2 (patch) | |
| tree | beaa483da2afe26d6897effc3b1780ee754b2a7b /BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java | |
| parent | 7ef3a2d28fd731a0f378b07a7d7f0c04911a3e8f (diff) | |
Added error-checking and input validation
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java index 3cb16b4..a946cae 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java @@ -35,15 +35,37 @@ public class ComponentDescription implements IDescribedComponent { * 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; @@ -63,4 +85,9 @@ public class ComponentDescription implements IDescribedComponent { public int getVersion() { return version; } + + @Override + public String toString() { + return name + " component v" + version + ", written by " + author; + } } |
