Java Code Examples for com.helger.commons.state.EChange#or()

The following examples show how to use com.helger.commons.state.EChange#or() . 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 iterator to this collection.
 *
 * @param aIter
 *        The iterator 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 Iterator <? extends ELEMENTTYPE> aIter,
                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (aFilter == null)
    return addAll (aIter);

  EChange eChange = EChange.UNCHANGED;
  if (aIter != null)
    while (aIter.hasNext ())
    {
      final ELEMENTTYPE aElement = aIter.next ();
      if (aFilter.test (aElement))
        eChange = eChange.or (add (aElement));
    }
  return eChange;
}
 
Example 2
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 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 aFilter
 *        The filter to be applied. May be <code>null</code>.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not 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
 */
@Nonnull
default <SRCTYPE> EChange addAllMapped (@Nullable final Iterable <? extends SRCTYPE> aElements,
                                        @Nullable final Predicate <? super SRCTYPE> aFilter,
                                        @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

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

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final SRCTYPE aValue : aElements)
      if (aFilter.test (aValue))
        eChange = eChange.or (add (aMapper.apply (aValue)));
  return eChange;
}
 
Example 4
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 Iterable <? extends 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 5
Source File: IMultiMapMapBased.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all values into the container identified by the passed key-value-map.
 *
 * @param aMap
 *        The key-value-map to use. May not be <code>null</code>.
 * @return {@link EChange}
 */
@Nonnull
default EChange putAllIn (@Nonnull final Map <? extends KEYTYPE1, ? extends Map <KEYTYPE2, VALUETYPE>> aMap)
{
  EChange eChange = EChange.UNCHANGED;
  for (final Map.Entry <? extends KEYTYPE1, ? extends Map <KEYTYPE2, VALUETYPE>> aEntry : aMap.entrySet ())
    for (final Map.Entry <KEYTYPE2, VALUETYPE> aEntry2 : aEntry.getValue ().entrySet ())
      eChange = eChange.or (putSingle (aEntry.getKey (), aEntry2.getKey (), aEntry2.getValue ()));
  return eChange;
}
 
Example 6
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all elements of the passed iterable to this collection.
 *
 * @param aElements
 *        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 Iterable <? extends ELEMENTTYPE> aElements,
                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (aFilter == null)
    return addAll (aElements);

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final ELEMENTTYPE aElement : aElements)
      if (aFilter.test (aElement))
        eChange = eChange.or (add (aElement));
  return eChange;
}
 
Example 7
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all matching elements of an array this collection.
 *
 * @param aElements
 *        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 ELEMENTTYPE [] aElements,
                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  if (aFilter == null)
    return addAll (aElements);

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final ELEMENTTYPE aElement : aElements)
      if (aFilter.test (aElement))
        eChange = eChange.or (add (aElement));
  return eChange;
}
 
Example 8
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 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 iterable to this collection.
 *
 * @param aElements
 *        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 Iterable <? extends ELEMENTTYPE> aElements)
{
  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final ELEMENTTYPE aElement : aElements)
      eChange = eChange.or (add (aElement));
  return eChange;
}
 
Example 10
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add an array of elements to this collection.
 *
 * @param aElements
 *        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 (@SuppressWarnings ("unchecked") @Nullable final ELEMENTTYPE... aElements)
{
  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final ELEMENTTYPE aElement : aElements)
      eChange = eChange.or (add (aElement));
  return eChange;
}
 
Example 11
Source File: PSXPathVariables.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all variables with the specified names
 *
 * @param aVars
 *        A list of variable names to be removed. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one variable was removed
 *         successfully. Never <code>null</code>.
 */
@Nonnull
public EChange removeAll (@Nullable final Iterable <String> aVars)
{
  EChange eChange = EChange.UNCHANGED;
  if (aVars != null)
    for (final String sName : aVars)
      eChange = eChange.or (remove (sName));
  return eChange;
}
 
