<commit_before>/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.core.keygen;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import io.shardingsphere.core.exception.ShardingConfigurationException;
import io.shardingsphere.core.keygen.generator.KeyGenerator;
import io.shardingsphere.spi.NewInstanceServiceLoader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Collection;

/**
 * Key generator factory.
 * 
 * @author zhangliang
 * @author panjuan
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class KeyGeneratorFactory {
    
    /**
     * Create key generator.
     * 
     * @param keyGeneratorType key generator type
     * @return key generator instance
     */
    public static KeyGenerator newInstance(final String keyGeneratorType) {
        Collection<KeyGenerator> keyGenerators = loadKeyGenerators(keyGeneratorType);
        if (keyGenerators.isEmpty()) {
            throw new ShardingConfigurationException("Invalid key generator type.");
        }
        return keyGenerators.iterator().next();
    }
    
    private static Collection<KeyGenerator> loadKeyGenerators(final String keyGeneratorType) {
        return Collections2.filter(NewInstanceServiceLoader.load(KeyGenerator.class), new Predicate<KeyGenerator>() {
            
            @Override
            public boolean apply(final KeyGenerator input) {
                return keyGeneratorType.equals(input.getType());
            }
        });
    }
}<commit_msg>use equalsIgnoreCase<commit_after>/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package io.shardingsphere.core.keygen;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import io.shardingsphere.core.exception.ShardingConfigurationException;
import io.shardingsphere.core.keygen.generator.KeyGenerator;
import io.shardingsphere.spi.NewInstanceServiceLoader;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Collection;

/**
 * Key generator factory.
 * 
 * @author zhangliang
 * @author panjuan
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class KeyGeneratorFactory {
    
    /**
     * Create key generator.
     * 
     * @param keyGeneratorType key generator type
     * @return key generator instance
     */
    public static KeyGenerator newInstance(final String keyGeneratorType) {
        Collection<KeyGenerator> keyGenerators = loadKeyGenerators(keyGeneratorType);
        if (keyGenerators.isEmpty()) {
            throw new ShardingConfigurationException("Invalid key generator type.");
        }
        return keyGenerators.iterator().next();
    }
    
    private static Collection<KeyGenerator> loadKeyGenerators(final String keyGeneratorType) {
        return Collections2.filter(NewInstanceServiceLoader.load(KeyGenerator.class), new Predicate<KeyGenerator>() {
            
            @Override
            public boolean apply(final KeyGenerator input) {
                return keyGeneratorType.equalsIgnoreCase(input.getType());
            }
        });
    }
}
{'fraction_non_alphanumeric': 0.08553400327179247, 'fraction_numerical': 0.006543584949754616, 'mean_word_length': 3.495798319327731, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3526875', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1104, 'n_words': 329}