78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
|
using BCG.Utilities;
|
|
using System.Collections;
|
|
|
|
namespace BCG
|
|
{
|
|
/// <summary>
|
|
/// GroupByOutputTable offers a conveniant way to manage a table, where theres one row per hash
|
|
/// </summary>
|
|
public class GroupByOutputTable : IBlueRowCollection
|
|
{
|
|
private IDictionary myDict = new Hashtable ();
|
|
private BlueTable myTable;
|
|
|
|
public GroupByOutputTable (IBlueTableSchema schema) {myTable = new BlueTable (schema);}
|
|
|
|
/// <summary>
|
|
/// Adds a row to table, with the hash string defined in the second arg. If theres a row
|
|
/// already with the hash code, its replaced (always one row per group)
|
|
/// </summary>
|
|
/// <param name="row"></param>
|
|
/// <param name="groupRepString"></param>
|
|
public void addRow (IBlueRow row, string groupRepString)
|
|
{
|
|
if (myDict[groupRepString] != null)
|
|
myTable.deleteRow ((IBlueRow)myDict[groupRepString]);
|
|
myTable.addRow (row);
|
|
myDict[groupRepString] = myTable[(int)row["id"]];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes the row present in the hash slot defined by the arg
|
|
/// </summary>
|
|
/// <param name="groupRepString"></param>
|
|
public void removeRow (string groupRepString)
|
|
{
|
|
// BlueEventLog.logAssert (myDict[groupRepString] != null);
|
|
myTable.deleteRow ((IBlueRow)myDict[groupRepString]);
|
|
myDict.Remove (groupRepString);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Removes all rows from the table, the schema is retained.
|
|
/// </summary>
|
|
public void clear ()
|
|
{
|
|
myTable.clear ();
|
|
myDict.Clear ();
|
|
}
|
|
|
|
public IBlueRow getRow (string groupRepString)
|
|
{
|
|
return myDict[groupRepString] == null ? null :
|
|
myDict[groupRepString] as IBlueRow;
|
|
}
|
|
|
|
#region IBlueRowCollection members
|
|
public IBlueRow this[int id] {get{return myTable[id];}}
|
|
public IBlueTableSchema schema {get{return myTable.schema;}}
|
|
public bool containsID (int id) {return myTable.containsID (id);}
|
|
|
|
#endregion
|
|
|
|
#region ICollection members
|
|
public int Count {get{return myTable.Count;}}
|
|
public bool IsSynchronized {get{return false;}}
|
|
public object SyncRoot {get{return this;}}
|
|
public void CopyTo (Array array, int index) {myTable.CopyTo (array, index);}
|
|
#endregion
|
|
|
|
#region IEnumerable members
|
|
public IEnumerator GetEnumerator() {return myTable.GetEnumerator ();}
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|