001: // htmlFilterImageEntry.java
002: // -----------------------------
003: // (C) by Michael Peter Christen; mc@anomic.de
004: // first published on http://www.anomic.de
005: // Frankfurt, Germany, 2006
006: // created 04.04.2006
007: //
008: // This program is free software; you can redistribute it and/or modify
009: // it under the terms of the GNU General Public License as published by
010: // the Free Software Foundation; either version 2 of the License, or
011: // (at your option) any later version.
012: //
013: // This program is distributed in the hope that it will be useful,
014: // but WITHOUT ANY WARRANTY; without even the implied warranty of
015: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: // GNU General Public License for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // along with this program; if not, write to the Free Software
020: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: //
022: // Using this software in any meaning (reading, learning, copying, compiling,
023: // running) means that you agree that the Author(s) is (are) not responsible
024: // for cost, loss of data or any harm that may be caused directly or indirectly
025: // by usage of this softare or this documentation. The usage of this software
026: // is on your own risk. The installation and usage (starting/running) of this
027: // software may allow other people or application to access your computer and
028: // any attached devices and is highly dependent on the configuration of the
029: // software which must be done by the user of the software; the author(s) is
030: // (are) also not responsible for proper configuration and usage of the
031: // software, even if provoked by documentation provided together with
032: // the software.
033: //
034: // Any changes to this file according to the GPL as documented in the file
035: // gpl.txt aside this file in the shipment you received can be done to the
036: // lines that follows this copyright notice here, but changes must not be
037: // done inside the copyright notive above. A re-distribution must contain
038: // the intact and unchanged copyright notice.
039: // Contributions and changes to the program code must be marked as such.
040:
041: package de.anomic.htmlFilter;
042:
043: import de.anomic.yacy.yacyURL;
044:
045: public class htmlFilterImageEntry implements
046: Comparable<htmlFilterImageEntry> {
047:
048: private yacyURL url;
049: private String alt;
050: private int width, height;
051:
052: public htmlFilterImageEntry(yacyURL url, String alt, int width,
053: int height) {
054: this .url = url;
055: this .alt = alt;
056: this .width = width;
057: this .height = height;
058: }
059:
060: public yacyURL url() {
061: return this .url;
062: }
063:
064: public String alt() {
065: return this .alt;
066: }
067:
068: public int width() {
069: return this .width;
070: }
071:
072: public int height() {
073: return this .height;
074: }
075:
076: public String toString() {
077: return "{" + url.toString() + ", " + alt + ", " + width + "/"
078: + height + "}";
079: }
080:
081: public int hashCode() {
082: // if htmlFilterImageEntry elements are stored in a TreeSet, the biggest images shall be listed first
083: // this hash method therefore tries to compute a 'perfect hash' based on the size of the images
084: // unfortunately it can not be ensured that all images get different hashes, but this should appear
085: // only in very rare cases
086: if ((width > 0) && (height > 0))
087: return ((0xFFFF - (((width * height) >> 8) & 0xFFFF)) << 16)
088: | (url.hashCode() & 0xFFFF);
089: else
090: return 0xFFFF0000 | (url.hashCode() & 0xFFFF);
091: }
092:
093: public int compareTo(htmlFilterImageEntry h) {
094: // this is needed if this object is stored in a TreeSet
095: // this method uses the image-size ordering from the hashCode method
096: // assuming that hashCode would return a 'perfect hash' this method would
097: // create a total ordering on images with respect on the image size
098: assert (url != null);
099: if (this .url.toNormalform(true, true)
100: .equals(
101: ((htmlFilterImageEntry) h).url.toNormalform(
102: true, true)))
103: return 0;
104: int thc = this .hashCode();
105: int ohc = ((htmlFilterImageEntry) h).hashCode();
106: if (thc < ohc)
107: return -1;
108: if (thc > ohc)
109: return 1;
110: return this .url.toString().compareTo(
111: ((htmlFilterImageEntry) h).url.toString());
112: }
113:
114: public boolean equals(htmlFilterImageEntry o) {
115: return compareTo(o) == 0;
116: }
117: }
|