Class MiscUtil


  • public class MiscUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      MiscUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void appendTo​(java.util.Formatter formatter, int width, int precision, boolean leftJustified, java.lang.String out)
      Can be used to append a String to a formatter.
      static int getShardForGuild​(long guildId, int shards)
      Returns the shard id the given guild will be loaded on for the given amount of shards.
      static int getShardForGuild​(java.lang.String guildId, int shards)
      Returns the shard id the given guild will be loaded on for the given amount of shards.
      static int getShardForGuild​(Guild guild, int shards)
      Returns the shard id the given Guild will be loaded on for the given amount of shards.
      static void locked​(java.util.concurrent.locks.ReentrantLock lock, java.lang.Runnable task)  
      static <E> E locked​(java.util.concurrent.locks.ReentrantLock lock, java.util.function.Supplier<E> task)  
      static <T> gnu.trove.map.TLongObjectMap<T> newLongMap()
      Generates a new thread-safe TLongObjectMap
      static long parseLong​(java.lang.String input)  
      static long parseSnowflake​(java.lang.String input)  
      static void tryLock​(java.util.concurrent.locks.Lock lock)
      Tries to acquire the provided lock in a 10 second timeframe.
      • Methods inherited from class java.lang.Object

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

      • MiscUtil

        public MiscUtil()
    • Method Detail

      • getShardForGuild

        public static int getShardForGuild​(long guildId,
                                           int shards)
        Returns the shard id the given guild will be loaded on for the given amount of shards. Discord determines which guilds a shard is connect to using the following format: shardId == (guildId >>> 22) % totalShards
        Source for formula: Discord Documentation
        Parameters:
        guildId - The guild id.
        shards - The amount of shards.
        Returns:
        The shard id for the guild.
      • getShardForGuild

        public static int getShardForGuild​(java.lang.String guildId,
                                           int shards)
        Returns the shard id the given guild will be loaded on for the given amount of shards. Discord determines which guilds a shard is connect to using the following format: shardId == (guildId >>> 22) % totalShards
        Source for formula: Discord Documentation
        Parameters:
        guildId - The guild id.
        shards - The amount of shards.
        Returns:
        The shard id for the guild.
      • getShardForGuild

        public static int getShardForGuild​(Guild guild,
                                           int shards)
        Returns the shard id the given Guild will be loaded on for the given amount of shards. Discord determines which guilds a shard is connect to using the following format: shardId == (guildId >>> 22) % totalShards
        Source for formula: Discord Documentation
        Parameters:
        guild - The guild.
        shards - The amount of shards.
        Returns:
        The shard id for the guild.
      • newLongMap

        public static <T> gnu.trove.map.TLongObjectMap<T> newLongMap()
        Generates a new thread-safe TLongObjectMap
        Type Parameters:
        T - The Object type
        Returns:
        a new thread-safe TLongObjectMap
      • parseLong

        public static long parseLong​(java.lang.String input)
      • parseSnowflake

        public static long parseSnowflake​(java.lang.String input)
      • locked

        public static <E> E locked​(java.util.concurrent.locks.ReentrantLock lock,
                                   java.util.function.Supplier<E> task)
      • locked

        public static void locked​(java.util.concurrent.locks.ReentrantLock lock,
                                  java.lang.Runnable task)
      • tryLock

        public static void tryLock​(java.util.concurrent.locks.Lock lock)
        Tries to acquire the provided lock in a 10 second timeframe.
        Parameters:
        lock - The lock to acquire
        Throws:
        java.lang.IllegalStateException - If the lock could not be acquired
      • appendTo

        public static void appendTo​(java.util.Formatter formatter,
                                    int width,
                                    int precision,
                                    boolean leftJustified,
                                    java.lang.String out)
        Can be used to append a String to a formatter.
        Parameters:
        formatter - The Formatter
        width - Minimum width to meet, filled with space if needed
        precision - Maximum amount of characters to append
        leftJustified - Whether or not to left-justify the value
        out - The String to append