1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.util.counter;
18
19 /***
20 * A simple counter
21 *
22 * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam</a>
23 *
24 * @since 1.7
25 */
26 public interface Counter {
27
28 /***
29 * Increment the counter by 1
30 *
31 * @return the value after incrementing
32 */
33 long increment();
34
35 /***
36 * Decrement the counter by 1
37 *
38 * @return the value after decrementing
39 */
40 long decrement();
41
42 /***
43 * Returns the value of the counter and sets it to the new value
44 *
45 * @param newValue
46 * @return Returns the old value
47 */
48 long getAndSet(long newValue);
49
50 /***
51 * Gets current value of the counter
52 *
53 * @return current value of the counter
54 */
55 long getValue();
56
57 /***
58 * Increment the counter by given amount
59 *
60 * @param amount
61 * @return the value of the counter after incrementing
62 */
63 long increment(long amount);
64
65 /***
66 * Decrement the counter by given amount
67 *
68 * @param amount
69 * @return the value of the counter after decrementing
70 */
71 long decrement(long amount);
72
73 /***
74 * Sets the value of the counter to the supplied value
75 *
76 * @param newValue
77 */
78 void setValue(long newValue);
79
80 }