aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/CsvBuilder.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-08-05 14:41:53 +0500
committerAbyss777 <abyss@fox5.ru>2016-08-05 14:41:53 +0500
commit5a6e7582a7978341f3a2de9a81cb63252bca0bb7 (patch)
tree585eab11bfd805b9de814324e5e892e854fc1c62 /src/org/traccar/web/CsvBuilder.java
parent933247b3d2ec24d65203fae39dcafbe2c9afb87e (diff)
downloadtrackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.tar.gz
trackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.tar.bz2
trackermap-server-5a6e7582a7978341f3a2de9a81cb63252bca0bb7.zip
- Moved GeneralReport to separate file
- Removed unnecessary getOut function - Added methods sorting
Diffstat (limited to 'src/org/traccar/web/CsvBuilder.java')
-rw-r--r--src/org/traccar/web/CsvBuilder.java26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
index 3f93ee102..d45d12873 100644
--- a/src/org/traccar/web/CsvBuilder.java
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -3,10 +3,13 @@ package org.traccar.web;
import java.beans.Introspector;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Date;
import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
@@ -75,9 +78,21 @@ public class CsvBuilder {
addSeparator();
}
+ private SortedSet<Method> getSortedMethods(Object object) {
+ Method[] methodArray = object.getClass().getMethods();
+ SortedSet<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
+ @Override
+ public int compare(Method m1, Method m2) {
+ return m1.getName().compareTo(m2.getName());
+ }
+ });
+ methods.addAll(Arrays.asList(methodArray));
+ return methods;
+ }
+
public void addLine(Object object) {
- Method[] methods = object.getClass().getMethods();
+ SortedSet<Method> methods = getSortedMethods(object);
for (Method method : methods) {
if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
@@ -110,7 +125,8 @@ public class CsvBuilder {
}
public void addHeaderLine(Object object) {
- Method[] methods = object.getClass().getMethods();
+
+ SortedSet<Method> methods = getSortedMethods(object);
for (Method method : methods) {
if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
@@ -145,7 +161,7 @@ public class CsvBuilder {
}
}
- public byte[] get() {
- return String.valueOf(builder).getBytes(StandardCharsets.UTF_8);
+ public String get() {
+ return builder.toString();
}
}