public Builder add(SubDocument subDocument) { Preconditions.checkState(!build, "This builder has already been used"); SubDocType type = subDocument.getType(); Integer index = indexBySubDoc.get(type); if (index == null) { index = 0; } else { index++; } indexBySubDoc.put(type, index); subDocuments.put(type, index, subDocument); return this; }