blob: 03d5e79962b5b9ba375047a3b60b932252d7a14a [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.projectfloodlight.openflow.protocol.match;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import org.projectfloodlight.openflow.types.OFValueType;
7
8public class Prerequisite<T extends OFValueType<T>> {
9 private final MatchField<T> field;
10 private final Set<OFValueType<T>> values;
11 private boolean any;
12
13 @SafeVarargs
14 public Prerequisite(MatchField<T> field, OFValueType<T>... values) {
15 this.values = new HashSet<OFValueType<T>>();
16 this.field = field;
17 if (values == null || values.length == 0) {
18 this.any = true;
19 } else {
20 this.any = false;
21 for (OFValueType<T> value : values) {
22 this.values.add(value);
23 }
24 }
25 }
26
27 /**
28 * Returns true if this prerequisite is satisfied by the given match object.
29 *
30 * @param match Match object
31 * @return true iff prerequisite is satisfied.
32 */
33 public boolean isSatisfied(Match match) {
34 OFValueType<T> res = match.get(this.field);
35 if (res == null)
36 return false;
37 if (this.any)
38 return true;
39 if (this.values.contains(res)) {
40 return true;
41 }
42 return false;
43 }
44
45}