private void showTagsPrompt() throws IOException { boolean fertig = false; do { System.out.print("Enter a genre that you want to listen to: "); String eingaben = in.readLine(); System.out.println("Fetching artists that match your search (this may take a while)..."); // separate the entry String and build a list of tags ArrayList<String> tags = Utils.chopTagsIntoList(eingaben); // fire a request towards the distribution layer with the tags & save results try { currentArtists = ui.findArtistsByTags(tags); if (currentArtists.size() > 0) { // start the menu loop if you found something fertig = true; } else { // if there were no matches, do it again System.out.println("We found no matching artist for your input! Please try again. :)"); } } catch (NullPointerException e) { System.out.println("There was a problem during your request! Please try again."); } catch (NoSuchEntryException e) { System.out.println( "There is no tag called \"" + e.getMessage().substring(2) + "\"! Please try again."); } } while (!fertig); }
private void showMenu() { String input = ""; do { Iterator<Artist> iter = currentArtists.iterator(); // display all current results with an associated index number for (int j = 1; j <= currentArtists.size(); j++) { Artist a = iter.next(); System.out.println("[" + j + "] " + a.getName()); } System.out.println("-"); System.out.println("[L] List traveled artists"); System.out.println("[q] Quit program"); // prompt System.out.println(separator); System.out.println("Which artist do you want to check out?"); System.out.print("Enter his/her index number or enter 'q' to exit: "); System.out.flush(); ArtistNode anode = null; try { input = in.readLine(); int neuerIndex = Integer.parseInt(input); // if the index exceeds the array's bounds, prompt again if (neuerIndex > currentArtists.size() || neuerIndex < 1) System.out.println("There is no such index! Please re-try your request, would you?"); else { // fetch the selected artist - it will become the new center Artist a = (Artist) ((ArrayList<Artist>) currentArtists).get(neuerIndex - 1); anode = ui.retrieveArtistInformation(a.getName()); displayArtistInformation(anode); currentArtists = ui.findArtistsByName(a.getName()); System.out.println(separator); } } catch (UnknownHostException e) { System.out.println( "You don't seem to have established a working internet " + "connection going on right now. Please fix that and try again."); System.exit(1); } catch (IOException e) { e.printStackTrace(); } catch (NumberFormatException e) { if (input.equals("L")) { listTraveledArtists(); System.out.println(separator); } else if (input.equals("q")) break; else System.out.println( "I believe you screwed up the index input (your input: " + input + ")" + "\n Would you mind doing it again, please?"); } catch (NoSuchEntryException e) { System.out.println("There was an entry retrieval error! The code is " + e.getMessage()); } } while (!input.equals("q")); }