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 isSet(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 isSubview(Resource resource) {
041        return isSet(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 whether 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 != null && Resource.QUALIFIER_PACKAGE.equals(resource.getQualifier());
063      }
064    
065      /**
066       * @return whether a resource is a set
067       */
068      public static boolean isSet(Resource resource) {
069        return resource != null && Resource.SCOPE_SET.equals(resource.getScope());
070      }
071    
072      /**
073       * @return whether a resource is a space
074       */
075      public static boolean isSpace(Resource resource) {
076        return resource != null && Resource.SCOPE_SPACE.equals(resource.getScope());
077      }
078    
079      /**
080       * @return whether a resource is an entity.
081       */
082      public static boolean isEntity(Resource resource) {
083        return resource != null && Resource.SCOPE_ENTITY.equals(resource.getScope());
084      }
085    
086      /**
087       * This method equal isRootProject(resource) or isModuleProject(resource)
088       */
089      public static boolean isProject(Resource resource) {
090        return isSet(resource);
091      }
092    
093      /**
094       * Alias for {@link #isSpace(Resource)}
095       */
096      public static boolean isDirectory(Resource resource) {
097        return isSpace(resource);
098      }
099    
100      /**
101       * Alias for {@link #isEntity(Resource)}
102       */
103      public static boolean isFile(Resource resource) {
104        return isEntity(resource);
105      }
106    
107      /* QUALIFIERS */
108    
109      /**
110       * @return whether a resource is a class
111       */
112      public static boolean isClass(Resource resource) {
113        return Resource.QUALIFIER_CLASS.equals(resource.getQualifier());
114      }
115    
116      /**
117       * @return whether a resource is a unit test class
118       */
119      public static boolean isUnitTestClass(Resource resource) {
120        return Resource.QUALIFIER_UNIT_TEST_CLASS.equals(resource.getQualifier());
121      }
122    
123      /**
124       * @return whether a resource is a library
125       */
126      public static boolean isLibrary(Resource resource) {
127        return Resource.QUALIFIER_LIB.equals(resource.getQualifier());
128      }
129    }