Skip to content

Commit

Permalink
Added minor checks and javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
sangupta committed Sep 5, 2016
1 parent a6bd18d commit 2a1ed36
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions src/main/java/com/sangupta/jerry/io/IndentedStringWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,63 @@ public boolean hasContent() {
return this.builder.length() > 0;
}

/**
* Set the indent level to the given value. If the value is less
* than zero, an {@link IllegalArgumentException} is thrown.
*
* @param indentLevel the level to be seto
*/
public void setIndentLevel(int indentLevel) {
if(indentLevel < 0) {
throw new IllegalArgumentException("Indent level cannot be less than zero");
}

this.indentLevel = indentLevel;

if(this.builder.length() == 0) {
return;
}

this.newLine();
if(this.currentPointer > 0) {
this.newLine();
}
}

/**
* Increment the indent by one.
*
*/
public void incrementIndent() {
this.indentLevel++;
this.newLine();

if(this.currentPointer > 0) {
this.newLine();
}
}

/**
* Decrement the indent by one. If the indentation level is
* already at zero, this method will not change anything.
*
*/
public void decrementIndent() {
if(this.indentLevel == 0) {
return;
}

this.indentLevel--;
this.newLine();

if(this.currentPointer > 0) {
this.newLine();
}
}

/**
* Write the given character to the underlying writer.
*
* @param ch the character to be written.
*
*/
public void write(char ch) {
this.write(String.valueOf(ch));
}
Expand Down Expand Up @@ -213,10 +250,6 @@ public void writeLine(String str) {
public void newLine() {
this.builder.append('\n');
this.currentPointer = 0;

if(this.indentLevel == 0) {
return;
}
}

private void addIndentation() {
Expand Down

0 comments on commit 2a1ed36

Please sign in to comment.