-
Notifications
You must be signed in to change notification settings - Fork 53
io microsphere lang MutableInteger
Type: Class | Module: microsphere-java-core | Package: io.microsphere.lang | Since: 1.0.0
Source:
microsphere-java-core/src/main/java/io/microsphere/lang/MutableInteger.java
A mutable integer container that provides various atomic operations for integer addition,
increment, decrement, and value retrieval. This class extends Number, allowing it to be used
in contexts where a numeric representation is required.
`MutableInteger i = MutableInteger.of(5); // Get and set a new value int oldValue = i.getAndSet(10); // Returns 5, value becomes 10 // Increment and get the new value int newValue = i.incrementAndGet(); // Returns 11, value becomes 11 // Add a delta and get the updated value int result = i.addAndGet(5); // Returns 16, value becomes 16 // Get current value int currentValue = i.get(); // Returns 16 `
public class MutableInteger extends NumberAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.1.10-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
MutableInteger i = MutableInteger.of(5);
// Get and set a new value
int oldValue = i.getAndSet(10); // Returns 5, value becomes 10
// Increment and get the new value
int newValue = i.incrementAndGet(); // Returns 11, value becomes 11
// Add a delta and get the updated value
int result = i.addAndGet(5); // Returns 16, value becomes 16
// Get current value
int currentValue = i.get(); // Returns 16MutableInteger i = new MutableInteger(5);
int currentValue = i.get(); // retrieves the current value
System.out.println(currentValue); // prints 5MutableInteger i = new MutableInteger(0);
i.set(10); // sets the value to 10
System.out.println(i.get()); // prints 10MutableInteger i = new MutableInteger(5);
int oldValue = i.getAndSet(10); // sets the value to 10, returns 5
System.out.println(oldValue); // prints 5
System.out.println(i.get()); // prints 10MutableInteger i = new MutableInteger(5);
int oldValue = i.getAndIncrement(); // increments the value to 6, returns 5
System.out.println(oldValue); // prints 5
System.out.println(i.get()); // prints 6MutableInteger i = new MutableInteger(5);
int oldValue = i.getAndDecrement(); // decrements the value to 4, returns 5
System.out.println(oldValue); // prints 5
System.out.println(i.get()); // prints 4MutableInteger i = new MutableInteger(5);
int oldValue = i.getAndAdd(3); // adds 3 to the current value (5), returns 5
System.out.println(oldValue); // prints 5
System.out.println(i.get()); // prints 8MutableInteger i = new MutableInteger(5);
int newValue = i.incrementAndGet(); // increments the value to 6, returns 6
System.out.println(newValue); // prints 6
System.out.println(i.get()); // prints 6MutableInteger i = new MutableInteger(5);
int newValue = i.decrementAndGet(); // decrements the value to 4, returns 4
System.out.println(newValue); // prints 4
System.out.println(i.get()); // prints 4MutableInteger i = new MutableInteger(5);
int newValue = i.addAndGet(3); // adds 3 to the current value (5), returns 8
System.out.println(newValue); // prints 8
System.out.println(i.get()); // prints 8MutableInteger i = new MutableInteger(7);
int value = i.intValue(); // retrieves the current integer value
System.out.println(value); // prints 7MutableInteger i = new MutableInteger(5);
long value = i.longValue(); // retrieves the current value as a long
System.out.println(value); // prints 5MutableInteger i = new MutableInteger(5);
float value = i.floatValue(); // retrieves the current value as a float
System.out.println(value); // prints 5.0MutableInteger i = new MutableInteger(5);
double value = i.doubleValue(); // retrieves the current value as a double
System.out.println(value); // prints 5.0MutableInteger i = MutableInteger.of(10); // creates an MutableInteger with initial value 10
System.out.println(i.get()); // prints 10Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-java-core</artifactId>
<version>${microsphere-java.version}</version>
</dependency>Tip: Use the BOM (
microsphere-java-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.lang.MutableInteger;| Method | Description |
|---|---|
get |
Gets the current value stored in this MutableInteger. |
set |
Sets the value to the given newValue and returns this instance. |
getAndSet |
Sets the value to the given newValue and returns the previous value. |
getAndIncrement |
increments the current value by 1 and returns the previous value before the increment. |
getAndDecrement |
Decrements the current value by 1 and returns the previous value before the decrement. |
getAndAdd |
Adds the given delta to the current value and returns the previous value before the addition. |
incrementAndGet |
Increments the current value by 1 and returns the updated value. |
decrementAndGet |
Decrements the current value by 1 and returns the updated value. |
addAndGet |
Adds the given delta to the current value and returns the updated value. |
intValue |
Returns the integer value stored in this MutableInteger. |
longValue |
Returns the current value as a long. |
floatValue |
Returns the current value as a float. |
doubleValue |
Returns the current value as a double. |
of |
Creates a new instance of MutableInteger initialized with the given value. |
public final int get()Gets the current value stored in this MutableInteger.
public final MutableInteger set(int newValue)Sets the value to the given newValue and returns this instance.
public final int getAndSet(int newValue)Sets the value to the given newValue and returns the previous value.
public final int getAndIncrement()increments the current value by 1 and returns the previous value before the increment.
This method behaves similarly to a combination of the get() and incrementAndGet()
methods, where the current value is returned before it is increased by 1.
public final int getAndDecrement()Decrements the current value by 1 and returns the previous value before the decrement.
This method behaves similarly to a combination of the get() and decrementAndGet()
methods, where the current value is returned before it is decreased by 1.
public final int getAndAdd(int delta)Adds the given delta to the current value and returns the previous value before the addition.
This method ensures that the current value is returned before the addition operation
is performed, similar to a combination of the get() and addAndGet(int) methods.
public final int incrementAndGet()Increments the current value by 1 and returns the updated value.
This method behaves similarly to the ++value operation,
where the value is increased by 1 before it is returned.
public final int decrementAndGet()Decrements the current value by 1 and returns the updated value.
This method behaves similarly to the --value operation,
where the value is decreased by 1 before it is returned.
public int addAndGet(int delta)Adds the given delta to the current value and returns the updated value.
This method ensures that the new value is calculated and stored before it is returned, behaving similarly to the compound addition operation followed by a retrieval.
public int intValue()Returns the integer value stored in this MutableInteger.
This method provides the implementation for the Number class's abstract method,
allowing this class to be used where a Number is expected.
public long longValue()Returns the current value as a long.
This method provides the implementation for the Number class's abstract method,
allowing this class to be used where a Number is expected.
public float floatValue()Returns the current value as a float.
This method provides the implementation for the Number class's abstract method,
allowing this class to be used where a Number is expected.
public double doubleValue()Returns the current value as a double.
This method provides the implementation for the Number class's abstract method,
allowing this class to be used where a Number is expected.
public static MutableInteger of(int value)Creates a new instance of MutableInteger initialized with the given value.
This static factory method provides a convenient way to create an instance of
MutableInteger with the specified initial value.
java.util.concurrent.atomic.AtomicInteger
This documentation was auto-generated from the source code of microsphere-java.
java-annotations
java-core
- ACLLoggerFactory
- AbstractArtifactResourceResolver
- AbstractConverter
- AbstractDeque
- AbstractEventDispatcher
- AbstractLogger
- AbstractURLClassPathHandle
- AccessibleObjectUtils
- AdditionalMetadataResourceConfigurationPropertyLoader
- AnnotationUtils
- ArchiveFileArtifactResourceResolver
- ArrayEnumeration
- ArrayStack
- ArrayUtils
- Artifact
- ArtifactDetector
- ArtifactResourceResolver
- Assert
- BannedArtifactClassLoadingExecutor
- BaseUtils
- BeanMetadata
- BeanProperty
- BeanUtils
- ByteArrayToObjectConverter
- CharSequenceComparator
- CharSequenceUtils
- CharsetUtils
- ClassDataRepository
- ClassDefinition
- ClassFileJarEntryFilter
- ClassFilter
- ClassLoaderUtils
- ClassPathResourceConfigurationPropertyLoader
- ClassPathUtils
- ClassUtils
- ClassicProcessIdResolver
- ClassicURLClassPathHandle
- CollectionUtils
- Compatible
- CompositeSubProtocolURLConnectionFactory
- CompositeURLStreamHandlerFactory
- ConditionalEventListener
- ConfigurationProperty
- ConfigurationPropertyGenerator
- ConfigurationPropertyLoader
- ConfigurationPropertyReader
- Configurer
- ConsoleURLConnection
- Constants
- ConstructorDefinition
- ConstructorUtils
- Converter
- Converters
- CustomizedThreadFactory
- DefaultConfigurationPropertyGenerator
- DefaultConfigurationPropertyReader
- DefaultDeserializer
- DefaultEntry
- DefaultSerializer
- DelegatingBlockingQueue
- DelegatingDeque
- DelegatingIterator
- DelegatingQueue
- DelegatingScheduledExecutorService
- DelegatingURLConnection
- DelegatingURLStreamHandlerFactory
- DelegatingWrapper
- Deprecation
- Deserializer
- Deserializers
- DirectEventDispatcher
- DirectoryFileFilter
- EmptyDeque
- EmptyIterable
- EmptyIterator
- EnumerationIteratorAdapter
- EnumerationUtils
- Event
- EventDispatcher
- EventListener
- ExceptionUtils
- ExecutableDefinition
- ExecutableUtils
- ExecutorUtils
- ExtendableProtocolURLStreamHandler
- FastByteArrayInputStream
- FastByteArrayOutputStream
- FieldDefinition
- FieldUtils
- FileChangedEvent
- FileChangedListener
- FileConstants
- FileExtensionFilter
- FileUtils
- FileWatchService
- Filter
- FilterOperator
- FilterUtils
- FormatUtils
- Functional
- GenericEvent
- GenericEventListener
- Handler
- Handler
- HierarchicalClassComparator
- IOFileFilter
- IOUtils
- ImmutableEntry
- IterableAdapter
- IterableUtils
- Iterators
- JDKLoggerFactory
- JSON
- JSONArray
- JSONException
- JSONObject
- JSONStringer
- JSONTokener
- JSONUtils
- JarEntryFilter
- JarUtils
- JavaType
- JmxUtils
- ListUtils
- Listenable
- Lists
- Logger
- LoggerFactory
- LoggingFileChangedListener
- MBeanAttribute
- MBeanAttributeInfoBuilder
- MBeanConstructorInfoBuilder
- MBeanDescribableBuilder
- MBeanExecutableInfoBuilder
- MBeanFeatureInfoBuilder
- MBeanInfoBuilder
- MBeanNotificationInfoBuilder
- MBeanOperationInfoBuilder
- MBeanParameterInfoBuilder
- ManagementUtils
- ManifestArtifactResourceResolver
- MapToPropertiesConverter
- MapUtils
- Maps
- MavenArtifact
- MavenArtifactResourceResolver
- MemberDefinition
- MemberUtils
- MetadataResourceConfigurationPropertyLoader
- MethodDefinition
- MethodHandleUtils
- MethodHandlesLookupUtils
- MethodUtils
- ModernProcessIdResolver
- ModernURLClassPathHandle
- Modifier
- MultiValueConverter
- MultipleType
- MutableInteger
- MutableURLStreamHandlerFactory
- NameFileFilter
- NoOpLogger
- NoOpLoggerFactory
- NoOpURLClassPathHandle
- NumberToByteConverter
- NumberToCharacterConverter
- NumberToDoubleConverter
- NumberToFloatConverter
- NumberToIntegerConverter
- NumberToLongConverter
- NumberToShortConverter
- NumberUtils
- ObjectToBooleanConverter
- ObjectToByteArrayConverter
- ObjectToByteConverter
- ObjectToCharacterConverter
- ObjectToDoubleConverter
- ObjectToFloatConverter
- ObjectToIntegerConverter
- ObjectToLongConverter
- ObjectToOptionalConverter
- ObjectToShortConverter
- ObjectToStringConverter
- PackageNameClassFilter
- PackageNameClassNameFilter
- ParallelEventDispatcher
- ParameterizedTypeImpl
- PathConstants
- Predicates
- Prioritized
- PriorityComparator
- ProcessExecutor
- ProcessIdResolver
- ProcessManager
- PropertiesToStringConverter
- PropertiesUtils
- PropertyConstants
- PropertyResourceBundleControl
- PropertyResourceBundleUtils
- ProtocolConstants
- ProxyUtils
- QueueUtils
- ReadOnlyIterator
- ReflectionUtils
- ReflectiveConfigurationPropertyGenerator
- ReflectiveDefinition
- ResourceConstants
- ReversedDeque
- Scanner
- SecurityUtils
- SeparatorConstants
- Serializer
- Serializers
- ServiceLoaderURLStreamHandlerFactory
- ServiceLoaderUtils
- ServiceLoadingURLClassPathHandle
- SetUtils
- Sets
- Sfl4jLoggerFactory
- ShutdownHookCallbacksThread
- ShutdownHookUtils
- SimpleClassScanner
- SimpleFileScanner
- SimpleJarEntryScanner
- SingletonDeque
- SingletonEnumeration
- SingletonIterator
- StackTraceUtils
- StandardFileWatchService
- StandardURLStreamHandlerFactory
- StopWatch
- StreamArtifactResourceResolver
- Streams
- StringBuilderWriter
- StringConverter
- StringDeserializer
- StringSerializer
- StringToArrayConverter
- StringToBlockingDequeConverter
- StringToBlockingQueueConverter
- StringToBooleanConverter
- StringToByteConverter
- StringToCharArrayConverter
- StringToCharacterConverter
- StringToClassConverter
- StringToCollectionConverter
- StringToDequeConverter
- StringToDoubleConverter
- StringToDurationConverter
- StringToFloatConverter
- StringToInputStreamConverter
- StringToIntegerConverter
- StringToIterableConverter
- StringToListConverter
- StringToLongConverter
- StringToMultiValueConverter
- StringToNavigableSetConverter
- StringToQueueConverter
- StringToSetConverter
- StringToShortConverter
- StringToSortedSetConverter
- StringToStringConverter
- StringToTransferQueueConverter
- StringUtils
- SubProtocolURLConnectionFactory
- SymbolConstants
- SystemUtils
- ThrowableAction
- ThrowableBiConsumer
- ThrowableBiFunction
- ThrowableConsumer
- ThrowableFunction
- ThrowableSupplier
- ThrowableUtils
- TrueClassFilter
- TrueFileFilter
- TypeArgument
- TypeFinder
- TypeUtils
- URLClassPathHandle
- URLUtils
- UnmodifiableDeque
- UnmodifiableIterator
- UnmodifiableQueue
- Utils
- ValueHolder
- Version
- VersionUtils
- VirtualMachineProcessIdResolver
- Wrapper
- WrapperProcessor
jdk-tools
lang-model
- AnnotatedElementJSONElementVisitor
- AnnotationUtils
- ClassUtils
- ConstructorUtils
- ElementUtils
- ExecutableElementComparator
- FieldUtils
- JSONAnnotationValueVisitor
- JSONElementVisitor
- LoggerUtils
- MemberUtils
- MessagerUtils
- MethodUtils
- ResolvableAnnotationValueVisitor
- StringAnnotationValue
- TypeUtils
annotation-processor
- ConfigurationPropertyAnnotationProcessor
- ConfigurationPropertyJSONElementVisitor
- FilerProcessor
- ResourceProcessor
java-test
- AbstractAnnotationProcessingTest
- Ancestor
- AnnotationProcessingTestProcessor
- ArrayTypeModel
- CollectionTypeModel
- Color
- CompilerInvocationInterceptor
- ConfigurationPropertyModel
- DefaultTestService
- GenericTestService
- MapTypeModel
- Model
- Parent
- PrimitiveTypeModel
- SimpleTypeModel
- StringArrayList
- TestAnnotation
- TestService
- TestServiceImpl