062aad7e1dee709526415aba196787cd55955fbe
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / dao / MappingServiceKey.java
1 /*
2  * Copyright (c) 2014 Contextream, 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.lispflowmapping.implementation.dao;
9
10 import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.lispaddress.LispAddressContainer;
12
13 public class MappingServiceKey implements IMappingServiceKey {
14
15     private LispAddressContainer EID;
16     private int mask;
17
18     public MappingServiceKey(LispAddressContainer lispAddressContainer, int mask) {
19         this.EID = lispAddressContainer;
20         this.mask = mask;
21     }
22
23     public LispAddressContainer getEID() {
24         return EID;
25     }
26
27     public int getMask() {
28         return mask & 0xFF;
29     }
30
31     @Override
32     public int hashCode() {
33         final int prime = 31;
34         int result = 1;
35         result = prime * result + ((EID == null) ? 0 : EID.hashCode());
36         result = prime * result + mask;
37         return result;
38     }
39
40     @Override
41     public boolean equals(Object obj) {
42         if (this == obj)
43             return true;
44         if (obj == null)
45             return false;
46         if (getClass() != obj.getClass())
47             return false;
48         MappingServiceKey other = (MappingServiceKey) obj;
49         if (EID == null) {
50             if (other.EID != null)
51                 return false;
52         } else if (!EID.equals(other.EID))
53             return false;
54         if (mask != other.mask)
55             return false;
56         return true;
57     }
58
59     @Override
60     public String toString() {
61         if (mask > 0) {
62             return EID.toString() + "/" + mask;
63         }
64         return EID.toString();
65     }
66
67 }