コード例 #1
0
        }     // _Ordered_Comparer_impl_ class

        public static DataSet getOrdered(DataSet dataSet, params OrderByItem[] orderByItems)
        {
            List <Row>      values          = new List <Row>();
            IComparer <Row> valueComparator = null;

            if (orderByItems != null && orderByItems.Length != 0)
            {
                int[] sortIndexes = new int[orderByItems.Length];
                for (int i = 0; i < orderByItems.Length; i++)
                {
                    OrderByItem item     = orderByItems[i];
                    int         index_of = dataSet.indexOf(item.getSelectItem());
                    sortIndexes[i] = index_of;
                }

                values = readDataSetFull(dataSet);
                if (values.IsEmpty())
                {
                    return(new EmptyDataSet(dataSet.getSelectItems()));
                }

                valueComparator = ObjectComparator.getComparator();

                // create a comparator for doing the actual sorting/ordering
                IComparer <Row> comparator = new _Ordered_Comparer_impl_(valueComparator, orderByItems);
            }
            values.Sort(valueComparator);     // Collections.sort(data, comparator);

            dataSet = new InMemoryDataSet(values);
            return(dataSet);
        }     // getOrdered()
コード例 #2
0
        private bool compare(Object selectItemValue, Object operandValue)
        {
            IComparer <Object> comparator = ObjectComparator.getComparator();

            if (_operator == OperatorType.DIFFERENT_FROM)
            {
                return(comparator.Compare(selectItemValue, operandValue) != 0);
            }
            else if (_operator == OperatorType.EQUALS_TO)
            {
                return(comparator.Compare(selectItemValue, operandValue) == 0);
            }
            else if (_operator == OperatorType.GREATER_THAN)
            {
                return(comparator.Compare(selectItemValue, operandValue) > 0);
            }
            else if (_operator == OperatorType.GREATER_THAN_OR_EQUAL)
            {
                return(comparator.Compare(selectItemValue, operandValue) >= 0);
            }
            else if (_operator == OperatorType.LESS_THAN)
            {
                return(comparator.Compare(selectItemValue, operandValue) < 0);
            }
            else if (_operator == OperatorType.LESS_THAN_OR_EQUAL)
            {
                return(comparator.Compare(selectItemValue, operandValue) <= 0);
            }
            else if (_operator == OperatorType.LIKE)
            {
                //WildcardPattern matcher = new WildcardPattern((String)operandValue, '%');
                //return matcher.matches((String)selectItemValue);
                return(false);
            }
            else if (_operator == OperatorType.NOT_LIKE)
            {
                //WildcardPattern matcher = new WildcardPattern((String)operandValue, '%');
                //return !matcher.matches((String)selectItemValue);
                return(false);
            }
            else if (_operator == OperatorType.IN)
            {
                HashSet <object> inValues = getInValues();
                return(inValues.Contains(selectItemValue));
            }
            else if (_operator == OperatorType.NOT_IN)
            {
                HashSet <object> inValues = getInValues();
                return(!inValues.Contains(selectItemValue));
            }
            else
            {
                throw new InvalidOperationException("Operator could not be determined");
            }
        }
        } //  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()