blob: ba2bbee8af2fb19916ba187318df51f41751fd85 [file] [log] [blame]
Felix Meschbergerefb2d082008-08-19 13:18:47 +00001/*
Richard S. Hall59aef192009-04-25 14:50:37 +00002 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Felix Meschbergerefb2d082008-08-19 13:18:47 +000017package org.apache.felix.shell.remote;
18
Felix Meschbergerefb2d082008-08-19 13:18:47 +000019/**
20 * Provides an atomic integer.
Felix Meschbergerefb2d082008-08-19 13:18:47 +000021 */
22class AtomicInteger
23{
Richard S. Hall59aef192009-04-25 14:50:37 +000024 private int m_value;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000025
26 public AtomicInteger()
27 {
Richard S. Hall59aef192009-04-25 14:50:37 +000028 m_value = 0;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000029 }//constructor
30
Felix Meschbergerefb2d082008-08-19 13:18:47 +000031 /**
32 * Constructs a new <tt>AtomicInteger</tt>
33 * with a given initial value.
34 *
35 * @param value the initial value.
36 */
Richard S. Hall59aef192009-04-25 14:50:37 +000037 public AtomicInteger(int value)
Felix Meschbergerefb2d082008-08-19 13:18:47 +000038 {
Richard S. Hall59aef192009-04-25 14:50:37 +000039 m_value = value;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000040 }//constructor
41
Felix Meschbergerefb2d082008-08-19 13:18:47 +000042 /**
43 * Increments this <tt>AtomicInteger</tt> by one.
44 *
45 * @return the resulting value.
46 */
47 public synchronized int increment()
48 {
Richard S. Hall59aef192009-04-25 14:50:37 +000049 return ++m_value;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000050 }//increment
51
Felix Meschbergerefb2d082008-08-19 13:18:47 +000052 /**
53 * Decrements this <tt>AtomicInteger</tt> by one.
54 *
55 * @return the resulting value.
56 */
57 public synchronized int decrement()
58 {
Richard S. Hall59aef192009-04-25 14:50:37 +000059 return --m_value;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000060 }//decrement
61
Felix Meschbergerefb2d082008-08-19 13:18:47 +000062 /**
63 * Sets the value of this <tt>AtomicInteger</tt>.
64 *
65 * @param i the new value.
66 */
Richard S. Hall59aef192009-04-25 14:50:37 +000067 public synchronized void set(int i)
Felix Meschbergerefb2d082008-08-19 13:18:47 +000068 {
Richard S. Hall59aef192009-04-25 14:50:37 +000069 m_value = i;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000070 }//set
71
Felix Meschbergerefb2d082008-08-19 13:18:47 +000072 /**
73 * Returns the value of this <tt>AtomicInteger</tt>.
74 *
75 * @return the actual value.
76 */
77 public synchronized int get()
78 {
Richard S. Hall59aef192009-04-25 14:50:37 +000079 return m_value;
Felix Meschbergerefb2d082008-08-19 13:18:47 +000080 }//get
Felix Meschbergerefb2d082008-08-19 13:18:47 +000081}//class AtomicInteger