001 /*
002 Galois, a framework to exploit amorphous data-parallelism in irregular
003 programs.
004
005 Copyright (C) 2010, The University of Texas at Austin. All rights reserved.
006 UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS SOFTWARE
007 AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR ANY
008 PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF PERFORMANCE, AND ANY
009 WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE.
010 NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE
011 SOFTWARE OR DOCUMENTATION. Under no circumstances shall University be liable
012 for incidental, special, indirect, direct or consequential damages or loss of
013 profits, interruption of business, or related expenses which may arise from use
014 of Software or Documentation, including but not limited to those resulting from
015 defects in Software and/or Documentation, or loss or inaccuracy of data of any
016 kind.
017
018 File: MutableInteger.java
019
020 */
021
022 package util;
023
024 /**
025 * Object wrapper around an integer
026 *
027 *
028 */
029 public class MutableInteger {
030 private int value;
031
032 /**
033 * Creates a new mutable integer with value 0
034 */
035 public MutableInteger() {
036 value = 0;
037 }
038
039 /**
040 * Creates a new mutable integer with the given value
041 *
042 * @param value initial value
043 */
044 public MutableInteger(int value) {
045 this.value = value;
046 }
047
048 public int get() {
049 return value;
050 }
051
052 public void set(int value) {
053 this.value = value;
054 }
055
056 public int incrementAndGet() {
057 return ++value;
058 }
059
060 public int getAndIncrement() {
061 return value++;
062 }
063
064 public void add(int delta) {
065 value += delta;
066 }
067
068 public int decrementAndGet() {
069 return --value;
070 }
071
072 public int getAndDecrement() {
073 return value--;
074 }
075
076 @Override
077 public String toString() {
078 return String.valueOf(value);
079 }
080 }