diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-17 19:28:59 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-17 19:28:59 -0400 |
| commit | 5832ef0286430d04484b70d49c73e081a80ec9c7 (patch) | |
| tree | 04ab56561978c14415f71b934f7d8a3aaa1a037e /BJC-Utils2/src/main/java/bjc/utils/data/Option.java | |
| parent | c8593896ba0d93c9512a71c2e70d1d503627b1b0 (diff) | |
Add more toString/hashCode/equals
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/Option.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/data/Option.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java index 052e78a..fa25b54 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/Option.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/Option.java @@ -60,4 +60,44 @@ public class Option<ContainedType> implements IHolder<ContainedType> { return unwrapper.apply(held); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("Option ["); + + if(held != null) { + builder.append("held="); + builder.append(held); + } + + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + + int result = 1; + result = prime * result + ((held == null) ? 0 : held.hashCode()); + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) return true; + if(obj == null) return false; + if(getClass() != obj.getClass()) return false; + + Option<?> other = (Option<?>) obj; + + if(held == null) { + if(other.held != null) return false; + } else if(!held.equals(other.held)) return false; + + return true; + } } |
