private static InMemoryNoteBucket addIfNotNull(InMemoryNoteBucket result, Note note) { if (note != null) return result.append(note); else return result; }
@Override int estimateSize(AnyObjectId objId, ObjectReader or) throws IOException { return load(objId, or).estimateSize(objId, or); }
/** * Lookup a note for a specific ObjectId. * * @param id * the object to look for. * @return the note for the given object id, or null if no note exists. * @throws java.io.IOException * a portion of the note space is not accessible. */ public Note getNote(AnyObjectId id) throws IOException { return root.getNote(id, reader); }
/** {@inheritDoc} */ @Override public Iterator<Note> iterator() { try { return root.iterator(new MutableObjectId(), reader); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Write this note map as a tree. * * @param inserter * inserter to use when writing trees to the object database. * Caller is responsible for flushing the inserter before trying * to read the objects, or exposing them through a reference. * @return the top level tree. * @throws java.io.IOException * a tree could not be written. */ public ObjectId writeTree(ObjectInserter inserter) throws IOException { return root.writeTree(inserter); }
@Override InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { return load(noteOn, or).set(noteOn, noteData, or); }
@Override Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader) throws IOException { return load(objId, reader).iterator(objId, reader); }
private void addIfNotNull(FanoutBucket b, int cell, NoteBucket child) throws IOException { if (child == null) return; if (child instanceof InMemoryNoteBucket) b.setBucket(cell, ((InMemoryNoteBucket) child).writeTree(inserter)); else b.setBucket(cell, child.getTreeId()); }
InMemoryNoteBucket newRoot = root.set(noteOn, noteData, reader); if (newRoot == null) { newRoot = new LeafBucket(0);
InMemoryNoteBucket contractIfTooSmall(AnyObjectId noteOn, ObjectReader or) throws IOException { if (estimateSize(noteOn, or) < LeafBucket.MAX_SIZE) { // We are small enough to just contract to a single leaf. InMemoryNoteBucket r = new LeafBucket(prefixLen); for (Iterator<Note> i = iterator(noteOn, or); i.hasNext();) r = r.append(i.next()); r.nonNotes = nonNotes; return r; } return this; }
@Override Note getNote(AnyObjectId objId, ObjectReader or) throws IOException { return load(objId, or).getNote(objId, or); }
/** {@inheritDoc} */ @Override public Iterator<Note> iterator() { try { return root.iterator(new MutableObjectId(), reader); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Write this note map as a tree. * * @param inserter * inserter to use when writing trees to the object database. * Caller is responsible for flushing the inserter before trying * to read the objects, or exposing them through a reference. * @return the top level tree. * @throws IOException * a tree could not be written. */ public ObjectId writeTree(ObjectInserter inserter) throws IOException { return root.writeTree(inserter); }
@Override InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { return load(noteOn, or).set(noteOn, noteData, or); }
@Override int estimateSize(AnyObjectId objId, ObjectReader or) throws IOException { return load(objId, or).estimateSize(objId, or); }
@Override InMemoryNoteBucket append(Note note) { int cell = cell(note); InMemoryNoteBucket b = (InMemoryNoteBucket) table[cell]; if (b == null) { LeafBucket n = new LeafBucket(prefixLen + 2); table[cell] = n.append(note); cnt++; } else { InMemoryNoteBucket n = b.append(note); if (n != b) table[cell] = n; } return this; }
/** * Lookup a note for a specific ObjectId. * * @param id * the object to look for. * @return the note's blob ObjectId, or null if no note exists. * @throws java.io.IOException * a portion of the note space is not accessible. */ public ObjectId get(AnyObjectId id) throws IOException { Note n = root.getNote(id, reader); return n == null ? null : n.getData(); }
@Override Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader) throws IOException { return load(objId, reader).iterator(objId, reader); }
/** * Write this note map as a tree. * * @param inserter * inserter to use when writing trees to the object database. * Caller is responsible for flushing the inserter before trying * to read the objects, or exposing them through a reference. * @return the top level tree. * @throws java.io.IOException * a tree could not be written. */ public ObjectId writeTree(ObjectInserter inserter) throws IOException { return root.writeTree(inserter); }
@Override InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData, ObjectReader or) throws IOException { return load(noteOn, or).set(noteOn, noteData, or); }