/** Test of fromJson method, of class Patch. */
  @Test
  public void testFromJson() throws Exception {
    String json =
        "[{\"op\":\"replace\",\"path\":\"name\",\"value\":\"Ged "
            + "corrigée\"},{\"op\":\"replace\",\"path\":\"versionning\",\"value\":\"false\"},{"
            + "\"op\":\"remove\",\"path\":\"xmlForm\",\"value\":\"\"}]";
    JsonPatch instance = new JsonPatch();
    instance.fromJson(json);
    assertThat(instance, is(notNullValue()));
    assertThat(instance.getOperations(), is(notNullValue()));
    assertThat(instance.getOperations(), hasSize(3));
    Operation operation = instance.getOperationByPath("name");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.replace));
    assertThat(operation.getValue(), is("Ged corrigée"));
    assertThat(operation.getPath(), is("name"));

    operation = instance.getOperationByPath("versionning");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.replace));
    assertThat(operation.getValue(), is("false"));
    assertThat(operation.getPath(), is("versionning"));

    operation = instance.getOperationByPath("xmlForm");
    assertThat(operation, is(notNullValue()));
    assertThat(operation.getOp(), is(Op.remove));
    assertThat(operation.getValue(), is(""));
    assertThat(operation.getPath(), is("xmlForm"));

    operation = instance.getOperationByPath("miguel");
    assertThat(operation, is(nullValue()));
  }
  /**
   * executes the operation from waitList of the Transaction that was waiting for Transaction
   * transactionID to end/abort
   *
   * @param transactionID
   */
  private void notifyWaitingTransaction(String transactionID) {
    Transaction tr = this.currentTransactions.get(transactionID);
    if (tr.transactionThatWaitsForThisTransaction == null) {
      // no transaction waits for this transaction so do not do anything
    } else {
      // Transaction waitingTransaction waits for Transaction transactionID
      Transaction waitingTransaction =
          this.currentTransactions.get(tr.transactionThatWaitsForThisTransaction);
      if (this.waitList.size() > 0
          && this.waitList.containsKey(waitingTransaction.getTransactionID())) {
        waitingTransaction.transactionsThatThisTransactionWaitsFor.remove(transactionID);
        int variableThatWaitingTransactionNeeds;
        ArrayList<Operation> opList = this.waitList.get(waitingTransaction.getTransactionID());
        Operation op = opList.get(0);
        variableThatWaitingTransactionNeeds = op.getVariableIndex();
        if (op.getOperationType() == 1) {
          this.getAllWriteLocksOnVariableThatYouCanGet(
              waitingTransaction.getTransactionID(), variableThatWaitingTransactionNeeds);
        }

        if (waitingTransaction.transactionsThatThisTransactionWaitsFor.size() == 0) {
          this.waitList.remove(waitingTransaction.getTransactionID());
          if (op.getOperationType() == 0) {
            // read operation
            this.readValue(waitingTransaction.getTransactionID(), op.getVariableIndex());
          } else { // write operation
            this.writeValue(
                waitingTransaction.getTransactionID(), op.getVariableIndex(), op.getValue());
          }
        }
      }
    }
  }
Esempio n. 3
0
 public int getB() {
   if (opeB != null)
     try {
       b = opeB.getValue();
     } catch (Exception e) {
       e.printStackTrace();
     }
   return b;
 }
Esempio n. 4
0
  public int getValue() throws Exception {

    if (opeA != null) a = opeA.getValue();
    if (opeB != null) b = opeB.getValue();

    switch (ope) {
      case ADDITION:
        return a + b;
      case SOUSTRACTION:
        return a - b;
      case MULTIPLICATION:
        return a * b;
      case DIVISION:
        if (b == 0) throw new Exception("Division par 0");
        return a / b;
    }
    return 0;
  }
Esempio n. 5
0
 public int getA() {
   if (opeA != null)
     try {
       a = opeA.getValue();
     } catch (Exception e) {
       e.printStackTrace();
     }
   return a;
 }