maidh91 / guava-libraries

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

Add ComparisonChain.compareToIgnoreCase #416

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the current implementation of com.google.common.collect.ComparisonChain, 
there's no direct way to compare two strings while ignoring case. This would be 
useful for case-insensitive comparison of entries in a table, among other 
things.

Therefore, I propose adding a method compareToIgnoreCase(String,String) to the 
aforementioned class.

Original issue reported on code.google.com by qforce....@gmail.com on 13 Sep 2010 at 11:05

GoogleCodeExporter commented 9 years ago
Simple as, com.google.common.collect.ComparisonChain.compare("SomeString", 
"somestring", String.CASE_INSENSITIVE_ORDER);

Original comment by amer...@gmail.com on 13 Sep 2010 at 12:24

GoogleCodeExporter commented 9 years ago
O.o

This indeed solves the problem. However, I don't find it obvious at all, 
because I think most people (like me a couple minutes ago) don't even know 
String.CASE_INSENSITIVE_ORDER exists, because they never use it.

So perhaps it would be a good idea to add compareToIgnoreCase nonetheless, or 
to point out in the API doc that you can do something like this.

Original comment by qforce....@gmail.com on 13 Sep 2010 at 12:46

GoogleCodeExporter commented 9 years ago
... and the second one is shorter:

compare("SomeString", "somestring", String.CASE_INSENSITIVE_ORDER);
compareIgnoreCase("SomeString", "somestring");

Original comment by qforce....@gmail.com on 13 Sep 2010 at 1:08

GoogleCodeExporter commented 9 years ago
Sorry if this sound pedantic (because i'm not, i've learned this the hard way 
:p), but every java programmer should know JDK foundation classes such as 
java.lang.* and java.util.* and so on, cf. 
http://java.sun.com/docs/books/effective/toc.html Item 47 which said that it is 
good to take some time to read APIs just to have some vocabulary.

So I don't think adding compareToIgnoreCase is a good thing but as you said 
pointing out the tip in doc would be cool.

^.^

Original comment by amer...@gmail.com on 13 Sep 2010 at 1:12

GoogleCodeExporter commented 9 years ago
Agreed :)

Original comment by qforce....@gmail.com on 13 Sep 2010 at 1:16

GoogleCodeExporter commented 9 years ago
String.CASE_INSENSITIVE_ORDER is but one comparator among thousands out there; 
it's not for us to try to advertise them. 

Original comment by kevinb@google.com on 13 Sep 2010 at 11:48

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:09