Interface Container<K,V,O>

Type Parameters:
K - key type of the parent data.
V - values type of the parent data.
O - type of the contained object.
All Superinterfaces:
OptionalValue<O>
All Known Implementing Classes:
ContainerImpl, NonExistentContainer

public interface Container<K,V,O> extends OptionalValue<O>
This class holds a value from an AbstractData (called parent data). It offers several methods to process this value. All these methods will not have any effect on the parent data. The value can be accessed using the OptionalValue.get() method and processed with the process(Consumer) method.

Code examples

The following code will throw an exception if the json did not contain a key "some_key" or if its value was null. Otherwise, it will just print the value of "some_key":

  JsonParser parser = new JsonParser();
  SOData data = parser.parseReader(new StringReader("{...}"));

  data.getContainer("some_key")
          .requireNotNull()
          .process((Object o) -> System.out.println("some_key: " + o));
 

The following code will do nothing if the key "some_value" does not exist. It throws an exception if the key does exist, but its value is null. And it will print the value of "some_key" if this exists and its value is not null:

  JsonParser parser = new JsonParser();
  SOData data = parser.parseReader(new StringReader("{...}"));

  data.getContainer("some_key")
          .ifExists()
          .requireNotNull()
          .process((Object o) -> System.out.println("some_key: " + o));