task 1.2-3
This commit is contained in:
parent
931e9b43e6
commit
b7c2adae27
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
/res/songs/
|
||||
|
@ -3,7 +3,9 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/res/songs" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
@ -4,4 +4,6 @@ import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
class Album(val name: String) {
|
||||
private var songs: ArrayBuffer[Song] = new ArrayBuffer()
|
||||
def addSong(song: Song): Unit = songs.addOne(song)
|
||||
def containsSong(song: Song): Boolean = songs.contains(song)
|
||||
}
|
||||
|
@ -4,4 +4,7 @@ import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
class Artist(val name: String) {
|
||||
private var albums: ArrayBuffer[Album] = new ArrayBuffer()
|
||||
def addAlbum(album: Album): Unit = albums.addOne(album)
|
||||
|
||||
def hasAlbum(album: Album): Boolean = albums.contains(album)
|
||||
}
|
||||
|
@ -4,4 +4,6 @@ import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
class DataBase {
|
||||
private var artists: ArrayBuffer[Artist] = new ArrayBuffer()
|
||||
def addArtist(artist: Artist): Unit = artists.addOne(artist)
|
||||
def containsArtist(artist: Artist): Boolean = artists.contains(artist)
|
||||
}
|
||||
|
62
src/ch/hevs/isc/slopify_v2/DataBaseHelper.scala
Normal file
62
src/ch/hevs/isc/slopify_v2/DataBaseHelper.scala
Normal file
@ -0,0 +1,62 @@
|
||||
package ch.hevs.isc.slopify_v2
|
||||
|
||||
import java.io.File
|
||||
|
||||
object DataBaseHelper {
|
||||
def create(directory:String) : DataBase = {
|
||||
val db = new DataBase()
|
||||
for (a <- new File(directory).listFiles() if a.isDirectory) {
|
||||
val artistName = a.getName
|
||||
println(s"found new artist : $artistName")
|
||||
val artist: Artist = new Artist(artistName)
|
||||
|
||||
for (b <- a.listFiles() if b.isDirectory ) {
|
||||
val albumName = b.getName
|
||||
println(s"found new album $albumName for artist : $artistName")
|
||||
val album: Album = new Album(albumName)
|
||||
|
||||
for (c <- b.listFiles() if c.isFile if c.getName.toLowerCase().endsWith(".mp3") ) {
|
||||
val fileName = c.getName.substring(0, c.getName.length - 4)
|
||||
val format1 = """(\d*) (.*)""".r
|
||||
val format2 = """(\d*)-(\d*) (.*)""".r
|
||||
val format3 = """(\d*)-(.*)""".r
|
||||
var songName: String = ""
|
||||
var songNumber: Int = 0
|
||||
|
||||
fileName match {
|
||||
case format1(nr, name) => {
|
||||
println(s"found song nr #$nr name:'$name' in album '$albumName' for artist : '${a.getName}'")
|
||||
songName = name
|
||||
songNumber = Integer.parseInt(nr)
|
||||
}
|
||||
case format2(cd, nr, name) => {
|
||||
println(s"found song nr #$nr on cd#$cd name:'$name' in album '$albumName' for artist : '${a.getName}'")
|
||||
songName = name
|
||||
songNumber = Integer.parseInt(nr)
|
||||
}
|
||||
case format3(nr, name) => {
|
||||
println(s"found song nr #$nr name:'$name' in album '$albumName' for artist : '$artistName'")
|
||||
songName = name
|
||||
songNumber = Integer.parseInt(nr)
|
||||
}
|
||||
}
|
||||
|
||||
val song: Song = new Song(songName, songNumber)
|
||||
album.addSong(song)
|
||||
}
|
||||
artist.addAlbum(album)
|
||||
}
|
||||
db.addArtist(artist)
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
def save(fileName:String, db:DataBase) : Unit = ???
|
||||
def load(fileName:String) : DataBase = ???
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
val db: DataBase = create("res/songs")
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user