All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.auties.protobuf.builtin.ProtobufAtomicMixin Maven / Gradle / Ivy

The newest version!
package it.auties.protobuf.builtin;

import it.auties.protobuf.annotation.ProtobufDefaultValue;
import it.auties.protobuf.annotation.ProtobufDeserializer;
import it.auties.protobuf.annotation.ProtobufMixin;
import it.auties.protobuf.annotation.ProtobufSerializer;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

import static it.auties.protobuf.annotation.ProtobufDeserializer.BuilderBehaviour.OVERRIDE;

@SuppressWarnings("unused")
@ProtobufMixin
public class ProtobufAtomicMixin {
    @ProtobufDefaultValue
    public static AtomicInteger newAtomicInt() {
        return new AtomicInteger();
    }

    @ProtobufDefaultValue
    public static AtomicLong newAtomicLong() {
        return new AtomicLong();
    }

    @ProtobufDefaultValue
    public static AtomicBoolean newAtomicBoolean() {
        return new AtomicBoolean();
    }

    @ProtobufDefaultValue
    public static  AtomicReference newAtomicReference() {
        return new AtomicReference<>();
    }

    @ProtobufDeserializer(builderBehaviour = OVERRIDE)
    public static AtomicInteger ofAtomic(Integer value) {
        return value == null ? new AtomicInteger() : new AtomicInteger(value);
    }

    @ProtobufDeserializer(builderBehaviour = OVERRIDE)
    public static AtomicLong ofAtomic(Long value) {
        return value == null ? new AtomicLong() : new AtomicLong(value);
    }

    @ProtobufDeserializer(builderBehaviour = OVERRIDE)
    public static AtomicBoolean ofAtomic(Boolean value) {
        return value == null ? new AtomicBoolean() : new AtomicBoolean(value);
    }

    @ProtobufDeserializer(builderBehaviour = OVERRIDE)
    public static  AtomicReference ofAtomic(T value) {
        return new AtomicReference<>(value);
    }

    @ProtobufSerializer
    public static int toInt(AtomicInteger value) {
        return value.get();
    }

    @ProtobufSerializer
    public static long toLong(AtomicLong value) {
        return value.get();
    }

    @ProtobufSerializer
    public static boolean toBoolean(AtomicBoolean value) {
        return value.get();
    }

    @ProtobufSerializer
    public static  T toValue(AtomicReference value) {
        return value.get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy