minimax4j/src/main/java/fr/avianey/minimax4j/impl/TranspositionNegamax.java
/**
     * Initialize the map of transposition table classified by groups.
     * @return
     * 		A {@link TreeMap} storing transposition tables by group
     */
Initialize the map of transposition table classified by groups.
@return
A  TreeMap storing transposition tables by group
Initialize the map of transposition table classified by groups . @return A TreeMap storing transposition tables by group
@SuppressWarnings("unchecked")
    private TreeMap<G, Map<Integer, Transposition<K>>> initTranspositionTableMap() {
        Type t = getClass().getGenericSuperclass();
        while (!(t instanceof ParameterizedType
                && TranspositionNegamax.class.getSimpleName().equals(
                ((Class<?>) ((ParameterizedType) t).getRawType()).getSimpleName()))) {
            t = ((Class<?>) t).getGenericSuperclass();
        }
        Class<G> cls = (Class<G>) ((ParameterizedType) t).getActualTypeArguments()[2];
        if (Comparable.class.isAssignableFrom(cls)) {
            return new TreeMap<>();
        } else if (cls.isAssignableFrom(Void.class)) {
            return new TreeMap<>(new Comparator<G>() {
                @Override
                public int compare(G o1, G o2) {
                    return 0;
                }
            });
        } else {
            throw new IllegalArgumentException("The transposition group type : " + cls.getSimpleName() + " is neither Void nor implement the java.lang.Comparable interface.");
        }
    }
@ SuppressWarnings ( "unchecked" ) private TreeMap < G , Map < Integer , Transposition < K > > > initTranspositionTableMap ( ) { Type t = getClass ( ) . getGenericSuperclass ( ) ; while ( ! ( t instanceof ParameterizedType && TranspositionNegamax . class . getSimpleName ( ) . equals ( ( ( Class < ? > ) ( ( ParameterizedType ) t ) . getRawType ( ) ) . getSimpleName ( ) ) ) ) { t = ( ( Class < ? > ) t ) . getGenericSuperclass ( ) ; } Class < G > cls = ( Class < G > ) ( ( ParameterizedType ) t ) . getActualTypeArguments ( ) [ 2 ] ; if ( Comparable . class . isAssignableFrom ( cls ) ) { return new TreeMap < > ( ) ; } else if ( cls . isAssignableFrom ( Void . class ) ) { return new TreeMap < > ( new Comparator < G > ( ) { @ Override public int compare ( G o1 , G o2 ) { return 0 ; } } ) ; } else { throw new IllegalArgumentException ( "The transposition group type : " + cls . getSimpleName ( ) + " is neither Void nor implement the java.lang.Comparable interface." ) ; } }
Initialize the map of transposition table classified by groups.
Initialize the map of transposition table classified by groups .
// search for the Group class within class hierarchy // the transposition Group type is Comparable // no transposition Group required // use everything-is-equal Comparator