Class SyncVarImpl<T>

java.lang.Object
de.linusdev.lutils.thready.var.SyncVarImpl<T>
All Implemented Interfaces:
SyncVar<T>

public class SyncVarImpl<T> extends Object implements SyncVar<T>
  • Constructor Details

    • SyncVarImpl

      public SyncVarImpl(@Nullable T var)
  • Method Details

    • get

      @Nullable public T get()
      Description copied from interface: SyncVar
      Synchronised get.
      Specified by:
      get in interface SyncVar<T>
      Returns:
      value of this variable
    • doSynchronised

      public void doSynchronised(@NotNull @NotNull Consumer<@NotNull SyncVar<T>> consumer)
      Description copied from interface: SyncVar
      Execute given consumer synchronised on this variable.
      Specified by:
      doSynchronised in interface SyncVar<T>
      Parameters:
      consumer - Consumer
    • consumeIfNotNull

      public boolean consumeIfNotNull(@NotNull @NotNull Consumer<@NotNull T> consumer)
      Description copied from interface: SyncVar
      locks on this variable and checks if its value is not null. If that is the case, given consumer will be executed, while keeping the lock on the variable.
      Specified by:
      consumeIfNotNull in interface SyncVar<T>
      Parameters:
      consumer - to consume the variable
      Returns:
      true if given consumer was executed. false otherwise.
    • setIfNull

      public boolean setIfNull(@Nullable T value)
      Description copied from interface: SyncVar
      Sets the variables value if it is null. thread safe.
      Specified by:
      setIfNull in interface SyncVar<T>
      Parameters:
      value - the value to set
      Returns:
      true if this variables value was null
    • setIfNull

      public boolean setIfNull(@NotNull @NotNull Supplier<T> supplier)
      Description copied from interface: SyncVar
      Specified by:
      setIfNull in interface SyncVar<T>
    • set

      public void set(@Nullable T value)
      Description copied from interface: SyncVar
      Synchronised set.
      Specified by:
      set in interface SyncVar<T>
      Parameters:
      value - the variables value