Using Smack Util - smacklib/dev_smack GitHub Wiki

CachedHolder

Goal is to change code sections like:

private String _value;

String getValue() {
  if ( _value == null )
    _value = constructValue();
  return _value;
}

to

private CachedHolder<String> _value =
    new CachedHolder<>( this::constructValue );

String getValue() {
  return _value.get();
}

That is, the class encapsulates the cache logic and simplifies the getter. On the other hand it allows to define the value including its initialization in one single place.

Note that the CachedHolder#reset()-operation allows to release the cached value. After a reset() the object stays usable and fetches the cached value on next access to get()again.

⚠️ **GitHub.com Fallback** ⚠️