dcc056a7d90308755bcdfba56e8604e0d4320729
[groupbasedpolicy.git] / groupbasedpolicy / src / main / java / org / opendaylight / groupbasedpolicy / util / EndpointUtils.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.util;
10
11 import java.util.Collections;
12 import java.util.List;
13
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpointKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.child.endpoints.ChildEndpoint;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.ParentEndpointChoice;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.ParentContainmentEndpointCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.ParentEndpointCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.containment.endpoint._case.ParentContainmentEndpoint;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.parent.child.endpoints.parent.endpoint.choice.parent.endpoint._case.ParentEndpoint;
24
25 public class EndpointUtils {
26
27     public static AddressEndpointKey createAddressEndpointKey(ChildEndpoint child) {
28         return new AddressEndpointKey(child.getAddress(), child.getAddressType(), child.getContextId(),
29                 child.getContextType());
30     }
31
32     public static AddressEndpointKey createAddressEndpointKey(ParentEndpoint parent) {
33         return new AddressEndpointKey(parent.getAddress(), parent.getAddressType(), parent.getContextId(),
34                 parent.getContextType());
35     }
36
37     public static @Nonnull List<ParentContainmentEndpoint> getParentContainmentEndpoints(
38             @Nullable ParentEndpointChoice parentEndpointChoice) {
39         if (parentEndpointChoice instanceof ParentContainmentEndpointCase) {
40             ParentContainmentEndpointCase parentCeCase = (ParentContainmentEndpointCase) parentEndpointChoice;
41             List<ParentContainmentEndpoint> parentContainmentEndpoints = parentCeCase.getParentContainmentEndpoint();
42             if (parentContainmentEndpoints != null) {
43                 return parentContainmentEndpoints;
44             }
45         }
46         return Collections.emptyList();
47     }
48
49     public static @Nonnull List<ParentEndpoint> getParentEndpoints(
50             @Nullable ParentEndpointChoice parentEndpointChoice) {
51         if (parentEndpointChoice instanceof ParentEndpointCase) {
52             ParentEndpointCase parentEpCase = (ParentEndpointCase) parentEndpointChoice;
53             List<ParentEndpoint> parentEndpoints = parentEpCase.getParentEndpoint();
54             if (parentEndpoints != null) {
55                 return parentEndpoints;
56             }
57         }
58         return Collections.emptyList();
59     }
60 }