Changeset 5311 for CMDIValidator


Ignore:
Timestamp:
05/30/14 11:39:18 (10 years ago)
Author:
Oliver Schonefeld
Message:
  • add file filtering capability
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMDIValidator/trunk/src/main/java/eu/clarin/cmdi/validator/CMDIValidatorJob.java

    r5052 r5311  
    11package eu.clarin.cmdi.validator;
    22
     3import java.io.FileFilter;
    34import java.util.LinkedList;
    45import java.util.List;
     
    1415
    1516
    16     public CMDIValidatorJob(TFile root, CMDIValidatorJobHandler handler) {
     17    public CMDIValidatorJob(TFile root, FileFilter filter,
     18            CMDIValidatorJobHandler handler) {
    1719        if (root == null) {
    1820            throw new NullPointerException("root = null");
     
    2628        }
    2729        this.handler = handler;
    28         this.fileEnumerator = new FileEnumerator(root);
     30        this.fileEnumerator = new FileEnumerator(root, filter);
    2931        this.handler.onJobStarted();
     32    }
     33
     34
     35    public CMDIValidatorJob(TFile root, CMDIValidatorJobHandler handler) {
     36        this(root, null, handler);
    3037    }
    3138
     
    6471            if (fileEnumerator.isEmpty() || (file == null)) {
    6572                jobList.remove(this);
     73                if (filesInProcessing == 0) {
     74                    signalDone();
     75                }
    6676            }
    6777            return file;
     
    7787            }
    7888            if (fileEnumerator.isEmpty() && (filesInProcessing == 0)) {
    79                 handler.onJobFinished(canceled);
    80                 if (canceled) {
    81                     this.notifyAll();
    82                     return true;
    83                 }
     89                signalDone();
     90                return true;
    8491            }
    8592        } // synchronized (this)
     
    8895
    8996
     97    private void signalDone() {
     98        handler.onJobFinished(canceled);
     99        if (canceled) {
     100            this.notifyAll();
     101        }
     102    }
     103
     104
    90105    private final static class FileEnumerator {
    91         private static final class FileList {
     106        private final class FileList {
    92107            private final TFile[] fileList;
    93108            private int idx = 0;
     
    100115
    101116            private TFile nextFile() {
    102                 if (idx < fileList.length) {
    103                     return fileList[idx++];
    104                 } else {
    105                     return null;
    106                 }
     117                while (idx < fileList.length) {
     118                    final TFile file = fileList[idx++];
     119                    if (file.isDirectory()) {
     120                        return file;
     121                    }
     122                    if ((filter != null) && !filter.accept(file)) {
     123                        continue;
     124                    }
     125                    return file;
     126                } // while
     127                return null;
    107128            }
    108129
     
    111132            }
    112133        }
     134        private final FileFilter filter;
    113135        private final LinkedList<FileList> stack =
    114136                new LinkedList<FileList>();
    115137
    116138
    117         private FileEnumerator(TFile root) {
     139        private FileEnumerator(TFile root, FileFilter filter) {
    118140            if (root == null) {
    119141                throw new NullPointerException("root == null");
     
    122144                throw new IllegalArgumentException("root is not a directory");
    123145            }
     146            this.filter = filter;
    124147            pushDirectory(root);
    125148        }
Note: See TracChangeset for help on using the changeset viewer.