public static void testMergeLivemapStored() { final Geocache stored = new Geocache(); stored.setGeocode("GC12345"); stored.setDetailed(true); stored.setDisabled(true); stored.setType(CacheType.TRADITIONAL); stored.setCoords(new Geopoint(40.0, 8.0)); saveFreshCacheToDB(stored); final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setType(CacheType.MULTI, 12); livemap.setCoords(new Geopoint(41.0, 9.0), 12); livemap.gatherMissingFrom(stored); assertThat(livemap.isDetailed()).as("merged detailed").isTrue(); assertThat(livemap.isDisabled()).as("merged disabled").isTrue(); assertThat(livemap.getType()).as("merged type").isEqualTo(CacheType.TRADITIONAL); assertThat(livemap.getCoords()) .as("merged coordinates") .isEqualToComparingFieldByField(new Geopoint(40.0, 8.0)); assertThat(livemap.getCoordZoomLevel()) .as("merged zoomlevel") .isEqualTo(stored.getCoordZoomLevel()); }
public static void testMergeDownloadedStored() { final Geocache stored = new Geocache(); stored.setGeocode("GC12345"); stored.setDetailed(true); stored.setDisabled(true); stored.setType(CacheType.TRADITIONAL); stored.setCoords(new Geopoint(40.0, 8.0)); stored.setDescription("Test1"); stored.setAttributes(Collections.singletonList("TestAttribute")); stored.setShortDescription("Short"); stored.setHint("Hint"); saveFreshCacheToDB(stored); final Geocache download = new Geocache(); download.setGeocode("GC12345"); download.setDetailed(true); download.setDisabled(false); download.setType(CacheType.MULTI); download.setCoords(new Geopoint(41.0, 9.0)); download.setDescription("Test2"); download.setAttributes(Collections.<String>emptyList()); download.gatherMissingFrom(stored); assertThat(download.isDetailed()).as("merged detailed").isTrue(); assertThat(download.isDisabled()).as("merged disabled").isFalse(); assertThat(download.getType()).as("merged download").isEqualTo(CacheType.MULTI); assertThat(download.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(41.0, 9.0)); assertThat(download.getDescription()).as("merged description").isEqualTo("Test2"); assertThat(download.getShortDescription()).as("merged short description").isEmpty(); assertThat(download.getAttributes()).as("merged attributes").isEmpty(); assertThat(download.getHint()).as("merged hint").isEmpty(); }
public static void testMergeLivemap() { final Geocache previous = new Geocache(); previous.setGeocode("GC12345"); previous.setDetailed(true); previous.setDisabled(true); previous.setType(CacheType.TRADITIONAL); previous.setCoords(new Geopoint(40.0, 8.0)); removeCacheCompletely(previous.getGeocode()); final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setType(CacheType.MULTI, 12); livemap.setCoords(new Geopoint(41.0, 9.0), 12); livemap.gatherMissingFrom(previous); assertThat(livemap.isDetailed()).as("merged detailed").isTrue(); assertThat(livemap.isDisabled()).as("merged disabled").isTrue(); assertThat(livemap.getType()).as("merged type").isEqualTo(CacheType.TRADITIONAL); assertThat(livemap.getCoords()) .as("merged coordinates") .isEqualToComparingFieldByField(new Geopoint(40.0, 8.0)); assertThat(livemap.getCoordZoomLevel()) .as("merged zoomlevel") .isEqualTo(previous.getCoordZoomLevel()); }
/** * @param excludeDisabled * @param excludeMine * @param cacheType * @return */ public SearchResult filterSearchResults( final boolean excludeDisabled, final boolean excludeMine, final CacheType cacheType) { SearchResult result = new SearchResult(this); result.geocodes.clear(); final ArrayList<Geocache> includedCaches = new ArrayList<Geocache>(); final Set<Geocache> caches = DataStore.loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB); int excluded = 0; for (Geocache cache : caches) { // Is there any reason to exclude the cache from the list? final boolean excludeCache = (excludeDisabled && cache.isDisabled()) || (excludeMine && (cache.isOwner() || cache.isFound())) || (!cacheType.contains(cache)); if (excludeCache) { excluded++; } else { includedCaches.add(cache); } } result.addAndPutInCache(includedCaches); // decrease maximum number of caches by filtered ones result.setTotalCountGC(result.getTotalCountGC() - excluded); GCVote.loadRatings(includedCaches); return result; }