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

The following examples show how to use com.helger.commons.state.EChange#valueOf() . 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: SystemProperties.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Set a system property value under consideration of an eventually present
 * {@link SecurityManager}.
 *
 * @param sKey
 *        The key of the system property. May not be <code>null</code>.
 * @param sValue
 *        The value of the system property. If the value is <code>null</code>
 *        the property is removed.
 * @return {@link EChange}
 */
@Nonnull
public static EChange setPropertyValue (@Nonnull final String sKey, @Nullable final String sValue)
{
  boolean bChanged;
  if (sValue == null)
  {
    // Was something removed?
    bChanged = removePropertyValue (sKey) != null;
  }
  else
  {
    final String sOld = IPrivilegedAction.systemSetProperty (sKey, sValue).invokeSafe ();
    bChanged = sOld != null && !sValue.equals (sOld);
    if (LOGGER.isDebugEnabled () && bChanged)
      LOGGER.debug ("Set system property '" + sKey + "' to '" + sValue + "'");
  }
  return EChange.valueOf (bChanged);
}
 
Example 2
Source File: GraphNode.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange removeRelation (@Nullable final IMutableGraphRelation aRelation)
{
  if (aRelation == null || m_aRelations == null)
    return EChange.UNCHANGED;
  return EChange.valueOf (m_aRelations.remove (aRelation.getID ()) != null);
}
 
Example 3
Source File: AbstractMicroNode.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange registerEventTarget (@Nonnull final EMicroEvent eEventType, @Nonnull final IMicroEventTarget aTarget)
{
  ValueEnforcer.notNull (eEventType, "EventType");
  ValueEnforcer.notNull (aTarget, "EventTarget");

  if (m_aEventTargets == null)
    m_aEventTargets = new CommonsEnumMap <> (EMicroEvent.class);
  final CallbackList <IMicroEventTarget> aSet = m_aEventTargets.computeIfAbsent (eEventType,
                                                                                 k -> new CallbackList <> ());
  return EChange.valueOf (aSet.add (aTarget));
}
 
Example 4
Source File: HttpHeaderMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public EChange removeHeader (@Nullable final String sName, @Nullable final String sValue)
{
  final Map.Entry <String, ICommonsList <String>> aEntry = _getHeaderEntry (sName);
  final boolean bRemoved = aEntry != null && aEntry.getValue ().remove (sValue);
  if (bRemoved && aEntry.getValue ().isEmpty ())
  {
    // If the last value was removed, remove the whole header
    m_aHeaders.remove (aEntry.getKey ());
  }

  return EChange.valueOf (bRemoved);
}
 
Example 5
Source File: IMultiMapMapBased.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Add a single value into the container identified by the passed key.
 *
 * @param aKey
 *        The key to use. May not be <code>null</code>.
 * @param aInnerKey
 *        The key for the inner map to use. May not be <code>null</code>.
 * @param aValue
 *        The value to be added. May be <code>null</code>.
 * @return {@link EChange}
 */
@Nonnull
default EChange putSingle (@Nonnull final KEYTYPE1 aKey,
                           @Nonnull final KEYTYPE2 aInnerKey,
                           @Nullable final VALUETYPE aValue)
{
  return EChange.valueOf (getOrCreate (aKey).put (aInnerKey, aValue) != null);
}
 
Example 6
Source File: ICommonsMap.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Remove the object with the passed key from this map. <br>
 * Note: this method returns {@link EChange#UNCHANGED} even if removal was
 * successful if the value was <code>null</code>.
 *
 * @param aKey
 *        The key to be removed. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if the removal was successful,
 *         {@link EChange#UNCHANGED} if removal fails.
 * @see #remove(Object)
 */
@Nonnull
default EChange removeObject (@Nullable final KEYTYPE aKey)
{
  return EChange.valueOf (remove (aKey) != null);
}
 
Example 7
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * add the provided element to the collection using {@link #add(Object)} but
 * returning a more structured return value.
 *
 * @param aElement
 *        The element to be add. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if the element was added successfully,
 *         {@link EChange#UNCHANGED} otherwise (e.g. because if is already
 *         contained).
 * @see #add(Object)
 */
@Nonnull
default EChange addObject (@Nullable final ELEMENTTYPE aElement)
{
  return EChange.valueOf (add (aElement));
}
 
Example 8
Source File: ICommonsCollection.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Remove the provided element from the collection using
 * {@link #remove(Object)} but returning a more structured return value.
 *
 * @param aElement
 *        The element to be removed. May be <code>null</code>.
 * @return {@link EChange#CHANGED} if the element was removed successfully,
 *         {@link EChange#UNCHANGED} otherwise.
 * @see #remove(Object)
 */
@Nonnull
default EChange removeObject (@Nullable final ELEMENTTYPE aElement)
{
  return EChange.valueOf (remove (aElement));
}
 
Example 9
Source File: AbstractHasTopLevelRules.java    From ph-css with Apache License 2.0 2 votes vote down vote up
/**
 * Remove all rules matching the passed predicate.
 *
 * @param aFilter
 *        The predicate to apply for deletion. May not be <code>null</code>.
 * @return {@link EChange#CHANGED} it at least one rule was removed,
 *         {@link EChange#UNCHANGED} otherwise.
 * @since 5.0.0
 */
@Nonnull
public EChange removeRules (@Nonnull final Predicate <? super ICSSTopLevelRule> aFilter)
{
  return EChange.valueOf (m_aRules.removeIf (aFilter));
}