/** {@inheritDoc} */
  protected PagingResult<Site> computeFavoriteSites(ListingContext listingContext) {
    List<Site> result = getFavoriteSites();

    if (listingContext != null) {
      Collections.sort(
          result,
          new AlphaComparator(listingContext.isSortAscending(), listingContext.getSortProperty()));
    }

    Boolean hasMoreItems = false;
    if (listingContext != null) {
      int fromIndex =
          (listingContext.getSkipCount() > result.size())
              ? result.size()
              : listingContext.getSkipCount();

      // Case if skipCount > result size
      if (listingContext.getSkipCount() < result.size()) {
        fromIndex = listingContext.getSkipCount();
      }

      // Case if skipCount > result size
      if (listingContext.getMaxItems() + fromIndex >= result.size()) {
        result = result.subList(fromIndex, result.size());
        hasMoreItems = false;
      } else {
        result = result.subList(fromIndex, listingContext.getMaxItems() + fromIndex);
        hasMoreItems = true;
      }
    }
    return new PagingResultImpl<Site>(result, hasMoreItems, result.size());
  }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  protected PagingResult<Site> computeSites(UrlBuilder url, ListingContext listingContext) {
    HttpUtils.Response resp = read(url, ErrorCodeRegistry.SITE_GENERIC);

    List<Object> json = JsonUtils.parseArray(resp.getStream(), resp.getCharset());
    int size = json.size();

    List<Site> result = new ArrayList<Site>();
    int fromIndex = 0, toIndex = size;
    Boolean hasMoreItems = false;

    // Define Listing Context
    if (listingContext != null) {
      fromIndex = (listingContext.getSkipCount() > size) ? size : listingContext.getSkipCount();

      // Case if skipCount > result size
      if (listingContext.getMaxItems() + fromIndex >= size) {
        toIndex = size;
        hasMoreItems = false;
      } else {
        toIndex = listingContext.getMaxItems() + fromIndex;
        hasMoreItems = true;
      }
    }

    String siteName = null;
    Map<String, Object> mapProperties = null;
    CacheSiteExtraProperties extraProperties = null;
    for (int i = fromIndex; i < toIndex; i++) {
      mapProperties = (Map<String, Object>) json.get(i);
      if (mapProperties != null) {
        siteName = JSONConverter.getString(mapProperties, OnPremiseConstant.SHORTNAME_VALUE);
        if (extraPropertiesCache.get(siteName) != null) {
          extraProperties = extraPropertiesCache.get(siteName);
          mapProperties.put(
              OnPremiseConstant.ISPENDINGMEMBER_VALUE, extraProperties.isPendingMember);
          mapProperties.put(OnPremiseConstant.ISMEMBER_VALUE, extraProperties.isMember);
          mapProperties.put(OnPremiseConstant.ISFAVORITE_VALUE, extraProperties.isFavorite);
        }
        result.add(SiteImpl.parseJson((Map<String, Object>) json.get(i)));
      }
    }

    if (listingContext != null) {
      Collections.sort(
          result,
          new AlphaComparator(listingContext.isSortAscending(), listingContext.getSortProperty()));
    }

    return new PagingResultImpl<Site>(result, hasMoreItems, size);
  }