SortItem AddSortItem(SortOrder s)
        {
            var si = new SortItem(s);

            SortMenuItem.DropDownItems.Add(si);
            return(si);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Check if item may be placed into this cell.
    /// </summary>
    /// <returns><c>true</c> if this instance is sort allowed the specified item; otherwise, <c>false</c>.</returns>
    /// <param name="item">Item.</param>
    public bool IsSortAllowed(GameObject item)
    {
        bool res = false;

        if (item != null)
        {
            SortItem sortItem = item.GetComponent <SortItem>();
            if (allowedItemTypes.Count <= 0)
            {
                res = true;
            }
            else
            {
                if (sortItem != null)
                {
                    foreach (string itemType in allowedItemTypes)
                    {
                        // If item has allowed sort
                        if (itemType == sortItem.itemType)
                        {
                            res = true;
                            break;
                        }
                    }
                }
            }
        }
        return(res);
    }
        public void Sort_MultipleElementsTwoDependencyDeep_CanSortByDependency()
        {
            // Arrange
            var a = new SortItem("A");
            var c = new SortItem("C");
            var f = new SortItem("F");
            var h = new SortItem("H");
            var d = new SortItem("D");
            var g = new SortItem("G");
            var e = new SortItem("E");
            var b = new SortItem("B");

            d.SetDependencies(a);
            g.SetDependencies(f, h);
            e.SetDependencies(d, g);
            b.SetDependencies(c, e);

            var unsorted = new[] { a, b, c, d, e, f, g, h };

            // Act
            TopologicalSorter topologicalSorter = new TopologicalSorter();
            var sorted = topologicalSorter.Sort(unsorted, x => x.Dependencies, new SortItemEqualityComparer());

            // Assert
            Assert.Equal(8, sorted.Count);
            Assert.Equal("A", sorted[0].Name);
            Assert.Equal("C", sorted[1].Name);
            Assert.Equal("D", sorted[2].Name);
            Assert.Equal("F", sorted[3].Name);
            Assert.Equal("H", sorted[4].Name);
            Assert.Equal("G", sorted[5].Name);
            Assert.Equal("E", sorted[6].Name);
            Assert.Equal("B", sorted[7].Name);
        }
        public override object getExtraInfo(SelectableMediaItem selectableItem)
        {
            String info = null;

            ImageResultItem item = (ImageResultItem)selectableItem.Item;

            SortItem sortItem = (SortItem)SortModes.CurrentItem;

            switch (sortItem.SortMode)
            {
            case SortMode.Width:

            case SortMode.Height:
                info = item.ImageInfo.Width + " x " + item.ImageInfo.Height;
                break;

            case SortMode.Size:
                info = MiscUtils.formatSizeBytes(item.ImageInfo.FileSize.Value);
                break;

            case SortMode.MimeType:
                info = item.ImageInfo.ContentType;
                break;

            case SortMode.Location:
                info = item.ImageInfo.SourceUrl;
                break;

            default:
                break;
            }

            return(info);
        }
Exemplo n.º 5
0
            public SortWrapper(SortItem handler)
            {
                if (handler == null)
                {
                    throw new ArgumentNullException("handler");
                }

                _sorter = handler;
            }
Exemplo n.º 6
0
        // Sort the eigenvalues and compute the corresponding permutation of the
        // indices of the array storing the eigenvalues.  The permutation is used
        // for reordering the eigenvalues and eigenvectors in the calls to
        // GetEigenvalues(...) and GetEigenvectors(...).
        private void ComputePermutation(int sortType)
        {
            mIsRotation = -1;

            if (sortType == 0)
            {
                // Set a flag for GetEigenvalues() and GetEigenvectors() to know
                // that sorted output was not requested.
                mPermutation[0] = -1;
                return;
            }

            // Compute the permutation induced by sorting.  Initially, we start with
            // the identity permutation I = (0,1,...,N-1).
            var items = new SortItem[mSize];

            for (int i = 0; i < mSize; ++i)
            {
                items[i].eigenvalue = mDiagonal[i];
                items[i].index      = i;
            }

            if (sortType > 0)
            {
                //std::sort(items.begin(), items.end(), std::less<SortItem>());
                Array.Sort(items, (a, b) => { return(a.eigenvalue == b.eigenvalue ? 0 : a.eigenvalue < b.eigenvalue ? -1 : 1); });
            }
            else
            {
                //std::sort(items.begin(), items.end(), std::greater<SortItem>());
                Array.Sort(items, (a, b) => { return(a.eigenvalue == b.eigenvalue ? 0 : a.eigenvalue > b.eigenvalue ? -1 : 1); });
            }

            for (int i = 0; i < mSize; ++i)
            {
                mPermutation[i] = items[i].index;
            }
            //typename std::vector < SortItem >::const_iterator item = items.begin();
            //for (i = 0; item != items.end(); ++item, ++i) {
            //    mPermutation[i] = item->index;
            //}

            // GetEigenvectors() has nontrivial code for computing the orthogonal Q
            // from the reflections and rotations.  To avoid complicating the code
            // further when sorting is requested, Q is computed as in the unsorted
            // case.  We then need to swap columns of Q to be consistent with the
            // sorting of the eigenvalues.  To minimize copying due to column swaps,
            // we use permutation P.  The minimum number of transpositions to obtain
            // P from I is N minus the number of cycles of P.  Each cycle is reordered
            // with a minimum number of transpositions; that is, the eigenitems are
            // cyclically swapped, leading to a minimum amount of copying.  For
            // example, if there is a cycle i0 -> i1 -> i2 -> i3, then the copying is
            //   save = eigenitem[i0];
            //   eigenitem[i1] = eigenitem[i2];
            //   eigenitem[i2] = eigenitem[i3];
            //   eigenitem[i3] = save;
        }
Exemplo n.º 7
0
        private SortItem ConvertRequestSort(string sort)
        {
            string[] sortItem = sort.Split('|');
            SortItem item     = new SortItem();

            item.FieldName    = sortItem[0];
            item.IsDescending = bool.Parse(sortItem[1]);
            return(item);
        }
Exemplo n.º 8
0
 public IActionResult Submit([FromBody] SortItem item)
 {
     if (item == null)
     {
         return(HttpBadRequest());
     }
     sortArray.sort(item);
     return(new ObjectResult(item));
 }
            public int CompareTo(object obj)
            {
                SortItem item = obj as SortItem;

                if (item == null || item.rate < rate)
                {
                    return(-1);
                }
                return(1);
            }
Exemplo n.º 10
0
 public SearchResult Search(string index, string type, IQuery query, SortItem sortItem, int from = 0, int size = 5, string[] fields = null)
 {
     string[] temp = null;
     if (type != null)
     {
         temp = new[] { type }
     }
     ;
     return(Search(index, temp, query, sortItem, from, size, fields));
 }
        void sortItems_ItemSortDirectionChanged(object sender, EventArgs e)
        {
            SortItem sortItem = (SortItem)sender;

            if (((SortItem)SortModes.CurrentItem).SortMode == sortItem.SortMode)
            {
                SortDirection = sortItem.SortDirection;

                refresh();
            }
        }
Exemplo n.º 12
0
    /// <summary>
    /// Gets the sort item from this cell.
    /// </summary>
    /// <returns>The sort item.</returns>
    public SortItem GetSortItem()
    {
        SortItem   res  = null;
        GameObject item = GetComponent <DadCell>().GetItem();

        if (item != null)
        {
            res = item.GetComponent <SortItem>();
        }
        return(res);
    }
Exemplo n.º 13
0
 void Awake()
 {
     for (int i = 0; i < title.Length; i++)
     {
         GameObject instance = GameObject.Instantiate(singleLetter, transform);
         instance.GetComponent <Text>().text = title[i].ToString();
         SortItem sortItem = instance.GetComponent <SortItem>();
         sortItem.size = i;
         sortItems.Add(sortItem);
     }
 }
Exemplo n.º 14
0
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var item in list.Items)
            {
                SortItem sortItem = item as SortItem;
                builder.Append($"{sortItem.Title}_{sortItem.Tid}.");
            }
            SettingHelper.SetValue("_sort", builder.Remove(builder.Length - 1, 1).ToString());
            action();
        }
