Search in sources :

Example 6 with EnumerIterator

use of net.sourceforge.processdash.util.EnumerIterator in project processdash by dtuma.

the class ImportedTimeLogManager method getImportedTimeLogEntries.

/**
     * Return an iterator of the time log entries mounted at the given prefix.
     * If no imported defects are mounted at the given prefix, returns null.
     */
public EnumerIterator getImportedTimeLogEntries(String prefix) throws IOException {
    prefix = cleanupPrefix(prefix);
    List timeLogIterators = new ArrayList();
    Map snapshot;
    synchronized (importedLogs) {
        snapshot = new HashMap(importedLogs);
    }
    for (Iterator i = snapshot.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry e = (Map.Entry) i.next();
        String importedPrefix = (String) e.getKey();
        File file = (File) e.getValue();
        if (Filter.pathMatches(importedPrefix, prefix)) {
            // this set of imported time log data is either (a) mounted
            // at the exact prefix requested, or (b) mounted at a prefix
            // underneath the one requested. In either case, we should
            // return all imported entries.
            Iterator content = new TimeLogReader(file);
            timeLogIterators.add(content);
        } else if (Filter.pathMatches(prefix, importedPrefix)) {
            // in this case, the requested prefix identifies a subset of
            // the imported time log data. We must filter that imported
            // data to return the requested entries.
            Iterator content = new TimeLogReader(file);
            Iterator filteredContent = new TimeLogIteratorFilter(content, prefix, null, null);
            if (filteredContent.hasNext())
                timeLogIterators.add(filteredContent);
        }
    }
    if (timeLogIterators.isEmpty())
        return null;
    else if (timeLogIterators.size() == 1)
        return (EnumerIterator) timeLogIterators.get(0);
    else
        return new IteratorConcatenator(timeLogIterators);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) Iterator(java.util.Iterator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

EnumerIterator (net.sourceforge.processdash.util.EnumerIterator)6 File (java.io.File)3 Iterator (java.util.Iterator)3 IteratorConcatenator (net.sourceforge.processdash.util.IteratorConcatenator)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 Map (java.util.Map)1 TimeLogEntry (net.sourceforge.processdash.log.time.TimeLogEntry)1 StringMapper (net.sourceforge.processdash.util.StringMapper)1