2015-10-05 23:23:06 +08:00
|
|
|
import scala.collection.immutable.StringOps
|
|
|
|
import org.bigbluebutton.core.apps.Answer
|
|
|
|
import org.bigbluebutton.core.apps.Question
|
|
|
|
|
|
|
|
object TestWorksheet {
|
2016-01-14 01:20:51 +08:00
|
|
|
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
|
2016-01-14 01:20:51 +08:00
|
|
|
val YesNoPollType = "YN" //> YesNoPollType : String = YN
|
|
|
|
val TrueFalsePollType = "TF" //> TrueFalsePollType : String = TF
|
|
|
|
val LetterPollType = "A-" //> LetterPollType : String = A-
|
|
|
|
val NumberPollType = "1-" //> NumberPollType : String = 1-
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
val LetterArray = Array("A", "B", "C", "D", "E", "F")
|
2016-01-14 01:20:51 +08:00
|
|
|
//> LetterArray : Array[String] = Array(A, B, C, D, E, F)
|
2015-10-05 23:23:06 +08:00
|
|
|
val NumberArray = Array("1", "2", "3", "4", "5", "6")
|
2016-01-14 01:20:51 +08:00
|
|
|
//> NumberArray : Array[String] = Array(1, 2, 3, 4, 5, 6)
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
def processYesNoPollType(qType: String):Question = {
|
|
|
|
val answers = new Array[Answer](2)
|
|
|
|
answers(0) = new Answer(0, "N", Some("No"))
|
|
|
|
answers(1) = new Answer(1, "Y", Some("Yes"))
|
|
|
|
|
|
|
|
new Question(0, YesNoPollType, false, None, answers)
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> processYesNoPollType: (qType: String)org.bigbluebutton.core.apps.Question
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
def processTrueFalsePollType(qType: String):Question = {
|
|
|
|
val answers = new Array[Answer](2)
|
|
|
|
|
|
|
|
answers(0) = new Answer(0, "F", Some("False"))
|
|
|
|
answers(1) = new Answer(1, "T", Some("True"))
|
|
|
|
|
|
|
|
new Question(0, TrueFalsePollType, false, None, answers)
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> processTrueFalsePollType: (qType: String)org.bigbluebutton.core.apps.Questio
|
|
|
|
//| n
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
def processLetterPollType(qType: String, multiResponse: Boolean):Option[Question] = {
|
|
|
|
val q = qType.split('-')
|
|
|
|
val numQs = q(1).toInt
|
|
|
|
|
|
|
|
var questionOption: Option[Question] = None
|
|
|
|
|
|
|
|
if (numQs > 0 && numQs <= 7) {
|
|
|
|
val answers = new Array[Answer](numQs)
|
|
|
|
var i = 0
|
|
|
|
for ( i <- 0 until numQs ) {
|
|
|
|
answers(i) = new Answer(i, LetterArray(i), Some(LetterArray(i)))
|
|
|
|
val question = new Question(0, LetterPollType, multiResponse, None, answers)
|
|
|
|
questionOption = Some(question)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
questionOption
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> processLetterPollType: (qType: String, multiResponse: Boolean)Option[org.bi
|
|
|
|
//| gbluebutton.core.apps.Question]
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
def processNumberPollType(qType: String, multiResponse: Boolean):Option[Question] = {
|
|
|
|
val q = qType.split('-')
|
|
|
|
val numQs = q(1).toInt
|
|
|
|
|
|
|
|
var questionOption: Option[Question] = None
|
|
|
|
|
|
|
|
if (numQs > 0 && numQs <= 7) {
|
|
|
|
val answers = new Array[Answer](numQs)
|
|
|
|
var i = 0
|
|
|
|
for ( i <- 0 until numQs ) {
|
|
|
|
answers(i) = new Answer(i, NumberArray(i), Some(NumberArray(i)))
|
|
|
|
val question = new Question(0, NumberPollType, multiResponse, None, answers)
|
|
|
|
questionOption = Some(question)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
questionOption
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> processNumberPollType: (qType: String, multiResponse: Boolean)Option[org.bi
|
|
|
|
//| gbluebutton.core.apps.Question]
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
def createQuestion(qType: String):Option[Question] = {
|
|
|
|
val qt = qType.toUpperCase()
|
|
|
|
var questionOption: Option[Question] = None
|
|
|
|
if (qt.matches(YesNoPollType)) {
|
|
|
|
questionOption = Some(processYesNoPollType(qt))
|
|
|
|
} else if (qt.matches(TrueFalsePollType)) {
|
|
|
|
questionOption = Some(processTrueFalsePollType(qt))
|
|
|
|
} else if (qt.startsWith(LetterPollType)) {
|
|
|
|
questionOption = processLetterPollType(qt, false)
|
|
|
|
} else if (qt.startsWith(NumberPollType)) {
|
|
|
|
processNumberPollType(qt, false)
|
|
|
|
} else {
|
|
|
|
questionOption = None
|
|
|
|
}
|
|
|
|
|
|
|
|
questionOption
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> createQuestion: (qType: String)Option[org.bigbluebutton.core.apps.Question]
|
|
|
|
//|
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
def determineQType3(qType: String) {
|
|
|
|
val qt = qType.toUpperCase()
|
|
|
|
|
|
|
|
if (qt.matches(YesNoPollType)) {
|
|
|
|
println("YN")
|
|
|
|
} else if (qt.matches("TF")) {
|
|
|
|
println(TrueFalsePollType)
|
|
|
|
} else if (qt.startsWith(LetterPollType)) {
|
|
|
|
println("A5")
|
|
|
|
processLetterPollType(qt, false)
|
|
|
|
} else if (qt.startsWith(NumberPollType)) {
|
|
|
|
println("1")
|
|
|
|
processNumberPollType(qt, false)
|
|
|
|
} else {
|
|
|
|
println("No Match for [" + qType + "]")
|
|
|
|
}
|
2016-01-14 01:20:51 +08:00
|
|
|
} //> determineQType3: (qType: String)Unit
|
2015-10-05 23:23:06 +08:00
|
|
|
|
2016-01-14 01:20:51 +08:00
|
|
|
determineQType3("YN") //> YN
|
|
|
|
determineQType3("YF") //> No Match for [YF]
|
|
|
|
determineQType3("TF") //> TF
|
|
|
|
determineQType3("A-5") //> A5
|
|
|
|
determineQType3("1-5") //> 1
|
2015-10-05 23:23:06 +08:00
|
|
|
|
2016-01-14 01:20:51 +08:00
|
|
|
val list = new java.util.ArrayList[String]() //> list : java.util.ArrayList[String] = []
|
|
|
|
list.add("Red") //> res0: Boolean = true
|
|
|
|
list.add("Green") //> res1: Boolean = true
|
|
|
|
list.add("Blue") //> res2: Boolean = true
|
2015-10-05 23:23:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|