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