- All Implemented Interfaces:
AsyncDataState
AsyncDataLink instances relying on multiple other
AsyncDataLink instances may choose to return an instance of
MultiAsyncDataState containing all the data states. The order of
states are important: each state's data retrieval process is considered to be
the subprocess of the data retrieval process of the previous state.
Note that the AsyncDataLink instance created by the
AsyncLinks.convertResultAsync(AsyncDataLink, AsyncDataQuery) method
returns MultiAsyncDataState instances as its state of progress.
Thread safety
The methods of this class are safe to be accessed by multiple threads concurrently. The wrapped list ofAsyncDataState instances cannot be
modified after construction time.
Synchronization transparency
The methods of this class are synchronization transparent.-
Constructor Summary
ConstructorsConstructorDescriptionMultiAsyncDataState(List<? extends AsyncDataState> states) Initializes theMultiAsyncDataStatewith the specified underlying states.MultiAsyncDataState(AsyncDataState... states) Initializes theMultiAsyncDataStatewith the specified underlying states. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns an aggregated progress value of the underlying states.doublegetSubProgress(int index) Returns theprogress valueof the underlying state at the given index.getSubState(int index) Returns the underlying state at the given index.intReturns the number of underlyingAsyncDataStateinstances.Returns a read-only list of the underlyingAsyncDataStateinstances in the order they were specified at construction time.toString()Returns the string representation of thisMultiAsyncDataStatein no particular format.
-
Constructor Details
-
MultiAsyncDataState
Initializes theMultiAsyncDataStatewith the specified underlying states.- Parameters:
states- the underlyingAsyncDataStateinstances in the order of significance. The content of the passed array will be copied, so modifying the passed array after this constructor returns will have no effect on the newly created instance. This argument cannot benullbut its elements are allowed to benull.- Throws:
NullPointerException- thrown if the specifiedAsyncDataStatearray isnull
-
MultiAsyncDataState
Initializes theMultiAsyncDataStatewith the specified underlying states.- Parameters:
states- the underlyingAsyncDataStateinstances in the order of significance. The content of the passed list will be copied, so modifying the passed list after this constructor returns will have no effect on the newly created instance. This argument cannot benullbut its elements are allowed to benull.- Throws:
NullPointerException- thrown if the specifiedAsyncDataStatelist isnull
-
-
Method Details
-
getSubStateList
Returns a read-only list of the underlyingAsyncDataStateinstances in the order they were specified at construction time.This method returns a list with the same element as if they were returned by the
getSubState(int)method and will have the same number of elements as returned by thegetSubStateCount()method.- Returns:
- a read-only list of the underlying
AsyncDataStateinstances in the order they were specified at construction time. This method never returnsnullbut the returned list may containnullelements at positions wherenullwas specified at construction time. - See Also:
-
getSubStateCount
public int getSubStateCount()Returns the number of underlyingAsyncDataStateinstances. That is, the number ofAsyncDataStateinstances specified at construction time.The returned integer is the exclusive upper bound for the argument of the
getSubState(int)method. The return value of this method is constant throughout the life time of thisMultiAsyncDataState.- Returns:
- the number of underlying
AsyncDataStateinstances. This method always returns an integer greater than or equal to zero. - See Also:
-
getSubState
Returns the underlying state at the given index. That is, theAsyncDataStateinstance specified at the given index at construction time. The inclusive lower bound for the index is zero and the exclusive upper bound is the value returned by thegetSubStateCount()method.Note that this method is effectively the same as invoking:
getSubStateList().get(index)but more efficient.- Parameters:
index- the index of the underlying state to be returned. This argument must be greater than or equal to zero and lower than the value returned by thegetSubStateCount()method.- Returns:
- the underlying state at the given index. This method may return
nullif such state was specified at the given index at construction time. - Throws:
IndexOutOfBoundsException- thrown if the specified index is not within its valid range- See Also:
-
getSubProgress
public double getSubProgress(int index) Returns theprogress valueof the underlying state at the given index. The progress value fornullstates is defined to be zero.This method is effectively the same as the
getSubState(index) != null ? getSubState(index).getProgress() : 0.0expression.- Parameters:
index- the index of the underlying state whose progress value is to be returned. This argument must be greater than or equal to zero and lower than the value returned by thegetSubStateCount()method.- Returns:
- the progress value of the state at the given index
- Throws:
IndexOutOfBoundsException- thrown if the specified index is not within its valid range- See Also:
-
getProgress
public double getProgress()Returns an aggregated progress value of the underlying states.How this aggregated progress value is calculated is not defined but the following condition holds for the resulting progress: If for two different invocation, the first N state has the same progress value but the progress value at
N + 1position is different, then this method will return greater or equal value for the invocation where the progress value at theN + 1position is greater. When the underlying progress values are all the same, this method will return the same value for both invocation.In case all the underlying
AsyncDataStateinstances return a value within the range[0.0, 1.0], this method will also return a value within this range.- Specified by:
getProgressin interfaceAsyncDataState- Returns:
- the aggregated progress value of the underlying states
-
toString
Returns the string representation of thisMultiAsyncDataStatein no particular format. The string representation contains the string representation of all the underlying states.This method is intended to be used for debugging only.
-