Advertisement
Guest User

Duplication

a guest
Dec 13th, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1.  public String insertCodeBlock(String newBlock) {
  2.         String text = textArea.getText();
  3.         int start = 0;
  4.         int count = 0;
  5.         String buildNewTextArea = "";
  6.         while (start >= 0) {
  7.             int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
  8.             if (nextLineStart == -1) {
  9.                 nextLineStart = text.length();
  10.             }
  11.             String[] temp = diffBlocks.get(indexOfLine).split(",");
  12.             int startLine = Integer.valueOf(temp[0]);
  13.             int endLine = (Integer.valueOf(temp[1]) - 1) + startLine;
  14.             if (count == startLine) {
  15.                 buildNewTextArea += newBlock;
  16.             } else if (count < startLine || count > (startLine + (endLine - startLine))) {
  17.                 buildNewTextArea += text.substring(start, nextLineStart);
  18.             }
  19.             count++;
  20.             start = text.indexOf(NEW_LINE, nextLineStart);
  21.         }
  22.         return buildNewTextArea;
  23.     }
  24.    
  25.     private int getLineIndex(int line) {
  26.         String text = textArea.getText();
  27.         int start = 0;
  28.         int count = 0;
  29.         String buildNewTextArea = "";
  30.         int index = 0;
  31.         while (start >= 0) {
  32.             int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
  33.             if (nextLineStart == -1) {
  34.                 nextLineStart = text.length();
  35.             }
  36.             if (count == line) {
  37.                 return index;
  38.             }
  39.             buildNewTextArea = text.substring(start, nextLineStart);
  40.             index += buildNewTextArea.length();
  41.             count++;
  42.             start = text.indexOf(NEW_LINE, nextLineStart);
  43.         }
  44.         return text.length();
  45.     }
  46.    
  47.    
  48.     public String getLineContent(int startLine, int endLine) {
  49.         String text = textArea.getText();
  50.         int start = 0;
  51.         int count = 0;
  52.         String buildNewTextArea = "";
  53.         while (start >= 0) {
  54.             int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.length());
  55.             if (nextLineStart == -1) {
  56.                 nextLineStart = text.length();
  57.             }
  58.             if (count >= startLine && count <= endLine) {
  59.                 buildNewTextArea += text.substring(start, nextLineStart);
  60.             }
  61.             count++;
  62.             start = text.indexOf(NEW_LINE, nextLineStart);
  63.         }
  64.         return buildNewTextArea;
  65.     }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement