⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 counter.java

📁 一个关于java 的常用工具包
💻 JAVA
字号:
package org.jutil.java.collections; import java.util.Collection;import java.util.Iterator;/** * <p>An IntegerAccumulator that counts the number of items in a collection that * satisfies some criterion.</p> * * <center> *  <img src="doc-files/Counter.png"/> * </center> * * <p>A convenience accumulator of collections that checks  * elements of a collection satisfy the criterion defined in  * <code>public boolean criterion(Object element)</code>.</p> * * <p>As with the accumulator, this class can best be used as an anonymous * inner class, as shown below.</p> * * <pre><code> * int number = new Counter() { *                public boolean criterion(Object element) { *                  // criterion code *                } *              }.in(collection); * </code></pre> * * @path    $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/java/collections/Counter.java,v $ * @version $Revision: 1.7 $ * @date    $Date: 2002/07/21 17:56:59 $ * @state   $State: Exp $ * @author  Marko van Dooren * @release $Name:  $ */public abstract class Counter extends IntegerAccumulator {  	/* The revision of this class */	public final static String CVS_REVISION ="$Revision: 1.7 $";  /*@	  @ also public behavior		@    @ post \result == 0;    @*/  public int initialAccumulator() {    return 0;  }    /*@	  @ also public behavior		@    @ // If the element satisfies the criterion, acc + 1 is returned to    @ // indicate 1 more element satisfies the criterion.    @ // otherwise acc is returned.    @ post criterion(element) == false ==> \result == acc;    @ post criterion(element) == true ==> \result == acc + 1;    @*/  public int accumulate(Object element, int acc) {    if(criterion(element)) {      return acc + 1;    }    else {      return acc;    }  }	  /**   * The criterion used to determine whether or not an element   * has to be counted.   */ /*@	 @ //As usual, criterion must be consistent with the semantics of equals   @ post (\forall Object o1;;   @         (\forall Object o2; o1.equals(o2);   @            criterion(o1) == criterion(o2)));   @*/  public abstract boolean criterion(Object element);  //  /*@ //FIXME//    @ // Count the number of elements in the given collection that//    @ // satisfy the criterion.//    @ post_redundantly \result == (\num_of Object o; collection.contains(o); criterion(o));//    @*/// //@//public int in(Collection collection);}/*<copyright>Copyright (C) 1997-2001. This software is copyrighted by the people and entities mentioned after the "@author" tags above, on behalf of the JUTIL.ORG Project. The copyright is dated by the dates after the "@date" tags above. All rights reserved.This software is published under the terms of the JUTIL.ORG SoftwareLicense version 1.1 or later, a copy of which has been included withthis distribution in the LICENSE file, which can also be found athttp://org-jutil.sourceforge.net/LICENSE. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the JUTIL.ORG Software License for more details. For more information,please see http://org-jutil.sourceforge.net/</copyright>/*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -