wildcardfilefilter.java

来自「Jodd是一个开源的公用Java基础类库」· Java 代码 · 共 66 行

JAVA
66
字号
package jodd.file.filters;

import java.io.File;
import java.io.FileFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jodd.util.StringFlags;
import jodd.util.StringUtil;

/**
 * FileFilter that matches files against wildcard pattern (* and ?).
 *
 * For more details check the <code>FileFilterAbs</code> documentation.
 * For wildcard matching check the <code>StringUtil</code> documentation.
 *
 * @see jodd.file.filters.FileFilterAbs
 * @see jodd.util.StringUtil
 */
public class WildcardFileFilter extends FileFilterAbs {

	// ---------------------------------------------------------------- construction

	/**
	 * Regular Expression file filter.
	 *
	 * @param pattern regexp pattern
	 * @param opt     option string
	 */
	public WildcardFileFilter(String pattern, String opt) {
		super(pattern, opt);
	}

	/**
	 * Regular Expression file filter with default behaviour.
	 *
	 * @param pattern pattern
	 */
	public WildcardFileFilter(String pattern) {
		super(pattern);
	}

	/**
	 * Regular Expression file filter with no behaviour and that may be
	 * configured later.
	 */
	public WildcardFileFilter() {
		super();
	}

	// ---------------------------------------------------------------- FileFilterAbs.match()

	/**
	 * Wildcard matching.
	 *
	 * @param file   File to match.
	 *
	 * @return <code>true</code> if file name matches regular expression pattern,
	 *         <code>false</code> otherwise.
	 */
	public boolean match(File file) {
		return StringUtil.match(getFileName(file), pattern);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?