Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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.mapping; |
| 17 | |
Jian Li | a0bf459 | 2017-02-03 17:43:21 +0900 | [diff] [blame] | 18 | import org.slf4j.Logger; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | import static org.slf4j.LoggerFactory.getLogger; |
| 22 | |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 23 | /** |
| 24 | * Default implementation of MappingEntry. |
| 25 | */ |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 26 | public class DefaultMappingEntry extends DefaultMapping implements StoredMappingEntry { |
Jian Li | a0bf459 | 2017-02-03 17:43:21 +0900 | [diff] [blame] | 27 | |
| 28 | private static final Logger log = getLogger(DefaultMappingEntry.class); |
| 29 | |
| 30 | private MappingEntryState state; |
| 31 | |
| 32 | /** |
| 33 | * Creates a mapping entry specified with the mapping, state information. |
| 34 | * |
| 35 | * @param mapping mapping |
| 36 | * @param state mapping state |
| 37 | */ |
| 38 | public DefaultMappingEntry(Mapping mapping, MappingEntryState state) { |
| 39 | super(mapping); |
| 40 | this.state = state; |
| 41 | } |
| 42 | |
Jian Li | 9876310 | 2017-02-19 23:48:46 +0900 | [diff] [blame] | 43 | /** |
| 44 | * Creates a mapping entry specified with the mapping. |
| 45 | * |
| 46 | * @param mapping mapping |
| 47 | */ |
| 48 | public DefaultMappingEntry(Mapping mapping) { |
| 49 | this(mapping, MappingEntryState.PENDING_ADD); |
| 50 | } |
| 51 | |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 52 | @Override |
| 53 | public MappingEntryState state() { |
Jian Li | a0bf459 | 2017-02-03 17:43:21 +0900 | [diff] [blame] | 54 | return state; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return toStringHelper(this) |
| 60 | .add("mapping", super.toString()) |
| 61 | .add("state", state) |
| 62 | .toString(); |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 63 | } |
Jian Li | 252750d | 2017-03-01 04:50:13 +0900 | [diff] [blame] | 64 | |
| 65 | @Override |
| 66 | public void setState(MappingEntryState newState) { |
| 67 | this.state = newState; |
| 68 | } |
Jian Li | 95edb59 | 2017-01-29 08:42:07 +0900 | [diff] [blame] | 69 | } |