public static CommonTable Create(string name, CommonHeading heading) { return(new CommonTable { TableName = name, Heading = heading }); }
public CommonHeading Adapt(string[] newheading) { var fields = newheading.Select(name => { var field = Fields.FirstOrDefault(f => f.Name == name); return((field.CType == CommonType.None) ? new CommonField(name, CommonType.None) : field); }); return(CommonHeading.Create(fields)); }
// Create map using old rename method public int[] CreateMapRename(CommonHeading other, bool dorename = false) { // a queue of indexes to new fields in other var q = new Queue <int>(Enumerable.Range(0, other.Degree) .Where(x => !Fields.Any(f => f.Name == other.Fields[x].Name))); return(Fields.Select(f => { var x = Array.FindIndex(other.Fields, o => f.Name == o.Name); // equals? return (dorename && x == -1 && q.Count > 0) ? q.Dequeue() : x; }).ToArray()); }
public static CommonTable Create(string name, CommonField[] fields) { return(Create(name, CommonHeading.Create(fields))); }
// Create a map from other to this public int[] CreateMap(CommonHeading other) { return(Enumerable.Range(0, Fields.Length) .Select(x => Array.FindIndex(other.Fields, f => f.Name == Fields[x].Name)) // equals? .ToArray()); }
// create a heading minus one field public CommonHeading Remove(CommonField field) { return(CommonHeading.Create(Fields.Where(f => f.Name != field.Name))); }
public CommonHeading Append(IEnumerable <CommonField> fields) { return(CommonHeading.Create(Fields.Concat(fields))); }
// create a heading plus one field public CommonHeading Append(CommonField field) { return(CommonHeading.Create(Fields.Append(field))); }
// create a heading as this minus other public CommonHeading Minus(CommonHeading other) { var fields = Fields.Where(f => !other.Fields.Any(o => f.Name == o.Name)); return(CommonHeading.Create(fields)); }
// create a heading as the intersection of this and other public CommonHeading Intersect(CommonHeading other) { var fields = Fields.Where(f => other.Fields.Any(o => f.Name == o.Name)); return(CommonHeading.Create(fields)); }
// create a heading as the union of this and other public CommonHeading Union(CommonHeading other) { var fields = Fields.Concat(other.Fields.Where(f => !Fields.Any(o => f.Name == o.Name))); return(CommonHeading.Create(fields)); }
// rename a field from old to new public CommonHeading Rename(CommonField field1, CommonField field2) { var fields = Fields.Select(f => (f.Name == field1.Name) ? new CommonField(field2.Name, f.CType) : f); return(CommonHeading.Create(fields)); }
// Compares structural equality public bool IsCompatible(CommonHeading other) { return(other != null && Degree == other.Degree && Fields.All(f => other.Fields.Contains(f))); }
// Compares equality but does not implement Equals() public bool IsEqual(CommonHeading other) { return(other != null && Fields.SequenceEqual(other.Fields)); //return other != null && Degree == other.Degree && Fields.SequenceEqual(other.Fields); }