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

📄 booleanaccumulator.java

📁 一个关于java 的常用工具包
💻 JAVA
字号:
package org.jutil.java.collections;import java.util.Collection;import java.util.Iterator;import java.util.ConcurrentModificationException;/** * <p>A boolean accumulator for collections. </p> * * <center> *   <img src="doc-files/BooleanAccumulator.png"/> * </center> * * <p>BooleanAccumulators process each element of a collection, * and add the result of the process to the accumulator. The original collection remains * unchanged.</p> * * <p>Instead of an <code>accumulate(Collection></code> method, it has an <code><a href="BooleanAccumulator.html#in(java.util.Collection)">in(Collection)</a></code> method. * That name just seems more convenient.</p> * * @path    $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/java/collections/BooleanAccumulator.java,v $ * @version $Revision: 1.12 $ * @date    $Date: 2002/07/20 19:11:30 $ * @state   $State: Exp $ * @author  Marko van Dooren * @author  Jan Dockx * @release $Name:  $ */public abstract class BooleanAccumulator implements CollectionOperator {  	/* The revision of this class */	public final static String CVS_REVISION ="$Revision: 1.12 $";	/**   * <p>Subclasses should implement this method to return the initialized accumulator.   * This method is called at the start of the accumulation. The result will be used   * in the application of <code>public boolean accumulate(Object element, boolean acc)</code>   * for the first element.</p>   */  public abstract boolean initialAccumulator();    /**   * <p>This method is called for each element in the collection we are accumulating.   * Subclasses should implement this method to process <element> and accumulate   * the result in <acc>.</p>   * <p>The result is the accumulator that will be used for the next element of the   * collection to process.</p>.   *   * @param  element   *         The object the method will process and change the accumulator with.   * @param  acc   *         The accumulator for the accumulation.   *         For the first element to be processed, the result of initialAccumulator   *         is used. For the other elements, the result of this method applied on   *         the previous element is used.   */ /*@	 @ public behavior	 @   @ pre isValidElement(element);   @*/  public abstract boolean accumulate(Object element, boolean acc);    /**   * <p>Perform the accumulation defined in   * <code>public boolean accumulate(Object element, boolean acc)</code> for each   * element of <collection>. For the first element, the object returned by   * <code>public boolean initialAccumulator()</code> is used as accumulator.   * For the other elements, the result of the application of   * <code>public boolean accumulate(Object element, boolean acc)</code> on the   * previous element is used as accumulator.</p>   * <p>The contents of <collection> is not changed.</p>   * <p>The result of this method is the object returned by the application of   * <code>public boolean accumulate(Object element, boolean acc)</code> on the   * last element of the collection to be processed.</p>   *   * <p>The precondition is variable. Subclasses could strengthen the postcondition   * of isValidElement. To the user, this means that this method cannot be called   * safely in a polymorphic context, since she has no idea what the actual   * precondition will become in subclasses. This can be resolved by making   * the model method isValidElement final in the polymorph supertype she needs   * to use.</p>	 *   * @param collection	 *        The collection for which the ForAll operator has to be computed.   */ /*@   @ public behavior   @   @ pre (\forall Object o; collection.contains(o); isValidElement(o));	 @	 @ post (* the result of the accumulation is returned *);	 @ post collection == null ==> \result == initialAccumulator();	 @	 @ signals (ConcurrentModificationException) (* The collection was modified while accumulating *);   @*/  public boolean in(Collection collection) throws ConcurrentModificationException {    boolean acc = initialAccumulator();		if(collection != null) {    	Iterator iter = collection.iterator();    	while (iter.hasNext()) {      	acc = accumulate(iter.next(), acc);    	}    }    return acc;  }}/*<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 + -