Wikibase
MediaWiki Wikibase extension
Loading...
Searching...
No Matches
Wikibase\DataModel\ByPropertyIdArray Class Reference

Helper for managing objects indexed by property id. More...

+ Inheritance diagram for Wikibase\DataModel\ByPropertyIdArray:
+ Collaboration diagram for Wikibase\DataModel\ByPropertyIdArray:

Public Member Functions

 __construct ( $input=null)
 
 getPropertyIds ()
 Returns the property ids used for indexing.
 
 getByPropertyId (PropertyId $propertyId)
 Returns the objects featuring the provided property id in the index.
 
 getFlatArrayIndexOfObject ( $object)
 Returns the absolute index of an object or false if the object could not be found.
 
 toFlatArray ()
 Returns the objects in a flat array (using the indexed form for generating the array).
 
 moveObjectToIndex ( $object, $toIndex)
 Moves an existing object to a new index.
 
 addObjectAtIndex ( $object, $index=null)
 Adds an object at a specific index.
 

Private Member Functions

 assertIndexIsBuild ()
 Checks whether id indexed array has been generated.
 
 getFlatArrayIndices (PropertyId $propertyId)
 Returns the absolute numeric indices of objects featuring the same property id.
 
 moveObjectInPropertyGroup ( $object, $toIndex)
 Moves an object within its "property group".
 
 moveObjectToEndOfPropertyGroup ( $object)
 Moves an object to the end of its "property group".
 
 removeObject ( $object)
 Removes an object from the array structures.
 
 insertObjectAtIndex ( $object, $index)
 Inserts an object at a specific index.
 
 movePropertyGroup (PropertyId $propertyId, $toIndex)
 
 getPropertyGroupIndex (PropertyId $propertyId)
 Returns the index of a "property group" (the first object in the flat array that features the specified property).
 
 addObjectToPropertyGroup ( $object, $index=null)
 Adds an object to an existing property group at the specified absolute index.
 

Private Attributes

 $byId = null
 

Detailed Description

Helper for managing objects indexed by property id.

This is a light weight alternative approach to using something like GenericArrayObject with the advantages that no extra interface is needed and that indexing does not happen automatically.

Lack of automatic indexing means that you will need to call the buildIndex method before doing any look-ups.

Since no extra interface is used, the user is responsible for only adding objects that have a getPropertyId method that returns either a string or integer when called with no arguments.

Objects may be added or moved within the structure. Absolute indices (indices according to the flat list of objects) may be specified to add or move objects. These management operations take the property grouping into account. Adding or moving objects outside their "property groups" shifts the whole group towards that index.

Example of moving an object within its "property group": o1 (p1) o1 (p1) o2 (p2) /-> o3 (p2) o3 (p2) ---> move to index 1 -/ o2 (p2)

Example of moving an object that triggers moving the whole "property group": o1 (p1) /-> o3 (p2) o2 (p2) | o2 (p2) o3 (p2) ---> move to index 0 -/ o1 (p1)

Since
0.2
Deprecated
since 5.0, use a DataModel Service instead
Author
H. Snater < media.nosp@m.wiki.nosp@m.@snat.nosp@m.er.c.nosp@m.om >

Constructor & Destructor Documentation

◆ __construct()

Wikibase\DataModel\ByPropertyIdArray::__construct ( $input = null)
Deprecated
since 5.0, use a DataModel Service instead
See also
ArrayObject::__construct
Parameters
PropertyIdProvider[] | Traversable | null$input
Exceptions
InvalidArgumentException

Member Function Documentation

◆ addObjectAtIndex()

Wikibase\DataModel\ByPropertyIdArray::addObjectAtIndex ( $object,
$index = null )

Adds an object at a specific index.

If no index is specified, the object will be append to the end of its "property group" or - if no objects featuring the same property exist - to the absolute end of the array. Specifying an index outside a "property group" will place the new object at the specified index with the existing "property group" objects being shifted towards the new object.

Since
0.5
Parameters
PropertyIdProvider$object
int | null$indexAbsolute index where to place the new object.
Exceptions
OutOfBoundsException
RuntimeException

◆ addObjectToPropertyGroup()

