public int CompareTo(object obj)
        {
            TaxiPath taxiPath = obj as TaxiPath;

            if (taxiPath == null)
            {
                return(-1);
            }
            if (this.TaxiId > taxiPath.TaxiId)
            {
                return((int)((int)TaxiId - taxiPath.TaxiId));
            }
            if (this.TaxiId == taxiPath.TaxiId)
            {
                return(0);
            }
            return(-1);
        }
        public override void Run(object[] args)
        {
            //1.获取所有记录
            this.Init(args);
            string[] lines = ReadAllText("taxi.data", false);
            WriteToConsole("Total lines count:" + lines.Count());

            //2.分别分析
            List <TaxiPath> taxiPaths    = new List <TaxiPath>();
            long            maxErrorLine = 100;

            foreach (var line in lines)
            {
                if (maxErrorLine < 1)
                {
                    WriteToConsole("Too many error lines, app has exit.");
                    break;
                }
                string[] columns = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (columns.Length == 9)
                {
                    long     taxiId    = long.Parse(columns[0]);
                    long     time      = long.Parse(columns[3]);
                    double   locationX = double.Parse(columns[4]);
                    double   locationY = double.Parse(columns[5]);
                    TaxiPath taxiPath  = new TaxiPath(taxiId, time, locationX, locationY);
                    taxiPaths.Add(taxiPath);
                }
                else
                {
                    maxErrorLine--;
                }
            }
            taxiPaths.Sort();
            WriteList(taxiPaths, "taxi.path", false);
            WriteToConsole("Finished.");
        }
Beispiel #3
0
        public override void Run(object[] args)
        {
            //1.获取所有记录
            this.Init(args);
            string[] lines = ReadAllText("taxi.data", false);
            WriteToConsole("Total lines count:" + lines.Count());

            //2.分别分析
            List<TaxiPath> taxiPaths = new List<TaxiPath>();
            long maxErrorLine = 100;
            foreach (var line in lines)
            {
                if (maxErrorLine < 1)
                {
                    WriteToConsole("Too many error lines, app has exit.");
                    break;
                }
                string[] columns = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (columns.Length == 9)
                {
                    long taxiId = long.Parse(columns[0]);
                    long time = long.Parse(columns[3]);
                    double locationX = double.Parse(columns[4]);
                    double locationY = double.Parse(columns[5]);
                    TaxiPath taxiPath = new TaxiPath(taxiId, time, locationX, locationY);
                    taxiPaths.Add(taxiPath);
                }
                else
                {
                    maxErrorLine--;
                }
            }
            taxiPaths.Sort();
            WriteList(taxiPaths, "taxi.path", false);
            WriteToConsole("Finished.");
        }