Skip to content

Instantly share code, notes, and snippets.

@chriswk
Created January 7, 2014 15:07
Show Gist options
  • Save chriswk/8300648 to your computer and use it in GitHub Desktop.
Save chriswk/8300648 to your computer and use it in GitHub Desktop.
private ImmutableList<IPoi> convertResultToPoisG(final String searchKey, final SearchServiceResult result) {
return FluentIterable
.from(result.getSearchResults().getResultItems())
.transform(new SearchResultToPoiBean(searchKey))
.filter(new MercatorFilter())
.transform(new Function<IadPoiBean, IPoi>() {
@Nullable
@Override
public IPoi apply(@Nullable IadPoiBean input) {
return input;
}
})
.toImmutableList();
}
private class SearchResultToPoiBean implements Function<ResultItem, IadPoiBean> {
private String searchKey;
private SearchResultToPoiBean(String key) {
this.searchKey = key;
}
public IadPoiBean apply(ResultItem resultItem) {
PoiType localType = poiConfig.getPoiTypeForSearchKey(searchKey);
if (resultItem.getFields().containsKey(PROJECT_FIELD_KEY)) {
localType = poiConfig.getPoiType(POI_TYPE_IAD_GROUP);
}
return new IadPoiBean(resultItem.getFields(), searchKey, Integer.valueOf(localType.getId()), localType);
}
}
private class MercatorFilter implements Predicate<IadPoiBean> {
@Override
public boolean apply(@Nullable IadPoiBean iPoi) {
return !(!iPoi.hasMercatorCoordinates() || Double.valueOf(0.0).equals(iPoi.getLat()) || Double.valueOf(0.0).equals(iPoi.getLng()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment