1 package org.robolectric.res; 2 3 import java.nio.file.Files; 4 import java.nio.file.Path; 5 6 @SuppressWarnings("NewApi") 7 public class ResourcePath { 8 private final Class<?> rClass; 9 private final Path resourceBase; 10 private final Path assetsDir; 11 private final Class<?> internalRClass; 12 ResourcePath(Class<?> rClass, Path resourceBase, Path assetsDir)13 public ResourcePath(Class<?> rClass, Path resourceBase, Path assetsDir) { 14 this(rClass, resourceBase, assetsDir, null); 15 } 16 ResourcePath(Class<?> rClass, Path resourceBase, Path assetsDir, Class<?> internalRClass)17 public ResourcePath(Class<?> rClass, Path resourceBase, Path assetsDir, Class<?> internalRClass) { 18 this.rClass = rClass; 19 this.resourceBase = resourceBase; 20 this.assetsDir = assetsDir; 21 this.internalRClass = internalRClass; 22 } 23 getRClass()24 public Class<?> getRClass() { 25 return rClass; 26 } 27 getResourceBase()28 public Path getResourceBase() { 29 return resourceBase; 30 } 31 hasResources()32 public boolean hasResources() { 33 return getResourceBase() != null && Files.exists(getResourceBase()); 34 } 35 getAssetsDir()36 public Path getAssetsDir() { 37 return assetsDir; 38 } 39 getInternalRClass()40 public Class<?> getInternalRClass() { 41 return internalRClass; 42 } 43 44 @Override toString()45 public String toString() { 46 return "ResourcePath { path=" + resourceBase + "}"; 47 } 48 49 @Override equals(Object o)50 public boolean equals(Object o) { 51 if (this == o) return true; 52 if (!(o instanceof ResourcePath)) return false; 53 54 ResourcePath that = (ResourcePath) o; 55 56 if (rClass != null ? !rClass.equals(that.rClass) : that.rClass != null) return false; 57 if (resourceBase != null ? !resourceBase.equals(that.resourceBase) : that.resourceBase != null) return false; 58 if (assetsDir != null ? !assetsDir.equals(that.assetsDir) : that.assetsDir != null) return false; 59 return internalRClass != null ? internalRClass.equals(that.internalRClass) : that.internalRClass == null; 60 61 } 62 63 @Override hashCode()64 public int hashCode() { 65 int result = rClass != null ? rClass.hashCode() : 0; 66 result = 31 * result + (resourceBase != null ? resourceBase.hashCode() : 0); 67 result = 31 * result + (assetsDir != null ? assetsDir.hashCode() : 0); 68 result = 31 * result + (internalRClass != null ? internalRClass.hashCode() : 0); 69 return result; 70 } 71 } 72