public void CanGetMostFrequentValue() { var distinctValues = new DistinctValues <string>(); distinctValues.Add("a"); distinctValues.Add("a"); distinctValues.Add("a"); distinctValues.Add("b"); distinctValues.Add(null); string value; int count; Assert.AreEqual(1, distinctValues.NullCount); Assert.IsTrue(distinctValues.TryGetMostFrequentValue(out value, out count)); Assert.AreEqual("a", value); Assert.AreEqual(3, count); }
private static void FindDuplicates() { Debug.Assert(DistinctValues.Count == 0); for (var index = 0; index < Arrays.Count; index++) { var generationCount = GenerationCounts[index]; IdCount += generationCount; var array = Arrays[index]; for (var i = 0; i < generationCount; i++) { if (!DistinctValues.Add(array[i])) { Collisions.Add(array[i]); } } } DistinctValues.Clear(); }
public void CanUnion() { var dv1 = new DistinctValues <string>(); dv1.Add("a"); dv1.Add("a"); dv1.Add("a"); dv1.Add("b"); dv1.Add(null); dv1.Add(null); dv1.Add(null); dv1.Add(null); var dv2 = new DistinctValues <string>(); dv2.Add("a"); dv2.Add("b"); dv2.Add("b"); dv2.Add("b"); dv2.Add("b"); dv2.Add("c"); dv2.Add(null); dv1.Union(dv2); Assert.AreEqual(5, dv1.NullCount); string value; int count; Assert.IsTrue(dv1.TryGetMostFrequentValue(out value, out count)); Assert.AreEqual("b", value); Assert.AreEqual(5, count); var list = new List <DistinctValue <string> >(dv1.Values); Assert.AreEqual(3, list.Count); }
private static bool ImportException( [NotNull] IRow row, [NotNull] string importOriginValue, DateTime importDate, [NotNull] ExceptionObjectFactory factory, [NotNull] IDictionary <Guid, QualityConditionExceptions> targetExceptionsByConditionVersion, [NotNull] IDictionary <esriGeometryType, HashSet <int> > replacedExceptionObjects, [NotNull] ExceptionWriter writer, out int matchCount) { ExceptionObject exceptionObject = factory.CreateExceptionObject(row); matchCount = 0; // import only active exceptions if (exceptionObject.Status != ExceptionObjectStatus.Active) { return(false); } var matchingLineageUuids = new DistinctValues <Guid>(); var origins = new HashSet <string>(StringComparer.OrdinalIgnoreCase) { importOriginValue }; foreach (ExceptionObject matchingExceptionObject in GetMatchingExceptionObjects( targetExceptionsByConditionVersion, exceptionObject)) { // add to Uuids of matching exceptions (usually, should be unique) if (matchingExceptionObject.ManagedLineageUuid != null) { // also if matching exception is inactive // --> lineage of inactive exceptions may be continued (resurrection of inactive exceptions) matchingLineageUuids.Add(matchingExceptionObject.ManagedLineageUuid.Value); // NOTE: consider *preferring* active exceptions, only if none: resurrect inactive exception lineage } // include the origin values of active replaced exceptions // Note: not for resurrected exceptions (inactive/with end date -> active) if (matchingExceptionObject.ManagedVersionEndDate == null) { foreach (string replacedOrigin in ExceptionObjectUtils.ParseOrigins(matchingExceptionObject.ManagedOrigin)) { origins.Add(replacedOrigin); } } matchCount++; AddToReplacedExceptionObjects(matchingExceptionObject, replacedExceptionObjects); } writer.Write(row, importDate, ExceptionObjectUtils.FormatOrigins(origins), GetLineageUuid(matchingLineageUuids), versionOriginValue: importOriginValue, statusValue: "Active"); return(true); }