Class ThreadLocalReason.Closable

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Enclosing class:
    ThreadLocalReason

    public static class ThreadLocalReason.Closable
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Allows to use try-with-resources blocks for setting reasons

    Example:

    
     try (ThreadLocalReason.Closable closable = new ThreadLocalReason.Closable("Massban")) { // calls setCurrent("Massban")
         List<Member> mentions = event.getMessage().getMentionedMembers();
         Guild guild = event.getGuild();
         mentions.stream()
                 .map(m -> guild.ban(m, 7))
                 .forEach(RestAction::queue);
     } // calls resetCurrent()
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Closable​(java.lang.String reason)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Closable

        public Closable​(@Nullable
                        java.lang.String reason)
    • Method Detail

      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable