Ejemplo n.º 1
0
 public static CommonTable Create(string name, CommonHeading heading)
 {
     return(new CommonTable {
         TableName = name,
         Heading = heading
     });
 }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        // 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());
        }
Ejemplo n.º 4
0
 public static CommonTable Create(string name, CommonField[] fields)
 {
     return(Create(name, CommonHeading.Create(fields)));
 }
Ejemplo n.º 5
0
 // 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());
 }
Ejemplo n.º 6
0
 // create a heading minus one field
 public CommonHeading Remove(CommonField field)
 {
     return(CommonHeading.Create(Fields.Where(f => f.Name != field.Name)));
 }
Ejemplo n.º 7
0
 public CommonHeading Append(IEnumerable <CommonField> fields)
 {
     return(CommonHeading.Create(Fields.Concat(fields)));
 }
Ejemplo n.º 8
0
 // create a heading plus one field
 public CommonHeading Append(CommonField field)
 {
     return(CommonHeading.Create(Fields.Append(field)));
 }
Ejemplo n.º 9
0
        // 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));
        }
Ejemplo n.º 10
0
        // 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));
        }
Ejemplo n.º 11
0
        // 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));
        }
Ejemplo n.º 12
0
        // 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));
        }
Ejemplo n.º 13
0
 // Compares structural equality
 public bool IsCompatible(CommonHeading other)
 {
     return(other != null && Degree == other.Degree && Fields.All(f => other.Fields.Contains(f)));
 }
Ejemplo n.º 14
0
 // 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);
 }