Skip to content

Commit

Permalink
Update StdOut
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Nov 5, 2024
1 parent 941c98f commit 9370b51
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions kala-base/src/main/java/kala/io/StdOut.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 Glavo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kala.io;

import kala.annotations.StaticClass;
Expand All @@ -15,26 +30,17 @@ public static void print(Object x) {
if (x == null) {
System.out.print("null");
} else if (x.getClass().isArray()) {
if (x instanceof Object[]) {
print((Object[]) x);
} else if (x instanceof char[]) {
print((char[]) x);
} else if (x instanceof boolean[]) {
print((boolean[]) x);
} else if (x instanceof byte[]) {
print((byte[]) x);
} else if (x instanceof short[]) {
print((short[]) x);
} else if (x instanceof int[]) {
print((int[]) x);
} else if (x instanceof long[]) {
print((long[]) x);
} else if (x instanceof float[]) {
print((float[]) x);
} else if (x instanceof double[]) {
print((double[]) x);
} else {
throw new AssertionError("Unknown array type: " + x.getClass());
switch (x) {
case Object[] objects -> print(objects);
case char[] chars -> print(chars);
case boolean[] booleans -> print(booleans);
case byte[] bytes -> print(bytes);
case short[] shorts -> print(shorts);
case int[] ints -> print(ints);
case long[] longs -> print(longs);
case float[] floats -> print(floats);
case double[] doubles -> print(doubles);
default -> throw new AssertionError("Unknown array type: " + x.getClass());
}
} else {
System.out.print(x);
Expand Down Expand Up @@ -283,26 +289,17 @@ public static void println(Object x) {
if (x == null) {
System.out.println("null");
} else if (x.getClass().isArray()) {
if (x instanceof Object[]) {
println((Object[]) x);
} else if (x instanceof char[]) {
println((char[]) x);
} else if (x instanceof boolean[]) {
println((boolean[]) x);
} else if (x instanceof byte[]) {
println((byte[]) x);
} else if (x instanceof short[]) {
println((short[]) x);
} else if (x instanceof int[]) {
println((int[]) x);
} else if (x instanceof long[]) {
println((long[]) x);
} else if (x instanceof float[]) {
println((float[]) x);
} else if (x instanceof double[]) {
println((double[]) x);
} else {
throw new AssertionError("Unknown array type: " + x.getClass());
switch (x) {
case Object[] objects -> println(objects);
case char[] chars -> println(chars);
case boolean[] booleans -> println(booleans);
case byte[] bytes -> println(bytes);
case short[] shorts -> println(shorts);
case int[] ints -> println(ints);
case long[] longs -> println(longs);
case float[] floats -> println(floats);
case double[] doubles -> println(doubles);
default -> throw new AssertionError("Unknown array type: " + x.getClass());
}
} else {
System.out.println(x);
Expand Down

0 comments on commit 9370b51

Please sign in to comment.