<commit_before>/*
 * (c) Copyright 2015 freiheit.com technologies GmbH
 *
 * Created on 14.07.15 by <EMAIL>
 *
 * This file contains unpublished, proprietary trade secret information of
 * freiheit.com technologies GmbH. Use, transcription, duplication and
 * modification are strictly prohibited without prior written consent of
 * freiheit.com technologies GmbH.
 */

package com.freiheit.fuava.simplebatch.fetch;

import java.io.File;
import java.util.Arrays;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;

/**
 * @author <EMAIL>
 */
class DirectoryFileFetcher<T> implements Supplier<Iterable<T>> {

    private final String filter;
    private final String uri;
    private final Function<File, T> func;

    public DirectoryFileFetcher( final String uri, final String filter, final Function<File, T> func ) {
        this.uri = Preconditions.checkNotNull( uri );
        this.filter = Preconditions.checkNotNull( filter );
        this.func = Preconditions.checkNotNull( func );
    }

    @Override
    public Iterable<T> get() {
        final File dir = new File( uri );
        final File[] files = dir.listFiles( ( dir1, name ) -> {
            return name != null && name.endsWith( filter );
        } );

        return FluentIterable.from( Arrays.asList( files ) ).transform( func );
    }
}
<commit_msg>fixed NPE<commit_after>/*
 * (c) Copyright 2015 freiheit.com technologies GmbH
 *
 * Created on 14.07.15 by <EMAIL>
 *
 * This file contains unpublished, proprietary trade secret information of
 * freiheit.com technologies GmbH. Use, transcription, duplication and
 * modification are strictly prohibited without prior written consent of
 * freiheit.com technologies GmbH.
 */

package com.freiheit.fuava.simplebatch.fetch;

import java.io.File;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;

/**
 * @author <EMAIL>
 */
class DirectoryFileFetcher<T> implements Supplier<Iterable<T>> {

    private final String filter;
    private final String uri;
    private final Function<File, T> func;

    public DirectoryFileFetcher( final String uri, final String filter, final Function<File, T> func ) {
        this.uri = Preconditions.checkNotNull( uri );
        this.filter = Preconditions.checkNotNull( filter );
        this.func = Preconditions.checkNotNull( func );
    }

    @Override
    public Iterable<T> get() {
        final File dir = new File( uri );
        final File[] files = dir.listFiles( ( dir1, name ) -> {
            return name != null && name.endsWith( filter );
        } );

        return FluentIterable.from( files == null
            ? ImmutableList.of()
            : ImmutableList.copyOf( files ) ).transform( func );
    }
}

{'fraction_non_alphanumeric': 0.10581121934833725, 'fraction_numerical': 0.007389989922741014, 'mean_word_length': 3.3347889374090247, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3113218', 'n_tokens_mistral': 879, 'n_tokens_neox': 833, 'n_words': 246}