tuwien.auto.calimero
Class GroupAddress

java.lang.Object
  extended by tuwien.auto.calimero.KNXAddress
      extended by tuwien.auto.calimero.GroupAddress

public class GroupAddress
extends KNXAddress

Represents an immutable KNX group address.

Both 2- and 3-level formats are supported. Available groups are

with separator of type '.' or '/'.
By default, the 3-level group notation is used.

Note, that the most significant bit of the main group (i.e. bit 15 in the unstructured address) is reserved, but not in use for now. Hence this bit is not checked for, but nevertheless stored and returned by this implementation.


Constructor Summary
GroupAddress(byte[] address)
          Creates a KNX group address from a byte array value.
GroupAddress(int address)
          Creates a KNX group address from a 16 Bit address value.
GroupAddress(int mainGroup, int subGroup)
          Creates a KNX group address from the 2-level notation main- and sub-group.
GroupAddress(int mainGroup, int middleGroup, int subGroup)
          Creates a KNX group address from the 3-level notation main-, middle- and sub-group.
GroupAddress(java.lang.String address)
          Creates a KNX group address from a string address representation.
GroupAddress(XMLReader r)
          Creates a KNX group address from XML input.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Returns whether obj is equal to this KNX address (type).
 byte getMainGroup()
          Returns the main group value.
 byte getMiddleGroup()
          Returns the middle group value for the 3-level group notation.
 short getSubGroup11()
          Returns the sub group value for the 2-level group notation.
 short getSubGroup8()
          Returns the sub group value for the 3-level group notation.
 java.lang.String getType()
          Returns the KNX address type, identifying a group or individual address.
 int hashCode()
           
static boolean is3LevelPresentation()
          Returns the current presentation of group addresses.
static void setLevelPresentation(boolean format3Level)
          Specifies the level presentation for KNX group addresses.
 java.lang.String toString()
          Returns the address as string using the '/' separator.
 
Methods inherited from class tuwien.auto.calimero.KNXAddress
create, create, getRawAddress, save, toByteArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GroupAddress

public GroupAddress(byte[] address)
Creates a KNX group address from a byte array value.

The address is read out of the first 2 byte fields, while the address array itself might be longer. The content of address is not modified.

Parameters:
address - the address byte array in big-endian format, with address.length > 1

GroupAddress

public GroupAddress(int address)
Creates a KNX group address from a 16 Bit address value.

Parameters:
address - the address value in the range 0 <= value <= 0xFFFF

GroupAddress

public GroupAddress(int mainGroup,
                    int subGroup)
Creates a KNX group address from the 2-level notation main- and sub-group.

Parameters:
mainGroup - main group value, in the range 0 <= value <= 0x1F
subGroup - sub group value, in the range 0 <= value <= 0x7FF

GroupAddress

public GroupAddress(int mainGroup,
                    int middleGroup,
                    int subGroup)
Creates a KNX group address from the 3-level notation main-, middle- and sub-group.

Parameters:
mainGroup - main group value, in the range 0 <= value <= 0x1F
middleGroup - middle group value, in the range 0 <= value <= 0x7
subGroup - sub group value, in the range 0 <= value <= 0xFF

GroupAddress

public GroupAddress(java.lang.String address)
             throws KNXFormatException
Creates a KNX group address from a string address representation.

The address might be formatted in 2- or 3-level groups. Allowed separators are '.' or '/', mutually exclusive.

Parameters:
address - string containing the KNX address
Throws:
KNXFormatException - on unknown address type, wrong address syntax, group values out of range, or wrong separator used

GroupAddress

public GroupAddress(XMLReader r)
             throws KNXMLException
Creates a KNX group address from XML input.

If the current XML element position is no start tag, the next element tag is read. The KNX address element is then expected to be the current element in the reader.

Parameters:
r - a XML reader
Throws:
KNXMLException - if the xml element is no KNX address or the address couldn't be read in correctly
Method Detail

equals

public boolean equals(java.lang.Object obj)
Returns whether obj is equal to this KNX address (type).

Overrides:
equals in class java.lang.Object
Parameters:
obj - KNX address object
Returns:
true iff obj is of this type and contains the same address (raw), false otherwise

getMainGroup

public final byte getMainGroup()
Returns the main group value.

The main group is equal for both the 2- and 3-level group address notation (see class header specification).

Returns:
the main group value (5 most significant address bits)

getMiddleGroup

public final byte getMiddleGroup()
Returns the middle group value for the 3-level group notation.

The middle group consists of 3 bits, starting with bit 8 to 10 in the address field.

Returns:
the middle group value (3 bits)

getSubGroup11

public final short getSubGroup11()
Returns the sub group value for the 2-level group notation.

The sub group consists of the lower 11 bits in the address field.

Returns:
the sub group value (11 least significant address bits)

getSubGroup8

public final short getSubGroup8()
Returns the sub group value for the 3-level group notation.

The sub group consists of the low byte of the address field.

Returns:
the sub group value (8 least significant address bits)

getType

public java.lang.String getType()
Description copied from class: KNXAddress
Returns the KNX address type, identifying a group or individual address.

Specified by:
getType in class KNXAddress
Returns:
address type as string

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

is3LevelPresentation

public static boolean is3LevelPresentation()
Returns the current presentation of group addresses.

Returns:
true for 3-level formatting, false otherwise

setLevelPresentation

public static void setLevelPresentation(boolean format3Level)
Specifies the level presentation for KNX group addresses.

Note that, since this notation of levels only affects visual presentation and not internal operation, this is a class setting.

Parameters:
format3Level - true for 3-level group format, false for 2-level group format

toString

public java.lang.String toString()
Returns the address as string using the '/' separator.

Depending on is3LevelPresentation(), the address is formatted in 2- or 3-level group notation.

Overrides:
toString in class java.lang.Object
Returns:
the address string