Search in sources :

Example 1 with MultiSet

use of org.apache.commons.collections4.MultiSet in project useful-java-links by Vedenin.

the class ApacheHashBagTest method main.

public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));
    // Print count words
    // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    System.out.println(bag);
    // Print all unique words
    // print [Hi, Hello, World!, All!] - in random orders
    System.out.println(bag.uniqueSet());
    // Print count occurrences of words
    // print 2
    System.out.println("Hello = " + bag.getCount("Hello"));
    // print 2
    System.out.println("World = " + bag.getCount("World!"));
    // print 1
    System.out.println("All = " + bag.getCount("All!"));
    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));
    // print 0
    System.out.println("Empty = " + bag.getCount("Empty"));
    // Print count all words
    // print 6
    System.out.println(bag.size());
    // Print count unique words
    // print 4
    System.out.println(bag.uniqueSet().size());
}
Also used : HashBag(org.apache.commons.collections4.bag.HashBag) Bag(org.apache.commons.collections4.Bag) HashBag(org.apache.commons.collections4.bag.HashBag)

Example 2 with MultiSet

use of org.apache.commons.collections4.MultiSet in project useful-java-links by Vedenin.

the class ApacheHashBag method main.

public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));
    // Print count words
    // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    System.out.println(bag);
    // Print all unique words
    // print [Hi, Hello, World!, All!] - in random orders
    System.out.println(bag.uniqueSet());
    // Print count occurrences of words
    // print 2
    System.out.println("Hello = " + bag.getCount("Hello"));
    // print 2
    System.out.println("World = " + bag.getCount("World!"));
    // print 1
    System.out.println("All = " + bag.getCount("All!"));
    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));
    // print 0
    System.out.println("Empty = " + bag.getCount("Empty"));
    // Print count all words
    // print 6
    System.out.println(bag.size());
    // Print count unique words
    // print 4
    System.out.println(bag.uniqueSet().size());
}
Also used : HashBag(org.apache.commons.collections4.bag.HashBag) Bag(org.apache.commons.collections4.Bag) HashBag(org.apache.commons.collections4.bag.HashBag)

Example 3 with MultiSet

use of org.apache.commons.collections4.MultiSet in project useful-java-links by Vedenin.

the class ApacheTreeBag method main.

public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = new TreeBag(Arrays.asList(INPUT_TEXT.split(" ")));
    // Print count words
    // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order
    System.out.println(bag);
    // Print all unique words
    // print [All!, Hello, Hi, World!]- in natural (alphabet) order
    System.out.println(bag.uniqueSet());
    // Print count occurrences of words
    // print 2
    System.out.println("Hello = " + bag.getCount("Hello"));
    // print 2
    System.out.println("World = " + bag.getCount("World!"));
    // print 1
    System.out.println("All = " + bag.getCount("All!"));
    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));
    // print 0
    System.out.println("Empty = " + bag.getCount("Empty"));
    // Print count all words
    // print 6
    System.out.println(bag.size());
    // Print count unique words
    // print 4
    System.out.println(bag.uniqueSet().size());
}
Also used : TreeBag(org.apache.commons.collections4.bag.TreeBag) TreeBag(org.apache.commons.collections4.bag.TreeBag) Bag(org.apache.commons.collections4.Bag)

Example 4 with MultiSet

use of org.apache.commons.collections4.MultiSet in project useful-java-links by Vedenin.

the class ApacheSynchronizedSortedBag method main.

public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))));
    // Print count words
    // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order
    System.out.println(bag);
    // Print all unique words
    // print [All!, Hello, Hi, World!]- in natural (alphabet) order
    System.out.println(bag.uniqueSet());
    // Print count occurrences of words
    // print 2
    System.out.println("Hello = " + bag.getCount("Hello"));
    // print 2
    System.out.println("World = " + bag.getCount("World!"));
    // print 1
    System.out.println("All = " + bag.getCount("All!"));
    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));
    // print 0
    System.out.println("Empty = " + bag.getCount("Empty"));
    // Print count all words
    // print 6
    System.out.println(bag.size());
    // Print count unique words
    // print 4
    System.out.println(bag.uniqueSet().size());
}
Also used : TreeBag(org.apache.commons.collections4.bag.TreeBag) SynchronizedSortedBag(org.apache.commons.collections4.bag.SynchronizedSortedBag) TreeBag(org.apache.commons.collections4.bag.TreeBag) Bag(org.apache.commons.collections4.Bag)

Example 5 with MultiSet

use of org.apache.commons.collections4.MultiSet in project useful-java-links by Vedenin.

the class ApacheSynchronizedSortedBagTest method main.

public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(" "))));
    // Print count words
    // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order
    System.out.println(bag);
    // Print all unique words
    // print [All!, Hello, Hi, World!]- in natural (alphabet) order
    System.out.println(bag.uniqueSet());
    // Print count occurrences of words
    // print 2
    System.out.println("Hello = " + bag.getCount("Hello"));
    // print 2
    System.out.println("World = " + bag.getCount("World!"));
    // print 1
    System.out.println("All = " + bag.getCount("All!"));
    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));
    // print 0
    System.out.println("Empty = " + bag.getCount("Empty"));
    // Print count all words
    // print 6
    System.out.println(bag.size());
    // Print count unique words
    // print 4
    System.out.println(bag.uniqueSet().size());
}
Also used : TreeBag(org.apache.commons.collections4.bag.TreeBag) SynchronizedSortedBag(org.apache.commons.collections4.bag.SynchronizedSortedBag) TreeBag(org.apache.commons.collections4.bag.TreeBag) Bag(org.apache.commons.collections4.Bag)

Aggregations

Bag (org.apache.commons.collections4.Bag)8 HashBag (org.apache.commons.collections4.bag.HashBag)4 TreeBag (org.apache.commons.collections4.bag.TreeBag)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FieldVector (org.apache.arrow.vector.FieldVector)2 SynchronizedBag (org.apache.commons.collections4.bag.SynchronizedBag)2 SynchronizedSortedBag (org.apache.commons.collections4.bag.SynchronizedSortedBag)2 HashMultiSet (org.apache.commons.collections4.multiset.HashMultiSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 BufferAllocator (org.apache.arrow.memory.BufferAllocator)1 MultiSet (org.apache.commons.collections4.MultiSet)1 CalendarUtils (org.apache.hadoop.hive.common.type.CalendarUtils)1