Beispiel #1
0
        private IndexData(TernarySearchTreeDictionary <NonNullImmutableList <WeightedEntry <TKey> > > data, IEqualityComparer <TKey> dataKeyComparer, bool validate)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            // If the constructor is called from a method within this class then the data should be known to be valid but if the constructor call was from
            // other code then perform some sanity checking on it
            if (validate)
            {
                var allValues = data.GetAllValues();
                if (allValues.Any(v => v == null))
                {
                    throw new ArgumentException("data may not contain any null WeightedEntry list values");
                }
                if (allValues.Any(v => v.Count == 0))
                {
                    throw new ArgumentException("data may not contain any empty WeightedEntry list values");
                }
            }

            _data = data;
            _sourceLocationsAvailable = new Lazy <bool>(() =>
            {
                var atLeastOneEntryIsMissingSourceLocations = _data.GetAllValues().Any(entries => entries.Any(entry => entry.SourceLocationsIfRecorded == null));
                return(!atLeastOneEntryIsMissingSourceLocations);
            });
            KeyComparer = dataKeyComparer ?? throw new ArgumentNullException("dataKeyComparer");
        }
 private void Write <TValue>(JsonWriter writer, TernarySearchTreeDictionary <TValue> value, JsonSerializer serializer)
 {
     // Note: Note using the ToDictionary method since that uses the KeyNormaliser as the IEqualityComparer on the dictionary, which is just one more complication - it's
     // simpler to just take lists of the keys and value and then to recombine when de-serialising
     serializer.Serialize(
         writer,
         new SerialisableData <TValue>
     {
         NormalisedKeysWithValues = value.GetAllNormalisedKeys().Zip(
             value.GetAllValues(),
             (normalisedKey, matches) => new KeyValuePair <string, TValue>(normalisedKey, matches)
             ),
         KeyNormaliser = value.KeyNormaliser
     }
         );
 }