📄 jacsonstatefilter.java
字号:
/* * JacsonStateFilter.java * * Created on 26. Januar 2003, 22:44 */package de.spieleck.app.jacson.filter;import java.util.Arrays;import java.util.Iterator;import gnu.trove.THashSet;import de.spieleck.config.ConfigNode;import de.spieleck.app.jacson.JacsonException;import de.spieleck.app.jacson.JacsonConfigException;import de.spieleck.app.jacson.JacsonRegistry;import de.spieleck.app.jacson.util.ConfigUtil;/** * Filtering chunks depending on the current JacsonState * @author Patrick Carl * @author fsn */public class JacsonStateFilter extends ConstFilter { /** This node determines which attribute of the JacsonState is examined */ public final static String PARAMETER_NAME_NODE = "stateParameterName"; /** These node determines the values which are accepted. */ public final static String PARAMETER_VALUE_NODE = "stateParameterValue"; /** * if more possible values of the parameter exists than LIMIT is, then * a THashSet will be used to store the values, otherwise an Array is used */ public final static int LIMIT = 6; /** * the parameter which is examined to determine whether a chunk is filtered * or not */ protected String parameterName = null; protected String[] parameterValue = null; protected THashSet parameterValueSet = null; protected boolean usingArray; /** Creates a new instance of JacsonStateFilter */ public JacsonStateFilter() { } public void init(ConfigNode config, JacsonRegistry registry) throws JacsonConfigException { super.init(config, registry); parameterName = config.getString(PARAMETER_NAME_NODE, null); if ( parameterName == null ) throw new JacsonConfigException("JacsonStateFilter needs one " +PARAMETER_NAME_NODE); int c = config.countChildrenNamed(PARAMETER_VALUE_NODE); if ( c == 0 ) throw new JacsonConfigException("JacsonStateFilter needs at least one " +PARAMETER_VALUE_NODE); usingArray = (c <= LIMIT); parameterValue = new String[c]; Iterator it = config.childrenNamed(PARAMETER_VALUE_NODE); int i = 0; while ( it.hasNext() ) { parameterValue[i++] = (String) it.next(); } if(!usingArray){ parameterValueSet = new THashSet(Arrays.asList(parameterValue)); parameterValue = null; } ConfigUtil.verify(config, this); } public boolean accept(ConfigNode node){ String name = node.getName(); return super.accept(node) || name.equals(PARAMETER_NAME_NODE) || name.equals(PARAMETER_VALUE_NODE); } public void putChunk(String chunk) throws JacsonException { String value = (String) getRegState().get(parameterName); if(value == null) { return; } if ( usingArray ) { int i = 0; while ( i < parameterValue.length ) { if ( parameterValue[i].equals(value) ) break; i++; } if ( i < parameterValue.length ^ inverse) drain.putChunk(chunk); } else{ if ( parameterValueSet.contains(value) ^ inverse) drain.putChunk(chunk); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -