-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d94e7f
commit 0b8af64
Showing
39 changed files
with
568 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.okhttpcache | ||
.classpath | ||
.project | ||
.settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 21 additions & 23 deletions
44
src/main/java/se/bjurr/violations/lib/ViolationsAccumulatedReporterApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,51 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static com.google.common.collect.Iterables.filter; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.google.common.collect.Ordering.from; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
public class ViolationsAccumulatedReporterApi { | ||
|
||
private final List<Violation> violations = newArrayList(); | ||
public static ViolationsAccumulatedReporterApi violationsAccumulatedReporterApi() { | ||
return new ViolationsAccumulatedReporterApi(); | ||
} | ||
|
||
private SEVERITY atLeastSeverity = INFO; | ||
private ORDERED_BY orderedBy; | ||
|
||
private final List<Violation> violations = new ArrayList<>(); | ||
|
||
private ViolationsAccumulatedReporterApi() { | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi withViolationsReporterApiList(List<Violation> violations) { | ||
this.violations.addAll(violations); | ||
public ViolationsAccumulatedReporterApi orderedBy(ORDERED_BY orderedBy) { | ||
this.orderedBy = orderedBy; | ||
return this; | ||
} | ||
|
||
public static ViolationsAccumulatedReporterApi violationsAccumulatedReporterApi() { | ||
return new ViolationsAccumulatedReporterApi(); | ||
public List<Violation> violations() { | ||
List<Violation> sorted = new ArrayList<>(); | ||
for (Violation violation : violations) { | ||
if (violation.getSeverity().ordinal() >= atLeastSeverity.ordinal()) { | ||
sorted.add(violation); | ||
} | ||
} | ||
Collections.sort(sorted, orderedBy.getComparator()); | ||
return sorted; | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi withAtLeastSeverity(SEVERITY atLeastSeverity) { | ||
this.atLeastSeverity = atLeastSeverity; | ||
return this; | ||
} | ||
|
||
public ViolationsAccumulatedReporterApi orderedBy(ORDERED_BY orderedBy) { | ||
this.orderedBy = orderedBy; | ||
public ViolationsAccumulatedReporterApi withViolationsReporterApiList(List<Violation> violations) { | ||
this.violations.addAll(violations); | ||
return this; | ||
} | ||
|
||
public List<Violation> violations() { | ||
return from(orderedBy.getComparator())// | ||
.sortedCopy(// | ||
filter(violations, new Predicate<Violation>() { | ||
@Override | ||
public boolean apply(Violation input) { | ||
return input.getSeverity().ordinal() >= atLeastSeverity.ordinal(); | ||
} | ||
})); | ||
} | ||
} |
Oops, something went wrong.