Example 12
Source File: MapBasedXPathFunctionResolver.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove all functions with the same name. This can be helpful when the same
 * function is registered for multiple parameters.
 *
 * @param aName
 *        The name to be removed. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one function was removed.
 */
@Nonnull
public EChange removeFunctionsWithName (@Nullable final QName aName)
{
  EChange eChange = EChange.UNCHANGED;
  if (aName != null)
  {
    // Make a copy of the key set to allow for inline modification
    for (final XPathFunctionKey aKey : m_aMap.copyOfKeySet ())
      if (aKey.getFunctionName ().equals (aName))
        eChange = eChange.or (removeFunction (aKey));
  }
  return eChange;
}
 
Example 13
Source File: MapBasedXPathVariableResolverQName.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove multiple variables at once.
 *
 * @param aNames
 *        The names to be removed. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one variable was removed.
 */
@Nonnull
public EChange removeVariables (@Nullable final Iterable <? extends QName> aNames)
{
  EChange eChange = EChange.UNCHANGED;
  if (aNames != null)
    for (final QName aName : aNames)
      eChange = eChange.or (removeVariable (aName));
  return eChange;
}
 
Example 14
Source File: IMutableDirectedGraphNode.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
default EChange removeAllRelations ()
{
  EChange ret = EChange.UNCHANGED;
  ret = ret.or (removeAllIncomingRelations ());
  ret = ret.or (removeAllOutgoingRelations ());
  return ret;
}
 
Example 15
Source File: DirectedGraph.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange removeRelation (@Nullable final IMutableDirectedGraphRelation aRelation)
{
  EChange ret = EChange.UNCHANGED;
  if (aRelation != null)
  {
    ret = ret.or (aRelation.getFrom ().removeOutgoingRelation (aRelation));
    ret = ret.or (aRelation.getTo ().removeIncomingRelation (aRelation));
    if (ret.isChanged ())
      _invalidateCache ();
  }
  return ret;
}
 
Example 16
Source File: Graph.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange removeRelation (@Nullable final IMutableGraphRelation aRelation)
{
  EChange ret = EChange.UNCHANGED;
  if (aRelation != null)
  {
    for (final IMutableGraphNode aNode : aRelation.getAllConnectedNodes ())
      ret = ret.or (aNode.removeRelation (aRelation));
    if (ret.isChanged ())
      _invalidateCache ();
  }
  return ret;
}
 
Example 17
Source File: SettingsWithDefault.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public final EChange setAllToDefault ()
{
  EChange eChange = EChange.UNCHANGED;
  for (final String sFieldName : m_aDefaultSettings.keySet ())
    eChange = eChange.or (setToDefault (sFieldName));
  return eChange;
}
 
Example 18
Source File: IMultiMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Add all values into the container identified by the passed key-value-map.
 *
 * @param aMap
 *        The key-value-map to use. May not be <code>null</code>.
 * @return {@link EChange}
 */
@Nonnull
default EChange putAllIn (@Nonnull final Map <? extends KEYTYPE, ? extends VALUETYPE> aMap)
{
  EChange eChange = EChange.UNCHANGED;
  for (final Map.Entry <? extends KEYTYPE, ? extends VALUETYPE> aEntry : aMap.entrySet ())
    eChange = eChange.or (putSingle (aEntry.getKey (), aEntry.getValue ()));
  return eChange;
}
 
Example 19
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Add all passed elements 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>.
 * @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
 */
@Nonnull
default <SRCTYPE> EChange addAllMapped (@Nullable final SRCTYPE [] aElements,
                                        @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final SRCTYPE aValue : aElements)
      eChange = eChange.or (add (aMapper.apply (aValue)));
  return eChange;
}
 
Example 20
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Add all passed elements 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>.
 * @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
 */
@Nonnull
default <SRCTYPE> EChange addAllMapped (@Nullable final Iterable <? extends SRCTYPE> aElements,
                                        @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final SRCTYPE aValue : aElements)
      eChange = eChange.or (add (aMapper.apply (aValue)));
  return eChange;
}