Ejemplo n.º 1
0
  private void assertWaypointsParsed(final String note, final int expectedWaypoints) {
    recordMapStoreFlags();

    try {
      setMapStoreFlags(false, false);

      final Geocache cache = new Geocache();
      final String geocode = "Test" + System.nanoTime();
      cache.setGeocode(geocode);
      cache.setWaypoints(new ArrayList<Waypoint>(), false);
      for (int i = 0; i < 2; i++) {
        cache.setPersonalNote(note);
        cache.parseWaypointsFromNote();
        final List<Waypoint> waypoints = cache.getWaypoints();
        assertThat(waypoints).isNotNull();
        assertThat(waypoints).hasSize(expectedWaypoints);
        final Waypoint waypoint = waypoints.get(0);
        assertThat(waypoint.getCoords()).isEqualTo(new Geopoint("N51 13.888 E007 03.444"));
        //            assertThat(waypoint.getNote()).isEqualTo("Test");
        assertThat(waypoint.getName())
            .isEqualTo(
                CgeoApplication.getInstance().getString(R.string.cache_personal_note) + " 1");
        cache.store(StoredList.TEMPORARY_LIST.id, null);
      }
      removeCacheCompletely(geocode);
    } finally {
      restoreMapStoreFlags();
    }
  }
Ejemplo n.º 2
0
 /**
  * Suffix the waypoint type with a running number to get a default name.
  *
  * @param type type to create a new default name for
  * @return
  */
 private String getDefaultWaypointName(final WaypointType type) {
   final ArrayList<String> wpNames = new ArrayList<>();
   for (final Waypoint waypoint : cache.getWaypoints()) {
     wpNames.add(waypoint.getName());
   }
   // try final and trailhead without index
   if (type == WaypointType.FINAL || type == WaypointType.TRAILHEAD) {
     if (!wpNames.contains(type.getL10n())) {
       return type.getL10n();
     }
   }
   // for other types add an index by default, which is highest found index + 1
   int max = 0;
   for (int i = 0; i < 30; i++) {
     if (wpNames.contains(type.getL10n() + " " + i)) {
       max = i;
     }
   }
   return type.getL10n() + " " + (max + 1);
 }