<commit_before>/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * 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.
 *******************************************************************************/

package com.pushtechnology.diffusion.transform.adder;

import static com.pushtechnology.diffusion.transform.transformer.Transformers.identity;

import com.pushtechnology.diffusion.client.topics.details.TopicType;
import com.pushtechnology.diffusion.datatype.binary.Binary;
import com.pushtechnology.diffusion.datatype.json.JSON;

/**
 * Factory for creating instances of {@link TopicAdderBuilder}s.
 *
 * @author Push Technology Limited
 */
public final class TopicAdderBuilders {
    private TopicAdderBuilders() {
    }

    /**
     * Create a builder for {@link JSON} topic adders.
     * @return The builder
     */
    public static UnboundSafeTopicAdderBuilder<JSON, JSON> jsonTopicAdderBuilder() {
        return new UnboundSafeTopicAdderBuilderImpl<>(TopicType.JSON, identity(JSON.class));
    }

    /**
     * Create a builder for {@link Binary} topic adders.
     * @return The builder
     */
    public static UnboundSafeTopicAdderBuilder<Binary, Binary> binaryTopicAdderBuilder() {
        return new UnboundSafeTopicAdderBuilderImpl<>(TopicType.BINARY, identity(Binary.class));
    }
}<commit_msg>Add a method that allows topic adders to be add from a provided value type.<commit_after>/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * 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.
 *******************************************************************************/

package com.pushtechnology.diffusion.transform.adder;

import static com.pushtechnology.diffusion.transform.transformer.Transformers.identity;

import com.pushtechnology.diffusion.client.topics.details.TopicType;
import com.pushtechnology.diffusion.datatype.Bytes;
import com.pushtechnology.diffusion.datatype.binary.Binary;
import com.pushtechnology.diffusion.datatype.json.JSON;
import com.pushtechnology.diffusion.datatype.recordv2.RecordV2;

/**
 * Factory for creating instances of {@link TopicAdderBuilder}s.
 *
 * @author Push Technology Limited
 */
public final class TopicAdderBuilders {
    private TopicAdderBuilders() {
    }

    /**
     * Create a builder for {@link JSON} topic adders.
     * @param valueType The value type
     * @param <V> The value type
     * @return The builder
     * @throws IllegalArgumentException If there is no known topic type for the value
     */
    public static <V extends Bytes> UnboundSafeTopicAdderBuilder<V, V> topicAdderBuilder(Class<V> valueType) {
        return new UnboundSafeTopicAdderBuilderImpl<>(topicTypeFromValueType(valueType), identity(valueType));
    }

    /**
     * Create a builder for {@link JSON} topic adders.
     * @return The builder
     */
    public static UnboundSafeTopicAdderBuilder<JSON, JSON> jsonTopicAdderBuilder() {
        return new UnboundSafeTopicAdderBuilderImpl<>(TopicType.JSON, identity(JSON.class));
    }

    /**
     * Create a builder for {@link Binary} topic adders.
     * @return The builder
     */
    public static UnboundSafeTopicAdderBuilder<Binary, Binary> binaryTopicAdderBuilder() {
        return new UnboundSafeTopicAdderBuilderImpl<>(TopicType.BINARY, identity(Binary.class));
    }

    /**
     * Returns the topic type for a given value type.
     * @throws IllegalArgumentException If there is no known topic type for the value
     */
    /*package*/ static TopicType topicTypeFromValueType(Class<?> valueType) {
        if (JSON.class.isAssignableFrom(valueType)) {
            return TopicType.JSON;
        }
        else if (Binary.class.isAssignableFrom(valueType)) {
            return TopicType.BINARY;
        }
        else if (String.class.isAssignableFrom(valueType)) {
            return TopicType.STRING;
        }
        else if (Double.class.isAssignableFrom(valueType)) {
            return TopicType.DOUBLE;
        }
        else if (Long.class.isAssignableFrom(valueType)) {
            return TopicType.INT64;
        }
        else if (RecordV2.class.isAssignableFrom(valueType)) {
            return TopicType.RECORD_V2;
        }
        else {
            throw new IllegalArgumentException("The topic type for " + valueType + " is unknown");
        }
    }
}
{'fraction_non_alphanumeric': 0.14041536482264289, 'fraction_numerical': 0.0040433743797096125, 'mean_word_length': 3.707612456747405, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6207815', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1408, 'n_words': 435}