private void mergeEqualRows() { List<RatingsTableRow> newList = new List<RatingsTableRow>(); RatingsTableRow row = new RatingsTableRow(rows[0]); int count = 1; for (int i = 1; i < rows.Count; i++) { if (rows[i].CompareTo(rows[i - 1]) == 0) { row.Rank += rows[i].Rank; row.Votes += rows[i].Votes; count++; } else { row.Rank = Math.Round(row.Rank / count, 1); newList.Add(row); row = new RatingsTableRow(rows[i]); count = 1; } } row.Rank = Math.Round(row.Rank / count, 1); newList.Add(row); rows = newList; }
private RatingsTableRow regexRaiting(String line) { if (line == "") throw new NotAFilmException(); String result = line.Trim(); Regex rgx = new Regex(@"\s\s+"); RatingsTableRow rait = new RatingsTableRow(); int votes = 0; double rank = 0; int year = 0; string[] array = rgx.Split(result); if (array.Length != 4) throw new NotAFilmException(); int.TryParse(array[1], out votes); rait.Votes = votes; double.TryParse(array[2].Replace('.', ','), out rank); rait.Rank = rank; result = array[3].Trim();//String.Join(" ", array, 3, array.Length - 3).Trim(); rgx = new Regex(@"\s+\([1-2]\d{3}[\)\\\/]"); // " (1111) " array = rgx.Split(result); rait.FilmTitle = array[0].Trim(); var k = rgx.Matches(result); if (k.Count > 0) { String temp = k[0].Value.Trim(); temp = temp.Substring(1, 4); //temp = temp.Replace("(","").Replace(")", ""); int.TryParse(temp, out year); rait.Year = year; } if (year == 0) throw new NotAFilmException(); return rait; }