1 package org.robolectric.res; 2 3 import org.robolectric.res.android.ResTable_config; 4 5 public class TypedResource<T> { 6 private final T data; 7 private final ResType resType; 8 private final XmlContext xmlContext; 9 TypedResource(T data, ResType resType, XmlContext xmlContext)10 public TypedResource(T data, ResType resType, XmlContext xmlContext) { 11 this.data = data; 12 this.resType = resType; 13 this.xmlContext = xmlContext; 14 } 15 getData()16 public T getData() { 17 return data; 18 } 19 getResType()20 public ResType getResType() { 21 return resType; 22 } 23 getConfig()24 public ResTable_config getConfig() { 25 return xmlContext.getConfig(); 26 } 27 getXmlContext()28 public XmlContext getXmlContext() { 29 return xmlContext; 30 } 31 asString()32 public String asString() { 33 T data = getData(); 34 return data instanceof String ? (String) data : null; 35 } 36 isFile()37 public boolean isFile() { 38 return false; 39 } 40 isReference()41 public boolean isReference() { 42 Object data = getData(); 43 if (data instanceof String) { 44 String s = (String) data; 45 return !s.isEmpty() && s.charAt(0) == '@'; 46 } 47 return false; 48 } 49 toString()50 @Override public String toString() { 51 return getClass().getSimpleName() + "{" + 52 "values=" + data + 53 ", resType=" + resType + 54 ", xmlContext=" + xmlContext + 55 '}'; 56 } 57 isXml()58 public boolean isXml() { 59 return false; 60 } 61 } 62