/**
  * Queries a position feed and prints feed and entry details.
  *
  * @param service authenticated client connection to a Finance GData service
  * @param feedUrl resource URL for the feed, including GData query parameters e.g.
  *     http://finance.google.com/finance/feeds/default/ portfolios/1/positions?returns=true
  * @throws IOException If there is a problem communicating with the server.
  * @throws MalformedURLException If the URL is invalid.
  * @throws ServiceException If the service is unable to handle the request.
  */
 private static void queryPositionFeed(FinanceService service, String feedUrl)
     throws IOException, MalformedURLException, ServiceException {
   System.out.println("Requesting Feed at location " + feedUrl);
   PositionFeed positionFeed = service.getFeed(new URL(feedUrl), PositionFeed.class);
   System.out.println("\nPosition Feed\n=============");
   printBasicFeedDetails(positionFeed);
   for (int i = 0; i < positionFeed.getEntries().size(); i++) {
     PositionEntry positionEntry = positionFeed.getEntries().get(i);
     printPositionEntry(positionEntry);
   }
 }
 /**
  * Prints detailed contents for a portfolio (i.e. a Portfolio Feed entry)
  *
  * @param portfolioEntry The portfolio entry of interest
  */
 private static void printPortfolioEntry(PortfolioEntry portfolioEntry) {
   System.out.println("\nPortfolio Entry\n---------------");
   printBasicEntryDetails(portfolioEntry);
   System.out.println("\tFeed Link: " + portfolioEntry.getFeedLink().getHref());
   if (portfolioEntry.getFeedLink().getFeed() == null) {
     System.out.println("\tNo inlined feed.");
   } else {
     System.out.println("********** Beginning of inline feed ***************");
     printBasicFeedDetails(portfolioEntry.getFeedLink().getFeed());
     PositionFeed inlinedFeed = portfolioEntry.getFeedLink().getFeed();
     printBasicFeedDetails(inlinedFeed);
     for (int i = 0; i < inlinedFeed.getEntries().size(); i++) {
       PositionEntry positionEntry = inlinedFeed.getEntries().get(i);
       printPositionEntry(positionEntry);
     }
     System.out.println("************* End of inlined feed *****************");
   }
   PortfolioData portfolioData = portfolioEntry.getPortfolioData();
   System.out.println("\tPortfolio Data:");
   System.out.println("\t\tCurrency is " + portfolioData.getCurrencyCode());
   System.out.printf("\t\tPercent Gain is %.2f%%\n", portfolioData.getGainPercentage() * 100.0);
   System.out.println("\t\tReturns:");
   System.out.printf("\t\t\tOne week: %.2f%%\n", portfolioData.getReturn1w() * 100.0);
   System.out.printf("\t\t\tFour weeks: %.2f%%\n", portfolioData.getReturn4w() * 100.0);
   System.out.printf("\t\t\tThree months: %.2f%%\n", portfolioData.getReturn3m() * 100.0);
   System.out.printf("\t\t\tYear-to-date: %.2f%%\n", portfolioData.getReturnYTD() * 100.0);
   System.out.printf("\t\t\tOne year: %.2f%%\n", portfolioData.getReturn1y() * 100.0);
   System.out.printf("\t\t\tThree years: %.2f%%\n", portfolioData.getReturn3y() * 100.0);
   System.out.printf("\t\t\tFive years: %.2f%%\n", portfolioData.getReturn5y() * 100.0);
   System.out.printf("\t\t\tOverall: %.2f%%\n", portfolioData.getReturnOverall() * 100.0);
   if (portfolioData.getCostBasis() == null) {
     System.out.println("\t\tCost Basis not specified");
   } else {
     for (int i = 0; i < portfolioData.getCostBasis().getMoney().size(); i++) {
       Money m = portfolioData.getCostBasis().getMoney().get(i);
       System.out.printf("\t\tThis portfolio cost %.2f %s.\n", m.getAmount(), m.getCurrencyCode());
     }
   }
   if (portfolioData.getDaysGain() == null) {
     System.out.println("\t\tDay's Gain not specified");
   } else {
     for (int i = 0; i < portfolioData.getDaysGain().getMoney().size(); i++) {
       Money m = portfolioData.getDaysGain().getMoney().get(i);
       System.out.printf(
           "\t\tThis portfolio made %.2f %s today.\n", m.getAmount(), m.getCurrencyCode());
     }
   }
   if (portfolioData.getGain() == null) {
     System.out.println("\t\tTotal Gain not specified");
   } else {
     for (int i = 0; i < portfolioData.getGain().getMoney().size(); i++) {
       Money m = portfolioData.getGain().getMoney().get(i);
       System.out.printf(
           "\t\tThis portfolio has a total gain of %.2f %s.\n",
           m.getAmount(), m.getCurrencyCode());
     }
   }
   if (portfolioData.getMarketValue() == null) {
     System.out.println("\t\tMarket Value not specified");
   } else {
     for (int i = 0; i < portfolioData.getMarketValue().getMoney().size(); i++) {
       Money m = portfolioData.getMarketValue().getMoney().get(i);
       System.out.printf(
           "\t\tThis portfolio is worth %.2f %s.\n", m.getAmount(), m.getCurrencyCode());
     }
   }
 }