diff options
| author | Mickael Istria | 2019-05-03 08:50:33 +0000 |
|---|---|---|
| committer | Mickael Istria | 2019-05-09 10:17:54 +0000 |
| commit | dfb72e8983e1e1998acd00e1839a26312f970f72 (patch) | |
| tree | c753e2caa598d3e2defec15113b553304a605d5e | |
| parent | 0a4c673c647bd9a6df438498dfe7d1d6b182547c (diff) | |
| download | eclipse.platform.ui-dfb72e8983e1e1998acd00e1839a26312f970f72.tar.gz eclipse.platform.ui-dfb72e8983e1e1998acd00e1839a26312f970f72.tar.xz eclipse.platform.ui-dfb72e8983e1e1998acd00e1839a26312f970f72.zip | |
Bug 546994 - Improve some equals/hashCode methods using Objects util
Change-Id: I5858f198bfa3f82dfa63abe251f007de9d40e870
Signed-off-by: Mickael Istria <mistria@redhat.com>
123 files changed, 512 insertions, 1674 deletions
diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Category.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Category.java index 88f8db9cd18..1dab9817278 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Category.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Category.java @@ -16,9 +16,9 @@ package org.eclipse.core.commands; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.Objects; import org.eclipse.core.commands.common.NamedHandleObject; -import org.eclipse.core.internal.commands.util.Util; /** * <p> @@ -94,10 +94,10 @@ public final class Category extends NamedHandleObject { final boolean definedChanged = !this.defined; this.defined = true; - final boolean nameChanged = !Util.equals(this.name, name); + final boolean nameChanged = !Objects.equals(this.name, name); this.name = name; - final boolean descriptionChanged = !Util.equals(this.description, description); + final boolean descriptionChanged = !Objects.equals(this.description, description); this.description = description; fireCategoryChanged(new CategoryEvent(this, definedChanged, descriptionChanged, nameChanged)); diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Command.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Command.java index 85f95b77146..8ef6e57e86d 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Command.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Command.java @@ -17,6 +17,7 @@ import java.io.BufferedWriter; import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; +import java.util.Objects; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.internal.util.Tracing; @@ -356,25 +357,25 @@ public final class Command extends NamedHandleObjectWithState implements Compara final boolean definedChanged = !this.defined; this.defined = true; - final boolean nameChanged = !Util.equals(this.name, name); + final boolean nameChanged = !Objects.equals(this.name, name); this.name = name; - final boolean descriptionChanged = !Util.equals(this.description, + final boolean descriptionChanged = !Objects.equals(this.description, description); this.description = description; - final boolean categoryChanged = !Util.equals(this.category, category); + final boolean categoryChanged = !Objects.equals(this.category, category); this.category = category; - final boolean parametersChanged = !Util.equals(this.parameters, + final boolean parametersChanged = !Objects.equals(this.parameters, parameters); this.parameters = parameters; - final boolean returnTypeChanged = !Util.equals(this.returnType, + final boolean returnTypeChanged = !Objects.equals(this.returnType, returnType); this.returnType = returnType; - final boolean helpContextIdChanged = !Util.equals(this.helpContextId, + final boolean helpContextIdChanged = !Objects.equals(this.helpContextId, helpContextId); this.helpContextId = helpContextId; @@ -948,7 +949,7 @@ public final class Command extends NamedHandleObjectWithState implements Compara * otherwise. */ public boolean setHandler(final IHandler handler) { - if (Util.equals(handler, this.handler)) { + if (Objects.equals(handler, this.handler)) { return false; } diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Parameterization.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Parameterization.java index d36b18312ea..c520470c45c 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Parameterization.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/Parameterization.java @@ -17,6 +17,7 @@ package org.eclipse.core.commands; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import org.eclipse.core.internal.commands.util.Util; @@ -94,11 +95,11 @@ public final class Parameterization { } final Parameterization parameterization = (Parameterization) object; - if (!(Util.equals(this.parameter.getId(), parameterization.parameter.getId()))) { + if (!(Objects.equals(this.parameter.getId(), parameterization.parameter.getId()))) { return false; } - return Util.equals(this.value, parameterization.value); + return Objects.equals(this.value, parameterization.value); } /** @@ -135,7 +136,7 @@ public final class Parameterization { while (parameterValueItr.hasNext()) { final Entry<?, ?> entry = (Entry<?, ?>) parameterValueItr.next(); final String currentValue = (String) entry.getValue(); - if (Util.equals(value, currentValue)) { + if (Objects.equals(value, currentValue)) { returnValue = (String) entry.getKey(); break; } @@ -151,8 +152,8 @@ public final class Parameterization { @Override public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(parameter); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(value); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(parameter); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(value); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/ParameterizedCommand.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/ParameterizedCommand.java index d6282e672f6..4430ba394d5 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/ParameterizedCommand.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/ParameterizedCommand.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.internal.commands.util.Util; @@ -430,11 +431,11 @@ public final class ParameterizedCommand implements Comparable { } final ParameterizedCommand command = (ParameterizedCommand) object; - if (!Util.equals(this.command, command.command)) { + if (!Objects.equals(this.command, command.command)) { return false; } - return Util.equals(this.parameterizations, command.parameterizations); + return Objects.equals(this.parameterizations, command.parameterizations); } /** @@ -607,11 +608,11 @@ public final class ParameterizedCommand implements Comparable { @Override public int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(command); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(command); hashCode = hashCode * HASH_FACTOR; if (parameterizations != null) { for (Parameterization parameterization : parameterizations) { - hashCode += Util.hashCode(parameterization); + hashCode += Objects.hashCode(parameterization); } } if (hashCode == HASH_CODE_NOT_COMPUTED) { diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/State.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/State.java index 3092909ab4e..ae17716b2f5 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/State.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/State.java @@ -14,8 +14,9 @@ package org.eclipse.core.commands; +import java.util.Objects; + import org.eclipse.core.commands.common.EventManager; -import org.eclipse.core.internal.commands.util.Util; /** * <p> @@ -129,7 +130,7 @@ public class State extends EventManager { * The value to set; may be anything. */ public void setValue(final Object value) { - if (!Util.equals(this.value, value)) { + if (!Objects.equals(this.value, value)) { final Object oldValue = this.value; this.value = value; fireStateChanged(oldValue); diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/common/HandleObject.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/common/HandleObject.java index ed23f8c1773..d950302e511 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/common/HandleObject.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/common/HandleObject.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.core.commands.common; -import org.eclipse.core.internal.commands.util.Util; +import java.util.Objects; /** * <p> @@ -124,7 +124,7 @@ public abstract class HandleObject extends EventManager implements // Check each property in turn. final HandleObject handle= (HandleObject) object; - return Util.equals(id, handle.id) + return Objects.equals(id, handle.id) && (this.getClass() == handle.getClass()); } @@ -141,7 +141,7 @@ public abstract class HandleObject extends EventManager implements @Override public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(id); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(id); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/Context.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/Context.java index 8d84a094be0..36dd9f2f28f 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/Context.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/Context.java @@ -16,6 +16,7 @@ package org.eclipse.core.commands.contexts; import java.util.HashSet; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import org.eclipse.core.commands.common.NamedHandleObject; @@ -143,14 +144,14 @@ public final class Context extends NamedHandleObject implements Comparable { final boolean definedChanged = !this.defined; this.defined = true; - final boolean nameChanged = !Util.equals(this.name, name); + final boolean nameChanged = !Objects.equals(this.name, name); this.name = name; - final boolean descriptionChanged = !Util.equals(this.description, + final boolean descriptionChanged = !Objects.equals(this.description, description); this.description = description; - final boolean parentIdChanged = !Util.equals(this.parentId, parentId); + final boolean parentIdChanged = !Objects.equals(this.parentId, parentId); this.parentId = parentId; fireContextChanged(new ContextEvent(this, definedChanged, nameChanged, descriptionChanged, parentIdChanged)); diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/ContextManager.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/ContextManager.java index 156785bb10c..7914e9999f8 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/ContextManager.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/commands/contexts/ContextManager.java @@ -16,11 +16,11 @@ package org.eclipse.core.commands.contexts; import java.util.Collections; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import org.eclipse.core.commands.common.HandleObjectManager; import org.eclipse.core.commands.internal.util.Tracing; -import org.eclipse.core.internal.commands.util.Util; /** * <p> @@ -272,7 +272,7 @@ public final class ContextManager extends HandleObjectManager implements IContex */ @SuppressWarnings("unchecked") public final void setActiveContextIds(@SuppressWarnings("rawtypes") final Set activeContextIds) { - if (Util.equals(this.activeContextIds, activeContextIds)) { + if (Objects.equals(this.activeContextIds, activeContextIds)) { return; } diff --git a/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java b/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java index f21ff2bec47..f375335d89b 100644 --- a/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java +++ b/bundles/org.eclipse.core.commands/src/org/eclipse/core/internal/commands/util/Util.java @@ -22,10 +22,6 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.SortedMap; -import java.util.SortedSet; -import java.util.TreeMap; -import java.util.TreeSet; import org.eclipse.core.commands.Command; @@ -37,19 +33,6 @@ import org.eclipse.core.commands.Command; public final class Util { /** - * A shared, unmodifiable, empty, sorted map. This value is guaranteed to - * always be the same. - */ - public static final SortedMap<?, ?> EMPTY_SORTED_MAP = Collections - .unmodifiableSortedMap(new TreeMap<>()); - - /** - * A shared, unmodifiable, empty, sorted set. This value is guaranteed to - * always be the same. - */ - public static final SortedSet<?> EMPTY_SORTED_SET = Collections.unmodifiableSortedSet(new TreeSet<>()); - - /** * A shared, zero-length string -- for avoiding non-externalized string * tags. This value is guaranteed to always be the same. */ @@ -172,98 +155,6 @@ public final class Util { } /** - * Decides whether two booleans are equal. - * - * @param left - * The first boolean to compare; may be <code>null</code>. - * @param right - * The second boolean to compare; may be <code>null</code>. - * @return <code>true</code> if the booleans are equal; <code>false</code> - * otherwise. - */ - public static final boolean equals(final boolean left, final boolean right) { - return left == right; - } - - /** - * Decides whether two objects are equal -- defending against - * <code>null</code>. - * - * @param left - * The first object to compare; may be <code>null</code>. - * @param right - * The second object to compare; may be <code>null</code>. - * @return <code>true</code> if the objects are equals; <code>false</code> - * otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left.equals(right)); - } - - /** - * Tests whether two arrays of objects are equal to each other. The arrays - * must not be <code>null</code>, but their elements may be - * <code>null</code>. - * - * @param leftArray - * The left array to compare; may be <code>null</code>, and - * may be empty and may contain <code>null</code> elements. - * @param rightArray - * The right array to compare; may be <code>null</code>, and - * may be empty and may contain <code>null</code> elements. - * @return <code>true</code> if the arrays are equal length and the - * elements at the same position are equal; <code>false</code> - * otherwise. - */ - public static final boolean equals(final Object[] leftArray, final Object[] rightArray) { - if (leftArray == null) { - return (rightArray == null); - } else if (rightArray == null) { - return false; - } - - if (leftArray.length != rightArray.length) { - return false; - } - - for (int i = 0; i < leftArray.length; i++) { - final Object left = leftArray[i]; - final Object right = rightArray[i]; - final boolean equal = (left == null) ? (right == null) : (left.equals(right)); - if (!equal) { - return false; - } - } - - return true; - } - - /** - * Computes the hash code for an integer. - * - * @param i - * The integer for which a hash code should be computed. - * @return <code>i</code>. - */ - public static final int hashCode(final int i) { - return i; - } - - /** - * Computes the hash code for an object, but with defense against - * <code>null</code>. - * - * @param object - * The object for which a hash code is needed; may be - * <code>null</code>. - * @return The hash code for <code>object</code>; or <code>0</code> if - * <code>object</code> is <code>null</code>. - */ - public static final int hashCode(final Object object) { - return object != null ? object.hashCode() : 0; - } - - /** * Makes a type-safe copy of the given map. This method should be used when * a map is crossing an API boundary (i.e., from a hostile plug-in into * internal code, or vice versa). diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/DecoratingObservable.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/DecoratingObservable.java index 8cc4658f410..07fe166d4bd 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/DecoratingObservable.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/DecoratingObservable.java @@ -16,7 +16,7 @@ package org.eclipse.core.databinding.observable; -import org.eclipse.core.internal.databinding.observable.Util; +import java.util.Objects; /** * An observable which decorates another observable @@ -102,9 +102,9 @@ public class DecoratingObservable extends AbstractObservable implements return false; if (getClass() == obj.getClass()) { DecoratingObservable other = (DecoratingObservable) obj; - return Util.equals(this.decorated, other.decorated); + return Objects.equals(this.decorated, other.decorated); } - return Util.equals(decorated, obj); + return Objects.equals(decorated, obj); } @Override diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java index 12924e32da4..e33233e841a 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Diffs.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.list.ListDiff; @@ -31,7 +32,6 @@ import org.eclipse.core.databinding.observable.list.ListDiffEntry; import org.eclipse.core.databinding.observable.map.MapDiff; import org.eclipse.core.databinding.observable.set.SetDiff; import org.eclipse.core.databinding.observable.value.ValueDiff; -import org.eclipse.core.internal.databinding.observable.Util; /** * @since 1.0 @@ -362,31 +362,27 @@ public class Diffs { * Checks whether the two objects are <code>null</code> -- allowing for * <code>null</code>. * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. + * @param left The left object to compare; may be <code>null</code>. + * @param right The right object to compare; may be <code>null</code>. * @return <code>true</code> if the two objects are equivalent; * <code>false</code> otherwise. + * @deprecated Use {@link Objects#equals(Object, Object)} instead */ + @Deprecated public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); + return Objects.equals(left, right); } /** - * Returns a {@link SetDiff} describing the change between the specified old - * and new set states. + * Returns a {@link SetDiff} describing the change between the specified old and + * new set states. * - * @param <E> - * the set element type + * @param <E> the set element type * - * @param oldSet - * the old set state - * @param newSet - * the new set state - * @return a {@link SetDiff} describing the change between the specified old - * and new set states. + * @param oldSet the old set state + * @param newSet the new set state + * @return a {@link SetDiff} describing the change between the specified old and + * new set states. */ public static <E> SetDiff<E> computeSetDiff(Set<? extends E> oldSet, Set<? extends E> newSet) { Set<E> additions = new HashSet<E>(newSet); @@ -466,7 +462,7 @@ public class Diffs { // potentially changed key since it is in oldMap and newMap V oldValue = oldEntry.getValue(); V newValue = newMap.get(oldKey); - if (!Util.equals(oldValue, newValue)) { + if (!Objects.equals(oldValue, newValue)) { changedKeys.add(oldKey); oldValues.put(oldKey, oldValue); newValues.put(oldKey, newValue); diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java index 403d4b5ae5a..f5f5d5c1505 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/ListDiff.java @@ -19,9 +19,9 @@ package org.eclipse.core.databinding.observable.list; import java.util.AbstractList; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.eclipse.core.databinding.observable.IDiff; -import org.eclipse.core.internal.databinding.observable.Util; /** * Object describing a diff between two lists. @@ -138,7 +138,7 @@ public abstract class ListDiff<E> implements IDiff { continue; } - if (Util.equals(removeElem, addElem)) { + if (Objects.equals(removeElem, addElem)) { visitor.handleMove(removePos, addPos, elem); i++; continue; diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/MultiList.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/MultiList.java index 8fc349b6322..2b36e1ee972 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/MultiList.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/list/MultiList.java @@ -332,11 +332,7 @@ public class MultiList<E> extends AbstractObservableList<E> { @Override public int hashCode() { getterCalled(); - int result = 1; - for (IObservableList<E> list : lists) { - result = result * 31 + list.hashCode(); - } - return result; + return lists.hashCode(); } @Override diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidiObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidiObservableMap.java index cec136e666e..59b75abc020 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidiObservableMap.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/BidiObservableMap.java @@ -20,10 +20,10 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.Util; /** * An @@ -191,7 +191,7 @@ public class BidiObservableMap<K, V> extends DecoratingObservableMap<K, V> { private Set<K> findKeys(Object value) { Set<K> keys = new HashSet<>(); for (Entry<K, V> entry : entrySet()) { - if (Util.equals(entry.getValue(), value)) + if (Objects.equals(entry.getValue(), value)) keys.add(entry.getKey()); } return keys; diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java index 8abda811156..1cc39e15e0e 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/MapDiff.java @@ -23,10 +23,10 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.IDiff; -import org.eclipse.core.internal.databinding.observable.Util; /** * @param <K> @@ -237,19 +237,14 @@ public abstract class MapDiff<K, V> implements IDiff { if (!(obj instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) obj; - return Util.equals(this.getKey(), that.getKey()) && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(this.getKey(), that.getKey()) && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { - Object key = getKey(); - Object value = getValue(); - return hash(key) ^ hash(value); + return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue()); } - private int hash(Object key) { - return key == null ? 0 : key.hashCode(); - } } private static class MapEntryWrapper<K, V> extends AbstractMapEntry<K, V> { diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java index 29729609827..745913cbb92 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/map/WritableMap.java @@ -21,11 +21,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.Util; /** * @@ -118,7 +118,7 @@ public class WritableMap<K, V> extends ObservableMap<K, V> { boolean containedKeyAfter = wrappedMap.containsKey(key); if (containedKeyBefore != containedKeyAfter - || !Util.equals(result, value)) { + || !Objects.equals(result, value)) { MapDiff<K, V> diff; if (containedKeyBefore) { if (containedKeyAfter) { diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java index 8e6496c5e75..902f1a16b19 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/AbstractVetoableValue.java @@ -16,9 +16,10 @@ *******************************************************************************/ package org.eclipse.core.databinding.observable.value; +import java.util.Objects; + import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.Util; /** * @@ -60,7 +61,7 @@ public abstract class AbstractVetoableValue<T> extends } doSetApprovedValue(value); - if (!Util.equals(diff.getOldValue(), diff.getNewValue())) { + if (!Objects.equals(diff.getOldValue(), diff.getNewValue())) { fireValueChange(diff); } } diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DateAndTimeObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DateAndTimeObservableValue.java index c483b3b9643..ffb8cf65ec3 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DateAndTimeObservableValue.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DateAndTimeObservableValue.java @@ -18,6 +18,7 @@ package org.eclipse.core.databinding.observable.value; import java.util.Calendar; import java.util.Date; +import java.util.Objects; import org.eclipse.core.databinding.observable.ChangeEvent; import org.eclipse.core.databinding.observable.Diffs; @@ -27,7 +28,6 @@ import org.eclipse.core.databinding.observable.IDisposeListener; import org.eclipse.core.databinding.observable.IStaleListener; import org.eclipse.core.databinding.observable.ObservableTracker; import org.eclipse.core.databinding.observable.StaleEvent; -import org.eclipse.core.internal.databinding.observable.Util; import org.eclipse.core.runtime.Assert; /** @@ -183,7 +183,7 @@ public class DateAndTimeObservableValue extends AbstractObservableValue<Date> { if (hasListeners()) { Date oldValue = cachedValue; Date newValue = cachedValue = doGetValue(); - if (!Util.equals(oldValue, newValue)) + if (!Objects.equals(oldValue, newValue)) fireValueChange(Diffs.createValueDiff(oldValue, newValue)); } } diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java index eafcda49486..951461eea2c 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/DuplexingObservableValue.java @@ -18,13 +18,13 @@ package org.eclipse.core.databinding.observable.value; import java.util.Collection; import java.util.Iterator; +import java.util.Objects; import org.eclipse.core.databinding.observable.ChangeEvent; import org.eclipse.core.databinding.observable.IChangeListener; import org.eclipse.core.databinding.observable.IStaleListener; import org.eclipse.core.databinding.observable.StaleEvent; import org.eclipse.core.databinding.observable.list.IObservableList; -import org.eclipse.core.internal.databinding.observable.Util; /** * @param <T> @@ -59,7 +59,7 @@ public abstract class DuplexingObservableValue<T> extends AbstractObservableValu Iterator<T> it = elements.iterator(); T first = it.next(); while (it.hasNext()) - if (!Util.equals(first, it.next())) + if (!Objects.equals(first, it.next())) return multiValue; return first; } diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/SelectObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/SelectObservableValue.java index 2d9ceb63faa..75fcd761713 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/SelectObservableValue.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/SelectObservableValue.java @@ -17,10 +17,10 @@ package org.eclipse.core.databinding.observable.value; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.Realm; -import org.eclipse.core.internal.databinding.observable.Util; /** * An observable value which behaves similarly to the <select> and @@ -199,7 +199,7 @@ public class SelectObservableValue<T> extends AbstractObservableValue<T> { private int indexOfValue(Object value) { for (int i = 0; i < options.size(); i++) - if (Util.equals(options.get(i).value, value)) + if (Objects.equals(options.get(i).value, value)) return i; return -1; } diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java index 2a011b82cf4..db1aef0f12c 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/ValueDiff.java @@ -16,7 +16,8 @@ package org.eclipse.core.databinding.observable.value; -import org.eclipse.core.databinding.observable.Diffs; +import java.util.Objects; + import org.eclipse.core.databinding.observable.IDiff; /** @@ -47,8 +48,7 @@ public abstract class ValueDiff<T> implements IDiff { if (obj instanceof ValueDiff) { ValueDiff<?> val = (ValueDiff<?>) obj; - return Diffs.equals(val.getNewValue(), getNewValue()) - && Diffs.equals(val.getOldValue(), getOldValue()); + return Objects.equals(val.getNewValue(), getNewValue()) && Objects.equals(val.getOldValue(), getOldValue()); } return false; @@ -58,10 +58,8 @@ public abstract class ValueDiff<T> implements IDiff { public int hashCode() { final int prime = 31; int result = 1; - Object nv = getNewValue(); - Object ov = getOldValue(); - result = prime * result + ((nv == null) ? 0 : nv.hashCode()); - result = prime * result + ((ov == null) ? 0 : ov.hashCode()); + result = prime * result + Objects.hashCode(getNewValue()); + result = prime * result + Objects.hashCode(getOldValue()); return result; } diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/identity/IdentityMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/identity/IdentityMap.java index 6d7a895237f..4917c3b04da 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/identity/IdentityMap.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/identity/IdentityMap.java @@ -23,9 +23,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; -import org.eclipse.core.internal.databinding.observable.Util; import org.eclipse.core.runtime.Assert; /** @@ -155,11 +155,11 @@ public class IdentityMap<K, V> implements Map<K, V> { public boolean equals(Object obj) { if (obj == this) return true; - if (obj == null || !(obj instanceof Map.Entry)) + if (!(obj instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) obj; return this.getKey() == that.getKey() - && Util.equals(this.getValue(), + && Objects.equals(this.getValue(), that.getValue()); } @@ -206,15 +206,13 @@ public class IdentityMap<K, V> implements Map<K, V> { if (obj == null || !(obj instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) obj; - return Util.equals(wrappedKey, that.getKey()) - && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(wrappedKey, that.getKey()) + && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { - return wrappedKey.hashCode() - ^ (getValue() == null ? 0 : getValue() - .hashCode()); + return wrappedKey.hashCode() ^ Objects.hashCode(getValue()); } }; return wrappedEntrySet.remove(wrappedEntry); diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/DelayedObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/DelayedObservableValue.java index 0fd4cf8255f..a8b2382bab0 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/DelayedObservableValue.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/DelayedObservableValue.java @@ -18,6 +18,8 @@ package org.eclipse.core.internal.databinding.observable; +import java.util.Objects; + import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.IStaleListener; import org.eclipse.core.databinding.observable.ObservableTracker; @@ -151,7 +153,7 @@ public class DelayedObservableValue<T> extends AbstractObservableValue<T> // passed to setValue(). Make sure we cache whatever is set. cachedValue = observable.getValue(); - if (!Util.equals(oldValue, cachedValue)) + if (!Objects.equals(oldValue, cachedValue)) fireValueChange(Diffs.createValueDiff(oldValue, cachedValue)); } finally { updating = false; diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/Util.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/Util.java deleted file mode 100644 index 97980dbe66f..00000000000 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/Util.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.observable; - -/** - * @since 3.3 - * - */ -public class Util { - - /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); - } -} diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableHelper.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableHelper.java index 2b5d8b518b7..9d3f56ae3a4 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableHelper.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/DetailObservableHelper.java @@ -14,16 +14,17 @@ package org.eclipse.core.internal.databinding.observable.masterdetail; +import java.util.Objects; + import org.eclipse.core.databinding.observable.Realm; import org.eclipse.core.databinding.util.Policy; -import org.eclipse.core.internal.databinding.observable.Util; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; /* package */class DetailObservableHelper { /* package */static void warnIfDifferentRealms(Realm detailRealm, Realm innerObservableRealm) { - if (!Util.equals(detailRealm, innerObservableRealm)) { + if (!Objects.equals(detailRealm, innerObservableRealm)) { Throwable throwable = new Throwable(); throwable.fillInStackTrace(); String message = "Inner observable realm (" + innerObservableRealm //$NON-NLS-1$ diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/MapDetailValueObservableMap.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/MapDetailValueObservableMap.java index b029c4a4d9f..e97fac45e1b 100644 --- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/MapDetailValueObservableMap.java +++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/masterdetail/MapDetailValueObservableMap.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -35,7 +36,6 @@ import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.internal.databinding.identity.IdentityMap; import org.eclipse.core.internal.databinding.identity.IdentitySet; -import org.eclipse.core.internal.databinding.observable.Util; /** * @param <K> @@ -399,16 +399,13 @@ public class MapDetailValueObservableMap<K, M, E> extends if (!(o instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) o; - return Util.equals(this.getKey(), that.getKey()) - && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(this.getKey(), that.getKey()) && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { MapDetailValueObservableMap.this.getterCalled(); - Object value = getValue(); - return (getKey() == null ? 0 : getKey().hashCode()) - ^ (value == null ? 0 : value.hashCode()); + return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue()); } } } diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/SimplePropertyEvent.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/SimplePropertyEvent.java index aaf38c1e31e..12459d4dff9 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/SimplePropertyEvent.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/SimplePropertyEvent.java @@ -17,9 +17,9 @@ package org.eclipse.core.databinding.property; import java.util.EventObject; +import java.util.Objects; import org.eclipse.core.databinding.observable.IDiff; -import org.eclipse.core.internal.databinding.property.Util; /** * Event object events in the properties API @@ -93,9 +93,8 @@ public final class SimplePropertyEvent<S, D extends IDiff> extends EventObject { return false; SimplePropertyEvent<?, ?> that = (SimplePropertyEvent<?, ?>) obj; - return Util.equals(getSource(), that.getSource()) - && Util.equals(this.property, that.property) - && Util.equals(this.diff, that.diff); + return Objects.equals(getSource(), that.getSource()) && Objects.equals(this.property, that.property) + && Objects.equals(this.diff, that.diff); } @Override @@ -103,7 +102,7 @@ public final class SimplePropertyEvent<S, D extends IDiff> extends EventObject { int hash = 17; hash = hash * 37 + getSource().hashCode(); hash = hash * 37 + property.hashCode(); - hash = hash * 37 + (diff == null ? 0 : diff.hashCode()); + hash = hash * 37 + Objects.hashCode(diff); return hash; } } diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/Util.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/Util.java deleted file mode 100644 index 71e4a22af67..00000000000 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/Util.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - ******************************************************************************/ - -package org.eclipse.core.internal.databinding.property; - -/** - * @since 3.3 - * - */ -public class Util { - - /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - */ - public static final boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left - .equals(right)); - } -} diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ListSimpleValueObservableList.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ListSimpleValueObservableList.java index 06846457d35..92dded68ecd 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ListSimpleValueObservableList.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/ListSimpleValueObservableList.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -44,7 +45,6 @@ import org.eclipse.core.databinding.property.value.SimpleValueProperty; import org.eclipse.core.internal.databinding.identity.IdentityMap; import org.eclipse.core.internal.databinding.identity.IdentityObservableSet; import org.eclipse.core.internal.databinding.identity.IdentitySet; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -223,7 +223,7 @@ public class ListSimpleValueObservableList<S, M extends S, T> extends AbstractOb getterCalled(); for (M m : masterList) { - if (Util.equals(detailProperty.getValue(m), o)) + if (Objects.equals(detailProperty.getValue(m), o)) return true; } return false; @@ -415,7 +415,7 @@ public class ListSimpleValueObservableList<S, M extends S, T> extends AbstractOb if (cachedValues != null) { T oldValue = cachedValues.get(masterElement); T newValue = detailProperty.getValue(masterElement); - if (!Util.equals(oldValue, newValue) || staleElements.contains(masterElement)) { + if (!Objects.equals(oldValue, newValue) || staleElements.contains(masterElement)) { cachedValues.put(masterElement, newValue); staleElements.remove(masterElement); fireListChange(indicesOf(masterElement), oldValue, newValue); diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapDelegatingValueObservableMap.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapDelegatingValueObservableMap.java index fb58dec4c0d..46fb8138caa 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapDelegatingValueObservableMap.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapDelegatingValueObservableMap.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -33,7 +34,6 @@ import org.eclipse.core.databinding.observable.map.MapChangeEvent; import org.eclipse.core.databinding.observable.map.MapDiff; import org.eclipse.core.databinding.property.IPropertyObservable; import org.eclipse.core.databinding.property.value.DelegatingValueProperty; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -131,14 +131,13 @@ public class MapDelegatingValueObservableMap<S, K, I extends S, V> extends Abstr if (!(o instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) o; - return Util.equals(this.getKey(), that.getKey()) && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(this.getKey(), that.getKey()) && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { getterCalled(); - Object value = getValue(); - return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()); + return Objects.hashCode(key) ^ Objects.hashCode(getValue()); } } @@ -186,7 +185,7 @@ public class MapDelegatingValueObservableMap<S, K, I extends S, V> extends Abstr V oldValue = cache.get(oldMasterValue); V newValue = cache.get(newMasterValue); - if (Util.equals(oldValue, newValue)) { + if (Objects.equals(oldValue, newValue)) { it.remove(); } else { oldValues.put(key, oldValue); diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapSimpleValueObservableMap.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapSimpleValueObservableMap.java index 89757766117..fcb139db5b5 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapSimpleValueObservableMap.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/MapSimpleValueObservableMap.java @@ -21,6 +21,7 @@ import java.util.AbstractSet; import java.util.Collections; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -41,7 +42,6 @@ import org.eclipse.core.databinding.property.value.SimpleValueProperty; import org.eclipse.core.internal.databinding.identity.IdentityMap; import org.eclipse.core.internal.databinding.identity.IdentityObservableSet; import org.eclipse.core.internal.databinding.identity.IdentitySet; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -110,7 +110,7 @@ public class MapSimpleValueObservableMap<S, K, I extends S, V> extends AbstractO V oldValue = detailProperty.getValue(oldSource); V newValue = detailProperty.getValue(newSource); - if (Util.equals(oldValue, newValue)) { + if (Objects.equals(oldValue, newValue)) { it.remove(); } else { oldValues.put(key, oldValue); @@ -304,14 +304,13 @@ public class MapSimpleValueObservableMap<S, K, I extends S, V> extends AbstractO if (!(o instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) o; - return Util.equals(this.getKey(), that.getKey()) && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(this.getKey(), that.getKey()) && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { getterCalled(); - Object value = getValue(); - return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode()); + return Objects.hashCode(key) ^ Objects.hashCode(getValue()); } } @@ -359,7 +358,7 @@ public class MapSimpleValueObservableMap<S, K, I extends S, V> extends AbstractO final V oldValue = cachedValues.get(masterValue); final V newValue = detailProperty.getValue(masterValue); - if (!Util.equals(oldValue, newValue) || staleMasterValues.contains(masterValue)) { + if (!Objects.equals(oldValue, newValue) || staleMasterValues.contains(masterValue)) { cachedValues.put(masterValue, newValue); staleMasterValues.remove(masterValue); fireMapChange(new MapDiff<K, V>() { diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetDelegatingValueObservableMap.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetDelegatingValueObservableMap.java index 0d8858e1277..88f8e8ce108 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetDelegatingValueObservableMap.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetDelegatingValueObservableMap.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -33,7 +34,6 @@ import org.eclipse.core.databinding.observable.set.SetChangeEvent; import org.eclipse.core.databinding.observable.set.SetDiff; import org.eclipse.core.databinding.property.IPropertyObservable; import org.eclipse.core.databinding.property.value.DelegatingValueProperty; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -124,16 +124,13 @@ public class SetDelegatingValueObservableMap<S, K extends S, V> extends Abstract if (!(o instanceof Map.Entry)) return false; Map.Entry<?, ?> that = (Map.Entry<?, ?>) o; - return Util.equals(this.getKey(), that.getKey()) - && Util.equals(this.getValue(), that.getValue()); + return Objects.equals(this.getKey(), that.getKey()) && Objects.equals(this.getValue(), that.getValue()); } @Override public int hashCode() { getterCalled(); - Object value = getValue(); - return (key == null ? 0 : key.hashCode()) - ^ (value == null ? 0 : value.hashCode()); + return Objects.hashCode(key) ^ Objects.hashCode(getValue()); } } diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetSimpleValueObservableMap.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetSimpleValueObservableMap.java index 65257655ec6..5abd103c0a6 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetSimpleValueObservableMap.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SetSimpleValueObservableMap.java @@ -18,6 +18,7 @@ package org.eclipse.core.internal.databinding.property.value; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.databinding.observable.Diffs; @@ -29,7 +30,6 @@ import org.eclipse.core.databinding.property.SimplePropertyEvent; import org.eclipse.core.databinding.property.value.SimpleValueProperty; import org.eclipse.core.internal.databinding.identity.IdentityMap; import org.eclipse.core.internal.databinding.identity.IdentitySet; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -142,7 +142,7 @@ public class SetSimpleValueObservableMap<S, K extends S, V> extends ComputedObse if (cachedValues != null) { V oldValue = cachedValues.get(key); V newValue = detailProperty.getValue(key); - if (!Util.equals(oldValue, newValue) || staleKeys.contains(key)) { + if (!Objects.equals(oldValue, newValue) || staleKeys.contains(key)) { cachedValues.put(key, newValue); staleKeys.remove(key); fireMapChange(Diffs.createMapDiffSingleChange(key, oldValue, diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SimplePropertyObservableValue.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SimplePropertyObservableValue.java index 575aecdef89..60aef094ecb 100644 --- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SimplePropertyObservableValue.java +++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/internal/databinding/property/value/SimplePropertyObservableValue.java @@ -16,6 +16,8 @@ package org.eclipse.core.internal.databinding.property.value; +import java.util.Objects; + import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.ObservableTracker; import org.eclipse.core.databinding.observable.Realm; @@ -25,7 +27,6 @@ import org.eclipse.core.databinding.property.INativePropertyListener; import org.eclipse.core.databinding.property.IPropertyObservable; import org.eclipse.core.databinding.property.SimplePropertyEvent; import org.eclipse.core.databinding.property.value.SimpleValueProperty; -import org.eclipse.core.internal.databinding.property.Util; /** * @param <S> @@ -114,7 +115,7 @@ public class SimplePropertyObservableValue<S, T> extends AbstractObservableValue T newValue = cachedValue = property.getValue(source); if (diff == null) diff = Diffs.createValueDiff(oldValue, newValue); - if (!Util.equals(oldValue, newValue) || stale) { + if (!Objects.equals(oldValue, newValue) || stale) { stale = false; fireValueChange(Diffs.unmodifiableDiff(diff)); } diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java index 54cce01cbb7..7e219642c41 100644 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ValidationStatus.java @@ -14,6 +14,8 @@ *******************************************************************************/ package org.eclipse.core.databinding.validation; +import java.util.Objects; + import org.eclipse.core.databinding.util.Policy; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -118,10 +120,9 @@ public class ValidationStatus extends Status { int severity = getSeverity(); Throwable throwable = getException(); - result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + Objects.hashCode(message); result = prime * result + severity; - result = prime * result - + ((throwable == null) ? 0 : throwable.hashCode()); + result = prime * result + Objects.hashCode(throwable); return result; } @@ -139,18 +140,7 @@ public class ValidationStatus extends Status { return false; final ValidationStatus other = (ValidationStatus) obj; - if (getSeverity() != other.getSeverity()) - return false; - if (getMessage() == null) { - if (other.getMessage() != null) - return false; - } else if (!getMessage().equals(other.getMessage())) - return false; - if (getException() == null) { - if (other.getException() != null) - return false; - } else if (!getException().equals(other.getException())) - return false; - return true; + return getSeverity() == other.getSeverity() && Objects.equals(getMessage(), other.getMessage()) + && Objects.equals(getException(), other.getException()); } } diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java index 945fb5bb8ff..e26fc31f217 100644 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.java @@ -74,22 +74,11 @@ public class BindingStatus extends MultiStatus { return new BindingStatus(Policy.JFACE_DATABINDING, 0, "", null); //$NON-NLS-1$ } - private static int hashCode(Object[] array) { - final int prime = 31; - if (array == null) - return 0; - int result = 1; - for (Object element : array) { - result = prime * result + (element == null ? 0 : element.hashCode()); - } - return result; - } - @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + BindingStatus.hashCode(getChildren()); + result = prime * result + Arrays.hashCode(getChildren()); return result; } @@ -102,8 +91,6 @@ public class BindingStatus extends MultiStatus { if (getClass() != obj.getClass()) return false; final BindingStatus other = (BindingStatus) obj; - if (!Arrays.equals(getChildren(), other.getChildren())) - return false; - return true; + return Arrays.equals(getChildren(), other.getChildren()); } } diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java deleted file mode 100644 index 57a8644b2b2..00000000000 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java +++ /dev/null @@ -1,464 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2015 Matthew Hall and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Matthew Hall - initial API and implementation (bug 215531) - * Matthew Hall - bug 228125 - * (through ViewerElementMap.java) - * Matthew Hall - bugs 262269, 303847 - ******************************************************************************/ - -package org.eclipse.core.internal.databinding; - -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.runtime.Assert; - -/** - * A {@link Map} whose keys are added, removed and compared by identity. The - * keys in the map are compared using <code>==</code> instead of - * {@link #equals(Object)}. - * <p> - * This class is <i>not</i> a strict implementation the {@link Map} interface. - * It intentionally violates the {@link Map} contract, which requires the use of - * {@link #equals(Object)} when comparing keys. - * - * @param <K> - * the type of the keys in the map - * @param <V> - * the type of the values in the map - * @since 1.2 - */ -public class IdentityMap<K, V> implements Map<K, V> { - private Map<IdentityWrapper<K>, V> wrappedMap; - - /** - * Constructs an IdentityMap. - */ - public IdentityMap() { - this.wrappedMap = new HashMap<>(); - } - - /** - * Constructs an IdentityMap containing all the entries in the specified - * map. - * - * @param map - * the map whose entries are to be added to this map. - */ - public IdentityMap(Map<? extends K, ? extends V> map) { - this(); - Assert.isNotNull(map); - putAll(map); - } - - @Override - public void clear() { - wrappedMap.clear(); - } - - @Override - public boolean containsKey(Object key) { - return wrappedMap.containsKey(IdentityWrapper.wrap(key)); - } - - @Override - public boolean containsValue(Object value) { - return wrappedMap.containsValue(value); - } - - @Override - public Set<Entry<K, V>> entrySet() { - final Set<Entry<IdentityWrapper<K>, V>> wrappedEntrySet = wrappedMap.entrySet(); - return new Set<Entry<K, V>>() { - @Override - public boolean add(Entry<K, V> o) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(Collection<? extends Entry<K, V>> c) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - wrappedEntrySet.clear(); - } - - @Override - public boolean contains(Object o) { - for (Entry<K, V> entry : this) - if (entry.equals(o)) - return true; - return false; - } - - @Override - public boolean containsAll(Collection<?> c) { - for (Object element : c) - if (!contains(element)) - return false; - return true; - } - - @Override - public boolean isEmpty() { - return wrappedEntrySet.isEmpty(); - } - - @Override - public Iterator<Entry<K, V>> iterator() { - final Iterator<Entry<IdentityWrapper<K>, V>> wrappedIterator = wrappedEntrySet.iterator(); - return new Iterator<Entry<K, V>>() { - @Override - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - @Override - public Entry<K, V> next() { - final Entry<IdentityWrapper<K>, V> wrappedEntry = wrappedIterator - .next(); - return new Entry<K, V>() { - @Override - public K getKey() { - return wrappedEntry.getKey().unwrap(); - } - - @Override - public V getValue() { - return wrappedEntry.getValue(); - } - - @Override - public V setValue(V value) { - return wrappedEntry.setValue(value); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Entry)) - return false; - Entry<?, ?> that = (Entry<?, ?>) obj; - return this.getKey() == that.getKey() - && Util.equals(this.getValue(), that.getValue()); - } - - @Override - public int hashCode() { - return wrappedEntry.hashCode(); - } - }; - } - - @Override - public void remove() { - wrappedIterator.remove(); - } - }; - } - - @Override - public boolean remove(Object o) { - final Entry<?, ?> unwrappedEntry = (Entry<?, ?>) o; - Object key = unwrappedEntry.getKey(); - final IdentityWrapper<Object> wrappedKey = IdentityWrapper.wrap(key); - Entry<IdentityWrapper<Object>, Object> wrappedEntry = new Entry<IdentityWrapper<Object>, Object>() { - @Override - public IdentityWrapper<Object> getKey() { - return wrappedKey; - } - - @Override - public Object getValue() { - return unwrappedEntry.getValue(); - } - - @Override - public Object setValue(Object value) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Entry)) - return false; - Entry<?, ?> that = (Entry<?, ?>) obj; - return Util.equals(wrappedKey, that.getKey()) - && Util.equals(this.getValue(), that.getValue()); - } - - @Override - public int hashCode() { - return wrappedKey.hashCode() - ^ (getValue() == null ? 0 : getValue() - .hashCode()); - } - }; - return wrappedEntrySet.remove(wrappedEntry); - } - - @Override - public boolean removeAll(Collection<?> c) { - boolean changed = false; - for (Object element : c) - changed |= remove(element); - return changed; - } - - @Override - public boolean retainAll(Collection<?> c) { - boolean changed = false; - Object[] toRetain = c.toArray(); - outer: for (Iterator<?> iterator = iterator(); iterator.hasNext();) { - Object entry = iterator.next(); - for (int i = 0; i < toRetain.length; i++) - if (entry.equals(toRetain[i])) - continue outer; - iterator.remove(); - changed = true; - } - return changed; - } - - @Override - public int size() { - return wrappedEntrySet.size(); - } - - @Override - public Object[] toArray() { - return toArray(new Object[size()]); - } - - @SuppressWarnings("unchecked") - @Override - public <T> T[] toArray(T[] a) { - int size = size(); - if (a.length < size) { - a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); - } - int i = 0; - for (Entry<K, V> entry : this) { - a[i++] = (T) entry; - } - return a; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Set)) - return false; - Set<?> that = (Set<?>) obj; - return this.size() == that.size() && containsAll(that); - } - - @Override - public int hashCode() { - return wrappedEntrySet.hashCode(); - } - }; - } - - @Override - public V get(Object key) { - return wrappedMap.get(IdentityWrapper.wrap(key)); - } - - @Override - public boolean isEmpty() { - return wrappedMap.isEmpty(); - } - - @Override - public Set<K> keySet() { - final Set<IdentityWrapper<K>> wrappedKeySet = wrappedMap.keySet(); - return new Set<K>() { - @Override - public boolean add(K o) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addAll(Collection<? extends K> c) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - wrappedKeySet.clear(); - } - - @Override - public boolean contains(Object o) { - return wrappedKeySet.contains(IdentityWrapper.wrap(o)); - } - - @Override - public boolean containsAll(Collection<?> c) { - for (Object element : c) - if (!wrappedKeySet.contains(IdentityWrapper.wrap(element))) - return false; - return true; - } - - @Override - public boolean isEmpty() { - return wrappedKeySet.isEmpty(); - } - - @Override - public Iterator<K> iterator() { - final Iterator<IdentityWrapper<K>> wrappedIterator = wrappedKeySet.iterator(); - return new Iterator<K>() { - @Override - public boolean hasNext() { - return wrappedIterator.hasNext(); - } - - @Override - public K next() { - return wrappedIterator.next().unwrap(); - } - - @Override - public void remove() { - wrappedIterator.remove(); - } - }; - } - - @Override - public boolean remove(Object o) { - return wrappedKeySet.remove(IdentityWrapper.wrap(o)); - } - - @Override - public boolean removeAll(Collection<?> c) { - boolean changed = false; - for (Object element : c) - changed |= wrappedKeySet.remove(IdentityWrapper - .wrap(element)); - return changed; - } - - @Override - public boolean retainAll(Collection<?> c) { - boolean changed = false; - Object[] toRetain = c.toArray(); - outer: for (Object element : this) { - for (int i = 0; i < toRetain.length; i++) - if (element == toRetain[i]) - continue outer; - // element not contained in collection, remove. - remove(element); - changed = true; - } - return changed; - } - - @Override - public int size() { - return wrappedKeySet.size(); - } - - @Override - public Object[] toArray() { - return toArray(new Object[wrappedKeySet.size()]); - } - - @SuppressWarnings("unchecked") - @Override - public <T> T[] toArray(T[] a) { - int size = wrappedKeySet.size(); - T[] result = a; - if (a.length < size) { - result = (T[]) Array.newInstance(a.getClass().getComponentType(), size); - } - int i = 0; - for (IdentityWrapper<K> wrapper : wrappedKeySet) { - result[i++] = (T) wrapper.unwrap(); - } - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Set)) - return false; - Set<?> that = (Set<?>) obj; - return this.size() == that.size() && containsAll(that); - } - - @Override - public int hashCode() { - return wrappedKeySet.hashCode(); - } - }; - } - - @Override - public V put(K key, V value) { - return wrappedMap.put(IdentityWrapper.wrap(key), value); - } - - @Override - public void putAll(Map<? extends K, ? extends V> other) { - for (Entry<? extends K, ? extends V> entry : other.entrySet()) { - K key = entry.getKey(); - V value = entry.getValue(); - wrappedMap.put(IdentityWrapper.wrap(key), value); - } - } - - @Override - public V remove(Object key) { - return wrappedMap.remove(IdentityWrapper.wrap(key)); - } - - @Override - public int size() { - return wrappedMap.size(); - } - - @Override - public Collection<V> values() { - return wrappedMap.values(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || !(obj instanceof Map)) - return false; - Map<?, ?> that = (Map<?, ?>) obj; - return this.entrySet().equals(that.entrySet()); - } - - @Override - public int hashCode() { - return wrappedMap.hashCode(); - } -} diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java index 607e4da9e7a..7d89731bf37 100644 --- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java +++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Pair.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.core.internal.databinding; +import java.util.Objects; + /** * Class Pair. Represents a mathematical pair of objects (a, b). * @since 1.0 @@ -44,8 +46,8 @@ public class Pair { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((a == null) ? 0 : a.hashCode()); - result = prime * result + ((b == null) ? 0 : b.hashCode()); + result = prime * result + Objects.hashCode(a); + result = prime * result + Objects.hashCode(b); return result; } @@ -58,17 +60,7 @@ public class Pair { if (getClass() != obj.getClass()) return false; Pair other = (Pair) obj; - if (a == null) { - if (other.a != null) - return false; - } else if (!a.equals(other.a)) - return false; - if (b == null) { - if (other.b != null) - return false; - } else if (!b.equals(other.b)) - return false; - return true; + return Objects.equals(this.a, other.a) && Objects.equals(this.b, other.b); } } diff --git a/bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF index c771d9b26f0..feb85627a8d 100644 --- a/bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.emf.xpath/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.e4.emf.xpath -Bundle-Version: 0.2.200.qualifier +Bundle-Version: 0.2.300.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.apache.commons.jxpath;bundle-version="1.2.0", org.eclipse.emf.ecore;bundle-version="2.6.0" diff --git a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EObjectPointer.java b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EObjectPointer.java index 291a40c6448..0cf85255a21 100644 --- a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EObjectPointer.java +++ b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EObjectPointer.java @@ -30,6 +30,7 @@ package org.eclipse.e4.emf.internal.xpath; import java.util.Locale; +import java.util.Objects; import org.apache.commons.jxpath.JXPathIntrospector; import org.apache.commons.jxpath.ri.QName; @@ -122,7 +123,7 @@ public class EObjectPointer extends EStructuralFeatureOwnerPointer { @Override public int hashCode() { - return name == null ? 0 : name.hashCode(); + return Objects.hashCode(name); } @Override @@ -136,12 +137,11 @@ public class EObjectPointer extends EStructuralFeatureOwnerPointer { } EObjectPointer other = (EObjectPointer) object; - if (parent != other.parent && (parent == null || !parent.equals(other.parent))) { + if (!Objects.equals(parent, other.parent)) { return false; } - if ((name == null && other.name != null) - || (name != null && !name.equals(other.name))) { + if (!Objects.equals(name, other.name)) { return false; } diff --git a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EStructuralFeaturePointer.java b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EStructuralFeaturePointer.java index f1eb5318253..0125d43783f 100644 --- a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EStructuralFeaturePointer.java +++ b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/EStructuralFeaturePointer.java @@ -29,6 +29,8 @@ ******************************************************************************/ package org.eclipse.e4.emf.internal.xpath; +import java.util.Objects; + import org.apache.commons.jxpath.AbstractFactory; import org.apache.commons.jxpath.JXPathAbstractFactoryException; import org.apache.commons.jxpath.JXPathContext; @@ -261,7 +263,7 @@ public abstract class EStructuralFeaturePointer extends NodePointer { } EStructuralFeaturePointer other = (EStructuralFeaturePointer) object; - if (parent != other.parent && (parent == null || !parent.equals(other.parent))) { + if (!Objects.equals(parent, other.parent)) { return false; } diff --git a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/NullPointer.java b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/NullPointer.java index 43792a93f36..6f7fc6d863c 100644 --- a/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/NullPointer.java +++ b/bundles/org.eclipse.e4.emf.xpath/src/org/eclipse/e4/emf/internal/xpath/NullPointer.java @@ -30,6 +30,7 @@ package org.eclipse.e4.emf.internal.xpath; import java.util.Locale; +import java.util.Objects; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.QName; @@ -141,7 +142,7 @@ public class NullPointer extends EStructuralFeatureOwnerPointer { @Override public int hashCode() { - return name == null ? 0 : name.hashCode(); + return Objects.hashCode(name); } @Override @@ -155,7 +156,7 @@ public class NullPointer extends EStructuralFeatureOwnerPointer { } NullPointer other = (NullPointer) object; - return name == other.name || name != null && name.equals(other.name); + return Objects.equals(name, other.name); } @Override diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/AbstractAttributeCondition.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/AbstractAttributeCondition.java index 3e8c6c6c607..fabffbad828 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/AbstractAttributeCondition.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/AbstractAttributeCondition.java @@ -20,6 +20,7 @@ package org.eclipse.e4.ui.css.core.impl.sac; +import java.util.Objects; import org.w3c.css.sac.AttributeCondition; /** @@ -63,7 +64,7 @@ public abstract class AbstractAttributeCondition implements AttributeCondition, */ @Override public int hashCode() { - return value == null ? -1 : value.hashCode(); + return Objects.hashCode(value); } /** diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/CSSAttributeConditionImpl.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/CSSAttributeConditionImpl.java index 39162214d55..3467d068938 100644 --- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/CSSAttributeConditionImpl.java +++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/impl/sac/CSSAttributeConditionImpl.java @@ -78,7 +78,7 @@ public class CSSAttributeConditionImpl extends AbstractAttributeCondition { @Override public int hashCode() { return namespaceURI.hashCode() ^ localName.hashCode() - ^ (specified ? -1 : 0); + ^ Boolean.hashCode(specified); } /** diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/URI.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/URI.java index 01fb9e04356..21f3c04a6f7 100644 --- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/URI.java +++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/helpers/URI.java @@ -29,6 +29,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.StringTokenizer; @@ -1012,57 +1013,36 @@ public final class URI String device, boolean absolutePath, String[] segments, String query, String fragment) { - int hashCode = 0; - //boolean iri = false; - + int tmpHashCode = 0; if (scheme != null) { - hashCode ^= scheme.toLowerCase().hashCode(); - } - if (authority != null) - { - hashCode ^= authority.hashCode(); - //iri = iri || containsNonASCII(authority); + tmpHashCode ^= scheme.toLowerCase().hashCode(); } - if (device != null) - { - hashCode ^= device.hashCode(); - //iri = iri || containsNonASCII(device); - } - if (query != null) - { - hashCode ^= query.hashCode(); - //iri = iri || containsNonASCII(query); - } - if (fragment != null) - { - hashCode ^= fragment.hashCode(); - //iri = iri || containsNonASCII(fragment); - } - + tmpHashCode ^= Objects.hashCode(authority); + tmpHashCode ^= Objects.hashCode(device); + tmpHashCode ^= Objects.hashCode(query); + tmpHashCode ^= Objects.hashCode(fragment); for (String segment : segments) { - hashCode ^= segment.hashCode(); - //iri = iri || containsNonASCII(segments[i]); + tmpHashCode ^= segment.hashCode(); } if (hierarchical) { - hashCode |= HIERARICHICAL_FLAG; + tmpHashCode |= HIERARICHICAL_FLAG; } else { - hashCode &= ~HIERARICHICAL_FLAG; + tmpHashCode &= ~HIERARICHICAL_FLAG; } if (absolutePath) { - hashCode |= ABSOLUTE_PATH_FLAG; + tmpHashCode |= ABSOLUTE_PATH_FLAG; } else { - hashCode &= ~ABSOLUTE_PATH_FLAG; + tmpHashCode &= ~ABSOLUTE_PATH_FLAG; } - this.hashCode = hashCode; - //this.iri = iri; + this.hashCode = tmpHashCode; this.scheme = scheme == null ? null : scheme.intern(); this.authority = authority; this.device = device; diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java index da8652f2948..ec8833ad2b4 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java @@ -541,11 +541,11 @@ public final class ContributionsAnalyzer { public int hashCode() { if (hc == -1) { Object exp1 = vexp == null ? null : vexp.getCoreExpression(); - hc = Util.hashCode(parentId); - hc = hc * 87 + Util.hashCode(position); + hc = Objects.hashCode(parentId); + hc = hc * 87 + Objects.hashCode(position); hc = hc * 87 + getSchemeTag(); - hc = hc * 87 + Util.hashCode(exp1); - hc = hc * 87 + Util.hashCode(factory); + hc = hc * 87 + Objects.hashCode(exp1); + hc = hc * 87 + Objects.hashCode(factory); } return hc; } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java index 857d5e202c7..33e2e8fdaf0 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Parameter.java @@ -212,7 +212,7 @@ public final class Parameter implements IParameter, ITypedParameter { @Override public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(id); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(id); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Util.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Util.java index 3cb89d2715d..edd0e2ff6cf 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Util.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/Util.java @@ -13,7 +13,6 @@ *******************************************************************************/ package org.eclipse.e4.ui.internal.workbench; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.MissingResourceException; @@ -242,88 +241,6 @@ public final class Util { } /** - * Checks whether the two objects are <code>null</code> -- allowing for - * <code>null</code>. - * - * @param left - * The left object to compare; may be <code>null</code>. - * @param right - * The right object to compare; may be <code>null</code>. - * @return <code>true</code> if the two objects are equivalent; - * <code>false</code> otherwise. - * @deprecated Use {@link Objects#equals(Object, Object)} - */ - @Deprecated - public static boolean equals(final Object left, final Object right) { - return left == null ? right == null : ((right != null) && left.equals(right)); - } - - /** - * Tests whether two arrays of objects are equal to each other. The arrays must - * not be <code>null</code>, but their elements may be <code>null</code>. - * - * @param leftArray - * The left array to compare; may be <code>null</code>, and may be - * empty and may contain <code>null</code> elements. - * @param rightArray - * The right array to compare; may be <code>null</code>, and may be - * empty and may contain <code>null</code> elements. - * @return <code>true</code> if the arrays are equal length and the elements at - * the same position are equal; <code>false</code> otherwise. - * @deprecated Use {@link Arrays#equals(Object[], Object[])} - */ - @Deprecated - public static boolean equals(final Object[] leftArray, final Object[] rightArray) { - return Arrays.equals(leftArray, rightArray); - } - - /** - * Provides a hash code based on the given integer value. - * - * @param i - * The integer value - * @return <code>i</code> - */ - public static int hashCode(final int i) { - return i; - } - - /** - * Provides a hash code for the object -- defending against <code>null</code>. - * - * @param object - * The object for which a hash code is required. - * @return <code>object.hashCode</code> or <code>0</code> if <code>object</code> if - * <code>null</code>. - */ - public static int hashCode(final Object object) { - return object != null ? object.hashCode() : 0; - } - - /** - * Computes the hash code for an array of objects, but with defense against <code>null</code>. - * - * @param objects - * The array of objects for which a hash code is needed; may be <code>null</code>. - * @return The hash code for <code>objects</code>; or <code>0</code> if <code>objects</code> is - * <code>null</code>. - */ - public static int hashCode(final Object[] objects) { - if (objects == null) { - return 0; - } - - int hashCode = 89; - for (final Object object : objects) { - if (object != null) { - hashCode = hashCode * 31 + object.hashCode(); - } - } - - return hashCode; - } - - /** * Checks whether the second array is a subsequence of the first array, and that they share * common starting elements. * diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/DisplayRealm.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/DisplayRealm.java index 93a5dc9f0c9..ae5031951da 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/DisplayRealm.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/databinding/swt/DisplayRealm.java @@ -15,6 +15,7 @@ package org.eclipse.jface.databinding.swt; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import org.eclipse.core.databinding.observable.Realm; import org.eclipse.swt.widgets.Display; @@ -80,7 +81,7 @@ public class DisplayRealm extends Realm { @Override public int hashCode() { - return (display == null) ? 0 : display.hashCode(); + return Objects.hashCode(display); } @Override @@ -92,11 +93,6 @@ public class DisplayRealm extends Realm { if (getClass() != obj.getClass()) return false; final DisplayRealm other = (DisplayRealm) obj; - if (display == null) { - if (other.display != null) - return false; - } else if (!display.equals(other.display)) - return false; - return true; + return Objects.equals(display, other.display); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java index a8e58f47ea8..5f36e6a0804 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementMap.java @@ -216,7 +216,7 @@ public class ViewerElementMap<K, V> implements Map<K, V> { @Override public int hashCode() { - return wrappedKey.hashCode() ^ (getValue() == null ? 0 : getValue().hashCode()); + return wrappedKey.hashCode() ^ Objects.hashCode(getValue()); } }; return wrappedEntrySet.remove(wrappedEntry); @@ -455,7 +455,7 @@ public class ViewerElementMap<K, V> implements Map<K, V> { public boolean equals(Object obj) { if (obj == this) return true; - if (obj == null || !(obj instanceof Map)) + if (!(obj instanceof Map)) return false; Map<?, ?> that = (Map<?, ?>) obj; return this.entrySet().equals(that.entrySet()); diff --git a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java index bf6d7b8444d..f8c396e66ef 100644 --- a/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java +++ b/bundles/org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerElementSet.java @@ -19,6 +19,7 @@ import java.lang.reflect.Array; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import org.eclipse.core.runtime.Assert; @@ -207,8 +208,7 @@ public class ViewerElementSet<E> implements Set<E> { public int hashCode() { int hash = 0; for (Iterator<?> iterator = iterator(); iterator.hasNext();) { - Object element = iterator.next(); - hash += element == null ? 0 : element.hashCode(); + hash += Objects.hashCode(iterator.next()); } return hash; } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/Binding.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/Binding.java index 72cc53e23d3..d9b78b91fc1 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/Binding.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/Binding.java @@ -19,7 +19,6 @@ import java.io.StringWriter; import java.util.Objects; import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.jface.util.Util; /** * <p> @@ -62,7 +61,7 @@ import org.eclipse.jface.util.Util; * a null command on the gtk platform. We then create a new binding that maps * the command to the "Esc Ctrl+F" key sequence. * </p> - * + * * <pre> * <code> * KeyBinding("Ctrl+Shift+F",null,scheme,context,null,gtk,null,SYSTEM) @@ -367,14 +366,14 @@ public abstract class Binding { if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode = HASH_INITIAL; hashCode = hashCode * HASH_FACTOR - + Util.hashCode(getParameterizedCommand()); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(getContextId()); + + Objects.hashCode(getParameterizedCommand()); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(getContextId()); hashCode = hashCode * HASH_FACTOR - + Util.hashCode(getTriggerSequence()); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(getLocale()); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(getPlatform()); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(getSchemeId()); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(getType()); + + Objects.hashCode(getTriggerSequence()); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(getLocale()); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(getPlatform()); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(getSchemeId()); + hashCode = hashCode * HASH_FACTOR + Integer.hashCode(getType()); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/CachedBindingSet.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/CachedBindingSet.java index 6fbcb7b9fa4..11e1da7c18b 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/CachedBindingSet.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/CachedBindingSet.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Objects; import org.eclipse.core.commands.util.Tracing; -import org.eclipse.jface.util.Util; /** * <p> @@ -297,10 +296,10 @@ final class CachedBindingSet { if (!hashCodeComputed) { hashCode = HASH_INITIAL; hashCode = hashCode * HASH_FACTOR - + Util.hashCode(activeContextTree); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(locales); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(platforms); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(schemeIds); + + Objects.hashCode(activeContextTree); + hashCode = hashCode * HASH_FACTOR + Arrays.hashCode(locales); + hashCode = hashCode * HASH_FACTOR + Arrays.hashCode(platforms); + hashCode = hashCode * HASH_FACTOR + Arrays.hashCode(schemeIds); hashCodeComputed = true; } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/TriggerSequence.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/TriggerSequence.java index cf8efeb7ac8..61eab90cd3f 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/TriggerSequence.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/bindings/TriggerSequence.java @@ -163,7 +163,7 @@ public abstract class TriggerSequence { public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode = HASH_INITIAL; - hashCode = hashCode * HASH_FACTOR + Util.hashCode(triggers); + hashCode = hashCode * HASH_FACTOR + Arrays.hashCode(triggers); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ArrayFontDescriptor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ArrayFontDescriptor.java index 5118f8ba1b2..03da8d0c5eb 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ArrayFontDescriptor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/ArrayFontDescriptor.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.jface.resource; +import java.util.Arrays; + import org.eclipse.swt.graphics.Device; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; @@ -89,19 +91,10 @@ final class ArrayFontDescriptor extends FontDescriptor { return true; } - if (data.length != descr.data.length) { + if (!Arrays.equals(data, descr.data)) { return false; } - for (int i = 0; i < data.length; i++) { - FontData fd = data[i]; - FontData fd2 = descr.data[i]; - - if (!fd.equals(fd2)) { - return false; - } - } - return true; } @@ -113,13 +106,7 @@ final class ArrayFontDescriptor extends FontDescriptor { if (originalFont != null) { return originalFont.hashCode(); } - - int code = 0; - - for (FontData fd : data) { - code += fd.hashCode(); - } - return code; + return Arrays.hashCode(data); } @Override diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java index 2088e199e70..8a6a9123e59 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java @@ -19,6 +19,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Objects; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; @@ -85,16 +86,7 @@ class FileImageDescriptor extends ImageDescriptor { return false; } FileImageDescriptor other = (FileImageDescriptor) o; - if (location != null) { - if (!location.equals(other.location)) { - return false; - } - } else { - if (other.location != null) { - return false; - } - } - return name.equals(other.name); + return Objects.equals(location, other.location) && Objects.equals(name, other.name); } /** diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/util/Util.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/util/Util.java index 5198bd246f2..5a093b6b1b5 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/util/Util.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/util/Util.java @@ -298,23 +298,24 @@ public final class Util { /** * Provides a hash code based on the given integer value. * - * @param i - * The integer value + * @param i The integer value * @return <code>i</code> + * @deprecated return directly value, or use {@link Integer#hashCode(int)} */ + @Deprecated public static int hashCode(final int i) { return i; } /** - * Provides a hash code for the object -- defending against - * <code>null</code>. + * Provides a hash code for the object -- defending against <code>null</code>. * - * @param object - * The object for which a hash code is required. - * @return <code>object.hashCode</code> or <code>0</code> if - * <code>object</code> if <code>null</code>. + * @param object The object for which a hash code is required. + * @return <code>object.hashCode</code> or <code>0</code> if <code>object</code> + * if <code>null</code>. + * @deprecated use {@link Objects#hashCode(Object)} */ + @Deprecated public static int hashCode(final Object object) { return object != null ? object.hashCode() : 0; } @@ -323,12 +324,13 @@ public final class Util { * Computes the hash code for an array of objects, but with defense against * <code>null</code>. * - * @param objects - * The array of objects for which a hash code is needed; may be - * <code>null</code>. + * @param objects The array of objects for which a hash code is needed; may be + * <code>null</code>. * @return The hash code for <code>objects</code>; or <code>0</code> if * <code>objects</code> is <code>null</code>. + * @deprecated use {@link Arrays#hashCode(Object[])} */ + @Deprecated public static int hashCode(final Object[] objects) { if (objects == null) { return 0; diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java index ac3ead6a4b1..308b0ef439e 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerCell.java @@ -16,6 +16,8 @@ package org.eclipse.jface.viewers; +import java.util.Objects; + import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; @@ -381,7 +383,7 @@ public class ViewerCell { final int prime = 31; int result = 1; result = prime * result + columnIndex; - result = prime * result + ((row == null) ? 0 : row.hashCode()); + result = prime * result + Objects.hashCode(row); return result; } @@ -394,14 +396,7 @@ public class ViewerCell { if (getClass() != obj.getClass()) return false; final ViewerCell other = (ViewerCell) obj; - if (columnIndex != other.columnIndex) - return false; - if (row == null) { - if (other.row != null) - return false; - } else if (!row.equals(other.row)) - return false; - return true; + return columnIndex == other.columnIndex && Objects.equals(row, other.row); } private boolean isVisible() { diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java index a3888baa1dc..8a555fc6ec4 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerRow.java @@ -16,6 +16,8 @@ package org.eclipse.jface.viewers; +import java.util.Objects; + import org.eclipse.jface.util.Policy; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.graphics.Color; @@ -251,11 +253,7 @@ public abstract class ViewerRow implements Cloneable { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((getItem() == null) ? 0 : getItem().hashCode()); - return result; + return Objects.hashCode(getItem()); } @Override @@ -267,12 +265,7 @@ public abstract class ViewerRow implements Cloneable { if (getClass() != obj.getClass()) return false; final ViewerRow other = (ViewerRow) obj; - if (getItem() == null) { - if (other.getItem() != null) - return false; - } else if (!getItem().equals(other.getItem())) - return false; - return true; + return Objects.equals(getItem(), other.getItem()); } /** diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java index 5e462f5ed81..9e70cf47fa7 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormFonts.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.internal.forms.widgets; +import java.util.Arrays; import java.util.HashMap; import org.eclipse.jface.resource.DeviceResourceException; @@ -53,22 +54,14 @@ public class FormFonts { public boolean equals(Object obj) { if (obj instanceof BoldFontDescriptor) { BoldFontDescriptor desc = (BoldFontDescriptor)obj; - if (desc.fFontData.length != fFontData.length) - return false; - for (int i = 0; i < fFontData.length; i++) - if (!fFontData[i].equals(desc.fFontData[i])) - return false; - return true; + return Arrays.equals(fFontData, desc.fFontData); } return false; } @Override public int hashCode() { - int hash = 0; - for (FontData element : fFontData) - hash = hash * 7 + element.hashCode(); - return hash; + return Arrays.hashCode(fFontData); } @Override diff --git a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java index 2bbb2e4aada..8011bd997ca 100644 --- a/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java +++ b/bundles/org.eclipse.ui.forms/src/org/eclipse/ui/internal/forms/widgets/FormImages.java @@ -19,6 +19,7 @@ package org.eclipse.ui.internal.forms.widgets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.LocalResourceManager; @@ -62,13 +63,7 @@ public class FormImages { public boolean equals(Object obj) { if (obj instanceof AbstractImageDescriptor) { AbstractImageDescriptor id = (AbstractImageDescriptor)obj; - if (id.fRGBs.length == fRGBs.length) { - boolean result = id.fLength == fLength; - for (int i = 0; i < fRGBs.length && result; i++) { - result = result && id.fRGBs[i].equals(fRGBs[i]); - } - return result; - } + return fLength == id.fLength && Arrays.equals(fRGBs, id.fRGBs); } return false; } @@ -156,9 +151,9 @@ public class FormImages { ComplexImageDescriptor id = (ComplexImageDescriptor) obj; if (super.equals(obj) && id.fVertical == fVertical && Arrays.equals(id.fPercents, fPercents)) { - if ((id.fBgRGB == null && fBgRGB == null) || - (id.fBgRGB != null && id.fBgRGB.equals(fBgRGB))) + if (Objects.equals(fBgRGB, id.fBgRGB)) { return true; + } // if the only thing that isn't the same is the background color // still return true if it does not matter (percents add up to 100) int sum = 0; @@ -174,9 +169,10 @@ public class FormImages { @Override public int hashCode() { int hash = super.hashCode(); - hash = hash * 7 + Boolean.valueOf(fVertical).hashCode(); - for (int fPercent : fPercents) - hash = hash * 7 + Integer.valueOf(fPercent).hashCode(); + hash = hash * 7 + Boolean.hashCode(fVertical); + for (int fPercent : fPercents) { + hash = hash * 7 + Integer.hashCode(fPercent); + } return hash; } @@ -276,8 +272,8 @@ public class FormImages { @Override public int hashCode() { int hash = super.hashCode(); - hash = hash * 7 + Integer.valueOf(fTheight).hashCode(); - hash = hash * 7 + Integer.valueOf(fMarginHeight).hashCode(); + hash = hash * 7 + Integer.hashCode(fTheight); + hash = hash * 7 + Integer.hashCode(fMarginHeight); return hash; } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQuery.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQuery.java index 8bec4a2ee80..d23480347a4 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQuery.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQuery.java @@ -14,6 +14,9 @@ *******************************************************************************/ package org.eclipse.ui.internal.ide.registry; +import java.util.Arrays; +import java.util.Objects; + import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.ui.internal.ide.Policy; @@ -145,25 +148,8 @@ public class MarkerQuery { } MarkerQuery mq = (MarkerQuery) o; - if (!(type == null ? mq.type == null : type.equals(mq.type))) { - return false; - } - - if (matchTypeChildren != mq.matchTypeChildren) { - return false; - } - - if (attributes.length != mq.attributes.length) { - return false; - } - - for (int i = 0; i < attributes.length; i++) { - if (!(attributes[i].equals(mq.attributes[i]))) { - return false; - } - } - - return true; + return Objects.equals(type, mq.type) && Objects.equals(matchTypeChildren, mq.matchTypeChildren) + && Arrays.equals(attributes, mq.attributes); } @Override diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQueryResult.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQueryResult.java index 09f092c0cc9..4b53dc238e0 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQueryResult.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/registry/MarkerQueryResult.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.ui.internal.ide.registry; +import java.util.Arrays; + /** * Instances of this class represent the result of a specific marker * query. Specifically they contain an ordered collection of marker @@ -57,17 +59,7 @@ public class MarkerQueryResult { } MarkerQueryResult mqr = (MarkerQueryResult) o; - if (values.length != mqr.values.length) { - return false; - } - - for (int i = 0; i < values.length; i++) { - if (!(values[i].equals(mqr.values[i]))) { - return false; - } - } - - return true; + return Arrays.equals(values, mqr.values); } @Override @@ -79,10 +71,6 @@ public class MarkerQueryResult { * Computes the hash code for this instance. */ public void computeHashCode() { - hashCode = 19; - - for (String value : values) { - hashCode = hashCode * 37 + value.hashCode(); - } + hashCode = Arrays.hashCode(values); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerCategory.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerCategory.java index 1f6c8e60d9b..32a331c3796 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerCategory.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerCategory.java @@ -14,6 +14,8 @@ package org.eclipse.ui.internal.views.markers; +import java.util.Objects; + import org.eclipse.core.resources.IMarker; import org.eclipse.osgi.util.NLS; import org.eclipse.ui.views.markers.MarkerItem; @@ -167,8 +169,8 @@ class MarkerCategory extends MarkerSupportItem { final int prime = 31; int result = 1; result = prime * result - + ((markers == null) ? 0 : markers.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); + + Objects.hashCode(markers); + result = prime * result + Objects.hashCode(name); return result; } @@ -181,17 +183,7 @@ class MarkerCategory extends MarkerSupportItem { if (getClass() != obj.getClass()) return false; MarkerCategory other = (MarkerCategory) obj; - if (markers == null) { - if (other.markers != null) - return false; - } else if (!markers.equals(other.markers)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; + return Objects.equals(markers, other.markers) && Objects.equals(name, other.name); } @Override diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java index a7cac9110f9..f2f465f9b1b 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkerEntry.java @@ -18,6 +18,7 @@ package org.eclipse.ui.internal.views.markers; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; @@ -414,10 +415,7 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((marker == null) ? 0 : marker.hashCode()); - return result; + return Objects.hashCode(marker); } @Override @@ -429,13 +427,6 @@ class MarkerEntry extends MarkerSupportItem implements IAdaptable { return false; } MarkerEntry other = (MarkerEntry) obj; - if (marker == null) { - if (other.marker != null) { - return false; - } - } else if (!marker.equals(other.marker)) { - return false; - } - return true; + return Objects.equals(marker, other.marker); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java index 67707063ca4..c3f42162fd9 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/Markers.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.TreeMap; import org.eclipse.core.resources.IMarker; @@ -409,10 +410,7 @@ class Markers { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((builder == null) ? 0 : builder.hashCode()); - return result; + return Objects.hashCode(builder); } @Override @@ -424,13 +422,6 @@ class Markers { return false; } Markers other = (Markers) obj; - if (builder == null) { - if (other.builder != null) { - return false; - } - } else if (!builder.equals(other.builder)) { - return false; - } - return true; + return Objects.equals(builder, other.builder); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersViewColumnsDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersViewColumnsDialog.java index 3eb27bca27c..90cf1b1bd96 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersViewColumnsDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/MarkersViewColumnsDialog.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ITableLabelProvider; @@ -230,10 +231,7 @@ public class MarkersViewColumnsDialog extends ViewerColumnsDialog<FieldEntry> { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((field == null) ? 0 : field.hashCode()); - return result; + return Objects.hashCode(field); } @Override @@ -248,14 +246,7 @@ public class MarkersViewColumnsDialog extends ViewerColumnsDialog<FieldEntry> { return false; } FieldEntry other = (FieldEntry) obj; - if (field == null) { - if (other.field != null) { - return false; - } - } else if (!field.equals(other.field)) { - return false; - } - return true; + return Objects.equals(field, other.field); } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java index cf60ffb3c45..894fb7c0411 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ViewerColumnsDialog.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import java.util.Objects; import java.util.Random; import org.eclipse.core.runtime.IStatus; @@ -746,7 +747,7 @@ abstract class ViewerColumnsDialog<T> extends ViewerSettingsAndStatusDialog { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + Objects.hashCode(key); result = prime * result + keyIndex; return result; } @@ -760,17 +761,7 @@ abstract class ViewerColumnsDialog<T> extends ViewerSettingsAndStatusDialog { return false; } TestData other = (TestData) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (keyIndex != other.keyIndex) { - return false; - } - return true; + return Objects.equals(key, other.key) && keyIndex == other.keyIndex; } @Override diff --git a/bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/CommonActionProviderDescriptor.java b/bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/CommonActionProviderDescriptor.java index c8a008559bb..5e6fbc109e8 100644 --- a/bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/CommonActionProviderDescriptor.java +++ b/bundles/org.eclipse.ui.navigator/src/org/eclipse/ui/internal/navigator/actions/CommonActionProviderDescriptor.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal.navigator.actions; import java.util.Comparator; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; @@ -330,8 +331,8 @@ public class CommonActionProviderDescriptor implements public int hashCode() { final int PRIME = 31; int result = 1; - result = PRIME * result + ((definedId == null) ? 0 : definedId.hashCode()); - result = PRIME * result + ((visibilityId == null) ? 0 : visibilityId.hashCode()); + result = PRIME * result + Objects.hashCode(definedId); + result = PRIME * result + Objects.hashCode(visibilityId); return result; } @@ -344,17 +345,7 @@ public class CommonActionProviderDescriptor implements if (getClass() != obj.getClass()) return false; final CommonActionProviderDescriptor other = (CommonActionProviderDescriptor) obj; - if (definedId == null) { - if (other.definedId != null) - return false; - } else if (!definedId.equals(other.definedId)) - return false; - if (visibilityId == null) { - if (other.visibilityId != null) - return false; - } else if (!visibilityId.equals(other.visibilityId)) - return false; - return true; + return Objects.equals(definedId, other.definedId) && Objects.equals(visibilityId, other.visibilityId); } diff --git a/bundles/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyShowInContext.java b/bundles/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyShowInContext.java index c3410fc3a2f..23399eb1e5e 100644 --- a/bundles/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyShowInContext.java +++ b/bundles/org.eclipse.ui.views/src/org/eclipse/ui/views/properties/PropertyShowInContext.java @@ -14,6 +14,8 @@ package org.eclipse.ui.views.properties; +import java.util.Objects; + import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ShowInContext; @@ -64,9 +66,9 @@ public class PropertyShowInContext extends ShowInContext { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((part == null) ? 0 : part.hashCode()) - + ((getSelection() == null) ? 0 : getSelection().hashCode()) - + ((getInput() == null) ? 0 : getInput().hashCode()); + result = prime * result + Objects.hashCode(part) + + Objects.hashCode(getSelection()) + + Objects.hashCode(getInput()); return result; } @@ -79,24 +81,15 @@ public class PropertyShowInContext extends ShowInContext { if (getClass() != obj.getClass()) return false; PropertyShowInContext other = (PropertyShowInContext) obj; - // part needs to be equal - if (part == null) { - if (other.part != null) - return false; - } else if (!part.equals(other.part)) - return false; - // selection needs to be equal - if (getSelection() == null) { - if (other.getSelection() != null) - return false; - } else if (!getSelection().equals(other.getSelection())) - return false; - // input needs to be equal, but only if both are really set. - // E.g. the property sheet doesn't have an input set if not created by ShowIn > ... - if (getInput() == null || other.getInput() == null) { + if (Objects.equals(part, other.part) && Objects.equals(getSelection(), other.getSelection())) { + // input needs to be equal, but only if both are really set. + // E.g. the property sheet doesn't have an input set if not created by ShowIn > + // ... + if (getInput() == null || other.getInput() == null) { return true; - } else if (!getInput().equals(other.getInput())) - return false; - return true; + } + return getInput().equals(other.getInput()); + } + return false; } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/SelectionEnabler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/SelectionEnabler.java index 3a830e303d6..d649bfc7989 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/SelectionEnabler.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/SelectionEnabler.java @@ -18,6 +18,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; @@ -28,7 +29,6 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.actions.SimpleWildcardTester; import org.eclipse.ui.internal.ActionExpression; import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.model.IWorkbenchAdapter; import org.osgi.framework.Bundle; @@ -204,9 +204,9 @@ public final class SelectionEnabler { public boolean equals(final Object object) { if (object instanceof SelectionEnabler) { final SelectionEnabler that = (SelectionEnabler) object; - return Util.equals(this.classes, that.classes) - && Util.equals(this.enablementExpression, that.enablementExpression) - && Util.equals(this.mode, that.mode); + return Objects.equals(this.classes, that.classes) + && Objects.equals(this.enablementExpression, that.enablementExpression) + && this.mode == that.mode; } return false; @@ -220,9 +220,9 @@ public final class SelectionEnabler { @Override public int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(classes); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(enablementExpression); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(mode); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(classes); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(enablementExpression); + hashCode = hashCode * HASH_FACTOR + Integer.hashCode(mode); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSet.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSet.java index edb1d9e7c64..63bdc299a24 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSet.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AbstractWorkingSet.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal; import java.util.ArrayList; +import java.util.Objects; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Platform; @@ -24,7 +25,6 @@ import org.eclipse.ui.IMemento; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.IWorkingSetManager; -import org.eclipse.ui.internal.util.Util; /** * Abstract baseclass for IWorkingSet implementations. @@ -68,7 +68,7 @@ public abstract class AbstractWorkingSet implements IAdaptable, IWorkingSet, Clo Assert.isNotNull(name, "name must not be null"); //$NON-NLS-1$ this.name = name; this.label = label; - labelBoundToName = Util.equals(name, label); + labelBoundToName = Objects.equals(name, label); uniqueId = Long.toString(System.currentTimeMillis()) + "_" + counter++; //$NON-NLS-1$ } @@ -191,7 +191,7 @@ public abstract class AbstractWorkingSet implements IAdaptable, IWorkingSet, Clo AbstractWorkingSet oldWorkingSet = clone(); this.label = label == null ? getName() : label; - labelBoundToName = Util.equals(label, name); // rebind the label to the name + labelBoundToName = Objects.equals(label, name); // rebind the label to the name fireWorkingSetChanged(IWorkingSetManager.CHANGE_WORKING_SET_LABEL_CHANGE, oldWorkingSet); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionExpression.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionExpression.java index cd80d166b58..677b7e74ca7 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionExpression.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ActionExpression.java @@ -18,13 +18,13 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IActionFilter; import org.eclipse.ui.internal.util.BundleUtility; -import org.eclipse.ui.internal.util.Util; import org.osgi.framework.Bundle; /** @@ -111,7 +111,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof AndExpression) { final AndExpression that = (AndExpression) object; - return Util.equals(this.list, that.list); + return Objects.equals(this.list, that.list); } return false; @@ -197,7 +197,7 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(list); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(list); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -322,7 +322,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof ObjectClassExpression) { final ObjectClassExpression that = (ObjectClassExpression) object; - return Util.equals(this.className, that.className) && Util.equals(this.extracted, that.extracted); + return Objects.equals(this.className, that.className) && Objects.equals(this.extracted, that.extracted); } return false; @@ -342,8 +342,8 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(className); - expressionHashCode = expressionHashCode * HASH_FACTOR + Util.hashCode(extracted); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(className); + expressionHashCode = expressionHashCode * HASH_FACTOR + Objects.hashCode(extracted); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -419,7 +419,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof ObjectStateExpression) { final ObjectStateExpression that = (ObjectStateExpression) object; - return Util.equals(this.name, that.name) && Util.equals(this.value, that.value); + return Objects.equals(this.name, that.name) && Objects.equals(this.value, that.value); } return false; @@ -437,8 +437,8 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(name); - expressionHashCode = expressionHashCode * HASH_FACTOR + Util.hashCode(value); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(name); + expressionHashCode = expressionHashCode * HASH_FACTOR + Objects.hashCode(value); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -518,7 +518,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof OrExpression) { final OrExpression that = (OrExpression) object; - return Util.equals(this.list, that.list); + return Objects.equals(this.list, that.list); } return false; @@ -565,7 +565,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof PluginStateExpression) { final PluginStateExpression that = (PluginStateExpression) object; - return Util.equals(this.id, that.id) && Util.equals(this.value, that.value); + return Objects.equals(this.id, that.id) && Objects.equals(this.value, that.value); } return false; @@ -579,8 +579,8 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(id); - expressionHashCode = expressionHashCode * HASH_FACTOR + Util.hashCode(value); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(id); + expressionHashCode = expressionHashCode * HASH_FACTOR + Objects.hashCode(value); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -647,7 +647,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof SingleExpression) { final SingleExpression that = (SingleExpression) object; - return Util.equals(this.child, that.child); + return Objects.equals(this.child, that.child); } return false; @@ -666,7 +666,7 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(child); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(child); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -728,7 +728,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof SystemPropertyExpression) { final SystemPropertyExpression that = (SystemPropertyExpression) object; - return Util.equals(this.name, that.name) && Util.equals(this.value, that.value); + return Objects.equals(this.name, that.name) && Objects.equals(this.value, that.value); } return false; @@ -742,8 +742,8 @@ public class ActionExpression { @Override public final int hashCode() { if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { - expressionHashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(name); - expressionHashCode = expressionHashCode * HASH_FACTOR + Util.hashCode(value); + expressionHashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(name); + expressionHashCode = expressionHashCode * HASH_FACTOR + Objects.hashCode(value); if (expressionHashCode == HASH_CODE_NOT_COMPUTED) { expressionHashCode++; } @@ -899,7 +899,7 @@ public class ActionExpression { public final boolean equals(final Object object) { if (object instanceof ActionExpression) { final ActionExpression that = (ActionExpression) object; - return Util.equals(this.root, that.root); + return Objects.equals(this.root, that.root); } return false; @@ -926,7 +926,7 @@ public class ActionExpression { @Override public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { - hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(root); + hashCode = HASH_INITIAL * HASH_FACTOR + Objects.hashCode(root); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java index 601a0a1effb..8aa7c19f0af 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/AggregateWorkingSet.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; +import java.util.Objects; import java.util.Set; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.resource.ImageDescriptor; @@ -268,8 +269,8 @@ public class AggregateWorkingSet extends AbstractWorkingSet implements IAggregat if (object instanceof AggregateWorkingSet) { AggregateWorkingSet workingSet = (AggregateWorkingSet) object; - return Util.equals(workingSet.getName(), getName()) - && Util.equals(workingSet.getComponentsInternal(), getComponentsInternal()); + return Objects.equals(workingSet.getName(), getName()) + && Objects.equals(workingSet.getComponentsInternal(), getComponentsInternal()); } return false; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/OverlayIcon.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/OverlayIcon.java index 7acc9b762bc..97f983f2e81 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/OverlayIcon.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/OverlayIcon.java @@ -13,11 +13,11 @@ *******************************************************************************/ package org.eclipse.ui.internal; +import java.util.Objects; import org.eclipse.jface.resource.CompositeImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.internal.util.Util; /** * An OverlayIcon consists of a main icon and an overlay icon @@ -78,7 +78,7 @@ public class OverlayIcon extends CompositeImageDescriptor { @Override public int hashCode() { - return Util.hashCode(fBase) * 17 + Util.hashCode(fOverlay); + return Objects.hashCode(fBase) * 17 + Objects.hashCode(fOverlay); } @Override @@ -87,7 +87,7 @@ public class OverlayIcon extends CompositeImageDescriptor { return false; } OverlayIcon overlayIcon = (OverlayIcon) obj; - return Util.equals(this.fBase, overlayIcon.fBase) && Util.equals(this.fOverlay, overlayIcon.fOverlay) - && Util.equals(this.fSize, overlayIcon.fSize); + return Objects.equals(this.fBase, overlayIcon.fBase) && Objects.equals(this.fOverlay, overlayIcon.fOverlay) + && Objects.equals(this.fSize, overlayIcon.fSize); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PendingSyncExec.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PendingSyncExec.java index 4cffb63e5b2..8bfcda96d77 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PendingSyncExec.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PendingSyncExec.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.internal; +import java.util.Objects; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; @@ -97,7 +98,7 @@ public final class PendingSyncExec { @Override public int hashCode() { - return runnable == null ? 0 : runnable.hashCode(); + return Objects.hashCode(runnable); } public void setOperationThread(Thread operation) { diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java index 6436f4574d7..d5da27bc858 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java @@ -41,6 +41,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.WeakHashMap; import javax.annotation.PostConstruct; @@ -181,7 +182,6 @@ import org.eclipse.ui.internal.registry.ViewDescriptor; import org.eclipse.ui.internal.tweaklets.TabBehaviour; import org.eclipse.ui.internal.tweaklets.Tweaklets; import org.eclipse.ui.internal.util.PrefUtil; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.model.IWorkbenchAdapter; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.ShowInContext; @@ -3672,7 +3672,7 @@ public class WorkbenchPage implements IWorkbenchPage { ISaveablePart2 saveable2 = SaveableHelper.getSaveable2(part); if (saveable2 != null) { WorkbenchPage page = (WorkbenchPage) part.getSite().getPage(); - if (!Util.equals(currentPage, page)) { + if (!Objects.equals(currentPage, page)) { if (currentPage != null && currentPageOriginalPerspective != null) { if (!currentPageOriginalPerspective.equals(currentPage.getActivePerspective())) { currentPage.setPerspective(currentPageOriginalPerspective.getDesc()); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java index 7a13b53b7cb..1f0a228385b 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkingSet.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal; import java.util.HashSet; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import org.eclipse.core.runtime.Adapters; import org.eclipse.core.runtime.IAdaptable; @@ -30,7 +31,6 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.misc.Policy; import org.eclipse.ui.internal.registry.WorkingSetDescriptor; import org.eclipse.ui.internal.registry.WorkingSetRegistry; -import org.eclipse.ui.internal.util.Util; /** * A working set holds a number of IAdaptable elements. A working set is @@ -92,9 +92,9 @@ public class WorkingSet extends AbstractWorkingSet { } if (object instanceof WorkingSet) { WorkingSet workingSet = (WorkingSet) object; - return Util.equals(workingSet.getName(), getName()) - && Util.equals(workingSet.getElementsArray(), getElementsArray()) - && Util.equals(workingSet.getId(), getId()); + return Objects.equals(workingSet.getName(), getName()) + && Objects.equals(workingSet.getElementsArray(), getElementsArray()) + && Objects.equals(workingSet.getId(), getId()); } return false; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Activity.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Activity.java index bb1406e8b63..9e77ce2e497 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Activity.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Activity.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; import org.eclipse.core.expressions.Expression; import org.eclipse.ui.activities.ActivityEvent; @@ -125,28 +126,10 @@ final class Activity implements IActivity { } final Activity castedObject = (Activity) object; - - if (!Util.equals(activityRequirementBindings, castedObject.activityRequirementBindings)) { - return false; - } - - if (!Util.equals(activityPatternBindings, castedObject.activityPatternBindings)) { - return false; - } - - if (!Util.equals(defined, castedObject.defined)) { - return false; - } - - if (!Util.equals(enabled, castedObject.enabled)) { - return false; - } - - if (!Util.equals(id, castedObject.id)) { - return false; - } - - return Util.equals(name, castedObject.name); + return Objects.equals(activityRequirementBindings, castedObject.activityRequirementBindings) + && Objects.equals(activityPatternBindings, castedObject.activityPatternBindings) + && defined == castedObject.defined && enabled == castedObject.enabled + && Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name); } void fireActivityChanged(ActivityEvent activityEvent) { @@ -193,12 +176,12 @@ final class Activity implements IActivity { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityRequirementBindings); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityPatternBindings); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(defined); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(enabled); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(name); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityRequirementBindings); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityPatternBindings); + hashCode = hashCode * HASH_FACTOR + Boolean.hashCode(defined); + hashCode = hashCode * HASH_FACTOR + Boolean.hashCode(enabled); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(id); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(name); if (hashCode == HASH_INITIAL) { hashCode++; } @@ -249,7 +232,7 @@ final class Activity implements IActivity { boolean setActivityRequirementBindings(Set<IActivityRequirementBinding> activityRequirementBindings) { activityRequirementBindings = Util.safeCopy(activityRequirementBindings, IActivityRequirementBinding.class); - if (!Util.equals(activityRequirementBindings, this.activityRequirementBindings)) { + if (!Objects.equals(activityRequirementBindings, this.activityRequirementBindings)) { this.activityRequirementBindings = activityRequirementBindings; this.activityRequirementBindingsAsArray = this.activityRequirementBindings .toArray(new IActivityRequirementBinding[this.activityRequirementBindings.size()]); @@ -264,7 +247,7 @@ final class Activity implements IActivity { boolean setActivityPatternBindings(Set<IActivityPatternBinding> activityPatternBindings) { activityPatternBindings = Util.safeCopy(activityPatternBindings, IActivityPatternBinding.class); - if (!Util.equals(activityPatternBindings, this.activityPatternBindings)) { + if (!Objects.equals(activityPatternBindings, this.activityPatternBindings)) { this.activityPatternBindings = activityPatternBindings; this.activityPatternBindingsAsArray = this.activityPatternBindings .toArray(new IActivityPatternBinding[this.activityPatternBindings.size()]); @@ -299,7 +282,7 @@ final class Activity implements IActivity { } boolean setName(String name) { - if (!Util.equals(name, this.name)) { + if (!Objects.equals(name, this.name)) { this.name = name; hashCode = HASH_INITIAL; string = null; @@ -314,7 +297,7 @@ final class Activity implements IActivity { } boolean setDescription(String description) { - if (!Util.equals(description, this.description)) { + if (!Objects.equals(description, this.description)) { this.description = description; hashCode = HASH_INITIAL; string = null; @@ -362,7 +345,7 @@ final class Activity implements IActivity { } boolean setDefaultEnabled(boolean defaultEnabled) { - if (!Util.equals(defaultEnabled, this.defaultEnabled)) { + if (defaultEnabled != this.defaultEnabled) { this.defaultEnabled = defaultEnabled; hashCode = HASH_INITIAL; string = null; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityDefinition.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityDefinition.java index 9065a53435e..6c28a99b632 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityDefinition.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityDefinition.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.eclipse.core.expressions.Expression; import org.eclipse.ui.internal.util.Util; @@ -119,15 +120,8 @@ public final class ActivityDefinition implements Comparable<ActivityDefinition> } final ActivityDefinition castedObject = (ActivityDefinition) object; - if (!Util.equals(id, castedObject.id)) { - return false; - } - - if (!Util.equals(name, castedObject.name)) { - return false; - } - - return Util.equals(sourceId, castedObject.sourceId); + return Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name) + && Objects.equals(sourceId, castedObject.sourceId); } public String getId() { @@ -145,14 +139,13 @@ public final class ActivityDefinition implements Comparable<ActivityDefinition> @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(name); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(id); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(name); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(sourceId); if (hashCode == HASH_INITIAL) { hashCode++; } } - return hashCode; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBinding.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBinding.java index 84ffb1aab2a..9944f3a30df 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBinding.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBinding.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.activities; +import java.util.Objects; import java.util.regex.Pattern; import org.eclipse.ui.activities.IActivityPatternBinding; import org.eclipse.ui.internal.util.Util; @@ -101,15 +102,9 @@ public final class ActivityPatternBinding implements IActivityPatternBinding { } final ActivityPatternBinding castedObject = (ActivityPatternBinding) object; - if (!Util.equals(activityId, castedObject.activityId)) { - return false; - } - - if (!Util.equals(isEqualityPattern, castedObject.isEqualityPattern)) { - return false; - } - - return Util.equals(getPattern(), castedObject.getPattern()); + return Objects.equals(activityId, castedObject.activityId) + && isEqualityPattern == castedObject.isEqualityPattern + && Objects.equals(getPattern(), castedObject.getPattern()); } @Override @@ -141,13 +136,12 @@ public final class ActivityPatternBinding implements IActivityPatternBinding { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(pattern); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(pattern); if (hashCode == HASH_INITIAL) { hashCode++; } } - return hashCode; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java index 14dc81b4152..c1beb45fd69 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityPatternBindingDefinition.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.eclipse.ui.internal.util.Util; public final class ActivityPatternBindingDefinition { @@ -107,19 +108,9 @@ public final class ActivityPatternBindingDefinition { } final ActivityPatternBindingDefinition castedObject = (ActivityPatternBindingDefinition) object; - if (!Util.equals(activityId, castedObject.activityId)) { - return false; - } - - if (!Util.equals(pattern, castedObject.pattern)) { - return false; - } - - if (!Util.equals(isEqualityPattern, castedObject.isEqualityPattern)) { - return false; - } - - return Util.equals(sourceId, castedObject.sourceId); + return Objects.equals(activityId, castedObject.activityId) && Objects.equals(pattern, castedObject.pattern) + && isEqualityPattern == castedObject.isEqualityPattern + && Objects.equals(sourceId, castedObject.sourceId); } public String getActivityId() { @@ -141,9 +132,9 @@ public final class ActivityPatternBindingDefinition { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(pattern); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(pattern); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(sourceId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java index 3b797747afa..526ba93eb19 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBinding.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.activities; +import java.util.Objects; import org.eclipse.ui.activities.IActivityRequirementBinding; import org.eclipse.ui.internal.util.Util; @@ -58,11 +59,8 @@ public final class ActivityRequirementBinding implements IActivityRequirementBin } final ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object; - if (!Util.equals(requiredActivityId, castedObject.requiredActivityId)) { - return false; - } - - return Util.equals(activityId, castedObject.activityId); + return Objects.equals(requiredActivityId, castedObject.requiredActivityId) + && Objects.equals(activityId, castedObject.activityId); } @Override @@ -78,8 +76,8 @@ public final class ActivityRequirementBinding implements IActivityRequirementBin @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(requiredActivityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(requiredActivityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java index fbd1ba44367..7f4baea62af 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/ActivityRequirementBindingDefinition.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.eclipse.ui.internal.util.Util; public final class ActivityRequirementBindingDefinition { @@ -95,15 +96,9 @@ public final class ActivityRequirementBindingDefinition { } final ActivityRequirementBindingDefinition castedObject = (ActivityRequirementBindingDefinition) object; - if (!Util.equals(requiredActivityId, castedObject.requiredActivityId)) { - return false; - } - - if (!Util.equals(activityId, castedObject.activityId)) { - return false; - } - - return Util.equals(sourceId, castedObject.sourceId); + return Objects.equals(requiredActivityId, castedObject.requiredActivityId) + && Objects.equals(activityId, castedObject.activityId) + && Objects.equals(sourceId, castedObject.sourceId); } public String getRequiredActivityId() { @@ -121,9 +116,9 @@ public final class ActivityRequirementBindingDefinition { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(requiredActivityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(requiredActivityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(sourceId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Category.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Category.java index 47478017efa..497e36509e9 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Category.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Category.java @@ -17,6 +17,7 @@ package org.eclipse.ui.internal.activities; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.eclipse.ui.activities.CategoryEvent; import org.eclipse.ui.activities.ICategory; @@ -102,19 +103,9 @@ final class Category implements ICategory { } final Category castedObject = (Category) object; - if (!Util.equals(categoryActivityBindings, castedObject.categoryActivityBindings)) { - return false; - } - - if (!Util.equals(defined, castedObject.defined)) { - return false; - } - - if (!Util.equals(id, castedObject.id)) { - return false; - } - - return Util.equals(name, castedObject.name); + return Objects.equals(categoryActivityBindings, castedObject.categoryActivityBindings) + && defined == castedObject.defined && Objects.equals(id, castedObject.id) + && Objects.equals(name, castedObject.name); } void fireCategoryChanged(CategoryEvent categoryEvent) { @@ -151,10 +142,10 @@ final class Category implements ICategory { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(categoryActivityBindings); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(defined); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(name); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(categoryActivityBindings); + hashCode = hashCode * HASH_FACTOR + Boolean.hashCode(defined); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(id); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(name); if (hashCode == HASH_INITIAL) { hashCode++; } @@ -186,7 +177,7 @@ final class Category implements ICategory { boolean setCategoryActivityBindings(Set<ICategoryActivityBinding> categoryActivityBindings) { categoryActivityBindings = Util.safeCopy(categoryActivityBindings, ICategoryActivityBinding.class); - if (!Util.equals(categoryActivityBindings, this.categoryActivityBindings)) { + if (!Objects.equals(categoryActivityBindings, this.categoryActivityBindings)) { this.categoryActivityBindings = categoryActivityBindings; this.categoryActivityBindingsAsArray = this.categoryActivityBindings .toArray(new ICategoryActivityBinding[this.categoryActivityBindings.size()]); @@ -210,7 +201,7 @@ final class Category implements ICategory { } boolean setName(String name) { - if (!Util.equals(name, this.name)) { + if (!Objects.equals(name, this.name)) { this.name = name; hashCode = HASH_INITIAL; string = null; @@ -249,7 +240,7 @@ final class Category implements ICategory { } public boolean setDescription(String description) { - if (!Util.equals(description, this.description)) { + if (!Objects.equals(description, this.description)) { this.description = description; hashCode = HASH_INITIAL; string = null; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBinding.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBinding.java index 251058920e2..c401032def5 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBinding.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBinding.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.activities; +import java.util.Objects; import org.eclipse.ui.activities.ICategoryActivityBinding; import org.eclipse.ui.internal.util.Util; @@ -58,11 +59,8 @@ public final class CategoryActivityBinding implements ICategoryActivityBinding { } final CategoryActivityBinding castedObject = (CategoryActivityBinding) object; - if (!Util.equals(activityId, castedObject.activityId)) { - return false; - } - - return Util.equals(categoryId, castedObject.categoryId); + return Objects.equals(activityId, castedObject.activityId) + && Objects.equals(categoryId, castedObject.categoryId); } @Override @@ -78,8 +76,8 @@ public final class CategoryActivityBinding implements ICategoryActivityBinding { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(categoryId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(categoryId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java index ee99fcf0bdf..5fe34aa222e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryActivityBindingDefinition.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.eclipse.ui.internal.util.Util; public final class CategoryActivityBindingDefinition { @@ -92,15 +93,9 @@ public final class CategoryActivityBindingDefinition { } final CategoryActivityBindingDefinition castedObject = (CategoryActivityBindingDefinition) object; - if (!Util.equals(activityId, castedObject.activityId)) { - return false; - } - - if (!Util.equals(categoryId, castedObject.categoryId)) { - return false; - } - - return Util.equals(sourceId, castedObject.sourceId); + return Objects.equals(activityId, castedObject.activityId) + && Objects.equals(categoryId, castedObject.categoryId) + && Objects.equals(sourceId, castedObject.sourceId); } public String getActivityId() { @@ -118,9 +113,9 @@ public final class CategoryActivityBindingDefinition { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(categoryId); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(categoryId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(sourceId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryDefinition.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryDefinition.java index 44abbd28f28..56b20e1097c 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryDefinition.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/CategoryDefinition.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import org.eclipse.ui.internal.util.Util; public final class CategoryDefinition implements Comparable<CategoryDefinition> { @@ -116,15 +117,8 @@ public final class CategoryDefinition implements Comparable<CategoryDefinition> } final CategoryDefinition castedObject = (CategoryDefinition) object; - if (!Util.equals(id, castedObject.id)) { - return false; - } - - if (!Util.equals(name, castedObject.name)) { - return false; - } - - return Util.equals(sourceId, castedObject.sourceId); + return Objects.equals(id, castedObject.id) && Objects.equals(name, castedObject.name) + && Objects.equals(sourceId, castedObject.sourceId); } public String getId() { @@ -142,9 +136,9 @@ public final class CategoryDefinition implements Comparable<CategoryDefinition> @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(name); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(sourceId); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(id); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(name); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(sourceId); if (hashCode == HASH_INITIAL) { hashCode++; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Identifier.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Identifier.java index dc281a32bc7..64b40bdd8ab 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Identifier.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/activities/Identifier.java @@ -17,6 +17,7 @@ package org.eclipse.ui.internal.activities; import java.util.Collections; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import org.eclipse.core.runtime.ListenerList; import org.eclipse.ui.activities.IIdentifier; @@ -90,15 +91,8 @@ final class Identifier implements IIdentifier { } final Identifier castedObject = (Identifier) object; - if (!Util.equals(activityIds, castedObject.activityIds)) { - return false; - } - - if (!Util.equals(enabled, castedObject.enabled)) { - return false; - } - - return Util.equals(id, castedObject.id); + return Objects.equals(activityIds, castedObject.activityIds) && enabled == castedObject.enabled + && Objects.equals(id, castedObject.id); } void fireIdentifierChanged(IdentifierEvent identifierEvent) { @@ -126,14 +120,13 @@ final class Identifier implements IIdentifier { @Override public int hashCode() { if (hashCode == HASH_INITIAL) { - hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityIds); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(enabled); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(activityIds); + hashCode = hashCode * HASH_FACTOR + Boolean.hashCode(enabled); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(id); if (hashCode == HASH_INITIAL) { hashCode++; } } - return hashCode; } @@ -159,7 +152,7 @@ final class Identifier implements IIdentifier { boolean setActivityIds(Set<String> activityIds) { activityIds = Util.safeCopy(activityIds, String.class); - if (!Util.equals(activityIds, this.activityIds)) { + if (!Objects.equals(activityIds, this.activityIds)) { this.activityIds = activityIds; this.activityIdsAsArray = this.activityIds.toArray(new String[this.activityIds.size()]); hashCode = HASH_INITIAL; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java index e2289fc393c..c5565ee1ee1 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Set; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; @@ -73,7 +74,6 @@ import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.misc.StatusUtil; import org.eclipse.ui.internal.progress.ProgressManager; import org.eclipse.ui.internal.registry.EditorRegistry; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; import org.eclipse.ui.statushandlers.StatusManager; @@ -268,7 +268,7 @@ public class ContentTypesPreferencePage extends PreferencePage implements IWorkb List elements = new ArrayList(); IContentType baseType = (IContentType) parentElement; for (IContentType contentType : manager.getAllContentTypes()) { - if (Util.equals(contentType.getBaseType(), baseType)) { + if (Objects.equals(contentType.getBaseType(), baseType)) { elements.add(contentType); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java index 94345e34154..5964048b30b 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PerspectivesPreferencePage.java @@ -23,6 +23,7 @@ import com.ibm.icu.text.Collator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Objects; import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.workbench.modeling.EModelService; @@ -61,7 +62,6 @@ import org.eclipse.ui.internal.registry.PerspectiveDescriptor; import org.eclipse.ui.internal.registry.PerspectiveRegistry; import org.eclipse.ui.internal.util.Descriptors; import org.eclipse.ui.internal.util.PrefUtil; -import org.eclipse.ui.internal.util.Util; /** * The Workbench / Perspectives preference page. @@ -421,7 +421,7 @@ public class PerspectivesPreferencePage extends PreferencePage implements IWorkb @Override public boolean performOk() { // Set the default perspective - if (!Util.equals(defaultPerspectiveId, perspectiveRegistry.getDefaultPerspective())) { + if (!Objects.equals(defaultPerspectiveId, perspectiveRegistry.getDefaultPerspective())) { perspectiveRegistry.setDefaultPerspective(defaultPerspectiveId); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java index 870de0cdb17..f38686fbd91 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PreferenceHistoryEntry.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.internal.dialogs; +import java.util.Objects; import org.eclipse.core.runtime.Assert; /** @@ -81,7 +82,7 @@ final class PreferenceHistoryEntry { if (obj instanceof PreferenceHistoryEntry) { PreferenceHistoryEntry other = (PreferenceHistoryEntry) obj; return id.equals(other.id) - && (argument == null && other.argument == null || argument.equals(other.argument)); + && Objects.equals(argument, other.argument); } return super.equals(obj); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java index 4f2b23637b6..c57cb1b466f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ViewsPreferencePage.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; @@ -549,10 +550,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; + return Objects.hashCode(id); } @Override @@ -564,12 +562,7 @@ public class ViewsPreferencePage extends PreferencePage implements IWorkbenchPre if (getClass() != obj.getClass()) return false; ColorsAndFontsTheme other = (ColorsAndFontsTheme) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; + return Objects.equals(id, other.id); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceBinding.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceBinding.java index c6a107aaee1..933cb30b34d 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceBinding.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeySequenceBinding.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.keys; +import java.util.Objects; import org.eclipse.ui.commands.IKeySequenceBinding; import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.keys.KeySequence; @@ -74,11 +75,7 @@ public final class KeySequenceBinding implements IKeySequenceBinding { } final KeySequenceBinding castedObject = (KeySequenceBinding) object; - if (!Util.equals(keySequence, castedObject.keySequence)) { - return false; - } - - return Util.equals(match, castedObject.match); + return Objects.equals(keySequence, castedObject.keySequence) && match == castedObject.match; } @Override @@ -94,8 +91,8 @@ public final class KeySequenceBinding implements IKeySequenceBinding { public int hashCode() { if (!hashCodeComputed) { hashCode = HASH_INITIAL; - hashCode = hashCode * HASH_FACTOR + Util.hashCode(keySequence); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(match); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(keySequence); + hashCode = hashCode * HASH_FACTOR + Integer.hashCode(match); hashCodeComputed = true; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferencePage.java index 8e5aca43971..bc7c59c35d8 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferencePage.java @@ -35,6 +35,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; import org.eclipse.core.commands.Category; @@ -1937,8 +1938,8 @@ public final class KeysPreferencePage extends PreferencePage implements IWorkben int selection = -1; for (int i = 0; i < items.length; i++) { final Binding binding = (Binding) items[i].getData(ITEM_DATA_KEY); - if ((Util.equals(contextId, binding.getContextId())) - && (Util.equals(triggerSequence, binding.getTriggerSequence()))) { + if ((Objects.equals(contextId, binding.getContextId())) + && (Objects.equals(triggerSequence, binding.getTriggerSequence()))) { selection = i; break; } @@ -1965,7 +1966,7 @@ public final class KeysPreferencePage extends PreferencePage implements IWorkben final Iterator bindingItr = bindings.iterator(); while (bindingItr.hasNext()) { final Binding binding = (Binding) bindingItr.next(); - if (!Util.equals(parameterizedCommand, binding.getParameterizedCommand())) { + if (!Objects.equals(parameterizedCommand, binding.getParameterizedCommand())) { continue; // binding does not match } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/BindingModel.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/BindingModel.java index d096e46532e..b97a33ef72d 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/BindingModel.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/BindingModel.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ParameterizedCommand; @@ -31,7 +32,6 @@ import org.eclipse.jface.bindings.TriggerSequence; import org.eclipse.jface.bindings.keys.KeyBinding; import org.eclipse.jface.bindings.keys.KeySequence; import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.services.IServiceLocator; /** @@ -48,16 +48,16 @@ public class BindingModel extends CommonModel { static final boolean deletes(final Binding del, final Binding binding) { boolean deletes = true; - deletes &= Util.equals(del.getContextId(), binding.getContextId()); - deletes &= Util.equals(del.getTriggerSequence(), binding.getTriggerSequence()); + deletes &= Objects.equals(del.getContextId(), binding.getContextId()); + deletes &= Objects.equals(del.getTriggerSequence(), binding.getTriggerSequence()); if (del.getLocale() != null) { - deletes &= Util.equals(del.getLocale(), binding.getLocale()); + deletes &= Objects.equals(del.getLocale(), binding.getLocale()); } if (del.getPlatform() != null) { - deletes &= Util.equals(del.getPlatform(), binding.getPlatform()); + deletes &= Objects.equals(del.getPlatform(), binding.getPlatform()); } deletes &= (binding.getType() == Binding.SYSTEM); - deletes &= Util.equals(del.getParameterizedCommand(), null); + deletes &= Objects.equals(del.getParameterizedCommand(), null); return deletes; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java index d53d4f58692..fd2537528fb 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/model/KeyController.java @@ -23,6 +23,7 @@ import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; import org.eclipse.core.commands.CommandManager; @@ -95,7 +96,7 @@ public class KeyController { if (!isNotifying()) { return; } - if (Util.equals(oldVal, newVal)) { + if (Objects.equals(oldVal, newVal)) { return; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/preferences/PropertyMapUnion.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/preferences/PropertyMapUnion.java index 157276057c2..7a752dd6ccd 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/preferences/PropertyMapUnion.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/preferences/PropertyMapUnion.java @@ -15,10 +15,9 @@ package org.eclipse.ui.internal.preferences; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; -import org.eclipse.ui.internal.util.Util; - /** * @since 3.1 */ @@ -96,7 +95,7 @@ public class PropertyMapUnion implements IPropertyMap { // Determine if the value is common Object value = toAdd.getValue(key, Object.class); - if (!Util.equals(value, toAdd.getValue(key, Object.class))) { + if (!Objects.equals(value, toAdd.getValue(key, Object.class))) { // Set the value to null if not common localInfo.value = null; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java index 37629137fe0..4ea04060c3f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ActionElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.LegacyActionTools; @@ -58,10 +59,7 @@ public class ActionElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((item == null) ? 0 : item.hashCode()); - return result; + return Objects.hashCode(item); } @Override @@ -73,11 +71,6 @@ public class ActionElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final ActionElement other = (ActionElement) obj; - if (item == null) { - if (other.item != null) - return false; - } else if (!item.equals(other.item)) - return false; - return true; + return Objects.equals(item, other.item); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java index f28863774b6..d61906ef33c 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/CommandElement.java @@ -17,6 +17,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.common.NotDefinedException; @@ -149,10 +150,7 @@ public class CommandElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((command == null) ? 0 : command.hashCode()); - return result; + return Objects.hashCode(command); } @Override @@ -164,11 +162,6 @@ public class CommandElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final CommandElement other = (CommandElement) obj; - if (command == null) { - if (other.command != null) - return false; - } else if (!command.equals(other.command)) - return false; - return true; + return Objects.equals(command, other.command); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java index c6f7adb1c6b..5988abbfe7e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/EditorElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorReference; @@ -76,10 +77,7 @@ public class EditorElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((editorReference == null) ? 0 : editorReference.hashCode()); - return result; + return Objects.hashCode(editorReference); } @Override @@ -91,11 +89,6 @@ public class EditorElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final EditorElement other = (EditorElement) obj; - if (editorReference == null) { - if (other.editorReference != null) - return false; - } else if (!editorReference.equals(other.editorReference)) - return false; - return true; + return Objects.equals(editorReference, other.editorReference); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java index 2f5eba2f981..d7bb51d52ac 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PerspectiveElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; @@ -81,10 +82,7 @@ public class PerspectiveElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((descriptor == null) ? 0 : descriptor.hashCode()); - return result; + return Objects.hashCode(descriptor); } @Override @@ -96,11 +94,6 @@ public class PerspectiveElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final PerspectiveElement other = (PerspectiveElement) obj; - if (descriptor == null) { - if (other.descriptor != null) - return false; - } else if (!descriptor.equals(other.descriptor)) - return false; - return true; + return Objects.equals(descriptor, other.descriptor); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java index 858f336779e..5003b0cd43f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PreferenceElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.jface.preference.IPreferenceNode; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; @@ -93,10 +94,7 @@ public class PreferenceElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((preferenceNode == null) ? 0 : preferenceNode.hashCode()); - return result; + return Objects.hashCode(preferenceNode); } @Override @@ -108,11 +106,6 @@ public class PreferenceElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final PreferenceElement other = (PreferenceElement) obj; - if (preferenceNode == null) { - if (other.preferenceNode != null) - return false; - } else if (!preferenceNode.equals(other.preferenceNode)) - return false; - return true; + return Objects.equals(preferenceNode, other.preferenceNode); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java index ded23b5fd99..ce2f38cd1b5 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/PropertiesElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.jface.preference.IPreferenceNode; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; @@ -68,10 +69,7 @@ public class PropertiesElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((preferenceNode == null) ? 0 : preferenceNode.hashCode()); - return result; + return Objects.hashCode(preferenceNode); } @Override @@ -83,11 +81,6 @@ public class PropertiesElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final PropertiesElement other = (PropertiesElement) obj; - if (preferenceNode == null) { - if (other.preferenceNode != null) - return false; - } else if (!preferenceNode.equals(other.preferenceNode)) - return false; - return true; + return Objects.equals(preferenceNode, other.preferenceNode); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java index c7f49b7e0d8..7fec15e4248 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/ViewElement.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal.quickaccess.providers; import java.net.MalformedURLException; import java.net.URL; +import java.util.Objects; import org.eclipse.e4.ui.model.LocalizationHelper; import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; @@ -123,10 +124,7 @@ public class ViewElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((viewDescriptor == null) ? 0 : viewDescriptor.hashCode()); - return result; + return Objects.hashCode(viewDescriptor); } @Override @@ -138,11 +136,6 @@ public class ViewElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final ViewElement other = (ViewElement) obj; - if (viewDescriptor == null) { - if (other.viewDescriptor != null) - return false; - } else if (!viewDescriptor.equals(other.viewDescriptor)) - return false; - return true; + return Objects.equals(viewDescriptor, other.viewDescriptor); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java index 85f241c7613..4b760a1e9c7 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/quickaccess/providers/WizardElement.java @@ -14,6 +14,7 @@ package org.eclipse.ui.internal.quickaccess.providers; +import java.util.Objects; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -59,10 +60,7 @@ public class WizardElement extends QuickAccessElement { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((wizardDescriptor == null) ? 0 : wizardDescriptor.hashCode()); - return result; + return Objects.hashCode(wizardDescriptor); } @Override @@ -74,11 +72,6 @@ public class WizardElement extends QuickAccessElement { if (getClass() != obj.getClass()) return false; final WizardElement other = (WizardElement) obj; - if (wizardDescriptor == null) { - if (other.wizardDescriptor != null) - return false; - } else if (!wizardDescriptor.equals(other.wizardDescriptor)) - return false; - return true; + return Objects.equals(wizardDescriptor, other.wizardDescriptor); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java index d46a1ac70b8..709dff84066 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java @@ -39,6 +39,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.StringTokenizer; import org.eclipse.core.commands.common.EventManager; import org.eclipse.core.runtime.IConfigurationElement; @@ -78,7 +79,6 @@ import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.editorsupport.ComponentSupport; import org.eclipse.ui.internal.misc.ExternalProgramImageDescriptor; import org.eclipse.ui.internal.misc.ProgramImageDescriptor; -import org.eclipse.ui.internal.util.Util; /** * Provides access to the collection of defined editors for resource types. @@ -1703,9 +1703,9 @@ class MockMapping implements IFileEditorMapping { return false; } - if (!Util.equals(this.getEditors(), mapping.getEditors())) { + if (!Objects.equals(this.getEditors(), mapping.getEditors())) { return false; } - return Util.equals(this.getDeletedEditors(), mapping.getDeletedEditors()); + return Objects.equals(this.getDeletedEditors(), mapping.getDeletedEditors()); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/FileEditorMapping.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/FileEditorMapping.java index 56fb365b9fb..3dac1ca16b7 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/FileEditorMapping.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/FileEditorMapping.java @@ -17,8 +17,8 @@ package org.eclipse.ui.internal.registry; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.TextProcessor; @@ -116,51 +116,21 @@ public class FileEditorMapping extends Object implements IFileEditorMapping, Clo return false; } FileEditorMapping mapping = (FileEditorMapping) obj; - if (!this.name.equals(mapping.name)) { - return false; - } - if (!this.extension.equals(mapping.extension)) { - return false; - } - - if (!compareList(this.editors, mapping.editors)) { - return false; - } - if (!compareList(this.declaredDefaultEditors, mapping.declaredDefaultEditors)) { - return false; - } - return compareList(this.deletedEditors, mapping.deletedEditors); - } - - /** - * Compare the editor ids from both lists and return true if they are equals. - */ - private boolean compareList(List<IEditorDescriptor> l1, List<IEditorDescriptor> l2) { - if (l1.size() != l2.size()) { - return false; - } - - Iterator<IEditorDescriptor> i1 = l1.iterator(); - Iterator<IEditorDescriptor> i2 = l2.iterator(); - while (i1.hasNext() && i2.hasNext()) { - Object o1 = i1.next(); - Object o2 = i2.next(); - if (!(o1 == null ? o2 == null : o1.equals(o2))) { - return false; - } - } - return true; + return Objects.equals(name, mapping.name) && Objects.equals(extension, mapping.extension) + && Objects.equals(editors, mapping.editors) + && Objects.equals(declaredDefaultEditors, mapping.declaredDefaultEditors) + && Objects.equals(deletedEditors, mapping.deletedEditors); } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((declaredDefaultEditors == null) ? 0 : declaredDefaultEditors.hashCode()); - result = prime * result + ((deletedEditors == null) ? 0 : deletedEditors.hashCode()); - result = prime * result + ((editors == null) ? 0 : editors.hashCode()); - result = prime * result + ((extension == null) ? 0 : extension.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + Objects.hashCode(declaredDefaultEditors); + result = prime * result + Objects.hashCode(deletedEditors); + result = prime * result + Objects.hashCode(editors); + result = prime * result + Objects.hashCode(extension); + result = prime * result + Objects.hashCode(name); return result; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActionSetSourceProvider.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActionSetSourceProvider.java index 94dd056de65..9bad956f4ae 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActionSetSourceProvider.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/ActionSetSourceProvider.java @@ -16,13 +16,12 @@ package org.eclipse.ui.internal.services; import java.util.HashMap; import java.util.Map; - +import java.util.Objects; import org.eclipse.ui.AbstractSourceProvider; import org.eclipse.ui.ISources; import org.eclipse.ui.internal.ActionSetsEvent; import org.eclipse.ui.internal.menus.IActionSetsListener; import org.eclipse.ui.internal.registry.IActionSetDescriptor; -import org.eclipse.ui.internal.util.Util; /** * <p> @@ -55,7 +54,7 @@ public final class ActionSetSourceProvider extends AbstractSourceProvider implem @Override public void actionSetsChanged(final ActionSetsEvent event) { final IActionSetDescriptor[] newActionSets = event.getNewActionSets(); - if (!Util.equals(newActionSets, activeActionSets)) { + if (!Objects.equals(newActionSets, activeActionSets)) { if (DEBUG) { final StringBuilder message = new StringBuilder(); message.append("Action sets changed to ["); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationResultCacheComparator.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationResultCacheComparator.java index 4df61a573a8..3ea466f51bd 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationResultCacheComparator.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/EvaluationResultCacheComparator.java @@ -15,7 +15,7 @@ package org.eclipse.ui.internal.services; import java.util.Comparator; - +import java.util.Objects; import org.eclipse.ui.internal.util.Util; /** @@ -36,7 +36,7 @@ public final class EvaluationResultCacheComparator implements Comparator { @Override public int compare(final Object object1, final Object object2) { - if (Util.equals(object2, object1)) { + if (Objects.equals(object2, object1)) { return 0; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/PreferencePersistence.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/PreferencePersistence.java index 84cf7f44d4a..532af333e72 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/PreferencePersistence.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/PreferencePersistence.java @@ -17,7 +17,7 @@ package org.eclipse.ui.internal.services; import java.util.ArrayList; import java.util.Collection; import java.util.List; - +import java.util.Objects; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.IParameter; import org.eclipse.core.commands.Parameterization; @@ -31,7 +31,6 @@ import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.ui.IMemento; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.util.Util; /** * <p> @@ -251,7 +250,7 @@ public abstract class PreferencePersistence extends RegistryPersistence { final IParameter[] commandParameters = command.getParameters(); if (commandParameters != null) { for (final IParameter currentParameter : commandParameters) { - if (Util.equals(currentParameter.getId(), id)) { + if (Objects.equals(currentParameter.getId(), id)) { parameter = currentParameter; break; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/RegistryPersistence.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/RegistryPersistence.java index 2b6acd30cb2..f3c42fef8ec 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/RegistryPersistence.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/RegistryPersistence.java @@ -17,7 +17,7 @@ package org.eclipse.ui.internal.services; import java.util.ArrayList; import java.util.Collection; import java.util.List; - +import java.util.Objects; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.IParameter; import org.eclipse.core.commands.Parameterization; @@ -41,7 +41,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.services.IDisposable; /** @@ -357,7 +356,7 @@ public abstract class RegistryPersistence implements IDisposable, IWorkbenchRegi final IParameter[] commandParameters = command.getParameters(); if (parameters != null) { for (final IParameter currentParameter : commandParameters) { - if (Util.equals(currentParameter.getId(), id)) { + if (Objects.equals(currentParameter.getId(), id)) { parameter = currentParameter; break; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java index 4672f13a595..b37965da3ac 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/services/WorkbenchSourceProvider.java @@ -17,6 +17,7 @@ package org.eclipse.ui.internal.services; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.core.runtime.Adapters; import org.eclipse.jface.util.IPropertyChangeListener; @@ -44,7 +45,6 @@ import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.internal.WorkbenchWindow; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.services.IServiceLocator; @@ -136,7 +136,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I @Override public final void selectionChanged(final IWorkbenchPart part, final ISelection newSelection) { - if (Util.equals(selection, newSelection)) + if (Objects.equals(selection, newSelection)) return; // we have already handled the change selection = newSelection; @@ -285,7 +285,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I // Figure out what was changed. final Object newActivePart = currentState.get(ISources.ACTIVE_PART_NAME); - if (!Util.equals(newActivePart, lastActivePart)) { + if (!Objects.equals(newActivePart, lastActivePart)) { sources |= ISources.ACTIVE_PART; if (newActivePart != IEvaluationContext.UNDEFINED_VARIABLE) { lastActivePart = (IWorkbenchPart) newActivePart; @@ -294,7 +294,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I } } final Object newActivePartId = currentState.get(ISources.ACTIVE_PART_ID_NAME); - if (!Util.equals(newActivePartId, lastActivePartId)) { + if (!Objects.equals(newActivePartId, lastActivePartId)) { sources |= ISources.ACTIVE_PART_ID; if (newActivePartId != IEvaluationContext.UNDEFINED_VARIABLE) { lastActivePartId = (String) newActivePartId; @@ -303,7 +303,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I } } final Object newActivePartSite = currentState.get(ISources.ACTIVE_SITE_NAME); - if (!Util.equals(newActivePartSite, lastActivePartSite)) { + if (!Objects.equals(newActivePartSite, lastActivePartSite)) { sources |= ISources.ACTIVE_SITE; if (newActivePartSite != IEvaluationContext.UNDEFINED_VARIABLE) { lastActivePartSite = (IWorkbenchPartSite) newActivePartSite; @@ -312,13 +312,13 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I } } final Object newShowInInput = currentState.get(ISources.SHOW_IN_INPUT); - if (!Util.equals(newShowInInput, lastShowInInput)) { + if (!Objects.equals(newShowInInput, lastShowInInput)) { sources |= ISources.ACTIVE_SITE; lastShowInInput = newShowInInput; } if (updateShowInSelection) { final Object newShowInSelection = currentState.get(ISources.SHOW_IN_SELECTION); - if (!Util.equals(newShowInSelection, lastShowInSelection)) { + if (!Objects.equals(newShowInSelection, lastShowInSelection)) { sources |= ISources.ACTIVE_SITE; if (newShowInSelection != IEvaluationContext.UNDEFINED_VARIABLE) { lastShowInSelection = (ISelection) newShowInSelection; @@ -328,14 +328,14 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I } } Object newActiveEditor = currentState.get(ISources.ACTIVE_EDITOR_NAME); - if (!Util.equals(newActiveEditor, lastActiveEditor)) { + if (!Objects.equals(newActiveEditor, lastActiveEditor)) { sources |= ISources.ACTIVE_EDITOR; newActiveEditor = (newActiveEditor == IEvaluationContext.UNDEFINED_VARIABLE ? null : newActiveEditor); hookListener(lastActiveEditor, (IEditorPart) newActiveEditor); lastActiveEditor = (IEditorPart) newActiveEditor; } Object newEditorInput = currentState.get(ISources.ACTIVE_EDITOR_INPUT_NAME); - if (!Util.equals(newEditorInput, lastEditorInput)) { + if (!Objects.equals(newEditorInput, lastEditorInput)) { sources |= ISources.ACTIVE_EDITOR; if (newEditorInput != IEvaluationContext.UNDEFINED_VARIABLE) { lastEditorInput = (IEditorInput) newEditorInput; @@ -344,7 +344,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I } } final Object newActiveEditorId = currentState.get(ISources.ACTIVE_EDITOR_ID_NAME); - if (!Util.equals(newActiveEditorId, lastActiveEditorId)) { + if (!Objects.equals(newActiveEditorId, lastActiveEditorId)) { sources |= ISources.ACTIVE_EDITOR_ID; if (newActiveEditorId != IEvaluationContext.UNDEFINED_VARIABLE) { lastActiveEditorId = (String) newActiveEditorId; @@ -573,7 +573,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I @Override public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { String id = perspective == null ? null : perspective.getId(); - if (Util.equals(lastPerspectiveId, id)) { + if (Objects.equals(lastPerspectiveId, id)) { return; } @@ -645,7 +645,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I final boolean statusLineChanged = newStatusLineVis != lastStatusLineVisibility; final boolean perspectiveBarChanged = newPerspectiveBarVisibility != lastPerspectiveBarVisibility; - final boolean perspectiveIdChanged = !Util.equals(lastPerspectiveId, perspectiveId); + final boolean perspectiveIdChanged = !Objects.equals(lastPerspectiveId, perspectiveId); // Fire an event for those sources that have changed. if (shellChanged && windowChanged) { final Map sourceValuesByName1 = new HashMap(5); @@ -758,7 +758,7 @@ public class WorkbenchSourceProvider extends AbstractSourceProvider implements I protected void handleInputChanged(IEditorPart editor) { IEditorInput newInput = editor.getEditorInput(); - if (!Util.equals(newInput, lastEditorInput)) { + if (!Objects.equals(newInput, lastEditorInput)) { fireSourceChanged(ISources.ACTIVE_EDITOR, ISources.ACTIVE_EDITOR_INPUT_NAME, newInput == null ? IEvaluationContext.UNDEFINED_VARIABLE : newInput); lastEditorInput = newInput; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/Theme.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/Theme.java index dd5795f72d6..ab8709d4b97 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/Theme.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/themes/Theme.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.internal.themes; +import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; import org.eclipse.core.commands.common.EventManager; @@ -31,7 +32,6 @@ import org.eclipse.ui.IWorkbenchPreferenceConstants; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.WorkbenchPlugin; import org.eclipse.ui.internal.util.PrefUtil; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.themes.ITheme; import org.eclipse.ui.themes.IThemeManager; @@ -110,7 +110,7 @@ public class Theme extends EventManager implements ITheme { try { String thisTheme = getId(); - if (Util.equals(thisTheme, theme)) { + if (Objects.equals(thisTheme, theme)) { if (getFontRegistry().hasValueFor(key)) { FontData[] data = event.getNewValue() instanceof String ? PreferenceConverter.basicGetFontData((String) event.getNewValue()) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/tweaklets/Tweaklets.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/tweaklets/Tweaklets.java index 235bbd01955..b4ad98aee4e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/tweaklets/Tweaklets.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/tweaklets/Tweaklets.java @@ -16,6 +16,7 @@ package org.eclipse.ui.internal.tweaklets; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -42,10 +43,7 @@ public class Tweaklets { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((tweakClass == null) ? 0 : tweakClass.hashCode()); - return result; + return Objects.hashCode(tweakClass); } @Override @@ -57,12 +55,7 @@ public class Tweaklets { if (getClass() != obj.getClass()) return false; final TweakKey other = (TweakKey) obj; - if (tweakClass == null) { - if (other.tweakClass != null) - return false; - } else if (!tweakClass.equals(other.tweakClass)) - return false; - return true; + return Objects.equals(tweakClass, other.tweakClass); } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/Util.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/Util.java index 1ddacb712e4..684d0f9d92f 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/Util.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/util/Util.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.MissingResourceException; +import java.util.Objects; import java.util.ResourceBundle; import java.util.Set; import java.util.SortedMap; @@ -205,7 +206,7 @@ public final class Util { if (!right.containsKey(key)) { leftOnly.add(key); - } else if (!Util.equals(leftEntry.getValue(), right.get(key))) { + } else if (!Objects.equals(leftEntry.getValue(), right.get(key))) { different.add(key); } } @@ -255,7 +256,7 @@ public final class Util { } for (int i = 0; i < r; i++) { - if (!equals(left.get(l - i - 1), right.get(r - i - 1))) { + if (!Objects.equals(left.get(l - i - 1), right.get(r - i - 1))) { return false; } } @@ -275,7 +276,7 @@ public final class Util { } for (int i = 0; i < r; i++) { - if (!equals(left[l - i - 1], right[r - i - 1])) { + if (!Objects.equals(left[l - i - 1], right[r - i - 1])) { return false; } } @@ -283,68 +284,6 @@ public final class Util { return true; } - public static boolean equals(boolean left, boolean right) { - return left == right; - } - - public static boolean equals(int left, int right) { - return left == right; - } - - public static boolean equals(Object left, Object right) { - return left == null ? right == null : ((right != null) && left.equals(right)); - } - - /** - * Tests whether two arrays of objects are equal to each other. The arrays must - * not be <code>null</code>, but their elements may be <code>null</code>. - * - * @param leftArray The left array to compare; may be <code>null</code>, and - * may be empty and may contain <code>null</code> elements. - * @param rightArray The right array to compare; may be <code>null</code>, and - * may be empty and may contain <code>null</code> elements. - * @return <code>true</code> if the arrays are equal length and the elements at - * the same position are equal; <code>false</code> otherwise. - */ - public static boolean equals(final Object[] leftArray, final Object[] rightArray) { - if (leftArray == rightArray) { - return true; - } - - if (leftArray == null) { - return (rightArray == null); - } else if (rightArray == null) { - return false; - } - - if (leftArray.length != rightArray.length) { - return false; - } - - for (int i = 0; i < leftArray.length; i++) { - final Object left = leftArray[i]; - final Object right = rightArray[i]; - final boolean equal = (left == null) ? (right == null) : (left.equals(right)); - if (!equal) { - return false; - } - } - - return true; - } - - public static int hashCode(boolean b) { - return b ? Boolean.TRUE.hashCode() : Boolean.FALSE.hashCode(); - } - - public static int hashCode(int i) { - return i; - } - - public static int hashCode(Object object) { - return object != null ? object.hashCode() : 0; - } - public static Collection safeCopy(Collection collection, Class c) { return safeCopy(collection, c, false); } @@ -477,7 +416,7 @@ public final class Util { } for (int i = 0; i < r; i++) { - if (!equals(left.get(i), right.get(i))) { + if (!Objects.equals(left.get(i), right.get(i))) { return false; } } @@ -498,7 +437,7 @@ public final class Util { } for (int i = 0; i < r; i++) { - if (!equals(left[i], right[i])) { + if (!Objects.equals(left[i], right[i])) { return false; } } @@ -566,7 +505,7 @@ public final class Util { /** * Returns an interned representation of the given string - * + * * @param string The string to intern * @return The interned string */ @@ -592,7 +531,7 @@ public final class Util { * Creates a {@link String} representing the elements in <code>items</code> as a * list. This method uses the {@link Object#toString()} method on the objects to * create them as a String. - * + * * @param items the List to make into a String * @return a string which presents <code>items</code> in String form. */ @@ -614,7 +553,7 @@ public final class Util { * Creates a {@link String} representing the elements in <code>items</code> as a * list. This method uses the {@link Object#toString()} method on the objects to * create them as a String. - * + * * @param items the array to make into a String * @return a string which presents <code>items</code> in String form. */ diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/Key.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/Key.java index f1610d063b3..954d4571fbc 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/Key.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/Key.java @@ -14,6 +14,7 @@ package org.eclipse.ui.keys; +import java.util.Objects; import org.eclipse.jface.bindings.keys.IKeyLookup; import org.eclipse.jface.bindings.keys.KeyLookupFactory; import org.eclipse.ui.internal.util.Util; @@ -81,7 +82,7 @@ public abstract class Key implements Comparable { @Override public final int hashCode() { - return Util.hashCode(key); + return Objects.hashCode(key); } /** diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/KeyStroke.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/KeyStroke.java index 482a77e1123..dd8532d52aa 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/KeyStroke.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/KeyStroke.java @@ -17,6 +17,7 @@ package org.eclipse.ui.keys; import java.util.Arrays; import java.util.Collections; import java.util.Locale; +import java.util.Objects; import java.util.Set; import java.util.SortedSet; import java.util.StringTokenizer; @@ -269,7 +270,7 @@ public final class KeyStroke implements Comparable { if (!modifierKeys.equals(castedObject.modifierKeys)) { return false; } - return Util.equals(naturalKey, castedObject.naturalKey); + return Objects.equals(naturalKey, castedObject.naturalKey); } /** @@ -307,7 +308,7 @@ public final class KeyStroke implements Comparable { if (!hashCodeComputed) { hashCode = HASH_INITIAL; hashCode = hashCode * HASH_FACTOR + modifierKeys.hashCode(); - hashCode = hashCode * HASH_FACTOR + Util.hashCode(naturalKey); + hashCode = hashCode * HASH_FACTOR + Objects.hashCode(naturalKey); hashCodeComputed = true; } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/IntroPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/IntroPart.java index 361b036ea1e..ed52d2d9b94 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/IntroPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/IntroPart.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.part; +import java.util.Objects; import org.eclipse.core.commands.common.EventManager; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; @@ -31,7 +32,6 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.intro.IntroMessages; import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.intro.IIntroPart; import org.eclipse.ui.intro.IIntroSite; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -289,7 +289,7 @@ public abstract class IntroPart extends EventManager implements IIntroPart, IExe */ protected void setTitle(String titleLabel) { Assert.isNotNull(titleLabel); - if (Util.equals(this.titleLabel, titleLabel)) + if (Objects.equals(this.titleLabel, titleLabel)) return; this.titleLabel = titleLabel; firePropertyChange(IIntroPart.PROP_TITLE); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/ViewPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/ViewPart.java index 2eef2f2c6ee..70beb08cfa6 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/ViewPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/ViewPart.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ui.part; +import java.util.Objects; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.ui.IMemento; @@ -22,7 +23,6 @@ import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchPartConstants; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.PartInitException; -import org.eclipse.ui.internal.util.Util; /** * Abstract base implementation of all workbench views. @@ -153,7 +153,7 @@ public abstract class ViewPart extends WorkbenchPart implements IViewPart { String partName = getPartName(); String title = getTitle(); - if (Util.equals(partName, title)) { + if (Objects.equals(partName, title)) { internalSetContentDescription(""); //$NON-NLS-1$ } else { internalSetContentDescription(title); diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java index 32ec8d1d85d..8480e072ebb 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/WorkbenchPart.java @@ -18,6 +18,7 @@ import com.ibm.icu.text.MessageFormat; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.eclipse.core.commands.common.EventManager; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; @@ -278,7 +279,7 @@ public abstract class WorkbenchPart extends EventManager title = Util.safeString(title); // Do not send changes if they are the same - if (Util.equals(this.title, title)) { + if (Objects.equals(this.title, title)) { return; } this.title = title; @@ -313,7 +314,7 @@ public abstract class WorkbenchPart extends EventManager protected void setTitleToolTip(String toolTip) { toolTip = Util.safeString(toolTip); // Do not send changes if they are the same - if (Util.equals(this.toolTip, toolTip)) { + if (Objects.equals(this.toolTip, toolTip)) { return; } this.toolTip = toolTip; @@ -322,7 +323,7 @@ public abstract class WorkbenchPart extends EventManager /** * Show that this part is busy due to a Job running that it is listening to. - * + * * @param busy boolean to indicate that the busy state has started or ended. * @see org.eclipse.ui.progress.IWorkbenchSiteProgressService#showBusyForFamily(Object) * @since 3.0 @@ -369,7 +370,7 @@ public abstract class WorkbenchPart extends EventManager String name = getPartName(); String newTitle = name; - if (!Util.equals(description, "")) { //$NON-NLS-1$ + if (!Objects.equals(description, "")) { //$NON-NLS-1$ newTitle = MessageFormat.format(WorkbenchMessages.WorkbenchPart_AutoTitleFormat, name, description); } @@ -417,7 +418,7 @@ public abstract class WorkbenchPart extends EventManager Assert.isNotNull(description); // Do not send changes if they are the same - if (Util.equals(contentDescription, description)) { + if (Objects.equals(contentDescription, description)) { return; } this.contentDescription = description; @@ -435,7 +436,7 @@ public abstract class WorkbenchPart extends EventManager Assert.isNotNull(partName); // Do not send changes if they are the same - if (Util.equals(this.partName, partName)) { + if (Objects.equals(this.partName, partName)) { return; } this.partName = partName; diff --git a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java index a3efe1df1d6..106562b5b55 100644 --- a/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java +++ b/tests/org.eclipse.jface.tests.databinding/src/org/eclipse/jface/tests/databinding/wizard/WizardPageSupportTest.java @@ -20,6 +20,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.Objects; + import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.ValidationStatusProvider; import org.eclipse.core.databinding.observable.Diffs; @@ -33,7 +35,6 @@ import org.eclipse.core.databinding.observable.value.AbstractObservableValue; import org.eclipse.core.databinding.observable.value.IObservableValue; import org.eclipse.core.databinding.observable.value.WritableValue; import org.eclipse.core.databinding.validation.ValidationStatus; -import org.eclipse.core.internal.commands.util.Util; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.databinding.dialog.ValidationMessageProvider; import org.eclipse.jface.databinding.wizard.WizardPageSupport; @@ -215,7 +216,7 @@ public class WizardPageSupportTest extends AbstractSWTTestCase { protected void doSetValue(IStatus value) { IStatus oldValue = this.value; this.value = value; - if (!Util.equals(oldValue, value)) { + if (!Objects.equals(oldValue, value)) { fireValueChange(Diffs.createValueDiff(oldValue, value)); } } diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/services/EditorSourceTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/services/EditorSourceTest.java index 752f3fe1654..0f0e031a9b4 100644 --- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/services/EditorSourceTest.java +++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/services/EditorSourceTest.java @@ -15,6 +15,8 @@ package org.eclipse.ui.tests.services; +import java.util.Objects; + import org.eclipse.core.expressions.EvaluationResult; import org.eclipse.core.expressions.Expression; import org.eclipse.core.expressions.ExpressionInfo; @@ -30,7 +32,6 @@ import org.eclipse.ui.ISources; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.services.IEvaluationService; import org.eclipse.ui.tests.api.MockReusableEditorPart; @@ -73,7 +74,7 @@ public class EditorSourceTest extends UITestCase { @Override public EvaluationResult evaluate(IEvaluationContext context) { stateInput = context.getVariable(ISources.ACTIVE_EDITOR_INPUT_NAME); - return EvaluationResult.valueOf(Util + return EvaluationResult.valueOf(Objects .equals(stateInput, editorInput)); } |
