fm.liveswitch.Utility Class Reference

Utility methods. More...

Public Member Functions

 Utility ()
 

Static Public Member Functions

static< T > java.util.ArrayList< T > clone (java.util.ArrayList< T > list)
 Clones the specified list. More...
 
static int[] cloneIntArray (int[] intArray)
 Clones an array of int values. More...
 
static long[] cloneLongArray (long[] longArray)
 Clones an array of long values. More...
 
static String[] cloneStringArray (String[] stringArray)
 Clones an array of string values. More...
 
static< T > T firstOrDefault (T[] array)
 Gets the first element in the array or the default value if the array is null or empty. More...
 
static< T > T firstOrDefault (java.util.ArrayList< T > list)
 Gets the first element in the list or the default value if the list is null or empty. More...
 
static String formatDoubleAsPercent (double value, int decimalPlaces)
 Formats a double as a percentage string. More...
 
static String generateId ()
 Generates a globally unique identifier with no hyphens. More...
 
static long generateSynchronizationSource ()
 Generates a synchronization source. More...
 
static String generateTieBreaker ()
 Generates a tie-breaker. More...
 
static int getRtpSequenceNumberDelta (int rtpSequenceNumber, int lastRtpSequenceNumber)
 Retrieves the difference between two RTP sequence numbers while accounting for overflow rollover. More...
 
static long getRtpTimestampDelta (long rtpTimestamp, long lastRtpTimestamp)
 Retrieves the difference between two RTP timestamps while accounting for overflow rollover. More...
 
static< T > T lastOrDefault (T[] array)
 Gets the last element in the array or the default value if the array is null or empty. More...
 
static< T > T lastOrDefault (java.util.ArrayList< T > list)
 Gets the last element in the list or the default value if the list is null or empty. More...
 
static boolean nullableLongEquals (fm.liveswitch.NullableLong long1, fm.liveswitch.NullableLong long2)
 Compares two nullable longs for equality. More...
 
static< T > T singleOrDefault (T[] array)
 Gets the only element in the array or the default value if the array is null or does not have exactly one value. More...
 
static< T > T singleOrDefault (java.util.ArrayList< T > list)
 Gets the only element in the list or the default value if the list is null or does not have exactly one value. More...
 
static< T > T[] splice (T[] array, int index, T[] addItems, fm.liveswitch.IFunction1< Integer, T[]> createArray)
 Splices an array. More...
 
static< T > T[] splice (T[] array, int index, int removeCount, T[] addItems, fm.liveswitch.IFunction1< Integer, T[]> createArray)
 Splices an array. More...
 
static< T > T[] splice (T[] array, int index, int removeCount, fm.liveswitch.IFunction1< Integer, T[]> createArray)
 Splices an array. More...
 
static int[] toIntArray (java.util.ArrayList< Integer > intList)
 Converts a list of int values to an array of int values. More...
 
static< T > java.util.ArrayList< T > toList (T[] array)
 Converts an array to a list. More...
 
static long[] toLongArray (java.util.ArrayList< Long > longList)
 Converts a list of long values to an array of long values. More...
 
static String[] toStringArray (java.util.ArrayList< String > stringList)
 Converts a list of string values to an array of string values. More...
 
static< T > void treeFindLeaves (T root, fm.liveswitch.IFunction1< T, T[]> childrenCallback, fm.liveswitch.IAction1< T > nodeCallback)
 Enumerates over all nodes in the tree, invoking the callback for each one. More...
 
static< T > void treeSearch (T root, fm.liveswitch.IFunction1< T, T[]> childrenCallback, fm.liveswitch.IAction1< T > nodeCallback)
 Enumerates over all nodes in the tree, invoking the callback for each one. More...
 

Detailed Description

Utility methods.

Constructor & Destructor Documentation

◆ Utility()

fm.liveswitch.Utility.Utility ( )

Member Function Documentation

◆ clone()

static <T> java.util.ArrayList<T> fm.liveswitch.Utility.clone ( java.util.ArrayList< T >  list)
static

Clones the specified list.

Parameters
listThe list.

◆ cloneIntArray()

static int [] fm.liveswitch.Utility.cloneIntArray ( int[]  intArray)
static

Clones an array of int values.

Parameters
intArrayAn array of int values.

◆ cloneLongArray()

static long [] fm.liveswitch.Utility.cloneLongArray ( long[]  longArray)
static

Clones an array of long values.

Parameters
longArrayAn array of long values.

◆ cloneStringArray()

static String [] fm.liveswitch.Utility.cloneStringArray ( String[]  stringArray)
static

Clones an array of string values.

Parameters
stringArrayAn array of string values.

◆ firstOrDefault() [1/2]

static <T> T fm.liveswitch.Utility.firstOrDefault ( java.util.ArrayList< T >  list)
static

Gets the first element in the list or the default value if the list is null or empty.

Parameters
listThe list.

◆ firstOrDefault() [2/2]

static <T> T fm.liveswitch.Utility.firstOrDefault ( T[]  array)
static

Gets the first element in the array or the default value if the array is null or empty.

Parameters
arrayThe array.

◆ formatDoubleAsPercent()

static String fm.liveswitch.Utility.formatDoubleAsPercent ( double  value,
int  decimalPlaces 
)
static

Formats a double as a percentage string.

Parameters
valueThe value.
decimalPlacesThe number of decimal places to include.

◆ generateId()

static String fm.liveswitch.Utility.generateId ( )
static

Generates a globally unique identifier with no hyphens.

Returns
A globally unique identifier with no hyphens.

◆ generateSynchronizationSource()

static long fm.liveswitch.Utility.generateSynchronizationSource ( )
static

Generates a synchronization source.

◆ generateTieBreaker()

static String fm.liveswitch.Utility.generateTieBreaker ( )
static

Generates a tie-breaker.

Returns
A tie-breaker.
Deprecated:
Use GenerateId instead.

◆ getRtpSequenceNumberDelta()

static int fm.liveswitch.Utility.getRtpSequenceNumberDelta ( int  rtpSequenceNumber,
int  lastRtpSequenceNumber 
)
static

Retrieves the difference between two RTP sequence numbers while accounting for overflow rollover.

Parameters
rtpSequenceNumberThe current RTP sequence number.
lastRtpSequenceNumberThe last (previous) RTP sequence number.
Returns
The difference between the two RTP sequence numbers.

◆ getRtpTimestampDelta()

static long fm.liveswitch.Utility.getRtpTimestampDelta ( long  rtpTimestamp,
long  lastRtpTimestamp 
)
static

Retrieves the difference between two RTP timestamps while accounting for overflow rollover.

Parameters
rtpTimestampThe current RTP timestamp.
lastRtpTimestampThe last (previous) RTP timestamp.
Returns
The difference between the two RTP timestamps.

◆ lastOrDefault() [1/2]

static <T> T fm.liveswitch.Utility.lastOrDefault ( java.util.ArrayList< T >  list)
static

Gets the last element in the list or the default value if the list is null or empty.

Parameters
listThe list.

◆ lastOrDefault() [2/2]

static <T> T fm.liveswitch.Utility.lastOrDefault ( T[]  array)
static

Gets the last element in the array or the default value if the array is null or empty.

Parameters
arrayThe array.

◆ nullableLongEquals()

static boolean fm.liveswitch.Utility.nullableLongEquals ( fm.liveswitch.NullableLong  long1,
fm.liveswitch.NullableLong  long2 
)
static

Compares two nullable longs for equality.

Parameters
long1The first long value.
long2The second long value.

◆ singleOrDefault() [1/2]

static <T> T fm.liveswitch.Utility.singleOrDefault ( java.util.ArrayList< T >  list)
static

Gets the only element in the list or the default value if the list is null or does not have exactly one value.

Parameters
listThe list.

◆ singleOrDefault() [2/2]

static <T> T fm.liveswitch.Utility.singleOrDefault ( T[]  array)
static

Gets the only element in the array or the default value if the array is null or does not have exactly one value.

Parameters
arrayThe array.

◆ splice() [1/3]

static <T> T [] fm.liveswitch.Utility.splice ( T[]  array,
int  index,
int  removeCount,
fm.liveswitch.IFunction1< Integer, T[]>  createArray 
)
static

Splices an array.

Parameters
arrayThe array.
indexThe splice index.
removeCountThe number of items to remove.
createArrayA function that creates an array of the given size.

◆ splice() [2/3]

static <T> T [] fm.liveswitch.Utility.splice ( T[]  array,
int  index,
int  removeCount,
T[]  addItems,
fm.liveswitch.IFunction1< Integer, T[]>  createArray 
)
static

Splices an array.

Parameters
arrayThe array.
indexThe splice index.
removeCountThe number of items to remove.
addItemsThe items to add.
createArrayA function that creates an array of the given size.

◆ splice() [3/3]

static <T> T [] fm.liveswitch.Utility.splice ( T[]  array,
int  index,
T[]  addItems,
fm.liveswitch.IFunction1< Integer, T[]>  createArray 
)
static

Splices an array.

Parameters
arrayThe array.
indexThe splice index.
addItemsThe items to add.
createArrayA function that creates an array of the given size.

◆ toIntArray()

static int [] fm.liveswitch.Utility.toIntArray ( java.util.ArrayList< Integer >  intList)
static

Converts a list of int values to an array of int values.

Parameters
intListA list of int values.

◆ toList()

static <T> java.util.ArrayList<T> fm.liveswitch.Utility.toList ( T[]  array)
static

Converts an array to a list.

Parameters
arrayThe array.

◆ toLongArray()

static long [] fm.liveswitch.Utility.toLongArray ( java.util.ArrayList< Long >  longList)
static

Converts a list of long values to an array of long values.

Parameters
longListA list of long values.

◆ toStringArray()

static String [] fm.liveswitch.Utility.toStringArray ( java.util.ArrayList< String >  stringList)
static

Converts a list of string values to an array of string values.

Parameters
stringListA list of string values.

◆ treeFindLeaves()

static <T> void fm.liveswitch.Utility.treeFindLeaves ( root,
fm.liveswitch.IFunction1< T, T[]>  childrenCallback,
fm.liveswitch.IAction1< T >  nodeCallback 
)
static

Enumerates over all nodes in the tree, invoking the callback for each one.

Parameters
rootThe root.
childrenCallbackThe children callback.
nodeCallbackThe node callback.

◆ treeSearch()

static <T> void fm.liveswitch.Utility.treeSearch ( root,
fm.liveswitch.IFunction1< T, T[]>  childrenCallback,
fm.liveswitch.IAction1< T >  nodeCallback 
)
static

Enumerates over all nodes in the tree, invoking the callback for each one.

Parameters
rootThe root.
childrenCallbackThe children callback.
nodeCallbackThe node callback.