SpecString.java
1 /* 2 * Copyright (C) 2022 github.com/REAndroid 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.reandroid.arsc.item; 17 18 import com.reandroid.arsc.base.Block; 19 import com.reandroid.arsc.value.Entry; 20 import com.reandroid.utils.StringsUtil; 21 22 import java.util.Iterator; 23 import java.util.function.Predicate; 24 25 public class SpecString extends StringItem { 26 public SpecString(boolean utf8) { 27 super(utf8); 28 } 29 30 public int resolveResourceId(String typeName){ 31 Iterator<Entry> itr = getEntries(typeName); 32 if(itr.hasNext()){ 33 return itr.next().getResourceId(); 34 } 35 return 0; 36 } 37 38 public Iterator<Entry> getEntries(Predicate<Entry> filter){ 39 return getUsers(Entry.class, filter); 40 } 41 public Iterator<Entry> getEntries(final int typeId){ 42 return getUsers(Entry.class, new Predicate<Entry>() { 43 @Override 44 public boolean test(Entry item) { 45 return typeId == item.getTypeId(); 46 } 47 }); 48 } 49 public Iterator<Entry> getEntries(final String typeName){ 50 return getUsers(Entry.class, new Predicate<Entry>() { 51 @Override 52 public boolean test(Entry item) { 53 return typeName == null 54 || typeName.equals(item.getTypeName()); 55 } 56 }); 57 } 58 public Iterator<Entry> getEntries(final Block parentContext){ 59 return getUsers(Entry.class, new Predicate<Entry>() { 60 @Override 61 public boolean test(Entry item) { 62 return item.getParentInstance(parentContext.getClass()) 63 == parentContext; 64 } 65 }); 66 } 67 @Override 68 public StyleItem getOrCreateStyle(){ 69 // Spec (resource name) don't have style unless to obfuscate/confuse other decompilers 70 return null; 71 } 72 @Override 73 public int compareTo(StringItem stringItem) { 74 if(stringItem == null){ 75 return -1; 76 } 77 return StringsUtil.compareStrings(this.get(), stringItem.get()); 78 } 79 }