Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / concepts / AbstractExtendedTunnelIdentifier.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.concepts;
9
10 import org.opendaylight.protocol.concepts.NetworkAddress;
11
12 /**
13  * Basic structure of Extended Tunnel Identifier.
14  * 
15  * @see <a
16  *      href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-7.2.2">LSP
17  *      Identifiers TLVs</a>
18  * @param <T>
19  */
20 public abstract class AbstractExtendedTunnelIdentifier<T extends NetworkAddress<T>> implements Comparable<ExtendedTunnelIdentifier<T>>, ExtendedTunnelIdentifier<T> {
21
22         private static final long serialVersionUID = 110737862492677555L;
23
24         private final T identifier;
25
26         protected AbstractExtendedTunnelIdentifier(final T identifier) {
27                 this.identifier = identifier;
28         }
29
30         @Override
31         public T getIdentifier() {
32                 return this.identifier;
33         }
34
35         @Override
36         public int compareTo(final ExtendedTunnelIdentifier<T> other) {
37                 if (this.identifier == other.getIdentifier())
38                         return 0;
39                 if (this.identifier == null)
40                         return -1;
41                 if (other.getIdentifier() == null)
42                         return 1;
43                 return this.identifier.compareTo(other.getIdentifier());
44         }
45
46         @Override
47         public int hashCode() {
48                 final int prime = 31;
49                 int result = 1;
50                 result = prime * result + ((this.identifier == null) ? 0 : this.identifier.hashCode());
51                 return result;
52         }
53
54         @Override
55         public boolean equals(Object obj) {
56                 if (this == obj)
57                         return true;
58                 if (obj == null)
59                         return false;
60                 if (this.getClass() != obj.getClass())
61                         return false;
62                 final AbstractExtendedTunnelIdentifier<?> other = (AbstractExtendedTunnelIdentifier<?>) obj;
63                 if (this.identifier == null) {
64                         if (other.identifier != null)
65                                 return false;
66                 } else if (!this.identifier.equals(other.identifier))
67                         return false;
68                 return true;
69         }
70
71         @Override
72         public String toString() {
73                 final StringBuilder builder = new StringBuilder();
74                 builder.append("AbstractExtendedTunnelIdentifier [identifier=");
75                 builder.append(this.identifier);
76                 builder.append("]");
77                 return builder.toString();
78         }
79 }