Skip to content

Commit

Permalink
A same file detection is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Zaichenkov committed Jun 2, 2011
1 parent 528c68d commit 0bcb28b
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 198 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ru/natty/parser/MainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MainClass {
public static void main(String[] args) throws SmbException, IOException {
LogManager.getLogManager().readConfiguration();
LocalParser musicController = new LocalParser();
musicController.parse("/mnt/s/Scorpions/[2007] Humanity Hour I");
musicController.parse("/mnt");
musicController.close();
}
}
10 changes: 9 additions & 1 deletion src/main/java/ru/natty/persist/Album.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
@NamedQuery(name = "Album.findByName", query = "SELECT a FROM Album a WHERE a.name = :name"),
@NamedQuery(name = "Album.findByPattern", query = "SELECT a FROM Album a WHERE UPPER(a.name) like :name"),
@NamedQuery(name = "Album.findByGenre", query = "SELECT a FROM Album a JOIN a.genreCollection g WHERE g.id = :genre"),
//@NamedQuery(name = "Album.findByNameYearAndArtist", query = "SELECT a FROM (Album a LEFT JOIN albums_artists b ON a.id=b.album_id) LEFT JOIN artist c ON c.id=b.artist_id WHERE a.name=:name AND a.year=:year AND c.name=:artist"),
@NamedQuery(name = "Album.findByNameAndYear", query = "SELECT a FROM Album a WHERE a.name = :name AND a.year = :year"),
@NamedQuery(name = "Album.findByNameAndNullYear", query = "SELECT a FROM Album a WHERE a.name = :name AND a.year IS NULL"),
@NamedQuery(name = "Album.findByYear", query = "SELECT a FROM Album a WHERE a.year = :year")})
public class Album implements Serializable, IdNamed {
private final static Logger log = Logger.getLogger(Album.class);
Expand Down Expand Up @@ -81,6 +82,9 @@ public class Album implements Serializable, IdNamed {
private Set<Track> trackCollection;
@Transient
private Boolean beanExists = false;
@Transient
private final Integer STRING_LENGTH = 255;

// @Transient
// private Artist artist = null;
//
Expand Down Expand Up @@ -113,6 +117,8 @@ public Album() {
public Album(String name) {
this();
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Integer getId() {
Expand All @@ -125,6 +131,8 @@ public String getName() {

public void setName(String name) {
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Date getYear() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ru/natty/persist/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class Artist implements Serializable, IdNamed {
private Set<Album> albumCollection;
@Transient
private Boolean beanExists = false;
@Transient
private final Integer STRING_LENGTH = 255;

public Boolean isExists()
{
Expand All @@ -90,6 +92,8 @@ public Artist() {
public Artist(String name) {
this();
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Integer getId() {
Expand All @@ -103,6 +107,8 @@ public String getName() {

public void setName(String name) {
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Set<Track> getTrackCollection() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ru/natty/persist/Genre.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class Genre implements Serializable, IdNamed {
private Set<Artist> artistCollection;
@Transient
private Boolean beanExists = false;
@Transient
private final Integer STRING_LENGTH = 255;

public Boolean isExists()
{
Expand All @@ -80,6 +82,8 @@ public Genre() {
public Genre(String name) {
this();
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Integer getId() {
Expand All @@ -92,6 +96,8 @@ public String getName() {

public void setName(String name) {
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Collection<Album> getAlbumCollection() {
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/ru/natty/persist/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
@NamedQuery(name = "Track.findByName", query = "SELECT t FROM Track t WHERE t.name = :name"),
@NamedQuery(name = "Track.findByPattern", query = "SELECT t FROM Track t WHERE UPPER(t.name) LIKE :name"),
@NamedQuery(name = "Track.findByYear", query = "SELECT t FROM Track t WHERE t.year = :year"),
@NamedQuery(name = "Track.findByNameAndYear", query = "SELECT t FROM Track t WHERE t.name = :name AND t.year = :year"),
@NamedQuery(name = "Track.findByNameAndNullYear", query = "SELECT t FROM Track t WHERE t.name = :name AND t.year IS NULL"),
//@NamedQuery(name = "Track.findByNameYearAndAlbum", query = "SELECT a FROM (Track a LEFT JOIN tracks_albums b ON a.id=b.track_id) LEFT JOIN Album c ON c.id=b.album_id WHERE a.name=:name AND a.year=:year AND c.name=:album"),
@NamedQuery(name = "Track.findByUrl", query = "SELECT t FROM Track t WHERE t.url = :url")})
public class Track implements Serializable, IdNamed
Expand All @@ -67,6 +69,8 @@ public class Track implements Serializable, IdNamed
private Set<Artist> artistCollection;
@Transient
private Boolean beanExists = false;
@Transient
private final Integer STRING_LENGTH = 255;

public Boolean isExists()
{
Expand All @@ -86,6 +90,8 @@ public Track() {
public Track(String name) {
this();
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Integer getId() {
Expand All @@ -98,6 +104,8 @@ public String getName() {

public void setName(String name) {
this.name = name.replaceAll("\u0000", "");
if(this.name.length() > STRING_LENGTH)
this.name = this.name.substring(0, STRING_LENGTH);
}

public Date getYear() {
Expand Down Expand Up @@ -177,15 +185,11 @@ public boolean equals(Object obj) {
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
return false;
}
if (!simpleDateformat.format(this.year).equals(simpleDateformat.format(other.year)) && (this.year == null || !simpleDateformat.format(this.year).equals(simpleDateformat.format(other.year)))) {
if (this.year == null) return other.year == null;
if (other.year == null) return this.year == null;
if (!simpleDateformat.format(this.year).equals(simpleDateformat.format(other.year))) {
return false;
}
//if (this.albumCollection != other.albumCollection && (this.albumCollection == null || !this.albumCollection.equals(other.albumCollection))) {
// return false;
//}
//if (this.artistCollection != other.artistCollection && (this.artistCollection == null || !this.artistCollection.equals(other.artistCollection))) {
// return false;
//}
return true;
}

Expand All @@ -206,8 +210,6 @@ public int hashCode() {
int hash = 3;
hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0);
hash = 29 * hash + (this.year != null ? simpleDateformat.format(this.year).hashCode() : 0);
//hash = 29 * hash + (this.albumCollection != null ? this.albumCollection.hashCode() : 0);
//hash = 29 * hash + (this.artistCollection != null ? this.artistCollection.hashCode() : 0);
return hash;
}

Expand Down
Loading

0 comments on commit 0bcb28b

Please sign in to comment.