<commit_before>package com.milaboratory.primitivio;

import java.lang.reflect.Array;
import java.util.UUID;

public class DefaultSerializersProviderImpl implements DefaultSerializersProvider {
    @Override
    public Serializer createSerializer(Class<?> type, SerializersManager manager) {
        if (type.isArray()) {
            Class<?> componentType = type.getComponentType();
            if (componentType.isPrimitive()) {
                if (componentType == Integer.TYPE)
                    return new IntArraySerializer();
                else if (componentType == Byte.TYPE)
                    return new ByteArraySerializer();
                else
                    return null;
            } else {
                return new ArraySerializer(manager.getSerializer(componentType) == null ? null : componentType);
            }
        }

        if (type.isEnum())
            return new EnumSerializer(type);

        if (type == Integer.class)
            return new IntegerSerializer();

        if (type == UUID.class)
            return new UUIDSerializer();

        return null;
    }

    private static class IntegerSerializer implements Serializer<Integer> {
        @Override
        public void write(PrimitivO output, Integer object) {
            output.writeInt(object);
        }

        @Override
        public Integer read(PrimitivI input) {
            return input.readInt();
        }

        @Override
        public boolean isReference() {
            return false;
        }

        @Override
        public boolean handlesReference() {
            return false;
        }
    }

    private static class IntArraySerializer implements Serializer<int[]> {
        @Override
        public void write(PrimitivO output, int[] object) {
            output.writeVarInt(object.length);
            for (int i : object)
                output.writeInt(i);
        }

        @Override
        public int[] read(PrimitivI input) {
            int[] object = new int[input.readVarInt()];
            for (int i = 0; i < object.length; i++)
                object[i] = input.readInt();
            return object;
        }

        @Override
        public boolean isReference() {
            return true;
        }

        @Override
        public boolean handlesReference() {
            return false;
        }
    }

    private static class ByteArraySerializer implements Serializer<byte[]> {
        @Override
        public void write(PrimitivO output, byte[] object) {
            output.writeVarInt(object.length);
            output.write(object);
        }

        @Override
        public byte[] read(PrimitivI input) {
            byte[] object = new byte[input.readVarInt()];
            input.readFully(object);
            return object;
        }
<commit_msg>Boolean array serializer for primitivio.<commit_after>package com.milaboratory.primitivio;

import java.lang.reflect.Array;
import java.util.UUID;

public class DefaultSerializersProviderImpl implements DefaultSerializersProvider {
    @Override
    public Serializer createSerializer(Class<?> type, SerializersManager manager) {
        if (type.isArray()) {
            Class<?> componentType = type.getComponentType();
            if (componentType.isPrimitive()) {
                if (componentType == Integer.TYPE)
                    return new IntArraySerializer();
                else if (componentType == Byte.TYPE)
                    return new ByteArraySerializer();
                else if (componentType == Boolean.TYPE)
                    return new BooleanArraySerializer();
                else
                    return null;
            } else {
                return new ArraySerializer(manager.getSerializer(componentType) == null ? null : componentType);
            }
        }

        if (type.isEnum())
            return new EnumSerializer(type);

        if (type == Integer.class)
            return new IntegerSerializer();

        if (type == UUID.class)
            return new UUIDSerializer();

        return null;
    }

    private static class IntegerSerializer implements Serializer<Integer> {
        @Override
        public void write(PrimitivO output, Integer object) {
            output.writeInt(object);
        }

        @Override
        public Integer read(PrimitivI input) {
            return input.readInt();
        }

        @Override
        public boolean isReference() {
            return false;
        }

        @Override
        public boolean handlesReference() {
            return false;
        }
    }

    private static class IntArraySerializer implements Serializer<int[]> {
        @Override
        public void write(PrimitivO output, int[] object) {
            output.writeVarInt(object.length);
            for (int i : object)
                output.writeInt(i);
        }

        @Override
        public int[] read(PrimitivI input) {
            int[] object = new int[input.readVarInt()];
            for (int i = 0; i < object.length; i++)
                object[i] = input.readInt();
            return object;
        }

        @Override
        public boolean isReference() {
            return true;
        }

        @Override
        public boolean handlesReference() {
            return false;
        }
    }

    private static class ByteArraySerializer implements Serializer<byte[]> {
        @Override
        public void write(PrimitivO output, byte[] object) {
            output.writeVarInt(object.length);
            output.write(object);
        }

        @Override
        public byte[] read(PrimitivI input) {
            byte[] object = new byte[input.readVarInt()];
            input.readFully(object);
            return object;
        }

        @Override
        public boolean isReference() {
            return false;
        }

        @Override
        public boolean handlesReference() {
            return false;
        }
    }

    private static class BooleanArraySerializer implements Serializer<boolean[]> {
        @Override
        public void write(PrimitivO output, boolean[] object) {
            output.writeVarInt(object.length);
            for (int i = 0; i < object.length; ++i)
                output.writeBoolean(object[i]);
        }

        @Override
        public boolean[] read(PrimitivI input) {
            boolean[] object = new boolean[input.readVarInt()];
            for (int i = 0; i < object.length; ++i)
                object[i] = input.readBoolean();
            return object;
        }

{'fraction_non_alphanumeric': 0.08907870652837095, 'fraction_numerical': 0.0006101281269066504, 'mean_word_length': 1.7343619683069225, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 14, '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': '142348', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1566, 'n_words': 421}