alteracoes classe
This commit is contained in:
parent
5a0e1dc335
commit
dbaec404d7
|
|
@ -1,96 +1,96 @@
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
public class Template {
|
public class Template {
|
||||||
|
|
||||||
// funcao que simula um construtor
|
// funcao que simula um construtor
|
||||||
public static Track cadastra(String dadosMusica) throws ParseException {
|
public static Track cadastra(String dadosMusica) throws ParseException {
|
||||||
String campos[] = new String[19];
|
String campos[] = new String[19];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
String temp = "";
|
String temp = "";
|
||||||
for (int i = 0; i < 19; i++) {
|
for (int i = 0; i < 19; i++) {
|
||||||
temp = "";
|
temp = "";
|
||||||
while (j < dadosMusica.length() && ((dadosMusica.charAt(j) != ',')
|
while (j < dadosMusica.length() && ((dadosMusica.charAt(j) != ',')
|
||||||
|| !(dadosMusica.charAt(j) == ',' && dadosMusica.charAt(j + 1) != ' '))) {
|
|| !(dadosMusica.charAt(j) == ',' && dadosMusica.charAt(j + 1) != ' '))) {
|
||||||
if (dadosMusica.charAt(j) != '"')
|
if (dadosMusica.charAt(j) != '"')
|
||||||
temp += dadosMusica.charAt(j);
|
temp += dadosMusica.charAt(j);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
campos[i] = temp;
|
campos[i] = temp;
|
||||||
}
|
}
|
||||||
Track musica = new Track(campos);
|
Track musica = new Track(campos);
|
||||||
|
|
||||||
return musica;
|
return musica;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leitura das musicas e geração dos objetos Track
|
* leitura das musicas e geracao dos objetos Track
|
||||||
*/
|
*/
|
||||||
public static Track[] inserirPlaylist(int quantidade, String idList[], String totalMusicList[]) throws ParseException {
|
public static Track[] inserirPlaylist(int quantidade, String idList[], String totalMusicList[]) throws ParseException {
|
||||||
Track musicas[] = new Track[quantidade];
|
Track musicas[] = new Track[quantidade];
|
||||||
for (int i = 0; i < quantidade; i++) {
|
for (int i = 0; i < quantidade; i++) {
|
||||||
for (int j = 0; j < totalMusicList.length; j++) {
|
for (int j = 0; j < totalMusicList.length; j++) {
|
||||||
if (totalMusicList[j].contains(idList[i])) {
|
if (totalMusicList[j].contains(idList[i])) {
|
||||||
String dadosMusic = totalMusicList[j];
|
String dadosMusic = totalMusicList[j];
|
||||||
musicas[i] = cadastra(dadosMusic);
|
musicas[i] = cadastra(dadosMusic);
|
||||||
j = totalMusicList.length;
|
j = totalMusicList.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return musicas;
|
return musicas;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leitura de todas as linhas da entrada padrão
|
* leitura de todas as linhas da entrada padrao
|
||||||
*/
|
*/
|
||||||
public static int entradaPadrao(String idList[]) throws IOException {
|
public static int entradaPadrao(String idList[]) throws IOException {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
// faco a leitura dos ids do pub.in
|
// faco a leitura dos ids do pub.in
|
||||||
String linha = in.readLine();
|
String linha = in.readLine();
|
||||||
while (!(linha.contains("FIM"))) {
|
while (!(linha.contains("FIM"))) {
|
||||||
idList[i] = linha;
|
idList[i] = linha;
|
||||||
i++;
|
i++;
|
||||||
linha = in.readLine();
|
linha = in.readLine();
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leitura de todas as musicas do arquivo de entrada /tmp/data.csv
|
* leitura de todas as musicas do arquivo de entrada /tmp/data.csv
|
||||||
*/
|
*/
|
||||||
public static String[] ler() throws Exception {
|
public static String[] ler() throws Exception {
|
||||||
final int TOTAL_MUSIC_NUMBER = 170625;
|
final int TOTAL_MUSIC_NUMBER = 170625;
|
||||||
String totalMusicList[] = new String[TOTAL_MUSIC_NUMBER];
|
String totalMusicList[] = new String[TOTAL_MUSIC_NUMBER];
|
||||||
FileReader arquivo = new FileReader("./tmp/data.csv");
|
FileReader arquivo = new FileReader("./tmp/data.csv");
|
||||||
BufferedReader ler = new BufferedReader(arquivo);
|
BufferedReader ler = new BufferedReader(arquivo);
|
||||||
String linha = ler.readLine();
|
String linha = ler.readLine();
|
||||||
linha = ler.readLine();
|
linha = ler.readLine();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (linha != null) {
|
while (linha != null) {
|
||||||
totalMusicList[i] = linha;
|
totalMusicList[i] = linha;
|
||||||
linha = ler.readLine();
|
linha = ler.readLine();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
arquivo.close();
|
arquivo.close();
|
||||||
return totalMusicList;
|
return totalMusicList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
// vetor que armazena os ids da entrada padrao pub.in
|
// vetor que armazena os ids da entrada padrao pub.in
|
||||||
String idList[] = new String[500];
|
String idList[] = new String[500];
|
||||||
int playlistTam = entradaPadrao(idList);
|
int playlistTam = entradaPadrao(idList);
|
||||||
// leitura de todas as musicas do arquivo de entrada /tmp/data.csv
|
// leitura de todas as musicas do arquivo de entrada /tmp/data.csv
|
||||||
String totalMusicList[] = ler();
|
String totalMusicList[] = ler();
|
||||||
Track musicas[] = inserirPlaylist(playlistTam, idList, totalMusicList);
|
Track musicas[] = inserirPlaylist(playlistTam, idList, totalMusicList);
|
||||||
|
|
||||||
for(Track musica:musicas)
|
for(Track musica:musicas)
|
||||||
musica.imprimir();
|
musica.imprimir();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,244 +1,244 @@
|
||||||
package classe;
|
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
|
public class Track {
|
||||||
public class Track {
|
|
||||||
|
// (0)valence,(1)year,(2)acousticness,(3)artists,(4)danceability,(5)duration_ms,(6)energy,
|
||||||
// (0)valence,(1)year,(2)acousticness,(3)artists,(4)danceability,(5)duration_ms,(6)energy,
|
// (7)explicit,(8)id,(9)instrumentalness,(10)key,(11)liveness,(12)loudness,(13)mode,
|
||||||
// (7)explicit,(8)id,(9)instrumentalness,(10)key,(11)liveness,(12)loudness,(13)mode,
|
// (14)name,(15)popularity,(16)release_date,(17)speechiness,(18)tempo
|
||||||
// (14)name,(15)popularity,(16)release_date,(17)speechiness,(18)tempo
|
private String nome;
|
||||||
private String id; // 8
|
private String id; // 8
|
||||||
private String key; // 10
|
private String key; // 10
|
||||||
private String artists; // 3
|
private String artists; // 3
|
||||||
private Date realease; // 16
|
private Date realease; // 16
|
||||||
private double acousticness; // 2
|
private double acousticness; // 2
|
||||||
private double danceability; // 4
|
private double danceability; // 4
|
||||||
private double energy; // 6
|
private double energy; // 6
|
||||||
private int duration; // 5
|
private int duration; // 5
|
||||||
private double instrumentalness; // 9
|
private double instrumentalness; // 9
|
||||||
private double valence; // 0
|
private double valence; // 0
|
||||||
private int popularity; // 15
|
private int popularity; // 15
|
||||||
private float tempo; // 18
|
private float tempo; // 18
|
||||||
private double liveness; // 11
|
private double liveness; // 11
|
||||||
private double loudness; // 12
|
private double loudness; // 12
|
||||||
private double speechiness; // 17
|
private double speechiness; // 17
|
||||||
private int year; // 1
|
private int year; // 1
|
||||||
|
|
||||||
public Track() {
|
public Track() {
|
||||||
this.id = "";
|
this.id = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Track(String[] values) throws ParseException {
|
public Track(String[] values) throws ParseException {
|
||||||
this.id = values[8]; // 8
|
this.id = values[8]; // 8
|
||||||
this.nome = values[14]; // 14
|
this.nome = values[14]; // 14
|
||||||
this.key = values[10]; // 10
|
this.key = values[10]; // 10
|
||||||
this.acousticness = Double.parseDouble(values[2]); // 2
|
this.acousticness = Double.parseDouble(values[2]); // 2
|
||||||
this.danceability = Double.parseDouble(values[4]); // 4
|
this.danceability = Double.parseDouble(values[4]); // 4
|
||||||
this.energy = Double.parseDouble(values[6]); // 6
|
this.energy = Double.parseDouble(values[6]); // 6
|
||||||
this.duration = Integer.parseInt(values[5]); // 5
|
this.duration = Integer.parseInt(values[5]); // 5
|
||||||
this.instrumentalness = Double.parseDouble(values[9]); // 9
|
this.instrumentalness = Double.parseDouble(values[9]); // 9
|
||||||
this.valence = Double.parseDouble(values[0]); // 0
|
this.valence = Double.parseDouble(values[0]); // 0
|
||||||
this.popularity = Integer.parseInt(values[15]); // 15
|
this.popularity = Integer.parseInt(values[15]); // 15
|
||||||
this.tempo = Float.parseFloat(values[18]); // 18
|
this.tempo = Float.parseFloat(values[18]); // 18
|
||||||
this.liveness = Double.parseDouble(values[11]); // 11
|
this.liveness = Double.parseDouble(values[11]); // 11
|
||||||
this.loudness = Double.parseDouble(values[12]); // 12
|
this.loudness = Double.parseDouble(values[12]); // 12
|
||||||
this.speechiness = Double.parseDouble(values[17]); // 17
|
this.speechiness = Double.parseDouble(values[17]); // 17
|
||||||
this.year = Integer.parseInt(values[1]); // 1
|
this.year = Integer.parseInt(values[1]); // 1
|
||||||
|
|
||||||
String artistsString = "";
|
String artistsString = "";
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < values[3].length()) {
|
while (i < values[3].length()) {
|
||||||
if (!(values[3].charAt(i) == 39 && (values[3].charAt(i - 1) == 91 ||
|
if (!(values[3].charAt(i) == 39 && (values[3].charAt(i - 1) == 91 ||
|
||||||
values[3].charAt(i + 1) == 93 || values[3].charAt(i + 1) == 44 ||
|
values[3].charAt(i + 1) == 93 || values[3].charAt(i + 1) == 44 ||
|
||||||
values[3].charAt(i - 2) == 44))) {
|
values[3].charAt(i - 2) == 44))) {
|
||||||
artistsString += values[3].charAt(i);
|
artistsString += values[3].charAt(i);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
artists = artistsString; // 3 ;
|
artists = artistsString; // 3 ;
|
||||||
|
|
||||||
SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
if (values[16].length() == 4) {
|
if (values[16].length() == 4) {
|
||||||
realease = formato.parse(values[16] + "-01-01");
|
realease = formato.parse(values[16] + "-01-01");
|
||||||
} else if (values[16].length() == 7) {
|
} else if (values[16].length() == 7) {
|
||||||
realease = formato.parse(values[16] + "-01");
|
realease = formato.parse(values[16] + "-01");
|
||||||
} else {
|
} else {
|
||||||
realease = formato.parse(values[16]);
|
realease = formato.parse(values[16]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNome() {
|
public String getNome() {
|
||||||
return nome;
|
return nome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String nome) {
|
public void setName(String nome) {
|
||||||
this.nome = nome;
|
this.nome = nome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String key) {
|
public void setKey(String key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getArtists() {
|
public String getArtists() {
|
||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArtists(String artists) {
|
public void setArtists(String artists) {
|
||||||
this.artists = artists;
|
this.artists = artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getRealease() {
|
public Date getRealease() {
|
||||||
return realease;
|
return realease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRealease(Date realease) {
|
public void setRealease(Date realease) {
|
||||||
this.realease = realease;
|
this.realease = realease;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAcousticness() {
|
public double getAcousticness() {
|
||||||
return acousticness;
|
return acousticness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAcousticness(double acousticness) {
|
public void setAcousticness(double acousticness) {
|
||||||
this.acousticness = acousticness;
|
this.acousticness = acousticness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDanceability() {
|
public double getDanceability() {
|
||||||
return danceability;
|
return danceability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDanceability(double danceability) {
|
public void setDanceability(double danceability) {
|
||||||
this.danceability = danceability;
|
this.danceability = danceability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getEnergy() {
|
public double getEnergy() {
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnergy(double energy) {
|
public void setEnergy(double energy) {
|
||||||
this.energy = energy;
|
this.energy = energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDuration(int duration) {
|
public void setDuration(int duration) {
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getInstrumentalness() {
|
public double getInstrumentalness() {
|
||||||
return instrumentalness;
|
return instrumentalness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstrumentalness(double instrumentalness) {
|
public void setInstrumentalness(double instrumentalness) {
|
||||||
this.instrumentalness = instrumentalness;
|
this.instrumentalness = instrumentalness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getValence() {
|
public double getValence() {
|
||||||
return valence;
|
return valence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValence(double valence) {
|
public void setValence(double valence) {
|
||||||
this.valence = valence;
|
this.valence = valence;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPopularity() {
|
public int getPopularity() {
|
||||||
return popularity;
|
return popularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPopularity(int popularity) {
|
public void setPopularity(int popularity) {
|
||||||
this.popularity = popularity;
|
this.popularity = popularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getTempo() {
|
public float getTempo() {
|
||||||
return tempo;
|
return tempo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTempo(float tempo) {
|
public void setTempo(float tempo) {
|
||||||
this.tempo = tempo;
|
this.tempo = tempo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLiveness() {
|
public double getLiveness() {
|
||||||
return liveness;
|
return liveness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLiveness(double liveness) {
|
public void setLiveness(double liveness) {
|
||||||
this.liveness = liveness;
|
this.liveness = liveness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLoudness() {
|
public double getLoudness() {
|
||||||
return loudness;
|
return loudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoudness(double loudness) {
|
public void setLoudness(double loudness) {
|
||||||
this.loudness = loudness;
|
this.loudness = loudness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSpeechiness() {
|
public double getSpeechiness() {
|
||||||
return speechiness;
|
return speechiness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeechiness(double speechiness) {
|
public void setSpeechiness(double speechiness) {
|
||||||
this.speechiness = speechiness;
|
this.speechiness = speechiness;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getYear() {
|
public int getYear() {
|
||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setYear(int year) {
|
public void setYear(int year) {
|
||||||
this.year = year;
|
this.year = year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Elemento clone() {
|
public Track clone() {
|
||||||
Track novo = new Track();
|
Track novo = new Track();
|
||||||
novo.nome = this.nome;
|
novo.nome = this.nome;
|
||||||
novo.id = this.id;
|
novo.id = this.id;
|
||||||
novo.key = this.key;
|
novo.key = this.key;
|
||||||
novo.artists = this.artists;
|
novo.artists = this.artists;
|
||||||
novo.realease = this.realease;
|
novo.realease = this.realease;
|
||||||
novo.acousticness = this.acousticness;
|
novo.acousticness = this.acousticness;
|
||||||
novo.danceability = this.danceability;
|
novo.danceability = this.danceability;
|
||||||
novo.energy = this.energy;
|
novo.energy = this.energy;
|
||||||
novo.duration = this.duration;
|
novo.duration = this.duration;
|
||||||
novo.instrumentalness = this.instrumentalness;
|
novo.instrumentalness = this.instrumentalness;
|
||||||
novo.valence = this.valence;
|
novo.valence = this.valence;
|
||||||
novo.popularity = this.popularity;
|
novo.popularity = this.popularity;
|
||||||
novo.tempo = this.tempo;
|
novo.tempo = this.tempo;
|
||||||
novo.liveness = this.liveness;
|
novo.liveness = this.liveness;
|
||||||
novo.loudness = this.loudness;
|
novo.loudness = this.loudness;
|
||||||
novo.speechiness = this.speechiness;
|
novo.speechiness = this.speechiness;
|
||||||
novo.year = this.year;
|
novo.year = this.year;
|
||||||
return novo;
|
return novo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void imprimir() throws Exception {
|
public void imprimir() throws Exception {
|
||||||
System.out.println(this.toString());
|
System.out.println(this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
return id + " ## " + artists.toString() + " ## " + nome + " ## " + sdf.format(realease) + " ## " + acousticness
|
return id + " ## " + artists.toString() + " ## " + nome + " ## " + sdf.format(realease) + " ## " + acousticness
|
||||||
+ " ## " + danceability + " ## " + instrumentalness + " ## " + liveness + " ## " + loudness + " ## "
|
+ " ## " + danceability + " ## " + instrumentalness + " ## " + liveness + " ## " + loudness + " ## "
|
||||||
+ speechiness + " ## " + energy + " ## " + duration;
|
+ speechiness + " ## " + energy + " ## " + duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue