gt:                 allFound = removeTrigger(key) && allFound;
context: /* 
   * Copyright 2001-2009 Terracotta, Inc. 
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
   * use this file except in compliance with the License. You may obtain a copy 
   * of the License at 
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0 
   *   
   * Unless required by applicable law or agreed to in writing, software 
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
   * License for the specific language governing permissions and limitations 
   * under the License.
   * 
   */
  
  package org.quartz.simpl;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeSet;
  import java.util.Map.Entry;
  import java.util.concurrent.atomic.AtomicLong;
  
  import org.quartz.Calendar;
  import org.quartz.Job;
  import org.quartz.JobDataMap;
  import org.quartz.JobDetail;
  import org.quartz.JobKey;
  import org.quartz.JobPersistenceException;
  import org.quartz.ObjectAlreadyExistsException;
  import org.quartz.Trigger;
  import org.quartz.TriggerKey;
  import org.quartz.Trigger.CompletedExecutionInstruction;
  import org.quartz.Trigger.TriggerState;
  import org.quartz.Trigger.TriggerTimeComparator;
  import org.quartz.impl.JobDetailImpl;
  import org.quartz.impl.matchers.GroupMatcher;
  import org.quartz.impl.matchers.StringMatcher;
  import org.quartz.spi.ClassLoadHelper;
  import org.quartz.spi.JobStore;
  import org.quartz.spi.OperableTrigger;
  import org.quartz.spi.SchedulerSignaler;
  import org.quartz.spi.TriggerFiredBundle;
  import org.quartz.spi.TriggerFiredResult;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import static org.quartz.impl.matchers.EverythingMatcher.allTriggers;
  
  /**
   * <p>
   * This class implements a <code>{@link org.quartz.spi.JobStore}</code> that
   * utilizes RAM as its storage device.
   * </p>
   * 
   * <p>
   * As you should know, the ramification of this is that access is extrememly
   * fast, but the data is completely volatile - therefore this <code>JobStore</code>
   * should not be used if true persistence between program shutdowns is
   * required.
   * </p>
   * 
   * @author James House
   * @author Sharada Jambula
   * @author Eric Mueller
   */
  public class RAMJobStore implements JobStore {
  
      /*
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       * 
       * Data members.
       * 
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       */
  
      protected HashMap<JobKey, JobWrapper> jobsByKey = new HashMap<JobKey, JobWrapper>(1000);
  
      protected HashMap<TriggerKey, TriggerWrapper> triggersByKey = new HashMap<TriggerKey, TriggerWrapper>(1000);
  
      protected HashMap<String, HashMap<JobKey, JobWrapper>> jobsByGroup = new HashMap<String, HashMap<JobKey, JobWrapper>>(25);
  
      protected HashMap<String, HashMap<TriggerKey, TriggerWrapper>> triggersByGroup = new HashMap<String, HashMap<TriggerKey, TriggerWrapper>>(25);
  
      protected TreeSet<TriggerWrapper> timeTriggers = new TreeSet<TriggerWrapper>(new TriggerWrapperComparator());
  
      protected HashMap<String, Calendar> calendarsByName = new HashMap<String, Calendar>(25);
  
      protected ArrayList<TriggerWrapper> triggers = new ArrayList<TriggerWrapper>(1000);
  
      protected final Object lock = new Object();
  
      protected HashSet<String> pausedTriggerGroups = new HashSet<String>();
  
      protected HashSet<String> pausedJobGroups = new HashSet<String>();
  
      protected HashSet<JobKey> blockedJobs = new HashSet<JobKey>();
      
      protected long misfireThreshold = 5000l;
  
      protected SchedulerSignaler signaler;
  
      private final Logger log = LoggerFactory.getLogger(getClass());
  
      /*
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       * 
       * Constructors.
       * 
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       */
  
      /**
       * <p>
       * Create a new <code>RAMJobStore</code>.
       * </p>
       */
      public RAMJobStore() {
      }
  
      /*
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       * 
       * Interface.
       * 
       * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       */
  
      protected Logger getLog() {
          return log;
      }
  
      /**
       * <p>
       * Called by the QuartzScheduler before the <code>JobStore</code> is
       * used, in order to give the it a chance to initialize.
       * </p>
       */
      public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler schedSignaler) {
  
          this.signaler = schedSignaler;
  
          getLog().info("RAMJobStore initialized.");
      }
  
      public void schedulerStarted() {
          // nothing to do
      }
  
      public void schedulerPaused() {
          // nothing to do
      }
      
      public void schedulerResumed() {
          // nothing to do
      }
      
      public long getMisfireThreshold() {
          return misfireThreshold;
      }
  
      /**
       * The number of milliseconds by which a trigger must have missed its
       * next-fire-time, in order for it to be considered "misfired" and thus
       * have its misfire instruction applied.
       * 
       * @param misfireThreshold the new misfire threshold
       */
      @SuppressWarnings("UnusedDeclaration")
      public void setMisfireThreshold(long misfireThreshold) {
          if (misfireThreshold < 1) {
              throw new IllegalArgumentException("Misfire threshold must be larger than 0");
          }
          this.misfireThreshold = misfireThreshold;
      }
  
      /**
       * <p>
       * Called by the QuartzScheduler to inform the <code>JobStore</code> that
       * it should free up all of it's resources because the scheduler is
       * shutting down.
       * </p>
       */
      public void shutdown() {
      }
  
      public boolean supportsPersistence() {
          return false;
      }
  
      /**
       * Clear (delete!) all scheduling data - all {@link Job}s, {@link Trigger}s
       * {@link Calendar}s.
       * 
       * @throws JobPersistenceException
       */
      public void clearAllSchedulingData() throws JobPersistenceException {
  
          synchronized (lock) {
              // unschedule jobs (delete triggers)
              List<String> lst = getTriggerGroupNames();
              for (String group: lst) {
                  Set<TriggerKey> keys = getTriggerKeys(GroupMatcher.triggerGroupEquals(group));
                  for (TriggerKey key: keys) {
                      removeTrigger(key);
                  }
              }
              // delete jobs
              lst = getJobGroupNames();
              for (String group: lst) {
                  Set<JobKey> keys = getJobKeys(GroupMatcher.jobGroupEquals(group));
                  for (JobKey key: keys) {
                      removeJob(key);
                  }
              }
              // delete calendars
              lst = getCalendarNames();
              for(String name: lst) {
                  removeCalendar(name);
              }
          }
      }
      
      /**
       * <p>
       * Store the given <code>{@link org.quartz.JobDetail}</code> and <code>{@link org.quartz.Trigger}</code>.
       * </p>
       * 
       * @param newJob
       *          The <code>JobDetail</code> to be stored.
       * @param newTrigger
       *          The <code>Trigger</code> to be stored.
       * @throws ObjectAlreadyExistsException
       *           if a <code>Job</code> with the same name/group already
       *           exists.
       */
      public void storeJobAndTrigger(JobDetail newJob,
              OperableTrigger newTrigger) throws JobPersistenceException {
          storeJob(newJob, false);
          storeTrigger(newTrigger, false);
      }
  
      /**
       * <p>
       * Store the given <code>{@link org.quartz.Job}</code>.
       * </p>
       * 
       * @param newJob
       *          The <code>Job</code> to be stored.
       * @param replaceExisting
       *          If <code>true</code>, any <code>Job</code> existing in the
       *          <code>JobStore</code> with the same name & group should be
       *          over-written.
       * @throws ObjectAlreadyExistsException
       *           if a <code>Job</code> with the same name/group already
       *           exists, and replaceExisting is set to false.
       */
      public void storeJob(JobDetail newJob,
              boolean replaceExisting) throws ObjectAlreadyExistsException {
          JobWrapper jw = new JobWrapper((JobDetail)newJob.clone());
  
          boolean repl = false;
  
          synchronized (lock) {
              if (jobsByKey.get(jw.key) != null) {
                  if (!replaceExisting) {
                      throw new ObjectAlreadyExistsException(newJob);
                  }
                  repl = true;
              }
  
              if (!repl) {
                  // get job group
                  HashMap<JobKey, JobWrapper> grpMap = jobsByGroup.get(newJob.getKey().getGroup());
                  if (grpMap == null) {
                      grpMap = new HashMap<JobKey, JobWrapper>(100);
                      jobsByGroup.put(newJob.getKey().getGroup(), grpMap);
                  }
                  // add to jobs by group
                  grpMap.put(newJob.getKey(), jw);
                  // add to jobs by FQN map
                  jobsByKey.put(jw.key, jw);
              } else {
                  // update job detail
                  JobWrapper orig = jobsByKey.get(jw.key);
                  orig.jobDetail = jw.jobDetail; // already cloned
              }
          }
      }
  
      /**
       * <p>
       * Remove (delete) the <code>{@link org.quartz.Job}</code> with the given
       * name, and any <code>{@link org.quartz.Trigger}</code> s that reference
       * it.
       * </p>
       *
       * @return <code>true</code> if a <code>Job</code> with the given name &
       *         group was found and removed from the store.
       */
      public boolean removeJob(JobKey jobKey) {
  
          boolean found = false;
  
          synchronized (lock) {
              List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey);
              for (OperableTrigger trig: triggersOfJob) {
                  this.removeTrigger(trig.getKey());
                  found = true;
              }
              
              found = (jobsByKey.remove(jobKey) != null) | found;
              if (found) {
  
                  HashMap<JobKey, JobWrapper> grpMap = jobsByGroup.get(jobKey.getGroup());
                  if (grpMap != null) {
                      grpMap.remove(jobKey);
                      if (grpMap.size() == 0) {
                          jobsByGroup.remove(jobKey.getGroup());
                      }
                  }
              }
          }
  
          return found;
      }
  
      public boolean removeJobs(List<JobKey> jobKeys)
              throws JobPersistenceException {
          boolean allFound = true;
  
          synchronized (lock) {
              for(JobKey key: jobKeys)
                  allFound = removeJob(key) && allFound;
          }
  
          return allFound;
      }
  
      public boolean removeTriggers(List<TriggerKey> triggerKeys)
              throws JobPersistenceException {
          boolean allFound = true;
  
          synchronized (lock) {
              for(TriggerKey key: triggerKeys)
  