@Override
  public void mergeWith(Record record, Map<Record, Object> recordsToRefresh) {
    super.mergeWith(record, recordsToRefresh);

    DynamicPlaylistRecord playlist = (DynamicPlaylistRecord) record;
    for (int artistId : playlist.getArtistIds().keySet()) addArtist(artistId);
    for (int labelId : playlist.getLabelIds().keySet()) addLabel(labelId);
    for (int releaseId : playlist.getReleaseIds().keySet()) addRelease(releaseId);
    for (int songId : playlist.getSongIds().keySet()) addSong(songId);

    for (int artistId : playlist.getExcludeArtistIds().keySet()) removeArtist(artistId);
    for (int labelId : playlist.getExcludeLabelIds().keySet()) removeLabel(labelId);
    for (int releaseId : playlist.getExcludeReleaseIds().keySet()) removeRelease(releaseId);
    for (int songId : playlist.getExcludeSongIds().keySet()) removeSong(songId);

    if (playlist.artistSearchParameters != null)
      for (ArtistSearchParameters params : playlist.artistSearchParameters)
        addArtistSearchParameters(params);
    if (playlist.labelSearchParameters != null)
      for (LabelSearchParameters params : playlist.labelSearchParameters)
        addLabelSearchParameters(params);
    if (playlist.releaseSearchParameters != null)
      for (ReleaseSearchParameters params : playlist.releaseSearchParameters)
        addReleaseSearchParameters(params);
    if (playlist.songSearchParameters != null)
      for (SongSearchParameters params : playlist.songSearchParameters)
        addSongSearchParameters(params);
  }
  @Override
  public void write(LineWriter textWriter) {
    textWriter.writeLine(2); // type
    super.write(textWriter);
    textWriter.writeLine(2); // version

    textWriter.writeLine(artistIds.size());
    for (Integer id : artistIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(labelIds.size());
    for (Integer id : labelIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(releaseIds.size());
    for (Integer id : releaseIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(songIds.size());
    for (Integer id : songIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(excludeArtistIds.size());
    for (Integer id : excludeArtistIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(excludeLabelIds.size());
    for (Integer id : excludeLabelIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(excludeReleaseIds.size());
    for (Integer id : excludeReleaseIds.keySet()) textWriter.writeLine(id);
    textWriter.writeLine(excludeSongIds.size());
    for (Integer id : excludeSongIds.keySet()) textWriter.writeLine(id);
    if (artistSearchParameters != null) {
      textWriter.writeLine(artistSearchParameters.length);
      for (ArtistSearchParameters params : artistSearchParameters) params.write(textWriter);
    } else {
      textWriter.writeLine(0);
    }
    if (labelSearchParameters != null) {
      textWriter.writeLine(labelSearchParameters.length);
      for (LabelSearchParameters params : labelSearchParameters) params.write(textWriter);
    } else {
      textWriter.writeLine(0);
    }
    if (releaseSearchParameters != null) {
      textWriter.writeLine(releaseSearchParameters.length);
      for (ReleaseSearchParameters params : releaseSearchParameters) params.write(textWriter);
    } else {
      textWriter.writeLine(0);
    }
    if (songSearchParameters != null) {
      textWriter.writeLine(songSearchParameters.length);
      for (SongSearchParameters params : songSearchParameters) params.write(textWriter);
    } else {
      textWriter.writeLine(0);
    }
  }