本文整理汇总了Scala中java.util.Enumeration类的典型用法代码示例。如果您正苦于以下问题:Scala Enumeration类的具体用法?Scala Enumeration怎么用?Scala Enumeration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Enumeration类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: determineRepresentation
//设置package包名称以及导入依赖的类
package shorty
import java.util.Enumeration
import javax.servlet.http._
def determineRepresentation(request:HttpServletRequest) = {
fromParam(request) match {
case Some(x) => x
case None => fromHeader(request) match {
case Some(y) => y
case None => DEFAULT_TYPE
}
}
}
private def fromHeader(request:HttpServletRequest) = {
val requestedTypes = requested(request.getHeaders(ACCEPT_HEADER),Nil)
knownTypes.intersect(requestedTypes) match {
case x :: rest => {
debug("Found mime type " + x)
Some(x.toLowerCase)
}
case _ => {
debug("No intersection between " + knownTypes.toString + " and " + requestedTypes.toString)
None
}
}
}
private def fromParam(request:HttpServletRequest):Option[String] = {
val param = request.getParameter(TYPE_PARAM)
if (param != null) {
if (knownTypes.contains(param.trim.toLowerCase) ) {
return Some(request.getParameter(TYPE_PARAM).trim.toLowerCase)
}
}
None
}
private def requested(enumeration:Enumeration[_],list:List[String]):List[String] = {
if (!enumeration.hasMoreElements) {
debug("None left, returning " + list.toString)
list
}
else {
val values = enumeration.nextElement.asInstanceOf[String]
debug("Got more; so far " + list.toString)
requested(enumeration,values.split(",").toList.map( _.toLowerCase ) ::: list)
}
}
}