package org.robolectric.res;

import android.content.res.Resources;
import org.jetbrains.annotations.NotNull;
import org.robolectric.res.builder.XmlBlock;

import java.io.InputStream;

public abstract class ResourceLoader {

  public abstract TypedResource getValue(@NotNull ResName resName, String qualifiers);

  public TypedResource getValue(int resId, String qualifiers) {
    ResName resName = checkResName(resId, getResourceIndex().getResName(resId));
    return getValue(resName, qualifiers);
  }

  protected abstract Plural getPlural(ResName resName, int quantity, String qualifiers);

  public Plural getPlural(int resId, int quantity, String qualifiers) {
    return getPlural(getResourceIndex().getResName(resId), quantity, qualifiers);
  }

  public abstract XmlBlock getXml(ResName resName, String qualifiers);

  public abstract DrawableNode getDrawableNode(ResName resName, String qualifiers);

  public DrawableNode getDrawableNode(int resId, String qualifiers) {
    return getDrawableNode(getResourceIndex().getResName(resId), qualifiers);
  }

  public abstract InputStream getRawValue(ResName resName);

  public InputStream getRawValue(int resId) {
    return getRawValue(getResourceIndex().getResName(resId));
  }

  public abstract ResourceIndex getResourceIndex();

  public abstract boolean providesFor(String namespace);

  private ResName checkResName(int id, ResName resName) {
    if (resName == null) {
      throw new Resources.NotFoundException("Unable to find resource ID #0x" + Integer.toHexString(id));
    }
    return resName;
  }
}

@@ -395,28 +395,8 @@
 me =
- checkResName(resId,
  get
@@ -424,25 +424,24 @@
 sName(resId)
-)
 ;%0A    return
@@ -436,24 +436,42 @@
 ;%0A    return
+ resName != null ?
  getValue(re
@@ -480,32 +480,39 @@
 ame, qualifiers)
+ : null
 ;%0A  %7D%0A%0A  protect
@@ -1348,228 +1348,7 @@
 ce);
-%0A%0A  private ResName checkResName(int id, ResName resName) %7B%0A    if (resName == null) %7B%0A      throw new Resources.NotFoundException(%22Unable to find resource ID #0x%22 + Integer.toHexString(id));%0A    %7D%0A    return resName;%0A  %7D
 %0A%7D%0A

Return null if resource not found, ResourceLoader cannot throw Resources.NotFoundException since its loaded by the system classloader which will return a different class to classes loaded from InstrumentationClassLoader