compareworker.java
来自「dump3 morpheus 0.2.9 src」· Java 代码 · 共 145 行
JAVA
145 行
/**
* 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.compare;
import java.util.Observable;
import net.za.grasser.duplicate.file.FingerprintFile;
import net.za.grasser.duplicate.fingerprint.AbstractFingerprint;
import net.za.grasser.duplicate.persist.DatabaseFactory;
import net.za.grasser.duplicate.util.Constants;
import org.apache.log4j.Logger;
/**
* @modelguid {6B9EB4EA-87E3-4482-8780-C4A45652D66A}
* @author <a href="http://sourceforge.net/sendmessage.php?touser=733840">pyropunk at sourceforge dot net</a>
* @version $Revision: 1.11 $
*/
class CompareWorker extends Observable implements Runnable {
/** @modelguid {2295ADEE-A695-4A57-ADD2-DD469FEA833F} */
static Logger log = Logger.getLogger(CompareWorker.class);
/**
* <code>running</code> Comparer -
*/
private boolean running = false;
/**
* <code>number</code> Comparer -
*/
private int number;
/**
* <code>parent</code> CompareWorker - refence to the Comparer singleton (othrewise we will have to call getInstance)
*/
private Comparer parent;
/**
* Constructor
*
* @param pParent
* @param pNum
*/
public CompareWorker(final Comparer pParent, final int pNum) {
super();
number = pNum;
parent = pParent;
start();
}
/**
* Start the thread with minimum thread priority otherwise it slows them machine dramitically.
*/
public void start() {
if (!running) {
running = true;
final Thread t = new Thread(this, Constants.getClassName(this) + ':' + number);
t.setDaemon(true);
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
}
/**
* This method generates the fingerprints
*
* @param ff
*/
private void process(final FingerprintFile ff) {
if (!DatabaseFactory.getDatabase().get(ff)) {
for (final String key : ff.getFingerprints().keySet()) {
final AbstractFingerprint af = ff.getFingerprints().get(key);
af.addInfo();
af.getFingerprint();
}
DatabaseFactory.getDatabase().put(ff);
}
// if the info was not found try to gen it.
if (ff.getInfo().isEmpty()) {
for (final String key : ff.getFingerprints().keySet()) {
final AbstractFingerprint af = ff.getFingerprints().get(key);
af.addInfo();
}
DatabaseFactory.getDatabase().put(ff);
}
parent.checkIn(ff);
}
/**
* This method processes the files.
*/
private void process() {
try {
final FingerprintFile ff1 = parent.removeFirst();
if (ff1 == null) {
running = false;
return;
}
process(ff1);
} catch (final Exception e) {
log.warn("Could not compute the fingerprint", e);
}
}
/**
* @see java.lang.Runnable#run()
*/
public void run() {
log.info("Generating (" + number + ") started");
while (running) {
process();
}
log.debug("stoppage notification received");
running = false;
setChanged();
super.notifyObservers("stop");
log.info("Generating (" + number + ") stopped");
}
/**
* @return boolean - Returns the running.
*/
public synchronized boolean isRunning() {
return running;
}
/**
* Stops all threads.
*
* @param pRunning boolean - The new value.
*/
public synchronized void setRunning(final boolean pRunning) {
running = pRunning;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?