List of usage examples for com.google.common.collect Lists newArrayList
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements)
From source file:com.example.aakas.signuptest.UpdateVideo.java
/** * Add a keyword tag to a video that the user specifies. Use OAuth 2.0 to * authorize the API request./* ww w .j ava 2 s. c o m*/ * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "updatevideo"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-updatevideo-sample").build(); // Prompt the user to enter the video ID of the video being updated. String videoId = getVideoIdFromUser(); System.out.println("You chose " + videoId + " to update."); // Prompt the user to enter a keyword tag to add to the video. String tag = getTagFromUser(); System.out.println("You chose " + tag + " as a tag."); // Call the YouTube Data API's youtube.videos.list method to // retrieve the resource that represents the specified video. YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet").setId(videoId); VideoListResponse listResponse = listVideosRequest.execute(); // Since the API request specified a unique video ID, the API // response should return exactly one video. If the response does // not contain a video, then the specified video ID was not found. List<Video> videoList = listResponse.getItems(); if (videoList.isEmpty()) { System.out.println("Can't find a video with ID: " + videoId); return; } // Extract the snippet from the video resource. Video video = videoList.get(0); VideoSnippet snippet = video.getSnippet(); // Preserve any videoTags already associated with the video. If the // video does not have any videoTags, create a new array. Append the // provided tag to the list of videoTags associated with the video. List<String> tags = snippet.getTags(); if (tags == null) { tags = new ArrayList<String>(1); snippet.setTags(tags); } tags.add(tag); // Update the video resource by calling the videos.update() method. YouTube.Videos.Update updateVideosRequest = youtube.videos().update("snippet", video); Video videoResponse = updateVideosRequest.execute(); // Print information from the updated resource. System.out.println("\n================== Returned Video ==================\n"); System.out.println(" - Title: " + videoResponse.getSnippet().getTitle()); System.out.println(" - Tags: " + videoResponse.getSnippet().getTags()); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { System.err.println("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:brooklyn.demo.RiakClusterExample.java
public static void main(String[] argv) { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION_SPEC); Preconditions.checkArgument(args.isEmpty(), "Unsupported args: " + args); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, RiakClusterExample.class)) .webconsolePort(port).location(location).start(); Entities.dumpInfo(launcher.getApplications()); }
From source file:com.google.api.services.samples.youtube.cmdline.data.UpdateVideo.java
/** * Add a keyword tag to a video that the user specifies. Use OAuth 2.0 to * authorize the API request.//from w w w .j a v a 2s . com * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "updatevideo"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-updatevideo-sample").build(); // Prompt the user to enter the video ID of the video being updated. String videoId = getVideoIdFromUser(); System.out.println("You chose " + videoId + " to update."); // Prompt the user to enter a keyword tag to add to the video. String tag = getTagFromUser(); System.out.println("You chose " + tag + " as a tag."); // Call the YouTube Data API's youtube.videos.list method to // retrieve the resource that represents the specified video. YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet").setId(videoId); VideoListResponse listResponse = listVideosRequest.execute(); // Since the API request specified a unique video ID, the API // response should return exactly one video. If the response does // not contain a video, then the specified video ID was not found. List<Video> videoList = listResponse.getItems(); if (videoList.isEmpty()) { System.out.println("Can't find a video with ID: " + videoId); return; } // Extract the snippet from the video resource. Video video = videoList.get(0); VideoSnippet snippet = video.getSnippet(); // Preserve any tags already associated with the video. If the // video does not have any tags, create a new array. Append the // provided tag to the list of tags associated with the video. List<String> tags = snippet.getTags(); if (tags == null) { tags = new ArrayList<String>(1); snippet.setTags(tags); } tags.add(tag); // Update the video resource by calling the videos.update() method. YouTube.Videos.Update updateVideosRequest = youtube.videos().update("snippet", video); Video videoResponse = updateVideosRequest.execute(); // Print information from the updated resource. System.out.println("\n================== Returned Video ==================\n"); System.out.println(" - Title: " + videoResponse.getSnippet().getTitle()); System.out.println(" - Tags: " + videoResponse.getSnippet().getTags()); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { System.err.println("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:brooklyn.demo.SingleWebServerExample.java
public static void main(String[] argv) throws Exception { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, SingleWebServerExample.class) .displayName("Brooklyn WebApp example")) .webconsolePort(port).location(location).start(); Entities.dumpInfo(launcher.getApplications()); }
From source file:com.google.api.services.samples.youtube.cmdline.live.DeleteLiveChatMessage.java
/** * Deletes a message from a live broadcast. * * @param args The message id to delete (required) followed by the videoId (optional). If the * videoId is given, live chat messages will be retrieved from the chat associated with this * video. If the videoId is not specified, the signed in user's current live broadcast will be * used instead./*from w w w. j a va 2 s.c om*/ */ public static void main(String[] args) { // Get the message id to delete if (args.length == 0) { System.err.println("No message id specified"); System.exit(1); } String messageId = args[0]; // This OAuth 2.0 access scope allows for write access to the authenticated user's account. List<String> scopes = Lists.newArrayList(YouTubeScopes.YOUTUBE_FORCE_SSL); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "deletelivechatmessage"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-deletechatmessages-sample").build(); // Delete the message from live chat YouTube.LiveChatMessages.Delete liveChatDelete = youtube.liveChatMessages().delete(messageId); liveChatDelete.execute(); System.out.println("Deleted message id " + messageId); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { System.err.println("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:com.mrmq.uyoutube.data.ChannelBulletin.java
/** * Authorize the user, call the youtube.channels.list method to retrieve * information about the user's YouTube channel, and post a bulletin with * a video ID to that channel.//ww w . j a va 2s . c o m * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "channelbulletin"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-channelbulletin-sample").build(); // Construct a request to retrieve the current user's channel ID. // See https://developers.google.com/youtube/v3/docs/channels/list YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails"); // channelRequest.setMine(true); channelRequest.setId("UC0jDoh3tVXCaqJ6oTve8ebA"); // In the API response, only include channel information needed // for this use case. channelRequest.setFields("items/contentDetails"); ChannelListResponse channelResult = channelRequest.execute(); List<Channel> channelsList = channelResult.getItems(); if (channelsList != null) { // The user's default channel is the first item in the list. String channelId = channelsList.get(0).getId(); // Create the snippet for the activity resource that // represents the channel bulletin. Set its channel ID // and description. ActivitySnippet snippet = new ActivitySnippet(); snippet.setChannelId(channelId); Calendar cal = Calendar.getInstance(); snippet.setDescription("Bulletin test video via YouTube API on " + cal.getTime()); // Create a resourceId that identifies the video ID. You could // set the kind to "youtube#playlist" and use a playlist ID // instead of a video ID. ResourceId resource = new ResourceId(); resource.setKind("youtube#video"); resource.setVideoId(VIDEO_ID); ActivityContentDetailsBulletin bulletin = new ActivityContentDetailsBulletin(); bulletin.setResourceId(resource); // Construct the ActivityContentDetails object for the request. ActivityContentDetails contentDetails = new ActivityContentDetails(); contentDetails.setBulletin(bulletin); // Construct the resource, including the snippet and content // details, to send in the activities.insert Activity activity = new Activity(); activity.setSnippet(snippet); activity.setContentDetails(contentDetails); // The API request identifies the resource parts that are being // written (contentDetails and snippet). The API response will // also include those parts. YouTube.Activities.Insert insertActivities = youtube.activities().insert("contentDetails,snippet", activity); // Return the newly created activity resource. Activity newActivityInserted = insertActivities.execute(); if (newActivityInserted != null) { System.out .println("New Activity inserted of type " + newActivityInserted.getSnippet().getType()); System.out.println(" - Video id " + newActivityInserted.getContentDetails().getBulletin().getResourceId().getVideoId()); System.out.println(" - Description: " + newActivityInserted.getSnippet().getDescription()); System.out.println(" - Posted on " + newActivityInserted.getSnippet().getPublishedAt()); System.out.println(newActivityInserted.getSnippet().getTitle()); System.out.println(newActivityInserted.getSnippet().getDescription()); System.out.println(newActivityInserted.getSnippet().getChannelId() + newActivityInserted.getSnippet().getChannelTitle()); } else { System.out.println("Activity failed."); } } else { System.out.println("No channels are assigned to this user."); } } catch (GoogleJsonResponseException e) { e.printStackTrace(); System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:nz.co.testamation.core.mock.requestmatcher.AttributeRequestMatcher.java
public static void main(String[] args) { ImmutableMap<String, ImmutableMap<String, String>> map = ImmutableMap.of("k1", ImmutableMap.of("v1", "actual")); System.out.println("k1".split("\\.")[0]); String[] elExpression = "k1.v1".split("\\."); System.out.println(Lists.newArrayList(elExpression)); Object value = map;/*from www . j ava2 s. com*/ for (String s : elExpression) { value = ((Map) value).get(s); } System.out.println("value: " + value); }
From source file:com.google.api.services.samples.youtube.cmdline.data.ChannelBulletin.java
/** * Authorize the user, call the youtube.channels.list method to retrieve * information about the user's YouTube channel, and post a bulletin with * a video ID to that channel./*from w w w .j a v a 2 s . c o m*/ * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "channelbulletin"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-channelbulletin-sample").build(); // Construct a request to retrieve the current user's channel ID. // See https://developers.google.com/youtube/v3/docs/channels/list YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails"); channelRequest.setMine(true); // In the API response, only include channel information needed // for this use case. channelRequest.setFields("items/contentDetails"); ChannelListResponse channelResult = channelRequest.execute(); List<Channel> channelsList = channelResult.getItems(); if (channelsList != null) { // The user's default channel is the first item in the list. String channelId = channelsList.get(0).getId(); // Create the snippet for the activity resource that // represents the channel bulletin. Set its channel ID // and description. ActivitySnippet snippet = new ActivitySnippet(); snippet.setChannelId(channelId); Calendar cal = Calendar.getInstance(); snippet.setDescription("Bulletin test video via YouTube API on " + cal.getTime()); // Create a resourceId that identifies the video ID. You could // set the kind to "youtube#playlist" and use a playlist ID // instead of a video ID. ResourceId resource = new ResourceId(); resource.setKind("youtube#video"); resource.setVideoId(VIDEO_ID); ActivityContentDetailsBulletin bulletin = new ActivityContentDetailsBulletin(); bulletin.setResourceId(resource); // Construct the ActivityContentDetails object for the request. ActivityContentDetails contentDetails = new ActivityContentDetails(); contentDetails.setBulletin(bulletin); // Construct the resource, including the snippet and content // details, to send in the activities.insert Activity activity = new Activity(); activity.setSnippet(snippet); activity.setContentDetails(contentDetails); // The API request identifies the resource parts that are being // written (contentDetails and snippet). The API response will // also include those parts. YouTube.Activities.Insert insertActivities = youtube.activities().insert("contentDetails,snippet", activity); // Return the newly created activity resource. Activity newActivityInserted = insertActivities.execute(); if (newActivityInserted != null) { System.out .println("New Activity inserted of type " + newActivityInserted.getSnippet().getType()); System.out.println(" - Video id " + newActivityInserted.getContentDetails().getBulletin().getResourceId().getVideoId()); System.out.println(" - Description: " + newActivityInserted.getSnippet().getDescription()); System.out.println(" - Posted on " + newActivityInserted.getSnippet().getPublishedAt()); } else { System.out.println("Activity failed."); } } else { System.out.println("No channels are assigned to this user."); } } catch (GoogleJsonResponseException e) { e.printStackTrace(); System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:uk.co.onehp.trickle.dao.HibernateMarketDaoCustomT.java
@Ignore public static void main(final String[] args) { final ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:/spring-trickle.xml"); final MarketDao marketDao = (MarketDao) applicationContext.getBean("marketDao"); final HorseDao horseDao = (HorseDao) applicationContext.getBean("horseDao"); final Market market = new Market(7483, "Market"); final Meeting meeting = new Meeting(234, "Meeting"); final Race race = new Race(867, "Race", new LocalDateTime(), "meeting"); final Horse horse = new Horse(); final Pricing pricing = new Pricing(new BigDecimal("3.45"), new BigDecimal("3090.96"), BettingAspect.BACK); horse.setRunnerId(441);/*from w w w. ja va 2 s . com*/ horse.setRaceId(867); horse.setRace(race); horse.setPrices(Lists.newArrayList(pricing)); race.addHorse(horse); meeting.addRace(race); market.addMeeting(meeting); marketDao.saveOrUpdate(market); System.out.println(marketDao.getMarket(7483)); }
From source file:com.google.api.services.samples.youtube.cmdline.data.MyUploads.java
/** * Authorize the user, call the youtube.channels.list method to retrieve * the playlist ID for the list of videos uploaded to the user's channel, * and then call the youtube.playlistItems.list method to retrieve the * list of videos in that playlist./*from ww w . ja v a 2 s. com*/ * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for read-only access to the // authenticated user's account, but not other types of account access. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.readonly"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "myuploads"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-myuploads-sample").build(); // Call the API's channels.list method to retrieve the // resource that represents the authenticated user's channel. // In the API response, only include channel information needed for // this use case. The channel's contentDetails part contains // playlist IDs relevant to the channel, including the ID for the // list that contains videos uploaded to the channel. YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails"); channelRequest.setMine(true); channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo"); ChannelListResponse channelResult = channelRequest.execute(); List<Channel> channelsList = channelResult.getItems(); if (channelsList != null) { // The user's default channel is the first item in the list. // Extract the playlist ID for the channel's videos from the // API response. String uploadPlaylistId = channelsList.get(0).getContentDetails().getRelatedPlaylists() .getUploads(); // Define a list to store items in the list of uploaded videos. List<PlaylistItem> playlistItemList = new ArrayList<PlaylistItem>(); // Retrieve the playlist of the channel's uploaded videos. YouTube.PlaylistItems.List playlistItemRequest = youtube.playlistItems() .list("id,contentDetails,snippet"); playlistItemRequest.setPlaylistId(uploadPlaylistId); // Only retrieve data used in this application, thereby making // the application more efficient. See: // https://developers.google.com/youtube/v3/getting-started#partial playlistItemRequest.setFields( "items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo"); String nextToken = ""; // Call the API one or more times to retrieve all items in the // list. As long as the API response returns a nextPageToken, // there are still more items to retrieve. do { playlistItemRequest.setPageToken(nextToken); PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute(); playlistItemList.addAll(playlistItemResult.getItems()); nextToken = playlistItemResult.getNextPageToken(); } while (nextToken != null); // Prints information about the results. prettyPrint(playlistItemList.size(), playlistItemList.iterator()); } } catch (GoogleJsonResponseException e) { e.printStackTrace(); System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }