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.web.gwt.client.webservices;
021    
022    import java.util.ArrayList;
023    import java.util.HashMap;
024    import java.util.List;
025    import java.util.Map;
026    
027    /**
028     * @deprecated since 2.5
029     */
030    @Deprecated
031    public class Violations extends ResponsePOJO {
032      private List<Violation> violations;
033      private Map<Integer, List<Violation>> byLines;
034    
035      public Violations(List<Violation> violations) {
036        this.violations = violations;
037      }
038    
039      public Violations() {
040        this.violations = new ArrayList<Violation>();
041      }
042    
043      public void add(Violation v) {
044        violations.add(v);
045        byLines = null;
046      }
047    
048      public List<Violation> getAll() {
049        return violations;
050      }
051    
052      public Map<Integer, List<Violation>> getByLines() {
053        if (byLines == null) {
054          byLines = new HashMap<Integer, List<Violation>>();
055          for (Violation violation : violations) {
056            List<Violation> lineViolations = byLines.get(violation.getLine());
057            if (lineViolations == null) {
058              lineViolations = new ArrayList<Violation>();
059              byLines.put(violation.getLine(), lineViolations);
060            }
061            lineViolations.add(violation);
062          }
063        }
064        return byLines;
065      }
066    
067      public String getLevelForLine(Integer line) {
068        List<Violation> lineViolations = getByLines().get(line);
069        String level = "";
070        if (lineViolations != null) {
071          for (Violation lineViolation : lineViolations) {
072            if ("BLOCKER".equals(lineViolation.getPriority()) || "CRITICAL".equals(lineViolation.getPriority())
073                || "MAJOR".equals(lineViolation.getPriority())) {
074              level = "error";
075    
076            } else if (!"error".equals(level)) {
077              level = "warning";
078            }
079          }
080        }
081        return level;
082      }
083    
084      public int countForLine(Integer line) {
085        List<Violation> lineViolations = getByLines().get(line);
086        if (lineViolations == null) {
087          return 0;
088        }
089        return lineViolations.size();
090      }
091    }