package com.heaven7.java.visitor.util;

import java.util.Comparator;

/**
 * some useful comparator.
 * @author heaven7
 * @since 1.1.5
 */
public final class Comparators {
	
	private Comparators(){}
	
	/**
	 * get the default comparator if the target class implements {@linkplain Comparable}.
	 * or else must cause {@linkplain IllegalStateException}
	 * @param <T> the class type who should implements {@linkplain Comparable}.
	 * @return a Comparator who's behaviour same as the {@linkplain Comparable}.
	 * @since 1.1.5
	 */
	@SuppressWarnings("unchecked")
	public static <T extends Comparable<T>> Comparator<T> getDefaultComparator(){
		return (Comparator<T>) DEFAULT_COMPARATOR;
	}

	private static final Comparator<Object> DEFAULT_COMPARATOR = new Comparator<Object>(){
		@SuppressWarnings({ "unchecked", "rawtypes" })
		@Override
		public int compare(Object o1, Object o2) {
			if((o1 instanceof Comparable) && (o2 instanceof Comparable)){
				return ((Comparable)o1).compareTo(o2);
			}
			throw new IllegalStateException("must implements interface Comparable.");
		}
		
	};
}

@@ -707,16 +707,48 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@SuppressWarnings(%22rawtypes%22)%0D%0A
 %09private
@@ -771,24 +771,16 @@
 mparator
-%3CObject%3E
  DEFAULT
@@ -811,16 +811,8 @@
 ator
-%3CObject%3E
 ()%7B%0D
@@ -833,17 +833,16 @@
 rnings(%7B
- 
 %22uncheck
@@ -848,20 +848,8 @@
 ked%22
-, %22rawtypes%22
  %7D)%0D
@@ -914,16 +914,17 @@
 %0D%0A%09%09%09if(
+ 
 (o1 inst
@@ -971,16 +971,17 @@
 parable)
+ 
 )%7B%0D%0A%09%09%09%09

change doc