Java Code Examples for com.helger.commons.wrapper.Wrapper#get()

The following examples show how to use com.helger.commons.wrapper.Wrapper#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMapBasedWALDAO.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
protected EChange onRead (@Nonnull final IMicroDocument aDoc)
{
  // Read all child elements independent of the name - soft migration
  final Class <IMPLTYPE> aDataTypeClass = getDataTypeClass ();
  final Wrapper <EChange> aChange = new Wrapper <> (EChange.UNCHANGED);

  aDoc.getDocumentElement ().forAllChildElements (m_aReadElementFilter, eItem -> {
    final IMPLTYPE aItem = MicroTypeConverter.convertToNative (eItem, aDataTypeClass);
    _addItem (aItem, EDAOActionType.CREATE);
    if (aItem instanceof IDAOReadChangeAware)
      if (((IDAOReadChangeAware) aItem).isReadChanged ())
      {
        // Remember that something was changed while reading
        aChange.set (EChange.CHANGED);
      }
  });
  return aChange.get ();
}
 
Example 2
Source File: MappedCache.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public VALUETYPE getFromCache (final KEYTYPE aKey)
{
  // Determine the internal key
  final KEYSTORETYPE aCacheKey = _getCacheKeyNonnull (aKey);

  Wrapper <VALUETYPE> aCacheValue = getFromCacheNoStats (aCacheKey);
  if (aCacheValue == null)
  {
    // No old value in the cache
    m_aRWLock.writeLock ().lock ();
    try
    {
      // Read again, in case the value was set between the two locking
      // sections
      // Note: do not increase statistics in this second try
      aCacheValue = getFromCacheNoStatsNotLocked (aCacheKey);
      if (aCacheValue == null)
      {
        // Call the value provide to create the value to cache
        final VALUETYPE aValue = m_aValueProvider.apply (aKey);
        aCacheValue = _getCacheValue (aKey, aValue);

        // Put the new value into the cache
        putInCacheNotLocked (aCacheKey, aCacheValue);
        m_aStatsCacheAccess.cacheMiss ();
      }
      else
        m_aStatsCacheAccess.cacheHit ();
    }
    finally
    {
      m_aRWLock.writeLock ().unlock ();
    }
  }
  else
    m_aStatsCacheAccess.cacheHit ();

  // the get() may resolve to a null value
  return aCacheValue.get ();
}