use of de.herrlock.manga.index.entity.HosterList in project Manga by herrlock.
the class Indexer method createIndex.
public static Index createIndex(final IndexerConfiguration conf) {
logger.traceEntry("({})", conf);
Iterable<Hoster> values;
if (conf.getUrl() == null) {
values = Hosters.values();
} else {
values = ImmutableSet.of(Hosters.tryGetHostByURL(conf.getUrl()));
}
Collection<HosterList> hosterEntries = new TreeSet<>(HosterList.HOSTER_NAME_COMPARATOR);
for (Hoster hoster : values) {
HosterList indexFor = createIndexFor(hoster, conf);
hosterEntries.add(indexFor);
}
Index index = new Index();
index.setHosters(hosterEntries);
return index;
}
use of de.herrlock.manga.index.entity.HosterList in project Manga by herrlock.
the class Indexer method createJsonIndex.
public static JsonArray createJsonIndex(final IndexerConfiguration conf) {
Index index = createIndex(conf);
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
for (HosterList hosterList : index.getHosters()) {
for (HosterListEntry hosterListEntry : hosterList.getMangas()) {
arrayBuilder.add(//
Json.createObjectBuilder().add("hosterName", //
hosterList.getHosterName()).add("name", //
hosterListEntry.getName()).add("url", hosterListEntry.getUrl()));
}
}
return arrayBuilder.build();
}
use of de.herrlock.manga.index.entity.HosterList in project Manga by herrlock.
the class Indexer method createIndexFor.
private static HosterList createIndexFor(final Hoster hoster, final IndexerConfiguration conf) {
logger.traceEntry("({})", hoster);
Collection<HosterListEntry> elements = hoster.getAvailabile(conf);
Collection<HosterListEntry> mangas = new TreeSet<>(HosterListEntry.NAME_COMPARATOR);
mangas.addAll(elements);
// select random elements from the list
// final int AMOUNT = 10;
// final java.util.Random random = new java.util.Random(
// Long.parseLong( new java.text.SimpleDateFormat( "yyMMdd" ).format( new java.util.Date() ) ) );
// for ( int i = 0; i < Math.min( elements.size(), AMOUNT ); i++ ) {
// int rnd = random.nextInt( elements.size() );
// HosterListEntry entry = com.google.common.collect.Iterables.get( elements, rnd );
// mangas.add( entry );
// }
HosterList hosterList = new HosterList();
hosterList.setHosterName(hoster.getName());
hosterList.setMangas(mangas);
return hosterList;
}
Aggregations