HBASE-21129 Clean up duplicate codes in #equals and #hashCode methods of Filter

Signed-off-by Ted Yu <yuzhihong@gmail.com>
This commit is contained in:
Reid Chan 2018-09-03 15:25:29 +08:00
parent 5cca61c4d0
commit 245bb44703
36 changed files with 107 additions and 182 deletions

View File

@ -136,11 +136,7 @@ public class ColumnCountGetFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ColumnCountGetFilter))) {
return false;
}
ColumnCountGetFilter f = (ColumnCountGetFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -234,15 +234,12 @@ public class ColumnPaginationFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ColumnPaginationFilter))) {
return false;
}
ColumnPaginationFilter f = (ColumnPaginationFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.limit, this.offset);
return columnOffset == null ? Objects.hash(this.limit, this.offset) :
Objects.hash(this.limit, Bytes.hashCode(this.columnOffset));
}
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
import org.apache.hadoop.hbase.Cell;
@ -165,15 +164,11 @@ public class ColumnPrefixFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ColumnPrefixFilter))) {
return false;
}
ColumnPrefixFilter f = (ColumnPrefixFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.getPrefix()));
return Bytes.hashCode(this.getPrefix());
}
}

View File

@ -243,16 +243,12 @@ public class ColumnRangeFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ColumnRangeFilter))) {
return false;
}
ColumnRangeFilter f = (ColumnRangeFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.toStringBinary(this.getMinColumn()), this.getMinColumnInclusive(),
Bytes.toStringBinary(this.getMaxColumn()), this.getMaxColumnInclusive());
return Objects.hash(Bytes.hashCode(getMinColumn()), getMinColumnInclusive(),
Bytes.hashCode(getMaxColumn()), getMaxColumnInclusive());
}
}

View File

@ -242,16 +242,12 @@ public class ColumnValueFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ColumnValueFilter))) {
return false;
}
ColumnValueFilter f = (ColumnValueFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.getFamily()), Bytes.hashCode(this.getQualifier()),
this.getCompareOperator(), this.getComparator());
return Objects.hash(Bytes.hashCode(getFamily()), Bytes.hashCode(getQualifier()),
getCompareOperator(), getComparator());
}
}

View File

@ -325,11 +325,7 @@ public abstract class CompareFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof CompareFilter))) {
return false;
}
CompareFilter f = (CompareFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -315,16 +315,12 @@ public class DependentColumnFilter extends CompareFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof DependentColumnFilter))) {
return false;
}
DependentColumnFilter f = (DependentColumnFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.getFamily()), Bytes.hashCode(this.getQualifier()),
this.dropDependentColumn());
return Objects.hash(Bytes.hashCode(getFamily()), Bytes.hashCode(getQualifier()),
dropDependentColumn(), getComparator(), getCompareOperator());
}
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CompareOperator;
@ -150,15 +149,11 @@ public class FamilyFilter extends CompareFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof FamilyFilter))) {
return false;
}
FamilyFilter f = (FamilyFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getComparator(), this.getCompareOperator());
return super.hashCode();
}
}

View File

@ -277,17 +277,14 @@ final public class FilterList extends FilterBase {
public String toString() {
return this.filterListBase.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof FilterList))) {
return false;
}
FilterList f = (FilterList) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getOperator(), Arrays.hashCode(this.getFilters().toArray()));
return Objects.hash(getOperator(), getFilters());
}
}

View File

@ -24,7 +24,6 @@ import org.apache.yetus.audience.InterfaceAudience;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -284,7 +283,7 @@ public class FilterListWithAND extends FilterListBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof FilterListWithAND))) {
if (!(obj instanceof FilterListWithAND)) {
return false;
}
if (this == obj) {
@ -296,6 +295,6 @@ public class FilterListWithAND extends FilterListBase {
@Override
public int hashCode() {
return Objects.hash(this.seekHintFilters, Arrays.hashCode(this.filters.toArray()));
return Objects.hash(this.seekHintFilters, this.filters);
}
}

View File

@ -26,7 +26,6 @@ import org.apache.yetus.audience.InterfaceAudience;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -405,13 +404,12 @@ public class FilterListWithOR extends FilterListBase {
}
FilterListWithOR f = (FilterListWithOR) obj;
return this.filters.equals(f.getFilters()) &&
this.prevFilterRCList.equals(f.prevFilterRCList) &&
this.prevCellList.equals(f.prevCellList);
this.prevFilterRCList.equals(f.prevFilterRCList) &&
this.prevCellList.equals(f.prevCellList);
}
@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(this.prevFilterRCList.toArray()),
Arrays.hashCode(this.prevCellList.toArray()), Arrays.hashCode(this.filters.toArray()));
return Objects.hash(this.prevFilterRCList, this.prevCellList, this.filters);
}
}

