Five more Equals/HashCode/StringBuilder replacements
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / packet / address / DataLinkAddress.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.packet.address;
11
12 import java.io.Serializable;
13
14 import javax.xml.bind.annotation.XmlRootElement;
15 import javax.xml.bind.annotation.XmlSeeAlso;
16
17 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
18
19 /**
20  * @file   DataLinkAddress.java
21  *
22  * @brief  Abstract base class for a Datalink Address
23  *
24  */
25
26 /**
27  * Abstract base class for a Datalink Address
28  *
29  */
30 @XmlRootElement
31 @XmlSeeAlso( { EthernetAddress.class })
32 abstract public class DataLinkAddress implements Serializable {
33     private static final long serialVersionUID = 1L;
34     private String name;
35
36     public DataLinkAddress() {
37
38     }
39
40     /**
41      * Constructor of super class
42      *
43      * @param name Create a new DataLink, not for general use but
44      * available only for sub classes
45      *
46      * @return constructed object
47      */
48     protected DataLinkAddress(String name) {
49         this.name = name;
50     }
51
52     /**
53      * Used to copy the DataLinkAddress in a polymorphic way
54      *
55      *
56      * @return A clone of this DataLinkAddress
57      */
58     abstract public DataLinkAddress clone();
59
60     /**
61      * Allow to distinguish among different data link addresses
62      *
63      *
64      * @return Name of the DataLinkAdress we are working on
65      */
66     public String getName() {
67         return this.name;
68     }
69
70     @Override
71     public int hashCode() {
72         final int prime = 31;
73         int result = 1;
74         result = prime * result + ((name == null) ? 0 : name.hashCode());
75         return result;
76     }
77
78     @Override
79     public boolean equals(Object obj) {
80         if (this == obj)
81             return true;
82         if (obj == null)
83             return false;
84         if (getClass() != obj.getClass())
85             return false;
86         DataLinkAddress other = (DataLinkAddress) obj;
87         if (name == null) {
88             if (other.name != null)
89                 return false;
90         } else if (!name.equals(other.name))
91             return false;
92         return true;
93     }
94
95     @Override
96     public String toString() {
97         return "DataLinkAddress[" + ReflectionToStringBuilder.toString(this)
98                 + "]";
99     }
100 }