Search in sources :

Example 16 with EChange

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;
}
Also used : EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 17 with 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;
}
Also used : MapEntry(com.helger.commons.collection.map.MapEntry) EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 18 with EChange

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;
}
Also used : XPathFunction(javax.xml.xpath.XPathFunction) EChange(com.helger.commons.state.EChange) ICommonsOrderedMap(com.helger.commons.collection.impl.ICommonsOrderedMap) Map(java.util.Map) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) Nonnull(javax.annotation.Nonnull)

Example 19 with 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;
}
Also used : QName(javax.xml.namespace.QName) EChange(com.helger.commons.state.EChange) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) Nonnull(javax.annotation.Nonnull)

Example 20 with 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;
}
Also used : EChange(com.helger.commons.state.EChange) CommonsHashMap(com.helger.commons.collection.impl.CommonsHashMap) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) Nonnull(javax.annotation.Nonnull)

Aggregations

EChange (com.helger.commons.state.EChange)50 Nonnull (javax.annotation.Nonnull)42 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)9 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)9 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)7 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)6 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)6 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)6 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)6 ESuccess (com.helger.commons.state.ESuccess)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)5 IUser (com.helger.photon.security.user.IUser)5 Map (java.util.Map)5 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4 CallbackList (com.helger.commons.callback.CallbackList)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)4 MutableBoolean (com.helger.commons.mutable.MutableBoolean)4