Class ResourceInternationalString

java.lang.Object
org.apache.sis.util.AbstractInternationalString
org.apache.sis.util.resources.ResourceInternationalString
All Implemented Interfaces:
Serializable, CharSequence, Comparable<org.opengis.util.InternationalString>, Formattable, org.opengis.util.InternationalString
Direct Known Subclasses:
Errors.International, Messages.International, Resources.International, Resources.International, Resources.International, Resources.International, Resources.International, Resources.International, Resources.International, Vocabulary.International

public abstract class ResourceInternationalString extends AbstractInternationalString implements Serializable
A copy of ResourceInternationalString specialized for IndexedResourceBundle. Compared to the public class, this specialization works with integer resource keys and accepts arguments.

Immutability and thread safety

This base class is immutable and thus inherently thread-safe.
Since:
0.8
Version:
1.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial number for inter-operability with different versions.
      See Also:
    • key

      private transient short key
      The key for the resource to fetch.
    • hasArguments

      private final boolean hasArguments
      true if the key has arguments. If false, then the arguments field shall be ignored. We cannot rely on null arguments value because null may be a valid value.
    • arguments

      private final Object arguments
      The argument(s), or null if none. Note that the user may also really want to specify null as an argument value. We distinguish the two cases with the sign of the key value.
  • Constructor Details

    • ResourceInternationalString

      protected ResourceInternationalString(short key)
      Creates a new international string for the given key.
      Parameters:
      key - the key for the resource to fetch.
    • ResourceInternationalString

      protected ResourceInternationalString(short key, Object arguments)
      Creates a new international string for the given key and arguments.
      Parameters:
      key - the key for the resource to fetch.
      arguments - the argument(s).
  • Method Details

    • getKeyConstants

      protected abstract KeyConstants getKeyConstants()
      Returns a handler for the constants declared in the inner Keys class. This is used at serialization time in order to serialize the constant name rather than its numeric value.
      Returns:
      a handler for the constants declared in the inner Keys class.
    • getBundle

      protected abstract IndexedResourceBundle getBundle(Locale locale)
      Returns the resource bundle for the given locale.
      Parameters:
      locale - the locale for which to get the resource bundle, or null for the default locale.
      Returns:
      the resource bundle for the given locale.
    • toLogRecord

      public final LogRecord toLogRecord(Level level)
      Converts this international string to a log record.
      Parameters:
      level - the logging level.
      Returns:
      a log record with the message of this international string.
      Since:
      1.0
    • toString

      public final String toString(Locale locale) throws MissingResourceException
      Returns a string in the specified locale.
      Specified by:
      toString in interface org.opengis.util.InternationalString
      Specified by:
      toString in class AbstractInternationalString
      Parameters:
      locale - the desired locale for the string to be returned.
      Returns:
      the string in the specified locale, or in a fallback locale.
      Throws:
      MissingResourceException - if the key given to the constructor is invalid.
      See Also:
    • equals

      public final boolean equals(Object object)
      Compares this international string with the specified object for equality. Two ResourceInternationalString are considered equal if they are of the same class and have been constructed with equal arguments.
      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this international string.
      Returns:
      true if the given object is equal to this string.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this international text.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for this international text.
    • writeObject

      private void writeObject(ObjectOutputStream out) throws IOException
      Serializes this international string using the key name rather than numerical value.
      Parameters:
      out - the output stream where to serialize this object.
      Throws:
      IOException - if an I/O error occurred while writing.
    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Deserializes an object serialized by writeObject(ObjectOutputStream).
      Parameters:
      in - the input stream from which to deserialize an object.
      Throws:
      IOException - if an I/O error occurred while reading or if the stream contains invalid data.
      ClassNotFoundException - if the class serialized on the stream is not on the classpath.