public class Union<T>
extends java.lang.Object
Integer, String)
and Elastic PL/I classes (FixedBin, Complex)
both mutable and sharable. So, two Groups that contain similar elements
are defined as containing those elements of type
UnionPL/I code
DCL 1 A,
2 B FIXED BIN(15)
2 C FIXED BIN(31)
2 D CHAR(10);
DCL 1 W BASED(ADDR(A)),
2 X FIXED BIN(15)
2 Y FIXED BIN(31)
2 Z CHAR(10);
A.C = 11;
W.Y = 22;
IF A.C = W.Y THEN PUT SKIP LIST('CORRECT');
ELSE PUT SKIP LIST('INCORRECT');
Java code
class A extends Group {
@OFF(0) Union b = new Union(short)0);
@OFF(2) Union c = new Union((int)0);
@OFF(6) @CHAR(10) Union d = new Union(" ");
}
A a = new A();
class W extends Group {
@OFF(0) Union x = a.b;
@OFF(2) Union y = a.c;
@OFF(6) @CHAR(10) Union z = a.z;
}
a.c.set(11);
W w = new W();
w.y.set(22);
if (a.c.get() = w.y.get()) {
System.out.println();
System.out.println("CORRECT");
} else {
System.out.println();
System.out.println("INCORRECT");
}
Or a single structure (or fields or variables) which are UNIONs or contain UNIONs
of one or more elements
PL/I code
DCL 1 G,
2 H FIXED BIN(15),
2 I UNION,
3 I1 FIXED BIN(31),
3 I2 FIXED BIN(31),
2 J CHAR(10)
// set the two elements to different values but because they are
// shared they should be the same (last set) value
G.I1 = 77;
G.I2 = 88;
IF I1 = I2 THEN PUT SKIP LIST('CORRECT');
ELSE PUT SKIP LIST('INCORRECT');
Java code
class G extends Group {
@OFF(0) Short h = Short.valueOf((short) 0);
@OFF(2) Union i1 = (new Union()).set((int) 0);
@OFF(2) Union i2 = i1;
@OFF(6) @CHAR(10) String j = new String(" ");
}
G g = new G();
// set the two elements to different values but because they are
// shared they should be the same (last set) value
g.i1.set((int) 77);
g.i2.set((int) 88);
if (g.i1.get() == g.i2.get()) {
System.out.println();
System.out.print("CORRECT");
} else {
System.out.println();
System.out.print("INCORRECT");
}
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES
size in bytes if converted to a byte array
|
protected int |
len |
protected int |
off |
protected T |
ref
the Object to which this Union refers
|
protected Union<T> |
uni
share a byte-range of another object
|
| Constructor and Description |
|---|
Union()
Construct a null Union
|
Union(T ref)
Construct a Union referencing another object
|
Union(Union<T> uni,
int off,
int len)
Construct a Union referencing another union's byte range
|
| Modifier and Type | Method and Description |
|---|---|
Union<T> |
fromBytes(byte[] bytes)
turn a sequence of bytes into a Union
|
T |
get()
Return the underlying shared object of this Union
|
static void |
main(java.lang.String[] args)
Union unit test
|
Union<T> |
set(T obj)
set the underlying shared object of this Union
|
byte[] |
toBytes()
turn a shared object of the Union into a sequence of bytes
|
java.lang.String |
toString()
convert the underlying object to a string
|
public static final int BYTES
protected T ref
protected int off
protected int len
public Union()
public Union(T ref)
public T get()
CONDITION - for NULLPOINTER if this Union was never setpublic Union<T> set(T obj)
obj - of type T to set this shared objectpublic byte[] toBytes()
CONDITION - for NULLPOINTER if this Union was never setpublic Union<T> fromBytes(byte[] bytes)
bytes - - sequence of bytes representing a UnionCONDITION - for NULLPOINTER if this Union was never setpublic java.lang.String toString()
toString in class java.lang.ObjectCONDITION - for NULLPOINTER if this Union was never setpublic static void main(java.lang.String[] args)