ClassUtils.comparator().

This commit is contained in:
Gary Gregory 2021-07-22 14:27:55 -04:00
parent e09ad8a91a
commit 7d9d4d41a6
3 changed files with 651 additions and 456 deletions

View File

@ -60,6 +60,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ObjectUtils.getClass(T).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ArrayUtils.newInstance(Class&gt;T>, int).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add and use null-safe Streams.of(T...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ClassUtils.comparator().</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump spotbugs-maven-plugin from 4.2.0 to 4.2.3 #735.</action>
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess">Bump Bump actions/cache from v2.1.4 to v2.1.6 #742, #752, #764.</action>

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.commons.lang3.ClassUtils.Interfaces;
import org.apache.commons.lang3.reflect.testbed.GenericConsumer;
@ -1137,6 +1138,24 @@ public class ClassUtilsTest {
assertFalse(ClassUtils.isInnerClass(null));
}
@Test
public void testComparable() {
final TreeMap<Class<?>, String> map = new TreeMap<>(ClassUtils.comparator());
map.put(String.class, "lastEntry");
map.toString();
map.put(Character.class, "firstEntry");
map.toString();
assertEquals("firstEntry", map.firstEntry().getValue());
assertEquals(Character.class, map.firstEntry().getKey());
//
assertEquals("lastEntry", map.lastEntry().getValue());
assertEquals(String.class, map.lastEntry().getKey());
//
map.put(null, "null");
map.toString();
assertEquals("null", map.get(null));
}
@Test
public void testConstructor() {
assertNotNull(new ClassUtils());