001    /*
002     * Copyright (C) 2010 Evgeny Mandrikov
003     *
004     * Sonar-IDE is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU Lesser General Public
006     * License as published by the Free Software Foundation; either
007     * version 3 of the License, or (at your option) any later version.
008     *
009     * Sonar-IDE is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012     * Lesser General Public License for more details.
013     *
014     * You should have received a copy of the GNU Lesser General Public
015     * License along with Sonar-IDE; if not, write to the Free Software
016     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
017     */
018    
019    package org.sonar.ide.shared;
020    
021    import org.sonar.wsclient.services.Metric;
022    
023    import java.util.*;
024    
025    /**
026     * @author Evgeny Mandrikov
027     */
028    public final class MetricUtils {
029      public static Map<String, List<Metric>> splitByDomain(Collection<Metric> metrics) {
030        Map<String, List<Metric>> result = new HashMap<String, List<Metric>>();
031        for (Metric metric : metrics) {
032          String domain = metric.getDomain();
033          List<Metric> domainMetrics;
034          if (result.containsKey(domain)) {
035            domainMetrics = result.get(domain);
036          } else {
037            domainMetrics = new ArrayList<Metric>();
038            result.put(domain, domainMetrics);
039          }
040          domainMetrics.add(metric);
041        }
042        return result;
043      }
044    
045      /**
046       * Hide utility-class constructor.
047       */
048      private MetricUtils() {
049      }
050    }