Package org.xmpp.util

Class JIDWeigher

java.lang.Object
org.xmpp.util.JIDWeigher
All Implemented Interfaces:
com.github.benmanes.caffeine.cache.Weigher<String,ValueWrapper<String>>

@NullMarked public class JIDWeigher extends Object implements com.github.benmanes.caffeine.cache.Weigher<String,ValueWrapper<String>>
A Weigher that weights cache entries that contains JID parts. The weights that are used are byte-size based.
Author:
Guus der Kinderen, guus.der.kinderen@gmail.com
  • Constructor Details

    • JIDWeigher

      public JIDWeigher()
  • Method Details

    • weigh

      public int weigh(String key, ValueWrapper<String> value)
      Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply relative to each other.
      Specified by:
      weigh in interface com.github.benmanes.caffeine.cache.Weigher<String,ValueWrapper<String>>
      Parameters:
      key - the key to weigh
      value - the value to weigh
      Returns:
      the weight of the entry; must be non-negative
    • sizeOfString

      public static int sizeOfString(@Nullable String string)
      Returns the size in bytes of a String.
      Parameters:
      string - the String to determine the size of.
      Returns:
      the size of a String.
    • sizeOfValueWrapper

      public static int sizeOfValueWrapper(@Nullable ValueWrapper<String> value)
      Returns the size in bytes of a String.
      Parameters:
      value - the object to determine the size of.
      Returns:
      the size of the object.