package com.insightfullogic.java8.exercises.chapter4; import com.insightfullogic.java8.examples.chapter1.Artist; import java.util.List; public class Artists { private List<Artist> artists; public Artists(List<Artist> artists) { this.artists = artists; } public Artist getArtist(int index) { if (index < 0 || index >= artists.size()) { indexException(index); } return artists.get(index); } private void indexException(int index) { throw new IllegalArgumentException(index + " doesn't correspond to an Artist"); } public String getArtistName(int index) { try { Artist artist = getArtist(index); return artist.getName(); } catch (IllegalArgumentException e) { return "unknown"; } } }