diff -r 000000000000 -r 5bf850c5b7f1 javaquery/canvas/src/main/java/net/java/html/canvas/Image.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Mon May 27 08:30:18 2013 +0200 @@ -0,0 +1,77 @@ +/** + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach + * + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. Look for COPYING file in the top folder. If not, see + * http://opensource.org/licenses/GPL-2.0. + */ +package net.java.html.canvas; + +import java.util.Objects; + +/** + * Image represents an Image defined by a Path. + * + * + * @author antonepple + */ +public class Image { + + private String src; + private Object cached; + private int cacheHash; + + void Image(String src) { + this.src = src; + } + + void cache(Object toCache) { + cacheHash = hashCode(); + this.cached = toCache; + } + + private boolean isCached() { + return cacheHash == hashCode(); + } + + Object getCached() { + return isCached() ? cached : null; + } + + public String getSrc() { + return src; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + Objects.hashCode(this.src); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Image other = (Image) obj; + if (!Objects.equals(this.src, other.src)) { + return false; + } + return true; + } + +}