blob: 96cf8e90ba482bd46fb5c976d9c58848b5697677 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -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
Andreas Wundsamdcb59da2013-09-24 13:01:15 -070013 public Prerequisite(MatchField<T> field, @SuppressWarnings("unchecked") OFValueType<T>... values) {
Yotam Harcholf3f11152013-09-05 16:47:16 -070014 this.values = new HashSet<OFValueType<T>>();
15 this.field = field;
16 if (values == null || values.length == 0) {
17 this.any = true;
18 } else {
19 this.any = false;
20 for (OFValueType<T> value : values) {
21 this.values.add(value);
22 }
23 }
24 }
25
26 /**
27 * Returns true if this prerequisite is satisfied by the given match object.
28 *
29 * @param match Match object
30 * @return true iff prerequisite is satisfied.
31 */
32 public boolean isSatisfied(Match match) {
33 OFValueType<T> res = match.get(this.field);
34 if (res == null)
35 return false;
36 if (this.any)
37 return true;
38 if (this.values.contains(res)) {
39 return true;
40 }
41 return false;
42 }
43
44}