一本码簿

众里寻码千百度,那段却在github处。

0%

Java

获取文件夹指定类型的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private File[] getFilterFiles(String path, String[] suffix) {

File baseFolder = new File(path);
if(!baseFolder.isDirectory())return null;

FileFilter imageFilter = pathname -> {
String fileName = pathname.getName().toLowerCase();
for (String s : suffix) {
if (fileName.endsWith(s.toLowerCase())) return true;
}
return false;
};

return baseFolder.listFiles(imageFilter);
}

二维表转树Json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class itemType;
class itemTypeTree extetends itemType{
List<itemTypeTree> children;
}

private List<ItemTypeTree> recursionNode(List<ItemType> list, ItemType itemTree) {

if(list==null)return null;
if(itemTree==null)itemTree=new ItemTypeTree();
return getChildNode(list,itemTree).stream()
.map(item -> {
if(getChildNode(list,item).size()>0){
item.setChildren(recursionNode(list,item));
}
return item;
})
.collect(Collectors.toList());
}
private List<ItemTypeTree> getChildNode(List<ItemType> list,ItemType itemTree){
return list.stream()
.filter(item -> {
if(StringUtils.isBlank(itemTree.getTypecode())){
return StringUtils.isBlank(item.getParentcode());
}else {
return item.getParentcode().equals(itemTree.getTypecode());
}
})
.map(itemType -> {
ItemTypeTree itemTypeTree=new ItemTypeTree();
BeanUtils.copyProperties(itemType,itemTypeTree);
return itemTypeTree;
})
.collect(Collectors.toList());
}