wro4j-core/src/main/java/ro/isdc/wro/model/group/Group.java
public void replace(final Resource resource, final List<Resource> expandedResources) {
    LOG.debug("replacing resource {} with expanded resources: {}", resource, expandedResources);
    notNull(resource);
    notNull(expandedResources);
    synchronized (this) {
      boolean found = false;
      // use set to avoid duplicates
      final Set<Resource> result = new LinkedHashSet<Resource>();
      for (final Resource resourceItem : resources) {
        if (resourceItem.equals(resource)) {
          found = true;
          for (final Resource expandedResource : expandedResources) {
            // preserve minimize flag.
            expandedResource.setMinimize(resource.isMinimize());
            result.add(expandedResource);
          }
        } else {
          result.add(resourceItem);
        }
      }
      // if no resources found, an invalid replace is performed
      if (!found) {
        throw new IllegalArgumentException("Cannot replace resource: " + resource + " for group: " + this
            + " because the resource is not a part of this group.");
      }
      // update resources with newly built list.
      setResources(new ArrayList<Resource>(result));
    }
  }
public void replace(final Resource resource, final List<Resource> expandedResources) {
    LOG.debug("replacing resource {} with expanded resources: {}", resource, expandedResources);
    notNull(resource);
    notNull(expandedResources);
    synchronized (this) {
      boolean found = false;
      // use set to avoid duplicates
      final Set<Resource> result = new LinkedHashSet<Resource>();
      for (final Resource resourceItem : resources) {
        if (resourceItem.equals(resource)) {
          found = true;
          for (final Resource expandedResource : expandedResources) {
            // preserve minimize flag.
            expandedResource.setMinimize(resource.isMinimize());
            result.add(expandedResource);
          }
        } else {
          result.add(resourceItem);
        }
      }
      // if no resources found, an invalid replace is performed
      if (!found) {
        throw new IllegalArgumentException("Cannot replace resource: " + resource + " for group: " + this
            + " because the resource is not a part of this group.");
      }
      // update resources with newly built list.
      setResources(new ArrayList<Resource>(result));
    }
  }
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.
<p/>
The implementation is synchronized, because it mutates the collection.

@param resource
to replace.
@param 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.