001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.internal;
014
015/**
016 * A simple settable integer value.
017 */
018public final class IntValue {
019
020   private int value;
021
022   /**
023    * Creates a new integer value initialized to <code>0</code>.
024    *
025    * @return A new integer value.
026    */
027   public static IntValue create() {
028      return of(0);
029   }
030
031   /**
032    * Creates an integer value with the specified initial state.
033    *
034    * @param value The initial state of the value.
035    * @return A new integer value.
036    */
037   public static IntValue of(int value) {
038      return new IntValue(value);
039   }
040
041   private IntValue(int value) {
042      this.value = value;
043   }
044
045   /**
046    * Sets the value.
047    *
048    * @param value The new value.
049    * @return This object.
050    */
051   public IntValue set(int value) {
052      this.value = value;
053      return this;
054   }
055
056   /**
057    * Returns the value.
058    *
059    * @return The value.
060    */
061   public int get() {
062      return value;
063   }
064
065   /**
066    * Returns the current value and then increments it.
067    *
068    * @return The current value.
069    */
070   public int getAndIncrement() {
071      int v = value;
072      value++;
073      return v;
074   }
075}