Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object eMails {
- val emails= """aau31@Informatik.haw-hamburg.de
- tde_g@Informatik.haw-hamburg.de
- aas06@Informatik.haw-hamburg.de
- dal_l@Informatik.haw-hamburg.de
- aa447@Informatik.haw-hamburg.de
- daund@gmail.com
- sims.alexr@googlemail.com
- mch@pikora.net
- sir@googlemail.com
- itt_p@Informatik.haw-hamburg.de
- aw_m@informatik.haw-hamburg.de
- ahl_l@informatik.haw-hamburg.de
- au86@Informatik.haw-hamburg.de
- hren@googlemail.com
- nik_t@Informatik.haw-hamburg.de
- eenb_o@Informatik.haw-hamburg.de
- rio,rein@haw-hamburg.de
- hede@gmail.com
- rca@breitsgen.de
- ikor_m@Informatik.haw-hamburg.de
- lex_phip01@hotmail.com
- memm@koni.de
- ve.a83@googlemail.com
- exand.inov@informatik.haw-hamburg.de
- ose_sds@informatik.haw-hamburg.de
- lojigaonlj@gmail.com
- ummeln.@gmx.de
- rit_m@informatik.haw-hamburg.de
- iler_f@informatik.haw-hamburg.de
- ahof_j@Informatik.haw-hamburg.de
- deny.rusk@googlemail.com
- jhannsen@web.de
- ritz.lig@haw-hamburg.de
- aab332@Informatik.haw-hamburg.de"""
- val userPartRfc2822 = """([A-Za-z0-9+_.-]+)"""
- val userPartRfc2822OrSpace = """([A-Za-z0-9+_.-]*)"""
- val atInform = """(@informatik.haw-hamburg.de)"""
- val dotUnderscore = """(.|_)"""
- val gmail = """(@gmail.com)"""
- val googlemail = """(@googlemail.com)"""
- // _?_@informatik.haw-hamburg.de
- val firstPattern = (userPartRfc2822OrSpace+dotUnderscore+userPartRfc2822OrSpace+atInform).r
- // _@informatik.haw-hamburg.de
- val secondPattern = (userPartRfc2822+atInform).r
- //_#@informatik.haw-hamburg.de
- val thirdPattern = (userPartRfc2822+"""(\d)"""+atInform).r
- //_._@gmail.com oder _@googlemail.com
- val fourthPattern = (userPartRfc2822OrSpace+"""(\.)"""+userPartRfc2822OrSpace+gmail).r
- val fifthPattern = (userPartRfc2822+googlemail).r
- //_._@_.de oder _._@_.com
- val sixthPattern = (userPartRfc2822OrSpace+"""(\.)"""+userPartRfc2822OrSpace+"""(@)"""+userPartRfc2822+"""(\.de|\.com)""").r
- }
- def main(args: Array[String]): Unit = {
- class EmailTyp;
- case object First extends EmailTyp;
- case object Second extends EmailTyp;
- case object Third extends EmailTyp;
- case object Fourth extends EmailTyp;
- case object Fifth extends EmailTyp;
- case object NoEmail extends EmailTyp;
- import eMails._
- import scala.util.matching._
- //:Map[EmailTyp,List[Product]]
- val eMailLists = emails.split("\n").toList.map(_.trim).map(_ match {
- case fourthPattern(underscore1, dot, underscore2, constant)
- => (Fourth,(underscore1, dot, underscore2, constant))
- case fifthPattern(underscore, constant)
- => (Fourth,(underscore, constant))
- case sixthPattern(underscore1, dot, underscore2, at, underscore ,country)
- => (Fifth, (underscore1, dot, underscore2, at, underscore ,country))
- case thirdPattern(underscore1, number, constant)
- => (Third,(underscore1, number, constant))
- case firstPattern(underscore1, questionMark, underscore2, constant)
- => (First,(underscore1, questionMark, underscore2, constant))
- case secondPattern(underscor, constant)
- => (Second,(underscor, constant))
- case i
- => (NoEmail,Tuple1(i))
- }).groupBy(_._1).mapValues(values => values.map(_._2))
- val firstEmails:List[Product] = eMailLists.getOrElse(First, Nil)
- val secondEmails:List[Product] = eMailLists.getOrElse(Second, Nil)
- val thirdEmails:List[Product] = eMailLists.getOrElse(Third, Nil)
- val fourthEmails:List[Product] = eMailLists.getOrElse(Fourth, Nil)
- val fifthEmails:List[Product] = eMailLists.getOrElse(Fifth, Nil)
- val noEmails:List[Product] = eMailLists.getOrElse(NoEmail, Nil)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement