Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 1 | package org.projectfloodlight.openflow.protocol.match; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import org.projectfloodlight.openflow.types.OFValueType; |
| 7 | |
| 8 | public class Prerequisite<T extends OFValueType<T>> { |
| 9 | private final MatchField<T> field; |
| 10 | private final Set<OFValueType<T>> values; |
| 11 | private boolean any; |
| 12 | |
Yotam Harchol | 4d63468 | 2013-09-26 13:21:06 -0700 | [diff] [blame] | 13 | @SafeVarargs |
Yotam Harchol | f3f1115 | 2013-09-05 16:47:16 -0700 | [diff] [blame] | 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 | } |