<commit_before>package com.thinkbiganalytics.feedmgr.nifi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.PropertySource;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Consumer;

/**
 * Created by sr186054 on 5/3/16.
 *
 * Helper class to get Environment Properties
 */
public class SpringEnvironmentProperties {

    private  Map<String,Object> properties;

    public SpringEnvironmentProperties() {

    }

    @Autowired
    private ConfigurableEnvironment environment;

    /**
     * Get All Properties that start with a prefix
     * @param key
     * @return
     */
    public Map<String,Object> getPropertiesStartingWith(String key){
        Map<String,Object> props = getAllProperties();
        if(props != null) {
            NavigableMap m = new TreeMap(props);
            return m.subMap( key, key + Character.MAX_VALUE );
        }
        return null;
    }

    /**
     * get All properties
     * @return
     */
    public  Map<String,Object> getAllProperties(  )
    {
        if(properties == null) {
            final Map<String, Object> result = new HashMap<>();
            environment.getPropertySources().forEach(new Consumer<PropertySource<?>>() {
                @Override
                public void accept(PropertySource<?> propertySource) {
                    addAll(result, getAllProperties(propertySource));
                }
            });
            properties = result;
        }
        return properties;
    }

    private  Map<String,Object> getAllProperties( PropertySource<?> aPropSource )
    {
        final Map<String,Object> result = new HashMap<>();

        if ( aPropSource instanceof CompositePropertySource)
        {
            CompositePropertySource cps = (CompositePropertySource) aPropSource;
            cps.getPropertySources().forEach(new Consumer<PropertySource<?>>() {
                @Override
                public void accept(PropertySource<?> propertySource) {
                    addAll(result, getAllProperties(propertySource));
                }
            });
            return result;
        }

        if ( aPropSource instanceof EnumerablePropertySource<?>)
        {
           final  EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
            Arrays.asList(ps.getPropertyNames()).forEach(new Consumer<String>() {
                @Override
                public void accept(String key) {
                    result.put(key, ps.getProperty(key));
                }
            });
            return result;
        }
        return result;

    }

    private  void addAll( Map<String, Object> aBase, Map<String, Object> aToBeAdded )
    {
        for (Map.Entry<String, Object> entry : aToBeAdded.entrySet())
        {
            if ( aBase.containsKey( entry.getKey() ) )
            {
                continue;
            }

            aBase.put( entry.getKey(), entry.getValue() );
        }
    }

}
<commit_msg>fix build remove Java 8 function<commit_after>package com.thinkbiganalytics.feedmgr.nifi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.*;

import java.util.*;

/**
 * Created by sr186054 on 5/3/16.
 *
 * Helper class to get Environment Properties
 */
public class SpringEnvironmentProperties {

    private  Map<String,Object> properties;

    public SpringEnvironmentProperties() {

    }

    @Autowired
    private ConfigurableEnvironment environment;

    /**
     * Get All Properties that start with a prefix
     * @param key
     * @return
     */
    public Map<String,Object> getPropertiesStartingWith(String key){
        Map<String,Object> props = getAllProperties();
        if(props != null) {
            NavigableMap m = new TreeMap(props);
            return m.subMap( key, key + Character.MAX_VALUE );
        }
        return null;
    }

    /**
     * get All properties
     * @return
     */
    public  Map<String,Object> getAllProperties(  )
    {
        if(properties == null) {
            final Map<String, Object> result = new HashMap<>();
           MutablePropertySources sources = environment.getPropertySources();
            while(sources.iterator().hasNext()){
                PropertySource propertySource = sources.iterator().next();
                addAll(result, getAllProperties(propertySource));
            }
            properties = result;
        }
        return properties;
    }

    private  Map<String,Object> getAllProperties( PropertySource<?> aPropSource )
    {
        final Map<String,Object> result = new HashMap<>();

        if ( aPropSource instanceof CompositePropertySource)
        {
            CompositePropertySource cps = (CompositePropertySource) aPropSource;
            for(PropertySource propertySource: cps.getPropertySources()){
                addAll(result, getAllProperties(propertySource));
            }

            return result;
        }

        if ( aPropSource instanceof EnumerablePropertySource<?>)
        {
            EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
            if(ps != null && ps.getPropertyNames() != null) {
                List<String> keys = Arrays.asList(ps.getPropertyNames());
                for (String key : keys) {
                    result.put(key, ps.getProperty(key));
                }
            }
            return result;
        }
        return result;

    }

    private  void addAll( Map<String, Object> aBase, Map<String, Object> aToBeAdded )
    {
        for (Map.Entry<String, Object> entry : aToBeAdded.entrySet())
        {
            if ( aBase.containsKey( entry.getKey() ) )
            {
                continue;
            }

            aBase.put( entry.getKey(), entry.getValue() );
        }
    }

}

{'fraction_non_alphanumeric': 0.10185486495281484, 'fraction_numerical': 0.003416856492027335, 'mean_word_length': 2.1604113110539847, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '5666241', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1569, 'n_words': 346}