mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 14:24:25 +02:00
implement method to trim Entries
This commit is contained in:
parent
94e6772e75
commit
64c08b592a
@ -45,6 +45,14 @@ public class TypeBlockArray extends BlockArray<TypeBlock>
|
||||
public void sort(){
|
||||
sort(this);
|
||||
}
|
||||
public boolean removeNullEntries(int startId){
|
||||
boolean result = true;
|
||||
for(TypeBlock typeBlock:listItems()){
|
||||
boolean removed = typeBlock.removeNullEntries(startId);
|
||||
result = result && removed;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void removeEmptyBlocks(){
|
||||
List<TypeBlock> allTypes=new ArrayList<>(listItems());
|
||||
boolean foundEmpty=false;
|
||||
|
@ -24,6 +24,34 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
||||
elementData= newInstance(0);
|
||||
}
|
||||
|
||||
public void removeAllNull(int start){
|
||||
removeAll(start, true);
|
||||
}
|
||||
public void removeAll(int start){
|
||||
removeAll(start, false);
|
||||
}
|
||||
private void removeAll(int start, boolean check_null){
|
||||
List<T> removeList = subList(start);
|
||||
if(removeList.size()==0 || (check_null && !isAllNull(removeList))){
|
||||
return;
|
||||
}
|
||||
T[] itemArray = this.elementData;
|
||||
for(T item:removeList){
|
||||
if(item==null){
|
||||
continue;
|
||||
}
|
||||
if(!item.isNull()){
|
||||
item.setNull(true);
|
||||
}
|
||||
int index = item.getIndex();
|
||||
if(index>=0 && itemArray[index]==item){
|
||||
item.setIndex(-1);
|
||||
item.setParent(null);
|
||||
itemArray[index] = null;
|
||||
}
|
||||
}
|
||||
setChildesCount(start);
|
||||
}
|
||||
public List<T> subList(int start){
|
||||
return subList(start, -1);
|
||||
}
|
||||
@ -363,6 +391,15 @@ public abstract class BlockArray<T extends Block> extends BlockContainer<T> impl
|
||||
return "count="+ childesCount();
|
||||
}
|
||||
|
||||
public static boolean isAllNull(Collection<? extends Block> itemsList){
|
||||
for(Block item:itemsList){
|
||||
if(item!=null && !item.isNull()){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private class BlockIterator implements Iterator<T> {
|
||||
private int mCursor;
|
||||
private final int mMaxSize;
|
||||
|
@ -53,6 +53,12 @@ public class TypeBlock extends Chunk<TypeHeader>
|
||||
addChild(entryOffsets);
|
||||
addChild(mEntryArray);
|
||||
}
|
||||
public boolean removeNullEntries(int startId){
|
||||
startId = 0x0000ffff & startId;
|
||||
EntryArray entryArray = getEntryArray();
|
||||
entryArray.removeAllNull(startId);
|
||||
return entryArray.childesCount() == startId;
|
||||
}
|
||||
public PackageBlock getPackageBlock(){
|
||||
SpecTypePair specTypePair = getParent(SpecTypePair.class);
|
||||
if(specTypePair!=null){
|
||||
|
@ -65,6 +65,15 @@ public class SpecTypePair extends BlockContainer<Block>
|
||||
public void sortTypes(){
|
||||
getTypeBlockArray().sort();
|
||||
}
|
||||
public boolean removeNullEntries(int startId){
|
||||
startId = 0x0000ffff & startId;
|
||||
boolean removed = getTypeBlockArray().removeNullEntries(startId);
|
||||
if(!removed){
|
||||
return false;
|
||||
}
|
||||
getSpecBlock().setEntryCount(startId);
|
||||
return true;
|
||||
}
|
||||
public void removeEmptyTypeBlocks(){
|
||||
getTypeBlockArray().removeEmptyBlocks();
|
||||
}
|
||||
|
@ -35,4 +35,8 @@ public class ReferenceBlock<T extends Block> implements ReferenceItem{
|
||||
public int get() {
|
||||
return BlockItem.getInteger(this.block.getBytes(), this.offset);
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return get()+":"+this.block;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user