blob: b22c280b07500d97eb564535db40a4f9ec9bd280 [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2007 IBM Corporation and others.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.library.services;
public class ElementFile implements Comparable {
String guid;
String fileName;
public ElementFile(String guid, String fileName) {
this.guid = guid;
this.fileName = fileName;
}
public boolean equals(Object e) {
ElementFile eFile = (ElementFile) e;
if (!(getGuid().equals(eFile.getGuid()))
&& getFileName().equals(eFile.getFileName())) {
return appendIndex();
}
return getFileName().equals(eFile.getFileName());
}
public int hashCode() {
return fileName.hashCode();
}
public int compareTo(Object aFile) {
if (aFile instanceof ElementFile)
{
ElementFile e = (ElementFile) aFile;
return fileName.compareTo(e.getFileName());
}
return 1;
}
public void setFileName(String fName) {
fileName = fName;
}
public String getFileName() {
return fileName;
}
public String getGuid() {
return guid;
}
private boolean appendIndex() {
StringBuffer tString = new StringBuffer(getFileName());
int begindIdx = getFileName().lastIndexOf("-");
int endIdx = getFileName().lastIndexOf(".htm");
if (begindIdx > -1 && endIdx > -1) {
String idxString = getFileName().substring(begindIdx+1, endIdx);
if (idxString != null && idxString.length() > 0) {
try {
int aInt = Integer.parseInt(idxString);
if (aInt > 0) {
tString.replace(begindIdx+1, endIdx, Integer.toString(++aInt));
setFileName(tString.toString());
return false;
}
return true;
} catch(NumberFormatException nfe) {
tString.insert(endIdx, "-1");
setFileName(tString.toString());
return false;
}
}
} else if (endIdx > -1) {
tString.insert(endIdx, "-1");
setFileName(tString.toString());
return false;
}
return true;
}
}