Exemplo n.º 15
0
        public static MethodInfo GetOrderByMethod(SortItem sortItem)
        {
            var methodName        = sortItem.SortDirection == ListSortDirection.Ascending ? "OrderBy" : "OrderByDescending";
            var orderByMethodInfo = typeof(Queryable)
                                    .GetMethods(BindingFlags.Public | BindingFlags.Static)
                                    .Single(mi => mi.Name == methodName &&
                                            mi.IsGenericMethodDefinition &&
                                            mi.GetGenericArguments().Length == 2 &&
                                            mi.GetParameters().Length == 2);

            return(orderByMethodInfo);
        }
Exemplo n.º 16
0
        int FindCurrentPosition(List <SortItem> currList, SortItem si)
        {
            for (int i = 0; i < currList.Count; i++)
            {
                if (currList[i].ord > si.ord)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 17
0
        private void AggregateBatches(RawList <SortItem> sortItems, RawList <VertexDrawItem> drawItems, RawList <DrawBatch> batches)
        {
            VertexDrawItem[] drawData = drawItems.Data;
            SortItem[]       sortData = sortItems.Data;

            SortItem       activeSortItem  = sortData[0];
            VertexDrawItem activeItem      = drawData[activeSortItem.DrawItemIndex];
            int            beginBatchIndex = 0;

            // Find sequences of draw items that can be batched together
            int count = sortItems.Count;

            for (int sortIndex = 1; sortIndex <= count; sortIndex++)
            {
                // Skip items until we can no longer put the next one into the same batch
                if (sortIndex < count)
                {
                    SortItem sortItem = sortData[sortIndex];
                    if (activeItem.CanShareBatchWith(ref drawData[sortItem.DrawItemIndex]))
                    {
                        continue;
                    }
                }

                // Create a batch for all previous items
                VertexBuffer vertexBuffer = this.vertexBuffers[activeItem.TypeIndex][activeItem.BufferIndex];
                DrawBatch    batch        = new DrawBatch(
                    vertexBuffer,
                    this.batchIndexPool.Rent(sortIndex - beginBatchIndex),
                    activeItem.Mode,
                    activeItem.Material);

                for (int i = beginBatchIndex; i < sortIndex; i++)
                {
                    batch.VertexRanges.Add(new VertexDrawRange
                    {
                        Index = drawData[sortData[i].DrawItemIndex].Offset,
                        Count = drawData[sortData[i].DrawItemIndex].Count
                    });
                }

                batches.Add(batch);

                // Proceed with the current item being the new sharing reference
                if (sortIndex < count)
                {
                    beginBatchIndex = sortIndex;
                    activeSortItem  = sortData[sortIndex];
                    activeItem      = drawData[activeSortItem.DrawItemIndex];
                }
            }
        }
Exemplo n.º 18
0
        private static IEnumerable <Lazy <T, IOrderMetadata> > Order(IEnumerable <Lazy <T, IOrderMetadata> > collection)
        {
            IndexDictionary index = new IndexDictionary(collection);
            SortItem        root  = new SortItem();

            foreach (Lazy <T, IOrderMetadata> item in collection)
            {
                SortItem sourceItem = null;
                if (!String.IsNullOrEmpty(item.Metadata.ID) && index.ContainsKey(item.Metadata.ID))
                {
                    sourceItem = index[item.Metadata.ID];
                }
                else
                {
                    sourceItem      = new SortItem();
                    sourceItem.Item = item;
                }


                if (!string.IsNullOrEmpty(item.Metadata.Before) && index.ContainsKey(item.Metadata.Before))
                {
                    SortItem targetItem = index[item.Metadata.Before];
                    if (!targetItem.Used)
                    {
                        sourceItem.Children.Add(targetItem);
                        targetItem.Used = true;
                    }
                }
                else
                if (!string.IsNullOrEmpty(item.Metadata.After) && index.ContainsKey(item.Metadata.After))
                {
                    if (!sourceItem.Used)
                    {
                        SortItem targetItem = index[item.Metadata.After];
                        targetItem.Children.Add(sourceItem);
                        sourceItem.Used = true;
                    }
                }

                if (!sourceItem.Used)
                {
                    root.Children.Add(sourceItem);
                    sourceItem.Used = true;
                }
            }

            return(root.ToCollection());
        }
Exemplo n.º 19
0
        public StatementBuilder Pipeline()
        {
            StatementBuilder statement = Cypher.Match(Node).Return(Node);

            if (_filters is not null)
            {
                statement.Match(new Where(_filters), Node);
            }

            if (_projection is not null)
            {
                statement.Return(Node.Project(_projection));
            }

            if (_sorting is null)
            {
                return(statement);
            }

            var sorts = new List <SortItem>();

            foreach (Neo4JSortDefinition sort in _sorting)
            {
                SortItem sortItem = Cypher.Sort(Node.Property(sort.Field));
                if (sort.Direction == SortDirection.Ascending)
                {
                    sorts.Push(sortItem.Ascending());
                }
                else if (sort.Direction == SortDirection.Descending)
                {
                    sorts.Push(sortItem.Descending());
                }
            }

            statement.OrderBy(sorts);

            if (_limit is not null)
            {
                statement.Limit((int)_limit);
            }

            if (_skip is not null)
            {
                statement.Limit((int)_skip);
            }

            return(statement);
        }
        public void Sort_FirstOrderCircularDependency_ThrowsSortException()
        {
            // Arrange
            var a = new SortItem("A");
            var c = new SortItem("C");

            a.SetDependencies(c);
            c.SetDependencies(a);

            var unsorted = new[] { a, c };

            // Act and Assert
            TopologicalSorter topologicalSorter = new TopologicalSorter();
            CircularDependencyException<SortItem> exception = Assert.Throws<CircularDependencyException<SortItem>>(
                () => topologicalSorter.Sort(unsorted, x => x.Dependencies, new SortItemEqualityComparer()));

            Assert.Equal(1, exception.AffectedItems.Count);
            Assert.Equal("A", exception.AffectedItems[0].Name);
        }
Exemplo n.º 21
0
        public void Sort(Span <SeqNo> input, Span <SortItem> outputItems)
        {
            if (input.Length != outputItems.Length)
            {
                throw new InvalidOperationException();
            }

            for (var i = 0; i < outputItems.Length; i++)
            {
                outputItems[i] = new SortItem(i, GetDifference(input[i].Value, Value));
            }


#warning TODO: SeqNo.Sort
            //public bool LessThan(SortItem a, SortItem b)
            //{
            //    return a.Value < b.Value;
            //}
            // TODO: outputItems.WithOrder(new Ordering()).Sort();
        }
Exemplo n.º 22
0
        public void Populate(List <Tuple <string, string, int> > fields)
        {
            //foreach (var s in fields)
            //{
            //	this.availibleFields.Add(s);
            //}
            for (int i = 0; i < fields.Count; i++)
            {
                var si = new  SortItem()
                {
                    val = fields[i].Item1, disp = fields[i].Item2, ord = fields[i].Item3
                };
                availibleFields.Add(si);
            }

            lstAvailFlds.DataSource    = availibleFields;
            lstAvailFlds.DisplayMember = "disp";
            lstAvailFlds.ValueMember   = "val";
            lstSortFlds.DataSource     = sortedFields;
        }
        public SearchResult Search(string index, string[] type, IQuery query, SortItem sortItem, int from, int size, string[] fields = null)
        {
            Contract.Assert(!string.IsNullOrEmpty(index));
            Contract.Assert(query != null);
            Contract.Assert(from >= 0);
            Contract.Assert(size > 0);

            var elasticQuery = new ElasticQuery(from, size);

            elasticQuery.SetQuery(query);
            if (sortItem != null)
            {
                elasticQuery.AddSortItem(sortItem);
            }
            if (fields != null)
            {
                elasticQuery.AddFields(fields);
            }

            return(Search(index, type, elasticQuery));
        }
Exemplo n.º 24
0
        public JsonResult Sort([FromBody] SortItem sortItem)
        {
            string[] splitValues = sortItem.InputValue.Split(',');
            int[]    intValues;

            if (sortItem.InputValue.Equals("") ||
                splitValues.Length == 0 ||
                splitValues.Length > 500)
            {
                return(Json(new { success = false, error = "Input size is 1 to 500 values." }));
            }

            switch (sortItem.InputTypeValue)
            {
            case "int":
                if (!ValidateNumbers(splitValues))
                {
                    return(Json(new { success = false, error = "Invalid Numbers(not integer size)" }));
                }

                intValues = Array.ConvertAll(splitValues, (string value) =>
                {
                    return(int.Parse(value));
                });

                return(Json(new { success = true, data = InsertionSort.SortIntArray(intValues) }));

            case "string":
                if (!ValidateStrings(splitValues))
                {
                    return(Json(new { success = false, error = "String values are up to 10 characters long." }));
                }

                return(Json(new { success = true, data = InsertionSort.SortStringArray(splitValues) }));

            default:
                return(Json(new { success = false, error = "Invalid input type." }));
            }
        }
Exemplo n.º 25
0
    IEnumerator fullSort()
    {
        yield return(new WaitForSeconds(time));

        for (int j = sortItems.Count - 1; j > 0; j--)
        {
            for (int i = 0; i < j; i++)
            {
                if (sortItems[i].size > sortItems[i + 1].size)
                {
                    SortItem temp = sortItems[i];
                    sortItems[i]     = sortItems[i + 1];
                    sortItems[i + 1] = temp;

                    //Animation Stuff
                    sortItems[i].move(indexToLetterPos(i), time, 0, 40);
                    sortItems[i + 1].move(indexToLetterPos(i + 1), time, 0, -40);
                    yield return(new WaitForSeconds(time));
                }
            }
        }
    }
Exemplo n.º 26
0
 private static int DepthSortComparison(SortItem first, SortItem second)
 {
     if (second.SortDepth < first.SortDepth)
     {
         return(-1);
     }
     if (second.SortDepth > first.SortDepth)
     {
         return(1);
     }
     if (second.SortDepth == first.SortDepth)
     {
         return(0);
     }
     if (float.IsNaN(second.SortDepth))
     {
         return(float.IsNaN(first.SortDepth) ? 0 : -1);
     }
     else
     {
         return(1);
     }
 }
Exemplo n.º 27
0
        //Generated the query clause
        private void GenerateClause()
        {
            try
            {
                string cl = "";

                //Clear all existing items, they will be regenerated
                SortedItems.Clear();

                foreach (string s in TheSorts)
                {
                    for (int i = 0; i < taig.Rows; i++)
                    {
                        if (taig.get_item(i, 0) == s)
                        {
                            cl += s + " " + taig.get_item(i, 2) + ",";
                            SortItem si = new SortItem(s, taig.get_item(i, 2));
                            SortedItems.Add(si);
                            break;
                        }
                    }
                }

                if (cl != "")
                {
                    cl = "ORDER BY " + cl.Substring(0, cl.Length - 1);
                }

                txtClause.Text = cl;
                Clause         = cl;
            }
            catch (Exception ex)
            {
                showError("Unable to generate the query clause" + System.Environment.NewLine
                          + ex.Message);
            }
        }
Exemplo n.º 28
0
        //populates an existing sort item's data
        private void populateData(string[] meta)
        {
            try
            {
                ArrayList rowIDs = new ArrayList();

                //populate SortedItems list
                for (int i = 0; i < meta.Length; i++)
                {
                    string[] sortedField = meta[i].Split(',');
                    SortItem si          = new SortItem(sortedField[0], sortedField[1]);
                    SortedItems.Add(si);
                }

                foreach (SortItem s in SortedItems)
                {
                    //select the row in the grid & set the sort properties
                    int rowID = taig.FindInColumn(s.SortField, taig.GetColumnIDByName("FIELD"), false);

                    if (rowID != -1)
                    {
                        taig.set_item(rowID, taig.GetColumnIDByName("SORT"), "YES");
                        taig.set_item(rowID, taig.GetColumnIDByName("DIRECTION"), s.SortDirection);
                        rowIDs.Add(rowID);
                        TheSorts.Add(s.SortField);
                    }
                }

                //highlight all selected fields
                taig.SelectRows(rowIDs);
            }
            catch (Exception ex)
            {
                showError("Unable to load the sort item's data" + System.Environment.NewLine
                          + ex.Message);
            }
        }
Exemplo n.º 29
0
 public GenericQuery(IFilter <T> filters, SortItem <T> sortItem) : this(filters, sortItem, null)
 {
 }
Exemplo n.º 30
0
 public GenericQuery(IFilter <T> filters, SortItem <T> sortItem, string orderQuery)
 {
     this.Filters   = filters;
     this.SortItem  = sortItem;
     this.SortQuery = orderQuery;
 }
        public void Sort_TwoElementsOneDependencyDeep_CanSortByDependency()
        {
            // Arrange
            SortItem a = new SortItem("A");
            SortItem c = new SortItem("C");

            c.SetDependencies(a);

            SortItem[] unsorted = new[] { c, a };

            // Act
            TopologicalSorter topologicalSorter = new TopologicalSorter();
            IList<SortItem> sorted = topologicalSorter.Sort(unsorted, x => x.Dependencies, new SortItemEqualityComparer());

            // Assert
            Assert.Equal(2, sorted.Count);
            Assert.Equal("A", sorted[0].Name);
            Assert.Equal("C", sorted[1].Name);
        }
Exemplo n.º 32
0
    public static DsDevice[] Sort(DsDevice[] devices, params object[] arg)
    {
      try
      {
        if (devices == null)
          return devices;
        if (devices.Length <= 1)
          return devices;
        List<string> compareNames = new List<string>();
        foreach (object obj in arg)
        {
          String name = obj as String;
          if (!string.IsNullOrEmpty(name))
          {
            compareNames.Add(name);
            continue;
          }
          DsDevice dev = obj as DsDevice;
          if (dev == null)
            continue;
          if (dev.Name == null)
            continue;
          if (dev.Name.Length == 0)
            continue;
          compareNames.Add(dev.Name);
        }
        if (compareNames.Count == 0)
          return devices;

        List<string> names = new List<string>();
        for (int i = 0; i < devices.Length; ++i)
        {
          if (devices[i] == null)
            continue;
          if (devices[i].Name == null)
            continue;
          if (devices[i].Name.Length == 0)
            continue;
          names.Add(devices[i].Name);
        }

        //sort the devices based 
        float[] results = new float[devices.Length + 20];
        for (int x = 0; x < results.Length; ++x)
        {
          results[x] = 0.0f;
        }

        for (int i = 0; i < compareNames.Count; ++i)
        {
          Levenstein comparer = new Levenstein();
          float[] tmpResults = comparer.batchCompareSet(names.ToArray(), compareNames[i]);
          for (int x = 0; x < tmpResults.Length; ++x)
          {
            results[x] += tmpResults[x];
          }
        }
        List<SortItem> items = new List<SortItem>();
        for (int i = 0; i < devices.Length; ++i)
        {
          SortItem item = new SortItem();
          item.rate = results[i];
          item.device = devices[i];
          items.Add(item);
        }
        items.Sort();
        DsDevice[] newDevices = new DsDevice[items.Count];

        int index = 0;
        foreach (SortItem item in items)
        {
          newDevices[index] = item.device;
          index++;
        }
        return newDevices;
      }
      catch (Exception ex)
      {
        Log.Log.Write(ex);
        return devices;
      }
    }
        public IQueryable <Product> DynamicFieldSelectWithSortOption(FilterItem[] filterItems, SortItem sortItem)
        {
            var products = DynamicFieldSelection(filterItems);

            return(GetOrderedList(products, sortItem));
        }
        private IOrderedQueryable <Product> GetOrderedList(IQueryable <Product> products, SortItem sortItem)
        {
            ParameterExpression p              = _expressionBuilder.BuildParameterExpression <Product>("product");
            MethodInfo          orderBy        = DemoHelper.GetOrderByMethod(sortItem);
            MemberExpression    sortMember     = Expression.PropertyOrField(p, sortItem.SortField);
            Expression          sortExpression = Expression.Lambda(sortMember, p);

            Type sortByPropType = typeof(Product).GetProperty(sortItem.SortField).PropertyType;
            var  sortedList     = (orderBy.MakeGenericMethod(new[] { typeof(Product), sortByPropType })
                                   .Invoke(products, new object[] { products, sortExpression }) as IOrderedQueryable <Product>);

            return(sortedList);
        }