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 */ 020package org.sonar.core.review; 021 022import com.google.common.base.Predicate; 023import org.apache.commons.lang.ArrayUtils; 024 025import javax.annotation.Nullable; 026 027/** 028 * @since 2.14 029 */ 030public final class ReviewPredicates { 031 032 private ReviewPredicates() { 033 } 034 035 public static Predicate<ReviewDto> status(String... statuses) { 036 return new StatusPredicate(statuses); 037 } 038 039 public static Predicate<ReviewDto> resolution(String... resolutions) { 040 return new ResolutionPredicate(resolutions); 041 } 042 043 public static Predicate<ReviewDto> manualViolation() { 044 return ManualViolationPredicate.INSTANCE; 045 } 046 047 public static Predicate<ReviewDto> manualSeverity() { 048 return ManualSeverityPredicate.INSTANCE; 049 } 050 051 private static final class StatusPredicate implements Predicate<ReviewDto> { 052 private String[] statuses; 053 054 private StatusPredicate(String... statuses) { 055 this.statuses = statuses; 056 } 057 058 public boolean apply(@Nullable ReviewDto review) { 059 return review!=null && ArrayUtils.contains(statuses, review.getStatus()); 060 } 061 } 062 063 private static final class ResolutionPredicate implements Predicate<ReviewDto> { 064 private String[] resolutions; 065 066 private ResolutionPredicate(String... resolutions) { 067 this.resolutions = resolutions; 068 } 069 070 public boolean apply(@Nullable ReviewDto review) { 071 return review!=null && ArrayUtils.contains(resolutions, review.getResolution()); 072 } 073 } 074 075 private static final class ManualViolationPredicate implements Predicate<ReviewDto> { 076 private static final ManualViolationPredicate INSTANCE = new ManualViolationPredicate(); 077 078 private ManualViolationPredicate() { 079 } 080 081 public boolean apply(@Nullable ReviewDto review) { 082 return review!=null && review.isManualViolation(); 083 } 084 } 085 086 private static final class ManualSeverityPredicate implements Predicate<ReviewDto> { 087 private static final ManualSeverityPredicate INSTANCE = new ManualSeverityPredicate(); 088 089 private ManualSeverityPredicate() { 090 } 091 092 public boolean apply(@Nullable ReviewDto review) { 093 return review!=null && review.isManualSeverity(); 094 } 095 } 096}