Make methods for encoding to string and decoding from string for sets, not collections
This commit is contained in:
parent
254014728b
commit
c2489ff440
2 changed files with 13 additions and 17 deletions
|
@ -20,11 +20,12 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -177,22 +178,18 @@ public class Algorithms {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static List<String> decodeCollection(String s) {
|
||||
public static Set<String> decodeStringSet(String s) {
|
||||
if (isEmpty(s)) {
|
||||
return Collections.emptyList();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return Arrays.asList(s.split(CHAR_TOSPLIT + ""));
|
||||
return new HashSet<>(Arrays.asList(s.split(CHAR_TOSPLIT + "")));
|
||||
}
|
||||
|
||||
public static String encodeCollection(Collection<String> collection) {
|
||||
if (collection != null) {
|
||||
Iterator<String> it = collection.iterator();
|
||||
public static String encodeStringSet(Set<String> set) {
|
||||
if (set != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (it.hasNext()) {
|
||||
sb.append(it.next());
|
||||
if (it.hasNext()) {
|
||||
sb.append(CHAR_TOSPLIT);
|
||||
}
|
||||
for (String s : set) {
|
||||
sb.append(s).append(CHAR_TOSPLIT);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class GPXDatabase {
|
||||
|
@ -273,7 +272,7 @@ public class GPXDatabase {
|
|||
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
|
||||
GPX_COL_WPT_CATEGORY_NAMES + " = ? " +
|
||||
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
|
||||
new Object[] { Algorithms.encodeCollection(gpxFile.getWaypointCategories(true)), fileName, fileDir });
|
||||
new Object[] { Algorithms.encodeStringSet(gpxFile.getWaypointCategories(true)), fileName, fileDir });
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
|
@ -425,7 +424,7 @@ public class GPXDatabase {
|
|||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
||||
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
||||
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
|
||||
Algorithms.encodeCollection(item.analysis.wptCategoryNames)});
|
||||
Algorithms.encodeStringSet(item.analysis.wptCategoryNames)});
|
||||
} else {
|
||||
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
|
||||
GPX_COL_NAME + ", " +
|
||||
|
@ -470,7 +469,7 @@ public class GPXDatabase {
|
|||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp,
|
||||
a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation,
|
||||
a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, item.file.lastModified(),
|
||||
Algorithms.encodeCollection(a.wptCategoryNames), fileName, fileDir });
|
||||
Algorithms.encodeStringSet(a.wptCategoryNames), fileName, fileDir });
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
|
@ -523,7 +522,7 @@ public class GPXDatabase {
|
|||
a.avgSpeed = avgSpeed;
|
||||
a.points = points;
|
||||
a.wptPoints = wptPoints;
|
||||
a.wptCategoryNames = new HashSet<>(Algorithms.decodeCollection(wptCategoryNames));
|
||||
a.wptCategoryNames = Algorithms.decodeStringSet(wptCategoryNames);
|
||||
|
||||
File dir;
|
||||
if (!Algorithms.isEmpty(fileDir)) {
|
||||
|
|
Loading…
Reference in a new issue