Skip to content

Commit

Permalink
convenient methods
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Jul 21, 2023
1 parent ab84408 commit 56a081f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/java/com/reandroid/archive/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ public ZipEntryMap createZipEntryMap(){
return new ZipEntryMap(mapEntrySource());
}

public InputSource[] getInputSources(){
ArchiveEntry[] entryList = this.entryList;
int length = entryList.length;
InputSource[] sources = new InputSource[length];
int dirCount = 0;
for(int i = 0; i < length; i++){
ArchiveEntry entry = entryList[i];
if(entry.isDirectory()){
//TODO: make InputSource for directory
dirCount++;
continue;
}
InputSource inputSource = createInputSource(entry);
inputSource.setSort(i);
sources[i] = inputSource;
}
if(dirCount == 0){
return sources;
}
InputSource[] filtered = new InputSource[length - dirCount];
int index = 0;
for(int i = 0; i < length; i++){
InputSource inputSource = sources[i];
if(inputSource == null){
continue;
}
filtered[index] = inputSource;
index++;
}
return filtered;
}
public LinkedHashMap<String, InputSource> mapEntrySource(){
ArchiveEntry[] entryList = this.entryList;
int length = entryList.length;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/reandroid/archive/ZipEntryMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.reandroid.archive;

import java.util.*;
import java.util.regex.Pattern;

public class ZipEntryMap implements Comparator<InputSource>{
private final Object mLock = new Object();
Expand Down Expand Up @@ -86,6 +87,21 @@ public void clear(){
onChanged(true);
}
}
public void removeAll(Pattern pattern){
synchronized (mLock){
boolean removed = false;
LinkedHashMap<String, InputSource> map = this.mSourceMap;
for(InputSource inputSource : toArray()){
String name = inputSource.getAlias();
if(pattern.matcher(name).matches()){
if(map.remove(name) != null){
removed = true;
}
}
}
onChanged(removed);
}
}
public InputSource remove(String name){
synchronized (mLock){
InputSource inputSource = mSourceMap.remove(name);
Expand Down

0 comments on commit 56a081f

Please sign in to comment.