<commit_before>﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Reflection;

namespace Lucene.Net.Facet.Taxonomy.WriterCache
{
    internal class CharBlockArrayConverter : JsonConverter
    {
        private const string BlockSize = "blockSize";
        private const string Contents = "contents";

        public override bool CanConvert(Type objectType)
        {
            return typeof(CharBlockArray).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonObect = JObject.Load(reader);
            var properties = jsonObect.Properties().ToArray();

            int blockSize = -1;
            string contents = null;

            Func<bool> arePropertiesSet = () => blockSize > 0 && !string.IsNullOrEmpty(contents);

            foreach (var property in properties)
            {
                if (property.Name.Equals(BlockSize, StringComparison.OrdinalIgnoreCase))
                {
                    blockSize = property.Value.Value<int>();
                }
                else if (property.Name.Equals(Contents, StringComparison.OrdinalIgnoreCase))
                {
                    contents = property.Value.Value<string>();
                }

                if (arePropertiesSet())
                {
                    break;
                }
            }

            if (!arePropertiesSet())
            {
                return null;
            }

            var deserialized = new CharBlockArray(blockSize);

            deserialized.Append(contents);

            return deserialized;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var charBlockArray = value as CharBlockArray;

            if (charBlockArray == null)
            {
                return;
            }

            writer.WriteStartObject();

            writer.WritePropertyName(BlockSize);
            serializer.Serialize(writer, charBlockArray.blockSize);

            writer.WritePropertyName(Contents);
            serializer.Serialize(writer, charBlockArray.ToString());

            writer.WriteEndObject();
        }
    }
}<commit_msg>Lucene.Net.Facet.Taxonomy.WriterCache.CharBlockArrayConverter: Renamed constants upper case to match other constants<commit_after>﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Reflection;

namespace Lucene.Net.Facet.Taxonomy.WriterCache
{
    internal class CharBlockArrayConverter : JsonConverter
    {
        private const string BLOCK_SIZE = "blockSize";
        private const string CONTENTS = "contents";

        public override bool CanConvert(Type objectType)
        {
            return typeof(CharBlockArray).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jsonObect = JObject.Load(reader);
            var properties = jsonObect.Properties().ToArray();

            int blockSize = -1;
            string contents = null;

            Func<bool> arePropertiesSet = () => blockSize > 0 && !string.IsNullOrEmpty(contents);

            foreach (var property in properties)
            {
                if (property.Name.Equals(CharBlockArrayConverter.BLOCK_SIZE, StringComparison.OrdinalIgnoreCase))
                {
                    blockSize = property.Value.Value<int>();
                }
                else if (property.Name.Equals(CharBlockArrayConverter.CONTENTS, StringComparison.OrdinalIgnoreCase))
                {
                    contents = property.Value.Value<string>();
                }

                if (arePropertiesSet())
                {
                    break;
                }
            }

            if (!arePropertiesSet())
            {
                return null;
            }

            var deserialized = new CharBlockArray(blockSize);

            deserialized.Append(contents);

            return deserialized;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var charBlockArray = value as CharBlockArray;

            if (charBlockArray == null)
            {
                return;
            }

            writer.WriteStartObject();

            writer.WritePropertyName(BLOCK_SIZE);
            serializer.Serialize(writer, charBlockArray.blockSize);

            writer.WritePropertyName(CONTENTS);
            serializer.Serialize(writer, charBlockArray.ToString());

            writer.WriteEndObject();
        }
    }
}
{'fraction_non_alphanumeric': 0.08233841086867023, 'fraction_numerical': 0.0008233841086867024, 'mean_word_length': 1.8515258215962442, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '4627840', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1118, 'n_words': 242}