Get rid of JSR305 annotations
[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 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import java.util.concurrent.atomic.LongAdder;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Provides util for increment/decrement counters whenever is not null
19  * Otherwise prints an informative warn.
20  */
21 public final class CountersUtil {
22     private static final Logger LOG = LoggerFactory.getLogger(CountersUtil.class);
23
24     private CountersUtil() {
25         throw new UnsupportedOperationException();
26     }
27
28     /**
29      * Increments counter by 1 if supported, otherwise produce a warn.
30      *
31      * @param counter   counter
32      * @param tablesKey tablesKey Type
33      */
34     static void increment(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey) {
35         add(counter, tablesKey, 1);
36     }
37
38     /**
39      * Increments counter by 1 if supported, otherwise produce a warn.
40      *
41      * @param counter   counter
42      * @param tablesKey tablesKey Type
43      */
44     static void decrement(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey) {
45         add(counter, tablesKey, -1);
46     }
47
48     /**
49      * Add specified valut to the counter if supported, otherwise produce a warn.
50      *
51      * @param counter   counter
52      * @param tablesKey tablesKey Type
53      */
54     static void add(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey, final long amount) {
55         if (counter != null) {
56             counter.add(amount);
57         } else {
58             LOG.warn("Family {} not supported", tablesKey);
59         }
60     }
61 }