From ec4d0e0ddcc24e2169e3ec82b04a0734979dbc65 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 28 Jan 2011 10:26:31 +0100 Subject: [PATCH] add methods Scopes#isHigherThan() and isHigherThanOrEquals() --- .../java/org/sonar/api/resources/Scopes.java | 33 ++++++++++++++++--- .../org/sonar/api/resources/ScopesTest.java | 20 +++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java index d9fdf46fa97..ff4f05d4dc0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Scopes.java @@ -19,6 +19,7 @@ */ package org.sonar.api.resources; +import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; /** @@ -63,24 +64,46 @@ public final class Scopes { */ public static final String BLOCK_UNIT = "BLU"; + public static final String[] SORTED_SCOPES = {PROJECT, DIRECTORY, FILE, TYPE, BLOCK_UNIT}; + public static boolean isProject(final Resource resource) { - return resource!=null && StringUtils.equals(PROJECT, resource.getScope()); + return StringUtils.equals(PROJECT, resource.getScope()); } public static boolean isDirectory(final Resource resource) { - return resource!=null && StringUtils.equals(DIRECTORY, resource.getScope()); + return StringUtils.equals(DIRECTORY, resource.getScope()); } public static boolean isFile(final Resource resource) { - return resource!=null && StringUtils.equals(FILE, resource.getScope()); + return StringUtils.equals(FILE, resource.getScope()); } public static boolean isType(final Resource resource) { - return resource!=null && StringUtils.equals(TYPE, resource.getScope()); + return StringUtils.equals(TYPE, resource.getScope()); } public static boolean isBlockUnit(final Resource resource) { - return resource!=null && StringUtils.equals(BLOCK_UNIT, resource.getScope()); + return StringUtils.equals(BLOCK_UNIT, resource.getScope()); + } + + public static boolean isHigherThan(final Resource resource, final String than) { + return isHigherThan(resource.getScope(), than); + } + + public static boolean isHigherThan(final String scope, final String than) { + int index = ArrayUtils.indexOf(SORTED_SCOPES, scope); + int thanIndex = ArrayUtils.indexOf(SORTED_SCOPES, than); + return index