Class PromisedFinder
public class PromisedFinder
extends java.lang.Object
PromisedFinder as a class doesn't actually do very much. However, the purpose of PromisedFinder is to allow you to easily write what are in essence "callbacks" upon the path generation's termination.
For example, if you'd like to run a piece of code after the pathfinder
has tried (and failed) to generate a path, you could make use of the
fail(Runnable)
method.
As a more contextualized example, take:
Pathfinder pathfinder;
pathfinder.followPath([path]).after(() -> {
// Code to be executed after the pathfinder finishes
// path generation and finding.
}).pass(() -> {
// Code to be executed after the pathfinder successfully
// generates a path.
}).fail(() -> {
// Code to be executed after the pathfinder doesn't manage
// to generate a path.
});
PromisedFinder
objects are also capable of providing information
about the status of path generation. If, for example, you'd like to execute
some code after the pathfinder's execution, but you need to get the path
that was just generated, you can use the method
getPath()
to do exactly that.
- Since:
- 0.2.0
- Author:
- Colin Robertson
-
Field Summary
-
Constructor Summary
Constructors Constructor Description PromisedFinder(boolean pass, me.wobblyyyy.edt.DynamicArray<Point> path)
Create a new PromisedFinder object. -
Method Summary
Modifier and Type Method Description PromisedFinder
after(java.lang.Runnable after)
Code that should be executed when the pathfinder finishes finding a path.PromisedFinder
fail(java.lang.Runnable fail)
Code that should be executed when the pathfinder finishes finding a path, if that path generation fails.me.wobblyyyy.edt.DynamicArray<Point>
getPath()
Get the generated path.PromisedFinder
pass(java.lang.Runnable pass)
Code that should be executed when the pathfinder finishes finding a path, if that path generation succeeds.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
DEFAULT
private static final java.lang.Runnable DEFAULTA default Runnable element.This element is subbed in for Runnable code if that code is null.
-
passed
private final boolean passedDid the pathfinder's path generation succeed or not? -
path
The pathfinder's path generation's outputted path.
-
-
Constructor Details
-
PromisedFinder
Create a new PromisedFinder object.- Parameters:
pass
- whether or not the path generation succeeded.path
- the path generation's outputted path.
-
-
Method Details
-
getPath
Get the generated path.This is the path that's been generated by the path generation code. It isn't modified or in any way mutilated before it's available here.
- Returns:
- the generated path.
-
after
Code that should be executed when the pathfinder finishes finding a path.After code is run once, as soon as the pathfinder finishes its path generation calculations. It doesn't matter if the pathfinder managed to find a path or not - this is run anyways.
- Parameters:
after
- the code that should be executed on the pathfinder's path generation's completion.- Returns:
- this - a chainable PromisedFinder object.
-
pass
Code that should be executed when the pathfinder finishes finding a path, if that path generation succeeds.Any code you put here will be run after the pathfinder has finished calculating a path, but it won't always be executed. Code that goes here will only be executed if the pathfinder DID find a path.
The following ruleset is applied to pathfinder passing and failing.
- The path has PASSED if it's non-zero in length.
- The path has FAILED if it's zero in length.
- Parameters:
pass
- the code that should be executed on the pathfinder's path generation's success.- Returns:
- this - a chainable PromisedFinder object.
-
fail
Code that should be executed when the pathfinder finishes finding a path, if that path generation fails.Any code you put here will be run after the pathfinder has finished calculating a path, but it won't always be executed. Code that goes here will only be executed if the pathfinder DID NOT find a path.
The following ruleset is applied to pathfinder passing and failing.
- The path has PASSED if it's non-zero in length.
- The path has FAILED if it's zero in length.
- Parameters:
fail
- the code that should be executed on the pathfinder's path generation's failure.- Returns:
- this - a chainable PromisedFinder object.
-