maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Expose a KeyedOrdering interface to use in outputting compared values #362

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
[Sorry about the summary... if someone can come up with a better one, feel 
free to update...]

I've found it useful to be able to order a collection and be able to get 
the "ordering key" from the first or last value in the collection, or even 
just to put out in information about iterating through a collection.  
Consider the following:

List<Invoices> invoices;
Function<Invoice, Date> invoiceDateFunction;
KeyedOrdering dateOrdering = 
Ordering.natural().onResultOf(invoiceDateFunction);
Collections.sort(invoices, dateOrdering);
for (Invoice i : invoices){
   println("Processing invoice for date: " + dateOrdering.getKey(i);
}

or:

Date firstInvoiceDate = Ordering.getMinKey(invoices, dateOrdering);

Original issue reported on code.google.com by stephen....@gmail.com on 20 May 2010 at 11:24

GoogleCodeExporter commented 9 years ago
I did not fully understand your request. What's wrong with 
dateOrdering.min(invoices) and dateOrdering.max(invoices) respectively?

Original comment by w.schoen...@gmail.com on 14 Jul 2010 at 3:23

GoogleCodeExporter commented 9 years ago
Aw, snap! Just saw you want to get the Date, not the Invoice. What about 
calling your function again? It's the function's responsibility to retrieve a 
Date from an Invoice, isn't it?

Original comment by w.schoen...@gmail.com on 14 Jul 2010 at 3:24

GoogleCodeExporter commented 9 years ago
Absent further information we assume there's nothing to do here.

Original comment by fry@google.com on 28 Jul 2011 at 5:17

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10