Class CommonUtil

java.lang.Object
org.eclipse.emf.common.util.CommonUtil

public final class CommonUtil extends Object
Static utilities for string pooling.

As of EMF 2.9, the core runtime maintains a number of pools managed by weak references, specifically a string pool, a string array pool, a segment sequence pool, and a URI pool. The weak referenced are optionally managed by a daemon thread. The daemon thread is created by default only if there is no security manager, but that default can be overridden by specifying a true or false for the system property "org.eclipse.emf.common.util.ReferenceClearingQueue".

Since:
2.9
  • Method Details

    • intern

      public static String intern(String value)
      Returns an interned value for the string. If the value needs to be added to the pool, a copy will be added. This ensures that we pool only instances with minimally-sized underlying character arrays. Note that the {copy constructor shares the underlying character array of the original if it's already minimally sized, so the memory impact of interning a string already interned by Java is minimal. Note that you should use javaIntern(String) for interning string literals. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • internToLowerCase

      public static String internToLowerCase(String value)
      Returns the interned version of the lower case version of this string. It is equivalent to calling intern(value.toLowerCase(Locale.getDefaultLocale())), however, it's much faster, because the pool entry for the value itself weakly records the lower case variant. Please note that the default locale at the time this class was initialized applies. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • internToUpperCase

      public static String internToUpperCase(String value)
      Returns the interned version of the upper case version of this string. It is equivalent to calling intern(value.toUpperCase(Locale.getDefaultLocale())), however, it's much faster, because the pool entry for the value itself weakly records the upper case variant. Please note that the default locale at the time this class was initialized applies. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • javaIntern

      public static String javaIntern(String value)
      Returns an interned value for the string. If the value needs to be added to the pool, a Java interned version will be added. It is highly recommend that you only call this with string constants, i.e., with values that are Java interned already, because you will exhaust permgen space if you do this haphazardly. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced but because they are Java interned, unless already in the pool, they will never be garbage collected.
    • intern

      public static String intern(char[] characters, int offset, int count)
      Returns an interned string value for the subsequence of characters. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • intern

      public static String intern(String string, int offset, int count)
      Returns an interned string value for the subsequence of characters. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • intern

      public static String intern(CharSequence value)
      Returns an interned string value for the char sequence. This method is thread safe; the underlying representation supports shared read access and exclusive write access, holding locks for the shorted time possible to support maximal concurrency. The interned strings are weakly referenced so are only maintained only as long as there remain strong references.
    • newURL

      public static URL newURL(String literal) throws MalformedURLException
      Creates a URL.
      Parameters:
      literal - the url literal.
      Returns:
      the corresponding new URL.
      Throws:
      MalformedURLException
      Since:
      2.40