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. --- .../bjc/utils/components/IDescribedComponent.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java b/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java index a397bbc..f231924 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IDescribedComponent.java @@ -7,7 +7,7 @@ package bjc.utils.components; * @author ben * */ -public interface IDescribedComponent { +public interface IDescribedComponent extends Comparable{ /** * Get the author of this component * @@ -15,7 +15,7 @@ public interface IDescribedComponent { * * @return The author of the component */ - public default String getAuthor() { + default String getAuthor() { return "Anonymous"; } @@ -27,7 +27,7 @@ public interface IDescribedComponent { * * @return The description of the component */ - public default String getDescription() { + default String getDescription() { return "No description provided."; } @@ -38,7 +38,7 @@ public interface IDescribedComponent { * * @return The name of the component */ - public String getName(); + String getName(); /** * Get the version of this component @@ -47,7 +47,19 @@ public interface IDescribedComponent { * * @return The version of this component */ - public default int getVersion() { + default int getVersion() { return 1; } + + + @Override + default int compareTo(IDescribedComponent o) { + int res = getName().compareTo(o.getName()); + + if(res == 0) { + res = getVersion() - o.getVersion(); + } + + return res; + } } \ No newline at end of file -- cgit v1.2.3