blob: 65e344d66aaa46c7255d610abb74aace3eaecb99 [file] [log] [blame]
Xin Jin313708b2015-07-09 13:43:04 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Xin Jin313708b2015-07-09 13:43:04 -07003 *
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 */
16package org.onosproject.net.flowobjective.impl.composition;
17
18import org.onosproject.net.flowobjective.FilteringObjective;
19
20import java.util.ArrayList;
21import java.util.HashMap;
22import java.util.List;
23import java.util.Map;
24
25/**
26 * Provides a table to store Fitler.
27 */
28public 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}