public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Company other = obj as Company; if (this.Segment.CompareTo(other.Segment) > 0) { return(1); } else if (this.Segment.CompareTo(other.Segment) < 0) { return(-1); } else { if (this.Location.CompareTo(other.Location) > 0) { return(1); } else if (this.Location.CompareTo(other.Location) < 0) { return(-1); } else { return(this.Name.CompareTo(other.Name)); } } }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Animal other = obj as Animal; if (this.Species.CompareTo(other.Species) > 0) { return(1); } else if (this.Species.CompareTo(other.Species) < 0) { return(-1); } else { if (this.Location.CompareTo(other.Location) > 0) { return(1); } else if (this.Location.CompareTo(other.Location) < 0) { return(-1); } else { return(this.Name.CompareTo(other.Name)); } } }
private static void Quicksort(IParsee[] source, int left, int right) { int i = left, j = right; IParsee pivot = source[(left + right) / 2]; while (i <= j) { while (source[i].CompareTo(pivot) < 0) { i++; } while (source[j].CompareTo(pivot) > 0) { j--; } if (i <= j) { IParsee tmp = source[i]; source[i] = source[j]; source[j] = tmp; i++; j--; } } if (left < j) { Quicksort(source, left, j); } if (i < right) { Quicksort(source, i, right); } }
public static List <IParsee> ParseAll(String input, Extract[] parsers) { int count = 0; IParsee[][] alloc = new IParsee[parsers.Length][]; for (int i = 0; i < parsers.Length; i++) { if (parsers[i](input) != null) { alloc[i] = parsers[i](input); count += alloc[i].Length; } } List <IParsee> res = new List <IParsee>(); for (int i = 0; i < parsers.Length; i++) { if (alloc[i] != null) { res.AddRange(alloc[i]); count -= alloc[i].Length; } } return(res); }
//only for sorted arrays (by type) private static IParsee[][] SplitByType(IParsee[] source) { int count = 0; Type t = null; foreach (IParsee obj in source) { if (obj.GetType() != t) { count++; t = obj.GetType(); } } IParsee[][] res = new IParsee[count][]; int currTypeStart = 0, currTypeNumb = 0; t = source[0].GetType(); for (int i = 0; i < source.Length; i++) { if (source[i].GetType() != t) { res[currTypeNumb] = new IParsee[i - currTypeStart]; Array.Copy(source, currTypeStart, res[currTypeNumb], 0, i - currTypeStart); currTypeStart = i; currTypeNumb++; t = source[i].GetType(); } } res[currTypeNumb] = new IParsee[source.Length - currTypeStart]; Array.Copy(source, currTypeStart, res[currTypeNumb], 0, source.Length - currTypeStart); return(res); }
//only for arrays of single type private static IParsee[] RemoveDuplicatesOneType(IParsee[] source) { IParsee[] newsource = new IParsee[source.Length]; Quicksort(source, 0, source.Length - 1); int i = 0, j = 0, count = 0; while (i < source.Length - 1) { if (source[i].CompareTo(source[i + 1]) == 0) { newsource[i - count] = source[i]; j = i; i++; while (i < source.Length && source[j].CompareTo(source[i]) == 0) { i++; count++; } } else { newsource[i - count] = source[i]; i++; } } if (i == source.Length - 1) { newsource[i - count] = source[i]; } IParsee[] resArray = new IParsee[source.Length - count]; Array.Copy(newsource, 0, resArray, 0, source.Length - count); return(resArray); }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Bicycle other = obj as Bicycle; if (this.Manufacturer.CompareTo(other.Manufacturer) > 0) { return(1); } else if (this.Manufacturer.CompareTo(other.Manufacturer) < 0) { return(-1); } else { if (this.Model.CompareTo(other.Model) > 0) { return(1); } else if (this.Model.CompareTo(other.Model) < 0) { return(-1); } else { return(this.Owner.CompareTo(other.Owner)); } } }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Plant other = obj as Plant; if (this.Name.CompareTo(other.Name) > 0) { return(1); } else if (this.Name.CompareTo(other.Name) < 0) { return(-1); } else { if (this.Type.CompareTo(other.Type) > 0) { return(1); } else if (this.Type.CompareTo(other.Type) < 0) { return(-1); } else { if (this.Location.CompareTo(other.Location) > 0) { return(1); } else if (this.Location.CompareTo(other.Location) < 0) { return(-1); } else { return(this.Height.CompareTo(other.Height)); } } } }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Newspaper other = obj as Newspaper; if (this.Name.CompareTo(other.Name) > 0) { return(1); } else if (this.Name.CompareTo(other.Name) < 0) { return(-1); } else { if (this.Country.CompareTo(other.Country) > 0) { return(1); } else if (this.Country.CompareTo(other.Country) < 0) { return(-1); } else { if (this.Frequency.CompareTo(other.Frequency) > 0) { return(1); } else if (this.Frequency.CompareTo(other.Frequency) < 0) { return(-1); } else { return(this.Subject.CompareTo(other.Subject)); } } } }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Car other = obj as Car; if (this.Manufacturer.CompareTo(other.Manufacturer) > 0) { return(1); } else if (this.Manufacturer.CompareTo(other.Manufacturer) < 0) { return(-1); } else { if (this.Model.CompareTo(other.Model) > 0) { return(1); } else if (this.Model.CompareTo(other.Model) < 0) { return(-1); } else { if (this.Transmission.CompareTo(other.Transmission) > 0) { return(1); } else if (this.Transmission.CompareTo(other.Transmission) < 0) { return(-1); } else { return(this.Owner.CompareTo(other.Owner)); } } } }
//defines folders to which xml files are written public static void SaveToXml(IParsee input) { Directory.CreateDirectory(xmlloc + "\\" + input.GetType().Name); String path = String.Format("{0}\\{1}\\{2}{3}.xml", xmlloc, input.GetType().Name, input.FileName, ""); int i = 1; while (File.Exists(path)) { path = String.Format("{0}\\{1}\\{2}{3}.xml", xmlloc, input.GetType().Name, input.FileName, "(" + i + ")"); i++; } var stream = new FileStream(path, FileMode.Create); XmlWriter xw = XmlWriter.Create(stream); input.WriteXml(xw); xw.Flush(); stream.Dispose(); }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } Person other = obj as Person; if (this.Gender > other.Gender) { return(1); } else if (this.Gender < other.Gender) { return(-1); } else { if (this.LastName.CompareTo(other.LastName) > 0) { return(1); } else if (this.LastName.CompareTo(other.LastName) < 0) { return(-1); } else { if (this.FirstName.CompareTo(other.FirstName) == 0) { return(DateTime.Compare(this.DateOfBirth, other.DateOfBirth)); } else { return(this.FirstName.CompareTo(other.FirstName)); } } } }
public int CompareTo(IParsee obj) { if (obj == null) { return(1); } FootballClub other = obj as FootballClub; if (this.Country.CompareTo(other.Country) > 0) { return(1); } else if (this.Country.CompareTo(other.Country) < 0) { return(-1); } else { if (this.City.CompareTo(other.City) > 0) { return(1); } else if (this.City.CompareTo(other.City) < 0) { return(-1); } else { if (this.Name.CompareTo(other.Name) == 0) { return(DateTime.Compare(this.Established, other.Established)); } else { return(this.Name.CompareTo(other.Name)); } } } }