<commit_before>package org.a0z.mpd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

/**
 * Class representing a file/music entry in playlist.
 * 
 * @author <NAME>
 * @version $Id: Music.java 2940 2005-02-09 02:31:48Z galmeida $
 */
public class Music extends Item implements FilesystemTreeEntry {
	/**
	 * Used to indicate this <code>Music</code> is a stream.
	 */
	public static final int STREAM = 1;

	/**
	 * Used to indicate this <code>Music</code> is a file.
	 */
	public static final int FILE = 0;

	private String album;

	private String artist = null;

	private String albumartist = null;

	private String fullpath;
	
	private int disc = -1;

	private long date = -1;

	private long time = -1;

	private String title;

	private int totalTracks = -1;

	private int track = -1;

	private Directory parent;

	private int songId = -1;

	private int pos = -1;

	private String name;

	private boolean selected = true;
	
	/**
	 * Constructs a new Music.
	 * 
	 * @param response
	 *           server response, which gets parsed into the instance.
	 */
	Music(List<String> response) {
		for (String line : response) {
			if (line.startsWith("file:")) {
				this.fullpath = line.substring("file: ".length());
			} else if (line.startsWith("Artist:")) {
				this.artist = line.substring("Artist: ".length());
			} else if (line.startsWith("AlbumArtist:")) {
				this.albumartist = line.substring("AlbumArtist: ".length());
			} else if (line.startsWith("Album:")) {
				this.album = line.substring("Album: ".length());
			} else if (line.startsWith("Title:")) {
				this.title = line.substring("Title: ".length());
			} else if (line.startsWith("Name:")) {
				this.name = line.substring("Name: ".length());
            } else if (line.startsWith("Track:")) {
                String[] aux = line.substring("Track: ".length()).split("/");
                if(aux.length > 0) {
					try {
                        this.track = Integer.parseInt(aux[0]);
                        if (aux.length > 1) {
                                this.totalTracks = Integer.parseInt(aux[1]);
                        }
					} catch (NumberFormatException e) {
					}
                }
            } else if (line.startsWith("Disc:")) {
            	String[] aux = line.substring("Disc: ".length()).split("/");
            	if(aux.length > 0) {
					try {
						this.disc = Integer.parseInt(aux[0]);
					} catch (NumberFormatException e) {
					}
            	}
			} else if (line.startsWith("Time:")) {
				try {
					this.time = Long.parseLong(line.substring("Time: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Id:")) {
				try {
					this.songId = Integer.parseInt(line.substring("Id: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Pos:")) {
				try {
					this.pos = Integer.parseInt(line.substring("Pos: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Date:")) {
				try {
					this.date = Long.parseLong(line.substring("Date: ".length()).replaceAll("\\D+", ""));
				} catch (NumberFormatException e) {
				}
			} else {
				// Ignore this case, there could be some id3 tags which are not common and therefore not implemented here...
				// (new InvalidResponseException("unknown response: " + line)).printStackTrace();
			}
		}
		
		if (isStream()) {
			String n=getStreamName();
			if (null!=n && !n.isEmpty()) {
				name=n;
			}
		}
	}
	
	private String getStreamName() {
		if (null!=fullpath && !fullpath.isEmpty()) {
			int pos=fullpath.indexOf("#");
			if (pos>1) {
				return fullpath.substring(pos+1, fullpath.length());
			}
		}
		return null;
	}

	public static List<Music> getMusicFromList(List<String> response, boolean sort) {
		ArrayList<Music> result = new ArrayList<Music>();
		LinkedList<String> lineCache = new LinkedList<String>();
		
		for (String line : response) {
			if (line.startsWith("file: ")) {
				if (lineCache.size() != 0) {
					result.add(new Music(lineCache));
					lineCache.clear();
				}
			}
			if (!line.startsWith("directory: "))
				lineCache.add(line);
		}

		if (lineCache.size() != 0) {
			result.add(new Music(lineCache));
		}

		if (sort) {
			Collections.sort(result);
		}<commit_msg>String.isEmpty missing on Froyo<commit_after>package org.a0z.mpd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

/**
 * Class representing a file/music entry in playlist.
 * 
 * @author <NAME>
 * @version $Id: Music.java 2940 2005-02-09 02:31:48Z galmeida $
 */
public class Music extends Item implements FilesystemTreeEntry {
	/**
	 * Used to indicate this <code>Music</code> is a stream.
	 */
	public static final int STREAM = 1;

	/**
	 * Used to indicate this <code>Music</code> is a file.
	 */
	public static final int FILE = 0;

	private String album;

	private String artist = null;

	private String albumartist = null;

	private String fullpath;
	
	private int disc = -1;

	private long date = -1;

	private long time = -1;

	private String title;

	private int totalTracks = -1;

	private int track = -1;

	private Directory parent;

	private int songId = -1;

	private int pos = -1;

	private String name;

	private boolean selected = true;
	
	/**
	 * Constructs a new Music.
	 * 
	 * @param response
	 *           server response, which gets parsed into the instance.
	 */
	Music(List<String> response) {
		for (String line : response) {
			if (line.startsWith("file:")) {
				this.fullpath = line.substring("file: ".length());
			} else if (line.startsWith("Artist:")) {
				this.artist = line.substring("Artist: ".length());
			} else if (line.startsWith("AlbumArtist:")) {
				this.albumartist = line.substring("AlbumArtist: ".length());
			} else if (line.startsWith("Album:")) {
				this.album = line.substring("Album: ".length());
			} else if (line.startsWith("Title:")) {
				this.title = line.substring("Title: ".length());
			} else if (line.startsWith("Name:")) {
				this.name = line.substring("Name: ".length());
            } else if (line.startsWith("Track:")) {
                String[] aux = line.substring("Track: ".length()).split("/");
                if(aux.length > 0) {
					try {
                        this.track = Integer.parseInt(aux[0]);
                        if (aux.length > 1) {
                                this.totalTracks = Integer.parseInt(aux[1]);
                        }
					} catch (NumberFormatException e) {
					}
                }
            } else if (line.startsWith("Disc:")) {
            	String[] aux = line.substring("Disc: ".length()).split("/");
            	if(aux.length > 0) {
					try {
						this.disc = Integer.parseInt(aux[0]);
					} catch (NumberFormatException e) {
					}
            	}
			} else if (line.startsWith("Time:")) {
				try {
					this.time = Long.parseLong(line.substring("Time: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Id:")) {
				try {
					this.songId = Integer.parseInt(line.substring("Id: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Pos:")) {
				try {
					this.pos = Integer.parseInt(line.substring("Pos: ".length()));
				} catch (NumberFormatException e) {
				}
			} else if (line.startsWith("Date:")) {
				try {
					this.date = Long.parseLong(line.substring("Date: ".length()).replaceAll("\\D+", ""));
				} catch (NumberFormatException e) {
				}
			} else {
				// Ignore this case, there could be some id3 tags which are not common and therefore not implemented here...
				// (new InvalidResponseException("unknown response: " + line)).printStackTrace();
			}
		}
		
		if (isStream()) {
			String n=getStreamName();
			if (!isEmpty(n)) {
				name=n;
			}
		}
	}
	
	private String getStreamName() {
		if (!isEmpty(fullpath)) {
			int pos=fullpath.indexOf("#");
			if (pos>1) {
				return fullpath.substring(pos+1, fullpath.length());
			}
		}
		return null;
	}

	public static List<Music> getMusicFromList(List<String> response, boolean sort) {
		ArrayList<Music> result = new ArrayList<Music>();
		LinkedList<String> lineCache = new LinkedList<String>();
		
		for (String line : response) {
			if (line.startsWith("file: ")) {
				if (lineCache.size() != 0) {
					result.add(new Music(lineCache));
					lineCache.clear();
				}
			}
			if (!line.startsWith("directory: "))
				lineCache.add(line);
		}

		if (lineCache.size() != 0) {
			result.add(new Music(lineCache));
		}

		if (sort) {
			Collections.sort(result);
		}
{'fraction_non_alphanumeric': 0.15742128935532235, 'fraction_numerical': 0.008995502248875561, 'mean_word_length': 2.6917837377607494, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204571', 'n_tokens_mistral': 3189, 'n_tokens_neox': 2693, 'n_words': 665}