Objectos 0.3.0 released: introduces Objectos Util

Marcio Endo
October 12, 2022

I am happy to announce the general availability of Objectos 0.3.0. This is the third public release of the Objectos suite of Java libraries in its new form.

Objectos 0.3.0 introduces Objectos Util.

Objectos Util

Objectos Util provides a special-purpose collections API to the Objectos libraries themselves. In other words, the collections API provided is not a general-purpose one.

As such, and at the current release, it contains a series of limitations.

Objectos Util also provides utilities for working with array instances.

Unmodifiable collections

Objectos Util provides unmodifiable implementations of the List, Set and Map interfaces:

var libraries = UnmodifiableSet.of(
    "Objectos Lang",
    "Objectos Util");

You can also use the Growable counterpart as a builder:

var builder = new GrowableList<String>();

builder.add("0.1.0");
builder.add("0.2.0");
builder.add("0.3.0");

var versions = builder.toUnmodifiableList();

Human-readable toString output

The List, Set and Map implementations provided by Objectos Util produce human-readable toString outputs.

Consider the following that maps Brazilian states to a few of their cities:

var states = new GrowableMap<State, List<City>>();

var cities = new GrowableList<City>();

cities.add(new City("São Paulo"));
cities.add(new City("Piracicaba"));
cities.add(new City("São José dos Campos"));

states.put(new State("SP"), cities.toUnmodifiableList());

cities.clear();

cities.add(new City("Belém"));
cities.add(new City("Santarém"));
cities.add(new City("Tomé-Açu"));

states.put(new State("PA"), cities.toUnmodifiableList());

System.out.println(states);

It produces the following output:

GrowableMap [
  State[abbr=SP] = UnmodifiableList [
    0 = City[name=São Paulo]
    1 = City[name=Piracicaba]
    2 = City[name=São José dos Campos]
  ]
  State[abbr=PA] = UnmodifiableList [
    0 = City[name=Belém]
    1 = City[name=Santarém]
    2 = City[name=Tomé-Açu]
  ]
]

Where both City and State are Java records:

public record City(String name) {}

public record State(String abbr) {}

Array utilities

Objectos Util provides utilities for creating "growable" arrays.

Here's a simple array list of double values:

import objectos.util.DoubleArrays;

public class DoubleList {
  private double[] values = DoubleArrays.empty();

  private int cursor = 0;

  public boolean add(double value) {
    values = DoubleArrays.growIfNecessary(values, cursor);
    values[cursor++] = value;
    return true;
  }

  public double sum() {
    var sum = 0d;
    for (var value : values) {
      sum += value;
    }
    return sum;
  }
}

Alpha release

With the zero-based version numbers we want to convey the idea that the API is of alpha quality and, therefore, subject to change.

What's next

You can find the full documentation here. It includes the full release notes as well.