001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2014 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * SonarQube 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     * SonarQube 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 License
017     * along with this program; if not, write to the Free Software Foundation,
018     * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     * @deprecated in 3.6 for the merge of violations and reviews into issues.
029     */
030    @Deprecated
031    public final class ViolationQuery {
032    
033      public static enum SwitchMode {
034        OFF, ON, BOTH
035      }
036    
037      private SwitchMode switchMode = SwitchMode.ON;
038      private Resource resource;
039    
040      /**
041       * Use the factory method <code>create()</code>
042       */
043      ViolationQuery() {
044      }
045    
046      /**
047       * Creates a new {@link ViolationQuery} object.
048       * 
049       * @return the new query
050       */
051      public static ViolationQuery create() {
052        return new ViolationQuery();
053      }
054    
055      /**
056       * Specifies if the query should return only switched-off violations.
057       * 
058       * @param b
059       *          if true, the query will return only switched-off violations. if false, it will return only active violations.
060       * @return the current violation query
061       */
062      public ViolationQuery setSwitchedOff(boolean b) {
063        this.switchMode = (b ? SwitchMode.OFF : SwitchMode.ON);
064        return this;
065      }
066    
067      /**
068       * Tells if the query should return only switched-off violations.
069       */
070      public boolean isSwitchedOff() {
071        return switchMode == SwitchMode.OFF;
072      }
073    
074      public SwitchMode getSwitchMode() {
075        return switchMode;
076      }
077    
078      public ViolationQuery setSwitchMode(SwitchMode s) {
079        this.switchMode = s;
080        return this;
081      }
082    
083      /**
084       * Specifies the resource which violations are search from.
085       * 
086       * @param resource
087       *          the resource
088       */
089      public ViolationQuery forResource(Resource resource) {
090        this.resource = resource;
091        return this;
092      }
093    
094      /**
095       * Returns the resource which violations are search from.
096       * 
097       * @return the resource
098       */
099      public Resource getResource() {
100        return resource;
101      }
102    }