YANG revision dates mass-update
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / extended / community / ExtendedCommunityUtil.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.protocol.bgp.parser.spi.extended.community;
9
10 /**
11  * The utility functions related to the extended communities.
12  */
13 public final class ExtendedCommunityUtil {
14     private static final byte NON_TRANS = 0x40;
15
16     private ExtendedCommunityUtil() {
17     }
18
19     /**
20      * Sets transitivity flag for the Extended Community type.
21      *
22      * @param type Extended Community Type
23      * @param isTransitive Extended Community transitivity
24      * @return Extended Community type with a transitivity flag set if isTransitive false, otherwise returns unchanged
25      *         type.
26      */
27     public static int setTransitivity(final int type, final boolean isTransitive) {
28         return isTransitive ? type : ExtendedCommunityUtil.toNonTransitiveType(type);
29     }
30
31     /**
32      * Check the Extended Community type for transitivity.
33      *
34      * @param type Extended Community Type
35      * @return True if input type is transitive, false if the type is non-transitive
36      */
37     public static boolean isTransitive(final int type) {
38         return (type & NON_TRANS) == 0 ? true : false;
39     }
40
41     private static int toNonTransitiveType(final int type) {
42         return type | NON_TRANS;
43     }
44 }