Package jmri.jmrix.openlcb
Class OlcbAddress
- java.lang.Object
-
- jmri.jmrix.openlcb.OlcbAddress
-
public final class OlcbAddress extends java.lang.Object
Utilities for handling OpenLCB event messages as addresses.OpenLCB event messages have header information, plus an EventID in the data part. JMRI maps these into address strings.
String forms:
- Special case for DCC Turnout addressing: Tnnn where nnn is a decimal number
- Full hex string preceeded by "x"
- Needs to be pairs of digits: 0123, not 123
- Full 8 byte ID as pairs separated by "."
Note: the
check()
routine does a full, expensive validity check of the name. All other operations assume correctness, diagnose some invalid-format strings, but may appear to successfully handle other invalid forms. - Special case for DCC Turnout addressing: Tnnn where nnn is a decimal number
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
singleAddressPattern
-
Constructor Summary
Constructors Constructor Description OlcbAddress(java.lang.String input, CanSystemConnectionMemo memo)
Construct from string without leading system or type lettersOlcbAddress(EventID e)
Construct from OlcbEvent.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check()
Confirm that the address string (provided earlier) is fully valid.boolean
checkSplit(CanSystemConnectionMemo memo)
int
compare(OlcbAddress opp)
static int
compareSystemNameSuffix(java.lang.String suffix1, java.lang.String suffix2, CanSystemConnectionMemo memo)
(package private) int[]
elements()
boolean
equals(java.lang.Object r)
Two addresses are equal if they result in the same numeric contentsint
hashCode()
boolean
isFromName()
Was this parsed from a name (e.g. not explicit ID, not pair)CanMessage
makeMessage()
(package private) boolean
match(CanMessage r)
(package private) boolean
match(CanReply r)
OlcbAddress[]
split(CanSystemConnectionMemo memo)
Split a string containing one or more addresses into individual ones.java.lang.String
toCanonicalString()
java.lang.String
toDottedString()
Provide as dotted pairs.EventID
toEventID()
java.lang.String
toString()
static java.lang.String
validateSystemNameFormat(java.lang.String name, java.util.Locale locale, java.lang.String prefix, CanSystemConnectionMemo memo)
Validates Strings for OpenLCB format.static java.lang.String
validateSystemNameFormat2Part(java.lang.String name, java.util.Locale locale, java.lang.String prefix, CanSystemConnectionMemo memo)
Validates 2 part Hardware Address Strings for OpenLCB format.
-
-
-
Field Detail
-
singleAddressPattern
static final java.lang.String singleAddressPattern
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OlcbAddress
public OlcbAddress(EventID e)
Construct from OlcbEvent.- Parameters:
e
- the event ID.
-
OlcbAddress
public OlcbAddress(java.lang.String input, CanSystemConnectionMemo memo)
Construct from string without leading system or type letters- Parameters:
input
- hex coded string of address
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object r)
Two addresses are equal if they result in the same numeric contents- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compare
public int compare(@Nonnull OlcbAddress opp)
-
makeMessage
public CanMessage makeMessage()
-
check
public boolean check()
Confirm that the address string (provided earlier) is fully valid.This is an expensive call. It's complete-compliance done using a regular expression. It can reject some forms that the code will normally handle OK.
- Returns:
- true if valid, else false.
-
match
boolean match(CanMessage r)
-
split
public OlcbAddress[] split(CanSystemConnectionMemo memo)
Split a string containing one or more addresses into individual ones.- Returns:
- null if entire string can't be parsed.
-
checkSplit
public boolean checkSplit(CanSystemConnectionMemo memo)
-
elements
int[] elements()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toCanonicalString
public java.lang.String toCanonicalString()
- Returns:
- The canonical form of 0x1122334455667788
-
toDottedString
public java.lang.String toDottedString()
Provide as dotted pairs.- Returns:
- dotted pair form off string.
-
toEventID
public EventID toEventID()
- Returns:
- null if no valid address was parsed earlier, e.g. there was a ; in the data
-
isFromName
public boolean isFromName()
Was this parsed from a name (e.g. not explicit ID, not pair)- Returns:
- true if constructed from an event name
-
validateSystemNameFormat
@Nonnull public static java.lang.String validateSystemNameFormat(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, @Nonnull java.lang.String prefix, CanSystemConnectionMemo memo) throws NamedBean.BadSystemNameException
Validates Strings for OpenLCB format.- Parameters:
name
- the system name to validate.locale
- the locale for a localized exception.prefix
- system prefix, eg. MT for OpenLcb turnout.- Returns:
- the unchanged value of the name parameter.
- Throws:
NamedBean.BadSystemNameException
- if provided name is an invalid format.
-
validateSystemNameFormat2Part
@Nonnull public static java.lang.String validateSystemNameFormat2Part(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, @Nonnull java.lang.String prefix, CanSystemConnectionMemo memo) throws NamedBean.BadSystemNameException
Validates 2 part Hardware Address Strings for OpenLCB format.- Parameters:
name
- the system name to validate.locale
- the locale for a localized exception.prefix
- system prefix, eg. MT for OpenLcb turnout.- Returns:
- the unchanged value of the name parameter.
- Throws:
NamedBean.BadSystemNameException
- if provided name is an invalid format.
-
compareSystemNameSuffix
@CheckReturnValue public static int compareSystemNameSuffix(@Nonnull java.lang.String suffix1, @Nonnull java.lang.String suffix2, CanSystemConnectionMemo memo)
SeeNamedBean.compareSystemNameSuffix(java.lang.String, java.lang.String, jmri.NamedBean)
for background. This is a common implementation for OpenLCB Sensors and Turnouts of the comparison method.- Parameters:
suffix1
- 1st suffix to compare.suffix2
- 2nd suffix to compare.- Returns:
- true if suffixes match, else false.
-
-