Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.net.flowobjective.impl.composition; |
| 17 | |
| 18 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.HashMap; |
| 22 | import java.util.List; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | /** |
| 26 | * Provides a table to store Fitler. |
| 27 | */ |
| 28 | public class FilterTable { |
| 29 | |
| 30 | protected Map<Integer, FilteringObjective> filterMap; |
| 31 | |
| 32 | public FilterTable() { |
| 33 | this.filterMap = new HashMap<>(); |
| 34 | } |
| 35 | |
| 36 | public List<FilteringObjective> updateFilter(FilteringObjective filteringObjective) { |
| 37 | List<FilteringObjective> updates = new ArrayList<>(); |
| 38 | switch (filteringObjective.op()) { |
| 39 | case ADD: |
| 40 | this.filterMap.put(filteringObjective.id(), filteringObjective); |
| 41 | updates.add(filteringObjective); |
| 42 | break; |
| 43 | case REMOVE: |
| 44 | this.filterMap.remove(filteringObjective.id()); |
| 45 | updates.add(filteringObjective); |
| 46 | break; |
| 47 | default: |
| 48 | break; |
| 49 | } |
| 50 | return updates; |
| 51 | } |
| 52 | |
| 53 | public List<FilteringObjective> updateFilter(List<FilteringObjective> filteringObjectives) { |
| 54 | List<FilteringObjective> updates = new ArrayList<>(); |
| 55 | for (FilteringObjective filteringObjective : filteringObjectives) { |
| 56 | updates.addAll(this.updateFilter(filteringObjective)); |
| 57 | } |
| 58 | return updates; |
| 59 | } |
| 60 | |
| 61 | } |