Files
spark/src/DataStreamSuite/DataStream/Primitives/LightJoinStreams/LightForeignJoinSimpleCollection.cs
T

99 lines
2.7 KiB
C#

using bts.collections;
using Bts.DataStreamCore;
using System;
using System.Collections;
using System.Collections.Generic;
namespace BCG
{
/// <summary>
/// A simple implementation of IBlueRowCollection which allows for the ImmutableBlueTable to contruct
/// itself from iterating through this class. The property 'schema' and the GetEnumerator are the
/// only 2 members that need implementation. This collection is used for the addedRows and deletedRows
/// </summary>
public class LightForeignJoinSimpleCollection : IBlueRowCollection
{
private IBlueTableSchema mySchema;
private ArrayList myRows = new ArrayList ();
public LightForeignJoinSimpleCollection (IBlueTableSchema schema) {mySchema = schema;}
public LightForeignJoinSimpleCollection (IBlueRowCollection rows)
: this (rows.schema)
{
foreach (IBlueRow r in rows)
addRow (r);
}
public void addRow (IBlueRow r)
{
myRows.Add (r);
}
public void addRow (IBlueRowCollection rs)
{
foreach (IBlueRow r in rs)
addRow (r);
}
#region IBlueRowCollection Members
public IBlueRow this[int id] {get{throw new NotSupportedException ("");}}
public bool containsID (int id) {throw new NotSupportedException ("");}
public IList<object?> GetColumn(int index) =>
index < 0 || index >= schema.columnInfo.Length
? throw new IndexOutOfRangeException()
: myRows.WrapType<IBlueRow>().WrapSelector(r => r[index], null);
public IBlueRow GetRow(int index) {
var rowObj = myRows[index];
ArgumentNullException.ThrowIfNull(rowObj);
return (IBlueRow)rowObj;
}
public IBlueTableSchema schema {get {return mySchema;}}
#endregion
#region ICollection Members
public bool IsSynchronized {get {return false;}}
public int Count {get {return myRows.Count;}}
public void CopyTo (Array array, int index) {throw new NotSupportedException ("");}
public object SyncRoot {get{return null;}}
public int IndexOf(IBlueRow item) {
int id = item.Id();
for (int i = 0; i < myRows.Count; i++) {
if (myRows[i] is not IBlueRow r || r.Id() != id) {
continue;
}
if (BlueRowEqualityComparer.Equals(item, r)) {
return i;
}
break;
}
return -1;
}
#endregion
#region IEnumerable Members
public IEnumerator<IBlueRow> GetEnumerator() {
foreach (IBlueRow r in myRows) {
yield return r;
}
}
#endregion
}
}