Remove classes merged into Converters.

This commit is contained in:
Jonathan Wood 2015-06-27 14:27:38 -07:00
parent bcc52f5cb0
commit 8b3652a309
4 changed files with 0 additions and 140 deletions

View file

@ -1,25 +0,0 @@
package com.moandjiezana.toml;
class BooleanValueWriter implements ValueWriter {
static final ValueWriter BOOLEAN_VALUE_WRITER = new BooleanValueWriter();
@Override
public boolean canWrite(Object value) {
return Boolean.class.isInstance(value);
}
@Override
public void write(Object value, WriterContext context) {
context.output.append(value.toString());
}
@Override
public boolean isPrimitiveType() {
return true;
}
@Override
public boolean isTable() {
return false;
}
}

View file

@ -1,34 +0,0 @@
package com.moandjiezana.toml;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
class DateValueWriter implements ValueWriter {
static final ValueWriter DATE_VALUE_WRITER = new DateValueWriter();
private static final Calendar calendar = new GregorianCalendar();
@Override
public boolean canWrite(Object value) {
return value instanceof Date;
}
@Override
public void write(Object value, WriterContext context) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:m:ss");
context.output.append(dateFormat.format(value));
int tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
context.output.append(String.format("%+03d:%02d", tzOffset / 60, tzOffset % 60));
}
@Override
public boolean isPrimitiveType() {
return true;
}
@Override
public boolean isTable() {
return false;
}
}

View file

@ -1,25 +0,0 @@
package com.moandjiezana.toml;
class NumberValueWriter implements ValueWriter {
static final ValueWriter NUMBER_VALUE_WRITER = new NumberValueWriter();
@Override
public boolean canWrite(Object value) {
return Number.class.isInstance(value);
}
@Override
public void write(Object value, WriterContext context) {
context.output.append(value.toString());
}
@Override
public boolean isPrimitiveType() {
return true;
}
@Override
public boolean isTable() {
return false;
}
}

View file

@ -1,56 +0,0 @@
package com.moandjiezana.toml;
class StringValueWriter implements ValueWriter {
static final ValueWriter STRING_VALUE_WRITER = new StringValueWriter();
static private final String[] specialCharacterEscapes = new String[93];
static {
specialCharacterEscapes[0x08] = "\\b";
specialCharacterEscapes[0x09] = "\\t";
specialCharacterEscapes[0x0A] = "\\n";
specialCharacterEscapes[0x0C] = "\\f";
specialCharacterEscapes[0x0D] = "\\r";
specialCharacterEscapes[0x22] = "\\\"";
specialCharacterEscapes[0x5C] = "\\";
}
@Override
public boolean canWrite(Object value) {
return value.getClass().isAssignableFrom(String.class);
}
@Override
public void write(Object value, WriterContext context) {
context.output.append('"');
escapeUnicode(value.toString(), context.output);
context.output.append('"');
}
@Override
public boolean isPrimitiveType() {
return true;
}
@Override
public boolean isTable() {
return false;
}
private void escapeUnicode(String in, StringBuilder out) {
for (int i = 0; i < in.length(); i++) {
int codePoint = in.codePointAt(i);
if (codePoint < specialCharacterEscapes.length && specialCharacterEscapes[codePoint] != null) {
out.append(specialCharacterEscapes[codePoint]);
} else if (codePoint > 0x1f && codePoint < 0x7f) {
out.append(Character.toChars(codePoint));
} else if (codePoint <= 0xFFFF) {
out.append(String.format("\\u%04X", codePoint));
} else {
out.append(String.format("\\U%08X", codePoint));
// Skip the low surrogate, which will be the next in the code point sequence.
i++;
}
}
}
}