diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-15 15:27:13 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-07-15 15:27:13 +0200 |
commit | 92abc2254d331891406f31b884760a1cd5326cfc (patch) | |
tree | ac8aa65bc7e93cb6b3080df60f7b38542f9cd4b0 /sonar-core | |
parent | 8613533e2166c217f27beaf00c71e940fe6fc084 (diff) | |
download | sonarqube-92abc2254d331891406f31b884760a1cd5326cfc.tar.gz sonarqube-92abc2254d331891406f31b884760a1cd5326cfc.zip |
Drop use of ad-hoc MultiSets and use Guava's instead
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/util/MultiSets.java | 61 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/util/MultiSetsTest.java | 48 |
2 files changed, 0 insertions, 109 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/util/MultiSets.java b/sonar-core/src/main/java/org/sonar/core/util/MultiSets.java deleted file mode 100644 index 4606b93704c..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/util/MultiSets.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.util; - -import com.google.common.collect.Multiset; -import com.google.common.collect.Ordering; -import com.google.common.primitives.Ints; -import java.util.List; - -/** - * Utility class heavily inspired by Guava - */ -public class MultiSets { - - private static final Ordering<Multiset.Entry<?>> DECREASING_COUNT_ORDERING = new NonNullOrdering<Multiset.Entry<?>>() { - @Override - public int doCompare(Multiset.Entry<?> entry1, Multiset.Entry<?> entry2) { - return Ints.compare(entry2.getCount(), entry1.getCount()); - } - }; - - private MultiSets() { - - } - - /** - * Returns a copy of {@code multiset} as a {@link List} whose iteration order is - * highest count first, with ties broken by the iteration order of the original multiset. - */ - public static <E> List<Multiset.Entry<E>> listOrderedByHighestCounts(Multiset<E> multiset) { - return DECREASING_COUNT_ORDERING.sortedCopy(multiset.entrySet()); - } - - private abstract static class NonNullOrdering<T> extends Ordering<T> { - - @Override - public int compare(T left, T right) { - return doCompare(left, right); - } - - public abstract int doCompare(T left, T right); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/util/MultiSetsTest.java b/sonar-core/src/test/java/org/sonar/core/util/MultiSetsTest.java deleted file mode 100644 index 9d4b0ed4614..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/util/MultiSetsTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.util; - -import com.google.common.collect.HashMultiset; -import com.google.common.collect.Multiset; -import java.util.List; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MultiSetsTest { - @Test - public void order_with_highest_count_first() { - Multiset<String> multiset = HashMultiset.create(); - add(multiset, "seneca", 10); - add(multiset, "plato", 5); - add(multiset, "confucius", 3); - - List<Multiset.Entry<String>> orderedEntries = MultiSets.listOrderedByHighestCounts(multiset); - - assertThat(orderedEntries).extracting("element").containsExactly("seneca", "plato", "confucius"); - } - - private void add(Multiset<String> multiset, String element, int times) { - for (int i = 0; i < times; i++) { - multiset.add(element); - } - } -} |