org.apache.sling.resource.collection

## Interface ResourceCollection

    @ProviderType
    public interface ResourceCollection

ResourceCollection is an ordered collection of `Resource`. The collection does not store the actual Resources, it only points to them. Each entry in the collection is represented by a Resource which contains a reference to original resource. That reference Resource can have additional properties (creationDate, etc.)

### Field Summary

Fields
`static String` `RESOURCE_TYPE` Sling resource type for resource representing a `ResourceCollection`

### Method Summary

All Methods Instance Methods Abstract Methods
`boolean` `add(org.apache.sling.api.resource.Resource resource)` Creates a new entry in the collection at the last position and add a reference to resource in the entry.
`boolean` `add(org.apache.sling.api.resource.Resource resource, Map<String,Object> properties)` Creates a new entry in the collection at the last position and add a reference to resource in the entry.
`boolean` `contains(org.apache.sling.api.resource.Resource resource)` Returns true if resource reference is part of the collection.
`String` `getName()` Returns name of the collection.
`String` `getPath()` Returns path of the collection.
`org.apache.sling.api.resource.ModifiableValueMap` `getProperties(org.apache.sling.api.resource.Resource resource)` Returns additional properties for a particular resource in Collection entry.
`Iterator<org.apache.sling.api.resource.Resource>` `getResources()` Returns an iterator over resources referred in the collection in the specified order.
`org.apache.sling.api.resource.ValueMap` `getValueMap(org.apache.sling.api.resource.Resource resource)` Returns additional properties for a particular resource in Collection entry.
`void` `orderBefore(org.apache.sling.api.resource.Resource srcResource, org.apache.sling.api.resource.Resource destResource)` This method inserts the referenced resource `srcResource` into the collection entry at the position immediately before the referenced resource `destResource`.
`boolean` `remove(org.apache.sling.api.resource.Resource resource)` Removes a entry of resource from collection & returns true if successful.

### Field Detail

#### RESOURCE_TYPE

    static final String RESOURCE_TYPE

Sling resource type for resource representing a `ResourceCollection`

See Also:
  Constant Field Values

### Method Detail

#### getName

    String getName()

Returns name of the collection.

Returns:
  name of the collection.

#### getPath

    String getPath()

Returns path of the collection.

Returns:
  path of the collection.

#### getResources

    Iterator<org.apache.sling.api.resource.Resource> getResources()

Returns an iterator over resources referred in the collection in the specified order.

Returns:
  iterator over resources referred in collection.

#### getValueMap

    org.apache.sling.api.resource.ValueMap getValueMap(org.apache.sling.api.resource.Resource resource)

Returns additional properties for a particular resource in Collection entry.

Parameters:
  `resource` - resource for which to get the properties
Returns:
  properties of the Collection entry as a `ValueMap` which will not be null

#### getProperties

    org.apache.sling.api.resource.ModifiableValueMap getProperties(org.apache.sling.api.resource.Resource resource)

Returns additional properties for a particular resource in Collection entry.

Parameters:
  `resource` - resource for which to get the properties
Returns:
  properties of the Collection entry as `ModifiableValueMap`, returns null if no entry found or the entry cannot be adapted to a ModifiableValueMap

#### contains

    boolean contains(org.apache.sling.api.resource.Resource resource)

Returns true if resource reference is part of the collection.

Parameters:
  `resource` - resource to be checked
Returns:
  true if resource is part of the collection. false otherwise

#### add

    boolean add(org.apache.sling.api.resource.Resource resource,
                Map<String,Object> properties)
         throws org.apache.sling.api.resource.PersistenceException

Creates a new entry in the collection at the last position and add a reference to resource in the entry. Changes are transient & have to be saved by calling resolver.commit()

Parameters:
  `resource` - resource to be added
  `properties` - The additional properties to be stored with the collection entry (can be null).
Returns:
  true if addition of resource to collection was successful or false if collection already contained the resource or resource is null.
Throws:
  `org.apache.sling.api.resource.PersistenceException` - if the operation fails

#### add

    boolean add(org.apache.sling.api.resource.Resource resource)
         throws org.apache.sling.api.resource.PersistenceException

Creates a new entry in the collection at the last position and add a reference to resource in the entry. Changes are transient & have to be saved by calling resolver.commit()

Parameters:
  `resource` - resource to be added
Returns:
  true if addition of resource to collection was successful or false if collection already contained the resource or resource is null.
Throws:
  `org.apache.sling.api.resource.PersistenceException` - if the operation fails

#### remove

    boolean remove(org.apache.sling.api.resource.Resource resource)
            throws org.apache.sling.api.resource.PersistenceException

Removes a entry of resource from collection & returns true if successful. Changes are transient & have to be saved by calling resolver.commit()

Parameters:
  `resource` - resource reference to be removed
Returns:
  true if resource reference was successfully removed from the collection. false if not removed/not present
Throws:
  `org.apache.sling.api.resource.PersistenceException` - if the operation fails

#### orderBefore

    void orderBefore(org.apache.sling.api.resource.Resource srcResource,
                     org.apache.sling.api.resource.Resource destResource)

This method inserts the referenced resource `srcResource` into the collection entry at the position immediately before the referenced resource `destResource`. To insert the referenced resource into last position, `destResource` can be null.

Parameters:
  `srcResource` - Referenced resource that needs to be moved in the order
  `destResource` - Referenced resource before which the `srcResource` will be placed.