gt:         for (TaggedStringList list : _ignoreSet) {
context: /*
   * Copyright (c) 2004-2020 The YAWL Foundation. All rights reserved.
   * The YAWL Foundation is a collaboration of individuals and
   * organisations who are committed to improving workflow technology.
   *
   * This file is part of YAWL. YAWL is free software: you can
   * redistribute it and/or modify it under the terms of the GNU Lesser
   * General Public License as published by the Free Software Foundation.
   *
   * YAWL is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
   * Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with YAWL. If not, see <http://www.gnu.org/licenses/>.
   */
  
  package org.yawlfoundation.yawl.resourcing;
  
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.jdom2.Element;
  import org.jdom2.Namespace;
  import org.yawlfoundation.yawl.engine.YSpecificationID;
  import org.yawlfoundation.yawl.engine.interfce.WorkItemRecord;
  import org.yawlfoundation.yawl.resourcing.allocators.ShortestQueue;
  import org.yawlfoundation.yawl.resourcing.datastore.persistence.Persister;
  import org.yawlfoundation.yawl.resourcing.interactions.*;
  import org.yawlfoundation.yawl.resourcing.resource.Participant;
  import org.yawlfoundation.yawl.resourcing.resource.SecondaryResources;
  import org.yawlfoundation.yawl.resourcing.util.TaggedStringList;
  
  import java.util.*;
  
  
  /**
   * Manages all of the resourcing requirements and distribution strategies for one
   * task.
   *
   *  @author Michael Adams
   *  v0.1, 03/08/2007
   */
  
  public class ResourceMap {
      
      // interaction points
      private OfferInteraction _offer ;
      private AllocateInteraction _allocate ;
      private StartInteraction _start ;
  
      // user-task privileges
      private TaskPrivileges _privileges ;
  
      private SecondaryResources _secondary;
  
      private long _id ;                                             // hibernate pkey
      private String _taskID ;
      private YSpecificationID _specID ;
  
      private Participant _piledResource = null ;
      private String _piledResourceID ;                              // for persistence
      private Persister _persister ;
  
      private Set<TaggedStringList> _ignoreSet = new HashSet<TaggedStringList>();
  
      // workitem id - offered-to-participants mapping
      private Map<String, Set<Participant>> _offered = new
              HashMap<String, Set<Participant>>() ;
  
      private static final Logger _log = LogManager.getLogger(ResourceMap.class) ;
  
  
      public ResourceMap() { }                                       // for persistence
      
  
      public ResourceMap(String taskID) {
          this();
          _taskID = taskID ;
          _offer = new OfferInteraction(taskID) ;
          _allocate = new AllocateInteraction(taskID);
          _start = new StartInteraction(taskID) ;
          _secondary = new SecondaryResources();
  
          _allocate.setAllocator(new ShortestQueue());               // default allocator
      }
  
      public ResourceMap(YSpecificationID specID, String taskID, Element eleSpec) {
          this(taskID);
          _specID = specID ;
          _privileges = new TaskPrivileges(specID, taskID);
          parse(eleSpec);
          restorePiledResource() ;
      }
  
      public ResourceMap(YSpecificationID specID, String taskID, Element eleSpec, boolean persisting) {
          this(specID, taskID, eleSpec);
          if (persisting) setPersisting(true);
          restorePiledResource() ;
      }
  
  
      public void setOfferInteraction(OfferInteraction oi) {
         _offer = oi ;
      }
  
      public void setAllocateInteraction(AllocateInteraction ai) {
         _allocate = ai ;
      }
  
      public void setStartInteraction(StartInteraction si) {
         _start = si ;
      }
  
      public void setSecondaryResources(SecondaryResources sr) {
          _secondary = sr;
      }
  
      public void setTaskPrivileges(TaskPrivileges tp) {
          _privileges = tp ;
      }
  
      public OfferInteraction getOfferInteraction() {
          return _offer ;
      }
  
      public AllocateInteraction getAllocateInteraction() {
         return _allocate ;
      }
  
      public StartInteraction getStartInteraction() {
         return _start ;
      }
  
      public SecondaryResources getSecondaryResources() {
          return _secondary;
      }
  
      public TaskPrivileges getTaskPrivileges() {
          return _privileges ;
      }
  
      public Set<Participant> getDistributionSet() {
          return (_offer != null) ? _offer.getDistributionSet() : null;
      }
  
  
      public String getTaskID() { return _taskID; }
  
      public void setTaskID(String taskID) { _taskID = taskID ; }
  
      public String getSpecName() { return _specID.getUri(); }
  
      public YSpecificationID getSpecID() { return _specID; }
  
      public void setSpecID(YSpecificationID specID) { _specID = specID ; }
  
      public String getPiledResourceID() { return _piledResourceID; }
  
      public void setPiledResourceID(String id) { _piledResourceID = id; }
  
  
      public Participant getPiledResource() { return _piledResource; }
  
      public String setPiledResource(Participant p, WorkItemRecord wir) {
          String result;
          if (! hasPiledResource()) {
              _piledResource = p;
              _piledResourceID = p.getID();
              if (isPersisting()) _persister.insert(this);
              if (getRM().routePiledWorkItem(_piledResource, wir)) {
                  result = "Task successfully piled." ;
              }
              else {
                  result = "Cannot pile task: problem starting workitem." ;
              }
          }
          else result = "Cannot pile task: already piled by another resource.";
  
          return result ;
      }
  
      public void removePiledResource() {
          _piledResource = null ;
          _piledResourceID = null ;
          if (isPersisting()) {
  
              // have to get persisted map first, so we can delete it (since 'this' is not
              // the same object as the one persisted)
              ResourceMap map = getPersistedMap();
              if (map != null) _persister.delete(map);
              _persister.commit();
          }
      }
  
      
      private ResourceMap getPersistedMap() {
          ResourceMap result = null;
          if (isPersisting()) {
              String where = String.format(
                "_specID.identifier='%s' and _specID.version.version='%s' and _taskID='%s'",
                    _specID.getIdentifier(), _specID.getVersionAsString(), _taskID);
              List map = _persister.selectWhere("ResourceMap", where) ;
              if ((map != null) && (! map.isEmpty())) {
                  result = (ResourceMap) map.iterator().next();
              }
              _persister.commit();
          }
          return result;
      }
  
      public boolean hasPiledResource() { return _piledResource != null; }
  
      private void restorePiledResource() {
          ResourceMap map = getPersistedMap();
          if (map != null) {
              if (getRM().isPersistPiling()) {
                  _piledResourceID = map.getPiledResourceID();
                  _piledResource = getRM().getOrgDataSet().getParticipant(_piledResourceID);
              }
              else _persister.delete(map);
          }
      }
  
  
      public void setPersisting(boolean persist) {
          if ((persist) && (_persister == null))
              _persister = Persister.getInstance();
          else
              _persister = null;
      }
  
      public boolean isPersisting() { return (_persister != null); }
  
  
      public void ignore(WorkItemRecord wir, Participant p) {
          TaggedStringList ignoredForWorkItem = getIgnoredList(wir.getID());
          if (ignoredForWorkItem != null)
              ignoredForWorkItem.add(p.getID());
          else
              _ignoreSet.add(new TaggedStringList(wir.getID(), p.getID())) ;
      }
  
  
      public TaggedStringList getIgnoredList(String key) {
          TaggedStringList result = null;
  