From 7f59d0b9de4536705b3122cb5a85d9c9f85846a3 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Fri, 17 Mar 2017 08:52:13 -0400 Subject: Add toString/equals/hashCode/compareTo part 1 Adds utility methods to classes that need them. This covers the cli & component packages. --- .../components/ComponentDescriptionState.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java index 02e003a..d6fbc5a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescriptionState.java @@ -67,4 +67,78 @@ public class ComponentDescriptionState { public ComponentDescription toDescription() { return new ComponentDescription(name, author, description, version); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + ((author == null) ? 0 : author.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + version; + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + ComponentDescriptionState other = (ComponentDescriptionState) obj; + + if(author == null) { + if(other.author != null) return false; + } else if(!author.equals(other.author)) return false; + + if(description == null) { + if(other.description != null) return false; + } else if(!description.equals(other.description)) return false; + + if(name == null) { + if(other.name != null) return false; + } else if(!name.equals(other.name)) return false; + + if(version != other.version) return false; + + return true; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ComponentDescriptionState ["); + + if(name != null) { + builder.append("name="); + builder.append(name); + builder.append(", "); + } + + if(description != null) { + builder.append("description="); + builder.append(description); + builder.append(", "); + } + + if(author != null) { + builder.append("author="); + builder.append(author); + builder.append(", "); + } + + builder.append("version="); + builder.append(version); + builder.append("]"); + + return builder.toString(); + } + } -- cgit v1.2.3