refactor: Make IBlueRowCollection inherit IList<IBlueRow>

This commit is contained in:
John Colvin committed 2025-11-15 12:38:51 -05:00
1 parent 144b29c728
commit d2a1b67717
39 files changed
+1035 -439

No files matched your search

@@ -1,12 +1,10 @@
using Spark.Core.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using BCG.Utilities.General;
using Bts.DataStreamCore;
namespace BCG {
[Serializable]
public class DataPacket : ICloneable, IDataPacket {
@@ -45,7 +43,11 @@ namespace BCG {
public IBlueRowCollection newRows, addedRows, deletedRows;
public Dictionary<string, object> meta_data = null;
public DataPacket() { }
public DataPacket(IBlueRowCollection newRows, IBlueRowCollection addedRows, IBlueRowCollection deletedRows) {
public DataPacket(IBlueTableSchema schema)
: this(new BlueTable(schema), new BlueTable(schema), new BlueTable(schema)) { }
public DataPacket (IBlueRowCollection newRows, IBlueRowCollection addedRows, IBlueRowCollection deletedRows) {
this.newRows = newRows;
this.addedRows = addedRows;
this.deletedRows = deletedRows;
@@ -57,9 +59,9 @@ namespace BCG {
IReadOnlyDictionary<string, object> IDataPacket.Metadata => meta_data;
public void get_new_added_deleted(out ICollection new_rows, out ICollection added_rows, out ICollection deleted_rows) {
new_rows = newRows;
added_rows = addedRows;
deleted_rows = deletedRows;
new_rows = ListNonGenericCollectionWrapper.Create(newRows);
added_rows = ListNonGenericCollectionWrapper.Create(addedRows);
deleted_rows = ListNonGenericCollectionWrapper.Create(deletedRows);
}
public IBlueRowCollection getTrulyAddedRows(params string[] idColumns) {
@@ -69,7 +71,9 @@ namespace BCG {
CollectionHelpers.EqualDelegate ed =
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
ICollection ta = CollectionHelpers.difference(addedRows, deletedRows, ed);
var addedRowCollection = ListNonGenericCollectionWrapper.Create(addedRows);
var deletedRowCollection = ListNonGenericCollectionWrapper.Create(deletedRows);
ICollection ta = CollectionHelpers.difference(addedRowCollection, deletedRowCollection, ed);
foreach (IBlueRow r in ta) {
truly.addRow(r);
@@ -111,7 +115,9 @@ namespace BCG {
CollectionHelpers.EqualDelegate ed =
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
ICollection td = CollectionHelpers.difference(deletedRows, addedRows, ed);
var addedRowCollection = ListNonGenericCollectionWrapper.Create(addedRows);
var deletedRowCollection = ListNonGenericCollectionWrapper.Create(deletedRows);
ICollection td = CollectionHelpers.difference(deletedRowCollection, addedRowCollection, ed);
foreach (IBlueRow r in td) {
truly.addRow(r);
@@ -128,8 +134,10 @@ namespace BCG {
CollectionHelpers.EqualDelegate ed =
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
ICollection ta = CollectionHelpers.difference(addedRows, deletedRows, ed);
ICollection tc = CollectionHelpers.difference(addedRows, ta, ed);
var addedRowCollection = ListNonGenericCollectionWrapper.Create(addedRows);
var deletedRowCollection = ListNonGenericCollectionWrapper.Create(deletedRows);
ICollection ta = CollectionHelpers.difference(addedRowCollection, deletedRowCollection, ed);
ICollection tc = CollectionHelpers.difference(addedRowCollection, ta, ed);
foreach (IBlueRow r in tc) {
truly.addRow(r);
@@ -145,8 +153,10 @@ namespace BCG {
CollectionHelpers.EqualDelegate ed =
new CollectionHelpers.EqualDelegate(c.blueRowIdEqualEvaluator);
ICollection td = CollectionHelpers.difference(deletedRows, addedRows, ed);
ICollection tco = CollectionHelpers.difference(deletedRows, td, ed);
var deletedRowCollection = ListNonGenericCollectionWrapper.Create(deletedRows);
var addedRowCollection = ListNonGenericCollectionWrapper.Create(addedRows);
ICollection td = CollectionHelpers.difference(deletedRowCollection, addedRowCollection, ed);
ICollection tco = CollectionHelpers.difference(deletedRowCollection, td, ed);
foreach (IBlueRow r in tco) {
truly.addRow(r);
@@ -223,13 +233,15 @@ namespace BCG {
}
deleted.AddRange(oldDeleted);
var deletedRowCollection = ListNonGenericCollectionWrapper.Create(dp.deletedRows);
deleted.AddRange(CollectionHelpers.difference(
CollectionHelpers.difference(dp.deletedRows, oldAdded, ed),
CollectionHelpers.difference(deletedRowCollection, oldAdded, ed),
oldDeleted, ed));
added.AddRange(dp.addedRows);
var addedRowCollection = ListNonGenericCollectionWrapper.Create(dp.addedRows);
added.AddRange(addedRowCollection);
added.AddRange(CollectionHelpers.difference(
CollectionHelpers.difference(oldAdded, dp.deletedRows, ed),
CollectionHelpers.difference(oldAdded, deletedRowCollection, ed),
added, ed));
nt = dp.newRows;
}
@@ -287,30 +299,30 @@ namespace BCG {
}
}
public class DataPacket<T> : IDataPacket<T> where T : IBlueRow {
public DataPacket(
IBlueRowCollection<T> newRows,
IBlueRowCollection<T> addedRows,
IBlueRowCollection<T> deletedRows,
IReadOnlyDictionary<string, object> metadata = null
) {
this.newRows = newRows;
this.addedRows = addedRows;
this.deletedRows = deletedRows;
Metadata = metadata ?? DictionaryHelper.empty<string, object>();
}
// public class DataPacket<T> : IDataPacket<T> where T : IBlueRow {
// public DataPacket(
// IBlueRowCollection<T> newRows,
// IBlueRowCollection<T> addedRows,
// IBlueRowCollection<T> deletedRows,
// IReadOnlyDictionary<string, object> metadata = null
// ) {
// this.newRows = newRows;
// this.addedRows = addedRows;
// this.deletedRows = deletedRows;
// Metadata = metadata ?? DictionaryHelper.empty<string, object>();
// }
public IBlueRowCollection<T> newRows { get; }
public IBlueRowCollection<T> addedRows { get; }
public IBlueRowCollection<T> deletedRows { get; }
public IReadOnlyDictionary<string, object> Metadata { get; }
// public IBlueRowCollection<T> newRows { get; }
// public IBlueRowCollection<T> addedRows { get; }
// public IBlueRowCollection<T> deletedRows { get; }
// public IReadOnlyDictionary<string, object> Metadata { get; }
public static DataPacket<T> Empty(IBlueTableSchema schema) =>
new(
new BlueTableImmutable<T>(schema),
new BlueTableImmutable<T>(schema),
new BlueTableImmutable<T>(schema));
}
// public static DataPacket<T> Empty(IBlueTableSchema schema) =>
// new(
// new BlueTableImmutable<T>(schema),
// new BlueTableImmutable<T>(schema),
// new BlueTableImmutable<T>(schema));
// }
public static class DataPacketExtensions {
public static bool HasChanges(this DataPacket dataPacket) =>