Java 类javax.annotation.concurrent.NotThreadSafe 实例源码

项目:truevfs    文件:TFileSystem.java   
DirectoryStream<Path> newDirectoryStream(
        final TPath path,
        final Filter<? super Path> filter)
throws IOException {
    final FsNode entry = stat(path);
    final Set<String> set;
    if (null == entry || null == (set = entry.getMembers()))
        throw new NotDirectoryException(path.toString());

    @NotThreadSafe
    class Adapter implements Iterator<Path> {
        final Iterator<String> it = set.iterator();

        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public Path next() {
            return path.resolve(it.next());
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    } // Adapter

    @NotThreadSafe
    class FilterIterator extends FilteringIterator<Path> {
        FilterIterator() { super(new Adapter()); }

        @Override
        protected boolean accept(Path element) {
            try {
                return filter.accept(element);
            } catch (IOException ex) {
                throw new DirectoryIteratorException(ex);
            }
        }
    } // FilterIterator

    return  new Stream(new FilterIterator());
}