Package lazyj

Class StringFactory

java.lang.Object
lazyj.StringFactory

public final class StringFactory
extends java.lang.Object
Keep references to common strings to avoid filling the memory with garbage. We don't use String.intern() any more because it seems to never clean up. Instead it is now relaying on a WeakHashMap.
Since:
Aug 10, 2007 (1.0.2)
Author:
costing
See Also:
String.intern()
  • Constructor Summary

    Constructors 
    Constructor Description
    StringFactory()  
  • Method Summary

    Modifier and Type Method Description
    static void clear()
    Deprecated. 
    static java.lang.String get​(byte[] vb)
    Get the global string pointer for this byte array
    static java.lang.String get​(char[] vc)
    Get the global string pointer for this char array
    static java.lang.String get​(java.lang.String s)
    Get the global string pointer for this value
    static long getAccessCount()
    Get the total number of accesses to this cache
    static int getCacheSize()
    Statistics function: the number of strings in the cache.
    static double getHitRatio()
    Calculate the cache efficiency (hits / total requests)
    static double getIgnoreRatio()
    Calculate the percentage of requests that were ignored because of size limits.
    static void resetHitCounters()
    Clear the counters

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • get

      public static java.lang.String get​(byte[] vb)
      Get the global string pointer for this byte array
      Parameters:
      vb -
      Returns:
      the global string pointer
    • get

      public static java.lang.String get​(char[] vc)
      Get the global string pointer for this char array
      Parameters:
      vc -
      Returns:
      the global string pointer
    • get

      public static java.lang.String get​(java.lang.String s)
      Get the global string pointer for this value
      Parameters:
      s -
      Returns:
      the global string pointer for an object having the same value
    • getCacheSize

      public static int getCacheSize()
      Statistics function: the number of strings in the cache.
      Returns:
      the number of strings in the cache
    • getHitRatio

      public static double getHitRatio()
      Calculate the cache efficiency (hits / total requests)
      Returns:
      cache efficiency
    • getIgnoreRatio

      public static double getIgnoreRatio()
      Calculate the percentage of requests that were ignored because of size limits.
      Returns:
      ignore ratio
    • getAccessCount

      public static long getAccessCount()
      Get the total number of accesses to this cache
      Returns:
      the number of accesses to this cache
    • resetHitCounters

      public static void resetHitCounters()
      Clear the counters
    • clear

      @Deprecated public static void clear()
      Deprecated.
      Clear this cache structure