1111import static fj .data .List .list ;
1212import static fj .data .Option .some ;
1313
14+ import java .util .Arrays ;
15+ import java .util .Collection ;
1416import java .util .ArrayList ;
1517import java .util .BitSet ;
1618import java .util .EnumSet ;
@@ -1723,7 +1725,7 @@ public static <A> F<ArrayList<A>, List<A>> ArrayList_List() {
17231725 return new F <ArrayList <A >, List <A >>() {
17241726 @ SuppressWarnings ({"unchecked" })
17251727 public List <A > f (final ArrayList <A > as ) {
1726- return list (as . toArray (( A []) new Object [ as . size ()]) );
1728+ return Collection_List (as );
17271729 }
17281730 };
17291731 }
@@ -1741,7 +1743,7 @@ public static <A> F<java.util.List<A>, List<A>> JUList_List() {
17411743 return new F <java .util .List <A >, List <A >>() {
17421744 @ SuppressWarnings ({"unchecked" })
17431745 public List <A > f (final java .util .List <A > as ) {
1744- return list (as . toArray (( A []) new Object [ as . size ()]) );
1746+ return Collection_List (as );
17451747 }
17461748 };
17471749 }
@@ -1775,14 +1777,27 @@ public Option<P2<Boolean, Integer>> f(final Integer i) {
17751777 * @return A function that converts enum sets to lists.
17761778 */
17771779 public static <A extends Enum <A >> F <EnumSet <A >, List <A >> EnumSet_List () {
1778- return new F <EnumSet <A >, List <A >>() {
1779- @ SuppressWarnings ({"unchecked" })
1780- public List <A > f (final EnumSet <A > as ) {
1781- return list (as . toArray (( A []) new Object [ as . size ()]) );
1782- }
1783- };
1780+ return new F <EnumSet <A >, List <A >>() {
1781+ @ SuppressWarnings ({"unchecked" })
1782+ public List <A > f (final EnumSet <A > as ) {
1783+ return Collection_List (as );
1784+ }
1785+ };
17841786 }
17851787
1788+ public static <A > List <A > Collection_List (Collection <A > c ) {
1789+ return Java .<A >Collection_List ().f (c );
1790+ }
1791+
1792+ public static <A > F <Collection <A >, List <A >> Collection_List () {
1793+ return c -> list (c .toArray (array (c .size ())));
1794+ }
1795+
1796+ @ SafeVarargs
1797+ private static <E > E [] array (int length , E ... array ) {
1798+ return Arrays .copyOf (array , length );
1799+ }
1800+
17861801 // todo
17871802
17881803 // END EnumSet ->
@@ -1798,7 +1813,7 @@ public static <A> F<HashSet<A>, List<A>> HashSet_List() {
17981813 return new F <HashSet <A >, List <A >>() {
17991814 @ SuppressWarnings ({"unchecked" })
18001815 public List <A > f (final HashSet <A > as ) {
1801- return list (as . toArray (( A []) new Object [ as . size ()]) );
1816+ return Collection_List (as );
18021817 }
18031818 };
18041819 }
@@ -1818,7 +1833,7 @@ public static <A> F<LinkedHashSet<A>, List<A>> LinkedHashSet_List() {
18181833 return new F <LinkedHashSet <A >, List <A >>() {
18191834 @ SuppressWarnings ({"unchecked" })
18201835 public List <A > f (final LinkedHashSet <A > as ) {
1821- return list (as . toArray (( A []) new Object [ as . size ()]) );
1836+ return Collection_List (as );
18221837 }
18231838 };
18241839 }
@@ -1838,7 +1853,7 @@ public static <A> F<LinkedList<A>, List<A>> LinkedList_List() {
18381853 return new F <LinkedList <A >, List <A >>() {
18391854 @ SuppressWarnings ({"unchecked" })
18401855 public List <A > f (final LinkedList <A > as ) {
1841- return list (as . toArray (( A []) new Object [ as . size ()]) );
1856+ return Collection_List (as );
18421857 }
18431858 };
18441859 }
@@ -1858,7 +1873,7 @@ public static <A> F<PriorityQueue<A>, List<A>> PriorityQueue_List() {
18581873 return new F <PriorityQueue <A >, List <A >>() {
18591874 @ SuppressWarnings ({"unchecked" })
18601875 public List <A > f (final PriorityQueue <A > as ) {
1861- return list (as . toArray (( A []) new Object [ as . size ()]) );
1876+ return Collection_List (as );
18621877 }
18631878 };
18641879 }
@@ -1878,7 +1893,7 @@ public static <A> F<Stack<A>, List<A>> Stack_List() {
18781893 return new F <Stack <A >, List <A >>() {
18791894 @ SuppressWarnings ({"unchecked" })
18801895 public List <A > f (final Stack <A > as ) {
1881- return list (as . toArray (( A []) new Object [ as . size ()]) );
1896+ return Collection_List (as );
18821897 }
18831898 };
18841899 }
@@ -1898,7 +1913,7 @@ public static <A> F<TreeSet<A>, List<A>> TreeSet_List() {
18981913 return new F <TreeSet <A >, List <A >>() {
18991914 @ SuppressWarnings ({"unchecked" })
19001915 public List <A > f (final TreeSet <A > as ) {
1901- return list (as . toArray (( A []) new Object [ as . size ()]) );
1916+ return Collection_List (as );
19021917 }
19031918 };
19041919 }
@@ -1918,7 +1933,7 @@ public static <A> F<Vector<A>, List<A>> Vector_List() {
19181933 return new F <Vector <A >, List <A >>() {
19191934 @ SuppressWarnings ({"unchecked" , "UseOfObsoleteCollectionType" })
19201935 public List <A > f (final Vector <A > as ) {
1921- return list (as . toArray (( A []) new Object [ as . size ()]) );
1936+ return Collection_List (as );
19221937 }
19231938 };
19241939 }
@@ -1938,7 +1953,7 @@ public static <A> F<ArrayBlockingQueue<A>, List<A>> ArrayBlockingQueue_List() {
19381953 return new F <ArrayBlockingQueue <A >, List <A >>() {
19391954 @ SuppressWarnings ({"unchecked" })
19401955 public List <A > f (final ArrayBlockingQueue <A > as ) {
1941- return list (as . toArray (( A []) new Object [ as . size ()]) );
1956+ return Collection_List (as );
19421957 }
19431958 };
19441959 }
@@ -1958,7 +1973,7 @@ public static <A> F<ConcurrentLinkedQueue<A>, List<A>> ConcurrentLinkedQueue_Lis
19581973 return new F <ConcurrentLinkedQueue <A >, List <A >>() {
19591974 @ SuppressWarnings ({"unchecked" })
19601975 public List <A > f (final ConcurrentLinkedQueue <A > as ) {
1961- return list (as . toArray (( A []) new Object [ as . size ()]) );
1976+ return Collection_List (as );
19621977 }
19631978 };
19641979 }
@@ -1978,7 +1993,7 @@ public static <A> F<CopyOnWriteArrayList<A>, List<A>> CopyOnWriteArrayList_List(
19781993 return new F <CopyOnWriteArrayList <A >, List <A >>() {
19791994 @ SuppressWarnings ({"unchecked" })
19801995 public List <A > f (final CopyOnWriteArrayList <A > as ) {
1981- return list (as . toArray (( A []) new Object [ as . size ()]) );
1996+ return Collection_List (as );
19821997 }
19831998 };
19841999 }
@@ -1998,7 +2013,7 @@ public static <A> F<CopyOnWriteArraySet<A>, List<A>> CopyOnWriteArraySet_List()
19982013 return new F <CopyOnWriteArraySet <A >, List <A >>() {
19992014 @ SuppressWarnings ({"unchecked" })
20002015 public List <A > f (final CopyOnWriteArraySet <A > as ) {
2001- return list (as . toArray (( A []) new Object [ as . size ()]) );
2016+ return Collection_List (as );
20022017 }
20032018 };
20042019 }
@@ -2018,7 +2033,7 @@ public static <A extends Delayed> F<DelayQueue<A>, List<A>> DelayQueue_List() {
20182033 return new F <DelayQueue <A >, List <A >>() {
20192034 @ SuppressWarnings ({"unchecked" })
20202035 public List <A > f (final DelayQueue <A > as ) {
2021- return list (as . toArray (( A []) new Object [ as . size ()]) );
2036+ return Collection_List (as );
20222037 }
20232038 };
20242039 }
@@ -2038,7 +2053,7 @@ public static <A> F<LinkedBlockingQueue<A>, List<A>> LinkedBlockingQueue_List()
20382053 return new F <LinkedBlockingQueue <A >, List <A >>() {
20392054 @ SuppressWarnings ({"unchecked" })
20402055 public List <A > f (final LinkedBlockingQueue <A > as ) {
2041- return list (as . toArray (( A []) new Object [ as . size ()]) );
2056+ return Collection_List (as );
20422057 }
20432058 };
20442059 }
@@ -2058,7 +2073,7 @@ public static <A> F<PriorityBlockingQueue<A>, List<A>> PriorityBlockingQueue_Lis
20582073 return new F <PriorityBlockingQueue <A >, List <A >>() {
20592074 @ SuppressWarnings ({"unchecked" })
20602075 public List <A > f (final PriorityBlockingQueue <A > as ) {
2061- return list (as . toArray (( A []) new Object [ as . size ()]) );
2076+ return Collection_List (as );
20622077 }
20632078 };
20642079 }
@@ -2078,7 +2093,7 @@ public static <A> F<SynchronousQueue<A>, List<A>> SynchronousQueue_List() {
20782093 return new F <SynchronousQueue <A >, List <A >>() {
20792094 @ SuppressWarnings ({"unchecked" })
20802095 public List <A > f (final SynchronousQueue <A > as ) {
2081- return list (as . toArray (( A []) new Object [ as . size ()]) );
2096+ return Collection_List (as );
20822097 }
20832098 };
20842099 }
0 commit comments