ro.isdc.wro.model.group
Class Group

java.lang.Object
  extended by ro.isdc.wro.model.group.Group

public final class Group
extends Object

A group is an entity holding a list of resources.

This class is thread safe.

Author:
Alex Objelean

Constructor Summary
Group()
          To be used by JSON serializer.
Group(String name)
          Creates a group with a name.
 
Method Summary
 Group addResource(Resource resource)
          Add a Resource to the collection of resources associated with this group.
 Group collectResourcesOfType(ResourceType type)
           
 boolean equals(Object obj)
          
 String getName()
           
 List<Resource> getResources()
           
 int hashCode()
          
 boolean hasResource(String resourceUri)
           
 boolean hasResourcesOfType(ResourceType resourceType)
          Check if the group has at least one resource of some type.
 void replace(Resource resource, List<Resource> expandedResources)
          Replace one resource with a list of other resources.
 void setResources(List<Resource> resources)
          This method will replace all earlier defined resources with the provided list of resources.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Group

public Group()
To be used by JSON serializer.


Group

public Group(String name)
Creates a group with a name.

Parameters:
name - of the group.
Method Detail

hasResourcesOfType

public final boolean hasResourcesOfType(ResourceType resourceType)
Check if the group has at least one resource of some type.

Parameters:
resourceType - type of the searched resource.
Returns:
true if at least one resource of some type exists.

hasResource

public boolean hasResource(String resourceUri)
Returns:
true if a Resource with an uri same as resourceUri is contained in this group.

replace

public void replace(Resource resource,
                    List<Resource> expandedResources)
Replace one resource with a list of other resources. The use case is related to wildcard expander functionality, when resources containing wildcard are replaced with a list of wildcard-free resources. The order of resources is preserved.

The implementation is synchronized, because it mutates the collection.

Parameters:
resource - to replace.
expandedResources - a list of resources to replace. If this list is empty, the result is similar to removing the resource from the group.
Throws:
IllegalArgumentException - when a missing resources is to be replaced.

collectResourcesOfType

public final Group collectResourcesOfType(ResourceType type)
Parameters:
type - of resources to collect. This value should not be null.
Returns:
a new group with the same name as original containing filtered resources. The created group has the same name.

getResources

public List<Resource> getResources()
Returns:
the readonly list of resources.

addResource

public Group addResource(Resource resource)
Add a Resource to the collection of resources associated with this group.

The implementation is synchronized, because it mutates the collection.

Parameters:
resource - Resource to add to this group (at the end).
Returns:
the reference to Group (fluent interface).

setResources

public final void setResources(List<Resource> resources)
This method will replace all earlier defined resources with the provided list of resources.

The implementation is synchronized, because it mutates the collection.

Parameters:
resources - the resources to replace the underlying resources.

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

getName

public String getName()
Returns:
the name

hashCode

public int hashCode()

Overrides:
hashCode in class Object

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2008-2013. All Rights Reserved.