public class WidgetId extends java.lang.Object implements java.io.Externalizable, java.lang.Comparable<WidgetId>
Approach currently used reserves the 1 number for default window, the number 2 and 3 reserved
for tiny editor used to implement message that allows value change so it has one frame and one
fill-in widget. Every new widget static or dynamic will consume numbers from 4 up to maximum
value of the int
variable type. The widget ID is not normally reused when the
widget is deleted. Instead this freed number can be used again when integer number wrapping
happen - integer become negative in attempt to increase after maximum value reached. Two
sequential pass of full integer range without getting free ID means there is no free ID and
this generates runtime exception to avoid infinite loop.
Modifier and Type | Class and Description |
---|---|
private static class |
WidgetId.ClientArea
Stores global data relating to the state of the current session context, and provides
client-side ID generator.
|
private static class |
WidgetId.ContextContainer
Simple container that stores and returns a context-local instance of the global work area.
|
private static class |
WidgetId.IDGenerator
The base class for widget ID generation.
|
private static class |
WidgetId.SessionArea
Stores global data relating to the state of the current session context and provides
server-side ID generator.
|
Modifier and Type | Field and Description |
---|---|
static int |
_DEFAULT_WINDOW_ID
The ID for default window widget.
|
static WidgetId |
DEFAULT_WINDOW_ID
The ID for default window widget.
|
private int |
id
The widget's ID.
|
static WidgetId |
INPUT_FRAME_ID
The ID for tiny input editor frame used on client side for editable message.
|
private static WidgetId.ContextContainer |
session
Stores session context-local state variables.
|
private static int |
WIDGET_ID_RANGE_BEGIN
Starting number for the first widget ID.
|
Constructor and Description |
---|
WidgetId()
Default c'tor.
|
WidgetId(int id)
Create a new instance and associate the given ID.
|
Modifier and Type | Method and Description |
---|---|
int |
asInt()
Get the numeric representation of this widget id.
|
int |
compareTo(WidgetId wid)
Compare this instance with the given object.
|
WidgetId |
createId(int widgetId)
Create a new
WidgetDownId instance which is assigned the given widgetId . |
WidgetId |
createId(WidgetId widgetId)
Create a new
WidgetDownId instance which is assigned the given widgetId . |
boolean |
equals(java.lang.Object obj)
Check if the given object is the same as this one.
|
static boolean |
equals(WidgetId objId,
int id)
Returns
true when objId != null && objId.asInt() == id . |
int |
hashCode()
Compute a hash code for this widget ID.
|
static WidgetId |
nextID()
Retrieve the unique per session integer id number for next new widget to create.
|
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
java.lang.String |
toString()
Get a string representation of this ID.
|
static boolean |
virtualWidget(int id)
Check if the widget ID is virtual (negative).
|
static boolean |
virtualWidget(WidgetId id)
Check if the widget ID is virtual (null or negative).
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
public static final WidgetId DEFAULT_WINDOW_ID
public static final int _DEFAULT_WINDOW_ID
public static final WidgetId INPUT_FRAME_ID
private static final int WIDGET_ID_RANGE_BEGIN
private static WidgetId.ContextContainer session
private int id
public WidgetId()
public WidgetId(int id)
Can be used on both client and server-side.
id
- The widget ID.public static boolean virtualWidget(WidgetId id)
id
- The widget ID.public static boolean virtualWidget(int id)
id
- The widget ID.public static WidgetId nextID()
java.lang.RuntimeException
- If all possible IDs are in use. This is very unlikely but could happen!public WidgetId createId(WidgetId widgetId)
WidgetDownId
instance which is assigned the given widgetId
.widgetId
- The new widgetId.public WidgetId createId(int widgetId)
WidgetDownId
instance which is assigned the given widgetId
.widgetId
- The new widgetId.public int asInt()
id
.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 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 boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- The candidate.true
if this instance represents the same widget ID as the given one.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(WidgetId wid)
Comparable.compareTo(T)
.compareTo
in interface java.lang.Comparable<WidgetId>
wid
- The widget ID to compare against.Comparable.compareTo(T)
.public static boolean equals(WidgetId objId, int id)
true
when objId != null && objId.asInt() == id
.objId
- The object id.id
- The numeric id.