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;
    final Set<Resource> result=new LinkedHashSet<Resource>();
    for (    final Resource resourceItem : resources) {
      if (resourceItem.equals(resource)) {
        found=true;
        for (        final Resource expandedResource : expandedResources) {
          expandedResource.setMinimize(resource.isMinimize());
          result.add(expandedResource);
        }
      }
 else {
        result.add(resourceItem);
      }
    }
    if (!found) {
      throw new IllegalArgumentException("Cannot replace resource: " + resource + " for group: "+ this+ " because the resource is not a part of this group.");
    }
    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 ; final Set < Resource > result = new LinkedHashSet < Resource > ( ) ; for ( final Resource resourceItem : resources ) { if ( resourceItem . equals ( resource ) ) { found = true ; for ( final Resource expandedResource : expandedResources ) { expandedResource . setMinimize ( resource . isMinimize ( ) ) ; result . add ( expandedResource ) ; } } else { result . add ( resourceItem ) ; } } if ( ! found ) { throw new IllegalArgumentException ( "Cannot replace resource: " + resource + " for group: " + this + " because the resource is not a part of this group." ) ; } 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 .
