Tod Commons organization logo
Home Usage: 1.1 Repo Wiki

Tod Commons implements basic utilities for

  • logging
  • building info
  • versioning
  • immutability
  • multilingual strings such as LocalizedString and Dict
  • validation
  • time representation

Maven

Tod Commons is available on Maven Central. To use it, put this in the dependencies section of your pom.xml:

    <dependency>
        <groupId>eu.trentorise.opendata</groupId>
        <artifactId>tod-commons</artifactId>
        <version>1.1.0</version>
    </dependency>

In case updates are available, version numbers follows semantic versioning rules.

Building objects

Most objects in tod-commons are immutable, and make heavy use of Guava immutable collections . In tod-commons, wherever you see an abstract class called ASomething or AbstractSomething, there will always be an immutable class Something implementing it.

Immutable classes don't have public constructors, they only have factory methods starting with of():

    LocalizedString myLocalizedString = LocalizedString.of(Locale.ITALIAN, "ciao");

Default language is always Locale.ROOT:

    LocalizedString localizedString = LocalizedString.of("string with unknwon language");

    assert Locale.ROOT.equals(localizedString.getLocale());

Generally, we are null hostile:

    try {
        LocalizedString.of(null);
    } catch(NullPointerException ex){

    }

Dicts are immutable multimaps with builders. Factory method for a Dict:

    Dict.of(Locale.ENGLISH, "hello", "my friend");

Building a Dict:

    Dict myDict = Dict.builder().put(Locale.ENGLISH, "hello")
                                .put(Locale.ENGLISH, "hello again")
                                .put(Locale.ITALIAN, "ciao")
                                .build();

    assert "hello".equals(myDict.string(Locale.ENGLISH));
    assert "hello again".equals(myDict.strings(Locale.ENGLISH).get(1)); 
    assert "ciao".equals(myDict.string(Locale.ITALIAN)); 

Logging

Tod-Commons uses native Java logging system (JUL). If you also use JUL in your application and want to see Tod-Commons logs, you can take inspiration from tod-commons test logging properties. If you have an application which uses SLF4J logging system, you can route logging with JUL to SLF4J bridge, just remember to programmatically install it first.