com.xiongyingqi.utils.code.CodeCondition Maven / Gradle / Ivy
package com.xiongyingqi.utils.code;
import com.xiongyingqi.util.CollectionHelper;
import java.util.Collection;
/**
* 代码查找条件
* Created by 瑛琪xiongyingqi.com on 2014/3/31 0031.
*/
public class CodeCondition {
private boolean findWhere;
private boolean findOnClass;
private boolean findOnMethod;
private boolean findOnArgument;
private Collection> orAnnotatedClasses;
private Collection> andAnnotatedClasses;
private Collection andCodeConditions;
private Collection orCodeConditions;
private void setFindWhere() {
findWhere = true;
}
/**
* 在方法上面进行查找
*
* @return
*/
public CodeCondition onMethod() {
setFindWhere();
findOnMethod = true;
return this;
}
/**
* 在类上进行查找
*
* @return
*/
public CodeCondition onClass() {
setFindWhere();
findOnClass = true;
return this;
}
public CodeCondition onArgument() {
setFindWhere();
findOnArgument = true;
return this;
}
/**
* 或者被orAnnotationClass
注解的条件,与andAnnotation方法冲突
*
* @param orAnnotationClass
* @return
*/
public CodeCondition orAnnotation(Class> orAnnotationClass) {
if (!orAnnotationClass.isAnnotation()) {
System.out.println("Class: " + orAnnotationClass + " 不是注解类!");
return this;
}
orAnnotatedClasses = CollectionHelper.checkOrInitHashSet(orAnnotatedClasses);
orAnnotatedClasses.add(orAnnotationClass);
return this;
}
/**
* 并且被andAnnotationClass
注解的条件
*
* @param andAnnotationClass
* @return
*/
public CodeCondition andAnnotation(Class> andAnnotationClass) {
if (!andAnnotationClass.isAnnotation()) {
System.out.println("Class: " + andAnnotationClass + " 不是注解类!");
return this;
}
andAnnotatedClasses = CollectionHelper.checkOrInitHashSet(andAnnotatedClasses);
andAnnotatedClasses.add(andAnnotationClass);
return this;
}
/**
* 条件且
*
* @param anotherCodeCondition
* @return
*/
public CodeCondition and(CodeCondition anotherCodeCondition) {
if (anotherCodeCondition == null) {
System.out.println("CodeCondition为空!");
return this;
}
andCodeConditions = CollectionHelper.checkOrInitHashSet(andCodeConditions);
return this;
}
/**
* 条件或
*
* @param anotherCodeCondition
* @return
*/
public CodeCondition or(CodeCondition anotherCodeCondition) {
if (anotherCodeCondition == null) {
System.out.println("CodeCondition为空!");
return this;
}
orCodeConditions = CollectionHelper.checkOrInitHashSet(orCodeConditions);
return this;
}
public boolean isFindWhere() {
return findWhere;
}
public boolean isFindOnClass() {
return findOnClass;
}
public boolean isFindOnMethod() {
return findOnMethod;
}
public boolean isFindOnArgument() {
return findOnArgument;
}
public Collection> getOrAnnotatedClasses() {
return orAnnotatedClasses;
}
public Collection> getAndAnnotatedClasses() {
return andAnnotatedClasses;
}
public Collection getAndCodeConditions() {
return andCodeConditions;
}
public Collection getOrCodeConditions() {
return orCodeConditions;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy