Java List Count count(List l, int from, int to, Object what)

Here you can find the source of count(List l, int from, int to, Object what)

Description

count the number of occurences in a list

License

Open Source License

Declaration

public static int count(List l, int from, int to, Object what) 

Method Source Code

//package com.java2s;
/*//ww w  .  ja v  a2s  . c o  m
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

import java.util.List;

public class Main {
    /**
     * count the number of occurences in a list
     */
    public static int count(List l, int from, int to, Object what) {
        int result = 0;
        while (from < to) {
            Object which = l.get(from++);
            if (equals(which, what))
                result++;
        }
        return result;
    }

    public static final boolean equals(int flags, int mask, int value) {
        return (flags & mask) == value;
    }

    /** compare two object for equality with equals(). null values accepted */
    public static final boolean equals(Object a, Object b) {
        if (a == b)
            return true;
        if (a == null || b == null)
            return false;
        return a.equals(b);
    }
}

Related

  1. count(List values)
  2. count(List lines)
  3. countAtLevel(List aList, int aLevel)
  4. countNumber(List list, int number)