Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-radaraccess-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e873e328
authored
Feb 21, 2024
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加stream流测试用例
1 parent
5219ac09
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
0 deletions
platform-radaraccess/src/test/java/cn/com/glsx/cn/com/glsx/test01.java
platform-radaraccess/src/test/java/cn/com/glsx/cn/com/glsx/test02.java
platform-radaraccess/src/test/java/cn/com/glsx/cn/com/glsx/test01.java
0 → 100644
View file @
e873e32
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
;
import
java.util.concurrent.*
;
/**
* @author Yanglinlong
* @date 2024/2/21 17:34
*/
public
class
test01
{
public
static
void
main
(
String
[]
args
)
{
// Create a ForkJoinPool with default configuration
ForkJoinPool
pool
=
new
ForkJoinPool
();
// Create a task that generates Fibonacci numbers
FibonacciTask
task
=
new
FibonacciTask
(
30L
);
// Submit the task to the pool
pool
.
submit
(
task
);
// Wait for the task to complete
pool
.
shutdown
();
try
{
pool
.
awaitTermination
(
Long
.
MAX_VALUE
,
TimeUnit
.
NANOSECONDS
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
// Print the result
System
.
out
.
println
(
task
.
compute
());
}
static
class
FibonacciTask
extends
RecursiveTask
<
Long
>
{
private
final
Long
n
;
public
FibonacciTask
(
Long
n
)
{
this
.
n
=
n
;
}
@Override
protected
Long
compute
()
{
if
(
n
<=
1
)
{
// Base case: return the value directly
return
n
;
}
else
{
// Divide the task into two smaller tasks
FibonacciTask
leftTask
=
new
FibonacciTask
(
n
-
1
);
FibonacciTask
rightTask
=
new
FibonacciTask
(
n
-
2
);
// Fork the tasks to the pool
leftTask
.
fork
();
rightTask
.
fork
();
// Join the tasks and return the sum of their results
return
leftTask
.
join
()
+
rightTask
.
join
();
}
}
}
}
platform-radaraccess/src/test/java/cn/com/glsx/cn/com/glsx/test02.java
0 → 100644
View file @
e873e32
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
;
import
cn.hutool.json.JSONUtil
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
/**
* @author Yanglinlong
* @date 2024/2/21 17:44
*/
public
class
test02
{
public
static
void
main
(
String
[]
args
)
{
Stream
<
Integer
>
numbers
=
Stream
.
of
(
1
,
2
,
3
,
4
,
5
);
Optional
<
Integer
>
first
=
numbers
.
findFirst
();
System
.
out
.
println
(
"first = "
+
first
.
get
());
Stream
<
Integer
>
numbers01
=
Stream
.
of
(
1
,
2
,
3
,
4
,
5
);
Optional
<
Integer
>
any
=
numbers01
.
findAny
();
System
.
out
.
println
(
"any = "
+
any
.
get
());
Stream
<
Integer
>
numbers02
=
Stream
.
of
(
1
,
2
,
3
,
4
,
5
);
// numbers02.forEach(System.out::println);
Integer
integer
=
numbers02
.
map
(
i
->
i
*
2
).
collect
(
Collectors
.
toList
()).
stream
().
peek
(
i
->
System
.
out
.
println
(
"i = "
+
i
)).
reduce
(
1
,
Integer:
:
sum
);
System
.
out
.
println
(
"integer = "
+
integer
);
Stream
<
Integer
>
numbers03
=
Stream
.
of
(
1
,
2
,
3
,
4
,
5
);
List
<
Integer
>
collect
=
numbers03
.
map
(
i
->
i
*
2
).
collect
(
Collectors
.
toList
()).
stream
().
peek
(
i
->
System
.
out
.
println
(
"i = "
+
i
)).
flatMap
(
i
->
Stream
.
of
(
6
,
7
,
8
,
9
,
10
)).
collect
(
Collectors
.
toList
());
System
.
out
.
println
(
"integer01 = "
+
JSONUtil
.
toJsonStr
(
collect
));
Stream
<
Integer
>
numbers04
=
Stream
.
of
(
1
,
2
,
3
,
4
,
5
);
List
<
Integer
>
collect01
=
numbers04
.
map
(
i
->
i
*
2
).
collect
(
Collectors
.
toList
()).
stream
().
peek
(
i
->
System
.
out
.
println
(
"i = "
+
i
)).
sorted
(
Integer:
:
compareTo
).
flatMap
(
i
->
Stream
.
of
(
6
,
7
,
8
,
9
,
10
)).
collect
(
Collectors
.
toList
());
System
.
out
.
println
(
"collect01 = "
+
JSONUtil
.
toJsonStr
(
collect01
));
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment