org.apache.commons.collections4.bag.HashBag Java Examples

The following examples show how to use org.apache.commons.collections4.bag.HashBag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApacheSynchronizedBagTest.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // Parse text to separate words
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Create Multiset
    Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));

    // Print count words
    System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    // Print all unique words
    System.out.println(bag.uniqueSet());    // print [Hi, Hello, World!, All!] - in random orders

    // Print count occurrences of words
    System.out.println("Hello = " + bag.getCount("Hello"));    // print 2
    System.out.println("World = " + bag.getCount("World!"));    // print 2
    System.out.println("All = " + bag.getCount("All!"));    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // print 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // print 0

    // Print count all words
    System.out.println(bag.size());    //print 6

    // Print count unique words
    System.out.println(bag.uniqueSet().size());    //print 4
}
 
Example #2
Source File: ApacheHashBagTest.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
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
    System.out.println(bag); // print [1:Hi,2:Hello,2:World!,1:All!] - in random orders
    // Print all unique words
    System.out.println(bag.uniqueSet());    // print [Hi, Hello, World!, All!] - in random orders

    // Print count occurrences of words
    System.out.println("Hello = " + bag.getCount("Hello"));    // print 2
    System.out.println("World = " + bag.getCount("World!"));    // print 2
    System.out.println("All = " + bag.getCount("All!"));    // print 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // print 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // print 0

    // Print count all words
    System.out.println(bag.size());    //print 6

    // Print count unique words
    System.out.println(bag.uniqueSet().size());    //print 4
}
 
Example #3
Source File: ApacheSynchronizedBagTest.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // Разберем текст на слова
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Создаем Multiset
    Bag bag = SynchronizedBag.synchronizedBag(new HashBag(Arrays.asList(INPUT_TEXT.split(" "))));

    // Выводим кол-вом вхождений слов
    System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(bag.uniqueSet());    // напечатает [Hi, Hello, World!, All!] - в произвольном порядке

    // Выводим количество по каждому слову
    System.out.println("Hello = " + bag.getCount("Hello"));    // напечатает 2
    System.out.println("World = " + bag.getCount("World!"));    // напечатает 2
    System.out.println("All = " + bag.getCount("All!"));    // напечатает 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // напечатает 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // напечатает 0

    // Выводим общее количества всех слов в тексте
    System.out.println(bag.size());    //напечатает 6

    // Выводим общее количество всех уникальных слов
    System.out.println(bag.uniqueSet().size());    //напечатает 4
}
 
Example #4
Source File: ApacheHashBagTest.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // Разберем текст на слова
    String INPUT_TEXT = "Hello World! Hello All! Hi World!";
    // Создаем Multiset
    Bag bag = new HashBag(Arrays.asList(INPUT_TEXT.split(" ")));

    // Выводим кол-вом вхождений слов
    System.out.println(bag); // напечатает [1:Hi,2:Hello,2:World!,1:All!] - в произвольном порядке
    // Выводим все уникальные слова
    System.out.println(bag.uniqueSet());    // напечатает [Hi, Hello, World!, All!] - в произвольном порядке

    // Выводим количество по каждому слову
    System.out.println("Hello = " + bag.getCount("Hello"));    // напечатает 2
    System.out.println("World = " + bag.getCount("World!"));    // напечатает 2
    System.out.println("All = " + bag.getCount("All!"));    // напечатает 1
    System.out.println("Hi = " + bag.getCount("Hi"));    // напечатает 1
    System.out.println("Empty = " + bag.getCount("Empty"));    // напечатает 0

    // Выводим общее количества всех слов в тексте
    System.out.println(bag.size());    //напечатает 6

    // Выводим общее количество всех уникальных слов
    System.out.println(bag.uniqueSet().size());    //напечатает 4
}
 
Example #5
Source File: PropertySet.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Creates a new PropertySet object.
 */
public PropertySet( Collection<String> properties)
  {
  properties_ = new HashBag<String>();
  addAll( properties);
  }
 
Example #6
Source File: PropertySet.java    From tcases with MIT License 4 votes vote down vote up
/**
 * Creates a new PropertySet object.
 */
public PropertySet( PropertySet properties)
  {
  properties_ = new HashBag<String>();
  addAll( properties);
  }
 
Example #7
Source File: ReceivedMessage.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Bag<User> getMentionedUsersBag()
{
    return processMentions(MentionType.USER, new HashBag<>(), false, this::matchUser);
}
 
Example #8
Source File: ReceivedMessage.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Bag<TextChannel> getMentionedChannelsBag()
{
    return processMentions(MentionType.CHANNEL, new HashBag<>(), false, this::matchTextChannel);
}
 
Example #9
Source File: ReceivedMessage.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Bag<Role> getMentionedRolesBag()
{
    return processMentions(MentionType.ROLE, new HashBag<>(), false, this::matchRole);
}
 
Example #10
Source File: ReceivedMessage.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Bag<Emote> getEmotesBag()
{
    return processMentions(MentionType.EMOTE, new HashBag<>(), false, this::matchEmote);
}