/** * Finds the range of references associated to {@code sourceName}. Note that even if there is no * sourceName references the returned information can be used to decide where to insert new * sourceName refs. */ private SourceRefRange findSourceRefRange(List<Reference> refList, InputId inputId) { Preconditions.checkNotNull(inputId); // TODO(bashir): We can do binary search here, but since this is fast enough // right now, we just do a linear search for simplicity. int lastBefore = -1; int firstAfter = refList.size(); int index = 0; Preconditions.checkState(inputOrder.containsKey(inputId), inputId.getIdName()); int sourceInputOrder = inputOrder.get(inputId); for (Reference ref : refList) { Preconditions.checkNotNull(ref.getInputId()); int order = inputOrder.get(ref.getInputId()); if (order < sourceInputOrder) { lastBefore = index; } else if (order > sourceInputOrder) { firstAfter = index; break; } index++; } return new SourceRefRange(refList, lastBefore, firstAfter); }
/** Returns a name for this input. Must be unique across all inputs. */ @Override public String getName() { return id.getIdName(); }