@@ -32,22 +32,24 @@ internal class ColumnDataHolderImpl<T> private constructor(
3232 internal fun <T > of (list : Collection <T >, type : KType , distinct : Lazy <Set <T >>? = null): ColumnDataHolder <T > {
3333 if (list is ColumnDataHolder <* >) return list as ColumnDataHolder <T >
3434
35- return try {
36- when (type) {
37- BOOLEAN -> ColumnDataHolderImpl ((list as Collection <Boolean >).toBooleanArray().asList(), distinct)
38- BYTE -> ColumnDataHolderImpl ((list as Collection <Byte >).toByteArray().asList(), distinct)
39- SHORT -> ColumnDataHolderImpl ((list as Collection <Short >).toShortArray().asList(), distinct)
40- INT -> ColumnDataHolderImpl ((list as Collection <Int >).toIntArray().asList(), distinct)
41- LONG -> ColumnDataHolderImpl ((list as Collection <Long >).toLongArray().asList(), distinct)
42- FLOAT -> ColumnDataHolderImpl ((list as Collection <Float >).toFloatArray().asList(), distinct)
43- DOUBLE -> ColumnDataHolderImpl ((list as Collection <Double >).toDoubleArray().asList(), distinct)
44- CHAR -> ColumnDataHolderImpl ((list as Collection <Char >).toCharArray().asList(), distinct)
45- UBYTE -> ColumnDataHolderImpl ((list as Collection <UByte >).toUByteArray().asList(), distinct)
46- USHORT -> ColumnDataHolderImpl ((list as Collection <UShort >).toUShortArray().asList(), distinct)
47- UINT -> ColumnDataHolderImpl ((list as Collection <UInt >).toUIntArray().asList(), distinct)
48- ULONG -> ColumnDataHolderImpl ((list as Collection <ULong >).toULongArray().asList(), distinct)
49- else -> ColumnDataHolderImpl (list.asList(), distinct)
50- } as ColumnDataHolder <T >
35+ try {
36+ val newList = when (type) {
37+ BOOLEAN -> (list as Collection <Boolean >).toBooleanArray().asList()
38+ BYTE -> (list as Collection <Byte >).toByteArray().asList()
39+ SHORT -> (list as Collection <Short >).toShortArray().asList()
40+ INT -> (list as Collection <Int >).toIntArray().asList()
41+ LONG -> (list as Collection <Long >).toLongArray().asList()
42+ FLOAT -> (list as Collection <Float >).toFloatArray().asList()
43+ DOUBLE -> (list as Collection <Double >).toDoubleArray().asList()
44+ CHAR -> (list as Collection <Char >).toCharArray().asList()
45+ UBYTE -> (list as Collection <UByte >).toUByteArray().asList()
46+ USHORT -> (list as Collection <UShort >).toUShortArray().asList()
47+ UINT -> (list as Collection <UInt >).toUIntArray().asList()
48+ ULONG -> (list as Collection <ULong >).toULongArray().asList()
49+ else -> list.asList()
50+ } as List <T >
51+
52+ return ColumnDataHolderImpl (newList, distinct)
5153 } catch (e: Exception ) {
5254 throw IllegalArgumentException (" Can't create ColumnDataHolder from $list and type $type " , e)
5355 }
@@ -59,83 +61,63 @@ internal class ColumnDataHolderImpl<T> private constructor(
5961 * wrapped with [asList].
6062 */
6163 @Suppress(" UNCHECKED_CAST" )
62- internal fun <T > of (array : Array <T >, type : KType , distinct : Lazy <Set <T >>? = null): ColumnDataHolder <T > =
64+ internal fun <T > of (array : Array <T >, type : KType , distinct : Lazy <Set <T >>? = null): ColumnDataHolder <T > {
6365 try {
64- when (type) {
65- BOOLEAN -> ColumnDataHolderImpl ((array as Array <Boolean >).toBooleanArray().asList(), distinct)
66- BYTE -> ColumnDataHolderImpl ((array as Array <Byte >).toByteArray().asList(), distinct)
67- SHORT -> ColumnDataHolderImpl ((array as Array <Short >).toShortArray().asList(), distinct)
68- INT -> ColumnDataHolderImpl ((array as Array <Int >).toIntArray().asList(), distinct)
69- LONG -> ColumnDataHolderImpl ((array as Array <Long >).toLongArray().asList(), distinct)
70- FLOAT -> ColumnDataHolderImpl ((array as Array <Float >).toFloatArray().asList(), distinct)
71- DOUBLE -> ColumnDataHolderImpl ((array as Array <Double >).toDoubleArray().asList(), distinct)
72- CHAR -> ColumnDataHolderImpl ((array as Array <Char >).toCharArray().asList(), distinct)
73- UBYTE -> ColumnDataHolderImpl ((array as Array <UByte >).toUByteArray().asList(), distinct)
74- USHORT -> ColumnDataHolderImpl ((array as Array <UShort >).toUShortArray().asList(), distinct)
75- UINT -> ColumnDataHolderImpl ((array as Array <UInt >).toUIntArray().asList(), distinct)
76- ULONG -> ColumnDataHolderImpl ((array as Array <ULong >).toULongArray().asList(), distinct)
77- else -> ColumnDataHolderImpl (array.asList(), distinct)
78- } as ColumnDataHolder <T >
66+ val list = when (type) {
67+ BOOLEAN -> (array as Array <Boolean >).toBooleanArray().asList()
68+ BYTE -> (array as Array <Byte >).toByteArray().asList()
69+ SHORT -> (array as Array <Short >).toShortArray().asList()
70+ INT -> (array as Array <Int >).toIntArray().asList()
71+ LONG -> (array as Array <Long >).toLongArray().asList()
72+ FLOAT -> (array as Array <Float >).toFloatArray().asList()
73+ DOUBLE -> (array as Array <Double >).toDoubleArray().asList()
74+ CHAR -> (array as Array <Char >).toCharArray().asList()
75+ UBYTE -> (array as Array <UByte >).toUByteArray().asList()
76+ USHORT -> (array as Array <UShort >).toUShortArray().asList()
77+ UINT -> (array as Array <UInt >).toUIntArray().asList()
78+ ULONG -> (array as Array <ULong >).toULongArray().asList()
79+ else -> array.asList()
80+ } as List <T >
81+
82+ return ColumnDataHolderImpl (list, distinct)
7983 } catch (e: Exception ) {
8084 throw IllegalArgumentException (
8185 " Can't create ColumnDataHolder from $array and mismatching type $type " ,
8286 e
8387 )
8488 }
89+ }
8590
8691 /* *
8792 * Constructs [ColumnDataHolderImpl] using an [asList] wrapper around the [primitiveArray].
8893 * [primitiveArray] must be an array of primitives, returns `null` if something goes wrong.
8994 */
9095 @Suppress(" UNCHECKED_CAST" )
91- internal fun <T > of (primitiveArray : Any , type : KType , distinct : Lazy <Set <T >>? = null): ColumnDataHolder <T > =
92- when {
93- type == BOOLEAN && primitiveArray is BooleanArray ->
94- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
95-
96- type == BYTE && primitiveArray is ByteArray ->
97- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
98-
99- type == SHORT && primitiveArray is ShortArray ->
100- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
101-
102- type == INT && primitiveArray is IntArray ->
103- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
104-
105- type == LONG && primitiveArray is LongArray ->
106- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
107-
108- type == FLOAT && primitiveArray is FloatArray ->
109- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
110-
111- type == DOUBLE && primitiveArray is DoubleArray ->
112- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
113-
114- type == CHAR && primitiveArray is CharArray ->
115- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
116-
117- type == UBYTE && primitiveArray is UByteArray ->
118- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
119-
120- type == USHORT && primitiveArray is UShortArray ->
121- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
122-
123- type == UINT && primitiveArray is UIntArray ->
124- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
125-
126- type == ULONG && primitiveArray is ULongArray ->
127- ColumnDataHolderImpl (primitiveArray.asList(), distinct)
96+ internal fun <T > of (primitiveArray : Any , type : KType , distinct : Lazy <Set <T >>? = null): ColumnDataHolder <T > {
97+ val newList = when {
98+ type == BOOLEAN && primitiveArray is BooleanArray -> primitiveArray.asList()
99+ type == BYTE && primitiveArray is ByteArray -> primitiveArray.asList()
100+ type == SHORT && primitiveArray is ShortArray -> primitiveArray.asList()
101+ type == INT && primitiveArray is IntArray -> primitiveArray.asList()
102+ type == LONG && primitiveArray is LongArray -> primitiveArray.asList()
103+ type == FLOAT && primitiveArray is FloatArray -> primitiveArray.asList()
104+ type == DOUBLE && primitiveArray is DoubleArray -> primitiveArray.asList()
105+ type == CHAR && primitiveArray is CharArray -> primitiveArray.asList()
106+ type == UBYTE && primitiveArray is UByteArray -> primitiveArray.asList()
107+ type == USHORT && primitiveArray is UShortArray -> primitiveArray.asList()
108+ type == UINT && primitiveArray is UIntArray -> primitiveArray.asList()
109+ type == ULONG && primitiveArray is ULongArray -> primitiveArray.asList()
110+ ! primitiveArray.isPrimitiveArray -> throw IllegalArgumentException (
111+ " Can't create ColumnDataHolder from non primitive array $primitiveArray and type $type "
112+ )
128113
129- ! primitiveArray.isPrimitiveArray ->
130- throw IllegalArgumentException (
131- " Can't create ColumnDataHolder from non primitive array $primitiveArray and type $type "
132- )
114+ else -> throw IllegalArgumentException (
115+ " Can't create ColumnDataHolder from primitive array $primitiveArray and type $type "
116+ )
117+ } as List < T >
133118
134- else ->
135- throw IllegalArgumentException (
136- " Can't create ColumnDataHolder from primitive array $primitiveArray and type $type "
137- )
138- } as ColumnDataHolder <T >
119+ return ColumnDataHolderImpl (newList, distinct)
120+ }
139121 }
140122}
141123
0 commit comments