/** Initialize a newly created manager to have no work queued up. */ @SuppressWarnings("unchecked") public WorkManager() { int queueCount = SourcePriority.values().length; workQueues = new ArrayList[queueCount]; for (int i = 0; i < queueCount; i++) { workQueues[i] = new ArrayList<Source>(); } }
/** * Record that the given source needs to be analyzed. The priority level is used to control when * the source will be analyzed with respect to other sources. * * @param source the source that needs to be analyzed * @param priority the priority level of the source */ public void add(Source source, SourcePriority priority) { // TODO(brianwilkerson) Optimize the order of the libraries so that libraries that depend on // other libraries get analyzed after the other libraries. int queueCount = workQueues.length; int ordinal = priority.ordinal(); for (int i = 0; i < queueCount; i++) { ArrayList<Source> queue = workQueues[i]; if (i == ordinal) { if (!queue.contains(source)) { queue.add(source); } } else { queue.remove(source); } } }