Releases: suk-ws/da4a
Release list
0.2.0 - Event, ByteHexConverter, InplaceSortable, EpochDateTime, and more
da4a Project Icon
The icon that presents da4a is out!
Event
This early-stage version may not works on Java platform.
Added a series of classes that can quickly create an Event object and pass events to listeners using rich-featured event context tool.
Events
Events are a series class that can manage listeners. It cannot be emitted directly, to emit a event, an Emitter is required.
┌────────────────────┐
Event series class graph │ AbstractEvent │
│ + SimpleEventOps │
└─────────▲──────────┘
┌──────────────────────────────────┤
┌──────────┴───────────┐ ┌─────────┴─────────┐
│ SimpleEmittableEvent │ │ AbstractRichEvent │
└──────────▲───────────┘ │ + RichEventOps │
│ └────────▲──────────┘
│ ├───────────────┐
│ ┌──────────────────┘ ┌────────────┴────────────┐
│ ┌──────────┴─────────┐ │ AbstractManageableEvent │
│ │ RichEmittableEvent │ │ + ManagableEventOps │
│ └──────────▲─────────┘ └────────────▲────────────┘
│ │ │
│ └──────────────┐ │
│ ┌─────┴─────┐ ┌───────┴────────┐
│ │ RichEvent │ │ ManagableEvent │
│ └─────┬─────┘ └───────▲────────┘
│ │ │
│ ├───────────────────┘
┌─────┴───────┐ ┌───┴────┐
│ SimpleEvent │ │ Event │
└─────────────┘ └────────┘
AbstractEventprovides theregisterListener(EP=>ER)andremoveListener(EP=>ER)function. ItsOpsprovides an opeation variant ofregisterListeneris--> (EP=>ER). Event that implements this will be able to register a callback, normally with no context manager and error handler.AbstractRichEventprovidesregisterListener(EventListener[EP, ER])andremoveListener(EventListener[EP, ER]). ItsOpsprovidesregisterRichListener(EventContext[EP]=>ER)along with its operator variant==>(EventContext[EP]=>ER]),registerListener(Int,EP=>ER),registerRichListener(Int, EventContext[EP]=>ER),removeListenerIf(EventListener[EP, ER]=>Boolean),removeRichListener(EventContext[EP]=>ER)AbstractManageableEventprovidesinitContextWith(EventContext[EP]=>Unit)andinitErrorHandlerWith((Throwable, EventContext[EP])=>Boolean). Those internal values can be accessed by theEmitterseries.SimpleEmittableEventprovidesforeachListeners[T]((EP=>ER)=>T)to iterate the event's listeners.RichEmittableEventprovidesforeachListeners[T](EventListener[EP, ER]=>T)to iterate the event's listeners.Eventis a type that for production use. It extendsRichEventandManagableEvent, so that it can register and managerEventListeners that can handleEventContext, and it also can set the error handler to handle errors occurred by listeners.SimpleEventis a trait that for production use.It only extendsAbstractEventand its ops. It can only register a simple callbackEP=>ER, with noEventContextavailable and cannot handler errors occurred by listeners.
For user-oriented Event and SimpleEvent, some variant types is provided:
| no listener returns | no event params | |
|---|---|---|
Event[EP, ER] |
SupplierEvent[EP] |
ConsumerEvent[ER] |
SimpleEvent[EP, ER] |
SupplierSimpleEvent[EP] |
ConsumerSimpleEvent[ER] |
To create an Event, Event and SimpleEvent both has an apply function.
EventListener
EventListener is a rich-featured event listener trait. It has an priority: Int field that can be used to order listeners, it can receive EventContext using , and use the EventContext to control whether to skip running (by its isSkipEvent(usng EventContext[EP])).
For EventListener's priority, there are also a pre-defined EventListener.Priorities:
ABSOLUTE_LOW |
LOWEST |
LOWER |
LOW |
NORMAL |
HIGH |
HIGHER |
HIGHEST |
ABSOLUTE_HIGH |
|---|---|---|---|---|---|---|---|---|
Int.MIN |
Short.MIN |
Byte.MIN |
-64 | 0 | 64 | Byte.MAX |
Short.MAX |
Int.MAX |
| -2147483648 | -65536 | -128 | -64 | 0 | 64 | 127 | 65535 | 2147483647 |
There are also CallbackIsFunction and CallbackIsSimpleFunction helper traits. They are used to record the creation methods and parameters for its EventListener. By these traits, equality checks with EventListener and EP=>ER and so on are available, makes removeListener better to use.
Predefined ordering for EventLisner is also provided: OrderingByPriorityFixed, and OrderingByPriorityStables
To create an EventListener, the following method is provided: apply[EP, ER](EventContext[EP]=>ER, Int), apply[EP, ER](EventContext[EP]=>ER), simple[EP, ER](EP=>ER, Int), simple[EP,ER](EP=>ER)
EventContext
EventContext is the alternate event params that used in rich-event series.
Provides an param: EP. It is also the only param that required to create an EventContext.
Provides givenCxt: GivenContext, to pass context parameters with listeners.
Provides timeStartup: EpochMillis
Provides isEventOk(), pushEventState(EventState), setEventOk(), setEventCanceled(), state: EventStates|Null, stateOption: Option[EventState], status: List[EventStatus] for control event states.
EventStatus
EventStatus series are used in EventContext for tagging event status.
It has root trait EventStatus, helper trait WithSource that requires a from: StackTraceElement, sub class Success extends EventStatus with WithSource, sub class Canceled extends EventStatus with WithSource, sub class Custom extends EventStatus (unstable currently).
emitter
Trait Emitter (in package event.emitter) is used to emit an Event. An Emitter is for a specific type of AbstractEvent, and provides an emit(EP) method to emit the event.
The implementation of Emitter can also access the protected method patchContext(AbstractManageableEvent[EP, ER], EventContext[EP]) and getErrorHandler(AbstractManageableEvent[EP, ER]) to support the features of AbstractManagableEvent.
An static method emittingFor(AbstractEvent) is provided to create an emitter instance for a specific event. This emitter supports all event types in this library.
data.collections extension - InPlaceSortable
Scala only features.
Add trait InPlaceSortable, which provides sortInPlace(using Ordering).
Add trait IteratingOps, provides removeIf(T=>Boolean).
Add new mutable collection implementation LinkedList, extends trait like normal Seq with additional InPlaceSortable and IteratingOps. (The internal implementation is java's LinkedList).
datetime - DateTimeTypeAliases
Scala only feature.
Add the new types aliases:
EpochMillisas alias ofLong. Can be created fromString time, String zoneas well, or converted fromEpochSecondsandEpochDays.EpochSecondsas alias ofInt. Can be converted fromEpochMillisas well. Max supported time is2038-01-19 03:14:07 UTC.EpochDaysas alias ofShort. Can be coverted fromEpochMillisas well. Max supported time is2059-09-18 UTC.DurationMillisas alias ofLong.
random features
This early-stage version may not works on Java platform.
ArrayChooser class changed to implicit class CollectiomChooser_ExtensionSeq, added top level method choose(Seq)(using RandomIntGenerator) and chooseOne(Seq, Int)(RandomIntGenerator)
GivenContext
Should works fine on both Java and Scala platform.
Add constructor method from to clone a GivenContext. Also the GivenContext extends Clonable now,clone method is available.
Add provide[T](Class[T], T), get[T: ClassTag], get[T](Class[T]) (and deprecated use), getOrNull[T](Class[T]), getOrNull[T: ClassTag] and its operator variant >?>[T](Class[T]), getUnsafe[T](Class[T]), getUnsafe[T: ClassTag] (as method variant of >!>), use[T, U](Class[T])(T=>U), use[T: ClassTag, U](T=>U) as a better consume, consume[T](Class[T])(T=>Any), consuming[T](Class[T])(java.function.Consumer[T]) as java friendly variant consume.
The above changes is applied for both GivenContext main context and OwnedContext that accessed by ownedBy method.
Add ownedBy[O](Class[O]) as java friendly variant of ownedBy.
stacks tools
Should works fine on both Java and Scala platform.
Fix method under WithCurrentStack has wrong answer when calling in java.
Add StackExtensions, contains static method dropWhileClass, and `implicit class StackExtensio...
v0.1.0
This early-stage version may not works on Java platform.
Features added
Add contexts.GivenContext. Which can does some provide/inject like work, passing variables between two non-depended functions, in a type-safe way.
Add math.dsl, provides some math operator and pre-defined values.
- method
x over yand operatorx /-/ yfor any two numeric valuexandy. Like/but always do calc in double. - operator
x *^ yfor any two numeric valuexandy. Calcs themath.pow(x, y). - method
x.asPercentagefor any two numeric valuex. Power the valuexwith100so that make it from a basic number to a percentage literal. (like1.asPercentageis100,0.55.asPercentageis55.0,1.14514.asPercentageis114.514)
Add data.IEncapsulateValue and data.EncapsulateValue, extensions Any makes a value x: T can be converted to Some, Left or Right etc using suffix method.
Add stacks.withCurrentStack makes it easier to get stack traces.
Add throwable.ThrowableExtensions makes it eaiser to get an exception's full error reporting message as String.
Features that NOT recommended to use (WIP or very unstable)
count.NumericCount, a class moved from Morny Coeur. Not recommended due to a bad design.
random.*, random utils. Not recommended due to WIP.