blob: a09085ca88f46fbceca060dfdafabe7c4f38893e [file] [log] [blame]
Jian Li0e09eaa2017-02-14 02:01:18 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li0e09eaa2017-02-14 02:01:18 +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.addresses;
17
18import java.util.Objects;
19
20/**
21 * Implementation of AS mapping address.
22 */
23public final class ASMappingAddress implements MappingAddress {
24
25 private final String asNumber;
26
27 /**
28 * Default constructor of ASMappingAddress.
29 *
30 * @param asNumber AS number
31 */
32 ASMappingAddress(String asNumber) {
33 this.asNumber = asNumber;
34 }
35
36 @Override
37 public Type type() {
38 return Type.AS;
39 }
40
41 /**
42 * Obtains AS number.
43 *
44 * @return AS number
45 */
46 public String asNumber() {
47 return this.asNumber;
48 }
49
50 @Override
51 public String toString() {
52 return type().toString() + TYPE_SEPARATOR + asNumber;
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(type().ordinal(), asNumber);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) {
63 return true;
64 }
65 if (obj instanceof ASMappingAddress) {
66 ASMappingAddress that = (ASMappingAddress) obj;
67 return Objects.equals(asNumber, that.asNumber);
68 }
69 return false;
70 }
71}