Interface IdentifiedCollection<T extends Identified>
- Type Parameters:
T
- actual type of object
- All Known Subinterfaces:
BookmarkResolvers
,Bookmarks
,FunctionSet
,PipelineOutputStores
- All Known Implementing Classes:
ExtensionPoints
,IdentifiedCollection.Base
,PipelineSteps
,SecretBuilders
,Secrets
,TypeRegistry
,TypeSet
A collection of Identified
objects. Most implementations should use the IdentifiedCollection.Base
class provided - the
interface is here to avoid repetition of these core methods when building interfaces that provide access to
Engine
and Project
objects.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
IdentifiedCollection.Base<T extends Identified>
Convenience class for anyIdentifiedCollection
s that want to work from an in-memory set of objects. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(String identifier, Resource source, ConstructionCallback<T> callback) Add a potentially lazily constructed identified object to this collection.void
Add a pre-constructed identified object to the collection.void
Same asadd(nz.org.riskscape.engine.Identified)
but with specified source.void
addAll
(Collection<T> identifieds) Add all of the given objects to this collection, returning a list of any that were replacedvoid
addAll
(Collection<T> identifieds, Resource source) void
clear()
Remove everything from the collectionboolean
containsKey
(String id) default T
Deprecated.get
(String id, ProblemSink problemSink) Get an object from the collection that has the given id.getAll()
Class<? extends Identified>
ResultOrProblems returning alternative to get, which will return the same problems that aNoSuchObjectException
or aFailedObjectException
would have, but as part of a ResultOrProblems.Alternative to get that returns the result wrapped in anOptional
and aResultOrProblems
instead of throwingIdentifiedException
s.getSimilarIds
(String candidate) Find possible matches for a failed id lookup.boolean
isEmpty()
boolean
Removes an object from the collection
-
Method Details
-
add
Add a pre-constructed identified object to the collection.
- Parameters:
identified
- object to add- Throws:
ObjectAlreadyExistsException
- if an object already exists with this id
-
add
Same as
add(nz.org.riskscape.engine.Identified)
but with specified source.- Throws:
ObjectAlreadyExistsException
-
add
void add(String identifier, Resource source, ConstructionCallback<T> callback) throws ObjectAlreadyExistsException Add a potentially lazily constructed identified object to this collection.
- Parameters:
identifier
- uniquely identifies the to be constructed objectsource
- a Resource that is linked to the original object - may beResource.UNKNOWN
callback
- a callback that will return the object - expect that theIdentifiedCollection
will cache the result of this call- Throws:
ObjectAlreadyExistsException
- if an object with the same identifier already exists in this collection
-
addAll
Add all of the given objects to this collection, returning a list of any that were replaced
- Throws:
ObjectAlreadyExistsException
-
addAll
- Throws:
ObjectAlreadyExistsException
-
getAll
- Returns:
- all items in the collection ordered by id, excluding failed things Note that any problems will be ignored.
-
getReferences
- Returns:
- all items in the collection ordered by id
-
get
Deprecated.useget(String, ProblemSink)
instead to make sure any warnings get picked upGet an object from the collection that has the given id.
- Parameters:
id
- of item to get.- Returns:
- item
- Throws:
NoSuchObjectException
- if no item with that id has been registeredFailedObjectException
- if an item was registered, but it failed to be built.
-
get
Get an object from the collection that has the given id.
- Parameters:
id
- of item to get.problemSink
- a place for any warnings or info problems to be sent during lookup/construction- Returns:
- item
- Throws:
NoSuchObjectException
- if no item with that id has been registeredFailedObjectException
- if an item was registered, but it failed to be built.
-
getOr
ResultOrProblems returning alternative to get, which will return the same problems that a
NoSuchObjectException
or aFailedObjectException
would have, but as part of a ResultOrProblems. Also adds any warnings that were encountered in to the result. -
getCollectionClass
Class<? extends Identified> getCollectionClass()- Returns:
- the class from this collections type signature. E.g. if this is
Foo extends IdentifiedCollection<Bar>
then getCollectionClass() will return a class instance for Bar.This method will fail if sub classes of
IdentifiedCollection.Base
do not declare a type for T parameters have been set.
-
getResult
Alternative to get that returns the result wrapped in an
Optional
and aResultOrProblems
instead of throwingIdentifiedException
s. -
getAllProblems
- Returns:
- A list of all the problems associated with any failed items in this collection.
-
containsKey
- Returns:
- true if collection contains an item with matching id
-
remove
Removes an object from the collection
- Returns:
- true if there was something in the collection with this id, failed or otherwise
-
clear
void clear()Remove everything from the collection
-
isEmpty
boolean isEmpty()- Returns:
- true of this collection contains no entries, failed or otherwise
-
getSimilarIds
Find possible matches for a failed id lookup.
- Parameters:
candidate
- the id that doesn't exist in this collection- Returns:
- a List of ids that might be what the user was looking for
-
get(String, ProblemSink)
instead to make sure any warnings get picked up