43780
|
1 |
/* Title: Pure/General/properties.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Property lists.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Properties
|
|
11 |
{
|
|
12 |
type Entry = (java.lang.String, java.lang.String)
|
|
13 |
type T = List[Entry]
|
|
14 |
|
64358
|
15 |
def defined(props: T, name: java.lang.String): java.lang.Boolean =
|
|
16 |
props.exists({ case (x, _) => x == name })
|
|
17 |
|
|
18 |
def get(props: T, name: java.lang.String): Option[java.lang.String] =
|
|
19 |
props.collectFirst({ case (x, y) if x == name => y })
|
|
20 |
|
|
21 |
def put(props: T, entry: Entry): T =
|
|
22 |
{
|
|
23 |
val (x, y) = entry
|
|
24 |
def update(ps: T): T =
|
|
25 |
ps match {
|
|
26 |
case (p @ (x1, _)) :: rest =>
|
|
27 |
if (x1 == x) (x1, y) :: rest else p :: update(rest)
|
|
28 |
case Nil => Nil
|
|
29 |
}
|
|
30 |
if (defined(props, x)) update(props) else entry :: props
|
|
31 |
}
|
|
32 |
|
|
33 |
|
|
34 |
/* named entries */
|
|
35 |
|
43780
|
36 |
class String(val name: java.lang.String)
|
|
37 |
{
|
|
38 |
def apply(value: java.lang.String): T = List((name, value))
|
|
39 |
def unapply(props: T): Option[java.lang.String] =
|
|
40 |
props.find(_._1 == name).map(_._2)
|
|
41 |
}
|
|
42 |
|
48344
|
43 |
class Boolean(val name: java.lang.String)
|
|
44 |
{
|
|
45 |
def apply(value: scala.Boolean): T = List((name, Value.Boolean(value)))
|
|
46 |
def unapply(props: T): Option[scala.Boolean] =
|
|
47 |
props.find(_._1 == name) match {
|
|
48 |
case None => None
|
|
49 |
case Some((_, value)) => Value.Boolean.unapply(value)
|
|
50 |
}
|
|
51 |
}
|
|
52 |
|
48015
|
53 |
class Int(val name: java.lang.String)
|
43780
|
54 |
{
|
|
55 |
def apply(value: scala.Int): T = List((name, Value.Int(value)))
|
|
56 |
def unapply(props: T): Option[scala.Int] =
|
|
57 |
props.find(_._1 == name) match {
|
|
58 |
case None => None
|
|
59 |
case Some((_, value)) => Value.Int.unapply(value)
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
48015
|
63 |
class Long(val name: java.lang.String)
|
43780
|
64 |
{
|
|
65 |
def apply(value: scala.Long): T = List((name, Value.Long(value)))
|
|
66 |
def unapply(props: T): Option[scala.Long] =
|
|
67 |
props.find(_._1 == name) match {
|
|
68 |
case None => None
|
|
69 |
case Some((_, value)) => Value.Long.unapply(value)
|
|
70 |
}
|
|
71 |
}
|
|
72 |
|
48015
|
73 |
class Double(val name: java.lang.String)
|
43780
|
74 |
{
|
|
75 |
def apply(value: scala.Double): T = List((name, Value.Double(value)))
|
|
76 |
def unapply(props: T): Option[scala.Double] =
|
|
77 |
props.find(_._1 == name) match {
|
|
78 |
case None => None
|
|
79 |
case Some((_, value)) => Value.Double.unapply(value)
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|