private Priority computeNewPriority() { Priority newPriority = LOW; final boolean hasMultiple = actions != null && !actions.isEmpty(); final boolean hasAny = action != null || hasMultiple; // Hunter has no requests, low priority. if (!hasAny) { return newPriority; } if (action != null) { newPriority = action.request.priority; } if (actions != null) { //noinspection ForLoopReplaceableByForEach for (int i = 0, n = actions.size(); i < n; i++) { Priority actionPriority = actions.get(i).request.priority; if (actionPriority.ordinal() > newPriority.ordinal()) { newPriority = actionPriority; } } } return newPriority; }
void attach(Action action) { boolean loggingEnabled = picasso.loggingEnabled; Request request = action.request; if (this.action == null) { this.action = action; if (loggingEnabled) { if (actions == null || actions.isEmpty()) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), "to empty hunter"); } else { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } } return; } if (actions == null) { actions = new ArrayList<>(3); } actions.add(action); if (loggingEnabled) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } Priority actionPriority = action.request.priority; if (actionPriority.ordinal() > priority.ordinal()) { priority = actionPriority; } }
@Override public int compareTo(PicassoFutureTask other) { Picasso.Priority p1 = hunter.getPriority(); Picasso.Priority p2 = other.hunter.getPriority(); // High-priority requests are "lesser" so they are sorted to the front. // Equal priorities are sorted by sequence number to provide FIFO ordering. return (p1 == p2 ? hunter.sequence - other.hunter.sequence : p2.ordinal() - p1.ordinal()); } }