Xin Jin | 313708b | 2015-07-09 13:43:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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.NextObjective; |
| 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 Next. |
| 27 | */ |
| 28 | public 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 | } |