use of com.helger.commons.state.EChange in project ph-commons by phax.
the class ICommonsCollection method addAllMapped.
/**
* 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;
}
use of com.helger.commons.state.EChange in project ph-commons by phax.
the class ICommonsMap method removeIf.
@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;
}
use of com.helger.commons.state.EChange in project ph-commons by phax.
the class MapBasedXPathFunctionResolver method addAllFrom.
/**
* 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;
}
use of com.helger.commons.state.EChange in project ph-commons by phax.
the class MapBasedXPathVariableResolver method addAllFrom.
/**
* Add all variables from the other variable resolver into this resolver. This
* methods takes only the local part of the QName and loses the namespace URI.
*
* @param aOther
* The variable resolver to import the variable from. May not be
* <code>null</code>.
* @param bOverwrite
* if <code>true</code> existing variables will be overwritten with the
* new variables, otherwise the old variables are kept.
* @return {@link EChange}
*/
@Nonnull
public EChange addAllFrom(@Nonnull final MapBasedXPathVariableResolverQName aOther, final boolean bOverwrite) {
ValueEnforcer.notNull(aOther, "Other");
EChange eChange = EChange.UNCHANGED;
for (final Map.Entry<QName, ?> aEntry : aOther.getAllVariables().entrySet()) {
// QName to local part only
final String sKey = aEntry.getKey().getLocalPart();
if (bOverwrite || !m_aMap.containsKey(sKey)) {
m_aMap.put(sKey, aEntry.getValue());
eChange = EChange.CHANGED;
}
}
return eChange;
}
use of com.helger.commons.state.EChange in project ph-commons by phax.
the class MapBasedXPathVariableResolver method addAllFrom.
/**
* Add all variables from the other variable resolver into this resolver.
*
* @param aOther
* The variable resolver to import the variable from. May not be
* <code>null</code>.
* @param bOverwrite
* if <code>true</code> existing variables will be overwritten with the
* new variables, otherwise the old variables are kept.
* @return {@link EChange}
*/
@Nonnull
public EChange addAllFrom(@Nonnull final MapBasedXPathVariableResolver aOther, final boolean bOverwrite) {
ValueEnforcer.notNull(aOther, "Other");
EChange eChange = EChange.UNCHANGED;
for (final Map.Entry<String, Object> aEntry : aOther.m_aMap.entrySet()) if (bOverwrite || !m_aMap.containsKey(aEntry.getKey())) {
m_aMap.put(aEntry.getKey(), aEntry.getValue());
eChange = EChange.CHANGED;
}
return eChange;
}
Aggregations