View File

@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.yetus.audience.InterfaceAudience;
@ -126,4 +127,14 @@ public class FirstKeyOnlyFilter extends FilterBase {
return true;
}
@Override
public boolean equals(Object obj) {
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hashCode(foundKV);
}
}

View File

@ -137,11 +137,7 @@ public class FirstKeyValueMatchingQualifiersFilter extends FirstKeyOnlyFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof FirstKeyValueMatchingQualifiersFilter))) {
return false;
}
FirstKeyValueMatchingQualifiersFilter f = (FirstKeyValueMatchingQualifiersFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -650,15 +650,11 @@ public class FuzzyRowFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof FuzzyRowFilter))) {
return false;
}
FuzzyRowFilter f = (FuzzyRowFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.fuzzyKeysData.toArray());
return Objects.hash(this.fuzzyKeysData);
}
}

View File

@ -20,7 +20,6 @@
package org.apache.hadoop.hbase.filter;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
@ -135,15 +134,11 @@ public class InclusiveStopFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof InclusiveStopFilter))) {
return false;
}
InclusiveStopFilter f = (InclusiveStopFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.stopRowKey));
return Bytes.hashCode(this.stopRowKey);
}
}

View File

@ -137,11 +137,7 @@ public class KeyOnlyFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof KeyOnlyFilter))) {
return false;
}
KeyOnlyFilter f = (KeyOnlyFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -516,7 +516,7 @@ public class MultiRowRangeFilter extends FilterBase {
@Override
public boolean equals(Object obj){
if (obj == null || (!(obj instanceof RowRange))) {
if (!(obj instanceof RowRange)) {
return false;
}
if (this == obj) {
@ -540,15 +540,11 @@ public class MultiRowRangeFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof MultiRowRangeFilter))) {
return false;
}
MultiRowRangeFilter f = (MultiRowRangeFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.rangeList.toArray());
return Objects.hash(this.rangeList);
}
}

View File

@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.TreeSet;
@ -212,15 +211,11 @@ public class MultipleColumnPrefixFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof MultipleColumnPrefixFilter))) {
return false;
}
MultipleColumnPrefixFilter f = (MultipleColumnPrefixFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Arrays.hashCode(this.sortedPrefixes.toArray()));
return Objects.hash(this.sortedPrefixes);
}
}

View File

@ -154,11 +154,7 @@ public class PageFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof PageFilter))) {
return false;
}
PageFilter f = (PageFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -20,7 +20,6 @@
package org.apache.hadoop.hbase.filter;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.ByteBufferExtendedCell;
import org.apache.hadoop.hbase.Cell;
@ -160,15 +159,11 @@ public class PrefixFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof PrefixFilter))) {
return false;
}
PrefixFilter f = (PrefixFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.getPrefix()));
return Bytes.hashCode(this.getPrefix());
}
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CompareOperator;
@ -147,15 +146,11 @@ public class QualifierFilter extends CompareFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof QualifierFilter))) {
return false;
}
QualifierFilter f = (QualifierFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getComparator(), this.getCompareOperator());
return super.hashCode();
}
}

View File

@ -158,11 +158,7 @@ public class RandomRowFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof RandomRowFilter))) {
return false;
}
RandomRowFilter f = (RandomRowFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CompareOperator;
@ -164,15 +163,11 @@ public class RowFilter extends CompareFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof RowFilter))) {
return false;
}
RowFilter f = (RowFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getComparator(), this.getCompareOperator());
return super.hashCode();
}
}

View File

@ -241,4 +241,14 @@ public class SingleColumnValueExcludeFilter extends SingleColumnValueFilter {
return super.areSerializedFieldsEqual(o);
}
@Override
public boolean equals(Object obj) {
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@ -464,16 +464,12 @@ public class SingleColumnValueFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(SingleColumnValueFilter.class.isInstance(obj)))) {
return false;
}
SingleColumnValueFilter f = (SingleColumnValueFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(Bytes.hashCode(this.getFamily()), Bytes.hashCode(this.getQualifier()),
this.op, this.getComparator(), this.getFilterIfMissing(), this.getLatestVersionOnly());
return Objects.hash(Bytes.hashCode(getFamily()), Bytes.hashCode(getQualifier()),
this.op, getComparator(), getFilterIfMissing(), getLatestVersionOnly());
}
}

View File

