Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
@@ -1,6 +1,7 @@
package org.itsallcode.openfasttrace.api;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -34,6 +35,7 @@ public Set<String> getArtifactTypes()
*
* @return artifact types that must be matched
*/

public Set<String> getTags()
{
return this.tags;
Expand Down Expand Up @@ -82,58 +84,16 @@ public boolean isAnyCriteriaSet()
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result
+ ((this.artifactTypes == null) ? 0 : this.artifactTypes.hashCode());
result = prime * result + (this.withoutTags ? 1231 : 1237);
result = prime * result + ((this.tags == null) ? 0 : this.tags.hashCode());
return result;
return Objects.hash(this.artifactTypes, this.tags, this.withoutTags);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only mentioned once: check if a Test with equalsverifier exists

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Junie says:

No classes were found that override equals and/or hashCode but lack a matching EqualsVerifier unit test. All identified classes that implement these methods are already covered by EqualsVerifier.

}

@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (!(obj instanceof FilterSettings))
{
return false;
}
final FilterSettings other = (FilterSettings) obj;
if (this.artifactTypes == null)
{
if (other.artifactTypes != null)
{
return false;
}
}
else if (!this.artifactTypes.equals(other.artifactTypes))
{
return false;
}
if (this.withoutTags != other.withoutTags)
{
return false;
}
if (this.tags == null)
{
if (other.tags != null)
{
return false;
}
}
else if (!this.tags.equals(other.tags))
{
public boolean equals(final Object other) {
if (!(other instanceof final FilterSettings that)) {
return false;
}
return true;
return withoutTags == that.withoutTags && Objects.equals(artifactTypes, that.artifactTypes)
&& Objects.equals(tags, that.tags);
}

/**
Expand All @@ -160,7 +120,7 @@ public static Builder builder()
/**
* Builder for {@link FilterSettings}
*/
public static class Builder
public static final class Builder
{
private Set<String> artifactTypes = Collections.emptySet();
private Set<String> tags = Collections.emptySet();
Expand All @@ -180,7 +140,7 @@ private Builder()
*/
public Builder artifactTypes(final Set<String> artifactTypes)
{
this.artifactTypes = artifactTypes;
this.artifactTypes = Set.copyOf(artifactTypes);
return this;
}

Expand All @@ -193,7 +153,7 @@ public Builder artifactTypes(final Set<String> artifactTypes)
*/
public Builder tags(final Set<String> tags)
{
this.tags = tags;
this.tags = Set.copyOf(tags);
return this;
}

Expand All @@ -220,4 +180,4 @@ public FilterSettings build()
return new FilterSettings(this);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* This class implements a parameter object to control the settings of OFT's
* report mode.
*/
public class ReportSettings
public final class ReportSettings
{
private final ReportVerbosity verbosity;
private final boolean showOrigin;
Expand Down Expand Up @@ -112,12 +112,12 @@ public static Builder builder()
/**
* Builder for {@link ReportSettings}
*/
public static class Builder
public static final class Builder
{
private DetailsSectionDisplay detailsSectionDisplay = DetailsSectionDisplay.COLLAPSE;
private Newline newline = Newline.UNIX;
private String outputFormat = ReportConstants.DEFAULT_REPORT_FORMAT;
private boolean showOrigin = false;
private boolean showOrigin;
private ReportVerbosity verbosity = ReportVerbosity.FAILURE_DETAILS;
private ColorScheme colorScheme = ColorScheme.BLACK_AND_WHITE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public interface DirectoryService
* @return current directory
*/
String getCurrent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public enum DeepCoverageStatus

private final int badness;

private DeepCoverageStatus(final int badness)
DeepCoverageStatus(final int badness)
{
this.badness = badness;
}

/**
* Get the worse of two coverage status
* Get the worst of two coverage statuses
*
* @param a
* left status to compare
* @param b
* right status to compare
* @return worse of both provided status
* @return worse of both provided statuses
*/
public static DeepCoverageStatus getWorst(final DeepCoverageStatus a,
final DeepCoverageStatus b)
{
return (b.badness > a.badness) ? b : a;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.itsallcode.openfasttrace.api.core;

import java.util.Locale;

/**
* This enumeration represents the different statuses of an item.
*/
Expand Down Expand Up @@ -47,6 +49,6 @@ public static ItemStatus parseString(final String text)
@Override
public String toString()
{
return this.name().toLowerCase();
return this.name().toLowerCase(Locale.ENGLISH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public enum LinkStatus
private final String shortTag;
private final String text;

private LinkStatus(final String shortTag, final String text)
LinkStatus(final String shortTag, final String text)
{
this.shortTag = shortTag;
this.text = text;
Expand Down Expand Up @@ -92,8 +92,10 @@ public boolean isOutgoing()
*/
public boolean isBadOutgoing()
{
return (this == PREDATED) || (this == OUTDATED) || (this == AMBIGUOUS) || (this == UNWANTED)
|| (this == ORPHANED);
return switch (this) {
case PREDATED, OUTDATED, AMBIGUOUS, UNWANTED, ORPHANED -> true;
default -> false;
};
}

/**
Expand Down Expand Up @@ -148,4 +150,4 @@ public String toString()
{
return this.text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void cacheOverCoveredArtifactType(final LinkedSpecificationItem overcove
*/
public Map<LinkStatus, List<LinkedSpecificationItem>> getLinks()
{
return this.links;
return new EnumMap<>(this.links);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make immutable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This one is tricky, since there is a bidirectional linking mechanism in the way.
Create issue #540.

}

/**
Expand Down Expand Up @@ -249,7 +249,7 @@ public List<String> getNeedsArtifactTypes()
*/
public Set<String> getCoveredArtifactTypes()
{
return this.coveredArtifactTypes;
return Collections.unmodifiableSet(this.coveredArtifactTypes);
}

/**
Expand All @@ -259,7 +259,7 @@ public Set<String> getCoveredArtifactTypes()
*/
public Set<String> getCoveredApprovedArtifactTypes()
{
return this.coveredArtifactTypesFromApprovedItems;
return Collections.unmodifiableSet(this.coveredArtifactTypesFromApprovedItems);
}

/**
Expand All @@ -270,7 +270,7 @@ public Set<String> getCoveredApprovedArtifactTypes()
public Set<String> getOverCoveredArtifactTypes()
{

return this.overCoveredArtifactTypes;
return Collections.unmodifiableSet(this.overCoveredArtifactTypes);
}

/**
Expand Down Expand Up @@ -416,9 +416,9 @@ private List<LinkedSpecificationItem> getIncomingItems()
public boolean isDefect()
{
return hasDuplicates() //
|| (getStatus() != ItemStatus.REJECTED) //
|| ((getStatus() != ItemStatus.REJECTED) //
&& (hasBadLinks()
|| (getDeepCoverageStatus() != DeepCoverageStatus.COVERED));
|| (getDeepCoverageStatus() != DeepCoverageStatus.COVERED)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.itsallcode.openfasttrace.api.core;

import java.util.Objects;

/**
* The location of a coverage item.
*/
Expand Down Expand Up @@ -112,58 +114,23 @@ public int getColumn()
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + this.column;
result = prime * result + this.line;
result = prime * result + ((this.path == null) ? 0 : this.path.hashCode());
return result;
return Objects.hash(this.column, this.line, this.path);
}

@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final Location other = (Location) obj;
if (this.column != other.column)
{
return false;
}
if (this.line != other.line)
{
return false;
}
if (this.path == null)
{
if (other.path != null)
{
return false;
}
}
else if (!this.path.equals(other.path))
{
public boolean equals(final Object other) {
if (!(other instanceof final Location location)) {
return false;
}
return true;
return line == location.line && column == location.column && Objects.equals(path, location.path);
}

@Override
public String toString()
{
return this.path //
+ (this.line != NO_LINE ? ":" + this.line : "") //
+ (this.column != NO_COLUMN ? ":" + this.column : "");
+ ((this.line != NO_LINE) ? (":" + this.line) : "") //
+ ((this.column != NO_COLUMN) ? (":" + this.column) : "");
}

/**
Expand All @@ -180,7 +147,7 @@ public static Builder builder()
* A builder for {@link Location}. Use {@link Location#builder()} to create
* a new builder and call {@link #build()} to build a {@link Location}.
*/
public static class Builder
public static final class Builder
{
private String path;
private int line = NO_LINE;
Expand Down Expand Up @@ -250,4 +217,4 @@ public boolean isCompleteEnough()
return this.path != null && !this.path.isEmpty();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum Newline
private static final Pattern ANY_NEWLINE_PATTERN = Pattern.compile(ANY_NEWLINE_REG_EX);
private final String representation;

private Newline(final String representation)
Newline(final String representation)
{
this.representation = representation;
}
Expand All @@ -38,18 +38,14 @@ public String toString()
*/
public static Newline fromRepresentation(final String representation)
{
switch (representation)
return switch (representation)
{
case "\n":
return UNIX;
case "\r\n":
return WINDOWS;
case "\r":
return OLDMAC;
default:
throw new IllegalArgumentException(
case "\n" -> UNIX;
case "\r\n" -> WINDOWS;
case "\r" -> OLDMAC;
default -> throw new IllegalArgumentException(
"Line separator not supported: '" + representation + "'");
}
};
}

/**
Expand Down
Loading
Loading