Interface RowRetriever
- All Known Subinterfaces:
ItemForest,RowManager
- All Known Implementing Classes:
ImmutableItemForest,ManagerBackedItemForest
RowRetriever is an abstraction of an object that can provide an instance of StructureRow by its numeric ID.
In addition, it has bulk access methods that may provide multiple StructureRow instances more efficiently.
There's a number of bulk scanning methods that are provided for convenience. The following naming convention is used:
scanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)– basic scanning method with aPredicatecallback, which allows breaking the iteration cycle.scanAllRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Consumer<com.almworks.jira.structure.api.row.StructureRow>)– "all" means that all passed rows will be scanned, and the callback is aConsumer.scanAllExistingRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, java.util.function.Consumer<com.almworks.jira.structure.api.row.StructureRow>)– "existing" means thatIGNORE_MISSING_ROWSwill be passed as the missing row collector, which guarantees that the method will not throwMissingRowException.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LongCollectorUse this to indicate that missing rows should not result in throwingMissingRowException. -
Method Summary
Modifier and TypeMethodDescriptiondefault <C extends LongCollector>
CcollectIssueIds(LongIterable rows, boolean sorted, C issuesCollector) Convenience method that can be used to collect all issue IDs from given row IDs.default <C extends LongCollector>
CcollectIssueIds(LongIterable rows, C issuesCollector) Convenience method that can be used to collect all issue IDs from given row IDs.collectItemIds(LongIterable rows) Convenience method that collects item IDs from row IDs.default StructureRowgetRow(long rowId) Retrieves information about a structure row by its ID.getRow(long rowId, ItemAccessMode access) RetrievesStructureRowwith additional information about how the calling code is going to use methodStructureRow.getItem(java.lang.Class<I>).default <T> TreduceOverRows(LongIterable rows, T startingValue, BiFunction<StructureRow, T, T> accumulator) Performs a reduction over a collection of rows, identified by their IDs.default voidscanAllExistingRows(LongIterable rows, boolean sorted, ItemAccessMode access, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs and ignores any missing rows.default voidscanAllExistingRows(LongIterable rows, boolean sorted, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode and ignores any missing rows.default voidscanAllExistingRows(LongIterable rows, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode, ignores any missing rows, and assumes that the row ID stream may be not sorted.default voidscanAllRows(LongIterable rows, boolean sorted, LongCollector missingCollector, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode.default voidscanAllRows(LongIterable rows, boolean sorted, ItemAccessMode access, LongCollector missingCollector, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs.default voidscanAllRows(LongIterable rows, LongCollector missingCollector, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs, uses normal access mode, and assumes that row ID stream may be not sorted.default voidscanAllRows(LongIterable rows, Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs, uses normal access mode, assumes that row ID stream may be not sorted, and does not provide a missing collector.default voidscanRows(LongIterable rows, boolean sorted, LongCollector missingCollector, Predicate<StructureRow> iteratee) A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode.default voidscanRows(LongIterable rows, boolean sorted, ItemAccessMode access, LongCollector missingCollector, Predicate<StructureRow> iteratee) Loads multiple rows by their IDs and callsiterateewith aStructureRowfor each row ID in the input.default voidscanRows(LongIterable rows, LongCollector missingCollector, Predicate<StructureRow> iteratee) A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode, and when the rows stream is not guaranteed to be sorted.default voidscanRows(LongIterable rows, Predicate<StructureRow> iteratee) A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode, when the rows stream is not guaranteed to be sorted, and without a missing row collector.
-
Field Details
-
IGNORE_MISSING_ROWS
static final LongCollector IGNORE_MISSING_ROWSUse this to indicate that missing rows should not result in throwingMissingRowException.
-
-
Method Details
-
getRow
Retrieves information about a structure row by its ID.
Note that it is a runtime error to request a non-existing row, because that should never happen in a correct code.
- Parameters:
rowId- row ID- Returns:
- row information
- Throws:
MissingRowException- if the specified row ID does not exist
-
getRow
Retrieves
StructureRowwith additional information about how the calling code is going to use methodStructureRow.getItem(java.lang.Class<I>). The implementation may be optimized according to theaccessparameter.If row's item is invisible or does not exist,
StructureRowis returned anyway, butStructureRow.getItem(java.lang.Class<I>)returnnull.- Parameters:
rowId- row IDaccess- defines how item object is going to be accessed- Returns:
- row instance
- Throws:
MissingRowException- if the specified row ID does not exist- See Also:
-
scanRows
default void scanRows(@Nullable LongIterable rows, boolean sorted, @NotNull ItemAccessMode access, @Nullable LongCollector missingCollector, @NotNull Predicate<StructureRow> iteratee) throws MissingRowException Loads multiple rows by their IDs and calls
iterateewith aStructureRowfor each row ID in the input. Use this method whenever you need to read a potentially large amount of rows and the order of retrieval is not important.For example, use
scanRowsto iterate through the whole forest to see if it has a generator row, or to process user input that has an array of row IDs.The order in which
iterateeis called is not guaranteed to be the same as the iteration order ofrows. Likewise,missingCollectormay receive row IDs out of order.The implementation of
iterateemust be reasonably fast and avoid taking locks or accessing long-running services. It's possible to call otherRowRetrievermethods insideiteratee.It's possible to pass
LongIteratorasLongIterable- the iterator() method is guaranteed to be called only once.Item access mode
You can choose an appropriate value for the access parameter based on what you're going to do with rows in the
iteratee. This allows the provider ofStructureRowinstances to optimize howStructureRow.getItem(java.lang.Class<I>)method works.Dealing with missing rows
If a row ID in the input stream does not correspond to an existing row, the behavior depends on whether the
missingCollectorparameter is set. If it'snull, then the method will immediately throw aMissingRowException. If it's not null, the collector will be called with the missing row ID.To simply ignore the missing rows, you can use
IGNORE_MISSING_ROWScollector or use one of thescanAllExistingRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, java.util.function.Consumer<com.almworks.jira.structure.api.row.StructureRow>)methods.Note that if the current user does not have access to a row, but the row itself exists, it's not considered missing.
Super-root
Note that normally a row retriever does not handle
SuperRootRowin any special way, so it will be a case of a missing row. Some implementations may, however, support accessing the super-root.Implementation notes
The default implementation is based on calling
getRow(long). Specific implementations should optimize this method for retrieving multiple rows at once.Do not override other bulk scanning methods, unless that allows for additional optimization.
- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationaccess- indicates how thegetItem()method of the providedStructureRowis going to be used and allows to skip the access checkingmissingCollector- a collector to receive non-existing row IDs, ornulliteratee- predicate to call for each resolved row; if it returnsfalse, the iteration stops and the method returns- Throws:
MissingRowException- if a row was not found andmissingCollectoris null- See Also:
-
scanRows
default void scanRows(@Nullable LongIterable rows, boolean sorted, @Nullable LongCollector missingCollector, @NotNull Predicate<StructureRow> iteratee) throws MissingRowException A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode.- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationmissingCollector- a collector to receive non-existing row IDs, ornulliteratee- predicate to call for each resolved row; if it returnsfalse, the iteration stops and the method returns- Throws:
MissingRowException- if a row was not found andmissingCollectoris null
-
scanRows
default void scanRows(@Nullable LongIterable rows, @Nullable LongCollector missingCollector, @NotNull Predicate<StructureRow> iteratee) throws MissingRowException A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode, and when the rows stream is not guaranteed to be sorted.- Parameters:
rows- row IDs of the rows to scanmissingCollector- a collector to receive non-existing row IDs, ornulliteratee- predicate to call for each resolved row; if it returnsfalse, the iteration stops and the method returns- Throws:
MissingRowException- if a row was not found andmissingCollectoris null
-
scanRows
default void scanRows(@Nullable LongIterable rows, @NotNull Predicate<StructureRow> iteratee) throws MissingRowException A convenience method that callsscanRows(LongIterable, boolean, ItemAccessMode, LongCollector, Predicate)with the normal access mode, when the rows stream is not guaranteed to be sorted, and without a missing row collector. This method will throwMissingRowExceptionif a non-existent row ID is encountered.- Parameters:
rows- row IDs of the rows to scaniteratee- predicate to call for each resolved row; if it returnsfalse, the iteration stops and the method returns- Throws:
MissingRowException- if a row was not found
-
scanAllRows
default void scanAllRows(@Nullable LongIterable rows, boolean sorted, @NotNull ItemAccessMode access, @Nullable LongCollector missingCollector, @NotNull Consumer<StructureRow> consumer) throws MissingRowException A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs. UnlikescanRows()methods, it accepts aConsumercallback.- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationaccess- indicates how thegetItem()method of the providedStructureRowis going to be used and allows to skip the access checkingmissingCollector- a collector to receive non-existing row IDs, ornullconsumer- a callback to call for every row- Throws:
MissingRowException- if a row was not found andmissingCollectoris null
-
scanAllRows
default void scanAllRows(@Nullable LongIterable rows, boolean sorted, @Nullable LongCollector missingCollector, @NotNull Consumer<StructureRow> consumer) throws MissingRowException A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode.- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationmissingCollector- a collector to receive non-existing row IDs, ornullconsumer- a callback to call for every row- Throws:
MissingRowException- if a row was not found andmissingCollectoris null
-
scanAllRows
default void scanAllRows(@Nullable LongIterable rows, @Nullable LongCollector missingCollector, @NotNull Consumer<StructureRow> consumer) throws MissingRowException A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs, uses normal access mode, and assumes that row ID stream may be not sorted.- Parameters:
rows- row IDs of the rows to scanmissingCollector- a collector to receive non-existing row IDs, ornullconsumer- a callback to call for every row- Throws:
MissingRowException- if a row was not found andmissingCollectoris null
-
scanAllRows
default void scanAllRows(@Nullable LongIterable rows, @NotNull Consumer<StructureRow> consumer) throws MissingRowException A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs, uses normal access mode, assumes that row ID stream may be not sorted, and does not provide a missing collector. This method will throwMissingRowExceptionif a non-existent row ID is encountered.- Parameters:
rows- row IDs of the rows to scanconsumer- a callback to call for every row- Throws:
MissingRowException- if a row was not found
-
scanAllExistingRows
default void scanAllExistingRows(@Nullable LongIterable rows, boolean sorted, @NotNull ItemAccessMode access, @NotNull Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs and ignores any missing rows.- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationaccess- indicates how thegetItem()method of the providedStructureRowis going to be used and allows to skip the access checkingconsumer- a callback to call for every row
-
scanAllExistingRows
default void scanAllExistingRows(@Nullable LongIterable rows, boolean sorted, @NotNull Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode and ignores any missing rows.- Parameters:
rows- row IDs of the rows to scansorted- if true, then the caller guarantees the row IDs to be sorted - this can be used for optimizationconsumer- a callback to call for every row
-
scanAllExistingRows
default void scanAllExistingRows(@Nullable LongIterable rows, @NotNull Consumer<StructureRow> consumer) A convenience variation ofscanRows(com.almworks.integers.LongIterable, boolean, com.almworks.jira.structure.api.row.ItemAccessMode, com.almworks.integers.LongCollector, java.util.function.Predicate<com.almworks.jira.structure.api.row.StructureRow>)that always goes through all of the row IDs with a normal access mode, ignores any missing rows, and assumes that the row ID stream may be not sorted.- Parameters:
rows- row IDs of the rows to scanconsumer- a callback to call for every row
-
reduceOverRows
@Nullable default <T> T reduceOverRows(@Nullable LongIterable rows, @Nullable T startingValue, @NotNull BiFunction<StructureRow, T, throws MissingRowExceptionT> accumulator) Performs a reduction over a collection of rows, identified by their IDs.
The reducer function must be associative and commutative, because it may be called in a random order, not corresponding to the iteration order of
rows.- Type Parameters:
T- result type- Parameters:
rows- row IDs of the rows to scanstartingValue- the initial value to start withaccumulator- a function that receives the next row and the accumulated value, and then produces the next accumulated value- Returns:
- the last accumulated value, or
startingValueif there was no iteration - Throws:
MissingRowException- if a row was not found
-
collectIssueIds
@NotNull default <C extends LongCollector> C collectIssueIds(@Nullable LongIterable rows, boolean sorted, @NotNull C issuesCollector) Convenience method that can be used to collect all issue IDs from given row IDs. Ignores missing rows.
- Type Parameters:
C- type of the collector- Parameters:
rows- a collection of rowssorted- if true, then rows is sorted - can be used by the optimized codeissuesCollector- a collection to receive issue IDs- Returns:
- the collector
-
collectIssueIds
@NotNull default <C extends LongCollector> C collectIssueIds(@Nullable LongIterable rows, @NotNull C issuesCollector) Convenience method that can be used to collect all issue IDs from given row IDs. Ignores missing rows.
- Type Parameters:
C- type of the collector- Parameters:
rows- a collection of rowsissuesCollector- a collection to receive issue IDs- Returns:
- the collector
-
collectItemIds
Convenience method that collects item IDs from row IDs. Ignores missing rows.
The returned collection is owned by the caller and may be further modified.
- Parameters:
rows- a collection of rows- Returns:
- a collection of item IDs found in the input rows
-