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