diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/components')
6 files changed, 166 insertions, 13 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 13132ed..b750848 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/ComponentDescription.java @@ -82,4 +82,52 @@ public class ComponentDescription implements IDescribedComponent { public String toString() { return name + " component v" + version + ", written by " + author; } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @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; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + ComponentDescription other = (ComponentDescription) 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; + } } 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(); + } + } diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java index d69b794..6fd6177 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/FileComponentRepository.java @@ -148,4 +148,30 @@ public class FileComponentRepository<ComponentType extends IDescribedComponent> + pth.toString() + ". This component will not be loaded"); } } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("FileComponentRepository ["); + + if(components != null) { + builder.append("components="); + builder.append(components); + builder.append(", "); + } + + if(sourceDirectory != null) { + builder.append("sourceDirectory="); + builder.append(sourceDirectory); + } + + builder.append("]"); + + return builder.toString(); + } }
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java index 5ef65ee..6ee51f3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java +++ b/BJC-Utils2/src/main/java/bjc/utils/components/IComponentRepository.java @@ -32,7 +32,7 @@ public interface IComponentRepository<ComponentType extends IDescribedComponent> public ComponentType getByName(String name); /** - * Get a list of all the registered componets + * Get a list of all the registered components * * @return A list of all the registered components */ 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<IDescribedComponent>{ /** * 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 diff --git a/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java deleted file mode 100644 index 37a9e84..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/components/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -/** - * This package contains utilities for components - * - * @author ben - * - */ -package bjc.utils.components; |
