| // Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| package com.android.tools.r8.utils.collections; |
| |
| import com.android.tools.r8.graph.DexEncodedMethod; |
| import com.android.tools.r8.graph.DexMethod; |
| import com.android.tools.r8.graph.DexMethodSignature; |
| import java.util.Collection; |
| import java.util.HashMap; |
| import java.util.LinkedHashMap; |
| import java.util.Map; |
| import java.util.Set; |
| import java.util.function.BiConsumer; |
| import java.util.function.BiFunction; |
| import java.util.function.Function; |
| import org.jetbrains.annotations.NotNull; |
| |
| public class DexMethodSignatureMap<T> implements Map<DexMethodSignature, T> { |
| |
| private final Map<DexMethodSignature, T> backing; |
| |
| private DexMethodSignatureMap(Map<DexMethodSignature, T> backing) { |
| this.backing = backing; |
| } |
| |
| public static <T> DexMethodSignatureMap<T> create() { |
| return new DexMethodSignatureMap<>(new HashMap<>()); |
| } |
| |
| public static <T> DexMethodSignatureMap<T> createLinked() { |
| return new DexMethodSignatureMap<>(new LinkedHashMap<>()); |
| } |
| |
| @Override |
| public T put(DexMethodSignature signature, T value) { |
| return backing.put(signature, value); |
| } |
| |
| public T put(DexMethod method, T value) { |
| return put(method.getSignature(), value); |
| } |
| |
| public T put(DexEncodedMethod method, T value) { |
| return put(method.getReference(), value); |
| } |
| |
| @Override |
| public void clear() { |
| backing.clear(); |
| } |
| |
| @Override |
| public Set<DexMethodSignature> keySet() { |
| return backing.keySet(); |
| } |
| |
| @Override |
| public Collection<T> values() { |
| return backing.values(); |
| } |
| |
| @Override |
| public Set<Entry<DexMethodSignature, T>> entrySet() { |
| return backing.entrySet(); |
| } |
| |
| @Override |
| public T getOrDefault(Object key, T defaultValue) { |
| return backing.getOrDefault(key, defaultValue); |
| } |
| |
| @Override |
| public void forEach(BiConsumer<? super DexMethodSignature, ? super T> action) { |
| backing.forEach(action); |
| } |
| |
| @Override |
| public void replaceAll(BiFunction<? super DexMethodSignature, ? super T, ? extends T> function) { |
| backing.replaceAll(function); |
| } |
| |
| @Override |
| public T putIfAbsent(DexMethodSignature key, T value) { |
| return backing.putIfAbsent(key, value); |
| } |
| |
| @Override |
| public boolean remove(Object key, Object value) { |
| return backing.remove(key, value); |
| } |
| |
| @Override |
| public boolean replace(DexMethodSignature key, T oldValue, T newValue) { |
| return backing.replace(key, oldValue, newValue); |
| } |
| |
| @Override |
| public T replace(DexMethodSignature key, T value) { |
| return backing.replace(key, value); |
| } |
| |
| @Override |
| public T computeIfAbsent( |
| DexMethodSignature key, |
| @NotNull Function<? super DexMethodSignature, ? extends T> mappingFunction) { |
| return backing.computeIfAbsent(key, mappingFunction); |
| } |
| |
| @Override |
| public T computeIfPresent( |
| DexMethodSignature key, |
| @NotNull BiFunction<? super DexMethodSignature, ? super T, ? extends T> remappingFunction) { |
| return backing.computeIfPresent(key, remappingFunction); |
| } |
| |
| @Override |
| public T compute( |
| DexMethodSignature key, |
| @NotNull BiFunction<? super DexMethodSignature, ? super T, ? extends T> remappingFunction) { |
| return backing.compute(key, remappingFunction); |
| } |
| |
| @Override |
| public T merge( |
| DexMethodSignature key, |
| @NotNull T value, |
| @NotNull BiFunction<? super T, ? super T, ? extends T> remappingFunction) { |
| return backing.merge(key, value, remappingFunction); |
| } |
| |
| public T merge( |
| DexMethod method, |
| @NotNull T value, |
| @NotNull BiFunction<? super T, ? super T, ? extends T> remappingFunction) { |
| return merge(method.getSignature(), value, remappingFunction); |
| } |
| |
| public T merge( |
| DexEncodedMethod method, |
| @NotNull T value, |
| @NotNull BiFunction<? super T, ? super T, ? extends T> remappingFunction) { |
| return merge(method.getReference(), value, remappingFunction); |
| } |
| |
| @Override |
| public boolean containsKey(Object o) { |
| return backing.containsKey(o); |
| } |
| |
| @Override |
| public boolean containsValue(Object value) { |
| return backing.containsValue(value); |
| } |
| |
| @Override |
| public T get(Object key) { |
| return backing.get(key); |
| } |
| |
| public boolean containsKey(DexMethodSignature signature) { |
| return backing.containsKey(signature); |
| } |
| |
| public boolean containsAnyKeyOf(Iterable<DexMethodSignature> signatures) { |
| for (DexMethodSignature signature : signatures) { |
| if (containsKey(signature)) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| public DexMethodSignatureSet intersectionWithKeys(Iterable<DexMethodSignature> signatures) { |
| DexMethodSignatureSet result = DexMethodSignatureSet.create(); |
| for (DexMethodSignature signature : signatures) { |
| if (containsKey(signature)) { |
| result.add(signature); |
| } |
| } |
| return result; |
| } |
| |
| @Override |
| public boolean isEmpty() { |
| return backing.isEmpty(); |
| } |
| |
| @Override |
| public T remove(Object o) { |
| return backing.remove(o); |
| } |
| |
| @Override |
| public void putAll(@NotNull Map<? extends DexMethodSignature, ? extends T> m) {} |
| |
| public T remove(DexMethodSignature signature) { |
| return backing.remove(signature); |
| } |
| |
| public T remove(DexEncodedMethod method) { |
| return remove(method.getSignature()); |
| } |
| |
| @Override |
| public int size() { |
| return backing.size(); |
| } |
| } |