From 3a80c78e801cb6227f058db22e87dc58fd0fd7f2 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 30 Mar 2016 09:34:34 -0400 Subject: Added error-checking and input validation --- .../bjc/utils/components/ComponentDescription.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java') 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; + } } -- cgit v1.2.3