-/*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowjava.statistics;\r
-\r
-import java.util.concurrent.atomic.AtomicLong;\r
-/**\r
- * Counts statistics\r
- * \r
- * @author madamjak\r
- */\r
-public class Counter {\r
-\r
- private AtomicLong counterValue;\r
- private AtomicLong counterLastReadValue;\r
-\r
- /**\r
- * Default constructor\r
- */\r
- public Counter() {\r
- counterValue = new AtomicLong(0L);\r
- counterLastReadValue = new AtomicLong(0L);\r
- }\r
-\r
- /**\r
- * Increment current counter value\r
- */\r
- public void incrementCounter(){\r
- counterValue.incrementAndGet();\r
- }\r
-\r
- /**\r
- * return the last read value of counter. This value can be set during the reading of current counter value, \r
- * for detail see method getCounterValue(boolean modifyLastReadValue).\r
- * @return the counterLastReadValue\r
- */\r
- public long getCounterLastReadValue() {\r
- return counterLastReadValue.get();\r
- }\r
-\r
- /**\r
- * get current value of counter and rewrite CounterLastReadValue by current value\r
- * @return the current value of counter\r
- */\r
- public long getCounterValue() {\r
- return getCounterValue(true);\r
- }\r
-\r
- /**\r
- * get current counter value\r
- * @param modifyLastReadValue\r
- * true - CounterLastReadValue will be rewritten by current CounterValue\r
- * false - no change CounterLastReadValue\r
- * @return the current value of counter\r
- */\r
- public long getCounterValue(boolean modifyLastReadValue) {\r
- if(modifyLastReadValue){\r
- counterLastReadValue.set(counterValue.get());\r
- }\r
- return counterValue.get();\r
- }\r
-\r
- /**\r
- * set current counter value and CounterLastReadValue to 0 (zero)\r
- */\r
- public void reset(){\r
- counterValue.set(0l);\r
- counterLastReadValue.set(0l);\r
- }\r
-\r
- /**\r
- * @return last and current count for specified statistic\r
- */\r
- public String getStat() {\r
- long cntPrevVal = getCounterLastReadValue();\r
- long cntCurValue = getCounterValue();\r
- return String.format("+%d | %d",cntCurValue-cntPrevVal,cntCurValue);\r
- }\r
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.statistics;
+
+import java.util.concurrent.atomic.AtomicLong;
+/**
+ * Counts statistics
+ *
+ * @author madamjak
+ */
+public class Counter {
+
+ private AtomicLong counterValue;
+ private AtomicLong counterLastReadValue;
+
+ /**
+ * Default constructor
+ */
+ public Counter() {
+ counterValue = new AtomicLong(0L);
+ counterLastReadValue = new AtomicLong(0L);
+ }
+
+ /**
+ * Increment current counter value
+ */
+ public void incrementCounter(){
+ counterValue.incrementAndGet();
+ }
+
+ /**
+ * return the last read value of counter. This value can be set during the reading of current counter value,
+ * for detail see method getCounterValue(boolean modifyLastReadValue).
+ * @return the counterLastReadValue
+ */
+ public long getCounterLastReadValue() {
+ return counterLastReadValue.get();
+ }
+
+ /**
+ * get current value of counter and rewrite CounterLastReadValue by current value
+ * @return the current value of counter
+ */
+ public long getCounterValue() {
+ return getCounterValue(true);
+ }
+
+ /**
+ * get current counter value
+ * @param modifyLastReadValue
+ * true - CounterLastReadValue will be rewritten by current CounterValue
+ * false - no change CounterLastReadValue
+ * @return the current value of counter
+ */
+ public long getCounterValue(boolean modifyLastReadValue) {
+ if(modifyLastReadValue){
+ counterLastReadValue.set(counterValue.get());
+ }
+ return counterValue.get();
+ }
+
+ /**
+ * set current counter value and CounterLastReadValue to 0 (zero)
+ */
+ public void reset(){
+ counterValue.set(0l);
+ counterLastReadValue.set(0l);
+ }
+
+ /**
+ * @return last and current count for specified statistic
+ */
+ public String getStat() {
+ long cntPrevVal = getCounterLastReadValue();
+ long cntCurValue = getCounterValue();
+ return String.format("+%d | %d",cntCurValue-cntPrevVal,cntCurValue);
+ }
}
\ No newline at end of file