コード例 #1
0
ファイル: Position.java プロジェクト: gnooth/j
 public boolean nextLine() {
   if (line.next() != null) {
     line = line.next();
     offset = 0;
     return true;
   }
   return false;
 }
コード例 #2
0
ファイル: Position.java プロジェクト: gnooth/j
 public boolean next() {
   if (offset < line.length()) {
     ++offset;
     return true;
   }
   if (line.next() != null) {
     line = line.next();
     offset = 0;
     return true;
   }
   return false;
 }
コード例 #3
0
  void printInfo(Line badLine, String msg) {
    Line line = getFirstLine();
    PrintStream stream = System.out;

    int i = 0;
    while (line != null) {

      int indent = line.getIndent();

      stream.println(
          CollectionUtils.repeat('.', line.getIndent())
              + line.toString()
              + " indent:"
              + indent
              + CollectionUtils.repeat(' ', 20)
              + line.getCachedNumberValue()
              + "  ("
              + i
              + ")");

      if (line == badLine) {
        stream.println("\n\n\n");
        stream = System.err;
        stream.println(msg);
        stream.println(">>>>>>>>>>>>>>>>>>>>>>>>> DIED ON LINE ABOVE <<<<<<<<<<<<<<<<<<\n\n");
      }

      line = line.next();
      i++;
    }
  }
コード例 #4
0
  private void process(List<Line> lines) {
    int initialSeparatorPosition = initialSeparatorPosition(lines);
    for (Line line : lines) {
      line.appendInitialSpace(initialSeparatorPosition);
    }

    boolean process = true;
    while (process) {
      process = false;

      int maxLength = 0;
      for (Line line : lines) {
        line.appendText();
        maxLength = Math.max(maxLength, line.resultLength());
      }
      for (Line line : lines) {
        line.appendSpace(maxLength);
      }
      for (Line line : lines) {
        line.appendSeparator();
      }

      for (Line line : lines) {
        line.next();
      }

      for (Line line : lines) {
        process = process || line.hasToken();
      }
    }
  }
コード例 #5
0
ファイル: Position.java プロジェクト: gnooth/j
 public boolean atEnd() {
   if (line != null) {
     if (offset < line.length()) return false;
     if (line.next() != null) return false;
   }
   return true;
 }
コード例 #6
0
ファイル: Block.java プロジェクト: wavicles/loklak_server
 /**
  * Removes the given line from this block.
  *
  * @param line Line to remove.
  */
 public void removeLine(final Line line) {
   if (line.previous == null) {
     this.lines = line.next;
   } else {
     line.previous.next = line.next;
   }
   if (line.next == null) {
     this.lineTail = line.previous;
   } else {
     line.next.previous = line.previous;
   }
   line.previous = line.next = null;
 }
コード例 #7
0
ファイル: PHPTagger.java プロジェクト: gnooth/j
 public void run() {
   ArrayList tags = new ArrayList();
   Line line = buffer.getFirstLine();
   while (line != null) {
     String s = line.trim();
     if (s != null && s.startsWith("function")) {
       REMatch match = functionRE.getMatch(s);
       if (match != null) {
         String token = s.substring(match.getSubStartIndex(1), match.getSubEndIndex(1));
         tags.add(new LocalTag(token, line));
       }
     }
     line = line.next();
   }
   buffer.setTags(tags);
 }
コード例 #8
0
  /**
   * Check the current line numbering is consistent with the document state.
   *
   * @param iter current test iteration, for debugging/logging purposes.
   */
  void check(int iter) {

    runTask();

    //    if (iter >= 1740) {
    //      info("\n\nCHECKING\n");
    //      printInfo(null, "XX");
    //      info("---");
    //    }

    LevelNumbers numbers = new LevelNumbers(0, 1);
    Line line = getFirstLine();

    while (line != null) {

      int indent = line.getIndent();

      numbers.setLevel(indent);
      if (line.isDecimalListItem()) {
        int num = numbers.getNumberAndIncrement();
        assertFalse(line.getCachedNumberValue() == Line.DIRTY);
        if (num != line.getCachedNumberValue()) {
          String msg = "Expected: " + num + ", got: " + line.getCachedNumberValue();
          printInfo(line, msg);
          fail(
              "Wrong number on iteration "
                  + iter
                  + ". "
                  + msg
                  + ". See stdout & stderr for debug details");
        }
      } else {
        numbers.setNumber(1);
      }

      line = line.next();
    }

    //    info("^^^");
  }
