/**
  * Prints detailed information regarding a Generic Entry
  *
  * @param entry The entry of interest
  */
 private static void printBasicEntryDetails(BaseEntry entry) {
   System.out.println("\tTitle: " + entry.getTitle().getPlainText());
   System.out.println("\tAtom ID: " + entry.getId());
   System.out.println("\tLast updated: " + entry.getUpdated());
   System.out.println("\tEntry Categories:");
   Iterator it = entry.getCategories().iterator();
   while (it.hasNext()) {
     System.out.println("\t\t" + it.next().toString());
   }
   System.out.println("\tLinks:");
   if (entry.getLinks().size() == 0) {
     System.out.println("\t\t<No links, sorry!>");
   }
   for (int i = 0; i < entry.getLinks().size(); i++) {
     System.out.println("\t\t" + ((Link) (entry.getLinks().get(i))).getHref());
   }
 }
Exemple #2
0
 /**
  * Displays the given list of entries and prompts the user to select the index of one of the
  * entries. NOTE: The displayed index is 1-based and is converted to 0-based before being
  * returned.
  *
  * @param reader to read input from the keyboard
  * @param entries the list of entries to display
  * @param type describes the type of things the list contains
  * @return the 0-based index of the user's selection
  * @throws IOException if an I/O error occurs while getting input from user
  */
 private int getIndexFromUser(BufferedReader reader, List entries, String type)
     throws IOException {
   for (int i = 0; i < entries.size(); i++) {
     BaseEntry entry = (BaseEntry) entries.get(i);
     System.out.println("\t(" + (i + 1) + ") " + entry.getTitle().getPlainText());
   }
   int index = -1;
   while (true) {
     out.print("Enter the number of the spreadsheet to load: ");
     String userInput = reader.readLine();
     try {
       index = Integer.parseInt(userInput);
       if (index < 1 || index > entries.size()) {
         throw new NumberFormatException();
       }
       break;
     } catch (NumberFormatException e) {
       System.out.println("Please enter a valid number for your selection.");
     }
   }
   return index - 1;
 }