code: private void deleteUnwantedJobs(List<HudsonJob> activeJobs, List<HudsonJob> existingJobs, List<String> activeServers, HudsonCollector collector) {
  
          List<HudsonJob> deleteJobList = new ArrayList<>();
          for (HudsonJob job : existingJobs) {
              if (job.isPushed()) continue; // build servers that push jobs will not be in active servers list by design
  
              // if we have a collector item for the job in repository but it's build server is not what we collect, remove it.
              if (!collector.getBuildServers().contains(job.getInstanceUrl())) {
                  deleteJobList.add(job);
              }
  
              //if the collector id of the collector item for the job in the repo does not match with the collector ID, delete it.
              if (!Objects.equals(job.getCollectorId(), collector.getId())) {
                  deleteJobList.add(job);
              }
  
              // this is to handle jobs that have been deleted from build servers. Will get 404 if we don't delete them.
              if (activeServers.contains(job.getInstanceUrl()) && !activeJobs.contains(job)) {
                  deleteJobList.add(job);
              }
  
          }
          if (!CollectionUtils.isEmpty(deleteJobList)) {
              hudsonJobRepository.delete(deleteJobList);
          }
      }
docs: Delete orphaned job collector items
  
  @param activeJobs
  @param existingJobs
  @param activeServers
  @param collector