001    /*
002     * Sonar, open source software quality management tool.
003     * Copyright (C) 2008-2011 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.api.violations;
021    
022    import org.sonar.api.resources.Resource;
023    
024    /**
025     * Class that allows to query the Sonar index about violations.
026     * 
027     * @since 2.8
028     */
029    public final class ViolationQuery {
030    
031      private boolean isSwitchedOff;
032      private Resource resource;
033    
034      /**
035       * Use the factory method <code>create()</code>
036       */
037      ViolationQuery() {
038      }
039    
040      /**
041       * Creates a new {@link ViolationQuery} object.
042       * 
043       * @return the new query
044       */
045      public static ViolationQuery create() {
046        return new ViolationQuery();
047      }
048    
049      /**
050       * Specifies if the query should returned switched-off violations or not.
051       * 
052       * @param ignore
053       *          if true, the query will return only switched-off violations. if false, it will return only active violations.
054       * @return the current violation query
055       */
056      public ViolationQuery setSwitchedOff(boolean ignore) {
057        this.isSwitchedOff = ignore;
058        return this;
059      }
060    
061      /**
062       * Tells if the query should returned switched-off violations or active violations.
063       * 
064       * @return
065       */
066      public boolean isSwitchedOff() {
067        return isSwitchedOff;
068      }
069    
070      /**
071       * Specifies the resource which violations are search from.
072       * 
073       * @param resource
074       *          the resource
075       */
076      public ViolationQuery forResource(Resource resource) {
077        this.resource = resource;
078        return this;
079      }
080    
081      /**
082       * Returns the resource which violations are search from.
083       * 
084       * @return the resource
085       */
086      public Resource getResource() {
087        return resource;
088      }
089    }