-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExtractTool: Add --concurrent option
- Loading branch information
Showing
2 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.netpreserve.jwarc; | ||
|
||
import java.net.URI; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* A set for testing whether WARC records are concurrent (i.e. part of the same capture event). | ||
*/ | ||
public class ConcurrentRecordSet { | ||
private final Set<URI> set = new HashSet<>(); | ||
|
||
/** | ||
* Adds a record to the set. | ||
*/ | ||
public void add(WarcRecord record) { | ||
set.add(record.id()); | ||
if (record instanceof WarcCaptureRecord) { | ||
set.addAll(((WarcCaptureRecord) record).concurrentTo()); | ||
} | ||
} | ||
|
||
/** | ||
* Tests if the given record is concurrent to any previously added record. | ||
*/ | ||
public boolean contains(WarcRecord record) { | ||
if (set.contains(record.id())) return true; | ||
if (record instanceof WarcCaptureRecord) { | ||
for (URI id : ((WarcCaptureRecord) record).concurrentTo()) { | ||
if (set.contains(id)) return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Removes all records from the set. | ||
*/ | ||
public void clear() { | ||
set.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters