- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
FilenameFilter
有一个 accept我可以实现告诉系统我想如何过滤文件的方法。我想实现类似的东西。这是我的场景:
我正在编写一个在 iText 之上运行的通用 API添加 Barcode到 pdf 文档。我有一个通用的自定义条形码。
public class MyCustomBarcode{
/**
* This variable holds the type of barcode
* com.itextpdf.text.pdf.Barcode
*/
private Barcode barcode;
/**
* The X position of the barcode. (0, 0) is at the bottom left
*/
private float x;
/**
* The Y position of the barcode. (0, 0) is at the bottom left
*/
private float y;
/**
*
*/
private int rotation;
...
}
所以当用户使用这个API时,他们只需要传入一个 List<MyCustomBarcode>
到我的 API 中的方法,然后 API 会将条形码插入到每个 pdf 页面上。问题是每个条形码都有不同的 code格式。例如,BarcodeInter25 可能使用类似 000001, 000002 ...
的代码。 Barcode39 可能会使用其他东西。所以我想让用户自己编写如何生成条形码值的实现。像这样的事情
MyCustomBarcode barcode = new MyCustomBarcode(x, y, z){
public String getSeqNum(int i){
//The user own implementation of how they want integer i to look like.
//E.g if i==1, I might return 000001
}
);
由于我允许用户拥有多种类型的条形码,我希望允许他们为他们拥有的每个条形码编写自己的实现。
最佳答案
在父类中,创建方法 abstract
,然后让每个子类提供自己的具体实现。
public abstract class Barcode{
.
.
.
public abstract String getSeqNum(int i);
}
public final class FooBarcode extends Barcode{
.
.
.
public final String getSeqNum(int i){
// provide own implementation
}
}
关于java - 如何允许用户在 FilenameFilter 中编写自己的预定义方法(例如accept())的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7968179/
这是我的FilenameFilter,它应该只允许以.docx 结尾的目录和文件。然而,由于某种原因,它现在允许每个文件,无论其结尾如何或是否是目录。一旦我删除 || dir.isDirectory(
我正在使用 FilenameFilter 类列出目录中具有特定扩展名的所有文件。但我还想列出该目录中的所有目录。我通过互联网搜索,只发现如何使用 FilenameFilter 进行多个扩展。但是我怎样
我有一个方法,在调用时将 FilenameFilter 传递给(作为匿名内部类)。现在,如果设置了变量,我想扩展FilenameFilter。示例: new FilenameFilter() {
我有这个类实现了 FilenameFilter package Logic; import java.io.File; import java.io.FilenameFilter; public
我正在尝试使用 FilenameFilter 来过滤文件以 grep 文件在目录中。 % ls -1 DirFilter.class DirList.class DirList.java doctor
这是我的文件在目录中的样子 Brake_20130901.xml Tire_20130902.xml Wheel_20130903.xml Brake_20130910.xml Brake_20131
我有一个包含 xml 文件的目录: 20140110-093721565_TOTO.xml 20140110-093821565_TATA.xml 20140110-094021565_TOTO
我正在使用一个小型 Java 工具来根据一组文件扩展名获取一组文件,我在使用 listFiles() 和使用 continue; 之间争论不休,当我遇到一个错误的文件时,与使用自定义 FileFilt
我需要扫描文件夹并过滤与特定正则表达式模式匹配的文件。 FileNameFilter 的 accept 方法中的示例代码 Scanner fileNameScanner = new Scanner(f
如何过滤多个扩展名,FileNameFilter 一次只允许一个字符串.. FileNameFilter API // filter extension, but only allow filter
我正在编写一个简单的程序,以递归方式列出目录中的文件 .class。 最初我这样编码: public class Parsing{ public static void main(String
当我尝试使用方法 someFile.listFiles(FileFilter foobar) 时,出现错误 The method listFiles(FilenameFilter) in the ty
我正在实现一个 ZipComparison 文件,它遍历目录树结构,并处理以下目录中所有 .zip 文件的 MD5该目录树结构。 import java.io.*; public class ZipC
FilenameFilter有一个 accept我可以实现告诉系统我想如何过滤文件的方法。我想实现类似的东西。这是我的场景: 我正在编写一个在 iText 之上运行的通用 API添加 Barcode到
我正在研究 java 8 中的 lambda 表达式 当我更改线程代码时它工作正常 new Thread(new Runnable() { @Override public void
美好的一天。 我想知道java.io.File.listFiles(FilenameFilter filter)是否返回一个已经排序的对象。 这是我的代码: String[] files = FIUt
假设我的测试有以下目录结构。 test | | ---test1 | | ---test2 | | ---random.txt 在此结构中,test1和test2是目录,而random.txt是常规文
所以我有以下代码: File txtFileDir = new File(MAIN_DIR + "test"); FilenameFilter filter = new FilenameFilter(
我是一名优秀的程序员,十分优秀!