JPad Functions Javadoc
io.jpad.scratch
Class JPad
- java.lang.Object
-
- io.jpad.scratch.JPad
-
public class JPad extends java.lang.Object
Util class for use by end users of JPad.
-
-
Field Summary
Fields Modifier and Type Field and Description static boolean
isGUI
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static <T> T
cache(java.lang.String name, java.lang.Class<T> cls, java.util.concurrent.Callable<T> callable)
Try to retrieve an entry from cache, if that fails use callable to calculate the value.static void
cacheClear(java.lang.String name)
Remove one entry from the cachestatic void
cacheClearAll()
Remove all entries from the cachestatic java.lang.String
cmd(java.lang.String command)
Run a command as if at the terminalstatic java.lang.String
cmd(java.lang.String[] commands)
Run a command as if at the terminalstatic java.lang.String
getArg(java.lang.String[] args, int idx, java.lang.String title)
static double
getArg(java.lang.String[] args, int idx, java.lang.String title, double defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title".static float
getArg(java.lang.String[] args, int idx, java.lang.String title, float defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title".static int
getArg(java.lang.String[] args, int idx, java.lang.String title, int defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title".static long
getArg(java.lang.String[] args, int idx, java.lang.String title, long defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title".static java.lang.String
getArg(java.lang.String[] args, int idx, java.lang.String title, java.lang.String defaultValue)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title".static java.nio.file.Path
getScriptsFolder()
boolean
isGUI()
static java.lang.String
readLine(java.lang.String message)
Prompt user for input line.static double
requestInput(java.lang.String title, double defaultNum)
Prompt the user for a value while displaying "title".static float
requestInput(java.lang.String title, float defaultNum)
Prompt the user for a value while displaying "title".static int
requestInput(java.lang.String title, int defaultNum)
Prompt the user for a value while displaying "title".static long
requestInput(java.lang.String title, long defaultNum)
Prompt the user for a value while displaying "title".static java.lang.String
requestInput(java.lang.String title, java.lang.String defaultValue)
Prompt the user for a value while displaying "title".static void
writeCsv(java.lang.Object o, java.io.File file)
Write an object to file in CSV format.
-
-
-
Method Detail
-
cacheClear
public static void cacheClear(java.lang.String name)
Remove one entry from the cache
-
cacheClearAll
public static void cacheClearAll()
Remove all entries from the cache
-
cache
public static <T> T cache(java.lang.String name, java.lang.Class<T> cls, java.util.concurrent.Callable<T> callable)
Try to retrieve an entry from cache, if that fails use callable to calculate the value.- Parameters:
name
- Identifying name of the value stored.cls
- The type of the stored object.Callable
- How the cached value is calculated, this will only be called it the value does not yet exist.- Returns:
- The calculated value.
-
cmd
public static java.lang.String cmd(java.lang.String command) throws java.io.IOException
Run a command as if at the terminal- Returns:
- The result of running the command.
- Throws:
java.io.IOException
-
cmd
public static java.lang.String cmd(java.lang.String[] commands) throws java.io.IOException
Run a command as if at the terminal- Returns:
- The result of running the command.
- Throws:
java.io.IOException
-
writeCsv
public static void writeCsv(java.lang.Object o, java.io.File file) throws java.io.IOException
Write an object to file in CSV format.- Parameters:
Object
- The object that you want saved. If it is a ResultSet it will be saved as-is. Otherwise JPad will attempt to convert it to a ResultSet using the builtin-converter.- Throws:
java.io.IOException
-
getArg
public static int getArg(java.lang.String[] args, int idx, java.lang.String title, int defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
args
- An array of stringsidx
- The position in the array idx whos value we will return if possible.title
- A name describing what this value represents.
-
getArg
public static double getArg(java.lang.String[] args, int idx, java.lang.String title, double defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
args
- An array of stringsidx
- The position in the array idx whos value we will return if possible.title
- A name describing what this value represents.
-
getArg
public static float getArg(java.lang.String[] args, int idx, java.lang.String title, float defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
args
- An array of stringsidx
- The position in the array idx whos value we will return if possible.title
- A name describing what this value represents.
-
getArg
public static long getArg(java.lang.String[] args, int idx, java.lang.String title, long defaultNum)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
args
- An array of stringsidx
- The position in the array idx whos value we will return if possible.title
- A name describing what this value represents.
-
getArg
public static java.lang.String getArg(java.lang.String[] args, int idx, java.lang.String title, java.lang.String defaultValue)
Get the value at position idx from the array args if possible, otherwise prompt the user while displaying "title". If the user does not enter a value assume defaultValue.- Parameters:
args
- An array of stringsidx
- The position in the array idx whos value we will return if possible.title
- A name describing what this value represents.defaultValue
-- Returns:
- the value at position idx from the array args if possible, otherwise what the user entered. If the user does not enter a value assume defaultValue.
-
requestInput
public static int requestInput(java.lang.String title, int defaultNum)
Prompt the user for a value while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
title
- A name describing what this value represents.defaultNum
- The assumed value if user enters nothing.
-
requestInput
public static double requestInput(java.lang.String title, double defaultNum)
Prompt the user for a value while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
title
- A name describing what this value represents.defaultNum
- The assumed value if user enters nothing.
-
requestInput
public static float requestInput(java.lang.String title, float defaultNum)
Prompt the user for a value while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
title
- A name describing what this value represents.defaultNum
- The assumed value if user enters nothing.
-
requestInput
public static long requestInput(java.lang.String title, long defaultNum)
Prompt the user for a value while displaying "title". If the user does not enter a value assume defaultNum.- Parameters:
title
- A name describing what this value represents.defaultNum
- The assumed value if user enters nothing.
-
requestInput
public static java.lang.String requestInput(java.lang.String title, java.lang.String defaultValue)
Prompt the user for a value while displaying "title". If the user does not enter a value assume defaultValue.- Parameters:
title
- A name describing what this value represents.defaultNum
- The assumed value if user enters nothing.
-
getArg
public static java.lang.String getArg(java.lang.String[] args, int idx, java.lang.String title)
-
readLine
public static java.lang.String readLine(java.lang.String message)
Prompt user for input line. Behaviour depends on if ran in terminal or GUI.- Returns:
- user supplied line as entered at command line
-
getScriptsFolder
public static java.nio.file.Path getScriptsFolder()
- Returns:
- Path of where the currently running .jpad script is located.
-
isGUI
public boolean isGUI()
- Returns:
- true if this script is being ran in the JPad GUI otherwise false.
-
-