Class RsLangs

java.lang.Object
org.apache.uima.analysis_engine.impl.RsLangs

public class RsLangs extends Object
A set of languages, each represented by a canonical string object The set is stored without any subsumed elements Instances of this class are shareable Duplicate-on-update strategy Requires that all update operations to it return the possibly new RsLangs object, and that calls are always of the form rsLangInstance = rsLangInstance.[some-update-operation] Requires that all copy operations set the shared bit: copiedInstance = origInstance.setShared(); A instance marked isShared == true is immutable Updates cause duplication. Users store x-unspecified as null for the rsLangs instance Because of this, users use static methods, passing in as the first argument, the value of rsLangs, and getting an updated value of rsLangs. This allows the passed-in value to be null. Languages kept in canonical form: duplicates removed subsumed languages removed language strings mapped to unique strings (allowing == comparisons) Languages kept in array list, to allow for expansion Languages not removed, only added (for a given tof)
  • Field Details

    • languages

      private ArrayList<String> languages
    • isShared

      private boolean isShared
  • Constructor Details

    • RsLangs

      private RsLangs()
    • RsLangs

      private RsLangs(RsLangs original)
  • Method Details

    • createSharableEmpty

      static RsLangs createSharableEmpty()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createOrNull

      static RsLangs createOrNull(String[] languages)
    • setShared

      void setShared()
    • createOrNull

      static RsLangs createOrNull(RsLangs rsl)
    • isEmpty

      static boolean isEmpty(RsLangs rsl)
    • subsumes

      static boolean subsumes(RsLangs rsl, String lang)
      Parameters:
      rsl - may be null (means x-unspec, subsumes all)
      lang -
      Returns:
      true if rsl subsumes lang
    • subsumesCanonical

      static boolean subsumesCanonical(RsLangs rsl, String lang)
      Parameters:
      lang -
      Returns:
      true if any of the rsLangs subsumes the param lang
    • subsumesCanonical

      private static boolean subsumesCanonical(RsLangs rsl, String lang, String baseLang)
      Parameters:
      rsl - assumed to be not null, not x-unspec
      lang - assumed to be not null, not x-unspec
      baseLang -
      Returns:
      true if any of the rsl languages is equal to the lang or the base lang
    • subsumesCanonical

      private static boolean subsumesCanonical(String containingLang, String langToTest, String langToTestBase)
    • getBaseLanguage

      private static String getBaseLanguage(String language)
      Parameters:
      language - (must not be null)
      Returns:
      the same == language or the base form of the language
    • replaceAll

      static RsLangs replaceAll(RsLangs rsl, String[] langs)
      Parameters:
      rsl - could be null meaning current is x-unspecified
      langs - null means x-unspecified
      Returns:
      null (meaning x-unspecified, or an instance of RsLangs
    • addAll

      static RsLangs addAll(RsLangs rsl, String[] langs)
    • addAll

      static RsLangs addAll(RsLangs rsl, RsLangs rsLangs)
    • add

      static RsLangs add(RsLangs rsl, String lang)
      add language unless it's subsumed by existing one remove any languages the newly added one subsumes store x-unspec as null
      Parameters:
      rsl - - is not null and has non-null languages array (may be empty)
      lang - - may be null or x-unspec
    • removeSubsumedLanguages

      private void removeSubsumedLanguages(String canonicalLang, String baseLang)
      Remove languages that are subsumed by the argument If all removed, keep as empty list
      Parameters:
      canonicalLang -
    • intersect

      RsLangs intersect(RsLangs other)
      Parameters:
      other -
      Returns:
      null for empty intersection (null doesn't mean x-unspecified here)
    • toArray

      static String[] toArray(RsLangs rsl)
    • hashCode

      public int hashCode()
      Must return the same hashcode regardless of the value of isShared, and treating the values as a set
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      This must return true ignoring the value of isShared, and treating the lists as a set
      Overrides:
      equals in class Object