📄 fingerprintfile.java
字号:
/**
* DuMP3 version morpheus_0.2.9 - a duplicate/similar file finder in Java<BR>
* Copyright 2005 Alexander Grässer<BR>
* All Rights Reserved, http://dump3.sourceforge.net/<BR>
* <BR>
* This file is part of DuMP3.<BR>
* <BR>
* DuMP3 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; either version 2 of the License, or (at your option) any later version.<BR>
* <BR>
* DuMP3 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.<BR>
* <BR>
* You should have received a copy of the GNU General Public License along with DuMP3; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.za.grasser.duplicate.file;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.za.grasser.duplicate.fingerprint.AbstractFingerprint;
import net.za.grasser.duplicate.util.Constants;
import org.apache.log4j.Logger;
/**
* This class defines a file to which a number of <code>AbstractFingerprint</code>s can be attached.
*
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.16 $
*/
public class FingerprintFile implements Comparable<FingerprintFile> {
/**
* <code>log</code> FingerprintFile -
*/
private static final Logger log = Logger.getLogger(FingerprintFile.class);
/**
* <code>name</code> FingerprintFile - the file name
*/
private String name;
/**
* <code>length</code> FingerprintFile - the length in bytes
*/
private long length;
/**
* <code>lastModified</code> FingerprintFile - the last modified date
*/
private long lastModified;
/**
* <code>parent</code> FingerprintFile -
*/
private DirectoryInfo parent;
/** @modelguid {78ACC448-8BAB-46D6-9966-E436FB71FEAD} */
private Status status = Status.FILE_UNKNOWN;
/**
* <code>fingerprints</code> FingerprintFile - a list of all fingerprints for this file
*/
private Map<String, AbstractFingerprint> fingerprints = null;
/**
* <code>similarity</code> FingerprintFile - similarity to base
*/
private float similarity = 0.0f;
/** @modelguid {E8F2057A-CF47-4A07-B27B-97AC6BF290F4} */
private ArrayList<FingerprintFile> duplicates = null;
/**
* <code>compared</code> FingerprintFile -
*/
private FingerprintFile compared = null;
/**
* <code>info</code> FingerprintFile -
*/
private Map<String, String> info = null;
/**
* @param pName
* @param pLength
* @param pLastMod
* @param pParent
*/
public FingerprintFile(final String pName, final long pLength, final long pLastMod, final DirectoryInfo pParent) {
super();
name = pName;
length = pLength;
lastModified = pLastMod;
parent = pParent;
}
/**
* @return String - Returns the name.
*/
public String getName() {
return name;
}
/**
* Sets the name to the value of pName.
*
* @param pName String - The new value.
*/
public void setName(final String pName) {
name = pName;
}
/**
* @return long - Returns the lastModified.
*/
public long getLastModified() {
return lastModified;
}
/**
* Sets the lastModified to the value of pLastModified.
*
* @param pLastModified long - The new value.
*/
public void setLastModified(final long pLastModified) {
lastModified = pLastModified;
}
/**
* @return long - Returns the length.
*/
public long getLength() {
return length;
}
/**
* Sets the length to the value of pLength.
*
* @param pLength long - The new value.
*/
public void setLength(final long pLength) {
length = pLength;
}
/**
* @return DirectoryInfo - Returns the parent.
*/
public DirectoryInfo getParent() {
return parent;
}
/**
* Sets the parent to the value of pParent.
*
* @param pParent DirectoryInfo - The new value.
*/
public void setParent(final DirectoryInfo pParent) {
parent = pParent;
}
/**
* @return full path of the file including the file name
*/
public String getPath() {
return parent.getPath() + getName();
}
/**
* @return the status.
* @modelguid {B35B3436-7B40-4184-9A6F-6EBDA7DE8023}
*/
public Status getStatus() {
return status;
}
/**
* Sets the status to the value of pStatus.
*
* @param pStatus - The new value.
* @modelguid {A7F2F20A-D30B-4AAD-825F-B1D5AE494939}
*/
public void setStatus(final Status pStatus) {
status = pStatus;
}
/**
* @param fp
*/
public void addFingerprint(final AbstractFingerprint fp) {
if (fingerprints == null) {
fingerprints = new HashMap<String, AbstractFingerprint>();
}
fingerprints.put(fp.getClassName(), fp);
}
/**
* display or log the status of the file if it is not ok.
*/
public void logFileStatus() {
if (status == Status.FILE_SIGNATURE_MISMATCH) {
log.warn(getPath() + " has invalid signature!");
} else if (status == Status.FILE_TOO_SHORT) {
log.warn(getPath() + " is too short!");
} else if (status == Status.FILE_MISSING) {
log.warn(getPath() + " is missing!");
} else if (status == Status.FILE_NOT_READABLE) {
log.warn(getPath() + " can not be opened!");
} else if (status == Status.FILE_CORRUPT) {
log.warn(getPath() + " could be corrupt!");
} else if (status == Status.FILE_INVALID) {
log.warn(getPath() + " is invalid!");
} else if (status == Status.FILE_EMPTY) {
log.warn(getPath() + " is empty!");
}
}
/**
* @return Map - Returns the fingerprints.
*/
public Map<String, AbstractFingerprint> getFingerprints() {
return fingerprints;
}
/**
* @return float - Returns the similarity.
*/
public float getSimilarity() {
return similarity;
}
/**
* Sets the similarity to the value of pSimilarity.
*
* @param pSimilarity float - The new value.
*/
public void setSimilarity(final float pSimilarity) {
similarity = pSimilarity;
}
/**
* @param fi FingerprintFile
* @modelguid {8FD2E139-2654-4FA7-BF30-46BC512319CF}
*/
public void addDuplicate(final FingerprintFile fi) {
if (duplicates == null) {
duplicates = new ArrayList<FingerprintFile>(1);
}
duplicates.add(fi);
fi.compared = this;
}
/**
* @return ArrayList
* @modelguid {B4E2FA3D-D858-4044-8BD1-F3221AA3B3CA}
*/
public List<FingerprintFile> getDuplicates() {
return duplicates;
}
/**
* This method recureses the duplicates list
*
* @param sb
* @param pFile
* @param pLevel
* @param hasSiblings
* @return StringBuffer
*/
private static StringBuffer recursDuplicates(final StringBuffer sb, final FingerprintFile pFile, final int pLevel, final boolean hasSiblings) {
for (int i = 0; i < pLevel - 1; i++) {
if (hasSiblings) {
sb.append(" | ");
} else {
sb.append(" ");
}
}
if (pLevel > 0) {
sb.append(" + ");
}
sb.append(pFile.getPath());
if (pLevel > 0) {
sb.append(" (").append(pFile.getSimilarity()).append("%)");
} else if (pFile.status != Status.FILE_OK) {
sb.append(" [").append(pFile.status).append("]");
return sb;
}
sb.append(Constants.LS);
if (pFile.duplicates == null || pFile.duplicates.isEmpty()) {
return sb;
}
final Iterator<FingerprintFile> it = pFile.duplicates.iterator();
while (it.hasNext()) {
final FingerprintFile sub = it.next();
recursDuplicates(sb, sub, pLevel + 1, it.hasNext());
}
return sb;
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return recursDuplicates(new StringBuffer(), this, 0, false).toString();
}
/**
* @return String
* @modelguid {796E55E1-8AEF-40CB-9275-EE4C88FA6376}
*/
public String getKey() {
return new StringBuffer(getPath()).append("-l").append(getLength()).append("m").append(getLastModified()).toString();
}
/**
* @return the extension of the file
*/
public String getExtension() {
if (name.lastIndexOf('.') >= 0) {
return name.substring(name.lastIndexOf('.') + 1).toLowerCase();
}
return "";
}
/**
* @param pArg0
* @return int
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(final FingerprintFile pArg0) {
return getPath().compareTo(pArg0.getPath());
}
/**
* @return FingerprintFile - Returns the compared.
*/
public FingerprintFile getCompared() {
return compared;
}
/**
* Sets the compared to the value of pCompared.
*
* @param pCompared FingerprintFile - The new value.
*/
public void setCompared(final FingerprintFile pCompared) {
compared = pCompared;
}
/**
* @return Map<String,String> - Returns the info.
*/
public Map<String, String> getInfo() {
if (info == null) {
info = new HashMap<String, String>();
}
return info;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -