sorting

List<T>.Sort sorting nulls incorrectly

I have a list of objects, some of which can be null. I want it sorted by some property, with nulls at the end of list. However, List<T>.Sort() method seems to put nulls in the beginning no matter what the comparer returns. This is a little program that I used to test this: class Program { class Foo { public int Bar; public Foo(...

Is there anyway to add metadata to Java Collections?

Let's say I have a collection of objects which can be sorted using a number of different comparators based on the different fields of the object. It would be nice to be able to know later on in the code which comparator was used to sort the Collection with and if it was ascending or descending. Is there anyway to do this elegantly instea...

Effectively disable Sort() within a CompareTo() override?

The CompareTo() method for my class is dynamic, and can range from a simple comparison to comparisons on a number of columns. This is all determined at run time, and it works great. But in some cases, I want any attempt to sort a collection of my objects using the default comparison to just do nothing. Having CompareTo() just return a ...

How to use SQL Order By statement to sort results case insensitive?

I have a SQLite database that I am trying to sort by Alphabetical order. The problem is, SQLite doesn't seem to consider A=a during sorting, thus I get results like this: A B C T a b c g I want to get: A a b B C c g T What special SQL thing needs to be done that I don't know about? SELECT * FROM NOTES ORDER BY title ...

jQuery sort unordered list alphabetically and numerically based on inner element value(s)

Code as reference: http://jsbin.com/aboca3/2/edit In this example above (thank you SLaks) I am truncating long unordered lists and providing a toggle link to view the entire thing. The issue, from a usability standpoint, is that as a full list, it is best sorted alphabetically, which will be the default sort order (the source order). ...

Sorting multiple XML elements within a node, by attribute

I've tried several of the solutions that I've found here, but none seem to work on the model that I'm using. In my example XML, I'm trying to sort the mixed up chapters, into their proper sequence. Source XML: <?xml version="1.0" encoding="utf-8"?> <library> <book> <title>A Fascinating Tale</title> <chapt...

Sort a List<?> by an enum, and then by alphabetical.

so i have my class, here: MyClass { public MyClass(Sort sort, string name){ this.srt = sort; this.Name = name; } public enum Sort { First, Second, Third, Fourth } public Sort srt { get; set; } public string Name { get; set; } } I have a list full of entries of MyClass, and I'm looking to sort them into groups by their srt prop...

How do I make this sorting case insensitive?

def sortProfiles(p): return sorted(p, key=itemgetter('first_name')) I have a list with dictionaries. This function allows me to sort them by their first_name. However, it's case-sensitive. ...

VirtualTreeview: when to sort children?

Hi all, I depend on VirtualTreeView to display thousands of items which are bound to change occasionally and when this happens the tree is cleaned and populated again. Sorting is done automatically (toAutoSort flag set) but this has an unwanted effect of initializing all the nodes recursively and this is a very expensive operation as yo...

Sort by key of dictionary inside a dictionary in Python

How to sort the following dictionary by the value of "remaining_pcs" or "discount_ratio"? promotion_items = { 'one': {'remaining_pcs': 100, 'discount_ratio': 10}, 'two': {'remaining_pcs': 200, 'discount_ratio': 20}, } EDIT What I mean is getting a sorted list of above dictionary, not to sort the dictionary itself. ...

How to omit "THE" in search using PHP and MYSQL

Hi all, I am doing a "ALPHABETICAL ORDER SEARCH" module for a project. that is it will look like A B C D E F . . . . . . . . . .. . . . . . . .. . . . Z When i click on "A" the results should be sort by "A". Which is same for all the alphabets. Now my prob is as follows: For example there is a film named "The Mummy". What i do i...

How to get the information and sort, a subset of elements with only identifiers using XSLT?

Hi, I'm new to XSLT and I can't resolve the following problem: I have a xml file like this: <root> <subset> <e id="A"></e> <e id="C"></e> </subset> <data> <info id="A" order="3" name="ANode"></info> <info id="B" order="4" name="BNode"></info> <info id="C" order="1" name="CNode"></inf...

CouchDB - Sorting documents by position

Hello, what is the best practice to sort/order multiple documents by user defined order (position) in CouchDB? Solutions I thought about: Every document has a "position" value, starting from 1 to n. The view would emit this value. Problem: If one document is sorted, all other documents with a greater position have to updates. This co...

Sort List of HashMaps based on hashMap values [not keys]

Here is what I have- How I can include multiple keys and their values in comparison? Right now I am only using employeeId but I wanted to include departmentId and other in my comparison for sorting... import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap;...

MySQL Hibernate sort on 2 columns

I have a table as follows Table item { ID - Primary Key content - String published_date - When the content was published create_date - When this database entry was created } Every hour (or specified time interval) I run a process to update this table with data from different sources (websites). I want to display the results accordi...

How do I sort a multidimensional array by one of the fields of the inner array in PHP?

Suppose I have an array that mimics a dayabase table. Each array element reporesents a row and within each row is another array that contains the field names and values. Array ( [0] => Array ( [name] => Sony TV [price] => 600.00 ) [1] => Array ( [name] => LG TV ...

Sorting NSSets of a core data entity - Objective-c

Hi everyone, I would like to sort the data of a core data NSSet (I know we can do it only with arrays but let me explain...). I have an entity user who has a relationship to-many with the entity recipe. A recipe has the attributes name and id. I would like to get the data such that: NSArray *id = [[user.recipes valueForKey:@"identity"] ...

Sort list using stl sort function

I'm trying to sort a list (part of a class) in descending containg items of a struct but it doesn't compile(error: no match for 'operator-' in '__last - __first'): sort(Result.poly.begin(), Result.poly.end(), SortDescending()); And here's SortDescending: struct SortDescending { bool operator()(const term& t1, const term& t2) ...

Removing duplicates (within a given tolerance) from a Numpy array of vectors

I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match. Following this thread on Scipy-user, I ca...

Sort by date in XSL

I am trying to sort by date for XML output. Here is my XSL: <?xml version="1.0" encoding="UTF-8"?> <!-- Example by Phil 'iwonder' Guerra --> <!-- Edited by Lee Sykes DNN Creative Magazine http://www.dnncreative.com --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; <xsl:output method="html" inden...