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