Created
October 11, 2011 18:14
-
-
Save FlorianX/1278895 to your computer and use it in GitHub Desktop.
Übung 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Phonebook { | |
var entries = List[Entry]() | |
def += (e: Entry) = { | |
entries ++= List(e) | |
entries = entries.toSet.toList | |
this | |
} | |
/* | |
//merge this into one def below | |
def ++=(l:List[Entry]) = { | |
entries ++= l | |
entries = entries.toSet.toList | |
this | |
} | |
def ++=(s:Set[Entry]) = { | |
entries ++= s | |
entries = entries.toSet.toList | |
this | |
} | |
*/ | |
def ++=(c:Collection[Entry]) = { | |
entries ++= c.toList | |
entries = entries.toSet.toList | |
this | |
} | |
override def toString(): String = { | |
entries.sortWith((e1,e2) => e1.lastname < e2.lastname).mkString(sep = "\n") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
object Phonebook {
var entries = ListEntry
def +=(e:Entry){ // hier fehlt mir der Rueckgabewert oder?
entries ++= List(e)
this
}
def ++=(l:List[Entry]){
entries ++= l
this
}
override def toString(): String = {
entries.sortWith((e1,e2) => e1.lastName < e2.lastName).mkString(sep = "\n")
}
}