public final class GroovyLocals extends Object
GroovyLocals.
.Modifier and Type | Class and Description |
---|---|
static class |
GroovyLocals.SortFunctionSignatures
This abstract class declares which signatures the closures passed into
newSort(groovy.lang.Closure<?>, groovy.lang.Closure<?>) can use. |
Modifier and Type | Method and Description |
---|---|
static ArrayVisualizer |
getArrayv()
Property for the main
ArrayVisualizer instance. |
static String |
getCategory()
Get the current category display
|
static SortInfo |
getSort(String internalName)
Get a sort by its internal name, which is usually the name of the sort class.
|
static SortInfo |
getSort(String name,
SortNameType nameType)
Get a sort by name
|
static SortInfo |
newSort(groovy.lang.Closure<?> sort,
groovy.lang.Closure<?> metadata)
Creates (and adds) a new sorting algorithm to this ArrayV instance.
|
static void |
registerCloser(Runnable closer)
Register a closer.
|
static ArrayVEventHandler |
registerEventHandler(ArrayVEventHandler.EventType eventType,
Runnable cb)
Registers an event handler and returns the handler object.
|
static SortInfo |
registerSort(Class<? extends Sort> sort)
Registers a sort with the sort list
|
static SortInfo |
registerSort(Sort sort)
Registers a sort with the sort list
|
static SortInfo |
registerSort(SortInfo sort)
Registers a sort with the sort list
|
static RunSortBuilder |
run(Class<?> sort)
Effectively an alias for
run(SortInfo) , but designed around a special
case dealing with TimSort and DualPivotQuickSort, as Groovy loads the java.util classes instead |
static RunSortBuilder |
run(Map<String,Object> options,
Class<?> sort)
Combination of
run(Class) and run(Map, SortInfo) |
static RunSortBuilder |
run(Map<String,Object> options,
SortInfo sort)
Runs a sort, but adds the ability to pass Groovy map arguments,
e.g.:
run(BubbleSort, numbers: 2048, speed: 0.75) |
static RunSortBuilder |
run(SortInfo sort)
Prepares to run a sorting algorithm
|
static void |
runGroup(Integer sortCount,
Runnable run)
Setus up a run group.
|
static Thread |
runGroupInThread(Integer sortCount,
Runnable run)
Setus up a run group.
|
static Thread |
runGroupInThread(Integer sortCount,
Runnable run,
boolean isRunAll)
Similar to
runGroupInThread(Integer, Runnable) , except that it has an extra isRunAll parameter . |
static void |
setCategory(String category)
Set the current category display
|
public static ArrayVisualizer getArrayv()
Property for the main ArrayVisualizer
instance.
println arrayv.sortAnalyzer
ArrayVisualizer
instancepublic static SortInfo getSort(String internalName)
internalName
- The internal name to find the sort bynull
if no sort with the given internal name was foundpublic static SortInfo getSort(String name, SortNameType nameType)
name
- The name of the sortnameType
- The type of name to search by (such as list name, run name, etc.).
See SortNameType
for more detailsnull
if no sort with the given name and name type was foundpublic static SortInfo newSort(groovy.lang.Closure<?> sort, @DelegatesTo(value=SortInfo.Builder.class) groovy.lang.Closure<?> metadata)
Creates (and adds) a new sorting algorithm to this ArrayV instance.
Here's an example:def sortFn(array, length) { // Sorting algorithm code here } newSort(this::sortFn) { listName "My Custom Sort" category "Examples" unreasonableLimit 1024 }
sort
- The sort method/function/closure to add.
This closure can follow any of the signatures listed in GroovyLocals.SortFunctionSignatures
metadata
- The closure used to define metadata.
See above for an example, and SortInfo.Builder
for the list of metadata methods you can use.SortInfo
object associated with the newly created algorithmpublic static SortInfo registerSort(SortInfo sort)
sort
- The sort to registersort
parameter, but likely with a different idpublic static SortInfo registerSort(Class<? extends Sort> sort)
public static RunSortBuilder run(SortInfo sort)
sort
- The sorting algorithm to runRunSortBuilder
for setting up sort running parameterspublic static RunSortBuilder run(Class<?> sort)
run(SortInfo)
, but designed around a special
case dealing with TimSort and DualPivotQuickSort, as Groovy loads the java.util classes insteadsort
- The class to coerce to a SortInfo
using getSort(sort.getSimpleName())
RunSortBuilder
for setting up sort running parameterspublic static RunSortBuilder run(Map<String,Object> options, SortInfo sort)
run(BubbleSort, numbers: 2048, speed: 0.75)
options
- Groovy map arguments. See RunSortBuilder
for valid keyssort
- The sorting algorithm to runRunSortBuilder
for setting up sort running parameterspublic static RunSortBuilder run(Map<String,Object> options, Class<?> sort)
run(Class)
and run(Map, SortInfo)
options
- sort
- public static String getCategory()
public static void setCategory(String category)
category
- The category to displaypublic static void runGroup(Integer sortCount, Runnable run)
runGroupInThread(Integer, Runnable)
.sortCount
- The total number of sorts in this grouprun
- A closure around the code to run. Generally built of mostly run(io.github.arrayv.sortdata.SortInfo)
callspublic static Thread runGroupInThread(Integer sortCount, Runnable run)
runGroup(java.lang.Integer, java.lang.Runnable)
, except that it returns the new thread instead of simply joining on it.sortCount
- The total number of sorts in this grouprun
- A closure around the code to run. Generally built of mostly run(io.github.arrayv.sortdata.SortInfo)
callspublic static Thread runGroupInThread(Integer sortCount, Runnable run, boolean isRunAll)
runGroupInThread(Integer, Runnable)
, except that it has an extra isRunAll parameter
.
This method is generally intended only to be used internally by SortPrompt.jButton1ActionPerformed()
.sortCount
- The total number of sorts in this grouprun
- A closure around the code to run. Generally built of mostly run(io.github.arrayv.sortdata.SortInfo)
callsisRunAll
- If this is true
, the group will behave as if it was Showcase Sorts.public static ArrayVEventHandler registerEventHandler(ArrayVEventHandler.EventType eventType, Runnable cb)
ArrayVEventHandler
for more details.eventType
- The type of the event to handlecb
- The callback to run for the eventpublic static void registerCloser(Runnable closer)
Register a closer.
Ok, so what is a closer? A closer is ArrayV's Groovy API's equivalent of finalizers. Closers fix many of the flaws of finalizers. Closers are guaranteed to be called when the thread exits, whereas finalizers may never be called. Closers are also guaranteed to be called in the thread they are registered in, whereas finalizers may be called from any any thread. Furthermore, finalizers have been deprecated and are scheduled to be removed at some point in the future.
closer
- The closer to registerCopyright © 2024. All rights reserved.