@ -165,11 +165,7 @@ public class SkipFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
return false;
}
SkipFilter f = (SkipFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -242,15 +242,11 @@ public class TimestampsFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof TimestampsFilter))) {
return false;
}
TimestampsFilter f = (TimestampsFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getTimestamps().toArray());
return Objects.hash(getTimestamps());
}
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CompareOperator;
@ -143,15 +142,11 @@ public class ValueFilter extends CompareFilter {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof ValueFilter))) {
return false;
}
ValueFilter f = (ValueFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override
public int hashCode() {
return Objects.hash(this.getComparator(), this.getCompareOperator());
return super.hashCode();
}
}

View File

@ -167,11 +167,7 @@ public class WhileMatchFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
return false;
}
WhileMatchFilter f = (WhileMatchFilter) obj;
return this.areSerializedFieldsEqual(f);
return obj instanceof Filter && areSerializedFieldsEqual((Filter) obj);
}
@Override

View File

@ -39,4 +39,17 @@ class MobReferenceOnlyFilter extends FilterBase {
}
return ReturnCode.SKIP;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof MobReferenceOnlyFilter)) {
return false;
}
return obj == this;
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@ -177,23 +177,23 @@ class AccessControlFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
if (!(obj instanceof AccessControlFilter)) {
return false;
}
if(this == obj){
if (this == obj){
return true;
}
AccessControlFilter f=(AccessControlFilter)obj;
return this.authManager.equals(f.authManager) &&
this.table.equals(f.table) &&
this.user.equals(f.user) &&
this.strategy.equals(f.strategy) &&
this.cfVsMaxVersions.equals(f.cfVsMaxVersions);
this.table.equals(f.table) &&
this.user.equals(f.user) &&
this.strategy.equals(f.strategy) &&
this.cfVsMaxVersions.equals(f.cfVsMaxVersions);
}
@Override
public int hashCode() {
return Objects.hash(this.authManager, this.table, this.strategy, this.user,
this.cfVsMaxVersions);
this.cfVsMaxVersions);
}
}

View File

@ -1038,12 +1038,13 @@ public class VisibilityController implements MasterCoprocessor, RegionCoprocesso
deleteCellVisTagsFormat);
return matchFound ? ReturnCode.INCLUDE : ReturnCode.SKIP;
}
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
if (!(obj instanceof DeleteVersionVisibilityExpressionFilter)) {
return false;
}
if(this == obj){
if (this == obj){
return true;
}
DeleteVersionVisibilityExpressionFilter f = (DeleteVersionVisibilityExpressionFilter)obj;

View File

@ -23,7 +23,6 @@ import java.util.Objects;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.util.ByteRange;
@ -91,9 +90,10 @@ class VisibilityLabelFilter extends FilterBase {
this.curFamilyMaxVersions = 0;
this.curQualMetVersions = 0;
}
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
if (!(obj instanceof VisibilityLabelFilter)) {
return false;
}
if(this == obj){
@ -101,7 +101,7 @@ class VisibilityLabelFilter extends FilterBase {
}
VisibilityLabelFilter f = (VisibilityLabelFilter)obj;
return this.expEvaluator.equals(f.expEvaluator) &&
this.cfVsMaxVersions.equals(f.cfVsMaxVersions);
this.cfVsMaxVersions.equals(f.cfVsMaxVersions);
}
@Override

View File

@ -59,7 +59,7 @@ public final class ColumnCountOnRowFilter extends FilterBase {
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj.getClass() == this.getClass()))) {
if (!(obj instanceof ColumnCountOnRowFilter)) {
return false;
}
if (this == obj) {

View File

@ -1027,10 +1027,10 @@ public class TestFilterList {
@Override
public boolean equals(Object obj) {
if(obj == null || !(obj instanceof TransformFilter)){
if(!(obj instanceof TransformFilter)){
return false;
}
if(obj == this){
if (obj == this) {
return true;
}
TransformFilter f = (TransformFilter)obj;

View File

@ -29,7 +29,6 @@ import java.util.Objects;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.spark.datasources.BytesEncoder;
import org.apache.hadoop.hbase.spark.datasources.JavaBytesEncoder;
@ -279,7 +278,7 @@ public class SparkSQLPushDownFilter extends FilterBase{
@Override
public boolean equals(Object obj) {
if (obj == null || (!(obj instanceof SparkSQLPushDownFilter))) {
if (!(obj instanceof SparkSQLPushDownFilter)) {
return false;
}
if (this == obj) {
@ -297,8 +296,8 @@ public class SparkSQLPushDownFilter extends FilterBase{
i++;
}
return this.dynamicLogicExpression.equals(f.dynamicLogicExpression) &&
this.currentCellToColumnIndexMap.equals(f.currentCellToColumnIndexMap) &&
this.encoderClassName.equals(f.encoderClassName);
this.currentCellToColumnIndexMap.equals(f.currentCellToColumnIndexMap) &&
this.encoderClassName.equals(f.encoderClassName);
}
@Override