· 9 years ago · May 26, 2017, 08:56 PM
1object eMails {
2val emails= """aau31@Informatik.haw-hamburg.de
3 tde_g@Informatik.haw-hamburg.de
4 aas06@Informatik.haw-hamburg.de
5 dal_l@Informatik.haw-hamburg.de
6 aa447@Informatik.haw-hamburg.de
7 daund@gmail.com
8 sims.alexr@googlemail.com
9 mch@pikora.net
10 sir@googlemail.com
11 itt_p@Informatik.haw-hamburg.de
12 aw_m@informatik.haw-hamburg.de
13 ahl_l@informatik.haw-hamburg.de
14 au86@Informatik.haw-hamburg.de
15 hren@googlemail.com
16 nik_t@Informatik.haw-hamburg.de
17 eenb_o@Informatik.haw-hamburg.de
18 rio,rein@haw-hamburg.de
19 hede@gmail.com
20 rca@breitsgen.de
21 ikor_m@Informatik.haw-hamburg.de
22 lex_phip01@hotmail.com
23 memm@koni.de
24 ve.a83@googlemail.com
25 exand.inov@informatik.haw-hamburg.de
26 ose_sds@informatik.haw-hamburg.de
27 lojigaonlj@gmail.com
28 ummeln.@gmx.de
29 rit_m@informatik.haw-hamburg.de
30 iler_f@informatik.haw-hamburg.de
31 ahof_j@Informatik.haw-hamburg.de
32 deny.rusk@googlemail.com
33 jhannsen@web.de
34 ritz.lig@haw-hamburg.de
35 aab332@Informatik.haw-hamburg.de"""
36
37
38 val userPartRfc2822 = """([A-Za-z0-9+_.-]+)"""
39 val userPartRfc2822OrSpace = """([A-Za-z0-9+_.-]*)"""
40 val atInform = """(@informatik.haw-hamburg.de)"""
41 val dotUnderscore = """(.|_)"""
42 val gmail = """(@gmail.com)"""
43 val googlemail = """(@googlemail.com)"""
44
45 // _?_@informatik.haw-hamburg.de
46 val firstPattern = (userPartRfc2822OrSpace+dotUnderscore+userPartRfc2822OrSpace+atInform).r
47
48 // _@informatik.haw-hamburg.de
49 val secondPattern = (userPartRfc2822+atInform).r
50
51 //_#@informatik.haw-hamburg.de
52 val thirdPattern = (userPartRfc2822+"""(\d)"""+atInform).r
53
54
55 //_._@gmail.com oder _@googlemail.com
56 val fourthPattern = (userPartRfc2822OrSpace+"""(\.)"""+userPartRfc2822OrSpace+gmail).r
57 val fifthPattern = (userPartRfc2822+googlemail).r
58
59 //_._@_.de oder _._@_.com
60 val sixthPattern = (userPartRfc2822OrSpace+"""(\.)"""+userPartRfc2822OrSpace+"""(@)"""+userPartRfc2822+"""(\.de|\.com)""").r
61}
62
63
64def main(args: Array[String]): Unit = {
65 class EmailTyp;
66 case object First extends EmailTyp;
67 case object Second extends EmailTyp;
68 case object Third extends EmailTyp;
69 case object Fourth extends EmailTyp;
70 case object Fifth extends EmailTyp;
71 case object NoEmail extends EmailTyp;
72
73 import eMails._
74 import scala.util.matching._
75
76//:Map[EmailTyp,List[Product]]
77 val eMailLists = emails.split("\n").toList.map(_.trim).map(_ match {
78 case fourthPattern(underscore1, dot, underscore2, constant)
79 => (Fourth,(underscore1, dot, underscore2, constant))
80 case fifthPattern(underscore, constant)
81 => (Fourth,(underscore, constant))
82 case sixthPattern(underscore1, dot, underscore2, at, underscore ,country)
83 => (Fifth, (underscore1, dot, underscore2, at, underscore ,country))
84 case thirdPattern(underscore1, number, constant)
85 => (Third,(underscore1, number, constant))
86 case firstPattern(underscore1, questionMark, underscore2, constant)
87 => (First,(underscore1, questionMark, underscore2, constant))
88 case secondPattern(underscor, constant)
89 => (Second,(underscor, constant))
90 case i
91 => (NoEmail,Tuple1(i))
92 }).groupBy(_._1).mapValues(values => values.map(_._2))
93
94 val firstEmails:List[Product] = eMailLists.getOrElse(First, Nil)
95 val secondEmails:List[Product] = eMailLists.getOrElse(Second, Nil)
96 val thirdEmails:List[Product] = eMailLists.getOrElse(Third, Nil)
97 val fourthEmails:List[Product] = eMailLists.getOrElse(Fourth, Nil)
98 val fifthEmails:List[Product] = eMailLists.getOrElse(Fifth, Nil)
99 val noEmails:List[Product] = eMailLists.getOrElse(NoEmail, Nil)
100}