1:package is346; 2: 3:import java.util.ArrayList; 4:import java.util.Iterator; 5:import java.util.Collection; 6:import java.util.List; 7: 8:public class TrackDtoAssembler { 9: public static TrackDto createDto(Track track) { 10: TrackDto trackDto = new TrackDto(); 11: if (track != null) { 12: trackDto.setId(track.getId()); 13: trackDto.setTitle(track.getTitle()); 14: trackDto.setDuration(track.getDuration()); 15: trackDto.setArtists(ArtistDtoAssembler.createDtos(track.getArtist())); 16: } 17: return trackDto; 18: } 19: 20: public static TrackDto[] createDtos(Collection tracks) { 21: List list = new ArrayList(); 22: if (tracks != null) { 23: Iterator iterator = tracks.iterator(); 24: while (iterator.hasNext()) { 25: list.add(createDto( (Track) iterator.next())); 26: } 27: } 28: TrackDto[] returnArray = new TrackDto[list.size()]; 29: return (TrackDto[]) list.toArray(returnArray); 30: } 31:}