< prev index next > test/jdk/java/util/Arrays/ArrayObjectMethods.java
Print this page
/*
! * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
* @test
* @bug 4906359 6239296
* @summary Basic test for content-based array object methods
* @author Josh Bloch, Martin Buchholz
* @key randomness
+ * @library /test/lib
*/
import java.util.*;
import java.io.*;
+ import jdk.test.lib.valueclass.AsValueClass;
+
public class ArrayObjectMethods {
+
+ @AsValueClass
+ record V(int x, int y) implements Serializable {}
+
int[] sizes = {0, 10, 100, 200, 1000};
void test(String[] args) throws Throwable {
equal(Arrays.deepToString(null), "null");
equal(Arrays.deepToString(new Object[]{}), "[]");
default: return rnd.nextFloat();
}
}
public static Object nextObject() {
! switch(rnd.nextInt(10)) {
case 0: return null;
case 1: return "foo";
! case 2: case 3: case 4:
! return Double.valueOf(nextDouble());
default: return Integer.valueOf(nextInt());
}
}
public static long[] longArray(int length) {
default: return rnd.nextFloat();
}
}
public static Object nextObject() {
! switch(rnd.nextInt(12)) {
case 0: return null;
case 1: return "foo";
! case 2: case 3: case 4: return Double.valueOf(nextDouble());
! case 5: case 6: return nextV();
default: return Integer.valueOf(nextInt());
}
}
public static long[] longArray(int length) {
for (int i = 0; i < length; i++)
result[i] = Rnd.nextObject();
return result;
}
+ public static ArrayObjectMethods.V nextV() {
+ return new ArrayObjectMethods.V(nextInt(), nextInt());
+ }
+
+ public static ArrayObjectMethods.V[] vArray(int length) {
+ ArrayObjectMethods.V[] result = new ArrayObjectMethods.V[length];
+ for (int i = 0; i < length; i++)
+ result[i] = nextV();
+ return result;
+ }
+
// Calling this for length >> 100 is likely to run out of memory! It
// should be perhaps be tuned to allow for longer arrays
public static Object[] nestedObjectArray(int length) {
Object[] result = new Object[length];
for (int i = 0; i < length; i++) {
break;
case 7: result[i] = doubleArray(length/2);
break;
case 8: result[i] = longArray(length/2);
break;
+ case 9: result[i] = vArray(length/2);
+ break;
+ case 10: result[i] = nextV();
+ break;
default: result[i] = Rnd.nextObject();
}
}
return result;
}
< prev index next >