001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2009 SonarSource SA
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.api.resources;
021    
022    /**
023     * @since 1.10
024     */
025    public final class ResourceUtils {
026    
027      private ResourceUtils() {
028      }
029    
030      /**
031       * @return whether the resource is a view
032       */
033      public static boolean isView(Resource resource) {
034        return isSpace(resource) && Resource.QUALIFIER_VIEW.equals(resource.getQualifier());
035      }
036    
037      /**
038       * @return whether the resource is a subview (in the view tree)
039       */
040      public static boolean isSubiew(Resource resource) {
041        return isSpace(resource) && Resource.QUALIFIER_SUBVIEW.equals(resource.getQualifier());
042      }
043    
044      /**
045       * @return whether the resource is the root project
046       */
047      public static boolean isRootProject(Resource resource) {
048        return Resource.QUALIFIER_PROJECT.equals(resource.getQualifier());
049      }
050    
051      /**
052       * @return whther a resource is a maven module of  project
053       */
054      public static boolean isModuleProject(Resource resource) {
055        return Resource.QUALIFIER_MODULE.equals(resource.getQualifier());
056      }
057    
058      /**
059       * @return whether a resource is a package
060       */
061      public static boolean isPackage(Resource resource) {
062        return Resource.QUALIFIER_PACKAGE.equals(resource.getQualifier());
063      }
064    
065    
066    
067    
068      /**
069       * @return whether a resource is a set
070       */
071      public static boolean isSet(Resource resource) {
072        return Resource.SCOPE_SET.equals(resource.getScope());
073      }
074    
075      /**
076       * @return whether a resource is a space
077       */
078      public static boolean isSpace(Resource resource) {
079        return Resource.SCOPE_SPACE.equals(resource.getScope());
080      }
081    
082      /**
083       * @return whether a resource is an entity
084       */
085      public static boolean isEntity(Resource resource) {
086        return Resource.SCOPE_ENTITY.equals(resource.getScope());
087      }
088    
089      /**
090       * Use isSet() instead
091       */
092      @Deprecated
093      public static boolean isProject(Resource resource) {
094        return isSet(resource);
095      }
096    
097      /**
098       * Use isSpace() instead
099       */
100      @Deprecated
101      public static boolean isDirectory(Resource resource) {
102        return isSpace(resource);
103      }
104    
105      /**
106       * Use isEntity() instead
107       */
108      @Deprecated
109      public static boolean isFile(Resource resource) {
110        return isEntity(resource);
111      }
112    
113    
114      /* QUALIFIERS */
115    
116      /**
117       * @return whether a resource is a class
118       */
119      public static boolean isClass(Resource resource) {
120        return Resource.QUALIFIER_CLASS.equals(resource.getQualifier());
121      }
122    
123    
124    
125      /**
126       * @return whether a resource is a unit test class
127       */
128      public static boolean isUnitTestClass(Resource resource) {
129        return Resource.QUALIFIER_UNIT_TEST_CLASS.equals(resource.getQualifier());
130      }
131    
132    
133    
134    
135    }