<commit_before>package com.proxerme.library.api;

import com.proxerme.library.enums.FskConstraint;
import com.proxerme.library.enums.Genre;
import com.squareup.moshi.*;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.EnumSet;
import java.util.Set;

/**
 * TODO: Describe class
 *
 * @author <NAME>
 */
class DelimitedEnumSetAdapterFactory implements JsonAdapter.Factory {

    @Override
    public JsonAdapter<?> create(final Type type, final Set<? extends Annotation> annotations, final Moshi moshi) {
        final Type rawType = Types.getRawType(type);

        if (rawType != Set.class || !(type instanceof ParameterizedType)) {
            return null;
        }

        final Type parameterType = ((ParameterizedType) type).getActualTypeArguments()[0];

        if (parameterType == Genre.class) {
            return new DelimitedEnumSetAdapter<>(Genre.class);
        } else if (parameterType == FskConstraint.class) {
            return new DelimitedEnumSetAdapter<>(FskConstraint.class);
        }

        return null;
    }

    private static class DelimitedEnumSetAdapter<T extends Enum<T>> extends JsonAdapter<Set<T>> {

        private static final String DELIMITER = " ";

        private final Class<T> enumType;

        DelimitedEnumSetAdapter(@NotNull final Class<T> enumType) {
            this.enumType = enumType;
        }

        @Override
        public Set<T> fromJson(final JsonReader reader) throws IOException {
            final String json = reader.nextString();

            if (json.isEmpty()) {
                return EnumSet.noneOf(enumType);
            }

            final String[] parts = json.split(DELIMITER);
            final EnumSet<T> result = EnumSet.noneOf(enumType);

            for (final String part : parts) {
                for (final Field field : enumType.getFields()) {
                    if (field.getAnnotation(Json.class).name().equals(part)) {
                        result.add(Enum.valueOf(enumType, field.getName()));
                    }
                }
            }

            return result;
        }

        @Override
        public void toJson(final JsonWriter writer, final Set<T> value) throws IOException {
            String result = "";

            for (final T item : value) {
                try {
                    result += enumType.getField(item.name()).getAnnotation(Json.class).name();
                } catch (NoSuchFieldException e) {
                    throw new JsonDataException("Illegal item in set: " + item.name());
                }

                result += DELIMITER;
            }

            if (!result.isEmpty()) {
                result = result.substring(result.length() - DELIMITER.length());
            }

            writer.value(result);
        }

        private String getName(FskConstraint fskConstraint) throws NoSuchFieldException {
            return enumType.getField(fskConstraint.name()).getAnnotation(Json.class).name();
        }
    }
}
<commit_msg>Remove unused method<commit_after>package com.proxerme.library.api;

import com.proxerme.library.enums.FskConstraint;
import com.proxerme.library.enums.Genre;
import com.squareup.moshi.*;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.EnumSet;
import java.util.Set;

/**
 * TODO: Describe class
 *
 * @author <NAME>
 */
class DelimitedEnumSetAdapterFactory implements JsonAdapter.Factory {

    @Override
    public JsonAdapter<?> create(final Type type, final Set<? extends Annotation> annotations, final Moshi moshi) {
        final Type rawType = Types.getRawType(type);

        if (rawType != Set.class || !(type instanceof ParameterizedType)) {
            return null;
        }

        final Type parameterType = ((ParameterizedType) type).getActualTypeArguments()[0];

        if (parameterType == Genre.class) {
            return new DelimitedEnumSetAdapter<>(Genre.class);
        } else if (parameterType == FskConstraint.class) {
            return new DelimitedEnumSetAdapter<>(FskConstraint.class);
        }

        return null;
    }

    private static class DelimitedEnumSetAdapter<T extends Enum<T>> extends JsonAdapter<Set<T>> {

        private static final String DELIMITER = " ";

        private final Class<T> enumType;

        DelimitedEnumSetAdapter(@NotNull final Class<T> enumType) {
            this.enumType = enumType;
        }

        @Override
        public Set<T> fromJson(final JsonReader reader) throws IOException {
            final String json = reader.nextString();

            if (json.isEmpty()) {
                return EnumSet.noneOf(enumType);
            }

            final String[] parts = json.split(DELIMITER);
            final EnumSet<T> result = EnumSet.noneOf(enumType);

            for (final String part : parts) {
                for (final Field field : enumType.getFields()) {
                    if (field.getAnnotation(Json.class).name().equals(part)) {
                        result.add(Enum.valueOf(enumType, field.getName()));
                    }
                }
            }

            return result;
        }

        @Override
        public void toJson(final JsonWriter writer, final Set<T> value) throws IOException {
            String result = "";

            for (final T item : value) {
                try {
                    result += enumType.getField(item.name()).getAnnotation(Json.class).name();
                } catch (NoSuchFieldException e) {
                    throw new JsonDataException("Illegal item in set: " + item.name());
                }

                result += DELIMITER;
            }

            if (!result.isEmpty()) {
                result = result.substring(result.length() - DELIMITER.length());
            }

            writer.value(result);
        }
    }
}

{'fraction_non_alphanumeric': 0.10502357340269874, 'fraction_numerical': 0.0003251503820516989, 'mean_word_length': 2.1500256016385046, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '4743956', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1591, 'n_words': 372}