test_class.file: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtilsTest.java
test_class.identifier: UpdateUtilsTest
test_case.body: @Test
      public void checkConditions() {
          Revision r = Revision.newRevision(1);
          String id = Utils.getIdFromPath("/foo");
          Document d = new Document();
          d.put(Document.ID, id);
  
          UpdateOp op = newUpdateOp(id);
          op.set("p", 42L);
          op.setMapEntry("t", r, "value");
          UpdateUtils.applyChanges(d, op);
  
          op = newUpdateOp(id);
          op.containsMapEntry("t", r, true);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.containsMapEntry("t", r, false);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.containsMapEntry("q", r, true);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.containsMapEntry("q", r, false);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("t", r, "value");
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("t", r, "value");
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("t", r, "foo");
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("t", r, "foo");
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("t", Revision.newRevision(1), "value");
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("t", Revision.newRevision(1), "value");
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("t", "value");
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("t", "value");
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("p", r, 42L);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("p", r, 42L);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("p", 42L);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("p", 42L);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("p", 7L);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("p", 7L);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          // check on non-existing property
          op = newUpdateOp(id);
          op.notEquals("other", 7L);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("other", r, 7L);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("other", r, null);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.equals("other", r, null);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          // check null
          op = newUpdateOp(id);
          op.notEquals("p", null);
          assertTrue(UpdateUtils.checkConditions(d, op.getConditions()));
  
          op = newUpdateOp(id);
          op.notEquals("other", r, null);
          assertFalse(UpdateUtils.checkConditions(d, op.getConditions()));
      }
test_case.class_method_signature: UpdateUtilsTest.checkConditions()
test_case.full_signature: @Test public void checkConditions()
test_case.identifier: checkConditions
test_case.invocations: newRevision getIdFromPath put newUpdateOp set setMapEntry applyChanges newUpdateOp containsMapEntry assertTrue checkConditions getConditions newUpdateOp containsMapEntry assertFalse checkConditions getConditions newUpdateOp containsMapEntry assertFalse checkConditions getConditions newUpdateOp containsMapEntry assertTrue checkConditions getConditions newUpdateOp equals assertTrue checkConditions getConditions newUpdateOp notEquals assertFalse checkConditions getConditions newUpdateOp equals assertFalse checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp equals newRevision assertFalse checkConditions getConditions newUpdateOp notEquals newRevision assertTrue checkConditions getConditions newUpdateOp equals assertFalse checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp equals assertFalse checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp equals assertTrue checkConditions getConditions newUpdateOp notEquals assertFalse checkConditions getConditions newUpdateOp equals assertFalse checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp notEquals assertFalse checkConditions getConditions newUpdateOp equals assertTrue checkConditions getConditions newUpdateOp notEquals assertTrue checkConditions getConditions newUpdateOp notEquals assertFalse checkConditions getConditions
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void checkConditions()
focal_class.file: oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/UpdateUtils.java
focal_class.identifier: UpdateUtils
focal_class.class_method_signature: UpdateUtils.applyChanges(@NotNull Document doc,
                                      @NotNull UpdateOp update)
focal_class.full_signature: public static void applyChanges(@NotNull Document doc,
                                      @NotNull UpdateOp update)
focal_class.identifier: applyChanges
focal_class.modifiers: public static
focal_class.parameters: (@NotNull Document doc,
                                      @NotNull UpdateOp update)
focal_class.return: void
focal_class.signature: void applyChanges(@NotNull Document doc,
                                      @NotNull UpdateOp update)
focal_class.class_method_signature: UpdateUtils.checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_class.full_signature: public static boolean checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_class.identifier: checkConditions
focal_class.modifiers: public static
focal_class.parameters: (@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_class.return: boolean
focal_class.signature: boolean checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_class.class_method_signature: UpdateUtils.assertUnconditional(@NotNull UpdateOp up)
focal_class.full_signature: public static void assertUnconditional(@NotNull UpdateOp up)
focal_class.identifier: assertUnconditional
focal_class.modifiers: public static
focal_class.parameters: (@NotNull UpdateOp up)
focal_class.return: void
focal_class.signature: void assertUnconditional(@NotNull UpdateOp up)
focal_method.body: public static boolean checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions) {
          for (Map.Entry<Key, Condition> entry : conditions.entrySet()) {
              Condition c = entry.getValue();
              Key k = entry.getKey();
              Object value = doc.get(k.getName());
              Revision r = k.getRevision();
              if (c.type == Condition.Type.EXISTS) {
                  boolean checkForExistence = Boolean.TRUE.equals(c.value);
                  if (value == null) {
                      if (checkForExistence) {
                          return false;
                      }
                  } else {
                      if (r == null) {
                          if (!checkForExistence) {
                              return false;
                          }
                      } else if (value instanceof Map) {
                          Map<?, ?> map = (Map<?, ?>) value;
                          if (checkForExistence) {
                              if (!map.containsKey(r)) {
                                  return false;
                              }
                          } else {
                              if (map.containsKey(r)) {
                                  return false;
                              }
                          }
                      } else {
                          return false;
                      }
                  }
              } else if (c.type == Condition.Type.EQUALS || c.type == Condition.Type.NOTEQUALS) {
                  if (r != null) {
                      if (value instanceof Map) {
                          value = ((Map) value).get(r);
                      } else {
                          value = null;
                      }
                  }
                  boolean equal = Objects.equal(value, c.value);
                  if (c.type == Condition.Type.EQUALS && !equal) {
                      return false;
                  } else if (c.type == Condition.Type.NOTEQUALS && equal) {
                      return false;
                  }
              } else {
                  throw new IllegalArgumentException("Unknown condition: " + c.type);
              }
          }
          return true;
      }
focal_method.class_method_signature: UpdateUtils.checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_method.full_signature: public static boolean checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_method.identifier: checkConditions
focal_method.invocations: entrySet getValue getKey get getName getRevision equals containsKey containsKey get equal
focal_method.modifiers: public static
focal_method.parameters: (@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)
focal_method.return: boolean
focal_method.signature: boolean checkConditions(@NotNull Document doc,
                                            @NotNull Map<Key, Condition> conditions)