The BEnum
base class is used to define enumerated types. An enum is composed of a
fixed set of int/String pairs called its range. The int
identifiers are called ordinals and the String identifiers
are called tags. Enum ranges are managed by the
BEnumRange
class.
There are three subclasses of BEnum
. BBoolean
is a special case which models a boolean
primitive. The
BDynamicEnum
class is used to manage weakly typed enums
which may store any ordinal and range. Strongly typed enums may be
defined at compile time by subclassing BFrozenEnum
. The
Niagara Framework builds a BFrozenEnum's
range using the
following set of introspection rules:
BObjects
;
BSimples
(although BFrozenEnum
is not required to declare a
DEFAULT
field);
public static final
fields which
reference instances of the BFrozenEnum's
range. Each of
these BFrozenEnum
must declare a unique ordinal value.
By convention ordinals should start at zero and increment by one.
Each of these BFrozenEnum
must have a type exactly equal
to the declaring class.
BFrozenEnum
outside of the fields declaring its range. This means no other instances
declared in static fields, returned by a static method, or instantiable
through non-private constructors.
BFrozenEnum
declared in the range.
BFrozenEnum
is the first instance,
by convention with an ordinal value of zero.
public static final int
field is defined
for each BFrozenEnum
in the range to provide access to the
ordinal value.
BOrientation
:
/*
* Copyright 2000 Tridium, Inc. All Rights Reserved.
*/
package javax.baja.ui.enum;
import javax.baja.sys.*;
/**
* BOrientation defines a widget's orientation as
* either horizontal or vertical.
*/
public final class BOrientation
extends BFrozenEnum
{
public static final int HORIZONTAL = 0;
public static final int VERTICAL = 1;
public static final BOrientation horizontal = new BOrientation(HORIZONTAL);
public static final BOrientation vertical = new BOrientation(VERTICAL);
public Type getType() { return TYPE; }
public static final Type TYPE = Sys.loadType(BOrientation.class);
public static BOrientation make(int ordinal)
{
return (BOrientation)horizontal.getRange().get(ordinal);
}
public static BOrientation make(String tag)
{
return (BOrientation)horizontal.getRange().get(tag);
}
private BOrientation(int ordinal) { super(ordinal); }
}
Copyright © 2000-2019 Tridium Inc. All rights reserved.