Java Code Examples for com.helger.commons.state.EChange#UNCHANGED

The following examples show how to use com.helger.commons.state.EChange#UNCHANGED . 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: ICommonsCollection.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Add all elements of the passed enumeration to this collection.
 *
 * @param aEnum
 *        The enumeration to be iterated and the elements to be added. May be
 *        <code>null</code>.
 * @param aFilter
 *        The filter to be applied. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one element was added,
 *         {@link EChange#UNCHANGED}. Never <code>null</code>.
 * @since 8.5.2
 */
@Nonnull
default EChange addAll (@Nullable final Enumeration <? extends ELEMENTTYPE> aEnum,
                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (aFilter == null)
    return addAll (aEnum);

  EChange eChange = EChange.UNCHANGED;
  if (aEnum != null)
    while (aEnum.hasMoreElements ())
    {
      final ELEMENTTYPE aElement = aEnum.nextElement ();
      if (aFilter.test (aElement))
        eChange = eChange.or (add (aElement));
    }
  return eChange;
}
 
Example 2
Source File: ICommonsMap.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
default EChange removeIf (@Nonnull final Predicate <? super Map.Entry <? extends KEYTYPE, ? extends VALUETYPE>> aFilter)
{
  ValueEnforcer.notNull (aFilter, "Filter");
  EChange ret = EChange.UNCHANGED;
  final Iterator <Map.Entry <KEYTYPE, VALUETYPE>> it = entrySet ().iterator ();
  while (it.hasNext ())
  {
    if (aFilter.test (it.next ()))
    {
      it.remove ();
      ret = EChange.CHANGED;
    }
  }
  return ret;
}
 
Example 3
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Add all passed elements matching the provided filter after performing a
 * mapping using the provided function.
 *
 * @param aElements
 *        The elements to be added after mapping. May be <code>null</code>.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not be <code>null</code>.
 * @param aFilter
 *        The filter to be applied on the mapped element. May be
 *        <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one element was added,
 *         {@link EChange#UNCHANGED}. Never <code>null</code>.
 * @param <SRCTYPE>
 *        The source type to be mapped from
 * @since 8.5.2
 */
@Nonnull
default <SRCTYPE> EChange addAllMapped (@Nullable final SRCTYPE [] aElements,
                                        @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper,
                                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

  if (aFilter == null)
    return addAllMapped (aElements, aMapper);

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final SRCTYPE aValue : aElements)
    {
      final ELEMENTTYPE aMapped = aMapper.apply (aValue);
      if (aFilter.test (aMapped))
        eChange = eChange.or (add (aMapped));
    }
  return eChange;
}
 
Example 4
Source File: MappedCache.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
@OverridingMethodsMustInvokeSuper
public EChange removeFromCache (final KEYTYPE aKey)
{
  final KEYSTORETYPE aCacheKey = _getCacheKeyNonnull (aKey);

  m_aRWLock.writeLock ().lock ();
  try
  {
    if (m_aCache == null || m_aCache.remove (aCacheKey) == null)
      return EChange.UNCHANGED;
  }
  finally
  {
    m_aRWLock.writeLock ().unlock ();
  }

  m_aStatsCountRemove.increment ();
  if (LOGGER.isDebugEnabled ())
    LOGGER.debug (_getCacheLogText () + "Cache key '" + aKey + "' was removed.");
  return EChange.CHANGED;
}
 
Example 5
Source File: Graph.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
public EChange removeNodeAndAllRelations (@Nonnull final IMutableGraphNode aNode)
{
  ValueEnforcer.notNull (aNode, "Node");

  if (!m_aNodes.containsKey (aNode.getID ()))
    return EChange.UNCHANGED;

  // Remove all affected relations from all nodes
  for (final IMutableGraphRelation aRelation : aNode.getAllRelations ())
    for (final IMutableGraphNode aNode2 : aRelation.getAllConnectedNodes ())
      aNode2.removeRelation (aRelation);

  // Remove the node itself
  if (removeNode (aNode).isUnchanged ())
    throw new IllegalStateException ("Inconsistency removing node and all relations");
  return EChange.CHANGED;
}
 
Example 6
Source File: MutableBigDecimal.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange set (@Nonnull final BigDecimal aValue)
{
  ValueEnforcer.notNull (aValue, "Value");
  if (aValue.equals (m_aValue))
    return EChange.UNCHANGED;
  m_aValue = aValue;
  onAfterChange ();
  return EChange.CHANGED;
}
 
Example 7
Source File: IAttributeContainer.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
default EChange putAllIn (@Nullable final Map <? extends KEYTYPE, ? extends VALUETYPE> aAttrs)
{
  EChange eChange = EChange.UNCHANGED;
  if (aAttrs != null)
    for (final Map.Entry <? extends KEYTYPE, ? extends VALUETYPE> aEntry : aAttrs.entrySet ())
      eChange = eChange.or (putIn (aEntry.getKey (), aEntry.getValue ()));
  return eChange;
}
 
Example 8
Source File: MapBasedXPathVariableResolverQName.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the variable with the specified name.
 *
 * @param aName
 *        The name to be removed. May be <code>null</code>.
 * @return {@link EChange}
 */
@Nonnull
public EChange removeVariable (@Nullable final QName aName)
{
  if (aName == null)
    return EChange.UNCHANGED;
  return m_aMap.removeObject (aName);
}
 
Example 9
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all elements of the passed enumeration to this collection.
 *
 * @param aEnum
 *        The enumeration to be iterated and the elements to be added. May be
 *        <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one element was added,
 *         {@link EChange#UNCHANGED}. Never <code>null</code>.
 */
@Nonnull
default EChange addAll (@Nullable final Enumeration <? extends ELEMENTTYPE> aEnum)
{
  EChange eChange = EChange.UNCHANGED;
  if (aEnum != null)
    while (aEnum.hasMoreElements ())
      eChange = eChange.or (add (aEnum.nextElement ()));
  return eChange;
}
 
Example 10
Source File: DOMReaderSettings.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public final EChange removeFeature (@Nullable final EXMLParserFeature eFeature)
{
  if (eFeature == null)
    return EChange.UNCHANGED;
  return m_aFeatures.removeObject (eFeature);
}
 
Example 11
Source File: Graph.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange removeAll ()
{
  if (m_aNodes.removeAll ().isUnchanged ())
    return EChange.UNCHANGED;

  _invalidateCache ();
  return EChange.CHANGED;
}
 
Example 12
Source File: GenericJAXBMarshaller.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Set the charset to be used for writing JAXB objects.
 *
 * @param aCharset
 *        The charset to be used by default. May be <code>null</code>.
 * @return {@link EChange}
 * @since 8.5.3
 */
@Nonnull
public final EChange setCharset (@Nullable final Charset aCharset)
{
  if (EqualsHelper.equals (aCharset, m_aCharset))
    return EChange.UNCHANGED;
  m_aCharset = aCharset;
  return EChange.CHANGED;
}
 
Example 13
Source File: GenericJAXBMarshaller.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Set the namespace context (prefix to namespace URL mapping) to be used.
 *
 * @param aNSContext
 *        The namespace context to be used. May be <code>null</code>.
 * @return {@link EChange}
 * @since 8.5.3
 */
@Nonnull
public final EChange setNamespaceContext (@Nullable final INamespaceContext aNSContext)
{
  if (EqualsHelper.equals (aNSContext, m_aNSContext))
    return EChange.UNCHANGED;
  m_aNSContext = aNSContext;
  return EChange.CHANGED;
}
 
Example 14
Source File: MutableInt.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange set (final int nValue)
{
  if (m_nValue == nValue)
    return EChange.UNCHANGED;
  m_nValue = nValue;
  onAfterChange ();
  return EChange.CHANGED;
}
 
Example 15
Source File: Pair.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange setSecond (@Nullable final DATA2TYPE aSecond)
{
  if (EqualsHelper.equals (aSecond, m_aSecond))
    return EChange.UNCHANGED;
  m_aSecond = aSecond;
  return EChange.CHANGED;
}
 
Example 16
Source File: Pair.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange setFirst (@Nullable final DATA1TYPE aFirst)
{
  if (EqualsHelper.equals (aFirst, m_aFirst))
    return EChange.UNCHANGED;
  m_aFirst = aFirst;
  return EChange.CHANGED;
}
 
Example 17
Source File: MapBasedXPathFunctionResolver.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all functions from the other function resolver into this resolver.
 *
 * @param aOther
 *        The function resolver to import the functions from. May not be
 *        <code>null</code>.
 * @param bOverwrite
 *        if <code>true</code> existing functions will be overwritten with the
 *        new functions, otherwise the old functions are kept.
 * @return {@link EChange}
 */
@Nonnull
public EChange addAllFrom (@Nonnull final MapBasedXPathFunctionResolver aOther, final boolean bOverwrite)
{
  ValueEnforcer.notNull (aOther, "Other");
  EChange eChange = EChange.UNCHANGED;
  for (final Map.Entry <XPathFunctionKey, XPathFunction> aEntry : aOther.m_aMap.entrySet ())
    if (bOverwrite || !m_aMap.containsKey (aEntry.getKey ()))
    {
      m_aMap.put (aEntry.getKey (), aEntry.getValue ());
      eChange = EChange.CHANGED;
    }
  return eChange;
}
 
Example 18
Source File: SimpleDAOFuncTest.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
protected EChange onRead (@Nonnull final IMicroDocument aDoc)
{
  return EChange.UNCHANGED;
}
 
Example 19
Source File: AbstractWALDAO.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Custom initialization routine. Called only if the underlying file does not
 * exist yet. This method is only called within a write lock!
 *
 * @return {@link EChange#CHANGED} if something was modified inside this
 *         method
 */
@Nonnull
@OverrideOnDemand
protected EChange onInit ()
{
  return EChange.UNCHANGED;
}
 
Example 20
Source File: GenericJAXBMarshaller.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Set the no namespace schema location to be used for writing JAXB objects.
 *
 * @param sNoNamespaceSchemaLocation
 *        The no namespace schema location to be used. May be
 *        <code>null</code>.
 * @return {@link EChange}
 * @since 9.0.0
 */
@Nonnull
public final EChange setNoNamespaceSchemaLocation (@Nullable final String sNoNamespaceSchemaLocation)
{
  if (EqualsHelper.equals (sNoNamespaceSchemaLocation, m_sNoNamespaceSchemaLocation))
    return EChange.UNCHANGED;
  m_sNoNamespaceSchemaLocation = sNoNamespaceSchemaLocation;
  return EChange.CHANGED;
}