001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 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.plugins.surefire.data;
021
022 import com.google.common.collect.Maps;
023 import com.google.common.collect.Sets;
024
025 import java.util.*;
026
027 /**
028 * @since 2.8
029 */
030 public class UnitTestIndex {
031
032 private Map<String, UnitTestClassReport> indexByClassname;
033
034 public UnitTestIndex() {
035 this.indexByClassname = Maps.newHashMap();
036 }
037
038 public UnitTestClassReport index(String classname) {
039 UnitTestClassReport classReport = indexByClassname.get(classname);
040 if (classReport == null) {
041 classReport = new UnitTestClassReport();
042 indexByClassname.put(classname, classReport);
043 }
044 return classReport;
045 }
046
047 public UnitTestClassReport get(String classname) {
048 return indexByClassname.get(classname);
049 }
050
051 public Set<String> getClassnames() {
052 return Sets.newHashSet(indexByClassname.keySet());
053 }
054
055 public Map<String, UnitTestClassReport> getIndexByClassname() {
056 return indexByClassname;
057 }
058
059 public int size() {
060 return indexByClassname.size();
061 }
062
063 public UnitTestClassReport merge(String classname, String intoClassname) {
064 UnitTestClassReport from = indexByClassname.get(classname);
065 if (from!=null) {
066 UnitTestClassReport to = index(intoClassname);
067 to.add(from);
068 indexByClassname.remove(classname);
069 return to;
070 }
071 return null;
072 }
073
074 public void remove(String classname) {
075 indexByClassname.remove(classname);
076 }
077
078
079 }