2018-10-11 09:26:00 +00:00
|
|
|
package activitystreams
|
2017-09-11 20:45:57 +00:00
|
|
|
|
2018-10-18 09:48:02 +00:00
|
|
|
// ItemCollection represents an array of items
|
2017-09-11 20:45:57 +00:00
|
|
|
type ItemCollection []Item
|
|
|
|
|
2018-03-25 18:54:51 +00:00
|
|
|
// Item struct
|
2018-04-09 11:10:27 +00:00
|
|
|
type Item ObjectOrLink
|
2018-07-25 09:54:12 +00:00
|
|
|
|
2019-12-03 15:26:43 +00:00
|
|
|
const EmptyObjectID = ObjectID("")
|
|
|
|
const EmptyIRI = IRI("")
|
|
|
|
|
2018-07-25 09:54:12 +00:00
|
|
|
// GetID returns the ObjectID corresponding to ItemCollection
|
2019-12-03 15:26:43 +00:00
|
|
|
func (i ItemCollection) GetID() ObjectID {
|
|
|
|
return EmptyObjectID
|
2018-07-25 09:54:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 18:48:38 +00:00
|
|
|
// GetLink returns the empty IRI
|
|
|
|
func (i ItemCollection) GetLink() IRI {
|
2019-12-03 15:26:43 +00:00
|
|
|
return EmptyIRI
|
2018-10-11 18:48:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 09:54:12 +00:00
|
|
|
// GetType returns the ItemCollection's type
|
|
|
|
func (i ItemCollection) GetType() ActivityVocabularyType {
|
2019-12-01 18:27:45 +00:00
|
|
|
return CollectionOfItems
|
2018-07-25 09:54:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsLink returns false for an ItemCollection object
|
|
|
|
func (i ItemCollection) IsLink() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsObject returns true for a ItemCollection object
|
|
|
|
func (i ItemCollection) IsObject() bool {
|
|
|
|
return false
|
|
|
|
}
|
2018-10-11 18:48:38 +00:00
|
|
|
|
|
|
|
// Append facilitates adding elements to Item arrays
|
|
|
|
// and ensures ItemCollection implements the Collection interface
|
|
|
|
func (i *ItemCollection) Append(o Item) error {
|
|
|
|
oldLen := len(*i)
|
|
|
|
d := make(ItemCollection, oldLen+1)
|
|
|
|
for k, it := range *i {
|
|
|
|
d[k] = it
|
|
|
|
}
|
|
|
|
d[oldLen] = o
|
|
|
|
*i = d
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-02 14:45:37 +00:00
|
|
|
// Count returns the length of Items in the item collection
|
|
|
|
func (i *ItemCollection) Count() uint {
|
|
|
|
return uint(len(*i))
|
|
|
|
}
|
|
|
|
|
2018-11-10 21:35:57 +00:00
|
|
|
// First returns the ObjectID corresponding to ItemCollection
|
|
|
|
func (i ItemCollection) First() Item {
|
|
|
|
if len(i) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return i[0]
|
|
|
|
}
|
|
|
|
|
2018-10-11 18:48:38 +00:00
|
|
|
// Collection returns the current object as collection interface
|
2019-12-01 18:27:45 +00:00
|
|
|
func (i *ItemCollection) Collection() ItemCollection {
|
|
|
|
return *i
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsCollection returns true for ItemCollection arrays
|
|
|
|
func (i ItemCollection) IsCollection() bool {
|
|
|
|
return true
|
2018-10-11 18:48:38 +00:00
|
|
|
}
|
2019-08-23 18:39:28 +00:00
|
|
|
|
|
|
|
// Contains verifies if IRIs array contains the received one
|
2019-12-01 18:27:45 +00:00
|
|
|
func (i ItemCollection) Contains(r IRI) bool {
|
2019-08-23 18:39:28 +00:00
|
|
|
if len(i) == 0 {
|
2019-08-23 19:49:42 +00:00
|
|
|
return false
|
2019-08-23 18:39:28 +00:00
|
|
|
}
|
|
|
|
for _, iri := range i {
|
2019-11-18 16:15:00 +00:00
|
|
|
if r.Equals(iri.GetLink(), false) {
|
2019-08-23 18:39:28 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|