Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -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)) {
Copy link
Contributor

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.

assert dateMathName.equals(indexAbstraction) == false;
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

field is a non-nullable object. Why not directly use field.equals(..)?

throw new IllegalArgumentException("All phrase terms must be in the same field (" + field + "): " + terms[i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ SortedDocsProducer createSortedDocsProducerOrNull(IndexReader reader, Query quer

if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
NumberFieldMapper.NumberFieldType ft = (NumberFieldMapper.NumberFieldType) fieldType;
if (ft.typeName() == "unsigned_long") {
if ("unsigned_long".equals(ft.typeName())) {
return new UnsignedLongPointsSortedDocsProducer(fieldType.name(), lowerPoint, upperPoint);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public void reset(TokenStream stream) {
public void nextToken() throws IOException {
anyTokens = true;
BytesRef term = fillBytesRef(termsRef);
if (requireUnigram && typeAttribute.type() == ShingleFilter.DEFAULT_TOKEN_TYPE) {
if (requireUnigram && ShingleFilter.DEFAULT_TOKEN_TYPE.equals(typeAttribute.type())) {
return;
}
anyUnigram = true;
if (posIncAttr.getPositionIncrement() == 0 && typeAttribute.type() == SynonymFilter.TYPE_SYNONYM) {
if (posIncAttr.getPositionIncrement() == 0 && SynonymFilter.TYPE_SYNONYM.equals(typeAttribute.type())) {
assert currentSet != null;
TermStats termStats = generator.termStats(term);
if (termStats.docFreq > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ protected IndexShard newShard(
Settings nodeSettings = Settings.builder().put("node.name", routing.currentNodeId()).build();
DiscoveryNodes discoveryNodes = IndexShardTestUtils.getFakeDiscoveryNodes(routing);
// To simulate that the node is remote backed
if (indexMetadata.getSettings().get(IndexMetadata.SETTING_REMOTE_STORE_ENABLED) == "true") {
if (indexMetadata.getSettings().getAsBoolean(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false)) {
nodeSettings = Settings.builder()
.put("node.name", routing.currentNodeId())
.put("node.attr.remote_store.translog.repository", "seg_repo")
Expand Down
Loading