package com.techshroom.mods.common;

import com.google.common.base.Optional;

/**
 * Generic functionalities for cleaner generic code.
 * 
 * @author Kenzie Togami
 */
public final class Generics {
    /**
     * Common {@code Optional<X>} as {@code Optional<Y>} functionality.
     * 
     * @param original
     *            - original Optional instance
     * @param castTo
     *            - class of Y
     * @return the original Optional as an {@code Optional<Y>} if X is actually
     *         a Y, otherwise {@link Optional#absent()}.
     */
    @SuppressWarnings("unchecked")
    public static <X, Y> Optional<Y> castOptional(Optional<X> original,
            Class<Y> castTo) {
        Optional<Y> itemStackOpt = Optional.absent();
        if (castTo.isInstance(original.orNull())) {
            // unsafe cast for less object creation
            itemStackOpt = (Optional<Y>) (Object) original;
        }
        return itemStackOpt;
    }

    private Generics() {
        throw new AssertionError();
    }
}

@@ -41,39 +41,133 @@
 ort 
-com.google.common.base.Optional
+java.lang.reflect.Array;%0Aimport java.util.Map;%0A%0Aimport com.google.common.base.Optional;%0Aimport com.google.common.collect.Maps
 ;%0A%0A/
@@ -1042,16 +1042,563 @@
 %0A    %7D%0A%0A
+    private static final Map%3CClass%3C?%3E, Object%3E ARRAYS = Maps.newConcurrentMap();%0A%0A    /**%0A     * Generic empty array sharing, for performance reasons.%0A     * %0A     * @param forceT%0A     *            - force type parameter with this class%0A     * %0A     * @return an empty array of type T%0A     */%0A    @SuppressWarnings(%22unchecked%22)%0A    public static %3CT%3E T%5B%5D emptyArray(Class%3CT%3E forceT) %7B%0A        if (!ARRAYS.containsKey(forceT)) %7B%0A            ARRAYS.put(forceT, Array.newInstance(forceT, 0));%0A        %7D%0A        return (T%5B%5D) ARRAYS.get(forceT);%0A    %7D%0A%0A
     priv

Fix generics class