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

📄 abstractpredicate.java

📁 一个关于java 的常用工具包
💻 JAVA
字号:
package org.jutil.predicate;import java.util.Iterator;import java.util.Collection;import java.util.Arrays;import java.util.List;import java.util.ConcurrentModificationException;import org.jutil.java.collections.CollectionOperator;/** * @path    $Source: /cvsroot/org-jutil/jutil.org/src/org/jutil/predicate/AbstractPredicate.java,v $ * @version $Revision: 1.2 $ * @date    $Date: 2002/09/07 09:24:11 $ * @state   $State: Exp $ * @author  ????? * @release $Name:  $ */public abstract class AbstractPredicate implements Predicate {     /**    * See superclass    */   public /*@ pure @*/ boolean exists(Collection collection) throws ConcurrentModificationException, Exception {    boolean acc = false;    if (collection != null) {      Iterator iter = collection.iterator();      // variant : the number of elements in the explicit collection that      //           have not yet been checked.      // invariant : acc == false if none of the previous elements in the      //             explicit collection satisfies the criterion.      //             Otherwise, it is true.      while (iter.hasNext() && (!acc)) {        acc = eval(iter.next());      }    }    return acc;  }    /**    * See superclass    */  public /*@ pure @*/ boolean forall(Collection collection) throws ConcurrentModificationException, Exception {    boolean acc = true;    if(collection != null) {      Iterator iter = collection.iterator();      // variant : the number of elements in the explicit collection that      //           have not yet been checked.      // invariant : acc == true if all previous elements in the explicit collection      //             satisfy the criterion. Otherwise, it is false.      while (iter.hasNext() && acc) {        acc = eval(iter.next());      }    }    return acc;  }   /**    * See superclass    */  public /*@ pure @*/ int count(Collection collection) throws ConcurrentModificationException, Exception {		int count = 0;		if (collection != null) {			Iterator iter = collection.iterator();			while (iter.hasNext()) {				if (eval(iter.next())) {					count++;				}			}		}		return count;  }   /**    * See superclass    */  public void filter(Collection collection) throws ConcurrentModificationException, Exception {   	if (collection != null) {			// Make a backup, just in case something goes wrong			Object[] backup = collection.toArray();			try {   	    Iterator iter = collection.iterator();   	    while (iter.hasNext()) {   	      if (! eval(iter.next())) {   	        iter.remove();   	      }   	    }   	  }			catch(Exception exc) {				// clear whatever is left in the collection				collection.clear();				collection.addAll(Arrays.asList(backup));				throw exc;			}		}  }  /**   * See superclass   */	public final boolean equals(Object other) {		//default implementation		return (other == this);	}  /**   * See superclass   */	public int nbSubPredicates() {		return getSubPredicates().size();	}}/* * <copyright>Copyright (C) 1997-2002. 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 Software * License version 1.1 or later, a copy of which has been included with * this distribution in the LICENSE file, which can also be found at * http://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 + -