public void TestCompareSimple() { Debug.WriteLine(">> TestCompareSimple"); IComparer <object> comparer = NumberComparator.getComparator(); var result = comparer.Compare(1, 2); //Assert.AreEqual(1, result); }
} // getChar() public NInteger getInt(string key) { object obj = get(key); if (obj == null) { return(null); } return(NumberComparator.toNumber(obj).asInt()); } // getInt()
} // select() protected object createOperand(string token, SelectItem leftSelectItem, bool searchSelectItems) { if (token.Equals("NULL", StringComparison.CurrentCultureIgnoreCase)) { return(null); } if (token.StartsWith("'") && token.EndsWith("'") && token.Length > 2) { string stringOperand = token.Substring(1, token.Length - 1); //[J2N] replaceAll <=> Replace stringOperand = stringOperand.Replace("\\\\'", "'"); return(stringOperand); } if (searchSelectItems) { SelectItem selectItem = findSelectItem(token, false); if (selectItem != null) { return(selectItem); } } ColumnType expectedColumnType = leftSelectItem.getExpectedColumnType(); object result = null; if (expectedColumnType == null) { // We're assuming number here, but it could also be boolean or a // time based type. But anyways, this should not happen since // expected column type should be available. result = NumberComparator.toNumber(token); } else if (expectedColumnType.isBoolean()) { result = BooleanComparator.toBoolean(token); } // else if (expectedColumnType.isTimeBased()) // { // result = FormatHelper.parseSqlTime(expectedColumnType, token); // } // else // { // result = NumberComparator.toNumber(token); // } // if (result == null) // { // // shouldn't happen since only "NULL" is parsed as null. // throw new QueryParserException("Could not parse operand: " + token); // } return(result); } // createOperand()
} // getName() // public override Comparator<object> getComparator() public IComparer <object> getComparator() { if (isTimeBased()) { return(TimeComparator.getComparator()); } if (isNumber()) { return(NumberComparator.getComparator()); } if (isLiteral()) { return(ToStringComparator.getComparator()); } return(ObjectComparator.getComparator()); } // getComparator()
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { PropertyInfo propertyInfo = validationContext.ObjectType.GetProperty(_comparePropertyName); if (propertyInfo == null) { return(null); } if (value == null) { return(null); } if (!propertyInfo.PropertyType.Equals(value.GetType())) { return(null); } bool result = false; switch (_compareType) { case CompareType.NUMBER: result = new NumberComparator().Compare((float)value, (float)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator); break; case CompareType.TIME: result = new TimeComparator().Compare((string)value, (string)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator); break; case CompareType.DATE: result = new DateComparator().Compare((DateTime)value, (DateTime)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator); break; case CompareType.STRING: result = new StringComparator().Compare((string)value, (string)propertyInfo.GetValue(validationContext.ObjectInstance), _compareOperator); break; } if (!result) { return(new ValidationResult(string.Format(ErrorMessageString, validationContext.DisplayName, _comparePropertyName))); } return(ValidationResult.Success); }
private void buttonSort_Click(object sender, EventArgs e) { this.tmp.CopyTo(array, 0); int tmp = _radioButtonList.FindIndex(button => button.Checked); switch (tmp) { case 0: { _comparator = new NumberComparator(); _sortable = new BubbleSorter <double>(); } break; case 1: { _comparator = new NumberComparator(); _sortable = new FlagBubble <double>(); } break; case 2: { _comparator = new NumberComparator(); _sortable = new SimpleSelection <double>(); } break; case 3: { _comparator = new NumberComparator(); _sortable = new QuickSort <double>(); } break; case 4: { IComparableLab <CustomDoubleArray> comparator = new CustomDoubleArrayComparator(); ISortable <CustomDoubleArray> sortable = new ShellSort <CustomDoubleArray>(); if (sortable.ArrayCheck(CustomDoubleArray, comparator)) { tmpArrayHolder.Text = ""; sortedArrayHolder.Text = ""; CustomDoubleArray = sortable.Sort(CustomDoubleArray, tmpArrayHolder, comparator, true, true); sortable.Print(CustomDoubleArray, sortedArrayHolder, ""); } else { tmpLabel.Text = "Please reenter array, because it does not fit the condition!!"; } } return; case 5: { _comparator = new NumberComparator(); _sortable = new MergeSort <double>(); _direction = false; } break; case 6: { int [] intArray = new int[array.Length]; for (int i = 0; i < intArray.Length; i++) { intArray[i] = (int)array[i]; } intArray = Lab6ArrayHandler.Execute(intArray); IComparableLab <int> comparable = new NumberComparator(); ISortable <int> sortable = new CountSort <int>(); _direction = false; if (sortable.ArrayCheck(intArray, comparable)) { tmpArrayHolder.Text = ""; sortedArrayHolder.Text = ""; sortable.Print(intArray, tmpArrayHolder, "Масив після виконання індивідуального завдання: \n"); intArray = sortable.Sort(intArray, tmpArrayHolder, comparable, _direction, true); sortable.Print(intArray, sortedArrayHolder, ""); } else { tmpLabel.Text = "Please reenter array, because it does not fit the condition!!"; } } return; default: { throw new IndexOutOfRangeException(); } } if (_sortable.ArrayCheck(array, _comparator)) { tmpArrayHolder.Text = ""; sortedArrayHolder.Text = ""; array = _sortable.Sort(array, tmpArrayHolder, _comparator, _direction, true); _sortable.Print(array, sortedArrayHolder, ""); } else { tmpLabel.Text = "Please reenter array, because it does not fit the condition!!"; } }