You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2013/10/05 01:45:53 UTC
svn commit: r1529349 [4/44] - in /pivot/trunk:
charts/src/org/apache/pivot/charts/
charts/src/org/apache/pivot/charts/skin/ core/src/org/apache/pivot/beans/
core/src/org/apache/pivot/collections/
core/src/org/apache/pivot/collections/adapter/ core/src/...
Modified: pivot/trunk/core/src/org/apache/pivot/io/FileObjectList.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/io/FileObjectList.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/io/FileObjectList.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/io/FileObjectList.java Fri Oct 4 23:45:40 2013
@@ -22,11 +22,10 @@ import java.util.Comparator;
import org.apache.commons.vfs2.FileObject;
import org.apache.pivot.collections.adapter.ListAdapter;
-
/**
* Collection representing a list of files. Each entry in the list is unique;
- * i.e. a single file can't be added to the list more than once.
- * TODO: compute new serailVersionUIDs
+ * i.e. a single file can't be added to the list more than once. TODO: compute
+ * new serailVersionUIDs
*/
public class FileObjectList extends ListAdapter<FileObject> {
private static final long serialVersionUID = -6741822480264805279L;
Modified: pivot/trunk/core/src/org/apache/pivot/io/FileSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/io/FileSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/io/FileSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/io/FileSerializer.java Fri Oct 4 23:45:40 2013
@@ -31,8 +31,8 @@ import org.apache.pivot.serialization.Se
import org.apache.pivot.serialization.Serializer;
/**
- * Implementation of the {@link Serializer} interface that reads and
- * writes {@link java.io.File} objects.
+ * Implementation of the {@link Serializer} interface that reads and writes
+ * {@link java.io.File} objects.
*/
public class FileSerializer implements Serializer<File> {
private File tempFileDirectory;
@@ -42,23 +42,22 @@ public class FileSerializer implements S
private static final MimetypesFileTypeMap MIME_TYPES_FILE_MAP = new MimetypesFileTypeMap();
/**
- * Creates a new file serializer that will store temporary files in the default
- * temporary file directory.
+ * Creates a new file serializer that will store temporary files in the
+ * default temporary file directory.
*/
public FileSerializer() {
this(null);
}
/**
- * Creates a new file serializer that will store temporary files in a specific
- * directory.
- *
- * @param tempFileDirectory
- * The directory in which to store temporary folders.
+ * Creates a new file serializer that will store temporary files in a
+ * specific directory.
+ *
+ * @param tempFileDirectory The directory in which to store temporary
+ * folders.
*/
public FileSerializer(File tempFileDirectory) {
- if (tempFileDirectory != null
- && !tempFileDirectory.isDirectory()) {
+ if (tempFileDirectory != null && !tempFileDirectory.isDirectory()) {
throw new IllegalArgumentException();
}
@@ -66,8 +65,8 @@ public class FileSerializer implements S
}
/**
- * Reads a file from an input stream. The returned file is a temporary file and must be
- * deleted by the caller.
+ * Reads a file from an input stream. The returned file is a temporary file
+ * and must be deleted by the caller.
*/
@Override
public File readObject(InputStream inputStream) throws IOException, SerializationException {
@@ -77,7 +76,7 @@ public class FileSerializer implements S
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE);
for (int data = inputStream.read(); data != -1; data = inputStream.read()) {
- outputStream.write((byte)data);
+ outputStream.write((byte) data);
}
} finally {
if (outputStream != null) {
@@ -99,7 +98,7 @@ public class FileSerializer implements S
try {
inputStream = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
for (int data = inputStream.read(); data != -1; data = inputStream.read()) {
- outputStream.write((byte)data);
+ outputStream.write((byte) data);
}
} finally {
if (inputStream != null) {
Modified: pivot/trunk/core/src/org/apache/pivot/json/JSON.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSON.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSON.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSON.java Fri Oct 4 23:45:40 2013
@@ -25,51 +25,35 @@ import org.apache.pivot.collections.adap
/**
* Contains utility methods for working with JSON or JSON-like data structures.
- *
* <p> Special treatment is afforded to {@link java.util.Map java.util.Map} and
- * {@link org.apache.pivot.collections.Map org.apache.pivot.collections.Map} objects at any level
- * of the hierarchy. Otherwise a {@link BeanAdapter} is used to
- * fetch the value from the object.
- *
- * <p> If, however, the object at a given level is a
- * {@link org.apache.pivot.collections.Sequence} then the key
- * is assumed to be an integer index into the sequence.
- *
- * <p> Also, special consideration is given to an object that
- * implements the {@link Dictionary} interface.
- *
+ * {@link org.apache.pivot.collections.Map org.apache.pivot.collections.Map}
+ * objects at any level of the hierarchy. Otherwise a {@link BeanAdapter} is
+ * used to fetch the value from the object. <p> If, however, the object at a
+ * given level is a {@link org.apache.pivot.collections.Sequence} then the key
+ * is assumed to be an integer index into the sequence. <p> Also, special
+ * consideration is given to an object that implements the {@link Dictionary}
+ * interface.
*/
public class JSON {
/**
* Returns the value at a given path.
- *
- * @param root
- * The root object.
- *
- * @param path
- * The path to the value as a JavaScript path.
- *
- * @return
- * The value at the given path.
- *
+ *
+ * @param root The root object.
+ * @param path The path to the value as a JavaScript path.
+ * @return The value at the given path.
* @see #get(Object, Sequence)
*/
@SuppressWarnings("unchecked")
public static <T> T get(Object root, String path) {
- return (T)get(root, parse(path));
+ return (T) get(root, parse(path));
}
/**
* Returns the value at a given path.
- *
- * @param root
- * The root object.
- *
- * @param keys
- * The path to the value as a sequence of keys.
- *
- * @return
- * The value at the given path.
+ *
+ * @param root The root object.
+ * @param keys The path to the value as a sequence of keys.
+ * @return The value at the given path.
*/
@SuppressWarnings("unchecked")
public static <T> T get(Object root, Sequence<String> keys) {
@@ -86,22 +70,24 @@ public class JSON {
String key = keys.get(i);
- Map<String, T> adapter = (Map<String, T>) (value instanceof java.util.Map ? new MapAdapter<>((java.util.Map<String, T>) value) :
- (value instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) value): new BeanAdapter(value)));
+ Map<String, T> adapter = (Map<String, T>) (value instanceof java.util.Map ? new MapAdapter<>(
+ (java.util.Map<String, T>) value)
+ : (value instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) value)
+ : new BeanAdapter(value)));
if (adapter.containsKey(key)) {
value = adapter.get(key);
} else if (value instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)value;
+ Sequence<Object> sequence = (Sequence<Object>) value;
value = sequence.get(Integer.parseInt(key));
} else if (value instanceof Dictionary<?, ?>) {
- Dictionary<String, Object> dictionary = (Dictionary<String, Object>)value;
+ Dictionary<String, Object> dictionary = (Dictionary<String, Object>) value;
value = dictionary.get(key);
} else {
throw new IllegalArgumentException("Property \"" + key + "\" not found.");
}
}
- return (T)value;
+ return (T) value;
}
public static byte getByte(Object root, String path) {
@@ -136,13 +122,11 @@ public class JSON {
/**
* Sets the value at the given path.
- *
+ *
* @param root
* @param path
* @param value
- *
- * @return
- * The value previously associated with the path.
+ * @return The value previously associated with the path.
*/
@SuppressWarnings("unchecked")
public static <T> T put(Object root, String path, T value) {
@@ -161,33 +145,33 @@ public class JSON {
throw new IllegalArgumentException("Invalid path.");
}
- Map<String, T> adapter = (Map<String, T>) (parent instanceof java.util.Map ? new MapAdapter<>((java.util.Map<String, T>) parent) :
- (parent instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) parent): new BeanAdapter(parent)));
+ Map<String, T> adapter = (Map<String, T>) (parent instanceof java.util.Map ? new MapAdapter<>(
+ (java.util.Map<String, T>) parent)
+ : (parent instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) parent)
+ : new BeanAdapter(parent)));
Object previousValue;
if (adapter.containsKey(key)) {
previousValue = adapter.put(key, value);
} else if (parent instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)parent;
+ Sequence<Object> sequence = (Sequence<Object>) parent;
previousValue = sequence.update(Integer.parseInt(key), value);
} else if (parent instanceof Dictionary<?, ?>) {
- Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
+ Dictionary<String, Object> dictionary = (Dictionary<String, Object>) parent;
previousValue = dictionary.put(key, value);
} else {
throw new IllegalArgumentException("Property \"" + key + "\" not found.");
}
- return (T)previousValue;
+ return (T) previousValue;
}
/**
* Removes the value at the given path.
- *
+ *
* @param root
* @param path
- *
- * @return
- * The value that was removed.
+ * @return The value that was removed.
*/
@SuppressWarnings("unchecked")
public static <T> T remove(Object root, String path) {
@@ -208,26 +192,24 @@ public class JSON {
Object previousValue;
if (parent instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)parent;
+ Sequence<Object> sequence = (Sequence<Object>) parent;
previousValue = sequence.remove(Integer.parseInt(key), 1).get(0);
} else if (parent instanceof Dictionary<?, ?>) {
- Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
+ Dictionary<String, Object> dictionary = (Dictionary<String, Object>) parent;
previousValue = dictionary.remove(key);
} else {
throw new IllegalArgumentException("Property \"" + key + "\" not found.");
}
- return (T)previousValue;
+ return (T) previousValue;
}
/**
* Tests the existence of a path in a given object.
- *
+ *
* @param root
* @param path
- *
- * @return
- * <tt>true</tt> if the path exists; <tt>false</tt>, otherwise.
+ * @return <tt>true</tt> if the path exists; <tt>false</tt>, otherwise.
*/
@SuppressWarnings("unchecked")
public static <T> boolean containsKey(Object root, String path) {
@@ -247,16 +229,18 @@ public class JSON {
if (parent == null) {
containsKey = false;
} else {
- Map<String, T> adapter = (Map<String, T>) (parent instanceof java.util.Map ? new MapAdapter<>((java.util.Map<String, T>) parent) :
- (parent instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) parent): new BeanAdapter(parent)));
+ Map<String, T> adapter = (Map<String, T>) (parent instanceof java.util.Map ? new MapAdapter<>(
+ (java.util.Map<String, T>) parent)
+ : (parent instanceof org.apache.pivot.collections.Map ? ((org.apache.pivot.collections.Map<String, T>) parent)
+ : new BeanAdapter(parent)));
containsKey = adapter.containsKey(key);
if (!containsKey) {
if (parent instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)parent;
+ Sequence<Object> sequence = (Sequence<Object>) parent;
containsKey = (sequence.getLength() > Integer.parseInt(key));
} else if (parent instanceof Dictionary<?, ?>) {
- Dictionary<String, Object> dictionary = (Dictionary<String, Object>)parent;
+ Dictionary<String, Object> dictionary = (Dictionary<String, Object>) parent;
containsKey = dictionary.containsKey(key);
} else {
throw new IllegalArgumentException("Property \"" + key + "\" not found.");
@@ -269,7 +253,7 @@ public class JSON {
/**
* Parses a JSON path into a sequence of string keys.
- *
+ *
* @param path
*/
public static Sequence<String> parse(String path) {
@@ -288,22 +272,18 @@ public class JSON {
StringBuilder identifierBuilder = new StringBuilder();
boolean bracketed = (c == '[');
- if (bracketed
- && i < n) {
+ if (bracketed && i < n) {
c = path.charAt(i++);
char quote = Character.UNASSIGNED;
- boolean quoted = (c == '"'
- || c == '\'');
- if (quoted
- && i < n) {
+ boolean quoted = (c == '"' || c == '\'');
+ if (quoted && i < n) {
quote = c;
c = path.charAt(i++);
}
- while (i <= n
- && bracketed) {
+ while (i <= n && bracketed) {
bracketed = quoted || (c != ']');
if (bracketed) {
@@ -344,9 +324,7 @@ public class JSON {
}
}
} else {
- while(i <= n
- && c != '.'
- && c != '[') {
+ while (i <= n && c != '.' && c != '[') {
if (!Character.isJavaIdentifierPart(c)) {
throw new IllegalArgumentException("Illegal identifier character.");
}
@@ -365,8 +343,7 @@ public class JSON {
}
}
- if (c == '.'
- && i == n) {
+ if (c == '.' && i == n) {
throw new IllegalArgumentException("Path cannot end with a '.' character.");
}
Modified: pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java Fri Oct 4 23:45:40 2013
@@ -47,8 +47,8 @@ import org.apache.pivot.serialization.Se
import org.apache.pivot.util.ListenerList;
/**
- * Implementation of the {@link Serializer} interface that reads data from
- * and writes data to a JavaScript Object Notation (JSON) file.
+ * Implementation of the {@link Serializer} interface that reads data from and
+ * writes data to a JavaScript Object Notation (JSON) file.
*/
public class JSONSerializer implements Serializer<Object> {
private static class JSONSerializerListenerList extends ListenerList<JSONSerializerListener>
@@ -167,7 +167,8 @@ public class JSONSerializer implements S
}
/**
- * Returns the type of the object that will be returned by {@link #readObject(Reader)}.
+ * Returns the type of the object that will be returned by
+ * {@link #readObject(Reader)}.
*/
public Type getType() {
return type;
@@ -183,10 +184,9 @@ public class JSONSerializer implements S
/**
* Sets a flag indicating that map keys should always be quote-delimited.
- *
- * @param alwaysDelimitMapKeys
- * <tt>true</tt> to bound map keys in double quotes; <tt>false</tt> to
- * only quote-delimit keys as necessary.
+ *
+ * @param alwaysDelimitMapKeys <tt>true</tt> to bound map keys in double
+ * quotes; <tt>false</tt> to only quote-delimit keys as necessary.
*/
public void setAlwaysDelimitMapKeys(boolean alwaysDelimitMapKeys) {
this.alwaysDelimitMapKeys = alwaysDelimitMapKeys;
@@ -200,9 +200,9 @@ public class JSONSerializer implements S
}
/**
- * Sets the serializer's verbosity flag. When verbosity is enabled, all data read or
- * written will be echoed to the console.
- *
+ * Sets the serializer's verbosity flag. When verbosity is enabled, all data
+ * read or written will be echoed to the console.
+ *
* @param verbose
*/
public void setVerbose(boolean verbose) {
@@ -211,16 +211,13 @@ public class JSONSerializer implements S
/**
* Reads data from a JSON stream.
- *
- * @param inputStream
- * The input stream from which data will be read.
- *
+ *
+ * @param inputStream The input stream from which data will be read.
* @see #readObject(Reader)
*/
@SuppressWarnings("resource")
@Override
- public Object readObject(InputStream inputStream)
- throws IOException, SerializationException {
+ public Object readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
@@ -235,26 +232,16 @@ public class JSONSerializer implements S
/**
* Reads data from a JSON stream.
- *
- * @param reader
- * The reader from which data will be read.
- *
- * @return
- * One of the following types, depending on the content of the stream
- * and the value of {@link #getType()}:
- *
- * <ul>
- * <li>pivot.collections.Dictionary</li>
- * <li>pivot.collections.Sequence</li>
- * <li>java.lang.String</li>
- * <li>java.lang.Number</li>
- * <li>java.lang.Boolean</li>
- * <li><tt>null</tt></li>
- * <li>A JavaBean object</li>
- * </ul>
+ *
+ * @param reader The reader from which data will be read.
+ * @return One of the following types, depending on the content of the stream
+ * and the value of {@link #getType()}: <ul>
+ * <li>pivot.collections.Dictionary</li> <li>pivot.collections.Sequence</li>
+ * <li>java.lang.String</li> <li>java.lang.Number</li>
+ * <li>java.lang.Boolean</li> <li><tt>null</tt></li> <li>A JavaBean
+ * object</li> </ul>
*/
- public Object readObject(Reader reader)
- throws IOException, SerializationException {
+ public Object readObject(Reader reader) throws IOException, SerializationException {
if (reader == null) {
throw new IllegalArgumentException("reader is null.");
}
@@ -282,8 +269,8 @@ public class JSONSerializer implements S
return object;
}
- private Object readValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
Object object = null;
skipWhitespaceAndComments(reader);
@@ -311,11 +298,9 @@ public class JSONSerializer implements S
return object;
}
- private void skipWhitespaceAndComments(Reader reader)
- throws IOException, SerializationException {
- while (c != -1
- && (Character.isWhitespace(c)
- || c == '/')) {
+ private void skipWhitespaceAndComments(Reader reader) throws IOException,
+ SerializationException {
+ while (c != -1 && (Character.isWhitespace(c) || c == '/')) {
boolean comment = (c == '/');
// Read the next character
@@ -324,17 +309,14 @@ public class JSONSerializer implements S
if (comment) {
if (c == '/') {
// Single-line comment
- while (c != -1
- && c != '\n'
- && c != '\r') {
+ while (c != -1 && c != '\n' && c != '\r') {
c = reader.read();
}
} else if (c == '*') {
// Multi-line comment
boolean closed = false;
- while (c != -1
- && !closed) {
+ while (c != -1 && !closed) {
c = reader.read();
if (c == '*') {
@@ -357,8 +339,7 @@ public class JSONSerializer implements S
}
}
- private Object readNullValue(Reader reader)
- throws IOException, SerializationException {
+ private Object readNullValue(Reader reader) throws IOException, SerializationException {
String nullString = "null";
int n = nullString.length();
@@ -385,8 +366,7 @@ public class JSONSerializer implements S
return null;
}
- private String readString(Reader reader)
- throws IOException, SerializationException {
+ private String readString(Reader reader) throws IOException, SerializationException {
StringBuilder stringBuilder = new StringBuilder();
// Use the same delimiter to close the string
@@ -414,23 +394,20 @@ public class JSONSerializer implements S
StringBuilder unicodeBuilder = new StringBuilder();
while (unicodeBuilder.length() < 4) {
c = reader.read();
- unicodeBuilder.append((char)c);
+ unicodeBuilder.append((char) c);
}
String unicode = unicodeBuilder.toString();
- c = (char)Integer.parseInt(unicode, 16);
+ c = (char) Integer.parseInt(unicode, 16);
} else {
- if (!(c == '\\'
- || c == '/'
- || c == '\"'
- || c == '\''
- || c == t)) {
- throw new SerializationException("Unsupported escape sequence in input stream.");
+ if (!(c == '\\' || c == '/' || c == '\"' || c == '\'' || c == t)) {
+ throw new SerializationException(
+ "Unsupported escape sequence in input stream.");
}
}
}
- stringBuilder.append((char)c);
+ stringBuilder.append((char) c);
}
c = reader.read();
@@ -446,8 +423,8 @@ public class JSONSerializer implements S
return stringBuilder.toString();
}
- private Object readStringValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readStringValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
if (!(typeArgument instanceof Class<?>)) {
throw new SerializationException("Cannot convert string to " + typeArgument + ".");
}
@@ -459,11 +436,11 @@ public class JSONSerializer implements S
jsonSerializerListeners.readString(this, string);
}
- return BeanAdapter.coerce(string, (Class<?>)typeArgument);
+ return BeanAdapter.coerce(string, (Class<?>) typeArgument);
}
- private Object readNumberValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readNumberValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
if (!(typeArgument instanceof Class<?>)) {
throw new SerializationException("Cannot convert number to " + typeArgument + ".");
}
@@ -479,9 +456,8 @@ public class JSONSerializer implements S
c = reader.read();
}
- while (c != -1 && (Character.isDigit(c) || c == '.'
- || c == 'e' || c == 'E' || c == '-')) {
- stringBuilder.append((char)c);
+ while (c != -1 && (Character.isDigit(c) || c == '.' || c == 'e' || c == 'E' || c == '-')) {
+ stringBuilder.append((char) c);
integer &= !(c == '.');
c = reader.read();
}
@@ -489,11 +465,10 @@ public class JSONSerializer implements S
if (integer) {
long value = Long.parseLong(stringBuilder.toString()) * (negative ? -1 : 1);
- if (value > Integer.MAX_VALUE
- || value < Integer.MIN_VALUE) {
+ if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
number = value;
} else {
- number = (int)value;
+ number = (int) value;
}
} else {
number = Double.parseDouble(stringBuilder.toString()) * (negative ? -1.0d : 1.0d);
@@ -504,11 +479,11 @@ public class JSONSerializer implements S
jsonSerializerListeners.readNumber(this, number);
}
- return BeanAdapter.coerce(number, (Class<?>)typeArgument);
+ return BeanAdapter.coerce(number, (Class<?>) typeArgument);
}
- private Object readBooleanValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readBooleanValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
if (!(typeArgument instanceof Class<?>)) {
throw new SerializationException("Cannot convert boolean to " + typeArgument + ".");
}
@@ -538,12 +513,12 @@ public class JSONSerializer implements S
jsonSerializerListeners.readBoolean(this, value);
}
- return BeanAdapter.coerce(value, (Class<?>)typeArgument);
+ return BeanAdapter.coerce(value, (Class<?>) typeArgument);
}
@SuppressWarnings("unchecked")
- private Object readListValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readListValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
Sequence<Object> sequence = null;
Type itemType = null;
@@ -556,8 +531,8 @@ public class JSONSerializer implements S
Type parentType = typeArgument;
while (parentType != null) {
if (parentType instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)parentType;
- Class<?> rawType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) parentType;
+ Class<?> rawType = (Class<?>) parameterizedType.getRawType();
if (Sequence.class.isAssignableFrom(rawType)) {
itemType = parameterizedType.getActualTypeArguments()[0];
@@ -566,15 +541,15 @@ public class JSONSerializer implements S
break;
}
- Class<?> classType = (Class<?>)parentType;
+ Class<?> classType = (Class<?>) parentType;
Type[] genericInterfaces = classType.getGenericInterfaces();
for (int i = 0; i < genericInterfaces.length; i++) {
Type genericInterface = genericInterfaces[i];
if (genericInterface instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
- Class<?> interfaceType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
+ Class<?> interfaceType = (Class<?>) parameterizedType.getRawType();
if (Sequence.class.isAssignableFrom(interfaceType)) {
itemType = parameterizedType.getActualTypeArguments()[0];
@@ -602,14 +577,14 @@ public class JSONSerializer implements S
// Instantiate the sequence type
Class<?> sequenceType;
if (typeArgument instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)typeArgument;
- sequenceType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) typeArgument;
+ sequenceType = (Class<?>) parameterizedType.getRawType();
} else {
- sequenceType = (Class<?>)typeArgument;
+ sequenceType = (Class<?>) typeArgument;
}
try {
- sequence = (Sequence<Object>)sequenceType.newInstance();
+ sequence = (Sequence<Object>) sequenceType.newInstance();
} catch (InstantiationException exception) {
throw new RuntimeException(exception);
} catch (IllegalAccessException exception) {
@@ -654,8 +629,8 @@ public class JSONSerializer implements S
}
@SuppressWarnings("unchecked")
- private Object readMapValue(Reader reader, Type typeArgument)
- throws IOException, SerializationException {
+ private Object readMapValue(Reader reader, Type typeArgument) throws IOException,
+ SerializationException {
Dictionary<String, Object> dictionary = null;
Type valueType = null;
@@ -668,8 +643,8 @@ public class JSONSerializer implements S
Type parentType = typeArgument;
while (parentType != null) {
if (parentType instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)parentType;
- Class<?> rawType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) parentType;
+ Class<?> rawType = (Class<?>) parameterizedType.getRawType();
if (Dictionary.class.isAssignableFrom(rawType)) {
valueType = parameterizedType.getActualTypeArguments()[1];
@@ -678,15 +653,15 @@ public class JSONSerializer implements S
break;
}
- Class<?> classType = (Class<?>)parentType;
+ Class<?> classType = (Class<?>) parentType;
Type[] genericInterfaces = classType.getGenericInterfaces();
for (int i = 0; i < genericInterfaces.length; i++) {
Type genericInterface = genericInterfaces[i];
if (genericInterface instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
- Class<?> interfaceType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
+ Class<?> interfaceType = (Class<?>) parameterizedType.getRawType();
if (Dictionary.class.isAssignableFrom(interfaceType)) {
valueType = parameterizedType.getActualTypeArguments()[1];
@@ -709,7 +684,7 @@ public class JSONSerializer implements S
// Instantiate the dictionary or bean type
if (valueType == null) {
- Class<?> beanType = (Class<?>)typeArgument;
+ Class<?> beanType = (Class<?>) typeArgument;
try {
dictionary = new BeanAdapter(beanType.newInstance());
@@ -721,14 +696,14 @@ public class JSONSerializer implements S
} else {
Class<?> dictionaryType;
if (typeArgument instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)typeArgument;
- dictionaryType = (Class<?>)parameterizedType.getRawType();
+ ParameterizedType parameterizedType = (ParameterizedType) typeArgument;
+ dictionaryType = (Class<?>) parameterizedType.getRawType();
} else {
- dictionaryType = (Class<?>)typeArgument;
+ dictionaryType = (Class<?>) typeArgument;
}
try {
- dictionary = (Dictionary<String, Object>)dictionaryType.newInstance();
+ dictionary = (Dictionary<String, Object>) dictionaryType.newInstance();
} catch (InstantiationException exception) {
throw new RuntimeException(exception);
} catch (IllegalAccessException exception) {
@@ -761,13 +736,12 @@ public class JSONSerializer implements S
throw new SerializationException("Illegal identifier start character.");
}
- while (c != -1
- && c != ':' && !Character.isWhitespace(c)) {
+ while (c != -1 && c != ':' && !Character.isWhitespace(c)) {
if (!Character.isJavaIdentifierPart(c)) {
throw new SerializationException("Illegal identifier character.");
}
- keyBuilder.append((char)c);
+ keyBuilder.append((char) c);
c = reader.read();
}
@@ -778,8 +752,7 @@ public class JSONSerializer implements S
key = keyBuilder.toString();
}
- if (key == null
- || key.length() == 0) {
+ if (key == null || key.length() == 0) {
throw new SerializationException("\"" + key + "\" is not a valid key.");
}
@@ -798,8 +771,9 @@ public class JSONSerializer implements S
c = reader.read();
if (valueType == null) {
- // The map is a bean instance; get the generic type of the property
- Type genericValueType = ((BeanAdapter)dictionary).getGenericType(key);
+ // The map is a bean instance; get the generic type of the
+ // property
+ Type genericValueType = ((BeanAdapter) dictionary).getGenericType(key);
if (genericValueType != null) {
// Set the value in the bean
@@ -834,28 +808,27 @@ public class JSONSerializer implements S
jsonSerializerListeners.endDictionary(this);
}
- return (dictionary instanceof BeanAdapter) ? ((BeanAdapter)dictionary).getBean() : dictionary;
+ return (dictionary instanceof BeanAdapter) ? ((BeanAdapter) dictionary).getBean()
+ : dictionary;
}
/**
* Writes data to a JSON stream.
- *
+ *
* @param object
- *
- * @param outputStream
- * The output stream to which data will be written.
- *
+ * @param outputStream The output stream to which data will be written.
* @see #writeObject(Object, Writer)
*/
@SuppressWarnings("resource")
@Override
- public void writeObject(Object object, OutputStream outputStream)
- throws IOException, SerializationException {
+ public void writeObject(Object object, OutputStream outputStream) throws IOException,
+ SerializationException {
if (outputStream == null) {
throw new IllegalArgumentException("outputStream is null.");
}
- Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset), BUFFER_SIZE);
+ Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset),
+ BUFFER_SIZE);
if (verbose) {
writer = new EchoWriter(writer);
}
@@ -865,25 +838,17 @@ public class JSONSerializer implements S
/**
* Writes data to a JSON stream.
- *
- * @param object
- * The object to serialize. Must be one of the following types:
- *
- * <ul>
- * <li>pivot.collections.Map</li>
- * <li>pivot.collections.List</li>
- * <li>java.lang.String</li>
- * <li>java.lang.Number</li>
- * <li>java.lang.Boolean</li>
- * <li><tt>null</tt></li>
- * </ul>
- *
- * @param writer
- * The writer to which data will be written.
+ *
+ * @param object The object to serialize. Must be one of the following
+ * types: <ul> <li>pivot.collections.Map</li>
+ * <li>pivot.collections.List</li> <li>java.lang.String</li>
+ * <li>java.lang.Number</li> <li>java.lang.Boolean</li>
+ * <li><tt>null</tt></li> </ul>
+ * @param writer The writer to which data will be written.
*/
@SuppressWarnings("unchecked")
- public void writeObject(Object object, Writer writer)
- throws IOException, SerializationException {
+ public void writeObject(Object object, Writer writer) throws IOException,
+ SerializationException {
if (writer == null) {
throw new IllegalArgumentException("writer is null.");
}
@@ -891,13 +856,13 @@ public class JSONSerializer implements S
if (object == null) {
writer.append("null");
} else if (object instanceof String) {
- String string = (String)object;
+ String string = (String) object;
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0, n = string.length(); i < n; i++) {
char ci = string.charAt(i);
- switch(ci) {
+ switch (ci) {
case '\t': {
stringBuilder.append("\\t");
break;
@@ -916,12 +881,11 @@ public class JSONSerializer implements S
}
default: {
- if (charset.name().startsWith("UTF")
- || ci <= 0xFF) {
+ if (charset.name().startsWith("UTF") || ci <= 0xFF) {
stringBuilder.append(ci);
} else {
stringBuilder.append("\\u");
- stringBuilder.append(String.format("%04x", (short)ci));
+ stringBuilder.append(String.format("%04x", (short) ci));
}
}
}
@@ -930,18 +894,16 @@ public class JSONSerializer implements S
writer.append("\"" + stringBuilder.toString() + "\"");
} else if (object instanceof Number) {
- Number number = (Number)object;
+ Number number = (Number) object;
if (number instanceof Float) {
- Float f = (Float)number;
- if (f.isNaN()
- || f.isInfinite()) {
+ Float f = (Float) number;
+ if (f.isNaN() || f.isInfinite()) {
throw new SerializationException(number + " is not a valid value.");
}
} else if (number instanceof Double) {
- Double d = (Double)number;
- if (d.isNaN()
- || d.isInfinite()) {
+ Double d = (Double) number;
+ if (d.isNaN() || d.isInfinite()) {
throw new SerializationException(number + " is not a valid value.");
}
}
@@ -950,7 +912,7 @@ public class JSONSerializer implements S
} else if (object instanceof Boolean) {
writer.append(object.toString());
} else if (object instanceof List<?>) {
- List<Object> list = (List<Object>)object;
+ List<Object> list = (List<Object>) object;
writer.append("[");
int i = 0;
@@ -967,7 +929,7 @@ public class JSONSerializer implements S
} else {
Map<String, Object> map;
if (object instanceof Map<?, ?>) {
- map = (Map<String, Object>)object;
+ map = (Map<String, Object>) object;
} else {
map = new BeanAdapter(object, true);
}
@@ -1030,12 +992,9 @@ public class JSONSerializer implements S
/**
* Converts a JSON value to a Java object.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed object.
+ *
+ * @param json The JSON value.
+ * @return The parsed object.
*/
public static Object parse(String json) throws SerializationException {
JSONSerializer jsonSerializer = new JSONSerializer();
@@ -1043,7 +1002,7 @@ public class JSONSerializer implements S
Object object;
try {
object = jsonSerializer.readObject(new StringReader(json));
- } catch(IOException exception) {
+ } catch (IOException exception) {
throw new RuntimeException(exception);
}
@@ -1052,145 +1011,111 @@ public class JSONSerializer implements S
/**
* Converts a JSON value to a string.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed string.
+ *
+ * @param json The JSON value.
+ * @return The parsed string.
*/
public static String parseString(String json) throws SerializationException {
- return (String)parse(json);
+ return (String) parse(json);
}
/**
* Converts a JSON value to a number.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed number.
+ *
+ * @param json The JSON value.
+ * @return The parsed number.
*/
public static Number parseNumber(String json) throws SerializationException {
- return (Number)parse(json);
+ return (Number) parse(json);
}
/**
* Converts a JSON value to a short.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed short.
+ *
+ * @param json The JSON value.
+ * @return The parsed short.
*/
public static Short parseShort(String json) throws SerializationException {
- return (Short)parse(json);
+ return (Short) parse(json);
}
/**
* Converts a JSON value to a integer.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed integer.
+ *
+ * @param json The JSON value.
+ * @return The parsed integer.
*/
public static Integer parseInteger(String json) throws SerializationException {
- return (Integer)parse(json);
+ return (Integer) parse(json);
}
/**
* Converts a JSON value to a long.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed number.
+ *
+ * @param json The JSON value.
+ * @return The parsed number.
*/
public static Long parseLong(String json) throws SerializationException {
- return (Long)parse(json);
+ return (Long) parse(json);
}
/**
* Converts a JSON value to a float.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed float.
+ *
+ * @param json The JSON value.
+ * @return The parsed float.
*/
public static Float parseFloat(String json) throws SerializationException {
- return (Float)parse(json);
+ return (Float) parse(json);
}
/**
* Converts a JSON value to a double.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed double.
+ *
+ * @param json The JSON value.
+ * @return The parsed double.
*/
public static Double parseDouble(String json) throws SerializationException {
- return (Double)parse(json);
+ return (Double) parse(json);
}
/**
* Converts a JSON value to a boolean.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed boolean.
+ *
+ * @param json The JSON value.
+ * @return The parsed boolean.
*/
public static Boolean parseBoolean(String json) throws SerializationException {
- return (Boolean)parse(json);
+ return (Boolean) parse(json);
}
/**
* Converts a JSON value to a list.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed list.
+ *
+ * @param json The JSON value.
+ * @return The parsed list.
*/
public static List<?> parseList(String json) throws SerializationException {
- return (List<?>)parse(json);
+ return (List<?>) parse(json);
}
/**
* Converts a JSON value to a map.
- *
- * @param json
- * The JSON value.
- *
- * @return
- * The parsed map.
+ *
+ * @param json The JSON value.
+ * @return The parsed map.
*/
@SuppressWarnings("unchecked")
public static Map<String, ?> parseMap(String json) throws SerializationException {
- return (Map<String, ?>)parse(json);
+ return (Map<String, ?>) parse(json);
}
/**
- * Converts a object to a JSON string representation. The map keys will always
- * be quote-delimited.
- *
- * @param value
- * The object to convert.
- *
- * @return
- * The resulting JSON string.
- *
+ * Converts a object to a JSON string representation. The map keys will
+ * always be quote-delimited.
+ *
+ * @param value The object to convert.
+ * @return The resulting JSON string.
* @see #toString(Object, boolean)
*/
public static String toString(Object value) throws SerializationException {
@@ -1199,17 +1124,14 @@ public class JSONSerializer implements S
/**
* Converts a object to a JSON string representation.
- *
- * @param value
- * The object to convert.
- *
- * @param alwaysDelimitMapKeys
- * A flag indicating whether or not map keys will always be quote-delimited.
- *
- * @return
- * The resulting JSON string.
+ *
+ * @param value The object to convert.
+ * @param alwaysDelimitMapKeys A flag indicating whether or not map keys will
+ * always be quote-delimited.
+ * @return The resulting JSON string.
*/
- public static String toString(Object value, boolean alwaysDelimitMapKeys) throws SerializationException {
+ public static String toString(Object value, boolean alwaysDelimitMapKeys)
+ throws SerializationException {
JSONSerializer jsonSerializer = new JSONSerializer();
jsonSerializer.setAlwaysDelimitMapKeys(alwaysDelimitMapKeys);
@@ -1217,7 +1139,7 @@ public class JSONSerializer implements S
try {
jsonSerializer.writeObject(value, writer);
- } catch(IOException exception) {
+ } catch (IOException exception) {
throw new RuntimeException(exception);
}
Modified: pivot/trunk/core/src/org/apache/pivot/json/JSONSerializerListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSONSerializerListener.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSONSerializerListener.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSONSerializerListener.java Fri Oct 4 23:45:40 2013
@@ -75,7 +75,7 @@ public interface JSONSerializerListener
/**
* Called when the serializer has begun reading a dictionary value.
- *
+ *
* @param jsonSerializer
* @param value
*/
@@ -83,14 +83,14 @@ public interface JSONSerializerListener
/**
* Called when the serializer has finished reading a dictionary value.
- *
+ *
* @param jsonSerializer
*/
public void endDictionary(JSONSerializer jsonSerializer);
/**
* Called when the serializer has read a dictionary key.
- *
+ *
* @param jsonSerializer
* @param key
*/
@@ -98,7 +98,7 @@ public interface JSONSerializerListener
/**
* Called when the serializer has begun reading a sequence value.
- *
+ *
* @param jsonSerializer
* @param value
*/
@@ -106,14 +106,14 @@ public interface JSONSerializerListener
/**
* Called when the serializer has finished reading a sequence value.
- *
+ *
* @param jsonSerializer
*/
public void endSequence(JSONSerializer jsonSerializer);
/**
* Called when the serializer has read a string value.
- *
+ *
* @param jsonSerializer
* @param value
*/
@@ -121,7 +121,7 @@ public interface JSONSerializerListener
/**
* Called when the serializer has read a numeric value.
- *
+ *
* @param jsonSerializer
* @param value
*/
@@ -129,7 +129,7 @@ public interface JSONSerializerListener
/**
* Called when the serializer has read a boolean value.
- *
+ *
* @param jsonSerializer
* @param value
*/
@@ -137,7 +137,7 @@ public interface JSONSerializerListener
/**
* Called when the serializer has read a null value.
- *
+ *
* @param jsonSerializer
*/
public void readNull(JSONSerializer jsonSerializer);
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/BinarySerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/BinarySerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/BinarySerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/BinarySerializer.java Fri Oct 4 23:45:40 2013
@@ -23,9 +23,9 @@ import java.io.ObjectOutputStream;
import java.io.OutputStream;
/**
- * Implementation of the {@link Serializer} interface that uses Java's
- * internal serialization mechanism to read and write values. All values in the
- * object hierarchy are required to implement {@link java.io.Serializable}.
+ * Implementation of the {@link Serializer} interface that uses Java's internal
+ * serialization mechanism to read and write values. All values in the object
+ * hierarchy are required to implement {@link java.io.Serializable}.
*/
public class BinarySerializer implements Serializer<Object> {
public static final String MIME_TYPE = "application/x-java-serialized-object";
@@ -35,8 +35,7 @@ public class BinarySerializer implements
* Reads a graph of serialized objects from an input stream.
*/
@Override
- public Object readObject(InputStream inputStream) throws IOException,
- SerializationException {
+ public Object readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
@@ -46,7 +45,7 @@ public class BinarySerializer implements
try {
ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
object = objectInputStream.readObject();
- } catch(ClassNotFoundException exception) {
+ } catch (ClassNotFoundException exception) {
throw new SerializationException(exception);
}
@@ -57,8 +56,8 @@ public class BinarySerializer implements
* Writes a graph of serializable objects to an output stream.
*/
@Override
- public void writeObject(Object object, OutputStream outputStream)
- throws IOException, SerializationException {
+ public void writeObject(Object object, OutputStream outputStream) throws IOException,
+ SerializationException {
if (object == null) {
throw new IllegalArgumentException("object is null.");
}
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/ByteArraySerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/ByteArraySerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/ByteArraySerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/ByteArraySerializer.java Fri Oct 4 23:45:40 2013
@@ -26,7 +26,7 @@ import java.io.OutputStream;
/**
* Implementation of the {@link Serializer} interface that reads and writes a
* byte array.
- *
+ *
* @see Serializer
*/
public class ByteArraySerializer implements Serializer<byte[]> {
@@ -38,8 +38,7 @@ public class ByteArraySerializer impleme
* Reads a byte array from an input stream.
*/
@Override
- public byte[] readObject(InputStream inputStream) throws IOException,
- SerializationException {
+ public byte[] readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java Fri Oct 4 23:45:40 2013
@@ -42,8 +42,8 @@ import org.apache.pivot.io.EchoWriter;
import org.apache.pivot.util.ListenerList;
/**
- * Implementation of the {@link Serializer} interface that reads data from
- * and writes data to a comma-separated value (CSV) file.
+ * Implementation of the {@link Serializer} interface that reads data from and
+ * writes data to a comma-separated value (CSV) file.
*/
public class CSVSerializer implements Serializer<List<?>> {
private static class CSVSerializerListenerList extends ListenerList<CSVSerializerListener>
@@ -138,7 +138,7 @@ public class CSVSerializer implements Se
/**
* Sets the keys that will be read or written by this serializer.
- *
+ *
* @param keys
*/
public void setKeys(Sequence<String> keys) {
@@ -151,7 +151,7 @@ public class CSVSerializer implements Se
/**
* Sets the keys that will be read or written by this serializer.
- *
+ *
* @param keys
*/
public void setKeys(String... keys) {
@@ -171,10 +171,10 @@ public class CSVSerializer implements Se
/**
* Sets the serializer's write keys flag.
- *
- * @param writeKeys
- * If <tt>true</tt>, the first line of the output will contain the keys.
- * Otherwise, the first line will contain the first line of data.
+ *
+ * @param writeKeys If <tt>true</tt>, the first line of the output will
+ * contain the keys. Otherwise, the first line will contain the first line
+ * of data.
*/
public void setWriteKeys(boolean writeKeys) {
this.writeKeys = writeKeys;
@@ -188,9 +188,9 @@ public class CSVSerializer implements Se
}
/**
- * Sets the serializer's verbosity flag. When verbosity is enabled, all data read or
- * written will be echoed to the console.
- *
+ * Sets the serializer's verbosity flag. When verbosity is enabled, all data
+ * read or written will be echoed to the console.
+ *
* @param verbose
*/
public void setVerbose(boolean verbose) {
@@ -199,16 +199,13 @@ public class CSVSerializer implements Se
/**
* Reads values from a comma-separated value stream.
- *
- * @param inputStream
- * The input stream from which data will be read.
- *
+ *
+ * @param inputStream The input stream from which data will be read.
* @see #readObject(Reader)
*/
@SuppressWarnings("resource")
@Override
- public List<?> readObject(InputStream inputStream)
- throws IOException, SerializationException {
+ public List<?> readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
@@ -223,20 +220,15 @@ public class CSVSerializer implements Se
/**
* Reads values from a comma-separated value stream.
- *
- * @param reader
- * The reader from which data will be read.
- *
- * @return
- * A list containing the data read from the CSV file. The list items are
- * instances of Dictionary<String, Object> populated by mapping columns in
- * the CSV file to keys in the key sequence.
- * <p>
- * If no keys have been specified when this method is called, they are assumed
- * to be defined in the first line of the file.
+ *
+ * @param reader The reader from which data will be read.
+ * @return A list containing the data read from the CSV file. The list items
+ * are instances of Dictionary<String, Object> populated by mapping columns
+ * in the CSV file to keys in the key sequence. <p> If no keys have been
+ * specified when this method is called, they are assumed to be defined in
+ * the first line of the file.
*/
- public List<?> readObject(Reader reader)
- throws IOException, SerializationException {
+ public List<?> readObject(Reader reader) throws IOException, SerializationException {
if (reader == null) {
throw new IllegalArgumentException("reader is null.");
}
@@ -281,8 +273,7 @@ public class CSVSerializer implements Se
items.add(item);
// Move to next line
- while (c != -1
- && (c == '\r' || c == '\n')) {
+ while (c != -1 && (c == '\r' || c == '\n')) {
c = lineNumberReader.read();
}
@@ -306,8 +297,7 @@ public class CSVSerializer implements Se
}
@SuppressWarnings("unchecked")
- private Object readItem(Reader reader)
- throws IOException, SerializationException {
+ private Object readItem(Reader reader) throws IOException, SerializationException {
Object item = null;
if (c != -1) {
@@ -316,22 +306,22 @@ public class CSVSerializer implements Se
try {
if (itemType instanceof ParameterizedType) {
- ParameterizedType parameterizedItemType = (ParameterizedType)itemType;
- Class<?> rawItemType = (Class<?>)parameterizedItemType.getRawType();
+ ParameterizedType parameterizedItemType = (ParameterizedType) itemType;
+ Class<?> rawItemType = (Class<?>) parameterizedItemType.getRawType();
item = rawItemType.newInstance();
} else {
- Class<?> classItemType = (Class<?>)itemType;
+ Class<?> classItemType = (Class<?>) itemType;
item = classItemType.newInstance();
}
if (item instanceof Dictionary<?, ?>) {
- itemDictionary = (Dictionary<String, Object>)item;
+ itemDictionary = (Dictionary<String, Object>) item;
} else {
itemDictionary = new BeanAdapter(item);
}
- } catch(IllegalAccessException exception) {
+ } catch (IllegalAccessException exception) {
throw new SerializationException(exception);
- } catch(InstantiationException exception) {
+ } catch (InstantiationException exception) {
throw new SerializationException(exception);
}
@@ -340,8 +330,8 @@ public class CSVSerializer implements Se
String key = keys.get(i);
String value = readValue(reader);
if (value == null) {
- throw new SerializationException("Error reading value for "
- + key + " from input stream.");
+ throw new SerializationException("Error reading value for " + key
+ + " from input stream.");
}
if (c == '\r' || c == '\n') {
@@ -369,14 +359,12 @@ public class CSVSerializer implements Se
return item;
}
- private String readValue(Reader reader)
- throws IOException, SerializationException {
+ private String readValue(Reader reader) throws IOException, SerializationException {
String value = null;
// Read the next value from this line, returning null if there are
// no more values on the line
- if (c != -1
- && (c != '\r' && c != '\n')) {
+ if (c != -1 && (c != '\r' && c != '\n')) {
// Read the value
StringBuilder valueBuilder = new StringBuilder();
@@ -387,8 +375,7 @@ public class CSVSerializer implements Se
c = reader.read();
}
- while (c != -1
- && (quoted || (c != ',' && c != '\r' && c != '\n'))) {
+ while (c != -1 && (quoted || (c != ',' && c != '\r' && c != '\n'))) {
if (c == '"') {
if (!quoted) {
throw new SerializationException("Dangling quote.");
@@ -396,17 +383,15 @@ public class CSVSerializer implements Se
c = reader.read();
- if (c != '"'
- && (c != ',' && c != '\r' && c != '\n' && c != -1)) {
+ if (c != '"' && (c != ',' && c != '\r' && c != '\n' && c != -1)) {
throw new SerializationException("Prematurely terminated quote.");
}
quoted &= (c == '"');
}
- if (c != -1
- && (quoted || (c != ',' && c != '\r' && c != '\n'))) {
- valueBuilder.append((char)c);
+ if (c != -1 && (quoted || (c != ',' && c != '\r' && c != '\n'))) {
+ valueBuilder.append((char) c);
c = reader.read();
}
}
@@ -417,7 +402,8 @@ public class CSVSerializer implements Se
value = valueBuilder.toString();
- // Move to the next character after ',' (don't automatically advance to
+ // Move to the next character after ',' (don't automatically advance
+ // to
// the next line)
if (c == ',') {
c = reader.read();
@@ -434,18 +420,15 @@ public class CSVSerializer implements Se
/**
* Writes values to a comma-separated value stream.
- *
+ *
* @param items
- *
- * @param outputStream
- * The output stream to which data will be written.
- *
+ * @param outputStream The output stream to which data will be written.
* @see #writeObject(List, Writer)
*/
@SuppressWarnings("resource")
@Override
- public void writeObject(List<?> items, OutputStream outputStream)
- throws IOException, SerializationException {
+ public void writeObject(List<?> items, OutputStream outputStream) throws IOException,
+ SerializationException {
if (items == null) {
throw new IllegalArgumentException("items is null.");
}
@@ -454,7 +437,8 @@ public class CSVSerializer implements Se
throw new IllegalArgumentException("outputStream is null.");
}
- Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset), BUFFER_SIZE);
+ Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream, charset),
+ BUFFER_SIZE);
if (verbose) {
writer = new EchoWriter(writer);
}
@@ -464,15 +448,11 @@ public class CSVSerializer implements Se
/**
* Writes values to a comma-separated value stream.
- *
- * @param items
- * A list containing the data to write to the CSV
- * file. List items must be instances of Dictionary<String, Object>. The
- * dictionary values will be written out in the order specified by the
- * key sequence.
- *
- * @param writer
- * The writer to which data will be written.
+ *
+ * @param items A list containing the data to write to the CSV file. List
+ * items must be instances of Dictionary<String, Object>. The dictionary
+ * values will be written out in the order specified by the key sequence.
+ * @param writer The writer to which data will be written.
*/
@SuppressWarnings("unchecked")
public void writeObject(List<?> items, Writer writer) throws IOException {
@@ -500,7 +480,7 @@ public class CSVSerializer implements Se
for (Object item : items) {
Dictionary<String, Object> itemDictionary;
if (item instanceof Dictionary<?, ?>) {
- itemDictionary = (Dictionary<String, Object>)item;
+ itemDictionary = (Dictionary<String, Object>) item;
} else {
itemDictionary = new BeanAdapter(item);
}
@@ -517,10 +497,8 @@ public class CSVSerializer implements Se
if (value != null) {
String string = value.toString();
- if (string.indexOf(',') >= 0
- || string.indexOf('"') >= 0
- || string.indexOf('\r') >= 0
- || string.indexOf('\n') >= 0) {
+ if (string.indexOf(',') >= 0 || string.indexOf('"') >= 0
+ || string.indexOf('\r') >= 0 || string.indexOf('\n') >= 0) {
writer.append('"');
if (string.indexOf('"') == -1) {
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializerListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializerListener.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializerListener.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializerListener.java Fri Oct 4 23:45:40 2013
@@ -44,7 +44,7 @@ public interface CSVSerializerListener {
/**
* Called when the serializer has begun reading the list.
- *
+ *
* @param csvSerializer
* @param list
*/
@@ -52,14 +52,14 @@ public interface CSVSerializerListener {
/**
* Called when the serializer has finished reading the list.
- *
+ *
* @param csvSerializer
*/
public void endList(CSVSerializer csvSerializer);
/**
* Called when the serializer has read an item.
- *
+ *
* @param csvSerializer
* @param item
*/
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/PropertiesSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/PropertiesSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/PropertiesSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/PropertiesSerializer.java Fri Oct 4 23:45:40 2013
@@ -24,11 +24,9 @@ import java.util.Properties;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.adapter.MapAdapter;
-
/**
- * Implementation of the {@link Serializer} interface that reads data from
- * and writes data to the Java properties file format.
- *
+ * Implementation of the {@link Serializer} interface that reads data from and
+ * writes data to the Java properties file format.
*/
public class PropertiesSerializer implements Serializer<Map<?, ?>> {
public static final String PROPERTIES_EXTENSION = "properties";
@@ -36,17 +34,13 @@ public class PropertiesSerializer implem
/**
* Reads data from a properties stream.
- *
- * @param inputStream
- * The input stream from which data will be read.
- *
- * @return
- * An instance of {@link Map} containing the data read from the properties
- * file. Both keys and values are strings.
+ *
+ * @param inputStream The input stream from which data will be read.
+ * @return An instance of {@link Map} containing the data read from the
+ * properties file. Both keys and values are strings.
*/
@Override
- public Map<?, ?> readObject(InputStream inputStream) throws IOException,
- SerializationException {
+ public Map<?, ?> readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
@@ -59,14 +53,11 @@ public class PropertiesSerializer implem
/**
* Writes data to a properties stream.
- *
- * @param object
- * An instance of {@link Map} containing the data to be written to the
- * properties file. Keys must be strings, and values will be converted to
- * strings.
- *
- * @param outputStream
- * The output stream to which data will be written.
+ *
+ * @param object An instance of {@link Map} containing the data to be
+ * written to the properties file. Keys must be strings, and values will be
+ * converted to strings.
+ * @param outputStream The output stream to which data will be written.
*/
@SuppressWarnings("unchecked")
@Override
@@ -80,7 +71,7 @@ public class PropertiesSerializer implem
throw new IllegalArgumentException("outputStream is null.");
}
- Map<Object, Object> map = (Map<Object, Object>)object;
+ Map<Object, Object> map = (Map<Object, Object>) object;
Properties properties = new Properties();
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/Serializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/Serializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/Serializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/Serializer.java Fri Oct 4 23:45:40 2013
@@ -16,47 +16,40 @@
*/
package org.apache.pivot.serialization;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.IOException;
/**
* Defines an interface for writing objects to and reading objects from a data
* stream.
- *
- * @param <T>
- * The type of data being read and written.
+ *
+ * @param <T> The type of data being read and written.
*/
public interface Serializer<T> {
/**
* Reads an object from an input stream.
- *
- * @param inputStream
- * The data stream from which the object will be read.
- *
- * @return
- * The deserialized object.
+ *
+ * @param inputStream The data stream from which the object will be read.
+ * @return The deserialized object.
*/
public T readObject(InputStream inputStream) throws IOException, SerializationException;
/**
* Writes an object to an output stream.
- *
- * @param object
- * The object to serialize.
- *
- * @param outputStream
- * The data stream to which the object will be written.
+ *
+ * @param object The object to serialize.
+ * @param outputStream The data stream to which the object will be written.
*/
- public void writeObject(T object, OutputStream outputStream) throws IOException, SerializationException;
+ public void writeObject(T object, OutputStream outputStream) throws IOException,
+ SerializationException;
/**
* Returns the MIME type of the data read and written by this serializer.
- *
- * @param object
- * If provided, allows the serializer to attach parameters to the returned
- * MIME type containing more detailed information about the data. If
- * <tt>null</tt>, the base MIME type is returned.
+ *
+ * @param object If provided, allows the serializer to attach parameters to
+ * the returned MIME type containing more detailed information about the
+ * data. If <tt>null</tt>, the base MIME type is returned.
*/
public String getMIMEType(T object);
}
Modified: pivot/trunk/core/src/org/apache/pivot/serialization/StringSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/StringSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/StringSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/StringSerializer.java Fri Oct 4 23:45:40 2013
@@ -25,8 +25,8 @@ import java.io.OutputStream;
import java.nio.charset.Charset;
/**
- * Implementation of the {@link Serializer} interface that reads data from
- * and writes data to Java Strings.
+ * Implementation of the {@link Serializer} interface that reads data from and
+ * writes data to Java Strings.
*/
public class StringSerializer implements Serializer<String> {
private final Charset charset;
@@ -54,12 +54,10 @@ public class StringSerializer implements
/**
* Reads plain text data from an input stream.
- *
- * @param inputStream
- * The input stream from which data will be read.
- *
- * @return
- * An instance of {@link String} containing the text read from the input stream.
+ *
+ * @param inputStream The input stream from which data will be read.
+ * @return An instance of {@link String} containing the text read from the
+ * input stream.
*/
@Override
public String readObject(InputStream inputStream) throws IOException, SerializationException {
@@ -91,16 +89,13 @@ public class StringSerializer implements
/**
* Writes plain text data to an output stream.
- *
- * @param text
- * The text to be written to the output stream.
- *
- * @param outputStream
- * The output stream to which data will be written.
+ *
+ * @param text The text to be written to the output stream.
+ * @param outputStream The output stream to which data will be written.
*/
@Override
- public void writeObject(String text, OutputStream outputStream)
- throws IOException, SerializationException {
+ public void writeObject(String text, OutputStream outputStream) throws IOException,
+ SerializationException {
if (text == null) {
throw new IllegalArgumentException("text is null.");
}