-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2e58a4
commit 7d14b66
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/com/greghaskins/spectrum/AfterEachBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.greghaskins.spectrum.Spectrum.Block; | ||
|
||
class AfterEachBlock implements Block { | ||
|
||
private final List<Block> blocks; | ||
|
||
public AfterEachBlock() { | ||
this.blocks = new ArrayList<Block>(); | ||
} | ||
|
||
@Override | ||
public void run() throws Throwable { | ||
runAllBlocksInReverseOrder(this.blocks.size() - 1); | ||
} | ||
|
||
private void runAllBlocksInReverseOrder(final int index) throws Throwable { | ||
if (index < 0) { | ||
return; | ||
} | ||
try { | ||
this.blocks.get(index).run(); | ||
} finally { | ||
runAllBlocksInReverseOrder(index - 1); | ||
} | ||
} | ||
|
||
public void addBlock(final Block block) { | ||
this.blocks.add(block); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters