@@ -1899,15 +1899,29 @@ private static Object decodeArrayValue(Type elementType, ListValue listValue) {
18991899 switch (elementType .getCode ()) {
19001900 case BOOL :
19011901 // Use a view: element conversion is virtually free.
1902- return new BoolArray (listValue );
1902+ return Lists .transform (
1903+ listValue .getValuesList (),
1904+ new Function <com .google .protobuf .Value , Boolean >() {
1905+ @ Override
1906+ public Boolean apply (com .google .protobuf .Value input ) {
1907+ return input .getKindCase () == KindCase .NULL_VALUE ? null : input .getBoolValue ();
1908+ }
1909+ });
19031910 case INT64 :
19041911 // For int64/float64 types, use custom containers. These avoid wrapper object
19051912 // creation for non-null arrays.
19061913 return new Int64Array (listValue );
19071914 case FLOAT64 :
19081915 return new Float64Array (listValue );
19091916 case STRING :
1910- return new StringArray (listValue );
1917+ return Lists .transform (
1918+ listValue .getValuesList (),
1919+ new Function <com .google .protobuf .Value , String >() {
1920+ @ Override
1921+ public String apply (com .google .protobuf .Value input ) {
1922+ return input .getKindCase () == KindCase .NULL_VALUE ? null : input .getStringValue ();
1923+ }
1924+ });
19111925 case BYTES :
19121926 {
19131927 // Materialize list: element conversion is expensive and should happen only once.
@@ -2514,44 +2528,4 @@ Double get(double[] array, int i) {
25142528 return array [i ];
25152529 }
25162530 }
2517-
2518- private static class StringArray extends AbstractList <String > implements Serializable {
2519- private static final long serialVersionUID = 695127243179520960L ;
2520- private final ListValue listValue ;
2521-
2522- private StringArray (ListValue listValue ) {
2523- this .listValue = listValue ;
2524- }
2525-
2526- @ Override
2527- public String get (int index ) {
2528- com .google .protobuf .Value value = listValue .getValues (index );
2529- return value .getKindCase () == KindCase .NULL_VALUE ? null : value .getStringValue ();
2530- }
2531-
2532- @ Override
2533- public int size () {
2534- return listValue .getValuesCount ();
2535- }
2536- }
2537-
2538- private static class BoolArray extends AbstractList <Boolean > implements Serializable {
2539- private static final long serialVersionUID = -2850504708084921083L ;
2540- private final ListValue listValue ;
2541-
2542- private BoolArray (ListValue listValue ) {
2543- this .listValue = listValue ;
2544- }
2545-
2546- @ Override
2547- public Boolean get (int index ) {
2548- com .google .protobuf .Value value = listValue .getValues (index );
2549- return value .getKindCase () == KindCase .NULL_VALUE ? null : value .getBoolValue ();
2550- }
2551-
2552- @ Override
2553- public int size () {
2554- return listValue .getValuesCount ();
2555- }
2556- }
25572531}
0 commit comments