Example usage for java.util Collections frequency

List of usage examples for java.util Collections frequency

Introduction

In this page you can find the example usage for java.util Collections frequency.

Prototype

public static int frequency(Collection<?> c, Object o) 

Source Link

Document

Returns the number of elements in the specified collection equal to the specified object.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<Integer> values = Arrays.asList(5, 0, 0, 2);
    int occurrences = Collections.frequency(values, 0);
    System.out.println("occurrences of zero is " + occurrences);

    occurrences = Collections.frequency(values, 5);
    System.out.println("occurrences of 5 is " + occurrences);
}

From source file:Main.java

public static void main(String[] args) {
    Integer[] arr = { 1, 2, 3, 1, 4, 4, 1, 5 };
    System.out.println(Arrays.toString(arr));
    List<Integer> l = Arrays.asList(arr);

    System.out.println(l);/*from   w  ww .ja  v  a 2  s .com*/

    Set<Integer> set = new HashSet<Integer>();
    for (int j = 0; j < l.size(); j++) {
        if (Collections.frequency(l, l.get(j)) > 1) {
            set.add(l.get(j));
        }
    }
    System.out.println("dups are:" + set);
}

From source file:Main.java

public static void main(String[] args) {
    String givenstring = "this is a test this is a another test";
    String[] words = givenstring.split(" ");

    ArrayList<String> arr = new ArrayList<String>();
    for (int i = 0; i < words.length; i++) {
        arr.add(words[i]);//  w w  w.  ja v a  2 s  .c o m
    }
    while (arr.size() != 0) {
        String word = arr.get(0);
        int frequency = Collections.frequency(arr, word);
        arr.removeAll(Collections.singleton(word));
        System.out.println(word + frequency);
    }
}

From source file:Main.java

public static void main(String args[]) {
    // create array list object       
    List<String> arrlist = new ArrayList<String>();

    // populate the list
    arrlist.add("A");
    arrlist.add("B");
    arrlist.add("B");
    arrlist.add("B");
    arrlist.add("B");
    arrlist.add("from java2s.com");

    // check frequensy of 'B'
    int freq = Collections.frequency(arrlist, "B");

    System.out.println("Frequency of 'B' is: " + freq);
}

From source file:Main.java

public static void main(String[] args) {

    String text = "a r b k c d se f g a d f s s f d s ft gh f ws w f v x s g h d h j j k f sd j e wed a d f";

    List<String> list = Arrays.asList(text.split(" "));

    Set<String> uniqueWords = new HashSet<String>(list);
    for (String word : uniqueWords) {
        System.out.println(word + ": " + Collections.frequency(list, word));
    }//from   w w w  . j  ava2 s.  co m
}

From source file:Main.java

public static <T> Map<T, Integer> frequency(Collection<? extends T> collection) {
    Map<T, Integer> res = new TreeMap<>();
    for (T element : collection) {
        if (!res.containsKey(element)) {
            res.put(element, Collections.frequency(collection, element));
        }//from w  w w  . j  a v a  2  s. c  om
    }
    return res;
}

From source file:utils.TextMatcher.java

public Map<String, Integer> matchesInText(String text, Collection<String> words) {
    Map<String, Integer> results = new HashMap<String, Integer>();
    String normalizedText = normalizer.normalizeText(text);
    List<String> tokenizedText = Arrays.asList(normalizedText.split("\\s+"));
    for (String word : words) {
        String normalizedWord = normalizer.normalizeText(word);
        int frequency = Collections.frequency(tokenizedText, normalizedWord);
        if (frequency > 0) {
            results.put(word, frequency);
        }//from  w  w  w .ja v  a  2  s .  c  o  m
    }
    return results;
}

From source file:com.thoughtworks.go.config.RolesConfig.java

public boolean isUniqueRoleName(final CaseInsensitiveString roleName) {
    return Collections.frequency(roleNames(), roleName) <= 1;
}

From source file:uniol.apt.analysis.synthesize.separation.KBoundedSeparation.java

/**
 * Construct a new instance for solving separation problems.
 * @param utility The region utility to use.
 * @param properties Properties that the calculated region should satisfy.
 * @param locationMap Mapping that describes the location of each event.
 * @throws UnsupportedPNPropertiesException If the requested properties are not supported.
 *//*  w  w w  . j  a  va 2s.c o m*/
public KBoundedSeparation(RegionUtility utility, PNProperties properties, String[] locationMap)
        throws UnsupportedPNPropertiesException {
    this.utility = utility;
    this.pure = properties.isPure();

    // Are we the right Separation implementation for the task?
    if (!properties.isKBounded())
        throw new UnsupportedPNPropertiesException();

    PNProperties supported = new PNProperties().requireKBounded(properties.getKForKBounded()).setPure(true);
    if (!supported.containsAll(properties))
        throw new UnsupportedPNPropertiesException();

    // We do not support locations, so no locations may be specified
    if (Collections.frequency(Arrays.asList(locationMap), null) != locationMap.length)
        throw new UnsupportedPNPropertiesException();

    // Check our preconditions
    TransitionSystem ts = utility.getTransitionSystem();
    if (!new TotallyReachable(ts).isTotallyReachable())
        throw new UnsupportedPNPropertiesException();
    Set<Event> events = new HashSet<>();
    for (Arc arc : ts.getEdges())
        events.add(arc.getEvent());
    if (!events.equals(ts.getAlphabetEvents()))
        throw new UnsupportedPNPropertiesException();

    // Ok, we can do it. Now do it.
    if (properties.getKForKBounded() == 0)
        // There are no 0-bounded regions that solve any kind of separation problem.
        // (Except if the alphabet has events that do not occur on any arc, which is not supported)
        return;
    generateAllRegions(properties.getKForKBounded());
}

From source file:calculators.Calculator.java

/**
 * Creates the HashMap that states which sample belongs to which sample
 * group. It can be done on index because the order of the samples in the
 * group file is the same as the order of the samples in the intensity file.
 * The group file does not contain the sample names so this is also the only
 * way to do it/*from   w ww. j a  v  a  2 s  .  co  m*/
 *
 * @param group_file the group file
 * @param control the control group
 * @param target the target group
 * @throws FileNotFoundException
 * @throws IOException
 */
private void createGroupMap(final File group_file, final String control, final String target)
        throws FileNotFoundException, IOException {
    BufferedReader br = new BufferedReader(new FileReader(group_file.getAbsolutePath()));
    String line;
    LinkedList<String> temporaryMap = new LinkedList<>();
    while ((line = br.readLine()) != null) {
        temporaryMap.add(line.split("\\s+")[1]);
    }
    Integer index = 0;
    for (String key : groupMap.keySet()) {
        groupMap.replace(key, temporaryMap.get(index));
        index++;
    }
    controlSize = Collections.frequency(new ArrayList<>(groupMap.values()), control);
    targetSize = Collections.frequency(new ArrayList<>(groupMap.values()), target);
}