All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperscala.ui.convert.DoubleConverter.scala Maven / Gradle / Ivy

There is a newer version: 0.10.3
Show newest version
package org.hyperscala.ui.convert

import org.powerscala.reflect.EnhancedClass

/**
 * @author Matt Hicks 
 */
class DoubleConverter(pre: String = "", post: String = "") extends Converter[Double] {
  def value2String(value: Double) = s"$pre$value$post"

  def string2Value(s: String, clazz: EnhancedClass): Option[Double] = DoubleConverter.string2Value(s, clazz)
}

object DoubleConverter extends DoubleConverter(pre = "", post = "") {
  val Regex = """(\d+([.]\d+)?)""".r

  override def string2Value(s: String, clazz: EnhancedClass) = s match {
    case DoubleConverter.Regex(d, extra) => try {
      Some(d.toDouble)
    } catch {
      case t: Throwable => None
    }
    case _ => None
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy