Named vs. Numbered Variables

Like MAPPER variables, MJ variables may be named (<firstOp>, for example), numbered (V22) or both (aliased, similar to MAPPER USE statement). As such, each MJ variable class has a Named subclass, Numbered subclass and Aliased subclass:

MJ Variable Class Named Subclass Numbered Subclass Aliased Subclass
MJString MJNamedString MJNumberedString MJAliasedString
MJInteger MJNamedInteger MJNumberedInteger MJAliasedInteger
MJDecimal MJNamedDecimal MJNumberedDecimal MJAliasedDecimal
MJDate MJNamedDate MJNumberedDate MJAliasedDate

Named and Numbered Variables

Here are a few examples of named and numbered variables:

// @LDV <firstOp>f10=12.34e+02 .
MJDecimal firstOp = new MJNamedDecimal("firstOp", VariableScope.LOCAL, 10, 0,
  EnumSet.noneOf(LoadOption.class), "12.34e+02");
assert firstOp instanceof INamedVariable;
assert ((INamedVariable) firstOp).getVariableName().equals("firstOp");

// @LDV <PNAME>s25='O. Henry' .
MJNamedString strPName = new MJNamedString("PNAME", VariableScope.LOCAL,
  MaprptVariableType.STRING, 25, EnumSet.of(LoadOption.TRUNCATE), "O. Henry");
assert strPName.getVariableName().equals("PNAME");

// @LDV V22i5=1234 .
MJNumberedInteger int22 = new MJNumberedInteger(22, VariableScope.LOCAL,
  5, EnumSet.noneOf(LoadOption.class), "1234");
assert int22.getVariableNumber() == 22;

// @LDV v33A10='GREEN' .
MJString str33 = new MJNumberedString(33, VariableScope.LOCAL,
  MaprptVariableType.ALPHANUMERIC, 10, EnumSet.of(LoadOption.TRUNCATE), "GREEN");
assert str33 instanceof INumberedVariable;
assert ((INumberedVariable) str33).getVariableNumber() == 33;

Aliased Variables

The Aliased subclasses identify an MJ variable by both name and number, providing the equivalent of the MAPPER USE statement:

// @LDV V44f10=12.34e+02 .
// @USE secondOp=V44 .
MJDecimal secondOp = new MJAliasedDecimal(44, "secondOp", VariableScope.LOCAL, 10, 0,
  EnumSet.noneOf(LoadOption.class), "12.34e+02");
assert secondOp instanceof IAliasedVariable;
assert secondOp instanceof INamedVariable;
assert ((INamedVariable) secondOp).getVariableName().equals("secondOp");
assert secondOp instanceof INumberedVariable;
assert ((INumberedVariable) secondOp).getVariableNumber() == 44;

// @LDV v45i9='1234567.' .
// @USE intVar=v45 .
MJAliasedInteger intVar45 = new MJAliasedInteger(45, "intVar", VariableScope.LOCAL, 9,
  EnumSet.noneOf(LoadOption.class), "1234567.");
assert intVar45.getVariableName().equals("intVar");
assert intVar45.getVariableNumber() == 45;