Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 1 | package org.openflow.protocol.match; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import org.openflow.types.OFValueType; |
| 7 | |
| 8 | public class Prerequisite<T extends OFValueType<T>> { |
| 9 | private MatchField<T> field; |
| 10 | private Set<OFValueType<T>> values; |
| 11 | private boolean any; |
| 12 | |
| 13 | public Prerequisite(MatchField<T> field, OFValueType<T>... values) { |
| 14 | 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 | */ |
Yotam Harchol | ff8f85e | 2013-08-21 10:02:23 -0700 | [diff] [blame] | 32 | public boolean isSatisfied(Match match) { |
Yotam Harchol | 6fccde6 | 2013-08-15 12:04:52 -0700 | [diff] [blame] | 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 | } |