Search in sources :

Example 6 with IteratorConcatenator

use of net.sourceforge.processdash.util.IteratorConcatenator 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

Iterator (java.util.Iterator)6 IteratorConcatenator (net.sourceforge.processdash.util.IteratorConcatenator)6 EnumerIterator (net.sourceforge.processdash.util.EnumerIterator)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 File (java.io.File)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RobustFileWriter (net.sourceforge.processdash.util.RobustFileWriter)1 StringMapper (net.sourceforge.processdash.util.StringMapper)1