From 0e422a81ceb3667246f545b1435821fbe421e8f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sat, 27 Oct 2018 14:01:53 -0400 Subject: [PATCH] Added equals Signed-off-by: Emmanuel Bigeon --- .../net/bigeon/gclc/tools/ConstantString.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java b/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java index 8ab2864..d6956bd 100644 --- a/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java +++ b/gclc/src/main/java/net/bigeon/gclc/tools/ConstantString.java @@ -77,7 +77,7 @@ public class ConstantString implements StringProvider { /** Create a provider for a string. * * @param string the string */ - public ConstantString(String string) { + public ConstantString(final String string) { this.string = string; } @@ -87,4 +87,38 @@ public class ConstantString implements StringProvider { public String apply() { return string; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((string == null) ? 0 : string.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) */ + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ConstantString other = (ConstantString) obj; + if (string == null) { + if (other.string != null) { + return false; + } + } else if (!string.equals(other.string)) { + return false; + } + return true; + } }