当前位置: 首页>>代码示例>>Java>>正文


Java Predicate类代码示例

本文整理汇总了Java中org.aikodi.rejuse.predicate.Predicate的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Predicate类属于org.aikodi.rejuse.predicate包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: post

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
  * Recursively return all descendants of this element that satisfy the given predicate.
  * 
  * @param predicate A predicate that determines which descendants are returned.
  */
/*@
  @ default behavior
  @
  @ pre predicate != null;
  @
  @ post \result != null;
  @ post (\forall Element e; ; \result.contains(e) <==> descendants().contains(e) && predicate.eval(e));
  @*/
 default <E extends Exception> List<T> descendants(Predicate<? super T,E> predicate) throws E, N {
	// Do not compute all descendants, and apply predicate afterwards.
	// That is way too expensive.
	List<T> tmp = children();
	predicate.filter(tmp);
	List<T> result = (List<T>)tmp;
	for (T child : children()) {
		result.addAll(tree(child).descendants(predicate));
	}
	return result;
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:25,代码来源:TreeStructure.java

示例2: descendants

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
  * Check whether this element has a descendant that satisfies the given predicate.
  * 
  * @param type The class object representing the type the descendants.
  * @param predicate The predicate of which we want to know whether it is satisfied by a descendant.
  * @throws N 
  */
/*@
  @ default behavior
  @
  @ pre c != null;
  @
  @ post \result == ! descendants(type, predicate).isEmpty();
  @*/
 default <X extends T, E extends Exception> boolean hasDescendant(Class<X> type, Predicate<X,E> predicate) throws E, N {
   List<X> result = children(type, predicate);
   if (!result.isEmpty()) {
     return true;
   }
   for (T e : children()) {
     if (tree(e).hasDescendant(type, predicate)) {
       return true;
     }
   }
   return false;
 }
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:27,代码来源:TreeStructure.java

示例3: getNodes

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
 * Return the leaf nodes of this graph.
 */
/*@
  @ post \result != null;
  @ // No nodes that are not in this graph.
  @ post getNodes().containsAll(\result);
  @ post (\forall Object o; \result.contains(o); o instanceof Node);
  @ post (\forall Node node; getNodes().contains(node);
  @         \result.contains(node) == node.isLeaf());
  @*/
public Set<Node<V>> getLeaves() {
	Set<Node<V>> result = nodes();
	new Predicate<Node<V>,Nothing>() {
		public boolean eval(Node<V> o) {
			return o.isLeaf();
		}
	}.filter(result);
	return result;
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:21,代码来源:Graph.java

示例4: parent

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
  * Return the nearest ancestor of type T that satisfies the given predicate. 
  * Null if no such ancestor can be found.
  * 
  * @param <T>
  *        The type of the ancestor to be found
  * @param c
  *        The class object of type T (T.class)
  * @return
  */
/*@
  @ default behavior
  @
  @ post parent() == null ==> \result == null;
  @ post parent() != null && kind.isInstance(parent()) && predicate.eval((T)parent()) ==> \result == parent();
  @ post parent() != null && ((! kind.isInstance(parent())) || (kindc.isInstance(parent()) && ! predicate.eval((T)parent())) 
  @          ==> \result == parent().nearestAncestor(kind, predicate);
  @*/
 default <X extends T, E extends Exception> X nearestAncestor(Class<X> kind, Predicate<X, E> predicate) throws E {
   return nearestIncluding(kind, predicate, parent());
 }
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:22,代码来源:TreeStructure.java

示例5: findFirst

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
public static <T,E extends Exception> T findFirst(Collection<T> collection, Predicate<? super T,E> predicate) throws E {
  Iterator<T> iterator = collection.iterator();
  while(iterator.hasNext()) {
    T t = iterator.next();
    if(predicate.eval(t)) {
      return t;
    }
  }
  return null;
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:11,代码来源:CollectionOperations.java

示例6: filter

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
public <E extends Exception> void filter(Predicate<? super Edge<V>,E> predicate) throws E {
	for(Edge<V> edge: edges()) {
		if(! predicate.eval(edge)) {
			edge.terminate();
		}
	}
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:8,代码来源:Graph.java

示例7: find

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
public <E extends Element,X extends Exception> List<E> find(Class<E> kind, Predicate<E,X> unsafe) throws X {
	List<E> result = new ArrayList<E>();
	for(Namespace ns: namespaces()) {
		result.addAll(ns.descendants(kind, unsafe));
	}
	return result;
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:8,代码来源:CommandLineTool.java

示例8: path

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
 * Create a new jar scanner for the jar with the given path, file filter, and base loader setting.
 * 
 * @param path The path of the jar file from which elements must be loaded.
 * @param filter A filter that selects files in the zip file based on their paths.
 * @param isBaseLoader Indicates whether the loader is responsible for loading a base library.
 */
/*@
  @ public behavior
  @
  @ pre path != null;
  @ post path() == path;
  @ post isBaseLoader() == isBaseLoader;
  @*/
public JarScanner(JarFile path, Predicate<? super String,Nothing> filter, boolean isBaseLoader) {
	super(path, filter, isBaseLoader);
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:18,代码来源:JarScanner.java

示例9: loadBin

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
private void loadBin(String path) throws ProjectException {
	Predicate<? super String,Nothing> binaryFileFilter = java().plugin(ProjectConfigurator.class).binaryFileFilter();
	if(path.endsWith(".jar")) {
		JarFile file;
		try {
			file = new JarFile(_project.absoluteFile(path));
			_project.views().get(0).addBinary(new JarScanner(file, binaryFileFilter));
		} catch (IOException e) {
			throw new ProjectException(e);
		}
	} else {
		_project.views().get(0).addBinary(new DirectoryScanner(".", binaryFileFilter, new LazyJavaFileInputSourceFactory()));
	}
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:15,代码来源:JavaEclipseClasspathConfig.java

示例10: involvedTypeParameters

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
public List<TypeParameter> involvedTypeParameters(JavaTypeReference tref) throws LookupException {
	Predicate<BasicJavaTypeReference, LookupException> predicate = 
	    object ->  parent().typeParameters().contains(object.getDeclarator());
	List<BasicJavaTypeReference> list = tref.descendants(BasicJavaTypeReference.class, predicate);
	if((tref instanceof BasicJavaTypeReference) && predicate.eval((BasicJavaTypeReference) tref)) {
		list.add((BasicJavaTypeReference) tref);
	}
	List<TypeParameter> parameters = new ArrayList<TypeParameter>();
	for(BasicJavaTypeReference cref: list) {
		parameters.add((TypeParameter) cref.getDeclarator());
	}
	return parameters;
}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:14,代码来源:FirstPhaseConstraint.java

示例11: replace

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
/**
	 * Replace all references to 'declarator' in 'in' with copies of 'replacement'.
	 * @param replacement
	 * @param declarator
	 * @param in
	 * @param kind
	 * @return
	 * @throws LookupException
	 */
	public static <E extends Element> E replace(TypeReference replacement, final Declaration declarator, E in, Class<E> kind) throws LookupException {
		ObjectOrientedLanguage lang = in.language(ObjectOrientedLanguage.class);
		E result = in;
		Predicate<BasicTypeReference, LookupException> predicate = object -> object.getDeclarator().sameAs(declarator);
		List<BasicTypeReference> crefs = in.descendants(BasicTypeReference.class, 
				predicate);
		if(in instanceof BasicTypeReference) {
			BasicTypeReference in2 = (BasicTypeReference) in;
			if(predicate.eval(in2)) {
				crefs.add(in2);
			}
		}
		for(BasicTypeReference cref: crefs) {
			TypeReference substitute;
			Element oldParent = replacement.parent();
			if(replacement.isDerived()) {
//				replacement.setUniParent(null);
			  substitute = lang.createNonLocalTypeReference(Util.clone(replacement),oldParent);
			  substitute.setOrigin(replacement);
			} else {
			  substitute = lang.createNonLocalTypeReference(Util.clone(replacement),oldParent);
			}
			if(! cref.isDerived()) {
				SingleAssociation crefParentLink = cref.parentLink();
				crefParentLink.getOtherRelation().replace(crefParentLink, substitute.parentLink());
			} else {
				substitute.setUniParent(in.parent());
			}
			if(cref == in) {
				if(kind.isInstance(substitute)) {
				  result = (E) substitute;
				} else {
					throw new ChameleonProgrammerException("The type reference passed to replace must be replaced as a whole, but the kind that was given is more specific than the newly created type reference.");
				}
			}
		}
		return result;
	}
 
开发者ID:markovandooren,项目名称:jnome,代码行数:48,代码来源:NonLocalJavaTypeReference.java

示例12: nearestAncestorOrSelf

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
default <X extends T, E extends Exception> X nearestAncestorOrSelf(Class<X> kind, Predicate<X, E> predicate) throws E {
  return nearestIncluding(kind, predicate, node());
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:4,代码来源:TreeStructure.java

示例13: nearestIncluding

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
default <X extends T, E extends Exception> X nearestIncluding(Class<X> kind, Predicate<X, E> predicate, T el) throws E {
	while ((el != null) && ((! kind.isInstance(el)) || (! predicate.eval((X)el)))) {
     el = tree(el).parent();
   }
   return (X) el;
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:7,代码来源:TreeStructure.java

示例14: farthestAncestorOrSelf

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
default <X extends T, E extends Exception> T farthestAncestorOrSelf(Class<X> kind, Predicate<X,E> p) throws E {
  return farthestAncestorOrSelf(UniversalPredicate.of(kind,p));
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:4,代码来源:TreeStructure.java

示例15: exists

import org.aikodi.rejuse.predicate.Predicate; //导入依赖的package包/类
public static <T,E extends Exception> boolean exists(Collection<T> collection, Predicate<? super T,E> predicate) throws E {
  return predicate.exists(collection);
}
 
开发者ID:markovandooren,项目名称:rejuse,代码行数:4,代码来源:CollectionOperations.java


注:本文中的org.aikodi.rejuse.predicate.Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。