org.opcfoundation.ua.utils
Class NumericRange

java.lang.Object
  extended by org.opcfoundation.ua.utils.NumericRange

public class NumericRange
extends Object

A helper class for defining index ranges according to the OPC UA specification. The index ranges are transferred as string values, but are easier to use with the NumericRange.


Constructor Summary
NumericRange()
          Constructor for NumericRange.
NumericRange(int begin)
          Initializes the object with a begin index.
NumericRange(int[]... indexes)
          Initializes the range with the default indexes.
NumericRange(int begin, int end)
          Initializes the object with a begin and end index.
 
Method Summary
 boolean ensureValid(int count)
          Tests the bounds are valid values for a collection with the specified length.
 boolean ensureValid(Object value)
          Ensures the bounds are valid values for the object passed in.
 boolean equals(Object obj)
          
 int getBegin()
          Getter for the field begin.
 int getBegin(int dim)
          Get the beginning of the range for the specified dimension.
 int getDimensions()
          The number of dimensions in the range.
static NumericRange getEmpty()
          getEmpty.
 int getEnd()
          Getter for the field end.
 int getEnd(int dim)
          Get the end of the range for the specified dimension.
 boolean isEmpty()
          Checks if the defined range is empty.
 boolean isEmpty(int dim)
          Checks if the defined range for the specified dimension is empty.
static boolean isNullOrEmpty(NumericRange indexRange)
          Check if the range is an empty range.
static NumericRange parse(String textToParse)
          Parses a string representing a numeric range.
 void setBegin(int value)
          Define the begin index of the range for the first dimension.
 void setBegin(int dim, int value)
          Define the begin index of the range for the specified dimension.
 void setDimensions(int dimensions)
          Define the number of dimensions for the NumericRange.
 void setEnd(int value)
          Define the end index of the range for the first dimension.
 void setEnd(int dim, int value)
          Define the end index of the range for the specified dimension.
 String toString()
          
static String toString(NumericRange indexRange)
          toString.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumericRange

public NumericRange()

Constructor for NumericRange.


NumericRange

public NumericRange(int begin)
Initializes the object with a begin index.

Parameters:
begin - a int.

NumericRange

public NumericRange(int begin,
                    int end)
Initializes the object with a begin and end index.

Parameters:
begin - a int.
end - a int.

NumericRange

public NumericRange(int[]... indexes)
Initializes the range with the default indexes. The dimensions will be initialized to the length of indexes.

Parameters:
indexes - the indexes to use for initializing the range. Each element is expected to define an array of [begin, end] indexes or just [begin].
Method Detail

ensureValid

public boolean ensureValid(Object value)
Ensures the bounds are valid values for the object passed in.

Returns false if the object is not indexable or if the numeric range is out of bounds.

Parameters:
value - a Object object.
Returns:
a boolean.

ensureValid

public boolean ensureValid(int count)
Tests the bounds are valid values for a collection with the specified length.

Returns false if the numeric range is out of bounds.

Parameters:
count - a int.
Returns:
true if valid

getBegin

public int getBegin()

Getter for the field begin.

Returns:
the begin index of the range for the first dimension.

getEnd

public int getEnd()

Getter for the field end.

Returns:
the end index of the range for the first dimension.

getBegin

public int getBegin(int dim)
Get the beginning of the range for the specified dimension.

Parameters:
dim - the dimension, minimum 0
Returns:
the begin index of the range for the specified dimension.

getEnd

public int getEnd(int dim)
Get the end of the range for the specified dimension.

Parameters:
dim - the dimension, minimum 0
Returns:
the end index of the range for the specified dimension.

setBegin

public void setBegin(int value)
Define the begin index of the range for the first dimension.

Parameters:
value - the begin index

setEnd

public void setEnd(int value)
Define the end index of the range for the first dimension.

Parameters:
value - the end index

setBegin

public void setBegin(int dim,
                     int value)
Define the begin index of the range for the specified dimension. Note that setDimensions(int) must be called first to define the number of dimensions in the range.

Parameters:
dim - the dimension, minimum 0
value - the begin index

setEnd

public void setEnd(int dim,
                   int value)
Define the end index of the range for the specified dimension. Note that setDimensions(int) must be called first to define the number of dimensions in the range.

Parameters:
dim - the dimension, minimum 0
value - the end index

getEmpty

public static NumericRange getEmpty()

getEmpty.

Returns:
a NumericRange object.

parse

public static NumericRange parse(String textToParse)
                          throws ServiceResultException
Parses a string representing a numeric range.

Parameters:
textToParse - a String object.
Returns:
numeric range
Throws:
ServiceResultException - in case the range is not in proper format

toString

public String toString()

Overrides:
toString in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

setDimensions

public void setDimensions(int dimensions)
Define the number of dimensions for the NumericRange. By default the range is 1-dimensional, but you can define a multidimensional range as well.

Parameters:
dimensions - the number of dimensions for the range; must be greater than 0

getDimensions

public int getDimensions()
The number of dimensions in the range.

Returns:
the dimensions

isEmpty

public boolean isEmpty()
Checks if the defined range is empty.

Returns:
a boolean.

isEmpty

public boolean isEmpty(int dim)
Checks if the defined range for the specified dimension is empty.

Parameters:
dim - the dimension to check
Returns:
a boolean.

isNullOrEmpty

public static boolean isNullOrEmpty(NumericRange indexRange)
Check if the range is an empty range. Adds a null check, in addition to the standard isEmpty() check.

Parameters:
indexRange - the range to check.
Returns:
true if indexRange is null or it is an empty range definition
See Also:
isEmpty()

toString

public static String toString(NumericRange indexRange)

toString.

Parameters:
indexRange - a NumericRange object.
Returns:
a String object.


Copyright © 2018. All rights reserved.