1 package jfun.yan.util.resource; 2 3 import java.io.InputStream ; 4 import java.net.URL ; 5 6 7 16 public class OrResourceLoader implements ResourceLoader { 17 private final ResourceLoader primary; 18 private final ResourceLoader alt; 19 public URL getResource(String path) { 20 URL ret = primary.getResource(path); 21 if(ret==null){ 22 ret = alt.getResource(path); 23 } 24 return ret; 25 } 26 27 public InputStream getResourceAsStream(String path) { 28 InputStream ret = primary.getResourceAsStream(path); 29 if(ret==null){ 30 ret = alt.getResourceAsStream(path); 31 } 32 return ret; 33 } 34 35 40 public OrResourceLoader(ResourceLoader primary, ResourceLoader alt) { 41 this.alt = alt; 42 this.primary = primary; 43 } 44 47 public ResourceLoader getPrimary(){ 48 return primary; 49 } 50 53 public ResourceLoader getAlternative(){ 54 return alt; 55 } 56 57 public boolean equals(Object obj) { 58 if(obj instanceof OrResourceLoader){ 59 final OrResourceLoader other = (OrResourceLoader)obj; 60 return primary.equals(other.primary) && alt.equals(other.alt); 61 } 62 else return false; 63 } 64 65 public int hashCode() { 66 return primary.hashCode()*31+alt.hashCode(); 67 } 68 69 public String toString() { 70 return primary.toString()+" | " + alt; 71 } 72 } 73 | Popular Tags |