/** * @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; }
/** * Copy a search result, for example to apply different filters on it. * * @param searchResult the original search result, which cannot be null */ public SearchResult(final SearchResult searchResult) { geocodes = new HashSet<String>(searchResult.geocodes); filteredGeocodes = new HashSet<String>(searchResult.filteredGeocodes); error = searchResult.error; url = searchResult.url; viewstates = searchResult.viewstates; setTotalCountGC(searchResult.getTotalCountGC()); }
public void addSearchResult(SearchResult other) { if (other == null) { return; } addGeocodes(other.geocodes); addFilteredGeocodes(other.filteredGeocodes); if (StringUtils.isBlank(url)) { url = other.url; } // copy the GC total search results number to be able to use "More caches" button if (getTotalCountGC() == 0 && other.getTotalCountGC() != 0) { setViewstates(other.getViewstates()); setTotalCountGC(other.getTotalCountGC()); } }
public SearchResult(final Parcel in) { final ArrayList<String> list = new ArrayList<String>(); in.readStringList(list); geocodes = new HashSet<String>(list); final ArrayList<String> filteredList = new ArrayList<String>(); in.readStringList(filteredList); filteredGeocodes = new HashSet<String>(filteredList); error = (StatusCode) in.readSerializable(); url = in.readString(); final int length = in.readInt(); if (length >= 0) { viewstates = new String[length]; in.readStringArray(viewstates); } setTotalCountGC(in.readInt()); }