public class EventDefinition
extends java.lang.Object
implements java.io.Externalizable
Multiple events can be associated with multiple widgets. Any defined combination of a single event with a single widget is a valid exit condition or will fire a trigger.
If there is no widgets specified, the case corresponds to the global ANYWHERE option. It is also possible to define a specific ANYWHERE option that accompanies the set of widgets.
If the association defines a trigger, the trigger ID should be a valid trigger ID from the trigger registry on the server. A special value of -1 means there is no trigger registered with this event definition instance. If there is no trigger, this instance defines an event processing loop exit condition.
A single instance of this class represents one association of a group of events with a group of widgets and/or the ANYWHERE option. To define a full list of triggers or exit conditions for a UI statement, more than one instance may be necessary. Only one trigger ID can be associated with an instance.
Widgets are specified with their numeric IDs. Events are specified with their symbolic names. These measures make this class independent from the server's classes and easily serializable.
The targets' IDs will be split in two sets, depending on the resource type:
The main reason for this approach is that widgets on client-side have their own unique IDs which are computed differently from their associated resource ID on the server-side. Thus, mixing client-side widget IDs and resource IDs would not allow to differentiate which is which and it cascades in lot of changes in the client UI code. Also, for the same reason, a widget referenced via a handle in a i.e. "wait-for close of h" statement will register it in the set of widget IDs, and not resources. The other reason was that the client uses a stack of UI event-queues which is empty when no wait-for loop is running; thus, server-events can not be posted there because they will get discarded if the event-queue is "trashed".Modifier and Type | Field and Description |
---|---|
private boolean |
anywhere
Widget-specific ANYWHERE option, if given.
|
private java.lang.Integer |
event
The event ID associated with this instance IF and ONLY IF there is only 1 event.
|
private org.roaringbitmap.RoaringBitmap |
events
Set of event IDs associated with this instance IF AND ONLY IF there is more than one event.
|
private boolean |
globalAnywhere
Global ANYWHERE option, if given.
|
private static byte |
MASK_ANYWHERE
Bitwise mask for the anywhere flag.
|
private static byte |
MASK_EVENT_SET
Bitwise mask to mark if the events are a Set or String in the stream.
|
private static byte |
MASK_GLOBAL_ANYWHERE
Bitwise mask for the global anywhere flag.
|
private static byte |
MASK_HAS_EVENT
Bitwise mask to mark if there are events in the stream.
|
private static byte |
MASK_HAS_RESOURCE
Bitwise mask to mark if there are resources in the stream.
|
private static byte |
MASK_HAS_WIDGET
Bitwise mask to mark if there are widgets in the stream.
|
private static byte |
MASK_RESOURCE_SET
Bitwise mask to mark if the resources are a Set or long in the stream.
|
private static byte |
MASK_WIDGET_SET
Bitwise mask to mark if the widgets are a Set or int in the stream.
|
private long |
resource
The resource associated with this instance IF and ONLY IF there is only 1 resource.
|
private org.roaringbitmap.longlong.Roaring64Bitmap |
resources
Set of resources (or not-attached widget) IF AND ONLY IF there is more than one resource.
|
private int |
triggerId
Trigger assigned to the event definition or -1 if this is an exit condition.
|
private int |
widget
The widget associated with this instance IF and ONLY IF there is only 1 widget.
|
private org.roaringbitmap.RoaringBitmap |
widgets
Set of widget IDs associated with this instance IF AND ONLY IF there is more than one widget.
|
Constructor and Description |
---|
EventDefinition()
Default constructor.
|
EventDefinition(boolean anywhere,
java.lang.Integer widgetId,
java.lang.Integer event)
Create a new event definition for the specified widget and event.
|
EventDefinition(boolean anywhere,
java.lang.Long resId,
java.lang.Integer event)
Create a new event definition for the specified resource and event.
|
EventDefinition(EventDefinition ed)
Copy state from the given instance to this one.
|
EventDefinition(java.lang.Integer event)
Create a new global ANYWHERE event definition for the specified event.
|
EventDefinition(java.lang.Integer event,
java.lang.Integer widget,
java.lang.Long resource,
boolean anywhere)
A constructor.
|
EventDefinition(java.lang.Integer event,
org.roaringbitmap.RoaringBitmap widgets,
org.roaringbitmap.longlong.Roaring64Bitmap resources,
boolean anywhere)
A constructor.
|
EventDefinition(org.roaringbitmap.RoaringBitmap events,
java.lang.Integer widget,
java.lang.Long resource,
boolean anywhere)
A constructor.
|
EventDefinition(org.roaringbitmap.RoaringBitmap events,
org.roaringbitmap.RoaringBitmap widgets,
org.roaringbitmap.longlong.Roaring64Bitmap resources,
boolean anywhere)
A constructor.
|
EventDefinition(java.util.Set<java.lang.String> events,
org.roaringbitmap.RoaringBitmap widgets,
org.roaringbitmap.longlong.Roaring64Bitmap resources,
boolean anywhere)
A constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
anyEventForWidget(int widgetId)
Checks whether this definition contains exit conditions referring
to the specified widget.
|
(package private) boolean |
cleanup(long rid,
int wid)
Remove the given resource and widget ids from the event definition.
|
(package private) void |
collectResourceIds(org.roaringbitmap.longlong.Roaring64Bitmap res)
Collect the resource ids registered for this event definition.
|
(package private) void |
collectWidgetIds(org.roaringbitmap.RoaringBitmap wids)
Collect the widget ids registered for this event definition.
|
(package private) boolean |
containsWidget(int wid)
Checks if the given widget id is contained in the widgets list of this event definition.
|
void |
copyEvents(EventDefinition ed)
Copy all events (if they exist) from the given instance into the current instance.
|
void |
copyResources(EventDefinition ed)
Copy all resources (if they exist) from the given instance into the current instance.
|
void |
copyWidgets(EventDefinition ed)
Copy all widgets (if they exist) from the given instance into the current instance.
|
EventDefinition[] |
difference(EventDefinition ed)
Returns a list of 0 to 2 instances of
EventDefinition s which represent the
events, widgets and resources of this instance which are not in the specified one. |
void |
eventsDifference(EventDefinition ed,
EventDefinition ned)
Subtract the events from the given instance from this instance and put then into the new instance.
|
boolean |
eventsIntersect(EventDefinition ed)
Reports if the two instances have intersecting events.
|
void |
eventsIntersection(EventDefinition ed,
EventDefinition ned)
Updates an instance of
EventDefinition which represents the common events. |
void |
gatherEventCodes(org.roaringbitmap.RoaringBitmap eventCodes)
Gather all the event codes in the given bitmap.
|
private void |
generateAtoms(java.lang.Integer name,
java.util.List<EventDefinition> atoms)
Create a set of separate definitions which pairs the given event with each widget, resource and one
for global-anywhere (if that is set).
|
int[][] |
getRowDisplayEvents()
Search for registered ROW-DISPLAY events.
|
int |
getTriggerId()
Gets trigger ID of this event definition.
|
(package private) org.roaringbitmap.RoaringBitmap |
getWidgetIds()
Get the widget ids registered for this event.
|
boolean |
hasEvent()
Report if there is any event in this definition.
|
boolean |
hasResource()
Report if there is any resource in this definition.
|
boolean |
hasSameEvents(EventDefinition other)
Reports if the given event definition has the exact same events as the current instance.
|
boolean |
hasSameResources(EventDefinition other)
Reports if the given event definition has the exact same resources as the current instance.
|
boolean |
hasSameWidgets(EventDefinition other)
Reports if the given event definition has the exact same widgets as the current instance.
|
boolean |
hasWidget()
Report if there is any widget in this definition.
|
EventDefinition |
intersection(EventDefinition ed)
Returns an instance of
EventDefinition which represents the common events,
widgets and resources with the specified one. |
boolean |
intersects(EventDefinition ed)
Checks whether this event definition has common events, widgets and resources with the
specified one.
|
boolean |
isAnywhere()
Gets widget or resource anywhere flag of this event definition.
|
boolean |
isAnywhereGlobally()
Check if this is a trigger for ANYWHERE globally.
|
boolean |
isEventMatch(java.lang.Integer name)
Check if the given event name is part of this instance.
|
static boolean |
isEventUniversal(int eventCode)
Classifies events as either universal or regular.
|
boolean |
isResourceMatch(long id)
Check if this is an event for given resource ID.
|
boolean |
isSame(EventDefinition other)
Reports if the given event definition is the same (in all data except for the trigger ID)
as the current instance.
|
boolean |
isWidgetMatch(int id)
Check if this is a exact event for given widget ID.
|
void |
lookup(int frameId,
int widgetId,
java.lang.Integer event,
boolean isTrigger,
boolean specific,
boolean universal,
TriggerMatch result)
Checks whether this event matches any event defined in this
EventDefinition
instance. |
int |
lookup(long resourceId,
java.lang.Integer event,
boolean trigExit)
Checks whether this server event matches any server event defined in this
EventDefinition instance. |
void |
processResources(java.util.function.Consumer<java.lang.Long> f)
Apply the given function to all resource IDs.
|
void |
processWidgets(java.util.function.Consumer<java.lang.Integer> f)
Apply the given function to all widget IDs.
|
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
resourcesDifference(EventDefinition ed,
EventDefinition ned)
Subtract the resources from the given instance from this instance and put then into the new instance.
|
boolean |
resourcesIntersect(EventDefinition ed)
Reports if the two instances have intersecting resources.
|
void |
resourcesIntersection(EventDefinition ed,
EventDefinition ned)
Updates an instance of
EventDefinition which represents the common resources. |
void |
setTriggerId(int triggerId)
Sets trigger ID for this event definition making it a trigger event
definition.
|
void |
splitEvents(java.util.List<EventDefinition> atoms)
Split the events in this definition into (id, event) and (anywhere, event) pairs.
|
java.lang.String |
toString()
Renders the instances as text.
|
private java.lang.String |
toString(java.lang.Integer event)
Get the string representation of this event.
|
private java.lang.String |
toString(org.roaringbitmap.RoaringBitmap events)
Get the string representation of all the events in this bitmap.
|
void |
widgetsDifference(EventDefinition ed,
EventDefinition ned)
Subtract the widgets from the given instance from this instance and put then into the new instance.
|
boolean |
widgetsIntersect(EventDefinition ed)
Reports if the two instances have intersecting widgets.
|
void |
widgetsIntersection(EventDefinition ed,
EventDefinition ned)
Updates an instance of
EventDefinition which represents the common widgets. |
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
private static final byte MASK_HAS_EVENT
private static final byte MASK_EVENT_SET
private static final byte MASK_HAS_WIDGET
private static final byte MASK_WIDGET_SET
private static final byte MASK_HAS_RESOURCE
private static final byte MASK_RESOURCE_SET
private static final byte MASK_ANYWHERE
private static final byte MASK_GLOBAL_ANYWHERE
private java.lang.Integer event
private org.roaringbitmap.RoaringBitmap events
private int widget
private org.roaringbitmap.RoaringBitmap widgets
private long resource
private org.roaringbitmap.longlong.Roaring64Bitmap resources
private boolean anywhere
private boolean globalAnywhere
private int triggerId
public EventDefinition()
public EventDefinition(java.util.Set<java.lang.String> events, org.roaringbitmap.RoaringBitmap widgets, org.roaringbitmap.longlong.Roaring64Bitmap resources, boolean anywhere)
events
- a Set of event nameswidgets
- a Set of widget IDsresources
- a Set of non-widget resource IDsanywhere
- true
if these events are defined as ANYWHEREpublic EventDefinition(org.roaringbitmap.RoaringBitmap events, org.roaringbitmap.RoaringBitmap widgets, org.roaringbitmap.longlong.Roaring64Bitmap resources, boolean anywhere)
events
- a bitmap of event IDswidgets
- a Set of widget IDsresources
- a Set of non-widget resource IDsanywhere
- true
if these events are defined as ANYWHEREpublic EventDefinition(java.lang.Integer event, java.lang.Integer widget, java.lang.Long resource, boolean anywhere)
event
- an event IDwidget
- a widget IDresource
- a non-widget resource IDanywhere
- true
if these events are defined as ANYWHEREpublic EventDefinition(org.roaringbitmap.RoaringBitmap events, java.lang.Integer widget, java.lang.Long resource, boolean anywhere)
events
- The event IDs.widget
- a widget IDresource
- a non-widget resource IDanywhere
- true
if these events are defined as ANYWHEREpublic EventDefinition(java.lang.Integer event, org.roaringbitmap.RoaringBitmap widgets, org.roaringbitmap.longlong.Roaring64Bitmap resources, boolean anywhere)
event
- The event ID.widgets
- a Set of widget IDsresources
- a Set of non-widget resource IDsanywhere
- true
if these events are defined as ANYWHEREEventDefinition(EventDefinition ed)
ed
- The source instance.EventDefinition(boolean anywhere, java.lang.Integer widgetId, java.lang.Integer event)
anywhere
- State of the ANYWHERE option for ON ... event OF resource ANYWHERE.widgetId
- The widget ID.event
- The event ID.EventDefinition(boolean anywhere, java.lang.Long resId, java.lang.Integer event)
anywhere
- State of the ANYWHERE option for ON ... event OF resource ANYWHERE.resId
- The resource ID.event
- The event ID.EventDefinition(java.lang.Integer event)
event
- The event ID.public static boolean isEventUniversal(int eventCode)
eventCode
- numeric event codetrue
if event is universal.public void gatherEventCodes(org.roaringbitmap.RoaringBitmap eventCodes)
eventCodes
- The map where to add all event codes.public void copyEvents(EventDefinition ed)
ed
- The source instance.public void copyWidgets(EventDefinition ed)
ed
- The source instance.public void copyResources(EventDefinition ed)
ed
- The source instance.public boolean isSame(EventDefinition other)
other
- The event definition to compare against.true
if the definitions are the same except the trigger ID.public boolean hasSameEvents(EventDefinition other)
other
- The event definition to compare against.true
if the definitions have the same events.public boolean hasSameWidgets(EventDefinition other)
other
- The event definition to compare against.true
if the definitions have the same widgets.public boolean hasSameResources(EventDefinition other)
other
- The event definition to compare against.true
if the definitions have the same resources.public boolean isAnywhere()
This does not track the global ANYWHERE event support. This is because global ANYWHERE
events are tracked in P2J without setting this flag, only when widgets
and
resources
are both null
. See isAnywhereGlobally()
.
TRUE
if the ANYWHERE option was specified with one or more widgets
or resources.public boolean isAnywhereGlobally()
public boolean isWidgetMatch(int id)
id
- The widget ID to test.true
if the event has been defined for particular widget.public boolean isEventMatch(java.lang.Integer name)
name
- The event ID to test.true
if the event has been defined for particular event name.public boolean isResourceMatch(long id)
id
- The resource ID to test.true
if the event has been defined for the particular resource.public boolean hasEvent()
true
if at least one event has been defined.public boolean hasWidget()
true
if at least one widget has been defined.public boolean hasResource()
true
if at least one resource has been defined.public int[][] getRowDisplayEvents()
public void setTriggerId(int triggerId)
triggerId
- ID of a trigger from the trigger registrypublic int getTriggerId()
-1
if this event definition
is for an exit condition.public void lookup(int frameId, int widgetId, java.lang.Integer event, boolean isTrigger, boolean specific, boolean universal, TriggerMatch result)
EventDefinition
instance.frameId
- Frame ID, can be -1
.widgetId
- Widget ID to check or -1 if this is a global anywhere event.event
- The event ID.isTrigger
- true
if the search is for a trigger or false
to
seach for an exit condition.specific
- true
if an exact match is to be returned.universal
- true
if the event is of the universal class.result
- On output both trigger ID and matched widget ID may be modified. If no match
was found, then the trigger ID will be set to -1.public int lookup(long resourceId, java.lang.Integer event, boolean trigExit)
EventDefinition
instance. Only exit conditions are checked.resourceId
- The ID of the resource.event
- event ID.trigExit
- flag, telling the search is for a trigger (true
)
or for an exit condition (false
).public boolean anyEventForWidget(int widgetId)
widgetId
- widget ID to checktrue
if the widget is referred from herepublic boolean eventsIntersect(EventDefinition ed)
ed
- The other instance to check against.true
if the event sets intersect.public boolean widgetsIntersect(EventDefinition ed)
ed
- The other instance to check against.true
if the widget sets intersect.public boolean resourcesIntersect(EventDefinition ed)
ed
- The other instance to check against.true
if the resource sets intersect.public boolean intersects(EventDefinition ed)
They intersect, if:
ed
- another instance of EventDefinition
true
if the event definitions have common events and widgetspublic void eventsIntersection(EventDefinition ed, EventDefinition ned)
EventDefinition
which represents the common events.ed
- The other instance to calculate the intersection against.ned
- The instance in which to collect the intersection.public void widgetsIntersection(EventDefinition ed, EventDefinition ned)
EventDefinition
which represents the common widgets.ed
- The other instance to calculate the intersection against.ned
- The instance in which to collect the intersection.public void resourcesIntersection(EventDefinition ed, EventDefinition ned)
EventDefinition
which represents the common resources.ed
- The other instance to calculate the intersection against.ned
- The instance in which to collect the intersection.public EventDefinition intersection(EventDefinition ed)
EventDefinition
which represents the common events,
widgets and resources with the specified one.
The returned EventDefinition
retains all remaining internal fields of this one.
ed
- another instance of EventDefinition
EventDefinition
or null
if there is
nothing in common.public void eventsDifference(EventDefinition ed, EventDefinition ned)
ed
- The instance to be subtracted.ned
- The new instance. It will have any events in the current instance that aren't in the ed
instance.public void widgetsDifference(EventDefinition ed, EventDefinition ned)
ed
- The instance to be subtracted.ned
- The new instance. It will have any widgets in the current instance that aren't in the ed
instance.public void resourcesDifference(EventDefinition ed, EventDefinition ned)
ed
- The instance to be subtracted.ned
- The new instance. It will have any resources in the current instance that aren't in the ed
instance.public EventDefinition[] difference(EventDefinition ed)
EventDefinition
s which represent the
events, widgets and resources of this instance which are not in the specified one.
The result list is empty if event, widget and resource lists match exactly.
If this is not the case, the result list contains 1 instance when widget lists match in both instances or don't exist, otherwise two.
More specifically, the resulting list is calculated as follows:
EventDefinition
is created off the DE, IW and IR
sets;
EventDefinition
is created off this events
(original set), and DW and DR sets if either DW or DR set is not empty
ed
- another instance of EventDefinition
EventDefinition
s or null
if there is nothing in
common.
The first element is for the hasEvent()
difference, the second is for the
hasWidget()
or hasResource()
difference. Each one can be null
.public void splitEvents(java.util.List<EventDefinition> atoms)
atoms
- The list to collect the new definitions.public void processWidgets(java.util.function.Consumer<java.lang.Integer> f)
f
- The function to apply.public void processResources(java.util.function.Consumer<java.lang.Long> f)
f
- The function to apply.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.public java.lang.String toString()
toString
in class java.lang.Object
void collectWidgetIds(org.roaringbitmap.RoaringBitmap wids)
wids
- The collection location.org.roaringbitmap.RoaringBitmap getWidgetIds()
boolean containsWidget(int wid)
wid
- The given widget idvoid collectResourceIds(org.roaringbitmap.longlong.Roaring64Bitmap res)
res
- The collection location.boolean cleanup(long rid, int wid)
rid
- Resource ID to remove.wid
- Widget ID to remove.true
if either or both IDs were removed.private void generateAtoms(java.lang.Integer name, java.util.List<EventDefinition> atoms)
name
- The event ID.atoms
- The list to collect the results.private java.lang.String toString(java.lang.Integer event)
event
- The event ID.private java.lang.String toString(org.roaringbitmap.RoaringBitmap events)
events
- The event IDs.