Ejemplo n.º 1
0
        public static List <string> OrderBy(List <string> source, OrderBy orders)
        {
            if (source.Count == 1 || orders.GetVariables().Count == 0)
            {
                return(source);
            }

            OrderByStruct first = orders.GetVariables()[0];

            List <string> orderedByFirstVar = OrderBySingleVariable(source, first);

            if (orders.GetVariables().Count == 0)
            {
                return(orderedByFirstVar);
            }
            else
            {
                List <string> result    = new List <string>();
                List <string> temporary = new List <string> {
                    orderedByFirstVar[0]
                };

                for (int i = 1; i < orderedByFirstVar.Count; i++)
                {
                    if (OrderByComparator.Equals(orderedByFirstVar[i - 1], orderedByFirstVar[i], first))
                    {
                        temporary.Add(orderedByFirstVar[i]);
                    }
                    else
                    {
                        if (temporary.Count == 1)
                        {
                            result.Add(temporary[0]);
                        }
                        else
                        {
                            result.AddRange(OrderBy(temporary, orders.CopyWithoutFirstVariable()));
                        }

                        temporary.Clear();
                        temporary.Add(orderedByFirstVar[i]);
                    }
                }
                if (temporary.Count == 1)
                {
                    result.Add(temporary[0]);
                }
                else
                {
                    result.AddRange(OrderBy(temporary, orders.CopyWithoutFirstVariable()));
                }


                return(result);
            }
        }
Ejemplo n.º 2
0
        public static List <string> OrderBySingleVariable(List <string> source, OrderByStruct order)
        {
            switch (order.GetVariable())
            {
            case OrderByVariable.Empty:
                source = source.OrderBy(s => FileInnerVariable.Empty(s)).ToList();
                break;

            case OrderByVariable.Exist:
                source = source.OrderBy(s => FileInnerVariable.Exist(s)).ToList();
                break;

            case OrderByVariable.Extension:
                source = source.OrderBy(s => FileInnerVariable.GetExtension(s)).ToList();
                break;

            case OrderByVariable.Fullname:
                source = source.OrderBy(s => FileInnerVariable.GetFullname(s)).ToList();
                break;

            case OrderByVariable.Name:
                source = source.OrderBy(s => FileInnerVariable.GetName(s)).ToList();
                break;

            case OrderByVariable.Size:
                source = source.OrderBy(s => FileInnerVariable.GetSize(s)).ToList();
                break;

            case OrderByVariable.IsCorrect:
                source = source.OrderBy(s => FileValidator.IsNameCorrect(s)).ToList();
                break;

            case OrderByVariable.IsDirectory:
                source = source.OrderBy(s => FileValidator.IsDirectory(s)).ToList();
                break;

            case OrderByVariable.IsFile:
                source = source.OrderBy(s => !FileValidator.IsDirectory(s)).ToList();
                break;

            case OrderByVariable.Access:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetAccess(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetAccess(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetAccess(s)).ToList();
                }
                break;
            }

            case OrderByVariable.Creation:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetCreation(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetCreation(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetCreation(s)).ToList();
                }
                break;
            }

            case OrderByVariable.Modification:
            {
                if (order is OrderByStructTime)
                {
                    source = source.OrderBy(s => DateExtractor.GetVariable(FileInnerVariable.GetModification(s),
                                                                           (order as OrderByStructTime).GetTimeVariable())).ToList();
                }
                else if (order is OrderByStructDate)
                {
                    source = source.OrderBy(s => DateExtractor.DateToInt(FileInnerVariable.GetModification(s))).ToList();
                }
                else if (order is OrderByStructClock)
                {
                    source = source.OrderBy(s => DateExtractor.ClockToInt(FileInnerVariable.GetModification(s))).ToList();
                }
                else
                {
                    source = source.OrderBy(s => FileInnerVariable.GetModification(s)).ToList();
                }
                break;
            }
            }

            if (order.GetOrderType().Equals(OrderByType.DESC))
            {
                source.Reverse();
            }

            return(source);
        }
Ejemplo n.º 3
0
        public static bool Equals(string s1, string s2, OrderByStruct order)
        {
            switch (order.GetVariable())
            {
            case OrderByVariable.Empty:
                return(FileInnerVariable.Empty(s1).Equals(FileInnerVariable.Empty(s2)));

            case OrderByVariable.Exist:
                return(FileInnerVariable.Exist(s1).Equals(FileInnerVariable.Exist(s2)));

            case OrderByVariable.Extension:
                return(FileInnerVariable.GetExtension(s1).Equals(FileInnerVariable.GetExtension(s2)));

            case OrderByVariable.Fullname:
                return(FileInnerVariable.GetFullname(s1).Equals(FileInnerVariable.GetFullname(s2)));

            case OrderByVariable.Name:
                return(FileInnerVariable.GetName(s1).Equals(FileInnerVariable.GetName(s2)));

            case OrderByVariable.Size:
                return(FileInnerVariable.GetSize(s1).Equals(FileInnerVariable.GetSize(s2)));

            case OrderByVariable.IsCorrect:
                return(FileValidator.IsNameCorrect(s1).Equals(FileValidator.IsNameCorrect(s2)));

            case OrderByVariable.IsDirectory:
                return(FileValidator.IsDirectory(s1).Equals(FileValidator.IsDirectory(s2)));

            case OrderByVariable.IsFile:
                return(FileValidator.IsDirectory(s1).Equals(FileValidator.IsDirectory(s2)));

            case OrderByVariable.Access:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetAccess(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetAccess(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetAccess(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetAccess(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetAccess(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetAccess(s1).Equals(FileInnerVariable.GetAccess(s2)));
                }
            }

            case OrderByVariable.Creation:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetCreation(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetCreation(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetCreation(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetCreation(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetCreation(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetCreation(s1).Equals(FileInnerVariable.GetCreation(s2)));
                }
            }

            case OrderByVariable.Modification:
            {
                if (order is OrderByStructTime)
                {
                    return(DateExtractor.GetVariable(FileInnerVariable.GetModification(s1), (order as OrderByStructTime).GetTimeVariable()) ==
                           DateExtractor.GetVariable(FileInnerVariable.GetModification(s2), (order as OrderByStructTime).GetTimeVariable()));
                }
                else if (order is OrderByStructDate)
                {
                    return(DateExtractor.DateToInt(FileInnerVariable.GetModification(s1)).Equals(
                               DateExtractor.DateToInt(FileInnerVariable.GetModification(s2))));
                }
                else if (order is OrderByStructClock)
                {
                    return(DateExtractor.ClockToInt(FileInnerVariable.GetModification(s1)).Equals(
                               DateExtractor.ClockToInt(FileInnerVariable.GetModification(s2))));
                }
                else
                {
                    return(FileInnerVariable.GetModification(s1).Equals(FileInnerVariable.GetModification(s2)));
                }
            }
            }
            return(false);
        }