1 32 33 package com.jeantessier.diff; 34 35 public abstract class Printer extends VisitorBase { 36 private StringBuffer buffer = new StringBuffer (); 37 38 private String indentText = " "; 39 private int indentLevel = 0; 40 41 public String getIndentText() { 42 return indentText; 43 } 44 45 public void setIndentText(String indentText) { 46 this.indentText = indentText; 47 } 48 49 protected Printer append(boolean b) { 50 buffer.append(b); 51 return this; 52 } 53 54 protected Printer append(char c) { 55 buffer.append(c); 56 return this; 57 } 58 59 protected Printer append(char[] str) { 60 buffer.append(str); 61 return this; 62 } 63 64 protected Printer append(char[] str, int offset, int len) { 65 buffer.append(str, offset, len); 66 return this; 67 } 68 69 protected Printer append(double d) { 70 buffer.append(d); 71 return this; 72 } 73 74 protected Printer append(float f) { 75 buffer.append(f); 76 return this; 77 } 78 79 protected Printer append(int i) { 80 buffer.append(i); 81 return this; 82 } 83 84 protected Printer append(long l) { 85 buffer.append(l); 86 return this; 87 } 88 89 protected Printer append(Object obj) { 90 buffer.append(obj); 91 return this; 92 } 93 94 protected Printer append(String str) { 95 buffer.append(str); 96 return this; 97 } 98 99 protected Printer indent() { 100 for (int i=0; i<indentLevel; i++) { 101 append(getIndentText()); 102 } 103 104 return this; 105 } 106 107 protected Printer eol() { 108 return append(System.getProperty("line.separator", "\n")); 109 } 110 111 protected void raiseIndent() { 112 indentLevel++; 113 } 114 115 protected void lowerIndent() { 116 indentLevel--; 117 } 118 119 public String toString() { 120 return buffer.toString(); 121 } 122 } 123 | Popular Tags |