diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/ClassHistory.java b/pitest-entry/src/main/java/org/pitest/mutationtest/ClassHistory.java index 3085acd24..99e612285 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/ClassHistory.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/ClassHistory.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest; import java.io.Serializable; +import java.util.Objects; import org.pitest.classinfo.ClassName; import org.pitest.classinfo.HierarchicalClassId; @@ -31,12 +32,7 @@ public ClassName getName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.coverageId == null) ? 0 : this.coverageId.hashCode()); - result = (prime * result) + ((this.id == null) ? 0 : this.id.hashCode()); - return result; + return Objects.hash(id, coverageId); } @Override @@ -44,28 +40,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final ClassHistory other = (ClassHistory) obj; - if (this.coverageId == null) { - if (other.coverageId != null) { - return false; - } - } else if (!this.coverageId.equals(other.coverageId)) { - return false; - } - if (this.id == null) { - if (other.id != null) { - return false; - } - } else if (!this.id.equals(other.id)) { - return false; - } - return true; + return Objects.equals(id, other.id) + && Objects.equals(coverageId, other.coverageId); } - } \ No newline at end of file diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/ClassMutationResults.java b/pitest-entry/src/main/java/org/pitest/mutationtest/ClassMutationResults.java index b61bc8087..9e9d19c6f 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/ClassMutationResults.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/ClassMutationResults.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Objects; import org.pitest.classinfo.ClassName; @@ -40,11 +41,7 @@ public String getPackageName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.mutations == null) ? 0 : this.mutations.hashCode()); - return result; + return Objects.hash(mutations); } @Override @@ -52,21 +49,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final ClassMutationResults other = (ClassMutationResults) obj; - if (this.mutations == null) { - if (other.mutations != null) { - return false; - } - } else if (!this.mutations.equals(other.mutations)) { - return false; - } - return true; + return Objects.equals(mutations, other.mutations); } @Override diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/MutationMetaData.java b/pitest-entry/src/main/java/org/pitest/mutationtest/MutationMetaData.java index da7d0e0a8..80f946cc1 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/MutationMetaData.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/MutationMetaData.java @@ -16,9 +16,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Objects; import org.pitest.classinfo.ClassName; @@ -35,7 +35,7 @@ public Collection getMutations() { } public Collection toClassResults() { - Collections.sort(this.mutations, comparator()); + this.mutations.sort(comparator()); final List cmrs = new ArrayList<>(); final List buffer = new ArrayList<>(); ClassName cn = null; @@ -55,16 +55,12 @@ public Collection toClassResults() { } private static Comparator comparator() { - return (arg0, arg1) -> arg0.getDetails().getId().compareTo(arg1.getDetails().getId()); + return Comparator.comparing(arg0 -> arg0.getDetails().getId()); } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.mutations == null) ? 0 : this.mutations.hashCode()); - return result; + return Objects.hash(mutations); } @Override @@ -72,21 +68,10 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MutationMetaData other = (MutationMetaData) obj; - if (this.mutations == null) { - if (other.mutations != null) { - return false; - } - } else if (!this.mutations.equals(other.mutations)) { - return false; - } - return true; + return Objects.equals(mutations, other.mutations); } - } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/MutationResult.java b/pitest-entry/src/main/java/org/pitest/mutationtest/MutationResult.java index c41c0d94a..c0b62c23b 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/MutationResult.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/MutationResult.java @@ -15,6 +15,7 @@ package org.pitest.mutationtest; import java.util.List; +import java.util.Objects; import java.util.Optional; import org.pitest.mutationtest.engine.MutationDetails; @@ -67,13 +68,7 @@ public String getKillingTestDescription() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.details == null) ? 0 : this.details.hashCode()); - result = (prime * result) - + ((this.status == null) ? 0 : this.status.hashCode()); - return result; + return Objects.hash(details, status); } @Override @@ -81,28 +76,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MutationResult other = (MutationResult) obj; - if (this.details == null) { - if (other.details != null) { - return false; - } - } else if (!this.details.equals(other.details)) { - return false; - } - if (this.status == null) { - if (other.status != null) { - return false; - } - } else if (!this.status.equals(other.status)) { - return false; - } - return true; + return Objects.equals(details, other.details) + && Objects.equals(status, other.status); } @Override diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/LineMutatorPair.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/LineMutatorPair.java index b17c3532a..4e49dc411 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/LineMutatorPair.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/intercept/javafeatures/LineMutatorPair.java @@ -1,5 +1,7 @@ package org.pitest.mutationtest.build.intercept.javafeatures; +import java.util.Objects; + public class LineMutatorPair { private final int lineNumber; @@ -12,12 +14,7 @@ public LineMutatorPair(final int lineNumber, final String mutator) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + this.lineNumber; - result = (prime * result) - + ((this.mutator == null) ? 0 : this.mutator.hashCode()); - return result; + return Objects.hash(lineNumber, mutator); } @Override @@ -25,24 +22,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final LineMutatorPair other = (LineMutatorPair) obj; - if (this.lineNumber != other.lineNumber) { - return false; - } - if (this.mutator == null) { - if (other.mutator != null) { - return false; - } - } else if (!this.mutator.equals(other.mutator)) { - return false; - } - return true; + return lineNumber == other.lineNumber + && Objects.equals(mutator, other.mutator); } - } diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/build/intercept/javafeatures/Loc.java b/pitest-entry/src/test/java/org/pitest/mutationtest/build/intercept/javafeatures/Loc.java index feb5266d9..eca5f1617 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/build/intercept/javafeatures/Loc.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/build/intercept/javafeatures/Loc.java @@ -2,44 +2,32 @@ import org.objectweb.asm.tree.AbstractInsnNode; +import java.util.Objects; + class Loc { int index; AbstractInsnNode node; + @Override public String toString() { return "[" + this.index + "] " + this.node; } + @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + this.index; - result = (prime * result) + ((this.node == null) ? 0 : this.node.hashCode()); - return result; + return Objects.hash(index, node); } + @Override public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Loc other = (Loc) obj; - if (this.index != other.index) { - return false; - } - if (this.node == null) { - if (other.node != null) { - return false; - } - } else if (!this.node.equals(other.node)) { - return false; - } - return true; + return index == other.index + && Objects.equals(node, other.node); } - } \ No newline at end of file diff --git a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/PackageSummaryData.java b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/PackageSummaryData.java index 62127f751..cd3964754 100644 --- a/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/PackageSummaryData.java +++ b/pitest-html-report/src/main/java/org/pitest/mutationtest/report/html/PackageSummaryData.java @@ -1,10 +1,10 @@ package org.pitest.mutationtest.report.html; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; public class PackageSummaryData implements Comparable { @@ -50,17 +50,13 @@ public String getPackageDirectory() { public List getSummaryData() { final ArrayList values = new ArrayList<>( this.fileNameToSummaryData.values()); - Collections.sort(values, new MutationTestSummaryDataFileNameComparator()); + values.sort(new MutationTestSummaryDataFileNameComparator()); return values; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.packageName == null) ? 0 : this.packageName.hashCode()); - return result; + return Objects.hash(packageName); } @Override @@ -68,21 +64,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final PackageSummaryData other = (PackageSummaryData) obj; - if (this.packageName == null) { - if (other.packageName != null) { - return false; - } - } else if (!this.packageName.equals(other.packageName)) { - return false; - } - return true; + return Objects.equals(packageName, other.packageName); } @Override diff --git a/pitest-maven/src/main/java/org/pitest/maven/DependencyFilter.java b/pitest-maven/src/main/java/org/pitest/maven/DependencyFilter.java index 407757520..8df558583 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/DependencyFilter.java +++ b/pitest-maven/src/main/java/org/pitest/maven/DependencyFilter.java @@ -18,6 +18,7 @@ import java.net.URL; import java.util.Enumeration; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -129,12 +130,7 @@ private static class GroupIdPair { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.group == null) ? 0 : this.group.hashCode()); - result = (prime * result) + ((this.id == null) ? 0 : this.id.hashCode()); - return result; + return Objects.hash(group, id); } @Override @@ -142,30 +138,13 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final GroupIdPair other = (GroupIdPair) obj; - if (this.group == null) { - if (other.group != null) { - return false; - } - } else if (!this.group.equals(other.group)) { - return false; - } - if (this.id == null) { - if (other.id != null) { - return false; - } - } else if (!this.id.equals(other.id)) { - return false; - } - return true; + return Objects.equals(group, other.group) + && Objects.equals(id, other.id); } - } } diff --git a/pitest/src/main/java/org/pitest/classinfo/ClassIdentifier.java b/pitest/src/main/java/org/pitest/classinfo/ClassIdentifier.java index 75f7ded3d..25fefe4dc 100644 --- a/pitest/src/main/java/org/pitest/classinfo/ClassIdentifier.java +++ b/pitest/src/main/java/org/pitest/classinfo/ClassIdentifier.java @@ -1,6 +1,7 @@ package org.pitest.classinfo; import java.io.Serializable; +import java.util.Objects; public final class ClassIdentifier implements Serializable { @@ -24,12 +25,7 @@ public ClassName getName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + (int) (this.hash ^ (this.hash >>> 32)); - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - return result; + return Objects.hash(hash, name); } @Override @@ -37,24 +33,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final ClassIdentifier other = (ClassIdentifier) obj; - if (this.hash != other.hash) { - return false; - } - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return hash == other.hash + && Objects.equals(name, other.name); } - } diff --git a/pitest/src/main/java/org/pitest/classinfo/ClassName.java b/pitest/src/main/java/org/pitest/classinfo/ClassName.java index ead03c65c..020ac9140 100644 --- a/pitest/src/main/java/org/pitest/classinfo/ClassName.java +++ b/pitest/src/main/java/org/pitest/classinfo/ClassName.java @@ -15,6 +15,7 @@ package org.pitest.classinfo; import java.io.Serializable; +import java.util.Objects; import java.util.function.Function; import java.util.logging.Logger; import java.util.stream.Stream; @@ -128,11 +129,7 @@ public static Function>> nameToClass( @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - return result; + return Objects.hash(name); } @Override @@ -140,21 +137,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final ClassName other = (ClassName) obj; - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return Objects.equals(name, other.name); } @Override diff --git a/pitest/src/main/java/org/pitest/classinfo/HierarchicalClassId.java b/pitest/src/main/java/org/pitest/classinfo/HierarchicalClassId.java index cac5f97c1..85d120558 100644 --- a/pitest/src/main/java/org/pitest/classinfo/HierarchicalClassId.java +++ b/pitest/src/main/java/org/pitest/classinfo/HierarchicalClassId.java @@ -2,6 +2,7 @@ import java.io.Serializable; import java.math.BigInteger; +import java.util.Objects; public final class HierarchicalClassId implements Serializable { @@ -45,14 +46,7 @@ public String toString() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.classId == null) ? 0 : this.classId.hashCode()); - result = (prime * result) - + ((this.hierarchicalHash == null) ? 0 : this.hierarchicalHash - .hashCode()); - return result; + return Objects.hash(classId, hierarchicalHash); } @Override @@ -60,28 +54,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final HierarchicalClassId other = (HierarchicalClassId) obj; - if (this.classId == null) { - if (other.classId != null) { - return false; - } - } else if (!this.classId.equals(other.classId)) { - return false; - } - if (this.hierarchicalHash == null) { - if (other.hierarchicalHash != null) { - return false; - } - } else if (!this.hierarchicalHash.equals(other.hierarchicalHash)) { - return false; - } - return true; + return Objects.equals(classId, other.classId) + && Objects.equals(hierarchicalHash, other.hierarchicalHash); } - } diff --git a/pitest/src/main/java/org/pitest/coverage/BlockLocation.java b/pitest/src/main/java/org/pitest/coverage/BlockLocation.java index f97fa72c3..0081201af 100644 --- a/pitest/src/main/java/org/pitest/coverage/BlockLocation.java +++ b/pitest/src/main/java/org/pitest/coverage/BlockLocation.java @@ -3,6 +3,8 @@ import org.pitest.classinfo.ClassName; import org.pitest.mutationtest.engine.Location; +import java.util.Objects; + public final class BlockLocation { private final Location location; @@ -45,12 +47,7 @@ public int getLastInsnInBlock() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + this.block; - result = (prime * result) - + ((this.location == null) ? 0 : this.location.hashCode()); - return result; + return Objects.hash(location, block); } @Override @@ -58,24 +55,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final BlockLocation other = (BlockLocation) obj; - if (this.block != other.block) { - return false; - } - if (this.location == null) { - if (other.location != null) { - return false; - } - } else if (!this.location.equals(other.location)) { - return false; - } - return true; + return block == other.block + && Objects.equals(location, other.location); } @Override diff --git a/pitest/src/main/java/org/pitest/coverage/ClassLine.java b/pitest/src/main/java/org/pitest/coverage/ClassLine.java index 3809eb0f8..2bddad7fe 100644 --- a/pitest/src/main/java/org/pitest/coverage/ClassLine.java +++ b/pitest/src/main/java/org/pitest/coverage/ClassLine.java @@ -17,6 +17,8 @@ import org.pitest.classinfo.ClassName; +import java.util.Objects; + public final class ClassLine { private final ClassName clazz; private final int lineNumber; @@ -40,12 +42,7 @@ public int getLineNumber() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.clazz == null) ? 0 : this.clazz.hashCode()); - result = (prime * result) + this.lineNumber; - return result; + return Objects.hash(clazz, lineNumber); } @Override @@ -53,24 +50,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final ClassLine other = (ClassLine) obj; - if (this.clazz == null) { - if (other.clazz != null) { - return false; - } - } else if (!this.clazz.equals(other.clazz)) { - return false; - } - if (this.lineNumber != other.lineNumber) { - return false; - } - return true; + return lineNumber == other.lineNumber + && Objects.equals(clazz, other.clazz); } @Override diff --git a/pitest/src/main/java/org/pitest/coverage/InstructionLocation.java b/pitest/src/main/java/org/pitest/coverage/InstructionLocation.java index e3f109f0a..7f5a336f7 100644 --- a/pitest/src/main/java/org/pitest/coverage/InstructionLocation.java +++ b/pitest/src/main/java/org/pitest/coverage/InstructionLocation.java @@ -2,6 +2,8 @@ import org.pitest.classinfo.ClassName; +import java.util.Objects; + public final class InstructionLocation { private final BlockLocation blockLocation; private final int instructionIndex; @@ -17,27 +19,21 @@ public BlockLocation getBlockLocation() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (o == null || getClass() != o.getClass()) { - return false; - } - - InstructionLocation that = (InstructionLocation) o; - - if (instructionIndex != that.instructionIndex) { + if (obj == null || getClass() != obj.getClass()) { return false; } - return blockLocation.getLocation().equals(that.blockLocation.getLocation()); + final InstructionLocation other = (InstructionLocation) obj; + return instructionIndex == other.instructionIndex + && Objects.equals(blockLocation.getLocation(), other.blockLocation.getLocation()); } @Override public int hashCode() { - int result = blockLocation.getLocation().hashCode(); - result = 31 * result + instructionIndex; - return result; + return Objects.hash(blockLocation.getLocation(), instructionIndex); } public boolean isFor(final ClassName clazz) { diff --git a/pitest/src/main/java/org/pitest/coverage/TestInfo.java b/pitest/src/main/java/org/pitest/coverage/TestInfo.java index ff4d9e61c..34fa069e9 100644 --- a/pitest/src/main/java/org/pitest/coverage/TestInfo.java +++ b/pitest/src/main/java/org/pitest/coverage/TestInfo.java @@ -15,6 +15,7 @@ package org.pitest.coverage; import java.io.Serializable; +import java.util.Objects; import java.util.function.Function; import org.pitest.classinfo.ClassName; @@ -73,13 +74,7 @@ public boolean directlyHits(final ClassName targetClass) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.definingClass == null) ? 0 : this.definingClass.hashCode()); - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - return result; + return Objects.hash(name, definingClass); } @Override @@ -87,28 +82,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final TestInfo other = (TestInfo) obj; - if (this.definingClass == null) { - if (other.definingClass != null) { - return false; - } - } else if (!this.definingClass.equals(other.definingClass)) { - return false; - } - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return Objects.equals(name, other.name) + && Objects.equals(definingClass, other.definingClass); } private static String internIfNotNull(final String string) { diff --git a/pitest/src/main/java/org/pitest/coverage/analysis/Block.java b/pitest/src/main/java/org/pitest/coverage/analysis/Block.java index d48bb34b9..be733e92e 100644 --- a/pitest/src/main/java/org/pitest/coverage/analysis/Block.java +++ b/pitest/src/main/java/org/pitest/coverage/analysis/Block.java @@ -1,5 +1,6 @@ package org.pitest.coverage.analysis; +import java.util.Objects; import java.util.Set; public final class Block { @@ -16,11 +17,7 @@ public Block(final int firstInstruction, final int lastInstruction, @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + this.firstInstruction; - result = (prime * result) + this.lastInstruction; - return result; + return Objects.hash(firstInstruction, lastInstruction); } @Override @@ -28,20 +25,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Block other = (Block) obj; - if (this.firstInstruction != other.firstInstruction) { - return false; - } - if (this.lastInstruction != other.lastInstruction) { - return false; - } - return true; + return (firstInstruction == other.firstInstruction) + && (lastInstruction == other.lastInstruction); } @Override diff --git a/pitest/src/main/java/org/pitest/dependency/DependencyAccess.java b/pitest/src/main/java/org/pitest/dependency/DependencyAccess.java index 950db36a1..557d00ffa 100644 --- a/pitest/src/main/java/org/pitest/dependency/DependencyAccess.java +++ b/pitest/src/main/java/org/pitest/dependency/DependencyAccess.java @@ -14,6 +14,8 @@ */ package org.pitest.dependency; +import java.util.Objects; + final class DependencyAccess { static class Member implements Comparable { @@ -35,13 +37,7 @@ public String getName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - result = (prime * result) - + ((this.owner == null) ? 0 : this.owner.hashCode()); - return result; + return Objects.hash(owner, name); } @Override @@ -49,28 +45,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Member other = (Member) obj; - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - if (this.owner == null) { - if (other.owner != null) { - return false; - } - } else if (!this.owner.equals(other.owner)) { - return false; - } - return true; + return Objects.equals(owner, other.owner) + && Objects.equals(name, other.name); } @Override @@ -99,13 +79,7 @@ public Member getDest() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.dest == null) ? 0 : this.dest.hashCode()); - result = (prime * result) - + ((this.source == null) ? 0 : this.source.hashCode()); - return result; + return Objects.hash(source, dest); } @Override @@ -113,28 +87,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final DependencyAccess other = (DependencyAccess) obj; - if (this.dest == null) { - if (other.dest != null) { - return false; - } - } else if (!this.dest.equals(other.dest)) { - return false; - } - if (this.source == null) { - if (other.source != null) { - return false; - } - } else if (!this.source.equals(other.source)) { - return false; - } - return true; + return Objects.equals(source, other.source) + && Objects.equals(dest, other.dest); } - } diff --git a/pitest/src/main/java/org/pitest/functional/FCollection.java b/pitest/src/main/java/org/pitest/functional/FCollection.java index cbfdd74f9..fe177dd25 100644 --- a/pitest/src/main/java/org/pitest/functional/FCollection.java +++ b/pitest/src/main/java/org/pitest/functional/FCollection.java @@ -156,11 +156,7 @@ public static Map> bucket(final Iterable bs, final Map> bucketed = new HashMap<>(); for (final B each : bs) { final A key = f.apply(each); - Collection existing = bucketed.get(key); - if (existing == null) { - existing = new ArrayList<>(); - bucketed.put(key, existing); - } + Collection existing = bucketed.computeIfAbsent(key, k -> new ArrayList<>()); existing.add(each); } return bucketed; diff --git a/pitest/src/main/java/org/pitest/mutationtest/MutationStatusTestPair.java b/pitest/src/main/java/org/pitest/mutationtest/MutationStatusTestPair.java index 69d94f91a..edee28a8a 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/MutationStatusTestPair.java +++ b/pitest/src/main/java/org/pitest/mutationtest/MutationStatusTestPair.java @@ -101,16 +101,7 @@ public String toString() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.killingTests == null) ? 0 : this.killingTests.hashCode()); - result = (prime * result) - + ((this.succeedingTests == null) ? 0 : this.succeedingTests.hashCode()); - result = (prime * result) + this.numberOfTestsRun; - result = (prime * result) - + ((this.status == null) ? 0 : this.status.hashCode()); - return result; + return Objects.hash(numberOfTestsRun, status, killingTests, succeedingTests); } @Override @@ -118,26 +109,13 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MutationStatusTestPair other = (MutationStatusTestPair) obj; - if (!Objects.equals( this.killingTests,other.killingTests)) { - return false; - } - if (!Objects.equals(this.succeedingTests, other.succeedingTests)) { - return false; - } - if (this.numberOfTestsRun != other.numberOfTestsRun) { - return false; - } - if (this.status != other.status) { - return false; - } - return true; + return numberOfTestsRun == other.numberOfTestsRun + && status == other.status + && Objects.equals(killingTests, other.killingTests) + && Objects.equals(succeedingTests, other.succeedingTests); } - } diff --git a/pitest/src/main/java/org/pitest/mutationtest/engine/Location.java b/pitest/src/main/java/org/pitest/mutationtest/engine/Location.java index 2d9bd1a74..6fa3553f0 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/engine/Location.java +++ b/pitest/src/main/java/org/pitest/mutationtest/engine/Location.java @@ -15,6 +15,7 @@ package org.pitest.mutationtest.engine; import java.io.Serializable; +import java.util.Objects; import org.pitest.classinfo.ClassName; @@ -56,15 +57,7 @@ public String getMethodDesc() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.clazz == null) ? 0 : this.clazz.hashCode()); - result = (prime * result) - + ((this.method == null) ? 0 : this.method.hashCode()); - result = (prime * result) - + ((this.methodDesc == null) ? 0 : this.methodDesc.hashCode()); - return result; + return Objects.hash(clazz, method, methodDesc); } @Override @@ -72,35 +65,13 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Location other = (Location) obj; - if (this.clazz == null) { - if (other.clazz != null) { - return false; - } - } else if (!this.clazz.equals(other.clazz)) { - return false; - } - if (this.method == null) { - if (other.method != null) { - return false; - } - } else if (!this.method.equals(other.method)) { - return false; - } - if (this.methodDesc == null) { - if (other.methodDesc != null) { - return false; - } - } else if (!this.methodDesc.equals(other.methodDesc)) { - return false; - } - return true; + return Objects.equals(clazz, other.clazz) + && Objects.equals(method, other.method) + && Objects.equals(methodDesc, other.methodDesc); } @Override diff --git a/pitest/src/main/java/org/pitest/mutationtest/engine/MethodName.java b/pitest/src/main/java/org/pitest/mutationtest/engine/MethodName.java index 4b7b4b3b9..6ae62341a 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/engine/MethodName.java +++ b/pitest/src/main/java/org/pitest/mutationtest/engine/MethodName.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest.engine; import java.io.Serializable; +import java.util.Objects; public class MethodName implements Serializable { @@ -18,11 +19,7 @@ public static MethodName fromString(final String name) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - return result; + return Objects.hash(name); } @Override @@ -30,21 +27,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MethodName other = (MethodName) obj; - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return Objects.equals(name, other.name); } @Override diff --git a/pitest/src/main/java/org/pitest/mutationtest/engine/MutationDetails.java b/pitest/src/main/java/org/pitest/mutationtest/engine/MutationDetails.java index 6a91043ff..186767aed 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/engine/MutationDetails.java +++ b/pitest/src/main/java/org/pitest/mutationtest/engine/MutationDetails.java @@ -272,10 +272,7 @@ private String defaultFilenameIfNotSupplued(String filename) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + ((this.id == null) ? 0 : this.id.hashCode()); - return result; + return Objects.hash(id); } @Override @@ -283,22 +280,10 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MutationDetails other = (MutationDetails) obj; - if (this.id == null) { - if (other.id != null) { - return false; - } - } else if (!this.id.equals(other.id)) { - return false; - } - return true; + return Objects.equals(id, other.id); } - - } diff --git a/pitest/src/main/java/org/pitest/mutationtest/engine/MutationIdentifier.java b/pitest/src/main/java/org/pitest/mutationtest/engine/MutationIdentifier.java index 2c2e25d92..0958195e0 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/engine/MutationIdentifier.java +++ b/pitest/src/main/java/org/pitest/mutationtest/engine/MutationIdentifier.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.pitest.classinfo.ClassName; @@ -126,15 +127,7 @@ public ClassName getClassName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.indexes == null) ? 0 : this.indexes.hashCode()); - result = (prime * result) - + ((this.location == null) ? 0 : this.location.hashCode()); - result = (prime * result) - + ((this.mutator == null) ? 0 : this.mutator.hashCode()); - return result; + return Objects.hash(location, indexes, mutator); } @Override @@ -142,35 +135,13 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MutationIdentifier other = (MutationIdentifier) obj; - if (this.indexes == null) { - if (other.indexes != null) { - return false; - } - } else if (!this.indexes.equals(other.indexes)) { - return false; - } - if (this.location == null) { - if (other.location != null) { - return false; - } - } else if (!this.location.equals(other.location)) { - return false; - } - if (this.mutator == null) { - if (other.mutator != null) { - return false; - } - } else if (!this.mutator.equals(other.mutator)) { - return false; - } - return true; + return Objects.equals(location, other.location) + && Objects.equals(indexes, other.indexes) + && Objects.equals(mutator, other.mutator); } @Override diff --git a/pitest/src/main/java/org/pitest/mutationtest/execute/HotSwap.java b/pitest/src/main/java/org/pitest/mutationtest/execute/HotSwap.java index cc4921414..09bb5fd39 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/execute/HotSwap.java +++ b/pitest/src/main/java/org/pitest/mutationtest/execute/HotSwap.java @@ -20,11 +20,10 @@ class HotSwap implements F3 { @Override public Boolean apply(final ClassName clazzName, final ClassLoader loader, final byte[] b) { - Class clazz; try { restoreLastClass(this.byteSource, clazzName, loader); this.lastUsedLoader = loader; - clazz = Class.forName(clazzName.asJavaName(), false, loader); + Class clazz = Class.forName(clazzName.asJavaName(), false, loader); return HotSwapAgent.hotSwap(clazz, b); } catch (final ClassNotFoundException e) { throw Unchecked.translateCheckedException(e); diff --git a/pitest/src/main/java/org/pitest/plugin/Feature.java b/pitest/src/main/java/org/pitest/plugin/Feature.java index 02dfff386..b65b054b4 100644 --- a/pitest/src/main/java/org/pitest/plugin/Feature.java +++ b/pitest/src/main/java/org/pitest/plugin/Feature.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; public final class Feature { @@ -56,11 +57,7 @@ public List params() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - return result; + return Objects.hash(name); } @Override @@ -68,22 +65,10 @@ public boolean equals(Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Feature other = (Feature) obj; - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - return true; + return Objects.equals(name, other.name); } - - } diff --git a/pitest/src/main/java/org/pitest/testapi/Description.java b/pitest/src/main/java/org/pitest/testapi/Description.java index bc922b1fa..e27a00ed6 100644 --- a/pitest/src/main/java/org/pitest/testapi/Description.java +++ b/pitest/src/main/java/org/pitest/testapi/Description.java @@ -16,6 +16,7 @@ package org.pitest.testapi; import java.io.Serializable; +import java.util.Objects; public final class Description implements Serializable { @@ -62,13 +63,7 @@ public String getName() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.name == null) ? 0 : this.name.hashCode()); - result = (prime * result) - + ((this.testClass == null) ? 0 : this.testClass.hashCode()); - return result; + return Objects.hash(testClass, name); } @Override @@ -76,28 +71,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final Description other = (Description) obj; - if (this.name == null) { - if (other.name != null) { - return false; - } - } else if (!this.name.equals(other.name)) { - return false; - } - if (this.testClass == null) { - if (other.testClass != null) { - return false; - } - } else if (!this.testClass.equals(other.testClass)) { - return false; - } - return true; + return Objects.equals(testClass, other.testClass) + && Objects.equals(name, other.name); } @Override diff --git a/pitest/src/main/java/org/pitest/testapi/TestResult.java b/pitest/src/main/java/org/pitest/testapi/TestResult.java index f4e335aa3..6d1a2ac5e 100644 --- a/pitest/src/main/java/org/pitest/testapi/TestResult.java +++ b/pitest/src/main/java/org/pitest/testapi/TestResult.java @@ -14,6 +14,8 @@ */ package org.pitest.testapi; +import java.util.Objects; + /** * @author henry * @@ -50,15 +52,7 @@ public Description getDescription() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.description == null) ? 0 : this.description.hashCode()); - result = (prime * result) - + ((this.state == null) ? 0 : this.state.hashCode()); - result = (prime * result) - + ((this.throwable == null) ? 0 : this.throwable.hashCode()); - return result; + return Objects.hash(description, throwable, state); } @Override @@ -66,35 +60,13 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final TestResult other = (TestResult) obj; - if (this.description == null) { - if (other.description != null) { - return false; - } - } else if (!this.description.equals(other.description)) { - return false; - } - if (this.state == null) { - if (other.state != null) { - return false; - } - } else if (!this.state.equals(other.state)) { - return false; - } - if (this.throwable == null) { - if (other.throwable != null) { - return false; - } - } else if (!this.throwable.equals(other.throwable)) { - return false; - } - return true; + return Objects.equals(description, other.description) + && Objects.equals(throwable, other.throwable) + && state == other.state; } @Override diff --git a/pitest/src/main/java/org/pitest/testapi/execute/MultipleTestGroup.java b/pitest/src/main/java/org/pitest/testapi/execute/MultipleTestGroup.java index b668201c0..a9fcac09b 100644 --- a/pitest/src/main/java/org/pitest/testapi/execute/MultipleTestGroup.java +++ b/pitest/src/main/java/org/pitest/testapi/execute/MultipleTestGroup.java @@ -16,6 +16,7 @@ package org.pitest.testapi.execute; import java.util.List; +import java.util.Objects; import org.pitest.testapi.AbstractTestUnit; import org.pitest.testapi.Description; @@ -44,11 +45,7 @@ public void execute(final ResultCollector rc) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.children == null) ? 0 : this.children.hashCode()); - return result; + return Objects.hash(children); } @Override @@ -56,21 +53,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final MultipleTestGroup other = (MultipleTestGroup) obj; - if (this.children == null) { - if (other.children != null) { - return false; - } - } else if (!this.children.equals(other.children)) { - return false; - } - return true; + return Objects.equals(children, other.children); } } diff --git a/pitest/src/main/java/org/pitest/util/SafeDataInputStream.java b/pitest/src/main/java/org/pitest/util/SafeDataInputStream.java index b552fc592..b77a8af66 100644 --- a/pitest/src/main/java/org/pitest/util/SafeDataInputStream.java +++ b/pitest/src/main/java/org/pitest/util/SafeDataInputStream.java @@ -100,16 +100,10 @@ public long readLong() { private Object deserialize(byte[] bytes) throws IOException { final ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInput in = null; - try { - in = new ObjectInputStream(bis); + try (ObjectInput in = new ObjectInputStream(bis)) { return in.readObject(); } catch (final ClassNotFoundException e) { throw Unchecked.translateCheckedException(e); - } finally { - if (in != null) { - in.close(); - } } } diff --git a/pitest/src/test/java/org/pitest/simpletest/SteppedTestUnit.java b/pitest/src/test/java/org/pitest/simpletest/SteppedTestUnit.java index 5ccb999f5..e1d9f3443 100644 --- a/pitest/src/test/java/org/pitest/simpletest/SteppedTestUnit.java +++ b/pitest/src/test/java/org/pitest/simpletest/SteppedTestUnit.java @@ -16,6 +16,7 @@ import java.util.Collection; +import java.util.Objects; import java.util.Optional; import org.pitest.testapi.AbstractTestUnit; import org.pitest.testapi.Description; @@ -86,13 +87,7 @@ private Collection steps() { @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = (prime * result) - + ((this.expected == null) ? 0 : this.expected.hashCode()); - result = (prime * result) - + ((this.steps == null) ? 0 : this.steps.hashCode()); - return result; + return Objects.hash(steps, expected); } @Override @@ -100,28 +95,12 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (!super.equals(obj)) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final SteppedTestUnit other = (SteppedTestUnit) obj; - if (this.expected == null) { - if (other.expected != null) { - return false; - } - } else if (!this.expected.equals(other.expected)) { - return false; - } - if (this.steps == null) { - if (other.steps != null) { - return false; - } - } else if (!this.steps.equals(other.steps)) { - return false; - } - return true; + return Objects.equals(steps, other.steps) + && Objects.equals(expected, other.expected); } @Override diff --git a/pitest/src/test/java/org/pitest/simpletest/TestMethod.java b/pitest/src/test/java/org/pitest/simpletest/TestMethod.java index 4a577dcff..2b6e21ee0 100644 --- a/pitest/src/test/java/org/pitest/simpletest/TestMethod.java +++ b/pitest/src/test/java/org/pitest/simpletest/TestMethod.java @@ -17,6 +17,7 @@ import java.lang.reflect.Method; +import java.util.Objects; import java.util.Optional; public class TestMethod { @@ -43,7 +44,7 @@ public Method getMethod() { } public Optional> getExpected() { - return Optional.> ofNullable(this.expected); + return Optional.ofNullable(this.expected); } @Override @@ -54,13 +55,7 @@ public String toString() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.expected == null) ? 0 : this.expected.hashCode()); - result = (prime * result) - + ((this.method == null) ? 0 : this.method.hashCode()); - return result; + return Objects.hash(method, expected); } @Override @@ -68,28 +63,11 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final TestMethod other = (TestMethod) obj; - if (this.expected == null) { - if (other.expected != null) { - return false; - } - } else if (!this.expected.equals(other.expected)) { - return false; - } - if (this.method == null) { - if (other.method != null) { - return false; - } - } else if (!this.method.equals(other.method)) { - return false; - } - return true; + return Objects.equals(method, other.method) && + Objects.equals(expected, other.expected); } - } diff --git a/pitest/src/test/java/org/pitest/simpletest/steps/NoArgsInstantiateStep.java b/pitest/src/test/java/org/pitest/simpletest/steps/NoArgsInstantiateStep.java index 923a352ac..b3e320bb8 100644 --- a/pitest/src/test/java/org/pitest/simpletest/steps/NoArgsInstantiateStep.java +++ b/pitest/src/test/java/org/pitest/simpletest/steps/NoArgsInstantiateStep.java @@ -15,6 +15,7 @@ package org.pitest.simpletest.steps; import java.lang.reflect.Modifier; +import java.util.Objects; import org.pitest.simpletest.CanNotCreateTestClassException; import org.pitest.simpletest.TestStep; @@ -44,7 +45,7 @@ public Object execute(final Description testDescription, final Object target) { throw new CanNotCreateTestClassException( "Cannot instantiate the abstract class " + c.getName(), null); } else { - return c.newInstance(); + return c.getDeclaredConstructor().newInstance(); } } catch (final Throwable e) { e.printStackTrace(); @@ -54,11 +55,7 @@ public Object execute(final Description testDescription, final Object target) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) - + ((this.clazz == null) ? 0 : this.clazz.hashCode()); - return result; + return Objects.hash(clazz); } @Override @@ -66,21 +63,10 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } final NoArgsInstantiateStep other = (NoArgsInstantiateStep) obj; - if (this.clazz == null) { - if (other.clazz != null) { - return false; - } - } else if (!this.clazz.equals(other.clazz)) { - return false; - } - return true; + return Objects.equals(clazz, other.clazz); } - }