Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 15, 2017
1 parent 91669be commit a8cda38
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
12 changes: 3 additions & 9 deletions jansi/src/main/java/org/fusesource/jansi/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Ansi {
private static final char FIRST_ESC_CHAR = 27;
private static final char SECOND_ESC_CHAR = '[';

public static enum Color {
public enum Color {
BLACK(0, "BLACK"),
RED(1, "RED"),
GREEN(2, "GREEN"),
Expand Down Expand Up @@ -74,9 +74,7 @@ public int bgBright() {
}
}

;

public static enum Attribute {
public enum Attribute {
RESET(0, "RESET"),
INTENSITY_BOLD(1, "INTENSITY_BOLD"),
INTENSITY_FAINT(2, "INTENSITY_FAINT"),
Expand Down Expand Up @@ -115,9 +113,7 @@ public int value() {

}

;

public static enum Erase {
public enum Erase {
FORWARD(0, "FORWARD"),
BACKWARD(1, "BACKWARD"),
ALL(2, "ALL");
Expand All @@ -140,8 +136,6 @@ public int value() {
}
}

;

public static final String DISABLE = Ansi.class.getName() + ".disable";

private static Callable<Boolean> detector = new Callable<Boolean>() {
Expand Down
14 changes: 7 additions & 7 deletions jansi/src/main/java/org/fusesource/jansi/AnsiOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AnsiOutputStream(OutputStream os) {
}

private final static int MAX_ESCAPE_SEQUENCE_LENGTH = 100;
private byte[] buffer = new byte[MAX_ESCAPE_SEQUENCE_LENGTH];
private final byte[] buffer = new byte[MAX_ESCAPE_SEQUENCE_LENGTH];
private int pos = 0;
private int startOfValue;
private final ArrayList<Object> options = new ArrayList<Object>();
Expand Down Expand Up @@ -104,9 +104,9 @@ public void write(int data) throws IOException {
} else if (';' == data) {
options.add(null);
} else if ('?' == data) {
options.add(new Character('?'));
options.add('?');
} else if ('=' == data) {
options.add(new Character('='));
options.add('=');
} else {
reset(processEscapeCommand(options, data));
}
Expand Down Expand Up @@ -224,7 +224,7 @@ private int getNextOptionInt(Iterator<Object> optionsIterator) throws IOExceptio
throw new IllegalArgumentException();
Object arg = optionsIterator.next();
if (arg != null)
return ((Integer)arg).intValue();
return (Integer) arg;
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ private boolean processEscapeCommand(ArrayList<Object> options, int command) thr
Object next = optionsIterator.next();
if (next != null) {
count++;
int value = ((Integer) next).intValue();
int value = (Integer) next;
if (30 <= value && value <= 37) {
processSetForegroundColor(value - 30);
} else if (40 <= value && value <= 47) {
Expand Down Expand Up @@ -552,7 +552,7 @@ private int optionInt(ArrayList<Object> options, int index) {
throw new IllegalArgumentException();
if (!value.getClass().equals(Integer.class))
throw new IllegalArgumentException();
return ((Integer) value).intValue();
return (Integer) value;
}

private int optionInt(ArrayList<Object> options, int index, int defaultValue) {
Expand All @@ -561,7 +561,7 @@ private int optionInt(ArrayList<Object> options, int index, int defaultValue) {
if (value == null) {
return defaultValue;
}
return ((Integer) value).intValue();
return (Integer) value;
}
return defaultValue;
}
Expand Down
26 changes: 14 additions & 12 deletions jansi/src/main/java/org/fusesource/jansi/AnsiRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,20 @@
* @since 1.1
*/
public class AnsiRenderer {
public static final String BEGIN_TOKEN = "@|";

private static final int BEGIN_TOKEN_LEN = 2;
public static final String BEGIN_TOKEN = "@|";

public static final String END_TOKEN = "|@";

private static final int END_TOKEN_LEN = 2;

public static final String CODE_TEXT_SEPARATOR = " ";

public static final String CODE_LIST_SEPARATOR = ",";

private AnsiRenderer() {
}
private static final int BEGIN_TOKEN_LEN = 2;

private static final int END_TOKEN_LEN = 2;

static public String render(final String input) throws IllegalArgumentException {
public static String render(final String input) throws IllegalArgumentException {
try {
return render(input, new StringBuilder()).toString();
} catch (IOException e) {
Expand All @@ -80,7 +78,7 @@ static public String render(final String input) throws IllegalArgumentException
* @throws IOException
* If an I/O error occurs
*/
static public Appendable render(final String input, Appendable target) throws IOException {
public static Appendable render(final String input, Appendable target) throws IOException {

int i = 0;
int j, k;
Expand Down Expand Up @@ -118,7 +116,7 @@ static public Appendable render(final String input, Appendable target) throws IO
}
}

static public String render(final String text, final String... codes) {
public static String render(final String text, final String... codes) {
Ansi ansi = Ansi.ansi();
for (String name : codes) {
Code code = Code.valueOf(name.toUpperCase(Locale.ENGLISH));
Expand All @@ -141,7 +139,7 @@ public static boolean test(final String text) {
return text != null && text.contains(BEGIN_TOKEN);
}

public static enum Code {
public enum Code {
//
// TODO: Find a better way to keep Code in sync with Color/Attribute/Erase
//
Expand Down Expand Up @@ -202,13 +200,13 @@ public static enum Code {
private final boolean background;

@SuppressWarnings("unchecked")
private Code(final Enum n, boolean background) {
Code(final Enum n, boolean background) {
this.n = n;
this.background = background;
}

@SuppressWarnings("unchecked")
private Code(final Enum n) {
Code(final Enum n) {
this(n, false);
}

Expand All @@ -232,4 +230,8 @@ public boolean isBackground() {
return background;
}
}

private AnsiRenderer() {
}

}
2 changes: 0 additions & 2 deletions jansi/src/main/java/org/fusesource/jansi/AnsiString.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.fusesource.jansi;

import org.fusesource.jansi.AnsiOutputStream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.ArrayList;
import java.util.List;

import org.fusesource.jansi.AnsiOutputStream;

/**
* @author <a href="http://code.dblock.org">Daniel Doubrovkine</a>
*/
Expand All @@ -47,7 +45,7 @@ public HtmlAnsiOutputStream(OutputStream os) {
super(os);
}

private List<String> closingAttributes = new ArrayList<String>();
private final List<String> closingAttributes = new ArrayList<String>();

private void write(String s) throws IOException {
super.out.write(s.getBytes());
Expand Down

0 comments on commit a8cda38

Please sign in to comment.