<commit_before>package de.cosmocode.commons;

import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class inspired by {@link StringUtils},
 * providing {@link String} related helper methods.
 *
 * @author <NAME>
 */
public final class Strings {
    
    public static final String DEFAULT_DELIMITER = " ";

    private static final Logger log = LoggerFactory.getLogger(Strings.class);
    
    /**
     * Prevent instantiation.
     */
    private Strings() {
        
    }
    
    /**
     * Joines instances of a collection
     * into a single string instance,
     * using a parametrizable JoinWalker
     * which transforms instances of T into Strings.
     * 
     * Calling this method is equivalent to
     * {@code StringUtility.join(collection, " ", walker}
     * 
     * @param <T> the generic type
     * @param collection the element provider
     * @param walker the function object which transform instances of T into strings
     * @throws NullPointerException if collection is null or collection is empty and walker is null
     * @return the joined collection as a string
     */
    public static <T> String join(Collection<? extends T> collection, JoinWalker<? super T> walker) {
        return Strings.join(collection, DEFAULT_DELIMITER, walker);
    }

    /**
     * Joines instances of a collection
     * into a single string instance,
     * using a parametrizable delimeter and
     * a JoinWalker which transforms instances
     * of T into Strings.
     * 
     * @param <T> the generic type
     * @param collection the element provider
     * @param delimiter the string betweens joined elements of collection
     * @param walker the function object which transform instances of T into strings
     * @throws NullPointerException if collection is null or collection is empty and walker is null
     * @return the joined collection as a string
     */
    public static <T> String join(Collection<? extends T> collection, String delimiter, JoinWalker<? super T> walker) {
        log.debug("Joining collection {} with delimiter '{}'", collection, delimiter);
        final StringBuilder builder = new StringBuilder();

        final Iterator<? extends T> iterator = collection.iterator();
        while (iterator.hasNext()) {
            final String value = walker.walk(iterator.next());
            log.debug("Walker returned {}", value);
            builder.append(value);
            if (iterator.hasNext()) builder.append(delimiter);
        }
        
        final String returnValue = builder.toString();
        log.debug("Joined collection: {}", returnValue);
        return returnValue;
    }
    
    /**
     * Checks whether a given {@link String} is a valid
     * number, containing only digits.<commit_msg>fixed checkstyle issue, changed log level from debug to trace<commit_after>package de.cosmocode.commons;

import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Utility class inspired by {@link StringUtils},
 * providing {@link String} related helper methods.
 *
 * @author <NAME>
 */
public final class Strings {
    
    public static final String DEFAULT_DELIMITER = " ";

    private static final Logger LOG = LoggerFactory.getLogger(Strings.class);
    
    /**
     * Prevent instantiation.
     */
    private Strings() {
        
    }
    
    /**
     * Joines instances of a collection
     * into a single string instance,
     * using a parametrizable JoinWalker
     * which transforms instances of T into Strings.
     * 
     * Calling this method is equivalent to
     * {@code StringUtility.join(collection, " ", walker}
     * 
     * @param <T> the generic type
     * @param collection the element provider
     * @param walker the function object which transform instances of T into strings
     * @throws NullPointerException if collection is null or collection is empty and walker is null
     * @return the joined collection as a string
     */
    public static <T> String join(Collection<? extends T> collection, JoinWalker<? super T> walker) {
        return Strings.join(collection, DEFAULT_DELIMITER, walker);
    }

    /**
     * Joines instances of a collection
     * into a single string instance,
     * using a parametrizable delimeter and
     * a JoinWalker which transforms instances
     * of T into Strings.
     * 
     * @param <T> the generic type
     * @param collection the element provider
     * @param delimiter the string betweens joined elements of collection
     * @param walker the function object which transform instances of T into strings
     * @throws NullPointerException if collection is null or collection is empty and walker is null
     * @return the joined collection as a string
     */
    public static <T> String join(Collection<? extends T> collection, String delimiter, JoinWalker<? super T> walker) {
        LOG.trace("Joining collection {} with delimiter '{}'", collection, delimiter);
        final StringBuilder builder = new StringBuilder();

        final Iterator<? extends T> iterator = collection.iterator();
        while (iterator.hasNext()) {
            final String value = walker.walk(iterator.next());
            LOG.trace("Walker returned {}", value);
            builder.append(value);
            if (iterator.hasNext()) builder.append(delimiter);
        }
        
        final String returnValue = builder.toString();
        LOG.trace("Joined collection: {}", returnValue);
        return returnValue;
    }
    
    /**
     * Checks whether a given {@link String} is a valid
     * number, containing only digits.
{'fraction_non_alphanumeric': 0.08634953464322648, 'fraction_numerical': 0.0006894174422612892, 'mean_word_length': 2.807742782152231, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6015350', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1458, 'n_words': 560}