本文整理汇总了Java中com.ivkos.wallhaven4j.models.wallpaper.Wallpaper类的典型用法代码示例。如果您正苦于以下问题:Java Wallpaper类的具体用法?Java Wallpaper怎么用?Java Wallpaper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Wallpaper类属于com.ivkos.wallhaven4j.models.wallpaper包,在下文中一共展示了Wallpaper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: post
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
public static void post() throws IOException {
Config.LOGGER.info("Connection to WallHaven, getting random wallpaper... ");
Wallpaper wallpaper;
do {
SearchQuery query = new SearchQueryBuilder()
.sorting(Sorting.RANDOM)
.purity(Purity.SFW)
.pages(1)
.build();
List<Wallpaper> wallpapers = WALLHAVEN.search(query);
wallpaper = wallpapers.get(RAND.nextInt(wallpapers.size()));
} while(!WallpaperManager.isValid(wallpaper));
Utils.downloadAndSaveImage(wallpaper.getImageUrl(), Storage.IMAGE_FILE);
Storage.addToHistory(wallpaper.getId());
StatusUpdate status = new StatusUpdate(wallpaper.getShortLink() + "\nResolution : " + wallpaper.getResolution().toString());
status.setMedia(Storage.IMAGE_FILE);
Config.LOGGER.info("Posting tweet...");
TwitterUtils.tweet(status);
Config.LOGGER.info("Tweet posted.");
}
示例2: getPage
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Override
public List<Wallpaper> getPage(long pageNumber, Map<String, String> queryParams)
{
checkArgument(pageNumber > 0, "page number must be greater than zero");
ImmutableMap<String, String> params = ImmutableMap.<String, String>builder()
.put("page", Long.toString(pageNumber))
.putAll(queryParams)
.build();
HttpResponse response = httpClient.get(getUrl(), ImmutableMap.of(
X_REQUESTED_WITH, "XMLHttpRequest",
CONTENT_TYPE, JSON_UTF_8.toString()
), params);
HtmlElement dom = htmlParser.parse(response.getBody());
List<HtmlElement> figureElements = dom.find("li > figure");
return unmodifiableList(transform(figureElements, thumbnailTransformer::transform));
}
示例3: searchWithQuery
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void searchWithQuery() throws Exception
{
List<Wallpaper> result1 = getWallhaven().search(new SearchQueryBuilder()
.keywords("cars")
.resolutions(new Resolution(1920, 1080))
.sorting(Sorting.VIEWS)
.order(Order.DESC)
.build()
);
assertFalse(result1.isEmpty());
List<Wallpaper> result2 = getWallhaven(true).search(new SearchQueryBuilder()
.sorting(Sorting.FAVORITES)
.order(Order.DESC)
.build()
);
assertFalse(result2.isEmpty());
}
示例4: isValid
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
public static boolean isValid(Wallpaper wallpaper) {
if(Utils.toList(Storage.getHistory()).contains(wallpaper.getId())) {
Config.LOGGER.info("Retrying... [Wallpaper already posted]");
return false;
}
if(!WallpaperManager.isAppropriateSize(wallpaper)) {
Config.LOGGER.info("Retrying... [Resolution : " + wallpaper.getResolution() + "]");
return false;
}
if(wallpaper.getViewsCount() < Config.MIN_VIEWS) {
Config.LOGGER.info("Retrying... [Views : " + wallpaper.getViewsCount() + "/" + Config.MIN_VIEWS + "]");
return false;
}
if(WallpaperManager.containsTag(wallpaper, "women") && wallpaper.getCategory().equals(Category.PEOPLE)) {
Config.LOGGER.info("Retrying... [Category : 'People', containing #women]");
return false;
}
if(WallpaperManager.containsTag(wallpaper, "car") && wallpaper.getCategory().equals(Category.GENERAL)) {
Config.LOGGER.info("Retrying... [Category : 'General', containing #car]");
return false;
}
return true;
}
示例5: isAppropriateSize
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
public static boolean isAppropriateSize(Wallpaper wallpaper) {
float width = wallpaper.getResolution().getWidth();
float height = wallpaper.getResolution().getHeight();
float ratio = width / height;
return width >= 1920 && height >= 1080 && ratio >= 1.6 && ratio <= 1.8;
}
示例6: search
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
/**
* Executes the search query and returns a list of wallpapers matching the query
*
* @param searchQuery the search query
* @return a list of wallpapers matching the query
* @throws NullPointerException if searchQuery is null
*/
public List<Wallpaper> search(SearchQuery searchQuery)
{
checkNotNull(searchQuery, "searchQuery must not be null");
return thumbnailPageCrawlerFactory
.create(UrlPrefixes.URL_SEARCH)
.getPageSequence(
searchQuery.getPages(),
searchQuery.getQueryParamsMap()
);
}
示例7: getFactoryFor
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <I, F extends ResourceFactory<R, I>, R extends AbstractResource<I>> F getFactoryFor(Class<R> resourceClass)
{
if (resourceClass == Tag.class) return (F) tagFactory;
if (resourceClass == TagCategory.class) return (F) tagCategoryFactory;
if (resourceClass == User.class) return (F) userFactory;
if (resourceClass == Wallpaper.class) return (F) wallpaperFactory;
if (resourceClass == WallpaperCollection.class) return (F) wallpaperCollectionFactory;
throw new IllegalArgumentException("There is no factory for the resource type " +
resourceClass.getSimpleName());
}
示例8: searchLatest
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void searchLatest() throws Exception
{
List<Wallpaper> result = getWallhaven().search(new SearchQueryBuilder()
.sorting(Sorting.DATE_ADDED)
.order(Order.DESC)
.build());
assertFalse(result.isEmpty());
}
示例9: searchPageWithQuery
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void searchPageWithQuery() throws Exception
{
SearchQuery query = new SearchQueryBuilder()
.keywords("minimal")
.categories(Category.GENERAL)
.ratios(new Ratio(9, 16))
.build();
List<Wallpaper> page2 = getWallhaven().search(query, 2);
assertFalse(page2.isEmpty());
}
示例10: inequalObjectsAreInequal
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void inequalObjectsAreInequal()
{
Tag tag1 = tagFactory.create(false, 1L, "somename", Purity.SFW);
Wallpaper wallpaper = wallpaperFactory.create(false, 1L);
assertFalse(tag1.equals(wallpaper));
assertFalse(tag1.hashCode() == wallpaper.hashCode());
}
示例11: toStringDefault
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void toStringDefault() throws Exception
{
Wallpaper wallpaper = wallpaperFactory.create(false, 42L);
assertEquals("42", wallpaper.toString());
}
示例12: toStringWithoutResourceType
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void toStringWithoutResourceType() throws Exception
{
Wallpaper wallpaper = wallpaperFactory.create(false, 42L);
assertEquals("42", wallpaper.toString(false));
}
示例13: toStringWithResourceType
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void toStringWithResourceType() throws Exception
{
Wallpaper wallpaper = wallpaperFactory.create(false, 42L);
assertEquals("Wallpaper 42", wallpaper.toString(true));
}
示例14: getWallpapers
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void getWallpapers() throws Exception
{
List<Wallpaper> wallpapers = wc.getWallpapers(3, Purity.SFW, Purity.SKETCHY, Purity.NSFW);
assertEquals(3 * 24, wallpapers.size());
}
示例15: supplyForClass
import com.ivkos.wallhaven4j.models.wallpaper.Wallpaper; //导入依赖的package包/类
@Test
public void supplyForClass() throws Exception
{
DescriptiveParseExceptionSupplier supplier = forResource(Wallpaper.class, "name");
assertEquals(ParseException.class, supplier.get().getClass());
assertEquals("Could not parse name of Wallpaper", supplier.get().getMessage());
}