DocumentReference (final @NotNull Document document) { DocumentReference result = myDocToRef.get(document); if (result == null) { result = new DocumentReferenceByDocument(document); myDocToRef.put(document, result); } return result; }