Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
31780ff5
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
31780ff5
编写于
10月 01, 2013
作者:
M
mduigou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8025067: Unconditionally throw NPE if null op provided to Arrays.parallelPrefix
Reviewed-by: henryjen, chegar, psandoz
上级
6029af9d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
147 addition
and
7 deletion
+147
-7
src/share/classes/java/util/Arrays.java
src/share/classes/java/util/Arrays.java
+8
-0
test/java/util/Arrays/ParallelPrefix.java
test/java/util/Arrays/ParallelPrefix.java
+139
-7
未找到文件。
src/share/classes/java/util/Arrays.java
浏览文件 @
31780ff5
...
@@ -1583,6 +1583,7 @@ public class Arrays {
...
@@ -1583,6 +1583,7 @@ public class Arrays {
* @since 1.8
* @since 1.8
*/
*/
public
static
<
T
>
void
parallelPrefix
(
T
[]
array
,
BinaryOperator
<
T
>
op
)
{
public
static
<
T
>
void
parallelPrefix
(
T
[]
array
,
BinaryOperator
<
T
>
op
)
{
Objects
.
requireNonNull
(
op
);
if
(
array
.
length
>
0
)
if
(
array
.
length
>
0
)
new
ArrayPrefixHelpers
.
CumulateTask
<>
new
ArrayPrefixHelpers
.
CumulateTask
<>
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
...
@@ -1606,6 +1607,7 @@ public class Arrays {
...
@@ -1606,6 +1607,7 @@ public class Arrays {
*/
*/
public
static
<
T
>
void
parallelPrefix
(
T
[]
array
,
int
fromIndex
,
public
static
<
T
>
void
parallelPrefix
(
T
[]
array
,
int
fromIndex
,
int
toIndex
,
BinaryOperator
<
T
>
op
)
{
int
toIndex
,
BinaryOperator
<
T
>
op
)
{
Objects
.
requireNonNull
(
op
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
if
(
fromIndex
<
toIndex
)
if
(
fromIndex
<
toIndex
)
new
ArrayPrefixHelpers
.
CumulateTask
<>
new
ArrayPrefixHelpers
.
CumulateTask
<>
...
@@ -1627,6 +1629,7 @@ public class Arrays {
...
@@ -1627,6 +1629,7 @@ public class Arrays {
* @since 1.8
* @since 1.8
*/
*/
public
static
void
parallelPrefix
(
long
[]
array
,
LongBinaryOperator
op
)
{
public
static
void
parallelPrefix
(
long
[]
array
,
LongBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
if
(
array
.
length
>
0
)
if
(
array
.
length
>
0
)
new
ArrayPrefixHelpers
.
LongCumulateTask
new
ArrayPrefixHelpers
.
LongCumulateTask
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
...
@@ -1649,6 +1652,7 @@ public class Arrays {
...
@@ -1649,6 +1652,7 @@ public class Arrays {
*/
*/
public
static
void
parallelPrefix
(
long
[]
array
,
int
fromIndex
,
public
static
void
parallelPrefix
(
long
[]
array
,
int
fromIndex
,
int
toIndex
,
LongBinaryOperator
op
)
{
int
toIndex
,
LongBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
if
(
fromIndex
<
toIndex
)
if
(
fromIndex
<
toIndex
)
new
ArrayPrefixHelpers
.
LongCumulateTask
new
ArrayPrefixHelpers
.
LongCumulateTask
...
@@ -1673,6 +1677,7 @@ public class Arrays {
...
@@ -1673,6 +1677,7 @@ public class Arrays {
* @since 1.8
* @since 1.8
*/
*/
public
static
void
parallelPrefix
(
double
[]
array
,
DoubleBinaryOperator
op
)
{
public
static
void
parallelPrefix
(
double
[]
array
,
DoubleBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
if
(
array
.
length
>
0
)
if
(
array
.
length
>
0
)
new
ArrayPrefixHelpers
.
DoubleCumulateTask
new
ArrayPrefixHelpers
.
DoubleCumulateTask
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
...
@@ -1695,6 +1700,7 @@ public class Arrays {
...
@@ -1695,6 +1700,7 @@ public class Arrays {
*/
*/
public
static
void
parallelPrefix
(
double
[]
array
,
int
fromIndex
,
public
static
void
parallelPrefix
(
double
[]
array
,
int
fromIndex
,
int
toIndex
,
DoubleBinaryOperator
op
)
{
int
toIndex
,
DoubleBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
if
(
fromIndex
<
toIndex
)
if
(
fromIndex
<
toIndex
)
new
ArrayPrefixHelpers
.
DoubleCumulateTask
new
ArrayPrefixHelpers
.
DoubleCumulateTask
...
@@ -1716,6 +1722,7 @@ public class Arrays {
...
@@ -1716,6 +1722,7 @@ public class Arrays {
* @since 1.8
* @since 1.8
*/
*/
public
static
void
parallelPrefix
(
int
[]
array
,
IntBinaryOperator
op
)
{
public
static
void
parallelPrefix
(
int
[]
array
,
IntBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
if
(
array
.
length
>
0
)
if
(
array
.
length
>
0
)
new
ArrayPrefixHelpers
.
IntCumulateTask
new
ArrayPrefixHelpers
.
IntCumulateTask
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
(
null
,
op
,
array
,
0
,
array
.
length
).
invoke
();
...
@@ -1738,6 +1745,7 @@ public class Arrays {
...
@@ -1738,6 +1745,7 @@ public class Arrays {
*/
*/
public
static
void
parallelPrefix
(
int
[]
array
,
int
fromIndex
,
public
static
void
parallelPrefix
(
int
[]
array
,
int
fromIndex
,
int
toIndex
,
IntBinaryOperator
op
)
{
int
toIndex
,
IntBinaryOperator
op
)
{
Objects
.
requireNonNull
(
op
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
rangeCheck
(
array
.
length
,
fromIndex
,
toIndex
);
if
(
fromIndex
<
toIndex
)
if
(
fromIndex
<
toIndex
)
new
ArrayPrefixHelpers
.
IntCumulateTask
new
ArrayPrefixHelpers
.
IntCumulateTask
...
...
test/java/util/Arrays/ParallelPrefix.java
浏览文件 @
31780ff5
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
*/
*/
/**
/**
* @test
* @test
8014076 8025067
* @summary unit test for Arrays.ParallelPrefix().
* @summary unit test for Arrays.ParallelPrefix().
* @author Tristan Yan
* @author Tristan Yan
* @run testng ParallelPrefix
* @run testng ParallelPrefix
...
@@ -54,30 +54,44 @@ public class ParallelPrefix {
...
@@ -54,30 +54,44 @@ public class ParallelPrefix {
private
final
static
int
LARGE_ARRAY_SIZE
=
1
<<
12
;
private
final
static
int
LARGE_ARRAY_SIZE
=
1
<<
12
;
private
final
static
int
[]
ARRAY_SIZE_COLLECTION
=
new
int
[]{
private
final
static
int
[]
ARRAY_SIZE_COLLECTION
=
new
int
[]{
SMALL_ARRAY_SIZE
,
THRESHOLD_ARRAY_SIZE
,
MEDIUM_ARRAY_SIZE
,
LARGE_ARRAY_SIZE
};
SMALL_ARRAY_SIZE
,
THRESHOLD_ARRAY_SIZE
,
MEDIUM_ARRAY_SIZE
,
LARGE_ARRAY_SIZE
};
@DataProvider
@DataProvider
public
static
Object
[][]
intSet
(){
public
static
Object
[][]
intSet
(){
return
genericData
(
size
->
IntStream
.
range
(
0
,
size
).
toArray
(),
new
IntBinaryOperator
[]{
Integer:
:
sum
,
Integer:
:
min
});
return
genericData
(
size
->
IntStream
.
range
(
0
,
size
).
toArray
(),
new
IntBinaryOperator
[]{
Integer:
:
sum
,
Integer:
:
min
});
}
}
@DataProvider
@DataProvider
public
static
Object
[][]
longSet
(){
public
static
Object
[][]
longSet
(){
return
genericData
(
size
->
LongStream
.
range
(
0
,
size
).
toArray
(),
new
LongBinaryOperator
[]{
Long:
:
sum
,
Long:
:
min
});
return
genericData
(
size
->
LongStream
.
range
(
0
,
size
).
toArray
(),
new
LongBinaryOperator
[]{
Long:
:
sum
,
Long:
:
min
});
}
}
@DataProvider
@DataProvider
public
static
Object
[][]
doubleSet
(){
public
static
Object
[][]
doubleSet
(){
return
genericData
(
size
->
IntStream
.
range
(
0
,
size
).
mapToDouble
(
i
->
(
double
)
i
).
toArray
(),
return
genericData
(
size
->
IntStream
.
range
(
0
,
size
).
mapToDouble
(
i
->
(
double
)
i
).
toArray
(),
new
DoubleBinaryOperator
[]{
Double:
:
sum
,
Double:
:
min
});
new
DoubleBinaryOperator
[]{
Double:
:
sum
,
Double:
:
min
});
}
}
@DataProvider
@DataProvider
public
static
Object
[][]
stringSet
(){
public
static
Object
[][]
stringSet
(){
Function
<
Integer
,
String
[]>
stringsFunc
=
size
->
Function
<
Integer
,
String
[]>
stringsFunc
=
size
->
IntStream
.
range
(
0
,
size
).
mapToObj
(
Integer:
:
toString
).
toArray
(
String
[]::
new
);
IntStream
.
range
(
0
,
size
).
mapToObj
(
Integer:
:
toString
).
toArray
(
String
[]::
new
);
BinaryOperator
<
String
>
cancatBop
=
String:
:
concat
;
BinaryOperator
<
String
>
concat
=
String:
:
concat
;
return
genericData
(
stringsFunc
,
new
BinaryOperator
[]{
cancatBop
});
return
genericData
(
stringsFunc
,
(
BinaryOperator
<
String
>[])
new
BinaryOperator
[]{
concat
});
}
}
private
static
<
T
,
OPS
>
Object
[][]
genericData
(
Function
<
Integer
,
T
>
generateFunc
,
OPS
[]
ops
)
{
private
static
<
T
,
OPS
>
Object
[][]
genericData
(
Function
<
Integer
,
T
>
generateFunc
,
OPS
[]
ops
)
{
...
@@ -161,5 +175,123 @@ public class ParallelPrefix {
...
@@ -161,5 +175,123 @@ public class ParallelPrefix {
Arrays
.
parallelPrefix
(
parallelRangeResult
,
op
);
Arrays
.
parallelPrefix
(
parallelRangeResult
,
op
);
assertEquals
(
parallelRangeResult
,
Arrays
.
copyOfRange
(
sequentialResult
,
fromIndex
,
toIndex
));
assertEquals
(
parallelRangeResult
,
Arrays
.
copyOfRange
(
sequentialResult
,
fromIndex
,
toIndex
));
}
}
@Test
public
void
testNPEs
()
{
// null array
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
int
[])
null
,
Integer:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
long
[])
null
,
Long:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
double
[])
null
,
Double:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
String
[])
null
,
String:
:
concat
),
NullPointerException
.
class
,
"should throw NPE"
);
// null array w/ range
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
int
[])
null
,
0
,
0
,
Integer:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
long
[])
null
,
0
,
0
,
Long:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
double
[])
null
,
0
,
0
,
Double:
:
max
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
((
String
[])
null
,
0
,
0
,
String:
:
concat
),
NullPointerException
.
class
,
"should throw NPE"
);
// null op
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
int
[]
{},
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
long
[]
{},
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
double
[]
{},
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
String
[]
{},
null
),
NullPointerException
.
class
,
"should throw NPE"
);
// null op w/ range
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
int
[]
{},
0
,
0
,
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
long
[]
{},
0
,
0
,
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
double
[]
{},
0
,
0
,
null
),
NullPointerException
.
class
,
"should throw NPE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
String
[]
{},
0
,
0
,
null
),
NullPointerException
.
class
,
"should throw NPE"
);
}
@Test
public
void
testIAEs
()
{
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
int
[]
{},
1
,
0
,
Integer:
:
max
),
IllegalArgumentException
.
class
,
"should throw IAE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
long
[]
{},
1
,
0
,
Long:
:
max
),
IllegalArgumentException
.
class
,
"should throw IAE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
double
[]
{},
1
,
0
,
Double:
:
max
),
IllegalArgumentException
.
class
,
"should throw IAE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
String
[]
{},
1
,
0
,
String:
:
concat
),
IllegalArgumentException
.
class
,
"should throw IAE"
);
}
@Test
public
void
testAIOBEs
()
{
// bad "fromIndex"
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
int
[]
{},
-
1
,
0
,
Integer:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
long
[]
{},
-
1
,
0
,
Long:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
double
[]
{},
-
1
,
0
,
Double:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
String
[]
{},
-
1
,
0
,
String:
:
concat
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
// bad "toIndex"
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
int
[]
{},
0
,
1
,
Integer:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
long
[]
{},
0
,
1
,
Long:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
double
[]
{},
0
,
1
,
Double:
:
max
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
assertThrows
(
()
->
Arrays
.
parallelPrefix
(
new
String
[]
{},
0
,
1
,
String:
:
concat
),
ArrayIndexOutOfBoundsException
.
class
,
"should throw AIOBE"
);
}
// "library" code
public
interface
Thrower
<
T
extends
Throwable
>
{
public
void
run
()
throws
T
;
}
public
static
<
T
extends
Throwable
>
void
assertThrows
(
Thrower
<
T
>
thrower
,
Class
<
T
>
throwable
)
{
assertThrows
(
thrower
,
throwable
,
null
);
}
public
static
<
T
extends
Throwable
>
void
assertThrows
(
Thrower
<
T
>
thrower
,
Class
<
T
>
throwable
,
String
message
)
{
Throwable
thrown
;
try
{
thrower
.
run
();
thrown
=
null
;
}
catch
(
Throwable
caught
)
{
thrown
=
caught
;
}
assertInstance
(
thrown
,
throwable
,
((
null
!=
message
)
?
message
:
""
)
+
" Failed to throw "
+
throwable
.
getCanonicalName
());
}
public
static
<
T
extends
Throwable
>
void
assertThrows
(
Class
<
T
>
throwable
,
String
message
,
Thrower
<
T
>...
throwers
)
{
for
(
Thrower
<
T
>
thrower
:
throwers
)
{
assertThrows
(
thrower
,
throwable
,
message
);
}
}
public
static
void
assertInstance
(
Object
actual
,
Class
<?>
expected
)
{
assertInstance
(
expected
.
isInstance
(
actual
),
null
);
}
public
static
void
assertInstance
(
Object
actual
,
Class
<?>
expected
,
String
message
)
{
assertTrue
(
expected
.
isInstance
(
actual
),
message
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录