Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/aria/client/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getAriaValue() {
}

private void init(String elementId) {
assert elementId != null || elementId.equals("") :
assert elementId != null && !elementId.isEmpty() :
"Invalid elementId: cannot be null or empty.";
this.id = elementId;
}
Expand Down
11 changes: 4 additions & 7 deletions user/src/com/google/gwt/cell/client/EditTextCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;

import java.util.Locale;
import java.util.Objects;

/**
* An editable text cell. Click to edit, escape to cancel, return to commit.
Expand Down Expand Up @@ -83,12 +84,12 @@ public ViewData(String text) {

@Override
public boolean equals(Object o) {
if (o == null) {
if (!(o instanceof ViewData)) {
return false;
}
ViewData vd = (ViewData) o;
return equalsOrBothNull(original, vd.original)
&& equalsOrBothNull(text, vd.text) && isEditing == vd.isEditing
return Objects.equals(original, vd.original)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, use pattern match instanceof in the return here, something like

Suggested change
return Objects.equals(original, vd.original)
return o instanceof ViewData vd
&& Objects.equals(original, vd.original)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to start using Java 17 features?

&& Objects.equals(text, vd.text) && isEditing == vd.isEditing
&& isEditingAgain == vd.isEditingAgain;
}

Expand Down Expand Up @@ -129,10 +130,6 @@ public void setEditing(boolean isEditing) {
public void setText(String text) {
this.text = text;
}

private boolean equalsOrBothNull(Object o1, Object o2) {
return (o1 == null) ? o2 == null : o1.equals(o2);
}
}

private static Template template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* An ordered list containing the sort history of {@link Column}s in a table.
Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean equals(Object obj) {
}

ColumnSortInfo other = (ColumnSortInfo) obj;
return equalsOrBothNull(getColumn(), other.getColumn())
return Objects.equals(getColumn(), other.getColumn())
&& isAscending() == other.isAscending();
}

Expand All @@ -93,10 +94,6 @@ public int hashCode() {
public boolean isAscending() {
return ascending;
}

private boolean equalsOrBothNull(Object a, Object b) {
return a == null ? b == null : a.equals(b);
}
}

/**
Expand Down
9 changes: 3 additions & 6 deletions user/src/com/google/gwt/view/client/SingleSelectionModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.gwt.view.client.SelectionModel.AbstractSelectionModel;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -93,7 +94,7 @@ public void setSelected(T item, boolean selected) {
if (!selected) {
Object oldKey = newSelectedPending ? getKey(newSelectedItem) : curKey;
Object newKey = getKey(item);
if (!equalsOrBothNull(oldKey, newKey)) {
if (!Objects.equals(oldKey, newKey)) {
return;
}
}
Expand All @@ -111,17 +112,13 @@ protected void fireSelectionChangeEvent() {
resolveChanges();
}

private boolean equalsOrBothNull(Object a, Object b) {
return (a == null) ? (b == null) : a.equals(b);
}

private void resolveChanges() {
if (!newSelectedPending) {
return;
}

Object key = getKey(newSelectedItem);
boolean sameKey = equalsOrBothNull(curKey, key);
boolean sameKey = Objects.equals(curKey, key);
boolean changed = false;
if (newSelected) {
changed = !sameKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* Wraps an {@link EventBus} to keep a count of registered handlers and how many times events have
Expand Down Expand Up @@ -130,8 +131,8 @@ public boolean equals(Object o) {
return false;
}

TypeSourcePair pair = (TypeSourcePair) o;
return doNullEquals(type, pair.type) && doNullEquals(source, pair.source);
TypeSourcePair pair = (TypeSourcePair) o;
return Objects.equals(type, pair.type) && Objects.equals(source, pair.source);
}

@Override
Expand All @@ -141,13 +142,6 @@ public int hashCode() {
hash = (hash * 31) + (source == null ? 0 : source.hashCode());
return hash;
}

private boolean doNullEquals(Object a, Object b) {
if ((a == null) ^ (b == null)) {
return false;
}
return ((a == null) && (b == null)) || a.equals(b);
}
}

private class KeyedCounter<K> {
Expand Down
Loading