blob: 86fdf00d0313e52a866b3b8590c3de79fb3a33fa [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.NextObjective;
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 Next.
27 */
28public class NextTable {
29
30 protected Map<Integer, NextObjective> nextMap;
31
32 public NextTable() {
33 this.nextMap = new HashMap<>();
34 }
35
36 public List<NextObjective> updateNext(NextObjective nextObjective) {
37 List<NextObjective> updates = new ArrayList<>();
38 switch (nextObjective.op()) {
39 case ADD:
40 this.nextMap.put(nextObjective.id(), nextObjective);
41 updates.add(nextObjective);
42 break;
43 case REMOVE:
44 this.nextMap.remove(nextObjective.id());
45 updates.add(nextObjective);
46 break;
47 default:
48 break;
49 }
50 return updates;
51 }
52
53 public List<NextObjective> updateNext(List<NextObjective> nextObjectives) {
54 List<NextObjective> updates = new ArrayList<>();
55 for (NextObjective nextObjective : nextObjectives) {
56 updates.addAll(this.updateNext(nextObjective));
57 }
58 return updates;
59 }
60
61}