@Test public void getVisibleChangesWithOverlappingRanges() throws Exception { MemoryDocumentStore store = new MemoryDocumentStore(); DocumentNodeStore ns = createTestStore(store, 1, 0); addNode(ns, "/test"); setProperty(ns, "/test/p", 1); setProperty(ns, "/test/p", 2); setProperty(ns, "/test/p", 3); RevisionVector readRev = ns.getHeadRevision(); setProperty(ns, "/test/q", 1); setProperty(ns, "/test/q", 2); String id = Utils.getIdFromPath("/test"); NodeDocument doc = store.find(NODES, id); assertNotNull(doc); List<UpdateOp> splitOps = SplitOperations.forDocument( doc, ns, ns.getHeadRevision(), NO_BINARY, 1); assertEquals(2, splitOps.size()); store.createOrUpdate(NODES, splitOps); setProperty(ns, "/test/p", 4); doc = store.find(NODES, id); assertNotNull(doc); splitOps = SplitOperations.forDocument( doc, ns, ns.getHeadRevision(), NO_BINARY, 1); assertEquals(2, splitOps.size()); store.createOrUpdate(NODES, splitOps); doc = store.find(NODES, id); assertNotNull(doc); for (Map.Entry<Revision, String> change : doc.getVisibleChanges("p", readRev)) { assertFalse(readRev.isRevisionNewer(change.getKey())); } }
@NotNull Iterable<Map.Entry<Revision, String>> getVisibleChanges(@NotNull final String property, @NotNull final RevisionVector readRevision) { Predicate<Map.Entry<Revision, String>> p = new Predicate<Map.Entry<Revision, String>>() { @Override public boolean apply(Map.Entry<Revision, String> input) { return !readRevision.isRevisionNewer(input.getKey()); } }; List<Iterable<Map.Entry<Revision, String>>> changes = Lists.newArrayList(); Map<Revision, String> localChanges = getLocalMap(property); if (!localChanges.isEmpty()) { changes.add(filter(localChanges.entrySet(), p)); } for (Revision r : readRevision) { collectVisiblePreviousChanges(property, r, changes); } if (changes.size() == 1) { return changes.get(0); } else { return mergeSorted(changes, ValueComparator.REVERSE); } }
NodeDocument extends Document { @NotNull Iterable<Map.Entry<Revision, String>> getVisibleChanges(@NotNull final String property, @NotNull final RevisionVector readRevision) { Predicate<Map.Entry<Revision, String>> p = new Predicate<Map.Entry<Revision, String>>() { @Override public boolean apply(Map.Entry<Revision, String> input) { return !readRevision.isRevisionNewer(input.getKey()); } }; List<Iterable<Map.Entry<Revision, String>>> changes = Lists.newArrayList(); Map<Revision, String> localChanges = getLocalMap(property); if (!localChanges.isEmpty()) { changes.add(filter(localChanges.entrySet(), p)); } for (Revision r : readRevision) { collectVisiblePreviousChanges(property, r, changes); } if (changes.size() == 1) { return changes.get(0); } else { return mergeSorted(changes, ValueComparator.REVERSE); } } }
NodeDocument extends Document { @NotNull Iterable<Map.Entry<Revision, String>> getVisibleChanges(@NotNull final String property, @NotNull final RevisionVector readRevision) { Predicate<Map.Entry<Revision, String>> p = new Predicate<Map.Entry<Revision, String>>() { @Override public boolean apply(Map.Entry<Revision, String> input) { return !readRevision.isRevisionNewer(input.getKey()); } }; List<Iterable<Map.Entry<Revision, String>>> changes = Lists.newArrayList(); Map<Revision, String> localChanges = getLocalMap(property); if (!localChanges.isEmpty()) { changes.add(filter(localChanges.entrySet(), p)); } for (Revision r : readRevision) { collectVisiblePreviousChanges(property, r, changes); } if (changes.size() == 1) { return changes.get(0); } else { return mergeSorted(changes, ValueComparator.REVERSE); } } NodeDocument(@NotNull DocumentStore store);  NodeDocument(@NotNull DocumentStore store, long creationTime); }
NodeDocument extends Document { @NotNull Iterable<Map.Entry<Revision, String>> getVisibleChanges(@NotNull final String property, @NotNull final RevisionVector readRevision) { Predicate<Map.Entry<Revision, String>> p = new Predicate<Map.Entry<Revision, String>>() { @Override public boolean apply(Map.Entry<Revision, String> input) { return !readRevision.isRevisionNewer(input.getKey()); } }; List<Iterable<Map.Entry<Revision, String>>> changes = Lists.newArrayList(); Map<Revision, String> localChanges = getLocalMap(property); if (!localChanges.isEmpty()) { changes.add(filter(localChanges.entrySet(), p)); } for (Revision r : readRevision) { collectVisiblePreviousChanges(property, r, changes); } if (changes.size() == 1) { return changes.get(0); } else { return mergeSorted(changes, ValueComparator.REVERSE); } } NodeDocument(@NotNull DocumentStore store);  NodeDocument(@NotNull DocumentStore store, long creationTime); static long getModifiedInSecs(long timestamp); @NotNull Map<Revision, String> getValueMap(@NotNull String key); long getCreated(); @Nullable Long getModified(); boolean hasChildren(); boolean wasDeletedOnce(); boolean hasBeenModifiedSince(long lastModifiedTime); boolean hasAllRevisionLessThan(long maxRevisionTime); boolean isSplitDocument(); SplitDocType getSplitDocType(); void markUpToDate(long checkTime); long getLastCheckTime(); boolean hasBinary(); @NotNull Path getMainPath(); @NotNull Map<Integer, Revision> getLastRev(); boolean containsRevision(@NotNull Revision revision); @Nullable Path getCommitRootPath(Revision revision); @Nullable DocumentNodeState getNodeAtRevision(@NotNull DocumentNodeStore nodeStore,
                                               @NotNull RevisionVector readRevision,
                                               @Nullable Revision lastModified); @Nullable Revision getLiveRevision(RevisionContext context,
                                    RevisionVector readRevision,
                                    Map<Revision, String> validRevisions,
                                    LastRevs lastRevs); @NotNull Iterable<UpdateOp> split(@NotNull RevisionContext context,
                                    @NotNull RevisionVector head,
                                    @NotNull Function<String, Long> binarySize); @NotNull Set<Revision> getLocalBranchCommits(); static void setChildrenFlag(@NotNull UpdateOp op,
                                       boolean hasChildNode); static void setModified(@NotNull UpdateOp op,
                                   @NotNull Revision revision); static void setRevision(@NotNull UpdateOp op,
                                   @NotNull Revision revision,
                                   @NotNull String commitValue); static void unsetRevision(@NotNull UpdateOp op,
                                     @NotNull Revision revision); static boolean isRevisionsEntry(String name); static boolean isCommitRootEntry(String name); static boolean isDeletedEntry(String name); static boolean isLastRevEntry(String name); static void removeRevision(@NotNull UpdateOp op,
                                      @NotNull Revision revision); static void addCollision(@NotNull UpdateOp op,
                                    @NotNull Revision revision,
                                    @NotNull Revision other); static void removeCollision(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void setLastRev(@NotNull UpdateOp op,
                                  @NotNull Revision revision); static void setCommitRoot(@NotNull UpdateOp op,
                                     @NotNull Revision revision,
                                     int commitRootDepth); static void removeCommitRoot(@NotNull UpdateOp op,
                                        @NotNull Revision revision); static void unsetCommitRoot(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void setDeleted(@NotNull UpdateOp op,
                                  @NotNull Revision revision,
                                  boolean deleted); static void setDeletedOnce(@NotNull UpdateOp op); static void removeDeleted(@NotNull UpdateOp op,
                                     @NotNull Revision revision); static void setPrevious(@NotNull UpdateOp op,
                                   @NotNull Range range); static void removePrevious(@NotNull UpdateOp op,
                                      @NotNull Range range); static void removePrevious(@NotNull UpdateOp op,
                                      @NotNull Revision revision); static void setStalePrevious(@NotNull UpdateOp op,
                                        @NotNull Revision revision,
                                        int height); static void removeStalePrevious(@NotNull UpdateOp op,
                                           @NotNull Revision revision); static void setHasBinary(@NotNull UpdateOp op); static void setBranchCommit(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void removeBranchCommit(@NotNull UpdateOp op,
                                          @NotNull Revision revision); static void setSweepRevision(@NotNull UpdateOp op,
                                        @NotNull Revision revision); static void hasLastRev(@NotNull UpdateOp op,
                                  @NotNull Revision revision); @NotNull Path getPath(); String asString(); static NodeDocument fromString(DocumentStore store, String s); }
NodeDocument extends Document { @NotNull Iterable<Map.Entry<Revision, String>> getVisibleChanges(@NotNull final String property, @NotNull final RevisionVector readRevision) { Predicate<Map.Entry<Revision, String>> p = new Predicate<Map.Entry<Revision, String>>() { @Override public boolean apply(Map.Entry<Revision, String> input) { return !readRevision.isRevisionNewer(input.getKey()); } }; List<Iterable<Map.Entry<Revision, String>>> changes = Lists.newArrayList(); Map<Revision, String> localChanges = getLocalMap(property); if (!localChanges.isEmpty()) { changes.add(filter(localChanges.entrySet(), p)); } for (Revision r : readRevision) { collectVisiblePreviousChanges(property, r, changes); } if (changes.size() == 1) { return changes.get(0); } else { return mergeSorted(changes, ValueComparator.REVERSE); } } NodeDocument(@NotNull DocumentStore store);  NodeDocument(@NotNull DocumentStore store, long creationTime); static long getModifiedInSecs(long timestamp); @NotNull Map<Revision, String> getValueMap(@NotNull String key); long getCreated(); @Nullable Long getModified(); boolean hasChildren(); boolean wasDeletedOnce(); boolean hasBeenModifiedSince(long lastModifiedTime); boolean hasAllRevisionLessThan(long maxRevisionTime); boolean isSplitDocument(); SplitDocType getSplitDocType(); void markUpToDate(long checkTime); long getLastCheckTime(); boolean hasBinary(); @NotNull Path getMainPath(); @NotNull Map<Integer, Revision> getLastRev(); boolean containsRevision(@NotNull Revision revision); @Nullable Path getCommitRootPath(Revision revision); @Nullable DocumentNodeState getNodeAtRevision(@NotNull DocumentNodeStore nodeStore,
                                               @NotNull RevisionVector readRevision,
                                               @Nullable Revision lastModified); @Nullable Revision getLiveRevision(RevisionContext context,
                                    RevisionVector readRevision,
                                    Map<Revision, String> validRevisions,
                                    LastRevs lastRevs); @NotNull Iterable<UpdateOp> split(@NotNull RevisionContext context,
                                    @NotNull RevisionVector head,
                                    @NotNull Function<String, Long> binarySize); @NotNull Set<Revision> getLocalBranchCommits(); static void setChildrenFlag(@NotNull UpdateOp op,
                                       boolean hasChildNode); static void setModified(@NotNull UpdateOp op,
                                   @NotNull Revision revision); static void setRevision(@NotNull UpdateOp op,
                                   @NotNull Revision revision,
                                   @NotNull String commitValue); static void unsetRevision(@NotNull UpdateOp op,
                                     @NotNull Revision revision); static boolean isRevisionsEntry(String name); static boolean isCommitRootEntry(String name); static boolean isDeletedEntry(String name); static boolean isLastRevEntry(String name); static void removeRevision(@NotNull UpdateOp op,
                                      @NotNull Revision revision); static void addCollision(@NotNull UpdateOp op,
                                    @NotNull Revision revision,
                                    @NotNull Revision other); static void removeCollision(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void setLastRev(@NotNull UpdateOp op,
                                  @NotNull Revision revision); static void setCommitRoot(@NotNull UpdateOp op,
                                     @NotNull Revision revision,
                                     int commitRootDepth); static void removeCommitRoot(@NotNull UpdateOp op,
                                        @NotNull Revision revision); static void unsetCommitRoot(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void setDeleted(@NotNull UpdateOp op,
                                  @NotNull Revision revision,
                                  boolean deleted); static void setDeletedOnce(@NotNull UpdateOp op); static void removeDeleted(@NotNull UpdateOp op,
                                     @NotNull Revision revision); static void setPrevious(@NotNull UpdateOp op,
                                   @NotNull Range range); static void removePrevious(@NotNull UpdateOp op,
                                      @NotNull Range range); static void removePrevious(@NotNull UpdateOp op,
                                      @NotNull Revision revision); static void setStalePrevious(@NotNull UpdateOp op,
                                        @NotNull Revision revision,
                                        int height); static void removeStalePrevious(@NotNull UpdateOp op,
                                           @NotNull Revision revision); static void setHasBinary(@NotNull UpdateOp op); static void setBranchCommit(@NotNull UpdateOp op,
                                       @NotNull Revision revision); static void removeBranchCommit(@NotNull UpdateOp op,
                                          @NotNull Revision revision); static void setSweepRevision(@NotNull UpdateOp op,
                                        @NotNull Revision revision); static void hasLastRev(@NotNull UpdateOp op,
                                  @NotNull Revision revision); @NotNull Path getPath(); String asString(); static NodeDocument fromString(DocumentStore store, String s); static final NodeDocument NULL; static final String MIN_ID_VALUE; static final String MAX_ID_VALUE; static final String COLLISIONS; static final String MODIFIED_IN_SECS; static final String DELETED_ONCE; static final String PATH; static final String HAS_BINARY_FLAG; static final String SD_TYPE; static final String SD_MAX_REV_TIME_IN_SECS; static final long HAS_BINARY_VAL; }