public List <Film> SortBy(List <Film> films, SortPriority sortPriority) { // Sorts the List<Film> based upon the sortValue // TODO: Find a way to eliminate the magic strings switch (sortPriority) { case SortPriority.Title: return(SortByTitle(films)); case SortPriority.TitleDesc: return(SortByTitleDescending(films)); case SortPriority.Year: return(SortByYear(films)); case SortPriority.YearDesc: return(SortByYearDescending(films)); case SortPriority.Media: return(SortByMediaFormat(films)); case SortPriority.MediaDesc: return(SortByMediaFormatDescending(films)); case SortPriority.Audio: return(SortByAudioFormat(films)); case SortPriority.AudioDesc: return(SortByAudioFormatDescending(films)); default: return(SortByTitle(films)); } }
/// <summary> /// Adds an item to the sorting list. If it exists already, it will be superceded (deprioritized), unless the existing /// item is marked as "Required" or "RequiredOrder." In the first case, only the order (asc or desc) will be changed to /// the current value. In the 2nd case, no changes will be made. /// </summary> /// <param name="field"></param> /// <param name="order"></param> /// <param name="priority"></param> /// <returns></returns> public ISqlQuery AddSort(string field, SortOrder order, SortPriority priority) { if (String.IsNullOrEmpty(field)) { throw new Exception("The field name cannot be missing to add a sort"); } string sortOrder = order == SortOrder.Ascending ? "" : " DESC"; int index = sortCriterionList.Count - 1; string fieldNameClean = unAliased(field.Trim().ToLower()); bool found = false; while (index >= 0) { var item = sortCriterionList[index]; if (item.Field == fieldNameClean) { switch (item.Priority) { case SortPriority.RequiredOrder: found = true; index = -1; break; case SortPriority.Required: sortCriterionList[index] = new SortCriterion(fieldNameClean, order, item.Priority); sortCriterionList[index].Owner = this; index = -1; found = true; break; default: sortCriterionList.RemoveAt(index); break; } } index--; } if (!found) { var crit = new SortCriterion(fieldNameClean, order, priority); crit.Owner = this; sortCriterionList.Add(crit); Touch(); } return(this); }
/// <summary> /// Returns true if RunnerDefinition instances are equal /// </summary> /// <param name="other">Instance of RunnerDefinition to be compared</param> /// <returns>Boolean</returns> public bool Equals(RunnerDefinition other) { // credit: http://stackoverflow.com/a/10454552/677735 if (other == null) { return(false); } return((SortPriority == other.SortPriority || SortPriority != null && SortPriority.Equals(other.SortPriority)) && (RemovalDate == other.RemovalDate || RemovalDate != null && RemovalDate.Equals(other.RemovalDate)) && (Id == other.Id || Id != null && Id.Equals(other.Id)) && (Hc == other.Hc || Hc != null && Hc.Equals(other.Hc)) && (AdjustmentFactor == other.AdjustmentFactor || AdjustmentFactor != null && AdjustmentFactor.Equals(other.AdjustmentFactor)) && (Bsp == other.Bsp || Bsp != null && Bsp.Equals(other.Bsp)) && (Status == other.Status || Status != null && Status.Equals(other.Status))); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { var hash = 41; // Suitable nullity checks etc, of course :) if (SortPriority != null) { hash = hash * 59 + SortPriority.GetHashCode(); } if (RemovalDate != null) { hash = hash * 59 + RemovalDate.GetHashCode(); } if (Id != null) { hash = hash * 59 + Id.GetHashCode(); } if (Hc != null) { hash = hash * 59 + Hc.GetHashCode(); } if (AdjustmentFactor != null) { hash = hash * 59 + AdjustmentFactor.GetHashCode(); } if (Bsp != null) { hash = hash * 59 + Bsp.GetHashCode(); } if (Status != null) { hash = hash * 59 + Status.GetHashCode(); } return(hash); } }
public KNTableColumn(string anIdentifier, string aTitle, KNCell aDataCell, KNTableColumnDelegate aDelegate) { ClipToBounds = true; activeCells = new Dictionary<int, KNCell>(); cellCache = new ArrayList(); sortPriority = SortPriority.NotUsed; sortDirection = SortDirection.Ascending; if (aDataCell != null) { dataCell = aDataCell; } else { dataCell = new KNTextCell(); } minSize = 100; maxSize = 2000; Width = 100; userResizable = true; HeaderCell = new KNHeaderCell(); headerCell.Column = this; del = aDelegate; if (anIdentifier != null) { identifier = anIdentifier; } else { identifier = ""; } KNActionCellDependencyProperty.SetDelegate((DependencyObject)headerCell, this); if (aTitle != null) { KNCellDependencyProperty.SetObjectValue((DependencyObject)headerCell, aTitle); } else { KNCellDependencyProperty.SetObjectValue((DependencyObject)headerCell, "Column Title"); } this.AddObserverToKeyPathWithOptions(this, "VerticalOffset", 0, null); this.AddObserverToKeyPathWithOptions(this, "RowHeight", 0, null); this.AddObserverToKeyPathWithOptions(this, "DataCell", 0, null); LayoutCompletely(); }
public ISqlQuery AddSort(string orderClause, SortPriority priority) { string[] items = orderClause.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (items.Length == 0) { throw new Exception("Cannot add a missing field for sorting."); } foreach (var item in items) { string clause = item.Trim(); SortOrder order = SortOrder.Ascending; if (clause.IndexOf(' ') > 0) { string[] parts = clause.Split(' '); clause = parts[0]; if (parts[1].ToLower().Trim() == "desc") { order = SortOrder.Descending; } } AddSort(clause, order, priority); } return(this); }
public SortCriterion(string field, SortOrder order, SortPriority priority) { Field = field; Order = order; Priority = priority; }
/// <summary> /// Adds an item to the sorting list. If it exists already, it will be superceded (deprioritized), unless the existing /// item is marked as "Required" or "RequiredOrder." In the first case, only the order (asc or desc) will be changed to /// the current value. In the 2nd case, no changes will be made. /// </summary> /// <param name="field"></param> /// <param name="order"></param> /// <param name="priority"></param> /// <returns></returns> public ISqlQuery AddSort(string field, SortOrder order, SortPriority priority) { if (String.IsNullOrEmpty(field)) { throw new Exception("The field name cannot be missing to add a sort"); } string sortOrder = order == SortOrder.Ascending ? "" : " DESC"; int index = sortCriterionList.Count - 1; string fieldNameClean = unAliased(field.Trim().ToLower()); bool found = false; while (index >= 0) { var item = sortCriterionList[index]; if (item.Field == fieldNameClean) { switch (item.Priority) { case SortPriority.RequiredOrder: found = true; index = -1; break; case SortPriority.Required: sortCriterionList[index] = new SortCriterion(fieldNameClean, order, item.Priority); sortCriterionList[index].Owner = this; index = -1; found = true; break; default: sortCriterionList.RemoveAt(index); break; } } index--; } if (!found) { var crit = new SortCriterion(fieldNameClean, order, priority); crit.Owner = this; sortCriterionList.Add(crit); Touch(); } return this; }
public ISqlQuery AddSort(string orderClause, SortPriority priority) { string[] items = orderClause.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (items.Length == 0) { throw new Exception("Cannot add a missing field for sorting."); } foreach (var item in items) { string clause = item.Trim(); SortOrder order = SortOrder.Ascending; if (clause.IndexOf(' ') > 0) { string[] parts = clause.Split(' '); clause = parts[0]; if (parts[1].ToLower().Trim() == "desc") { order = SortOrder.Descending; } } AddSort(clause, order, priority); } return this; }