- Timestamp:
- 2021-05-01T22:59:57+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r17757 r17847 849 849 */ 850 850 public static String gpxVal(OsmPrimitive prim, String key) { 851 return Optional.ofNullable(prim.get(GpxConstants.GPX_PREFIX + key)).orElse(prim.get(key)); 851 String val = prim.get(GpxConstants.GPX_PREFIX + key); 852 return val != null ? val : prim.get(key); 852 853 } 853 854 … … 874 875 // Position info 875 876 876 addDoubleIfPresent(wpt, n, GpxConstants.PT_ELE );877 addDoubleIfPresent(wpt, n, GpxConstants.PT_ELE, null); 877 878 878 879 try { … … 889 890 } 890 891 891 addDoubleIfPresent(wpt, n, GpxConstants.PT_MAGVAR );892 addDoubleIfPresent(wpt, n, GpxConstants.PT_GEOIDHEIGHT );892 addDoubleIfPresent(wpt, n, GpxConstants.PT_MAGVAR, null); 893 addDoubleIfPresent(wpt, n, GpxConstants.PT_GEOIDHEIGHT, null); 893 894 894 895 // Description info 895 896 896 addStringIfPresent(wpt, n, GpxConstants.GPX_NAME );897 addStringIfPresent(wpt, n, GpxConstants.GPX_DESC, "description" );898 addStringIfPresent(wpt, n, GpxConstants.GPX_CMT, "comment" );897 addStringIfPresent(wpt, n, GpxConstants.GPX_NAME, null, null); 898 addStringIfPresent(wpt, n, GpxConstants.GPX_DESC, "description", null); 899 addStringIfPresent(wpt, n, GpxConstants.GPX_CMT, "comment", null); 899 900 addStringIfPresent(wpt, n, GpxConstants.GPX_SRC, "source", "source:position"); 900 901 … … 906 907 wpt.put(GpxConstants.META_LINKS, links); 907 908 908 addStringIfPresent(wpt, n, GpxConstants.PT_SYM, "wpt_symbol" );909 addStringIfPresent(wpt, n, GpxConstants.PT_TYPE );909 addStringIfPresent(wpt, n, GpxConstants.PT_SYM, "wpt_symbol", null); 910 addStringIfPresent(wpt, n, GpxConstants.PT_TYPE, null, null); 910 911 911 912 // Accuracy info 912 addStringIfPresent(wpt, n, GpxConstants.PT_FIX, "gps:fix" );913 addStringIfPresent(wpt, n, GpxConstants.PT_FIX, "gps:fix", null); 913 914 addIntegerIfPresent(wpt, n, GpxConstants.PT_SAT, "gps:sat"); 914 915 addDoubleIfPresent(wpt, n, GpxConstants.PT_HDOP, "gps:hdop"); … … 933 934 } 934 935 935 private static void addIntegerIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) {936 List<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys));937 possibleKeys.add(0, gpxKey);938 for (String key : possibleKeys) {939 String value = gpxVal(p, key);940 941 942 943 944 936 private static void addIntegerIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String osmKey) { 937 String value = gpxVal(p, gpxKey); 938 if (value == null && osmKey != null) { 939 value = gpxVal(p, osmKey); 940 } 941 if (value != null) { 942 try { 943 int i = Integer.parseInt(value); 944 // Sanity checks 945 if ((!GpxConstants.PT_SAT.equals(gpxKey) || i >= 0) && 945 946 (!GpxConstants.PT_DGPSID.equals(gpxKey) || (0 <= i && i <= 1023))) { 946 wpt.put(gpxKey, value); 947 break; 948 } 949 } catch (NumberFormatException e) { 950 Logging.trace(e); 947 wpt.put(gpxKey, value); 951 948 } 952 } 953 } 954 } 955 956 private static void addDoubleIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String... osmKeys) { 957 List<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 958 possibleKeys.add(0, gpxKey); 959 for (String key : possibleKeys) { 960 String value = gpxVal(p, key); 961 if (value != null) { 962 try { 963 double d = Double.parseDouble(value); 964 // Sanity checks 965 if (!GpxConstants.PT_MAGVAR.equals(gpxKey) || (0.0 <= d && d < 360.0)) { 966 wpt.put(gpxKey, value); 967 break; 968 } 969 } catch (NumberFormatException e) { 970 Logging.trace(e); 949 } catch (NumberFormatException e) { 950 Logging.trace(e); 951 } 952 } 953 } 954 955 private static void addDoubleIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String osmKey) { 956 String value = gpxVal(p, gpxKey); 957 if (value == null && osmKey != null) { 958 value = gpxVal(p, osmKey); 959 } 960 if (value != null) { 961 try { 962 double d = Double.parseDouble(value); 963 // Sanity checks 964 if (!GpxConstants.PT_MAGVAR.equals(gpxKey) || (0.0 <= d && d < 360.0)) { 965 wpt.put(gpxKey, value); 971 966 } 972 } 973 } 974 } 975 976 private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String... osmKeys) { 977 Stream.concat(Stream.of(gpxKey), Arrays.stream(osmKeys)) 978 .map(key -> gpxVal(p, key)) 979 // Sanity checks 980 .filter(value -> value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) 981 .findFirst() 982 .ifPresent(value -> wpt.put(gpxKey, value)); 967 } catch (NumberFormatException e) { 968 Logging.trace(e); 969 } 970 } 971 } 972 973 private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String osmKey, String osmKey2) { 974 String value = gpxVal(p, gpxKey); 975 if (value == null && osmKey != null) { 976 value = gpxVal(p, osmKey); 977 } 978 if (value == null && osmKey2 != null) { 979 value = gpxVal(p, osmKey2); 980 } 981 // Sanity checks 982 if (value != null && (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value))) { 983 wpt.put(gpxKey, value); 984 } 983 985 } 984 986
Note:
See TracChangeset
for help on using the changeset viewer.