mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Add a helper for casting some common collection types into generic form
This commit is contained in:
1 parent
123f5919ba
commit
0a9099c8dd
1 file changed
+32
@@ -0,0 +1,32 @@
|
||||
package cpw.mods.fml.common.functions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class CollectionWrapperFactory {
|
||||
/**
|
||||
* Return a read only cast view of the supplied ungeneric collection, based on the element type given
|
||||
* @param coll The collection to cast
|
||||
* @param elementType the supertype contained in the collection
|
||||
* @return a collection asserting that type relationship
|
||||
*/
|
||||
public static <T> Collection<T> wrap(@SuppressWarnings("rawtypes") Collection coll, Class<T> elementType)
|
||||
{
|
||||
Collection<?> asGeneric = coll;
|
||||
return Collections2.transform(asGeneric, new TypeCastFunction<T>(elementType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a read only cast view of the supplied ungeneric list, based on the element type given
|
||||
* @param list The list to cast
|
||||
* @param elementType the supertype contained in the list
|
||||
* @return a list asserting that type relationship
|
||||
*/
|
||||
public static <T> List<T> wrap(@SuppressWarnings("rawtypes") List list, Class<T> elementType)
|
||||
{
|
||||
List<?> asGeneric = list;
|
||||
return Lists.transform(asGeneric, new TypeCastFunction<T>(elementType));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user