Пример #1
0
  // AddFile - AddFile
  public TranspResult transp(AddTxtFile c1, AddBlock c2) throws Exception {
    if (c1.getPath().equals(c2.getPath())) {
      c2.doTheJobOnFile(c1.getAttachement());

      return new TranspResult(c1, new EmptyOp(c2), false);
    }

    return new TranspResult(c2, c1, true);
  }
Пример #2
0
  // AddBlock - AddBlock
  public TranspResult transp(AddBlock c1, AddBlock c2) {
    if (c1.getPath().equals(c2.getPath())) {
      int s1 = c1.getInsertPoint();
      int l1 = c1.getSize();
      int s2 = c2.getInsertPoint();
      int l2 = c2.getSize();

      if ((s1 <= s2) && (s2 <= (s1 + l1))) {
        // s2 inside of s1
        Collection block = c1.getContent();
        Collection blockInside = c2.getContent();
        ArrayList newContent = new ArrayList();
        Iterator i = block.iterator();

        for (int b = 0; (b < (s2 - s1)) && i.hasNext(); b++) {
          newContent.add(i.next());
        }

        for (Iterator j = blockInside.iterator(); j.hasNext(); ) {
          newContent.add(j.next());
        }

        while (i.hasNext()) {
          newContent.add(i.next());
        }

        c1.setContent(newContent);

        return new TranspResult(c1, new EmptyOp(c2), false);
      } else {
        // The two blocks are disjoint
        return new TranspResult(c1, c2, false);
      }
    }

    return new TranspResult(c2, c1, true);
  }
Пример #3
0
  // AddBlock - DelBlock
  public TranspResult transp(AddBlock c1, DelBlock c2) {
    if (c1.getPath().equals(c2.getPath())) {
      int s1 = c1.getInsertPoint();
      int l1 = c1.getSize();
      int s2 = c2.getDeletePoint();
      int l2 = c2.getSize();
      Object[] add = c1.getContent().toArray();
      Object[] delete = c2.getOldContent().toArray();
      Collection addContent = new ArrayList();
      Collection deleteContent = new ArrayList();

      if ((s1 <= s2) && (s2 < (s1 + l1))) {
        // s2 inside s1
        if (l2 > (l1 - (s2 - s1))) {
          // The delete is bigger than the add
          if (s1 == s2) {
            // The delete remove the add
            for (int i = add.length; i < delete.length; i++) {
              deleteContent.add(delete[i]);
            }

            c2.setOldContent(deleteContent);

            return new TranspResult(c2, new EmptyOp(c1), true);
          } else {
            // The delete remove the tail of the add
            for (int i = 0; i < (s2 - s1); i++) {
              addContent.add(add[i]);
            }

            for (int i = ((s1 + l1) - (s2 - s1)); i < delete.length; i++) {
              deleteContent.add(delete[i]);
            }

            c1.setContent(addContent);
            c2.setOldContent(deleteContent);
            c2.setDeletePoint(s2 - c1.getSize());

            return new TranspResult(c2, c1, true);
          }
        } else {
          // The delete is include in the add
          for (int i = 0; i < add.length; i++) {
            if (!(((s2 - s1) <= i) && (i < (s2 - s1 + l2)))) {
              addContent.add(add[i]);
            }
          }

          if (addContent.size() == 0) {
            return new TranspResult(new EmptyOp(c1), new EmptyOp(c2), false);
          }

          c1.setContent(addContent);

          return new TranspResult(c1, new EmptyOp(c2), false);
        }
      } else {
        // The two blocks are disjoint
        if (s1 < s2) {
          // Add before del
          c2.setDeletePoint(s2 - l1);
        }

        return new TranspResult(c2, c1, true);
      }
    }

    return new TranspResult(c2, c1, true);
  }