InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { int p = search(noteOn); if (0 <= p) { if (noteData != null) { notes[p].setData(noteData.copy()); return this; } else { System.arraycopy(notes, p + 1, notes, p, cnt - p - 1); cnt--; return 0 < cnt ? this : null; } } else if (noteData != null) { if (shouldSplit()) { return split().set(noteOn, noteData, or); } else { growIfFull(); p = -(p + 1); if (p < cnt) System.arraycopy(notes, p, notes, p + 1, cnt - p); notes[p] = new Note(noteOn, noteData.copy()); cnt++; return this; } } else { return this; } }
private int search(AnyObjectId objId) { int low = 0; int high = cnt; while (low < high) { int mid = (low + high) >>> 1; int cmp = objId.compareTo(notes[mid]); if (cmp < 0) high = mid; else if (cmp == 0) return mid; else low = mid + 1; } return -(low + 1); }
void parseOneEntry(AnyObjectId noteOn, AnyObjectId noteData) { growIfFull(); notes[cnt++] = new Note(noteOn, noteData.copy()); }