Example #1
0
        public void IColumnExtensions_FindComponent()
        {
            IColumn <object> column = ColumnFactory.Build(new ColumnDetails("sample", "string", null), 0);

            Assert.IsNotNull(column.FindComponent <IndexedColumn>());
            Assert.IsNotNull(column.FindComponent <UntypedColumn <ByteBlock> >());
            Assert.IsNotNull(column.FindComponent <ByteBlockColumn>());
            Assert.IsNotNull(column.FindComponent <SortedColumn <ByteBlock> >());
            Assert.IsNull(column.FindComponent <ValueTypeColumn <int> >());

            IColumn c2 = new ValueTypeColumn <short>(short.MinValue);

            Assert.IsNull(c2.FindComponent <SortedColumn <short> >());
            Assert.IsNotNull(c2.FindComponent <ValueTypeColumn <short> >());
        }
Example #2
0
        private static IUntypedColumn Build <T>(ColumnDetails details, string[] typeComponents, ushort initialCapacity) where T : struct, IComparable <T>, IEquatable <T>
        {
            // Convert the default for the new column
            Value defaultValue = Value.Create(details.Default);
            T     dAsT;

            if (!defaultValue.TryConvert <T>(out dAsT))
            {
                dAsT = default(T);
            }

            // Build the raw column
            IColumn <T> columnSoFar = new ValueTypeColumn <T>(dAsT, initialCapacity);

            // Wrap the column as requested (the last component is the type itself)
            for (int i = typeComponents.Length - 2; i >= 0; --i)
            {
                switch (typeComponents[i])
                {
                case "sorted":
                    columnSoFar = CreateSortedColumn(columnSoFar, initialCapacity);
                    break;

                default:
                    throw new ArribaException(StringExtensions.Format("Column Type Wrapper '{0}' is not currently supported.", typeComponents[i]));
                }
            }

            // De-type the column for generic use
            var utc = new UntypedColumn <T>(columnSoFar);

            // Tell it the column name
            utc.Name = details.Name;

            return(utc);
        }