-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use equalsTo() for string comparison instead of == #16714
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
|
@@ -105,7 +106,7 @@ public List<String> resolveIndexAbstractions( | |
|
||
// we always need to check for date math expressions | ||
final String dateMathName = indexNameExpressionResolver.resolveDateMathExpression(indexAbstraction); | ||
if (dateMathName != indexAbstraction) { | ||
if (!Objects.equals(dateMathName, indexAbstraction)) { | ||
assert dateMathName.equals(indexAbstraction) == false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering why do we even need this assertion. Why can remove this since that's the entry criteria in this block. |
||
if (replaceWildcards && Regex.isSimpleMatchPattern(dateMathName)) { | ||
// continue | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ public void add(Term[] terms) { | |
*/ | ||
public void add(Term[] terms, int position) { | ||
for (int i = 0; i < terms.length; i++) { | ||
if (terms[i].field() != field) { | ||
if (!Objects.equals(terms[i].field(), field)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw new IllegalArgumentException("All phrase terms must be in the same field (" + field + "): " + terms[i]); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think either of the 2 is null - can you verify once. If they are non-null than
s1.equals(s2)
will be slightly (unnoticeable but still) faster.