Debian Codegraph @

scala-unit-tests/src/test/scala/org/eclipse/collections/impl/MutableAnagramTest.scala

raw
1 /*
2 * Copyright (c) 2021 Goldman Sachs.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
6 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7 * and the Eclipse Distribution License is available at
8 * http://www.eclipse.org/org/documents/edl-v10.php.
9 */
10
11 package org.eclipse.collections.impl
12
13 import java.util.Collections
14
15 import org.eclipse.collections.api._
16 import org.eclipse.collections.api.block.function.Function
17 import org.eclipse.collections.impl.Prelude._
18 import org.eclipse.collections.impl.block.factory.Comparators
19 import org.eclipse.collections.impl.list.mutable.FastList
20 import org.eclipse.collections.impl.utility.internal.IteratorIterate
21 import org.junit.Test
22 import org.slf4j.LoggerFactory
23
24 object MutableAnagramTest
25 {
26 val LOGGER = LoggerFactory.getLogger(classOf[MutableAnagramTest])
27 }
28
29 class MutableAnagramTest
30 {
31 val SIZE_THRESHOLD = 10
32 val WORDS = FastList.newListWith("alerts", "alters", "artels", "estral", "laster", "ratels", "salter", "slater", "staler", "stelar", "talers", "least", "setal", "slate", "stale", "steal", "stela", "taels", "tales", "teals", "tesla").iterator
33
34 @Test
35 def testAnagrams
36 {
37 val sizeOfIterable: Function[RichIterable[String], Integer] = (iterable: RichIterable[String]) => Integer.valueOf(iterable.size)
38 IteratorIterate.groupBy(WORDS, (string: String) => string.sortWith(_ > _))
39 .multiValuesView
40 .select((iterable: RichIterable[String]) => iterable.size > SIZE_THRESHOLD)
41 .toSortedList(Collections.reverseOrder(Comparators.byFunction[RichIterable[String], Integer](sizeOfIterable)))
42 .asLazy
43 .collect[String]((iterable: RichIterable[String]) => iterable.size + ": " + iterable)
44 .forEach((string: String) => MutableAnagramTest.LOGGER.info(string))
45 }
46 }