コード例 #9
0
ファイル: Block.java プロジェクト: wavicles/loklak_server
  /**
   * Splits this block's lines, creating a new child block having 'line' as it's lineTail.
   *
   * @param line The line to split from.
   * @return The newly created Block.
   */
  public Block split(final Line line) {
    final Block block = new Block();

    block.lines = this.lines;
    block.lineTail = line;
    this.lines = line.next;
    line.next = null;
    if (this.lines == null) {
      this.lineTail = null;
    } else {
      this.lines.previous = null;
    }

    if (this.blocks == null) {
      this.blocks = this.blockTail = block;
    } else {
      this.blockTail.next = block;
      this.blockTail = block;
    }

    return block;
  }
コード例 #10
0
  /**
   * Performs a randomized test of renumbering logic.
   *
   * @param testIterations number of test iterations on the same document. Each iteration does a
   *     substantial amount of work (depending on document size).
   * @param seed initial random seed.
   */
  void doRandomTest(int testIterations, int seed) {
    ContentDocument.performExpensiveChecks = false;
    ContentDocument.validateLocalOps = false;
    IndexedDocumentImpl.performValidation = false;

    final int LEVELS = 4;
    final int MAX_RUN = 3;
    final int ITERS_PER_BATCH_RENDER = 6;
    final int DECIMALS_TO_OTHERS = 4; // ratio of decimal bullets to other stuff
    final int UPDATE_TO_ADD_REMOVE = 4; // ratio of updates to node adds/removals

    assertNull(scheduledTask);

    int maxRand = 5;
    Random r = new Random(seed);

    // For each iteration
    for (int iter = 0; iter < testIterations; iter++) {
      info("Iter: " + iter);

      // Repeat several times for a single batch render, to make sure we are
      // able to handle multiple overlapping, redundant updates.
      // Times two because we are alternating between two documents to test
      // the ability of the renumberer to handle more than one document
      // correctly.
      int innerIters = (r.nextInt(ITERS_PER_BATCH_RENDER) + 1) * 2;
      for (int inner = 0; inner < innerIters; inner++) {
        doc = doc1; // (inner % 2 == 0) ? doc1 : doc2;

        int totalLines = (doc.size() - 2) / 2;

        Line line = getFirstLine();

        // Pick a random section of the document to perform a bunch of random
        // changes to
        int i = 0;
        int a = r.nextInt(totalLines);
        int b = r.nextInt(totalLines);
        int startSection = Math.min(a, b);
        int endSection = Math.max(a, b);

        while (i < startSection) {
          i++;
          line = line.next();
        }

        while (i < endSection && line != null) {
          // Pick a random indentation to set
          int level = r.nextInt(LEVELS);
          // Length of run of elements to update
          int length;
          // Whether we are making them numbered items or doing something else
          boolean decimal;

          if (r.nextInt(DECIMALS_TO_OTHERS) == 0) {
            // No need making it a long run for non-numbered items.
            length = r.nextInt(2);
            decimal = false;
          } else {
            decimal = true;
            length = r.nextInt(MAX_RUN - 1) + 1;
          }

          while (length > 0 && i < endSection && line != null) {
            boolean fiftyFifty = i % 2 == 0;
            // If we're numbering these lines, then DECIMAL, otherwise choose a
            // random other type.
            Type type = decimal ? Type.DECIMAL : Type.values()[r.nextInt(Type.values().length - 1)];

            // Randomly decide to add/remove, or to update
            if (r.nextInt(UPDATE_TO_ADD_REMOVE) == 0) {

              int index = index(line);
              // Randomly decide to add or remove.
              // Include some constraints to ensure the document doesn't get too small or too large.
              boolean add =
                  index == 0 || totalLines < SIZE / 2
                      ? true
                      : (totalLines > SIZE * 2 ? false : r.nextBoolean());

              if (add) {
                line = create(index, type, level, r.nextBoolean());
              } else {
                line = delete(index);
                if (line == null) {
                  // We just deleted the last line.
                  continue;
                }
              }
              assert line != null;

            } else {
              update(index(line), type, level, fiftyFifty);
            }

            length--;
            i++;
            line = line.next();
          }
        }
      }

      check(iter);
    }
  }
コード例 #11
0
ファイル: Position.java プロジェクト: gnooth/j
 public final Line getNextLine() {
   return line.next();
 }