Fix checkstyle complains
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / CountersUtil.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.protocol.bgp.rib.impl;
10
11 import java.util.concurrent.atomic.LongAdder;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Provides util for increment/decrement counters whenever is not null
20  * Otherwise prints an informative warn.
21  */
22 public final class CountersUtil {
23     private static final Logger LOG = LoggerFactory.getLogger(CountersUtil.class);
24
25     private CountersUtil() {
26         throw new UnsupportedOperationException();
27     }
28
29     /**
30      * Increments counter by 1 if supported, otherwise produce a warn.
31      *
32      * @param counter   counter
33      * @param tablesKey tablesKey Type
34      */
35     static void increment(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
36         if (counter != null) {
37             counter.increment();
38             return;
39         }
40         LOG.warn("Family {} not supported", tablesKey);
41     }
42
43     /**
44      * Increments counter by 1 if supported, otherwise produce a warn.
45      *
46      * @param counter   counter
47      * @param tablesKey tablesKey Type
48      */
49     static void decrement(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
50         if (counter != null) {
51             counter.decrement();
52             return;
53         }
54         LOG.warn("Family {} not supported", tablesKey);
55     }
56 }