scalqa.j.__.scala Maven / Gradle / Ivy
package scalqa; import language.implicitConversions
/**
* ### Java Extension API
*/
object J:
/**
* Schedule job
*
* Schedules a job to run every given `period`
*
* ```
* // Prints time every 1 second for the rest of the day
*
* val day = Day()
*
* App.Concurrent.runEvery(1.Seconds, Time().tp).cancelIf(day != Day())
* ```
*/
def scheduleEvery [U](period: Time.Length, f: => U) : Event.Control = j.vm.z.Schedule.everyIn(period, period, () => f)
/**
* Schedule start of job
*
* Schedules a job with given `initDelay`, which will run every given `period`
*
* ```
* // In 10 minutes, this will start printing time every 1 second for one hour
* Schedule.everyIn(1.Second, 10.Minutes, Time().tp).expireIn(1.Hour)
* ```
*/
def scheduleEveryIn[U](period: Time.Length, initDelay:Time.Length, f: =>U): Event.Control = j.vm.z.Schedule.everyIn(period, initDelay, () => f)
/**
* Schedule one time job
*
* Schedules a one time job with given delay
* ```
* // Prints "Hello" in 3 seconds
* J.scheduleIn(3.Seconds, "Hello".tp)
* ```
*/
def scheduleIn[U](delay: Time.Length, job: => U) : Event.Control = j.vm.z.Schedule.in(delay, () => job)
/**/ def schedule[U](f: => U) : Unit = j.vm.z.Schedule(() => f)
/**
* Pauses current execution thread
*
* ```
* J.sleep(10.Millis) // Pauses for 10 milliseconds
*
* J.sleep(2.Seconds) // Pauses for 2 seconds
*
* J.sleep(1.Minute) // Pauses for 1 minute
* ```
*/
def sleep(tl: Time.Length) : Unit = java.lang.Thread.sleep(tl.millisTotal, (tl.micros * 1000 + tl.nanos).Int)
inline def initSize : Int = ZZ.initSize
/**
* To Do tag
*
* Inlines `throw new UnsupportedOperationException()`
*
* 'J.toDo' is the tag to leave in code to search for later.
*
* Never use `???`, which is for debugging and short term playing around
*/
inline def toDo( inline message: String = \/) : Nothing = throw new UnsupportedOperationException("J.toDo. "+message)
/**
* Fail unsupported
*
* Inlines `throw new UnsupportedOperationException()`
*
* The only benefit is reducing boilerplate code
*/
inline def unsupportedOperation(inline message: String = \/) : Nothing = throw new UnsupportedOperationException(message)
/**
* Fail with illegal state
*
* Inlines `throw new IllegalStateException()`
*
* The only benefit is reducing boilerplate code
*/
inline def illegalState( inline message: String = \/) : Nothing = throw new IllegalStateException(message)
/**
* Fail with illegal argument
*
* Inlines `throw new IllegalArgumentException()`
*
* The only benefit is reducing boilerplate code
*/
inline def illegalArgument( inline message: String = \/) : Nothing = throw new IllegalArgumentException(message)
/**/ def printStack(sizeLimit: Int.Opt = \/, label: String.Opt = \/) : Unit = { new Exception().getStackTrace().~.take_<>(1 <> sizeLimit.or(5000)).zipIndex(1)
/**/ .map("\t" + _.toString.padEndTo(3) + " " + _).joinAt(0,label or "J.printStack").foreach(println) }
// Members ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
transparent inline def File = j.File; type File = j.File.opaque.`type`
/**
* Companion alias
*
* Shortcut to [[scalqa.j.file.Path$ J.File.Path]]
*/
transparent inline def Path = j.file.Path;
/**
* Type alias
*
* Shortcut to [[scalqa.j.file.Path J.File.Path]]
*/
type Path = j.file.Path.opaque.`type`
transparent inline def Url = j.Url; type Url = j.Url.opaque.`type`
/**
* Type alias
*
* Shortcut to java.io.PrintStream
*/
type Printer = java.io.PrintStream
transparent inline def Io = j.Io
/**
* Companion alias
*
* Shortcut to [[scalqa.j.io.Input$ J.Io.Input]]
*/
transparent inline def Input = j.io.Input;
/**
* Type alias
*
* Shortcut to [[scalqa.j.io.Input J.Io.Input]]
*/
type Input = j.io.Input.opaque.`type`
/**
* Companion alias
*
* Shortcut to [[scalqa.j.io.Output$ J.Io.Output]]
*/
transparent inline def Output = j.io.Output;
/**
* Type alias
*
* Shortcut to [[scalqa.j.io.Output J.Io.Output]]
*/
type Output = j.io.Output.opaque.`type`
transparent inline def Json = j.Json
/**
* Companion alias
*
* Shortcut to [[scalqa.j.json.Object$ J.Json.Object]]
*/
transparent inline def Object = j.json.Object;
/**
* Type alias
*
* Shortcut to [[scalqa.j.json.Object J.Json.Object]]
*/
type Object = j.json.Object
/**
* Companion alias
*
* Shortcut to [[scalqa.j.json.Array$ J.Json.Array]]
*/
transparent inline def Array = j.json.Array;
/**
* Type alias
*
* Shortcut to [[scalqa.j.json.Array J.Json.Array]]
*/
type Array = j.json.Array
transparent inline def Zip = j.Zip
transparent inline def Util = j.Util
/**
* Alias
*
* Shortcut to [[scalqa.j.util.Benchmark$ J.Util.Benchmark]]
*/
transparent inline def Benchmark = j.util.Benchmark
/**
* Companion alias
*
* Shortcut to [[scalqa.j.util.Random$ J.Util.Random]]
*/
transparent inline def Random = j.util.Random
/**
* Type alias
*
* Shortcut to [[scalqa.j.util.Test J.Util.Test]]
*/
type Test = j.util.Test
transparent inline def Concurrent = j.util.Concurrent
/**
* Companion alias
*
* Shortcut to [[scalqa.j.util.WeakRef$ J.Util.WeakRef]]
*/
transparent inline def WeakRef = j.util.WeakRef;
/**
* Type alias
*
* Shortcut to [[scalqa.j.util.WeakRef J.Util.WeakRef]]
*/
type WeakRef[A] = j.util.WeakRef.opaque.`type`[A]
transparent inline def Vm = j.Vm
/**
* Companion alias
*
* Shortcut to [[scalqa.j.vm.Priority$ J.Vm.Priority]]
*/
transparent inline def Priority = j.vm.Priority;
/**
* Type alias
*
* Shortcut to [[scalqa.j.vm.Priority J.Vm.Priority]]
*/
type Priority = j.vm.Priority.opaque.`type`
/**
* Companion alias
*
* Shortcut to [[scalqa.j.vm.Setup$ J.Vm.Setup]]
*/
transparent inline def Setup = j.vm.Setup
/**
* Companion alias
*
* Shortcut to [[scalqa.j.vm.Memory$ J.Vm.Memory]]
*
*/
transparent inline def Memory = j.vm.Memory
/**
* Companion alias
*
* Shortcut to [[scalqa.j.vm.Host$ J.Vm.Host]]
*/
transparent inline def Host = j.vm.Host
/*___________________________________________________________________________
__________ ____ __ ______ ____
/ __/ ___// _ | / / / __ / / _ | Scala Quick API
__\ \/ /___/ __ |/ /__/ /_/ /_/ __ | (c) 2021, Scalqa.org Inc
/_____/\____/_/ |_/____/\______/_/ |_| github.com/scalqa
___________________________________________________________________________*/