Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Predicate |
|
| 1.0;1 | ||||
Predicate$1 |
|
| 1.0;1 | ||||
Predicate$2 |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.policy; | |
11 | ||
12 | import java.util.Map; | |
13 | ||
14 | /** | |
15 | * Interface for all nodes and leaves of the predicate tree. | |
16 | * @since 0.1.0 | |
17 | */ | |
18 | public interface Predicate extends Part { | |
19 | ||
20 | //---- Static | |
21 | ||
22 | /** | |
23 | * A predicate that evaluates always to true. | |
24 | * @since 0.1.0 | |
25 | */ | |
26 | public static final Predicate TRUE = new Predicate() { | |
27 | ||
28 | //---- Static | |
29 | ||
30 | /** | |
31 | * @since 0.1.0 | |
32 | */ | |
33 | private static final long serialVersionUID = -5851044295796919321L; | |
34 | ||
35 | //---- Predicate | |
36 | ||
37 | /** | |
38 | * @since 0.1.0 | |
39 | */ | |
40 | public boolean matches (TimeStamp timeStamp, Map<String, ?> arguments) { | |
41 | 21 | return true; |
42 | } | |
43 | ||
44 | /** | |
45 | * @since 0.3.0 | |
46 | */ | |
47 | public boolean isMatchable (Map<String, Class<?>> arguments) { | |
48 | 0 | return true; |
49 | } | |
50 | ||
51 | /** | |
52 | * @since 0.1.0 | |
53 | */ | |
54 | public boolean isValid () { | |
55 | 0 | return true; |
56 | } | |
57 | ||
58 | //---- Part | |
59 | ||
60 | /** | |
61 | * @since 0.1.0 | |
62 | */ | |
63 | 1 | public boolean isValid (PartProblemReporter reporter) { |
64 | 5 | return true; |
65 | } | |
66 | }; | |
67 | ||
68 | /** | |
69 | * A predicate that evaluates always to false. | |
70 | * @since 0.1.0 | |
71 | */ | |
72 | public static final Predicate FALSE = new Predicate() { | |
73 | ||
74 | //---- Static | |
75 | ||
76 | /** | |
77 | * @since 0.1.0 | |
78 | */ | |
79 | private static final long serialVersionUID = 2225570631372300973L; | |
80 | ||
81 | //---- Predicate | |
82 | ||
83 | /** | |
84 | * @since 0.1.0 | |
85 | */ | |
86 | public boolean matches (TimeStamp timeStamp, Map<String, ?> arguments) { | |
87 | 8 | return false; |
88 | } | |
89 | ||
90 | /** | |
91 | * @since 0.3.0 | |
92 | */ | |
93 | public boolean isMatchable (Map<String, Class<?>> arguments) { | |
94 | 0 | return true; |
95 | } | |
96 | ||
97 | /** | |
98 | * @since 0.1.0 | |
99 | */ | |
100 | public boolean isValid () { | |
101 | 0 | return true; |
102 | } | |
103 | ||
104 | //---- Part | |
105 | ||
106 | /** | |
107 | * @since 0.1.0 | |
108 | */ | |
109 | 1 | public boolean isValid (PartProblemReporter reporter) { |
110 | 4 | return true; |
111 | } | |
112 | }; | |
113 | ||
114 | //---- Methods | |
115 | ||
116 | /** | |
117 | * Try to match the predicate according to time and arguments. | |
118 | * @param timeStamp the current {@link TimeStamp}. | |
119 | * @param arguments a {@link Map} of arguments. | |
120 | * @return the result of this predicate. | |
121 | * @throws IllegalStateException if the predicate is not valid. | |
122 | * @since 0.1.0 | |
123 | */ | |
124 | boolean matches (TimeStamp timeStamp, Map<String, ?> arguments); | |
125 | ||
126 | /** | |
127 | * Try to match the predicate with arguments, without evaluating the predicates but to check | |
128 | * that no runtime exception is thrown at runtime. | |
129 | * @param arguments a {@link Map} of arguments. | |
130 | * @return <code>true</code> if this predicate is matchable and won't throw an exception at | |
131 | * runtime. | |
132 | * @since 0.3.0 | |
133 | */ | |
134 | boolean isMatchable (Map<String, Class<?>> arguments); | |
135 | ||
136 | /** | |
137 | * Validates this predicate. | |
138 | * @return true if this predicate is valid. | |
139 | * @since 0.1.0 | |
140 | */ | |
141 | boolean isValid (); | |
142 | ||
143 | ||
144 | } |