Пример #1
0
 public static CommonTable Create(string name, CommonHeading heading)
 {
     return(new CommonTable {
         TableName = name,
         Heading = heading
     });
 }
Пример #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));
        }
Пример #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());
        }
Пример #4
0
 public static CommonTable Create(string name, CommonField[] fields)
 {
     return(Create(name, CommonHeading.Create(fields)));
 }
Пример #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());
 }
Пример #6
0
 // create a heading minus one field
 public CommonHeading Remove(CommonField field)
 {
     return(CommonHeading.Create(Fields.Where(f => f.Name != field.Name)));
 }
Пример #7
0
 public CommonHeading Append(IEnumerable <CommonField> fields)
 {
     return(CommonHeading.Create(Fields.Concat(fields)));
 }
Пример #8
0
 // create a heading plus one field
 public CommonHeading Append(CommonField field)
 {
     return(CommonHeading.Create(Fields.Append(field)));
 }
Пример #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));
        }
Пример #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));
        }
Пример #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));
        }
Пример #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));
        }
Пример #13
0
 // Compares structural equality
 public bool IsCompatible(CommonHeading other)
 {
     return(other != null && Degree == other.Degree && Fields.All(f => other.Fields.Contains(f)));
 }
Пример #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);
 }