Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Fixed 18:05 08.12.2014
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreosGhost committed Dec 8, 2014
1 parent b3f88c1 commit 9fe6eb1
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
import java.util.function.Predicate;

final class DBTableProvider implements AutoCloseableProvider {
public static final char ESCAPE_CHARACTER = '\\';
private static final char QUOTE_CHARACTER = '\"';
// public static final String QUOTED_STRING_REGEX =
// Utility.getQuotedStringRegex(QUOTE_CHARACTER + "", ESCAPE_CHARACTER + "" +
// ESCAPE_CHARACTER);

private static final Collection<Class<?>> SUPPORTED_TYPES = new ConvenientCollection<>(
new HashSet<Class<?>>()).addNext(Integer.class).addNext(Long.class).addNext(Byte.class)
.addNext(Double.class).addNext(Float.class).addNext(Boolean.class)
Expand Down Expand Up @@ -222,16 +219,6 @@ public Storeable deserialize(Table table, String value) throws ParseException {
Utility.checkNotNull(table, "Table");
Utility.checkNotNull(value, "Value");

// String partRegex = "null|true|false|-?[0-9]+(\\.[0-9]+)?";
// partRegex += "|" + QUOTED_STRING_REGEX;
// partRegex = "\\s*(" + partRegex + ")\\s*";
// String regex = "^\\s*\\[" + partRegex + "(," + partRegex + ")*" + "\\]\\s*$";
//
// if (!value.matches(regex)) {
// throw new ParseException(
// "wrong type (Does not match JSON simple list regular expression)", -1);
// }
//
int leftBound = value.indexOf('[');
int rightBound = value.lastIndexOf(']');

Expand Down Expand Up @@ -281,79 +268,6 @@ public Storeable deserialize(Table table, String value) throws ParseException {
}

return storeable;
// int currentColumn = 0;
//
// int index = leftBound + 1;
//
// for (; index < rightBound; ) {
// char currentChar = value.charAt(index);
//
// if (Character.isSpaceChar(currentChar)) {
// // Space that does not mean anything.
//
// index++;
// } else if (LIST_SEPARATOR_CHARACTER == currentChar) {
// // Next list element.
//
// currentColumn++;
// if (currentColumn >= columnsCount) {
// throw new ParseException(
// "wrong type (Too many elements in the list; expected: " +
// columnsCount + ")",
// index);
// }
// index++;
// } else {
// // Boolean, Number, Null, String.
//
// // End of element (exclusive).
// int elementEnd;
//
// if (QUOTE_CHARACTER == currentChar) {
// // As soon as the given value matches JSON format, closing quotes
// // are guaranteed to
// // have been found and no exception can be thrown here -> so format
// // 'wrong type(..
// // .)' support is not necessary here.
//
// elementEnd = Utility.findClosingQuotes(
// value, index + 1, rightBound, QUOTE_CHARACTER,
// ESCAPE_CHARACTER) + 1;
// } else {
// elementEnd = value.indexOf(LIST_SEPARATOR_CHARACTER, index + 1);
// if (elementEnd == -1) {
// elementEnd = rightBound;
// }
// }
//
// // Parsing the value.
// Object elementObj;
//
// String elementStr = value.substring(index, elementEnd).trim();
// if ("null".equals(elementStr)) {
// elementObj = null;
// } else {
// Class<?> elementClass = table.getColumnType(currentColumn);
// try {
// elementObj = PARSERS.get(elementClass).apply(elementStr);
// } catch (RuntimeException exc) {
// throw new ParseException(
// "wrong type (" + exc.getMessage() + ")", index);
// }
// }
//
// storeable.setColumnAt(currentColumn, elementObj);
// index = elementEnd;
// }
// }
//
// if (currentColumn + 1 != columnsCount) {
// throw new ParseException(
// "wrong type (Too few elements in the list; expected: " + columnsCount
// + ")", -1);
// }
//
// return storeable;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Not thread-safe.<br/>
* Not bound to any table.
*/
@JSONComplexObject(singleField = true)
@JSONComplexObject(wrapper = true)
public final class StoreableImpl implements Storeable {
@JSONField
private final Object[] values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private StoreableTableImpl(TableProvider provider,
this.provider = provider;
this.onTableClosedListener = onTableClosedListener;
this.store = store;
this.columnTypes = Collections.unmodifiableList(new ArrayList<Class<?>>(columnTypes));
this.columnTypes = Collections.unmodifiableList(new ArrayList<>(columnTypes));
}

static AutoCloseableTable createTable(TableProvider provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import java.lang.annotation.Target;

/**
* This annotation indicates that objects of the annotated type contain multiple JSON fields.
* This annotation indicates that objects of the annotated type contain JSON fields that need to be converted
* to json as parts of these objects.
* @author Phoenix
*/
@Target({ElementType.TYPE})
Expand All @@ -19,5 +20,5 @@
/**
* If true, this object will not be converted to JSON directly. Its single field will be taken instead.
*/
boolean singleField() default false;
boolean wrapper() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private static void appendJSONString(final StringBuilder sb,
if (annotatedFields.isEmpty()) {
throw new IllegalArgumentException(
"Illegal annotation @JSONComplexObject: there are no @JSONField annotated fields");
} else if (objClass.getAnnotation(JSONComplexObject.class).singleField()) {
} else if (objClass.getAnnotation(JSONComplexObject.class).wrapper()) {
if (annotatedFields.size() > 1) {
throw new IllegalArgumentException(
"Illegal annotation @JSONComplexObject: there are more then one @JSONField");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public String toString() {
}
}

@JSONComplexObject(singleField = true)
@JSONComplexObject(wrapper = true)
private static class MapObject implements JSONParsedObject {
@JSONField
private final Map<String, Object> map;
Expand Down Expand Up @@ -438,7 +438,7 @@ public String toString() {
}
}

@JSONComplexObject(singleField = true)
@JSONComplexObject(wrapper = true)
private static class ArrayObject implements JSONParsedObject {
@JSONField
private final Object[] array;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Log {
/**
* If logging is disabled, no messages are output
*/
private static boolean enableLogging = true;
private static boolean enableLogging = false;
/**
* Writer to the log file.
*/
Expand Down Expand Up @@ -61,13 +61,14 @@ public static synchronized void log(Class<?> logger, String message) {
}

public static synchronized void log(Class<?> logger, Throwable throwable, String message) {
if (writer == null) {
reopen();
if (enableLogging) {
if (writer == null) {
return;
reopen();
if (writer == null) {
return;
}
}
}
if (enableLogging) {

StringBuilder sb = new StringBuilder(message == null ? 100 : message.length() * 2);

boolean appendSpace = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,6 @@ public static <K, V> Map<V, K> inverseMap(Map<K, V> map) throws IllegalArgumentE
return inversed;
}

/**
* Forms a regular expression for a string inside quotes.
* @param quotes
* Sequence of symbols that plays role of quotes [regex-style].
* @param escapeSequence
* Inside quotes escapeSequence and quotes must occur only after escapeSequence [regex-style].
*/
public static String getQuotedStringRegex(String quotes, String escapeSequence) {
// Regex: "((plain text)|(escaped symbols))*"

return quotes + "([^" + quotes + escapeSequence + "]|(" + escapeSequence + escapeSequence + ")|("
+ escapeSequence + quotes + "))*" + quotes;
}

/**
* Returns string between two quotes. All quote and escape sequences inside the string are escaped by
* escape sequence.
Expand All @@ -253,10 +239,8 @@ public static String quoteString(String s, String quoteSequence, String escapeSe
if (s == null) {
return null;
}
s = s.replace(
escapeSequence, escapeSequence + escapeSequence);
s = s.replaceAll(
quoteSequence, escapeSequence + quoteSequence);
s = s.replace(escapeSequence, escapeSequence + escapeSequence);
s = s.replace(quoteSequence, escapeSequence + quoteSequence);
return quoteSequence + s + quoteSequence;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class UtilityTest {
private static final char QUOTE_CHARACTER = '"';
private static final char ESCAPE_CHARACTER = '\\';

private static final String QUOTED_STRING_REGEX =
Utility.getQuotedStringRegex(QUOTE_CHARACTER + "", ESCAPE_CHARACTER + "" + ESCAPE_CHARACTER);
@Rule
public ExpectedException exception = ExpectedException.none();

Expand Down Expand Up @@ -56,21 +54,6 @@ private static String[] supplyArray(String... strings) {
return strings;
}

@Test
public void testMatchQuotedStringRegex() {
assertFalse("\"/\"".matches(QUOTED_STRING_REGEX));
}

@Test
public void testMatchQuotedStringRegex1() {
assertTrue("\"//\"".matches(QUOTED_STRING_REGEX));
}

@Test
public void testMatchQuotedStringRegex2() {
assertFalse("\"//\"\"".matches(QUOTED_STRING_REGEX));
}

@Test
public void testSplitString() {
assertArrayEquals(
Expand Down Expand Up @@ -113,7 +96,7 @@ public void testSplitString4() {

@Test
public void testSplitString5() {
String part = quoteString("\"/ word \"/\"");
String part = quoteString("\"\\ word \"\\\"");
assertArrayEquals(
"Invalid string split",
supplyArray("create", "table", "(" + part + "," + "1,", "null", ")"),
Expand Down

0 comments on commit 9fe6eb1

Please sign in to comment.