Fix equals and hashCode in SuppressionFilter and remove toString. #1088
This commit is contained in:
parent
ffd17e5ad6
commit
be08323f8a
2
pom.xml
2
pom.xml
|
|
@ -886,7 +886,7 @@
|
|||
<regex><pattern>.*.filters.SuppressElement</pattern><branchRate>82</branchRate><lineRate>88</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressionCommentFilter</pattern><branchRate>83</branchRate><lineRate>87</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressionCommentFilter\$.*</pattern><branchRate>41</branchRate><lineRate>69</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressionFilter</pattern><branchRate>0</branchRate><lineRate>0</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressionFilter</pattern><branchRate>100</branchRate><lineRate>58</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressionsLoader</pattern><branchRate>68</branchRate><lineRate>77</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressWithNearbyCommentFilter</pattern><branchRate>76</branchRate><lineRate>89</lineRate></regex>
|
||||
<regex><pattern>.*.filters.SuppressWithNearbyCommentFilter\$Tag</pattern><branchRate>88</branchRate><lineRate>78</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
|||
import com.puppycrawl.tools.checkstyle.api.Filter;
|
||||
import com.puppycrawl.tools.checkstyle.api.FilterSet;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This filter accepts AuditEvents according to file, check, line, and
|
||||
|
|
@ -55,21 +57,19 @@ public class SuppressionFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return filters.toString();
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final SuppressionFilter that = (SuppressionFilter) obj;
|
||||
return Objects.equals(filters, that.filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return filters.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof SuppressionFilter) {
|
||||
final SuppressionFilter other = (SuppressionFilter) object;
|
||||
return this.filters.equals(other.filters);
|
||||
}
|
||||
return false;
|
||||
return Objects.hash(filters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2015 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.puppycrawl.tools.checkstyle.filters;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import nl.jqno.equalsverifier.Warning;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SuppressionFilterTest {
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
EqualsVerifier
|
||||
.forClass(SuppressionFilter.class)
|
||||
.usingGetClass()
|
||||
.suppress(Warning.NONFINAL_FIELDS)
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue