java.lang.Object
com.blackhillsoftware.smf.Utils
Data manipulation utility class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
divideDurations
(Duration d1, Duration d2) Divide 2 durations to show one duration as a proportion of anotherstatic <T> T
Return the item from a single item list, or null if the list is empty.static double
Convert a Duration into whole and fractional seconds
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
divideDurations
Divide 2 durations to show one duration as a proportion of anotherdouble result = Utils.divideDurations(Duration.ofSeconds(5), Duration.ofSeconds(10))
- Parameters:
d1
- Duration 1d2
- Duration 2 the divisor- Returns:
- double d1 divided by d2
-
ToSeconds
Convert a Duration into whole and fractional seconds- Parameters:
d
- Duration- Returns:
- double the duration in seconds
-
oneOrNull
Return the item from a single item list, or null if the list is empty. Throw an exception if there is more than one item in the list.SMF has many instances of triplets that specify the number of sections present. in most cases this API provides the sections in a List<SectionType>. In some cases there can be a maximum of one section and the number in the triplet simply indicates whether it is present or not. This is not always clearly documented in the SMF documentation.
This method is a convenience method that performs 2 functions:
- Returns a single item or null, so you don't need to check if the item is present and then get the item.
- Throws an IllegalArgumentException if there is more than one item in the list. If you are assuming that there can be a maximum of one item, more than one item almost certainly indicates a logic error. Throwing the exception allows the error to be discovered instead of going undetected.
- Parameters:
list
- A list expected to have 1 or 0 members- Returns:
- The single member in the list, or null
- Throws:
IllegalArgumentException
- if there is more than 1 item in the list
-