Wikibase\DataModel\ByPropertyIdArray::addObjectToPropertyGroup ( $object,
$index = null )
private

Adds an object to an existing property group at the specified absolute index.

Parameters
PropertyIdProvider$object
int | null$index
Exceptions
OutOfBoundsException

◆ assertIndexIsBuild()

Wikibase\DataModel\ByPropertyIdArray::assertIndexIsBuild ( )
private

Checks whether id indexed array has been generated.

Exceptions
RuntimeException

◆ getByPropertyId()

Wikibase\DataModel\ByPropertyIdArray::getByPropertyId ( PropertyId $propertyId)

Returns the objects featuring the provided property id in the index.

Since
0.2
Parameters
PropertyId$propertyId
Exceptions
OutOfBoundsException
RuntimeException
Returns
PropertyIdProvider[]

◆ getFlatArrayIndexOfObject()

Wikibase\DataModel\ByPropertyIdArray::getFlatArrayIndexOfObject ( $object)

Returns the absolute index of an object or false if the object could not be found.

Since
0.5
Parameters
PropertyIdProvider$object
Returns
bool|int
Exceptions
RuntimeException

◆ getFlatArrayIndices()

Wikibase\DataModel\ByPropertyIdArray::getFlatArrayIndices ( PropertyId $propertyId)
private

Returns the absolute numeric indices of objects featuring the same property id.

Parameters
PropertyId$propertyId
Exceptions
RuntimeException
Returns
int[]

◆ getPropertyGroupIndex()

Wikibase\DataModel\ByPropertyIdArray::getPropertyGroupIndex ( PropertyId $propertyId)
private

Returns the index of a "property group" (the first object in the flat array that features the specified property).

Returns false if property id could not be found.

Parameters
PropertyId$propertyId
Returns
bool|int

◆ getPropertyIds()

Wikibase\DataModel\ByPropertyIdArray::getPropertyIds ( )

Returns the property ids used for indexing.

Since
0.2
Returns
PropertyId[]
Exceptions
RuntimeException

◆ insertObjectAtIndex()

Wikibase\DataModel\ByPropertyIdArray::insertObjectAtIndex ( $object,
$index )
private

Inserts an object at a specific index.

Parameters
PropertyIdProvider$object
int$indexAbsolute index within the flat list of objects.

◆ moveObjectInPropertyGroup()

Wikibase\DataModel\ByPropertyIdArray::moveObjectInPropertyGroup ( $object,
$toIndex )
private

Moves an object within its "property group".

Parameters
PropertyIdProvider$object
int$toIndexAbsolute index within a "property group".
Exceptions
OutOfBoundsException

◆ moveObjectToEndOfPropertyGroup()

Wikibase\DataModel\ByPropertyIdArray::moveObjectToEndOfPropertyGroup ( $object)
private

Moves an object to the end of its "property group".

Parameters
PropertyIdProvider$object

◆ moveObjectToIndex()

Wikibase\DataModel\ByPropertyIdArray::moveObjectToIndex ( $object,
$toIndex )

Moves an existing object to a new index.

Specifying an index outside the object's "property group" will move the object to the edge of the "property group" and shift the whole group to achieve the designated index for the object to move.

Since
0.5
Parameters
PropertyIdProvider$object
int$toIndexAbsolute index where to move the object to.
Exceptions
OutOfBoundsException
RuntimeException

◆ movePropertyGroup()

Wikibase\DataModel\ByPropertyIdArray::movePropertyGroup ( PropertyId $propertyId,
$toIndex )
private
Parameters
PropertyId$propertyId
int$toIndex

◆ removeObject()

Wikibase\DataModel\ByPropertyIdArray::removeObject ( $object)
private

Removes an object from the array structures.

Parameters
PropertyIdProvider$object

◆ toFlatArray()

Wikibase\DataModel\ByPropertyIdArray::toFlatArray ( )

Returns the objects in a flat array (using the indexed form for generating the array).

Since
0.5
Returns
PropertyIdProvider[]
Exceptions
RuntimeException

Member Data Documentation

◆ $byId

Wikibase\DataModel\ByPropertyIdArray::$byId = null
private

The documentation for this class was generated from the following file: