本文整理汇总了Java中com.flickr4java.flickr.photos.PhotoList.size方法的典型用法代码示例。如果您正苦于以下问题:Java PhotoList.size方法的具体用法?Java PhotoList.size怎么用?Java PhotoList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.flickr4java.flickr.photos.PhotoList
的用法示例。
在下文中一共展示了PhotoList.size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: download
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
protected void download(Flickr flickr, Element setXml) throws IOException, SAXException, FlickrException {
int pageNum = 1;
int retrievedPhotos = 0;
int totalPhotos = 0;
do {
PhotoList photos = flickr.getPhotosetsInterface().getPhotos(getSetId(), 500, pageNum++);
totalPhotos = photos.getTotal();
for (int i = 0; i < photos.size(); i++) {
retrievedPhotos++;
Photo photo = (Photo) photos.get(i);
Logger.getLogger(Set.class).info("Processing photo " + retrievedPhotos + " of " + totalPhotos + ": " + photo.getUrl());
processPhoto(photo, flickr, setXml);
}
} while (retrievedPhotos < totalPhotos);
}
示例2: doSearch
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
protected SearchResults<Photo> doSearch(SectionInfo info, FlickrSearchEvent searchEvent)
{
// Remove any selections on new search
results.setSelectedStringValues(info, null);
SimpleSearchResults<Photo> searchResults = null;
try
{
PhotoList<Photo> photoList = invokeService(info, searchEvent);
int queryTotal = 0, photoListSize = 0;
if( photoList != null )
{
photoListSize = photoList.size();
queryTotal = photoList.getTotal();
searchResults = new SimpleSearchResults<Photo>(photoList, photoListSize, searchEvent.getOffset(),
queryTotal);
}
}
catch( FlickrException e )
{
searchResults = new SimpleSearchResults<Photo>(null, 0, 0, 0);
String errorMessage = e.getMessage();
searchResults.setErrorMessage(CurrentLocale.get(SEARCH_ERROR));
LOGGER.error(errorMessage);
}
return searchResults;
}
示例3: createFromGallery
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
/**
* Create an image dataset from a flickr gallery with the specified
* parameters. The number of images can be limited to a subset.
*
* @param reader
* the reader with which to load the images
* @param token
* the flickr api authentication token
* @param galleryId
* the Flickr gallery ID
* @param number
* the maximum number of images to add to the dataset. Setting to
* 0 or less will attempt to use all the images.
* @return a {@link FlickrImageDataset} created from the gallery described
* by the given parameters
* @throws Exception
* if an error occurs
*/
public static <IMAGE extends Image<?, IMAGE>> FlickrImageDataset<IMAGE> createFromGallery(
InputStreamObjectReader<IMAGE> reader,
FlickrAPIToken token,
String galleryId, int number) throws Exception
{
final Flickr flickr = makeFlickr(token);
List<Photo> photos = new ArrayList<Photo>();
final PhotoList<Photo> first = flickr.getGalleriesInterface().getPhotos(galleryId, Extras.ALL_EXTRAS, 250, 0);
photos.addAll(first);
if (number > 0)
number = Math.min(number, first.getTotal());
for (int page = 1, n = photos.size(); n < number; page++) {
final PhotoList<Photo> result = flickr.getGalleriesInterface().getPhotos(galleryId, Extras.ALL_EXTRAS, 250,
page);
photos.addAll(result);
n += result.size();
}
if (number > 0 && number < photos.size())
photos = photos.subList(0, number);
return new FlickrImageDataset<IMAGE>(reader, photos);
}
示例4: createFromPhotoset
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
/**
* Create an image dataset from a flickr photoset. The number of images can
* be limited to a subset.
*
* @param reader
* the reader with which to load the images
* @param token
* the flickr api authentication token
* @param setId
* the photoset identifier
* @param number
* the maximum number of images to add to the dataset. Setting to
* 0 or less will attempt to use all the images.
* @return a {@link FlickrImageDataset} created from the gallery described
* by the given parameters
* @throws Exception
* if an error occurs
*/
public static <IMAGE extends Image<?, IMAGE>> FlickrImageDataset<IMAGE> createFromPhotoset(
InputStreamObjectReader<IMAGE> reader,
FlickrAPIToken token,
String setId, int number) throws Exception
{
final Flickr flickr = makeFlickr(token);
final PhotosetsInterface setsInterface = flickr.getPhotosetsInterface();
List<Photo> photos = new ArrayList<Photo>();
final PhotoList<Photo> first = setsInterface.getPhotos(setId, Extras.ALL_EXTRAS, 0, 250, 0);
photos.addAll(first);
if (number > 0)
number = Math.min(number, first.getTotal());
for (int page = 1, n = photos.size(); n < number; page++) {
final PhotoList<Photo> result = setsInterface.getPhotos(setId, Extras.ALL_EXTRAS, 0, 250, page);
photos.addAll(result);
n += result.size();
}
if (number > 0 && number < photos.size())
photos = photos.subList(0, number);
return new FlickrImageDataset<IMAGE>(reader, photos);
}
示例5: PhotosNotInASet
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
public PhotosNotInASet(Configuration configuration, Flickr flickr) throws IOException, SAXException, FlickrException {
super(configuration);
if(configuration.limitDownloadsToSets.size() > 0) {
return;
}
Logger.getLogger(getClass()).info("Downloading list of photos that are not in a set");
int pageNum = 1;
while (true) {
PhotoList photos = flickr.getPhotosInterface().getNotInSet(500, pageNum);
if (photos.size() == 0)
break;
for (int i = 0; i < photos.size(); i++) {
Photo photo = (Photo) photos.get(i);
if (this.primaryPhotoId == null) {
this.primaryPhotoId = photo.getId();
this.primaryPhotoSmallSquareUrl = photo.getSmallSquareUrl();
}
this.photoSet.add(photo);
}
pageNum++;
}
Logger.getLogger(getClass()).info(String.format("There are a total of %s photos that are not in a set", this.photoSet.size()));
}
示例6: findPhoto
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
private boolean findPhoto(PhotoList<Photo> photoList, String name) {
if (photoList == null || name == null)
return false;
for (int i = 0; i < photoList.size(); i++) {
if (photoList.get(i).getTitle().equals(name)) {
return true;
}
}
return false;
}
示例7: FindPicture
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
public FindPicture() {
try {
String apikey = "Your API key";
String secret = "Your secret";
Flickr flickr = new Flickr(apikey, secret, new REST());
SearchParameters searchParameters = new SearchParameters();
searchParameters.setBBox("-180", "-90", "180", "90");
searchParameters.setMedia("photos");
PhotoList<Photo> list = flickr.getPhotosInterface().search(searchParameters, 10, 0);
out.println("Image List");
for (int i = 0; i < list.size(); i++) {
Photo photo = list.get(i);
out.println("Image: " + i
+ "\nTitle: " + photo.getTitle()
+ "\nMedia: " + photo.getOriginalFormat()
+ "\nPublic: " + photo.isPublicFlag()
+ "\nPublic: " + photo.isPublicFlag()
+ "\nUrl: " + photo.getUrl()
+ "\n");
}
out.println();
PhotosInterface pi = new PhotosInterface(apikey, secret, new REST());
out.println("pi: " + pi);
Photo currentPhoto = list.get(0);
out.println("currentPhoto url: " + currentPhoto.getUrl());
// Get image using URL
BufferedImage bufferedImage = pi.getImage(currentPhoto.getUrl());
out.println("bi: " + bufferedImage);
// Get image using Photo instance
bufferedImage = pi.getImage(currentPhoto, Size.SMALL);
// Save image to file
out.println("bufferedImage: " + bufferedImage);
File outputfile = new File("image.jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);
} catch (FlickrException | IOException ex) {
ex.printStackTrace();
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:46,代码来源:FindPicture.java
示例8: toTinyPhotoDTOs
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
private void toTinyPhotoDTOs(List<PhotoDTO> list, PhotoList<Photo> photos) throws FlickrException {
for(int a = 0; a < photos.size(); a++) {
list.add(new PhotoDTO(photos.get(a)));
}
}
示例9: retrieveUserFeeds
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public List<Item> retrieveUserFeeds(SourceFeed feed) {
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
int page=1, pages=1; //pagination
int numberOfRequests = 0;
int numberOfResults = 0;
//Here we search the user by the userId given (NSID) -
// however we can get NSID via flickrAPI given user's username
Source source = feed.getSource();
String userID = source.getId();
if(userID == null) {
logger.info("#Flickr : No source feed");
return items;
}
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setUserId(userID);
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
numberOfRequests++;
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (Exception e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
//logger.info("#Flickr : Done retrieving for this session");
// logger.info("#Flickr : Handler fetched " + items.size() + " photos from " + userID +
// " [ " + lastItemDate + " - " + new Date(System.currentTimeMillis()) + " ]");
// The next request will retrieve only items of the last day
dateToRetrieve = new Date(System.currentTimeMillis() - (24*3600*1000));
feed.setDateToRetrieve(dateToRetrieve);
return items;
}
示例10: retrieveLocationFeeds
import com.flickr4java.flickr.photos.PhotoList; //导入方法依赖的package包/类
@Override
public List<Item> retrieveLocationFeeds(LocationFeed feed){
List<Item> items = new ArrayList<Item>();
long currRunningTime = System.currentTimeMillis();
Date dateToRetrieve = feed.getDateToRetrieve();
String label = feed.getLabel();
Double[][] bbox = feed.getLocation().getbbox();
if(bbox == null || bbox.length==0)
return items;
int page=1, pages=1;
int numberOfRequests = 0;
int numberOfResults = 0;
PhotosInterface photosInteface = flickr.getPhotosInterface();
SearchParameters params = new SearchParameters();
params.setBBox(bbox[0][0].toString(), bbox[0][1].toString(), bbox[1][0].toString(), bbox[1][1].toString());
params.setMinUploadDate(dateToRetrieve);
Set<String> extras = new HashSet<String>(Extras.ALL_EXTRAS);
extras.remove(Extras.MACHINE_TAGS);
params.setExtras(extras);
while(page<=pages && numberOfRequests<=maxRequests && numberOfResults<=maxResults &&
(System.currentTimeMillis()-currRunningTime)<maxRunningTime) {
PhotoList<Photo> photos;
try {
photos = photosInteface.search(params , PER_PAGE, page++);
} catch (FlickrException e) {
break;
}
pages = photos.getPages();
numberOfResults += photos.size();
if(photos.isEmpty()) {
break;
}
for(Photo photo : photos) {
String userid = photo.getOwner().getId();
StreamUser streamUser = userMap.get(userid);
if(streamUser == null) {
streamUser = getStreamUser(userid);
userMap.put(userid, streamUser);
}
FlickrItem flickrItem = new FlickrItem(photo, streamUser);
flickrItem.setList(label);
items.add(flickrItem);
}
}
logger.info("#Flickr : Handler fetched " + items.size() + " photos "+
" [ " + dateToRetrieve + " - " + new Date(System.currentTimeMillis()) + " ]");
return items;
}