Search in sources :

Example 1 with IteratorConcatenator

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

the class PropertyKeyIterator method getForPrefixes.

public static Iterator getForPrefixes(DashHierarchy hier, Collection prefixes) {
    List results = new ArrayList(prefixes.size());
    for (Iterator i = prefixes.iterator(); i.hasNext(); ) {
        String onePrefix = (String) i.next();
        PropertyKey oneKey = hier.findExistingKey(onePrefix);
        if (oneKey != null)
            results.add(new PropertyKeyIterator(hier, oneKey));
    }
    if (results.isEmpty())
        return Collections.EMPTY_LIST.iterator();
    else if (results.size() == 1)
        return (Iterator) results.get(0);
    else
        return new IteratorConcatenator(results);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IteratorConcatenator

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

the class TimeLogModifications method filter.

public EnumerIterator filter(String path, Date from, Date to) throws IOException {
    if (isEmpty())
        // optimization if there are no modifications to perform
        return parent.filter(path, from, to);
    Iterator baseEntries = parent.filter(null, null, null);
    Iterator modifiedEntries = new ModifiedEntriesFilter(baseEntries);
    Iterator addedEntries = new AddedEntriesFilter();
    EnumerIterator allEntries = new IteratorConcatenator(modifiedEntries, addedEntries);
    if (path == null && from == null && to == null)
        return allEntries;
    else
        return new TimeLogIteratorFilter(allEntries, path, from, to);
}
Also used : EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) Iterator(java.util.Iterator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator)

Example 3 with IteratorConcatenator

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

the class TimeLogModifications method save.

public synchronized boolean save() {
    if (saveFile == null || Settings.isReadOnly())
        return false;
    try {
        RobustFileWriter out = new RobustFileWriter(saveFile, "UTF-8");
        Iterator entries = new IteratorConcatenator(//
        new RenamingOperationsIterator(), modifications.values().iterator());
        TimeLogWriter.write(out, entries);
        saveFileTimestamp = saveFile.lastModified();
        dirty = false;
        return true;
    } catch (IOException ioe) {
        System.err.println("Unable to save time log modifications to file '" + saveFile + "'");
        ioe.printStackTrace();
        return false;
    }
}
Also used : Iterator(java.util.Iterator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator) RobustFileWriter(net.sourceforge.processdash.util.RobustFileWriter) IOException(java.io.IOException)

Example 4 with IteratorConcatenator

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

the class RolledUpTimeLog method filter.

public EnumerIterator filter(String path, Date from, Date to) throws IOException {
    List entries = new ArrayList();
    String[] prefixes = getPrefixes();
    StringMapper pathRemapper = getPathRemapper(prefixes);
    for (int i = 0; i < prefixes.length; i++) {
        String onePrefix = prefixes[i];
        // find any imported entries for the given prefix
        Iterator importedEntries = ImportedTimeLogManager.getInstance().getImportedTimeLogEntries(onePrefix);
        maybeAddEntries(entries, importedEntries, pathRemapper);
        // find any regular entries for the given prefix
        Iterator regularEntries = context.getTimeLog().filter(onePrefix, from, to);
        maybeAddEntries(entries, regularEntries, pathRemapper);
    }
    EnumerIterator result = new IteratorConcatenator(entries);
    result = new TimeLogIteratorFilter(result, path, from, to);
    return result;
}
Also used : StringMapper(net.sourceforge.processdash.util.StringMapper) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with IteratorConcatenator

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

the class WorkingTimeLog method maybeCleanup.

private synchronized void maybeCleanup() throws IOException {
    if (Settings.isReadOnly())
        return;
    File oldStyleFile = getFile(OLD_TIME_LOG_FILENAME);
    if (oldStyleFile.isFile() && oldStyleFile.length() > 0) {
        Iterator currentEntries = realTimeMods.filter(null, null, null);
        Iterator watcherCurrentEntries = new IDWatcher(currentEntries);
        Iterator extraEntries = new OldStyleTimeLogReader(oldStyleFile, this);
        Iterator allEntries = new IteratorConcatenator(watcherCurrentEntries, extraEntries);
        doCleanup(allEntries);
        getFile(OLD_TIME_LOG_FILENAME).delete();
    } else if (realTimeMods.isEmpty() == false) {
        Iterator currentEntries = realTimeMods.filter(null, null, null);
        Iterator watcherCurrentEntries = new IDWatcher(currentEntries);
        doCleanup(watcherCurrentEntries);
    } else {
        // no need to cleanup, but we still need to scan the existing log
        // to find out the highest numbered TimeLogEntry ID in use
        Iterator currentEntries = historicalTimeLog.filter(null, null, null);
        Iterator watcherCurrentEntries = new IDWatcher(currentEntries);
        while (watcherCurrentEntries.hasNext()) watcherCurrentEntries.next();
    }
}
Also used : Iterator(java.util.Iterator) EnumerIterator(net.sourceforge.processdash.util.EnumerIterator) IteratorConcatenator(net.sourceforge.processdash.util.IteratorConcatenator) 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