Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4a117002
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看板
提交
4a117002
编写于
6月 10, 2013
作者:
P
psandoz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8015492: Remove DoubleStream.range methods
Reviewed-by: alanb
上级
bcb20e82
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
9 addition
and
301 deletion
+9
-301
src/share/classes/java/util/stream/DoubleStream.java
src/share/classes/java/util/stream/DoubleStream.java
+0
-71
src/share/classes/java/util/stream/Streams.java
src/share/classes/java/util/stream/Streams.java
+0
-81
test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestDataProvider.java
...ootlib/java/util/stream/DoubleStreamTestDataProvider.java
+0
-22
test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java
...est/org/openjdk/tests/java/util/stream/ExplodeOpTest.java
+2
-2
test/java/util/stream/test/org/openjdk/tests/java/util/stream/ForEachOpTest.java
...est/org/openjdk/tests/java/util/stream/ForEachOpTest.java
+1
-1
test/java/util/stream/test/org/openjdk/tests/java/util/stream/RangeTest.java
...am/test/org/openjdk/tests/java/util/stream/RangeTest.java
+0
-118
test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java
...org/openjdk/tests/java/util/stream/StreamBuilderTest.java
+5
-5
test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java
...openjdk/tests/java/util/stream/StreamSpliteratorTest.java
+1
-1
未找到文件。
src/share/classes/java/util/stream/DoubleStream.java
浏览文件 @
4a117002
...
...
@@ -753,75 +753,4 @@ public interface DoubleStream extends BaseStream<Double, DoubleStream> {
},
Spliterator
.
ORDERED
|
Spliterator
.
IMMUTABLE
|
Spliterator
.
NONNULL
));
}
/**
* Returns a sequential {@code DoubleStream} from {@code startInclusive} (inclusive)
* to {@code endExclusive} (exclusive) by an incremental step of 1.0.
*
* @implSpec
* The implementation behaves as if:
* <pre>{@code
* doubleRange(startInclusive, endExclusive, 1.0);
* }</pre>
*
* @param startInclusive the (inclusive) initial value
* @param endExclusive the exclusive upper bound
* @return a sequential {@code DoubleStream} for the range of {@code double}
* elements
*/
public
static
DoubleStream
range
(
double
startInclusive
,
double
endExclusive
)
{
return
range
(
startInclusive
,
endExclusive
,
1.0
);
}
/**
* Returns a sequential {@code DoubleStream} from {@code startInclusive}
* (inclusive) to {@code endExclusive} (exclusive) by {@code step}. If
* {@code startInclusive} is greater than or equal to {@code
* endExclusive}, an empty stream is returned.
*
* An equivalent sequence of increasing values can be produced
* sequentially using a {@code for} loop as follows:
* <pre>{@code
* long size = (long) Math.ceil((startInclusive - endExclusive) / step);
* long i = 0
* for (double v = startInclusive; i < size; i++, v = startInclusive + step * i) {
* ...
* }
* }</pre>
*
* @param startInclusive the (inclusive) initial value
* @param endExclusive the exclusive upper bound
* @param step the difference between consecutive values
* @return a sequential {@code DoubleStream} for tne range of {@code double}
* elements
* @throws IllegalArgumentException if {@code step} is less than or equal to
* 0. is {@code NaN}, or the count of elements in the range would be
* greater than {@code Long.MAX_VALUE}
*/
public
static
DoubleStream
range
(
double
startInclusive
,
double
endExclusive
,
double
step
)
{
// @@@ Need to check for ranges that may not produce distinct values
// such as when the step is very small
// Also clarify the size of the range which may produce more or less
// than expected
if
(
step
<=
0
||
Double
.
isNaN
(
step
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Illegal step: %f"
,
step
));
}
else
{
double
range
=
endExclusive
-
startInclusive
;
if
(
range
<=
0
)
{
return
empty
();
}
double
size
=
Math
.
ceil
((
endExclusive
-
startInclusive
)
/
step
);
if
(
Double
.
isNaN
(
size
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Illegal range: %f size is NaN"
,
size
));
}
else
if
(
size
>
Long
.
MAX_VALUE
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Illegal range: size %f > Long.MAX_VALUE"
,
size
));
}
else
{
return
StreamSupport
.
doubleStream
(
new
Streams
.
RangeDoubleSpliterator
(
startInclusive
,
endExclusive
,
step
,
0
,
(
long
)
size
));
}
}
}
}
src/share/classes/java/util/stream/Streams.java
浏览文件 @
4a117002
...
...
@@ -192,87 +192,6 @@ class Streams {
}
}
/**
* A {@code double} range spliterator.
*
* <p>The traversing and splitting logic is equivalent to that of
* {@code RangeLongSpliterator} for increasing values with a {@code step} of
* {@code 1}.
*
* <p>A {@code double} value is calculated from the function
* {@code start + i * step} where {@code i} is the absolute position of the
* value when traversing an instance of this class that has not been split.
* This ensures the same values are produced at the same absolute positions
* regardless of how an instance of this class is split or traversed.
*/
static
final
class
RangeDoubleSpliterator
implements
Spliterator
.
OfDouble
{
private
final
double
from
;
private
final
double
upTo
;
private
final
double
step
;
private
long
lFrom
;
private
final
long
lUpTo
;
RangeDoubleSpliterator
(
double
from
,
double
upTo
,
double
step
,
long
lFrom
,
long
lUpTo
)
{
this
.
from
=
from
;
this
.
upTo
=
upTo
;
this
.
step
=
step
;
this
.
lFrom
=
lFrom
;
this
.
lUpTo
=
lUpTo
;
}
@Override
public
boolean
tryAdvance
(
DoubleConsumer
consumer
)
{
boolean
hasNext
=
lFrom
<
lUpTo
;
if
(
hasNext
)
{
consumer
.
accept
(
from
+
lFrom
*
step
);
lFrom
++;
}
return
hasNext
;
}
@Override
public
void
forEachRemaining
(
DoubleConsumer
consumer
)
{
double
hOrigin
=
from
;
double
hStep
=
step
;
long
hLUpTo
=
lUpTo
;
long
i
=
lFrom
;
for
(;
i
<
hLUpTo
;
i
++)
{
consumer
.
accept
(
hOrigin
+
i
*
hStep
);
}
lFrom
=
i
;
}
@Override
public
long
estimateSize
()
{
return
lUpTo
-
lFrom
;
}
@Override
public
int
characteristics
()
{
return
Spliterator
.
ORDERED
|
Spliterator
.
SIZED
|
Spliterator
.
SUBSIZED
|
Spliterator
.
IMMUTABLE
|
Spliterator
.
NONNULL
|
Spliterator
.
DISTINCT
|
Spliterator
.
SORTED
;
}
@Override
public
Comparator
<?
super
Double
>
getComparator
()
{
return
null
;
}
@Override
public
Spliterator
.
OfDouble
trySplit
()
{
return
estimateSize
()
<=
1
?
null
:
new
RangeDoubleSpliterator
(
from
,
upTo
,
step
,
lFrom
,
lFrom
=
lFrom
+
midPoint
());
}
private
long
midPoint
()
{
// Size is known to be >= 2
return
(
lUpTo
-
lFrom
)
/
2
;
}
}
private
static
abstract
class
AbstractStreamBuilderImpl
<
T
,
S
extends
Spliterator
<
T
>>
implements
Spliterator
<
T
>
{
// >= 0 when building, < 0 when built
// -1 == no elements
...
...
test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestDataProvider.java
浏览文件 @
4a117002
...
...
@@ -92,15 +92,6 @@ public class DoubleStreamTestDataProvider {
}
list
.
add
(
new
Object
[]{
"SpinedList:"
+
name
,
TestData
.
Factory
.
ofSpinedBuffer
(
"SpinedList:"
+
name
,
isl
)});
list
.
add
(
streamDataDescr
(
"Primitives.range(0,l): "
+
doubles
.
length
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
)));
list
.
add
(
streamDataDescr
(
"Primitives.range(0,l,2): "
+
doubles
.
length
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
2
)));
list
.
add
(
streamDataDescr
(
"Primitives.range(0,l,3): "
+
doubles
.
length
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
3
)));
list
.
add
(
streamDataDescr
(
"Primitives.range(0,l,7): "
+
doubles
.
length
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
7
)));
}
testData
=
list
.
toArray
(
new
Object
[
0
][]);
}
...
...
@@ -128,15 +119,6 @@ public class DoubleStreamTestDataProvider {
()
->
Spliterators
.
spliterator
(
isl
.
iterator
(),
doubles
.
length
,
0
)));
spliterators
.
add
(
splitDescr
(
"Primitives.s(SpinedBuffer.iterator()):"
+
name
,
()
->
Spliterators
.
spliteratorUnknownSize
(
isl
.
iterator
(),
0
)));
spliterators
.
add
(
splitDescr
(
"Primitives.range(0,l):"
+
name
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
).
spliterator
()));
spliterators
.
add
(
splitDescr
(
"Primitives.range(0,l,2):"
+
name
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
2
).
spliterator
()));
spliterators
.
add
(
splitDescr
(
"Primitives.range(0,l,3):"
+
name
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
3
).
spliterator
()));
spliterators
.
add
(
splitDescr
(
"Primitives.range(0,l,7):"
+
name
,
()
->
DoubleStream
.
range
(
0
,
doubles
.
length
,
7
).
spliterator
()));
// Need more!
}
spliteratorTestData
=
spliterators
.
toArray
(
new
Object
[
0
][]);
...
...
@@ -144,10 +126,6 @@ public class DoubleStreamTestDataProvider {
}
static
<
T
>
Object
[]
streamDataDescr
(
String
description
,
Supplier
<
DoubleStream
>
s
)
{
return
new
Object
[]
{
description
,
TestData
.
Factory
.
ofDoubleSupplier
(
description
,
s
)
};
}
static
<
T
>
Object
[]
splitDescr
(
String
description
,
Supplier
<
Spliterator
.
OfDouble
>
s
)
{
return
new
Object
[]
{
description
,
s
};
}
...
...
test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java
浏览文件 @
4a117002
...
...
@@ -110,7 +110,7 @@ public class ExplodeOpTest extends OpTestCase {
result
=
exerciseOps
(
data
,
s
->
DoubleStream
.
empty
());
assertEquals
(
0
,
result
.
size
());
exerciseOps
(
data
,
s
->
s
.
flatMap
(
e
->
DoubleStream
.
range
(
0
,
e
)));
exerciseOps
(
data
,
s
->
s
.
flatMap
(
e
->
DoubleStream
.
range
(
0
,
e
).
limit
(
10
)));
exerciseOps
(
data
,
s
->
s
.
flatMap
(
e
->
IntStream
.
range
(
0
,
(
int
)
e
).
doubles
(
)));
exerciseOps
(
data
,
s
->
s
.
flatMap
(
e
->
IntStream
.
range
(
0
,
(
int
)
e
).
limit
(
10
).
doubles
(
)));
}
}
test/java/util/stream/test/org/openjdk/tests/java/util/stream/ForEachOpTest.java
浏览文件 @
4a117002
...
...
@@ -205,7 +205,7 @@ public class ForEachOpTest extends OpTestCase {
public
void
testDoubleForEachOrdered
()
{
List
<
Integer
>
input
=
countTo
(
10000
);
TestData
.
OfDouble
data
=
TestData
.
Factory
.
ofDoubleSupplier
(
"[1, 10000]"
,
()
->
DoubleStream
.
range
(
1
,
10001
));
()
->
IntStream
.
range
(
1
,
10001
).
doubles
(
));
Function
<
DoubleStream
,
List
<
Integer
>>
terminalFunc
=
s
->
{
List
<
Integer
>
l
=
new
ArrayList
<>();
...
...
test/java/util/stream/test/org/openjdk/tests/java/util/stream/RangeTest.java
浏览文件 @
4a117002
...
...
@@ -221,124 +221,6 @@ public class RangeTest extends OpTestCase {
//
public
void
testDoubleRangeErrors
()
{
for
(
double
start
:
Arrays
.
asList
(
1
,
10
,
-
1
,
-
10
))
{
for
(
double
end
:
Arrays
.
asList
(
1
,
10
,
-
1
,
-
10
))
{
for
(
double
step
:
Arrays
.
asList
(
0.0
,
+
0.0
,
-
0.0
,
1.0
,
-
1.0
,
Double
.
POSITIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
))
{
try
{
if
(
step
>
0
)
executeAndNoCatch
(()
->
DoubleStream
.
range
(
start
,
end
,
step
));
else
executeAndCatch
(()
->
DoubleStream
.
range
(
start
,
end
,
step
));
}
catch
(
AssertionError
e
)
{
System
.
out
.
printf
(
"start=%f, end=%f, step=%f%n"
,
start
,
end
,
step
);
throw
e
;
}
}
}
}
for
(
double
start
:
Arrays
.
asList
(
0.0
,
Double
.
POSITIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
,
Double
.
NaN
))
{
for
(
double
end
:
Arrays
.
asList
(
0.0
,
Double
.
POSITIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
,
Double
.
NaN
))
{
for
(
double
step
:
Arrays
.
asList
(
1.0
,
-
1.0
,
Double
.
POSITIVE_INFINITY
,
Double
.
NEGATIVE_INFINITY
,
Double
.
NaN
))
{
try
{
if
((
start
==
0.0
&&
end
==
0.0
&&
step
>
0
)
||
(
start
>
end
&&
step
>
0
))
{
executeAndNoCatch
(()
->
DoubleStream
.
range
(
start
,
end
,
step
));
}
else
{
executeAndCatch
(()
->
DoubleStream
.
range
(
start
,
end
,
step
));
}
}
catch
(
AssertionError
e
)
{
System
.
out
.
printf
(
"start=%f, end=%f, step=%f%n"
,
start
,
end
,
step
);
throw
e
;
}
}
}
}
}
public
void
testDoubleRange
()
{
// Without step
for
(
double
start
:
Arrays
.
asList
(
1
,
1000
,
-
1
,
-
1000
))
{
for
(
double
end
:
Arrays
.
asList
(
1
,
1000
,
-
1
,
-
1000
))
{
double
step
=
1
;
double
size
=
start
<
end
?
Math
.
ceil
((
end
-
start
)
/
step
)
:
0
;
double
[]
exp
=
new
double
[(
int
)
size
];
for
(
long
i
=
0
;
i
<
size
;
i
++)
{
exp
[(
int
)
i
]
=
start
+
i
*
step
;
}
double
[]
inc
=
DoubleStream
.
range
(
start
,
end
).
toArray
();
assertEquals
(
inc
.
length
,
(
int
)
size
);
assertTrue
(
Arrays
.
equals
(
exp
,
inc
));
withData
(
doubleRangeData
(
start
,
end
,
step
)).
stream
(
s
->
s
).
expectedResult
(
exp
).
exercise
();
}
}
// With step
for
(
double
start
:
Arrays
.
asList
(
1
,
1000
,
-
1
,
-
1000
))
{
for
(
double
end
:
Arrays
.
asList
(
1
,
1000
,
-
1
,
-
1000
))
{
for
(
double
step
:
Arrays
.
asList
(
1
,
-
1
,
-
2
,
2
))
{
if
(
step
<=
0
)
continue
;
double
size
=
start
<
end
?
Math
.
ceil
((
end
-
start
)
/
step
)
:
0
;
double
[]
exp
=
new
double
[(
int
)
size
];
for
(
long
i
=
0
;
i
<
size
;
i
++)
{
exp
[(
int
)
i
]
=
start
+
i
*
step
;
}
double
[]
inc
=
DoubleStream
.
range
(
start
,
end
,
step
).
toArray
();
assertEquals
(
inc
.
length
,
(
int
)
size
);
assertTrue
(
Arrays
.
equals
(
exp
,
inc
));
withData
(
doubleRangeData
(
start
,
end
,
step
)).
stream
(
s
->
s
).
expectedResult
(
exp
).
exercise
();
}
}
}
// With non-integer values
for
(
double
step
:
Arrays
.
asList
(
Math
.
PI
/
1000.0
,
Math
.
PI
/
1000.0
,
Math
.
PI
/
10000.0
))
{
double
start
=
-
Math
.
PI
;
double
end
=
Math
.
PI
;
double
size
=
start
<
end
?
Math
.
ceil
((
end
-
start
)
/
step
)
:
0
;
double
[]
exp
=
new
double
[(
int
)
size
];
for
(
long
i
=
0
;
i
<
size
;
i
++)
{
exp
[(
int
)
i
]
=
start
+
i
*
step
;
}
withData
(
doubleRangeData
(
start
,
end
,
step
)).
stream
(
s
->
s
).
expectedResult
(
exp
).
exercise
();
}
}
TestData
.
OfDouble
doubleRangeData
(
double
start
,
double
end
,
double
step
)
{
return
TestData
.
Factory
.
ofDoubleSupplier
(
"double range"
,
()
->
DoubleStream
.
range
(
start
,
end
,
step
));
}
public
void
tesDoubleRangeReduce
()
{
withData
(
doubleRangeData
(
0
,
10000
,
1
)).
terminal
(
s
->
s
.
reduce
(
0
,
Double:
:
sum
)).
exercise
();
}
public
void
testDoubleInfiniteRangeLimit
()
{
withData
(
TestData
.
Factory
.
ofDoubleSupplier
(
"double range"
,
()
->
DoubleStream
.
iterate
(
0
,
i
->
i
+
1
).
limit
(
10000
))).
terminal
(
s
->
s
.
reduce
(
0
,
Double:
:
sum
)).
exercise
();
}
public
void
testDoubleInfiniteRangeFindFirst
()
{
double
first
=
DoubleStream
.
iterate
(
0
,
i
->
i
+
1
).
filter
(
i
->
i
>
10000
).
findFirst
().
getAsDouble
();
assertEquals
(
first
,
DoubleStream
.
iterate
(
0
,
i
->
i
+
1
).
parallel
().
filter
(
i
->
i
>
10000
).
findFirst
().
getAsDouble
());
}
//
private
static
int
[]
reverse
(
int
[]
a
)
{
int
[]
b
=
new
int
[
a
.
length
];
for
(
int
i
=
0
;
i
<
a
.
length
;
i
++)
{
...
...
test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamBuilderTest.java
浏览文件 @
4a117002
...
...
@@ -275,7 +275,7 @@ public class StreamBuilderTest extends OpTestCase {
@Test
(
dataProvider
=
"sizes"
)
public
void
testDoubleAfterBuilding
(
int
size
)
{
StreamBuilder
.
OfDouble
sb
=
DoubleStream
.
builder
();
DoubleStream
.
range
(
0
,
size
).
forEach
(
sb
);
IntStream
.
range
(
0
,
size
).
doubles
(
).
forEach
(
sb
);
sb
.
build
();
checkISE
(()
->
sb
.
accept
(
1
));
...
...
@@ -287,13 +287,13 @@ public class StreamBuilderTest extends OpTestCase {
public
void
testDoubleStreamBuilder
(
int
size
)
{
testDoubleStreamBuilder
(
size
,
(
s
)
->
{
StreamBuilder
.
OfDouble
sb
=
DoubleStream
.
builder
();
DoubleStream
.
range
(
0
,
s
).
forEach
(
sb
);
IntStream
.
range
(
0
,
s
).
doubles
(
).
forEach
(
sb
);
return
sb
.
build
();
});
testDoubleStreamBuilder
(
size
,
(
s
)
->
{
StreamBuilder
.
OfDouble
sb
=
DoubleStream
.
builder
();
DoubleStream
.
range
(
0
,
s
).
forEach
(
i
->
{
IntStream
.
range
(
0
,
s
).
doubles
(
).
forEach
(
i
->
{
StreamBuilder
.
OfDouble
_sb
=
sb
.
add
(
i
);
assertTrue
(
sb
==
_sb
);
});
...
...
@@ -307,12 +307,12 @@ public class StreamBuilderTest extends OpTestCase {
withData
(
data
).
stream
(
s
->
s
).
expectedResult
(
DoubleStream
.
range
(
0
,
size
).
toArray
()).
expectedResult
(
IntStream
.
range
(
0
,
size
).
doubles
(
).
toArray
()).
exercise
();
withData
(
data
).
stream
(
s
->
s
.
map
(
i
->
i
)).
expectedResult
(
DoubleStream
.
range
(
0
,
size
).
toArray
()).
expectedResult
(
IntStream
.
range
(
0
,
size
).
doubles
(
).
toArray
()).
exercise
();
}
...
...
test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java
浏览文件 @
4a117002
...
...
@@ -526,7 +526,7 @@ public class StreamSpliteratorTest extends OpTestCase {
for
(
boolean
proxyEstimateSize
:
new
boolean
[]{
false
,
true
})
{
// Size is assumed to be larger than the target size for no splitting
// @@@ Need way to obtain the target size
Spliterator
.
OfDouble
sp
=
intermediateOp
.
apply
(
DoubleStream
.
range
(
0
,
1000
)).
spliterator
();
Spliterator
.
OfDouble
sp
=
intermediateOp
.
apply
(
IntStream
.
range
(
0
,
1000
).
doubles
(
)).
spliterator
();
ProxyNoExactSizeSpliterator
.
OfDouble
psp
=
new
ProxyNoExactSizeSpliterator
.
OfDouble
(
sp
,
proxyEstimateSize
);
DoubleStream
s
=
StreamSupport
.
doubleParallelStream
(
psp
);
terminalOp
.
accept
(
s
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录