Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2021-01-16 16:13:48 +0000
committerMickael Istria2021-01-20 07:33:02 +0000
commit8419e5d0ef13c10ee33e73c0f332d0fa0145e034 (patch)
treebfdb69cabdda6e3f6bc83672ef159f4a81d0791f
parent0deabf27e64cd8fef5187ba089485d9d3624fca9 (diff)
downloadeclipse.platform.text-8419e5d0ef13c10ee33e73c0f332d0fa0145e034.tar.gz
eclipse.platform.text-8419e5d0ef13c10ee33e73c0f332d0fa0145e034.tar.xz
eclipse.platform.text-8419e5d0ef13c10ee33e73c0f332d0fa0145e034.zip
dogfooding Objects.hash and Objects.equals
Use Objects.hash() Use Objects.equals() in the equals method implementation Change-Id: I5c86208e25236b2db8c306f6a3a1c676991ae05e Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java9
-rw-r--r--org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/LineItem.java14
-rwxr-xr-xorg.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/rulers/RulerColumnDescriptor.java12
3 files changed, 12 insertions, 23 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java
index 25f18e08d..29462b484 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/revisions/Hunk.java
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.jface.internal.text.revisions;
+import java.util.Objects;
+
import org.eclipse.core.runtime.Assert;
/**
@@ -58,12 +60,7 @@ public final class Hunk {
@Override
public int hashCode() {
- final int prime= 31;
- int result= 1;
- result= prime * result + changed;
- result= prime * result + delta;
- result= prime * result + line;
- return result;
+ return Objects.hash(changed, delta, line);
}
@Override
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/LineItem.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/LineItem.java
index 018cbae85..8088577a7 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/LineItem.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/LineItem.java
@@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.text.quicksearch.internal.core;
+import java.util.Objects;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.search.internal.ui.text.FileMatch;
@@ -56,11 +58,7 @@ public class LineItem {
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((f == null) ? 0 : f.hashCode());
- result = prime * result + lineNumber;
- return result;
+ return Objects.hash(f, lineNumber);
}
@Override
@@ -72,11 +70,9 @@ public class LineItem {
if (getClass() != obj.getClass())
return false;
LineItem other = (LineItem) obj;
- if (f == null) {
- if (other.f != null)
- return false;
- } else if (!f.equals(other.f))
+ if (!Objects.equals(f, other.f)) {
return false;
+ }
if (lineNumber != other.lineNumber)
return false;
return true;
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/rulers/RulerColumnDescriptor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/rulers/RulerColumnDescriptor.java
index 7a6c6f9e1..246983ef0 100755
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/rulers/RulerColumnDescriptor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/rulers/RulerColumnDescriptor.java
@@ -14,6 +14,7 @@
package org.eclipse.ui.texteditor.rulers;
import java.net.URL;
+import java.util.Objects;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
@@ -270,10 +271,7 @@ public final class RulerColumnDescriptor {
@Override
public int hashCode() {
- final int prime= 31;
- int result= 1;
- result= prime * result + ((fId == null) ? 0 : fId.hashCode());
- return result;
+ return Objects.hash(fId);
}
@Override
@@ -285,11 +283,9 @@ public final class RulerColumnDescriptor {
if (getClass() != obj.getClass())
return false;
final RulerColumnDescriptor other= (RulerColumnDescriptor) obj;
- if (fId == null) {
- if (other.fId != null)
- return false;
- } else if (!fId.equals(other.fId))
+ if (!Objects.equals(fId, other.fId)) {
return false;
+ }
return true;
}

Back to the top