001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.files;
009:
010: //base classes
011: import java.io.ByteArrayOutputStream;
012: import java.io.File;
013: import java.io.IOException;
014: import java.io.InputStream;
015: import java.util.ArrayList;
016: import java.util.Collections;
017: import java.util.HashMap;
018: import java.util.Iterator;
019: import java.util.StringTokenizer;
020: import java.util.zip.ZipEntry;
021: import java.util.zip.ZipInputStream;
022: import java.util.zip.ZipOutputStream;
023:
024: //project specific classes
025: import org.jfolder.common.UnexpectedSystemException;
026: import org.jfolder.common.utils.misc.MiscHelper;
027:
028: //other classes
029:
030: public abstract class BaseVirtualFileSystemFile implements
031: VirtualFileSystemFile {
032:
033: protected BaseVirtualFileSystemFile() {
034: }
035:
036: //
037: public int hashCode() {
038:
039: int outValue = 0;
040:
041: //
042: if (getName() != null) {
043: outValue = outValue + getName().hashCode();
044: }
045: //
046: if (getContent() != null) {
047: outValue = outValue + getContent().hashCode();
048: }
049:
050: return outValue;
051: }
052:
053: public boolean equals(Object inObject) {
054:
055: boolean outValue = false;
056:
057: if (inObject != null) {
058:
059: String n1 = this .getClass().getName();
060: String n2 = inObject.getClass().getName();
061:
062: if (n1.equals(n2)) {
063:
064: VirtualFileSystemFile fsf = (VirtualFileSystemFile) inObject;
065:
066: outValue = true;
067: //
068: String name1 = this .getName();
069: String name2 = fsf.getName();
070: //
071: byte content1[] = this .getContent();
072: byte content2[] = fsf.getContent();
073:
074: outValue &= name1.equals(name2);
075: //
076: if (content1 != null && content2 != null) {
077: outValue &= compare(content1, content2);
078: } else if (content1 == null && content2 == null) {
079: outValue &= true;
080: } else {
081: outValue = false;
082: }
083: }
084: }
085:
086: return outValue;
087: }
088:
089: private final static boolean compare(byte inContent1[],
090: byte inContent2[]) {
091:
092: boolean outValue = true;
093:
094: if (inContent1 != null && inContent2 != null) {
095: //outValue = compare(inContent1, inContent2);
096: if (inContent1.length == inContent2.length) {
097: for (int i = 0; i < inContent1.length; i++) {
098: outValue &= (inContent1[i] == inContent2[i]);
099: }
100: } else {
101: outValue = false;
102: }
103: } else if (inContent1 == null && inContent2 == null) {
104: outValue = true;
105: } else {
106: outValue = false;
107: }
108:
109: return outValue;
110: }
111: }
|