📄 iteratormethod.java
字号:
/**
*
*/
package com.asterix.validation;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Iterator;
import com.asterix.validation.annotations.RuleIterator;
/**
* @author Andrei A Adamian
*
*/
public class IteratorMethod {
private Method method;
private Class<IValidationRule> clazz;
private IValidationRule target;
public IteratorMethod(Method method, Class<IValidationRule> clazz) {
this.method = method;
this.clazz = clazz;
}
public IteratorMethod(Method method, IValidationRule target) {
this.method = method;
this.target = target;
}
public Method getMethod() {
return method;
}
public void setMethod(Method method) {
this.method = method;
}
public IValidationRule getTarget() {
return target;
}
public void setTarget(IValidationRule target) {
this.target = target;
}
public Class<IValidationRule> getClazz() {
return clazz;
}
public void setClazz(Class<IValidationRule> clazz) {
this.clazz = clazz;
}
public String getMessage() {
RuleIterator rule = method.getAnnotation(RuleIterator.class);
if (rule != null) {
return rule.message();
}
throw new IllegalStateException("Rule annotation not specified");
}
public Iterator invoke(Object param) {
try {
return (Iterator) method.invoke(target, param);
} catch (Throwable t) {
t.printStackTrace();
}
return Collections.EMPTY_LIST.iterator();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -