001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.core.review;
021
022 import com.google.common.base.Predicate;
023 import org.apache.commons.lang.ArrayUtils;
024
025 /**
026 * @since 2.14
027 */
028 public final class ReviewPredicates {
029
030 private ReviewPredicates() {
031 }
032
033 public static Predicate<ReviewDto> status(String... statuses) {
034 return new StatusPredicate(statuses);
035 }
036
037 public static Predicate<ReviewDto> resolution(String... resolutions) {
038 return new ResolutionPredicate(resolutions);
039 }
040
041 public static Predicate<ReviewDto> manualViolation() {
042 return ManualViolationPredicate.INSTANCE;
043 }
044
045 public static Predicate<ReviewDto> manualSeverity() {
046 return ManualSeverityPredicate.INSTANCE;
047 }
048
049 private static final class StatusPredicate implements Predicate<ReviewDto> {
050 private String[] statuses;
051
052 private StatusPredicate(String... statuses) {
053 this.statuses = statuses;
054 }
055
056 public boolean apply(ReviewDto review) {
057 return ArrayUtils.contains(statuses, review.getStatus());
058 }
059 }
060
061 private static final class ResolutionPredicate implements Predicate<ReviewDto> {
062 private String[] resolutions;
063
064 private ResolutionPredicate(String... resolutions) {
065 this.resolutions = resolutions;
066 }
067
068 public boolean apply(ReviewDto review) {
069 return ArrayUtils.contains(resolutions, review.getResolution());
070 }
071 }
072
073 private static final class ManualViolationPredicate implements Predicate<ReviewDto> {
074 private static final ManualViolationPredicate INSTANCE = new ManualViolationPredicate();
075
076 private ManualViolationPredicate() {
077 }
078
079 public boolean apply(ReviewDto review) {
080 return review.isManualViolation();
081 }
082 }
083
084 private static final class ManualSeverityPredicate implements Predicate<ReviewDto> {
085 private static final ManualSeverityPredicate INSTANCE = new ManualSeverityPredicate();
086
087 private ManualSeverityPredicate() {
088 }
089
090 public boolean apply(ReviewDto review) {
091 return review.isManualSeverity();
092 }
093 }
094 }