blob: 97d2b871a51917c198331e71df802bc268af5f71 [file] [log] [blame]
Jian Li95edb592017-01-29 08:42:07 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li95edb592017-01-29 08:42:07 +09003 *
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.mapping;
17
Jian Lia0bf4592017-02-03 17:43:21 +090018import org.slf4j.Logger;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21import static org.slf4j.LoggerFactory.getLogger;
22
Jian Li95edb592017-01-29 08:42:07 +090023/**
24 * Default implementation of MappingEntry.
25 */
Jian Li252750d2017-03-01 04:50:13 +090026public class DefaultMappingEntry extends DefaultMapping implements StoredMappingEntry {
Jian Lia0bf4592017-02-03 17:43:21 +090027
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 Li98763102017-02-19 23:48:46 +090043 /**
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 Li95edb592017-01-29 08:42:07 +090052 @Override
53 public MappingEntryState state() {
Jian Lia0bf4592017-02-03 17:43:21 +090054 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 Li95edb592017-01-29 08:42:07 +090063 }
Jian Li252750d2017-03-01 04:50:13 +090064
65 @Override
66 public void setState(MappingEntryState newState) {
67 this.state = newState;
68 }
Jian Li95edb592017-01-29 08:42:07 +090069}