@Test public void listRecommendZones() throws Exception { ZoneInfo z1 = service.createDefault("zone1", "Zone 1"); ZoneInfo z2 = service.createDefault("zone2", "Zone 2"); ZoneInfo z3 = service.createDefault("zone3", "No article zone"); ZoneInfo z4 = service.createDefault("zone4", "Zone 4"); Account account = savedAccountCitizen("foobar"); IntStream.rangeClosed(1, 10).forEach(i -> { savedArticle(z1, account, i + " z1 - title"); savedArticle(z2, account, i + " z2 - title"); savedArticle(z4, account, i + " z4 - title"); }); assertTrue(service.listRecommendZones().containsAll(asList(z1, z2, z3, z4))); }
@Override public List<ZoneInfo> listRecommendZones() { int recommendSize = 10; List<ZoneInfo> results = articleDao.listHotZonesWithCache(recommendSize, Instant.now().minus(Duration.ofHours(24))); if (results.size() >= recommendSize) { return results; } List<ZoneInfo> all = zoneDao.listOrderByName() .stream() .filter(zoneInfo -> !zoneInfo.isHideFromTop()) .collect(toList()); Collections.shuffle(all); return all.stream().limit(recommendSize).collect(toList()); }
ZoneServiceImpl implements ZoneService { @Override public List<ZoneInfo> listRecommendZones() { int recommendSize = 10; List<ZoneInfo> results = articleDao.listHotZonesWithCache(recommendSize, Instant.now().minus(Duration.ofHours(24))); if (results.size() >= recommendSize) { return results; } List<ZoneInfo> all = zoneDao.listOrderByName() .stream() .filter(zoneInfo -> !zoneInfo.isHideFromTop()) .collect(toList()); Collections.shuffle(all); return all.stream().limit(recommendSize).collect(toList()); } }
ZoneServiceImpl implements ZoneService { @Override public List<ZoneInfo> listRecommendZones() { int recommendSize = 10; List<ZoneInfo> results = articleDao.listHotZonesWithCache(recommendSize, Instant.now().minus(Duration.ofHours(24))); if (results.size() >= recommendSize) { return results; } List<ZoneInfo> all = zoneDao.listOrderByName() .stream() .filter(zoneInfo -> !zoneInfo.isHideFromTop()) .collect(toList()); Collections.shuffle(all); return all.stream().limit(recommendSize).collect(toList()); }  }
ZoneServiceImpl implements ZoneService { @Override public List<ZoneInfo> listRecommendZones() { int recommendSize = 10; List<ZoneInfo> results = articleDao.listHotZonesWithCache(recommendSize, Instant.now().minus(Duration.ofHours(24))); if (results.size() >= recommendSize) { return results; } List<ZoneInfo> all = zoneDao.listOrderByName() .stream() .filter(zoneInfo -> !zoneInfo.isHideFromTop()) .collect(toList()); Collections.shuffle(all); return all.stream().limit(recommendSize).collect(toList()); }  @Override ZoneInfo loadZone(Zone zone); @Override ZoneInfo createDefault(String zone, String aliasName); @Override ZoneInfo createKaif(String zone, String aliasName); @Override void updateTheme(Zone zone, String theme); @Override Map<String, List<ZoneInfo>> listZoneAtoZ(); @Override List<ZoneInfo> listRecommendZones(); @Override List<ZoneInfo> listCitizenZones(); @Override ZoneInfo createByUser(String zone, String aliasName, Authorization creator); @Override List<ZoneInfo> listAdministerZones(String username); @Override boolean isZoneAvailable(String zone); @Override boolean canCreateZone(Authorization authorization); @Override List<String> listAdministratorsWithCache(Zone zone); }
ZoneServiceImpl implements ZoneService { @Override public List<ZoneInfo> listRecommendZones() { int recommendSize = 10; List<ZoneInfo> results = articleDao.listHotZonesWithCache(recommendSize, Instant.now().minus(Duration.ofHours(24))); if (results.size() >= recommendSize) { return results; } List<ZoneInfo> all = zoneDao.listOrderByName() .stream() .filter(zoneInfo -> !zoneInfo.isHideFromTop()) .collect(toList()); Collections.shuffle(all); return all.stream().limit(recommendSize).collect(toList()); }  @Override ZoneInfo loadZone(Zone zone); @Override ZoneInfo createDefault(String zone, String aliasName); @Override ZoneInfo createKaif(String zone, String aliasName); @Override void updateTheme(Zone zone, String theme); @Override Map<String, List<ZoneInfo>> listZoneAtoZ(); @Override List<ZoneInfo> listRecommendZones(); @Override List<ZoneInfo> listCitizenZones(); @Override ZoneInfo createByUser(String zone, String aliasName, Authorization creator); @Override List<ZoneInfo> listAdministerZones(String username); @Override boolean isZoneAvailable(String zone); @Override boolean canCreateZone(Authorization authorization); @Override List<String> listAdministratorsWithCache(Zone zone);  }