Package jmri.jmrix.openlcb
Class OlcbAddress
- java.lang.Object
-
- jmri.jmrix.openlcb.OlcbAddress
-
public 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.
Forms:
- Full hex string preceeded by "x"
- Needs to be pairs of digits: 0123, not 123
- Full 8 byte ID as pairs separated by "."
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.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int[]
aFrame
(package private) java.lang.String
aString
(package private) static int
GROUP_DOT_HEX
(package private) static int
GROUP_FULL_HEX
(package private) boolean
match
(package private) static int
NODEFACTOR
(package private) static java.lang.String
singleAddressPattern
-
Constructor Summary
Constructors Constructor Description OlcbAddress(java.lang.String s)
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()
int
compare(OlcbAddress opp)
static int
compareSystemNameSuffix(java.lang.String suffix1, java.lang.String suffix2)
(package private) int[]
elements()
boolean
equals(java.lang.Object r)
Two addresses are equal if they result in the same numeric contentsint
hashCode()
CanMessage
makeMessage()
(package private) boolean
match(CanMessage r)
(package private) boolean
match(CanReply r)
OlcbAddress[]
split()
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)
Validates Strings for OpenLCB format.static java.lang.String
validateSystemNameFormat2Part(java.lang.String name, java.util.Locale locale, java.lang.String prefix)
Validates 2 part Hardware Address Strings for OpenLCB format.
-
-
-
Field Detail
-
GROUP_FULL_HEX
static final int GROUP_FULL_HEX
- See Also:
- Constant Field Values
-
GROUP_DOT_HEX
static final int GROUP_DOT_HEX
- See Also:
- Constant Field Values
-
singleAddressPattern
static final java.lang.String singleAddressPattern
- See Also:
- Constant Field Values
-
aString
java.lang.String aString
-
aFrame
int[] aFrame
-
match
boolean match
-
NODEFACTOR
static final int NODEFACTOR
- 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 s)
Construct from string without leading system or type letters- Parameters:
s
- 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()
Split a string containing one or more addresses into individual ones.- Returns:
- null if entire string can't be parsed.
-
checkSplit
public boolean checkSplit()
-
elements
int[] elements()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toCanonicalString
public java.lang.String toCanonicalString()
-
toDottedString
public java.lang.String toDottedString()
Provide as dotted pairs.- Returns:
- dotted pair form off string.
-
validateSystemNameFormat
@Nonnull public static java.lang.String validateSystemNameFormat(@Nonnull java.lang.String name, @Nonnull java.util.Locale locale, @Nonnull java.lang.String prefix) 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) 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)
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.
-
-