Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab_reactive_java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rtbdp
labs
lab_reactive_java
Commits
d748deb7
Commit
d748deb7
authored
8 years ago
by
Stuart Marks
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite source processor script into Java.
parent
305b3e63
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LambdaLab/src/support/Grind.java
+63
-0
63 additions, 0 deletions
LambdaLab/src/support/Grind.java
with
63 additions
and
0 deletions
LambdaLab/src/support/Grind.java
0 → 100644
+
63
−
0
View file @
d748deb7
package
support
;
import
java.io.IOException
;
import
java.io.PrintStream
;
import
java.io.UncheckedIOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.function.Consumer
;
import
java.util.stream.Stream
;
/**
* Process all files test/solutions/*.java into
* corresponding files in test/exercises/*.java.
*/
public
class
Grind
{
static
class
Sink
implements
Consumer
<
String
>
{
boolean
removing
=
false
;
final
PrintStream
out
;
Sink
(
PrintStream
out
)
{
this
.
out
=
out
;
}
public
void
accept
(
String
line
)
{
if
(
line
.
contains
(
"//BEGINREMOVE"
))
{
removing
=
true
;
}
else
if
(
line
.
contains
(
"//ENDREMOVE"
))
{
removing
=
false
;
}
else
if
(!
removing
)
{
out
.
println
(
line
);
}
}
}
String
subst
(
String
line
)
{
return
line
.
replace
(
"package solutions;"
,
"package exercises;"
)
.
replace
(
"@Test"
,
"@Test @Ignore"
)
.
replace
(
"//UNCOMMENT//"
,
""
);
}
void
processFile
(
Path
input
)
{
Path
output
=
Paths
.
get
(
"test"
,
"exercises"
)
.
resolve
(
input
.
getName
(
input
.
getNameCount
()
-
1
));
System
.
out
.
println
(
input
+
" => "
+
output
);
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
input
);
PrintStream
out
=
new
PrintStream
(
output
.
toFile
()))
{
lines
.
map
(
this
::
subst
)
.
forEachOrdered
(
new
Sink
(
out
));
}
catch
(
IOException
ioe
)
{
throw
new
UncheckedIOException
(
ioe
);
}
}
void
run
()
throws
IOException
{
Path
dir
=
Paths
.
get
(
"test"
,
"solutions"
);
try
(
Stream
<
Path
>
paths
=
Files
.
list
(
dir
))
{
paths
.
filter
(
p
->
p
.
toString
().
endsWith
(
".java"
))
.
forEachOrdered
(
this
::
processFile
);
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
new
Grind
().
run
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment