All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.res.ResBunch Maven / Gradle / Ivy

There is a newer version: 3.4-rc2
Show newest version
package org.robolectric.res;

import java.util.LinkedHashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class ResBunch {
  private final Map> types = new LinkedHashMap<>();

  public void put(String attrType, String name, TypedResource value, XmlLoader.XmlContext xmlContext) {
    ResBundle bundle = getBundle(attrType);
    bundle.put(attrType, name, value, xmlContext);
  }

  private ResBundle getBundle(String attrType) {
    ResBundle bundle = types.get(attrType);
    if (bundle == null) {
      bundle = new ResBundle<>();
      types.put(attrType, bundle);
    }
    return bundle;
  }

  public TypedResource get(@NotNull ResName resName, String qualifiers) {
    ResBundle.Value value = getValue(resName, qualifiers);
    return value == null ? null : value.getValue();
  }

  public ResBundle.Value getValue(@NotNull ResName resName, String qualifiers) {
    ResBundle bundle = getBundle(resName.type);
    return bundle.getValue(resName, qualifiers);
  }

  public int size() {
    int size = 0;
    for (ResBundle bundle : types.values()) {
      size += bundle.size();
    }
    return size;
  }

  public void makeImmutable() {
    for (ResBundle bundle : types.values()) {
      bundle.makeImmutable();
    }
  }

  public void mergeLibraryStyle(ResBunch fromResBundle, String packageName) {
    for (Map.Entry> entry : fromResBundle.types.entrySet()) {
      getBundle(entry.getKey()).mergeLibraryStyle(entry.getValue(), packageName);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy