Packages

  • package root

    Documentation for the Axiell Utilities Project

    Documentation for the Axiell Utilities Project

    Overview

    The Axiell Utilities Project attempts to provide a small library of classes and object applicable to most Axiell developments. The library is not geared towards any one project and so should be useful for new projects as well as existing ones.

    The library is based on a few simple principles, namely:

    • referential transparency. The principle that defines a call to a method with the same arguments will always return the same result and that the method does not have any side effects (e.g. updating global variables, etc).
    • functional programming support. If a method or class does have side effects then the method or class is marked as effectful. The library has been designed to not contain any effectful code.
    • minimal functionality. The library is designed to be small with support for a small number of common utilities. The main reason for the small size is to limit the number of dependencies drawn in by the package.

    Package structure

    The com.axiell.util package consists of a number of utilities, where each utility provides a single piece of functionality.

    Notable utilities are:

    • Configure generic configuration reader allowing application settings defined as resources to be interrogated.
    • Error generic error handling class defining a locale independent error message along with details relating to the context of the error. The context may include an exception and other relevant values.
    • Formatter retrieves and formats a locale specific string from a specified resource bundle. The formatting is specified in a C printf style.
    • Implicits implements implicit methods and classes used to pimp methods onto existing classes (e.g. fold() method to Boolean class) and to provide implicit implementations for the JsonLocal and ShowLocal type classes.
    • JsonLocal type class used to output locale specific JSON structures. Implementations exist for Message and Error.
    • Message provides a locale independent mechanism for handling strings. The strings for a given locale are stored in resource bundles that are accessed when the message is to be displayed.
    • ShowLocal type class used to show locale specific strings. Allows Message and Error to be converted to a given language string.

    Dependencies

    The list of dependencies are:

    • Typesafe Config a generic configuration file reader. The library is used by the Configure class to access settings stored as resources within an application.
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package axiell
    Definition Classes
    com
  • package util

    Axiell Utilities Project

    Axiell Utilities Project

    A set of classes and traits that provide a simple mechanism for the internationalisation of strings and error handling. A mechanism is also supplied to read an application's configuration resource. All methods have been designed to be referentially transparent without the introduction of an effectful library (e.g. cats).

    Imports

    The utility classes/traits can be imported in the usual way, however it is necessary to include the Implicits object if the showLocal and jsonLocal type class methods are used, similarly for the read method on Configure.

    Example:

    import com.axiell.util.Implicits._

    A shorthand way to gain access to all utility classes is to import:

    import com.axiell.util._
    import com.axiell.util.Implicits._

    For more detail on project see the root package page.

    Definition Classes
    axiell
  • package instances

    Contains implicit values used by type classes.

    Contains implicit values used by type classes.

    The implicit values are used by the ShowLocal, JsonLocal and ConfigureReader type classes to print out language dependent strings, language dependent JSON strings and read configuration values respectively.

    Implicit values exist for the following classes:

    • ConfigureReader (read)
    • Error (showLocal, jsonLocal)
    • Int (showLocal, jsonLocal)
    • List (showLocal, jsonLocal)
    • Message (showLocal, jsonLocal)
    • java.time.OffsetDateTime (showLocal, jsonLocal)
    • java.lang.String (showLocal, jsonLocal)
    • java.lang.Throwable (showLocal, jsonLocal)

    The method names appended in brackets are the extension methods added by the implicit values.

    Definition Classes
    util
  • package syntax

    Contains implicit classes used to add extension methods.

    Contains implicit classes used to add extension methods.

    The implicit classes are used to add the following extension methods:

    • showLocal displays a language dependent version of an object
    • jsonLocal generates a JSON string with language dependent strings
    • masonLocal generates a Mason Draft 2 compliant JSON string for Error
    • fold functionality for Boolean type

    All traits found in the package are for the implementation of extension methods. The traits are mixed into the Implicits object so they can be easily imported into clients when required.

    Definition Classes
    util
  • Configure
  • ConfigureReader
  • Error
  • ErrorException
  • Formatter
  • Implicits
  • JsonLocal
  • Message
  • MessageBundle
  • ShowLocal

object Formatter

Creates a Formatter used to access strings for a given locale stored in a given bundle.

The support for language specific strings involves two values. The first is a MessageBundle that defines the name of a class containing language dependent strings. The second value is the java.util.Locale used to select the set of language strings to be accessed. When a Formatter is created an attempt is made to load the supplied bundle with the given locale. If the loading succeeds then the strings may be accessed via the returned Formatter.

The current class loader is used to try and load the bundle class. The bundle class must extend java.util.ListResourceBundle. The class name may have a language code (e.g. _en) appended indicating the language whose strings are defined in the class. A class name without a language extension is the default bundle, used when a language specific version cannot be found.

Example:

package com.acme

class Resources extends java.util.ListResourceBundle {
  final override val getContents: Array[Array[AnyRef]] =
    Array(
      Array("BadValue", "The bad value is %s")
      ...
    )
}

class Resources_de extends java.util.ListResourceBundle {
  final override val getContents: Array[Array[AnyRef]] =
    Array(
      Array("BadValue", "Der falsche Wert ist %s")
      ...
    )
}

The above bundle classes define strings for German (Resources_de) and the default bundle (Resources). When defining bundles it makes sense to define all languages within a single file.

Referential Transparency

The string resources are stored in a class and read as a java.util.ListResourceBundle. The strings are constants defined in a class ensuring that the same value is always returned for the same arguments. The read-only nature of the resource class ensures the Formatter methods are referentially transparent and so not effectful.

Source
Formatter.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Formatter
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply(bundle: MessageBundle, locale: Locale): Either[Error, Formatter]

    Creates a Formatter tied to a given bundle and locale.

    Creates a Formatter tied to a given bundle and locale.

    The name of the bundle defines a resource containing language dependent strings. The locale determines the language of the set of strings to be accessed. For full details on the locations of the resource bundle see java.util.ResourceBundle. If the requested bundle cannot be loaded then an error is returned.

    Example:

    package com.acme
    
    class Resources_en extends java.util.ListResourceBundle {
      final override val getContents: Array[Array[AnyRef]] =
        Array(
          Array("BadValue", "The bad value is %s")
          ...
        )
    }
    
    class Resources_de extends java.util.ListResourceBundle {
      final override val getContents: Array[Array[AnyRef]] =
        Array(
          Array("BadValue", "Der falsche Wert ist %s")
          ...
        )
    }
    
    Formatter(MessageBundle("com.acme.Resources"), Locale.ENGLISH)
    bundle

    to retrieve strings from

    locale

    of the language for the strings to retrieve

    returns

    Formatter used to access the locale specific strings stored in the bundle, otherwise an Error

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped