/*========================================================================= Program: FusionViewer Module: $RCSfile: FilePair.java,v $ Language: Java Date: $Date: 2007/02/02 19:26:29 $ Version: $Revision: 1.2 $ Copyright (c) Insightful Corporation. All rights reserved. See Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ package org.fusionviewer.io; import java.io.File; /**\class FilePair *\brief A pair of files. */ public class FilePair { private String file1, file2; /** * Construct a file pair from 2 file paths * * @param file1 the first file * @param file2 the second file */ public FilePair(String file1, String file2) { this.file1 = file1; this.file2 = file2; } /** * Construct this file pair as a duplicate of another file pair * * @param p file pair to copy */ public FilePair(FilePair p) { file1 = p.file1; file2 = p.file2; } /** * Return a human-readable representation */ public String toString() { return getFilename(file1) + " / " + getFilename(file2); } /* * Return only the name part of a file path. */ private String getFilename(String path) { if (path.length() <= 0) return ""; int pos = path.lastIndexOf(File.separatorChar); if (pos < 0) return path; return path.substring(pos + 1); } /** * Access file 1 of the pair * * @return file 1 */ public String getFile1() { return file1; } /** * Access file 2 of the pair * * @return file 2 */ public String getFile2() { return file2; } /** * Determine if this object is equivalent to another FilePair. */ public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof FilePair)) return false; FilePair p = (FilePair) o; return file1.equals(p.file1) && file2.equals(p.file2); } /** * Compute the hash code for this object. */ public int hashCode() { // Hash code computation from Effective Java by Joshua Block int result = 17; result = 37 * result + file1.hashCode(); result = 37 * result + file2.hashCode(); return result; } }