LogManagerProperties extends Properties { @SuppressWarnings("unchecked") static <T> Comparator<T> reverseOrder(final Comparator<T> c) { if (c == null) { throw new NullPointerException(); } Comparator<T> reverse = null; try { final Method m = c.getClass().getMethod("reversed"); if (!Modifier.isStatic(m.getModifiers()) && Comparator.class.isAssignableFrom(m.getReturnType())) { try { reverse = (Comparator<T>) m.invoke(c); } catch (final ExceptionInInitializerError eiie) { throw wrapOrThrow(eiie); } } } catch (final NoSuchMethodException ignore) { } catch (final IllegalAccessException ignore) { } catch (final RuntimeException ignore) { } catch (final InvocationTargetException ite) { paramOrError(ite); } if (reverse == null) { reverse = Collections.reverseOrder(c); } return reverse; } LogManagerProperties(final Properties parent, final String prefix); @Override @SuppressWarnings("CloneDoesntCallSuperClone") synchronized Object clone(); @Override synchronized String getProperty(final String key); @Override String getProperty(final String key, final String def); @Override Object get(final Object key); @Override synchronized Object put(final Object key, final Object value); @Override Object setProperty(String key, String value); @Override boolean containsKey(final Object key); @Override synchronized Object remove(final Object key); @Override Enumeration<?> propertyNames(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testReverseOrder() throws Exception { try { LogManagerProperties.reverseOrder(null); fail("Null was allowed."); } catch (NullPointerException expect) { } Comparator<LogRecord> c = new ErrorComparator(); Comparator<LogRecord> r = LogManagerProperties.reverseOrder(c); assertTrue(c.getClass() != r.getClass()); assertFalse(r instanceof ErrorComparator); assertFalse(r instanceof AscComparator); assertFalse(r instanceof DescComparator); c = new AscComparator(); r = LogManagerProperties.reverseOrder(c); assertTrue(r instanceof DescComparator); c = new AscComparator(); r = LogManagerProperties.reverseOrder(c); assertTrue(r instanceof DescComparator); }