[#5625] Add Name.equalsIgnoreCase()

This commit is contained in:
lukaseder 2016-10-31 11:22:44 +01:00
parent 89beeb1bbe
commit eee2643454
2 changed files with 38 additions and 4 deletions

View File

@ -427,4 +427,15 @@ public interface Name extends QueryPart {
DerivedColumnList22 fields(String fieldName1, String fieldName2, String fieldName3, String fieldName4, String fieldName5, String fieldName6, String fieldName7, String fieldName8, String fieldName9, String fieldName10, String fieldName11, String fieldName12, String fieldName13, String fieldName14, String fieldName15, String fieldName16, String fieldName17, String fieldName18, String fieldName19, String fieldName20, String fieldName21, String fieldName22);
// [jooq-tools] END [fields]
/**
* {@inheritDoc}
*/
@Override
boolean equals(Object other);
/**
* Compare this name with another one ignoring case.
*/
boolean equalsIgnoreCase(Name other);
}

View File

@ -317,16 +317,39 @@ final class NameImpl extends AbstractQueryPart implements Name {
@Override
public boolean equals(Object that) {
if (this == that) {
if (this == that)
return true;
}
// [#1626] NameImpl equality can be decided without executing the
// rather expensive implementation of AbstractQueryPart.equals()
if (that instanceof NameImpl) {
if (that instanceof NameImpl)
return Arrays.equals(getName(), (((NameImpl) that).getName()));
}
return super.equals(that);
}
@Override
public final boolean equalsIgnoreCase(Name that) {
if (this == that)
return true;
String[] thisName = getName();
String[] thatName = that.getName();
if (thisName.length != thatName.length)
return false;
for (int i = 0; i < thisName.length; i++) {
if (thisName[i] == null && thatName[i] == null)
continue;
if (thisName[i] == null || thatName[i] == null)
return false;
if (!thisName[i].equalsIgnoreCase(thatName[i]))
return false;
}
return true;
}
}