BUG-6650: ep-sgt/ip, propose initial sxp-ep-provider
[groupbasedpolicy.git] / sxp-integration / sxp-ep-provider / src / main / java / org / opendaylight / groupbasedpolicy / sxp / ep / provider / impl / util / SubnetInfoKeyDecorator.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.util;
10
11 import org.apache.commons.net.util.SubnetUtils;
12
13 /**
14  * Purpose: wraps {@link SubnetUtils.SubnetInfo} and overwrites hashcode and equals methods in order to
15  * be applicable as map key
16  *
17  */
18 public class SubnetInfoKeyDecorator {
19
20     private final SubnetUtils.SubnetInfo delegate;
21
22     public SubnetInfoKeyDecorator(final SubnetUtils.SubnetInfo delegate) {
23         this.delegate = delegate;
24     }
25
26     public SubnetUtils.SubnetInfo getDelegate() {
27         return delegate;
28     }
29
30     @Override
31     public boolean equals(final Object o) {
32         if (this == o) return true;
33         if (o == null || getClass() != o.getClass()) return false;
34
35         final SubnetInfoKeyDecorator that = (SubnetInfoKeyDecorator) o;
36
37         return delegate.getCidrSignature().equals(that.delegate.getCidrSignature());
38
39     }
40
41     @Override
42     public int hashCode() {
43         return delegate.getCidrSignature().hashCode();
44     }
45 }