You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2021/01/05 14:48:21 UTC

svn commit: r1885147 - /turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java

Author: tv
Date: Tue Jan  5 14:48:21 2021
New Revision: 1885147

URL: http://svn.apache.org/viewvc?rev=1885147&view=rev
Log:
Add reasonable hashCode(), equals() and toString() methods

Modified:
    turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java

Modified: turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java?rev=1885147&r1=1885146&r2=1885147&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/util/uri/URIParam.java Tue Jan  5 14:48:21 2021
@@ -1,6 +1,5 @@
 package org.apache.turbine.util.uri;
 
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -20,6 +19,7 @@ package org.apache.turbine.util.uri;
  * under the License.
  */
 
+import java.util.Objects;
 
 import org.apache.commons.lang3.StringUtils;
 
@@ -73,4 +73,40 @@ public class URIParam
     {
         return value;
     }
+
+    /**
+     * Calculate hash code based on field values
+     */
+    @Override
+    public int hashCode()
+    {
+        return Objects.hash(key, value);
+    }
+
+    /**
+     * Calculate equality based on field values
+     */
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        URIParam other = (URIParam) obj;
+
+        return Objects.equals(getKey(), other.getKey()) ||
+                Objects.equals(getValue(), other.getValue());
+    }
+
+    /**
+     * Provide a string representation of the object
+     */
+    @Override
+    public String toString()
+    {
+        return "URIParam [key=" + key + ", value=" + value + "]";
+    }
 }