diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index c6303810ae..8f1bae7cbf 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -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 decodeCollection(String s) { + public static Set 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 collection) { - if (collection != null) { - Iterator it = collection.iterator(); + public static String encodeStringSet(Set 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(); } diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 4d9ca952c6..983d09fba6 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -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)) {