
spice.net.PathPart.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spice-core_3 Show documentation
Show all versions of spice-core_3 Show documentation
Core functionality leveraged and shared by most other sub-projects of YouI.
package spice.net
sealed trait PathPart extends Any {
def value: String
}
object PathPart {
private val ArgumentPartRegex1 = """:(.+)""".r
private val ArgumentPartRegex2 = """[{](.+)[}]""".r
object UpLevel extends PathPart {
override def value: String = ".."
}
object SameLevel extends PathPart {
override def value: String = "."
}
case class Literal(value: String) extends AnyVal with PathPart
case class Argument(name: String) extends AnyVal with PathPart {
override def value: String = s":$name"
}
def apply(value: String): Option[PathPart] = value match {
case null | "" => None
case ".." => Some(UpLevel)
case "." => Some(SameLevel)
case ArgumentPartRegex1(name) => Some(Argument(name))
case ArgumentPartRegex2(name) => Some(Argument(name))
case s => Some(Literal(s))
}
def equals(p1: PathPart, p2: PathPart): Boolean = if (p1 == p2) {
true
} else {
p1 match {
case _: Literal => p2 match {
case _: Argument => true
case _ => false
}
case _: Argument => p2 match {
case _: Literal => true
case _ => false
}
case _ => false
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy