Checkstyle: fix issues and enforce on lisp-proto
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / util / LispSimpleAddressStringifier.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc.  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.lisp.util;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.lispflowmapping.lisp.util.LispAddressStringifier.Destination;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
13
14 /**
15  * Utility class with static methods returning string representations of
16  * supported LISP simple address types.
17  *
18  * @author Lorand Jakab
19  *
20  */
21 public final class LispSimpleAddressStringifier {
22     // Utility class, should not be instantiated
23     private LispSimpleAddressStringifier() {
24     }
25
26     public static String getString(SimpleAddress addr) {
27         return getString(Destination.USER, addr);
28     }
29
30     public static String getString(Destination dst, SimpleAddress addr) {
31         Preconditions.checkNotNull(addr, "address should not be null");
32
33         if (addr.getIpAddress() != null) {
34             if (addr.getIpAddress().getIpv4Address() != null) {
35                 return addr.getIpAddress().getIpv4Address().getValue();
36             } else if (addr.getIpAddress().getIpv6Address() != null) {
37                 return addr.getIpAddress().getIpv6Address().getValue();
38             }
39         } else if (addr.getIpPrefix() != null) {
40             if (addr.getIpPrefix().getIpv4Prefix() != null) {
41                 return addr.getIpPrefix().getIpv4Prefix().getValue();
42             } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
43                 return addr.getIpPrefix().getIpv6Prefix().getValue();
44             }
45         } else if (addr.getMacAddress() != null) {
46             return addr.getMacAddress().getValue();
47         } else if (addr.getDistinguishedNameType() != null) {
48             return (addr.getDistinguishedNameType().getValue());
49         } else if (addr.getAsNumber() != null) {
50             return "AS" + addr.getAsNumber().getValue();
51         }
52
53         return null;
54     }
55
56     protected static String getURLPrefix(SimpleAddress addr) {
57         Preconditions.checkNotNull(addr, "address should not be null");
58
59         if (addr.getIpAddress() != null) {
60             if (addr.getIpAddress().getIpv4Address() != null) {
61                 return "ipv4";
62             } else if (addr.getIpAddress().getIpv6Address() != null) {
63                 return "ipv6";
64             }
65         } else if (addr.getIpPrefix() != null) {
66             if (addr.getIpPrefix().getIpv4Prefix() != null) {
67                 return "ipv4";
68             } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
69                 return "ipv6";
70             }
71         } else if (addr.getMacAddress() != null) {
72             return "mac";
73         } else if (addr.getDistinguishedNameType() != null) {
74             return "dn";
75         } else if (addr.getAsNumber() != null) {
76             return "as";
77         }
78
79         return null;
80     }
81
82 }