Java Code Examples for com.helger.commons.string.StringHelper#hasNoText()

The following examples show how to use com.helger.commons.string.StringHelper#hasNoText() . 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: AbstractMapBasedWALDAO.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the item by removing it from the map. If something was remove the
 * onDeleteItem callback is invoked. Must only be invoked inside a write-lock.
 *
 * @param sID
 *        The ID to be removed. May be <code>null</code>.
 * @param bInvokeCallbacks
 *        <code>true</code> to invoke callbacks, <code>false</code> to not do
 *        so.
 * @return The deleted item. If <code>null</code> no such item was found and
 *         therefore nothing was removed.
 * @since 9.2.1
 */
@MustBeLocked (ELockType.WRITE)
@Nullable
protected final IMPLTYPE internalDeleteItem (@Nullable final String sID, final boolean bInvokeCallbacks)
{
  if (StringHelper.hasNoText (sID))
    return null;

  final IMPLTYPE aDeletedItem = m_aMap.remove (sID);
  if (aDeletedItem == null)
    return null;

  // Trigger save changes
  super.markAsChanged (aDeletedItem, EDAOActionType.DELETE);

  if (bInvokeCallbacks)
  {
    // Invoke callbacks
    m_aCallbacks.forEach (aCB -> aCB.onDeleteItem (aDeletedItem));
  }
  return aDeletedItem;
}
 
Example 2
Source File: Option.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an Option with the values declared by this {@link Builder}.
 *
 * @return the new {@link Option}
 * @throws IllegalArgumentException
 *         if neither {@code opt} or {@code longOpt} has been set
 */
@Nonnull
@ReturnsMutableCopy
public Option build ()
{
  if (StringHelper.hasNoText (m_sShortOpt) && StringHelper.hasNoText (m_sLongOpt))
    throw new IllegalStateException ("Either opt or longOpt must be specified");
  if (m_nMaxArgs != INFINITE_VALUES && m_nMaxArgs < m_nMinArgs)
    throw new IllegalStateException ("MinArgs (" + m_nMinArgs + ") must be <= MaxArgs (" + m_nMaxArgs + ")");
  if (m_nMinArgs == 0 && m_nMaxArgs == 0)
  {
    if (m_sArgName != null)
      throw new IllegalStateException ("ArgName may only be provided if at least one argument is present");
    if (m_eMultiplicity.isRequired ())
      LOGGER.warn ("Having a required option without an argument may not be what is desired.");
    if (m_eMultiplicity.isRepeatable ())
      LOGGER.warn ("Having a repeatable option without an argument may not be what is desired.");
    if (m_cValueSep != DEFAULT_VALUE_SEPARATOR)
      throw new IllegalStateException ("ValueSeparator may only be provided if at least one argument is present");
  }

  return new Option (this);
}
 
Example 3
Source File: Config.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
public ConfiguredValue getConfiguredValue (@Nullable final String sKey)
{
  // Resolve value
  final ConfiguredValue ret;
  if (StringHelper.hasNoText (sKey))
    ret = null;
  else
    ret = m_aValueProvider.getConfigurationValue (sKey);

  // Call consumers if configured
  if (ret != null)
  {
    if (m_aKeyFoundConsumer != null)
      m_aKeyFoundConsumer.accept (sKey, ret);
  }
  else
  {
    if (m_aKeyNotFoundConsumer != null)
      m_aKeyNotFoundConsumer.accept (sKey);
  }
  return ret;
}
 
Example 4
Source File: ParsedCmdLine.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nullable
private ICommonsList <String> _find (@Nullable final String sOption)
{
  if (StringHelper.hasNoText (sOption))
    return null;

  for (final Map.Entry <IOptionBase, ICommonsList <String>> aEntry : m_aParams.entrySet ())
    if (aEntry.getKey () instanceof Option)
    {
      if (((Option) aEntry.getKey ()).matches (sOption))
        return aEntry.getValue ();
    }
    else
      // Do not resolve option groups, as the resolution happens on insertion!
      if (false)
      {
        for (final Option aOption : (OptionGroup) aEntry.getKey ())
          if (aOption.matches (sOption))
            return aEntry.getValue ();
      }
  return null;
}
 
Example 5
Source File: CertificateHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove any eventually preceding {@value #BEGIN_CERTIFICATE} and succeeding
 * {@value #END_CERTIFICATE} values from the passed certificate string.
 * Additionally all whitespaces of the string are removed.
 *
 * @param sCertificate
 *        The source certificate string. May be <code>null</code>.
 * @return <code>null</code> if the input string is <code>null</code> or
 *         empty, the stripped down string otherwise.
 */
@Nullable
public static String getWithoutPEMHeader (@Nullable final String sCertificate)
{
  if (StringHelper.hasNoText (sCertificate))
    return null;

  // Remove special begin and end stuff
  String sRealCertificate = sCertificate.trim ();

  /**
   * Handle certain misconfiguration issues. E.g. for 9906:testconsip on
   *
   * <pre>
   * http://b-c073e04afb234f70e74d3444ba3f8eaa.iso6523-actorid-upis.acc.edelivery.tech.ec.europa.eu/iso6523-actorid-upis%3A%3A9906%3Atestconsip/services/busdox-docid-qns%3A%3Aurn%3Aoasis%3Anames%3Aspecification%3Aubl%3Aschema%3Axsd%3AOrder-2%3A%3AOrder%23%23urn%3Awww.cenbii.eu%3Atransaction%3Abiitrns001%3Aver2.0%3Aextended%3Aurn%3Awww.peppol.eu%3Abis%3Apeppol3a%3Aver2.0%3A%3A2.1
   * </pre>
   */
  sRealCertificate = StringHelper.trimStart (sRealCertificate, BEGIN_CERTIFICATE_INVALID);
  sRealCertificate = StringHelper.trimEnd (sRealCertificate, END_CERTIFICATE_INVALID);

  // Remove regular PEM headers also
  sRealCertificate = StringHelper.trimStart (sRealCertificate, BEGIN_CERTIFICATE);
  sRealCertificate = StringHelper.trimEnd (sRealCertificate, END_CERTIFICATE);

  // Remove all existing whitespace characters
  return StringHelper.getWithoutAnySpaces (sRealCertificate);
}
 
Example 6
Source File: PSAssertReport.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  for (final Object aContent : m_aContent)
    if (aContent instanceof IPSElement)
      ((IPSElement) aContent).validateCompletely (aErrorHandler);
  if (StringHelper.hasNoText (m_sTest))
    aErrorHandler.error (this, (m_bIsAssert ? "<assert>" : "<report>") + " has no 'test'");
}
 
Example 7
Source File: PSSpan.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  if (StringHelper.hasNoText (m_sClass))
    aErrorHandler.error (this, "<span> has no 'class'");
  if (m_aContent.isEmpty ())
    aErrorHandler.error (this, "<span> has no content");
}
 
Example 8
Source File: PSLet.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public boolean isValid (@Nonnull final IPSErrorHandler aErrorHandler)
{
  if (StringHelper.hasNoText (m_sName))
  {
    aErrorHandler.error (this, "<let> has no 'name'");
    return false;
  }
  if (StringHelper.hasNoText (m_sValue))
  {
    aErrorHandler.error (this, "<let> has no 'value'");
    return false;
  }
  return true;
}
 
Example 9
Source File: CertificateHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the passed X.509 certificate string to a byte array.
 *
 * @param sCertificate
 *        The original certificate string. May be <code>null</code> or empty.
 * @return <code>null</code> if the passed string is <code>null</code> or
 *         empty or an invalid Base64 string
 */
@Nullable
public static byte [] convertCertificateStringToByteArray (@Nullable final String sCertificate)
{
  // Remove prefix/suffix
  final String sPlainCert = getWithoutPEMHeader (sCertificate);
  if (StringHelper.hasNoText (sPlainCert))
    return null;

  // The remaining string is supposed to be Base64 encoded -> decode
  return Base64.safeDecode (sPlainCert);
}
 
Example 10
Source File: PSParam.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  if (StringHelper.hasNoText (m_sName))
    aErrorHandler.error (this, "<param> has no 'name'");
  if (StringHelper.hasNoText (m_sValue))
    aErrorHandler.error (this, "<param> has no 'value'");
}
 
Example 11
Source File: MimeTypeInfoManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nullable
@ReturnsMutableCopy
public ICommonsList <MimeTypeInfo> getAllInfosOfFilename (@Nullable final String sFilename)
{
  if (StringHelper.hasNoText (sFilename))
    return null;

  final String sExtension = FilenameHelper.getExtension (sFilename);
  return getAllInfosOfExtension (sExtension);
}
 
Example 12
Source File: PSActive.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  for (final Object aContent : m_aContent)
    if (aContent instanceof IPSElement)
      ((IPSElement) aContent).validateCompletely (aErrorHandler);
  if (StringHelper.hasNoText (m_sPattern))
    aErrorHandler.error (this, "<active> has no 'pattern'");
}
 
Example 13
Source File: ISVRLErrorLevelDeterminator.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
/**
 * Get the error level associated with a single failed assertion.
 *
 * @param aFailedAssert
 *        The failed assert to be queried. May not be <code>null</code>.
 * @return The error level and never <code>null</code>.
 */
@Nonnull
default IErrorLevel getErrorLevelFromFailedAssert (@Nonnull final FailedAssert aFailedAssert)
{
  ValueEnforcer.notNull (aFailedAssert, "FailedAssert");

  // First try "flag" (for backwards compatibility)
  String sValue = aFailedAssert.getFlag ();
  if (StringHelper.hasNoText (sValue))
  {
    // Fall back to "role"
    sValue = aFailedAssert.getRole ();
  }
  return getErrorLevelFromString (sValue);
}
 
Example 14
Source File: HelpFormatter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the trailing whitespace from the specified String.
 *
 * @param sStr
 *        The String to remove the trailing padding from.
 * @return The String of without the trailing padding
 */
@Nullable
protected static String rtrim (@Nullable final String sStr)
{
  if (StringHelper.hasNoText (sStr))
    return sStr;

  int pos = sStr.length ();
  while (pos > 0 && Character.isWhitespace (sStr.charAt (pos - 1)))
  {
    --pos;
  }

  return sStr.substring (0, pos);
}
 
Example 15
Source File: PSValueOf.java    From ph-schematron with Apache License 2.0 4 votes vote down vote up
public void validateCompletely (@Nonnull final IPSErrorHandler aErrorHandler)
{
  if (StringHelper.hasNoText (m_sSelect))
    aErrorHandler.error (this, "<value-of> has no 'select'");
}
 
Example 16
Source File: XMLHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public static boolean hasNoNamespaceURI (@Nonnull final Node aNode)
{
  return StringHelper.hasNoText (aNode.getNamespaceURI ());
}
 
Example 17
Source File: CSSColorHelper.java    From ph-css with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the passed string is any color value.
 *
 * @param sValue
 *        The value to check. May be <code>null</code>.
 * @return <code>true</code> if the passed value is not <code>null</code>, not
 *         empty and a valid CSS color value.
 * @see #isRGBColorValue(String)
 * @see #isRGBAColorValue(String)
 * @see #isHSLColorValue(String)
 * @see #isHSLAColorValue(String)
 * @see #isHexColorValue(String)
 * @see ECSSColor#isDefaultColorName(String)
 * @see ECSSColorName#isDefaultColorName(String)
 * @see CCSSValue#CURRENTCOLOR
 * @see CCSSValue#TRANSPARENT
 */
public static boolean isColorValue (@Nullable final String sValue)
{
  final String sRealValue = StringHelper.trim (sValue);
  if (StringHelper.hasNoText (sRealValue))
    return false;

  return isRGBColorValue (sRealValue) ||
         isRGBAColorValue (sRealValue) ||
         isHSLColorValue (sRealValue) ||
         isHSLAColorValue (sRealValue) ||
         isHexColorValue (sRealValue) ||
         ECSSColor.isDefaultColorName (sRealValue) ||
         ECSSColorName.isDefaultColorName (sRealValue) ||
         sRealValue.equals (CCSSValue.CURRENTCOLOR) ||
         sRealValue.equals (CCSSValue.TRANSPARENT);
}
 
Example 18
Source File: LocaleHelper.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Convert a String in the form "language-country-variant" to a Locale object.
 * Language needs to have exactly 2 characters. Country is optional but if
 * present needs to have exactly 2 characters. Variant is optional.
 *
 * @param sLocaleAsString
 *        The string representation to be converted to a Locale.
 * @return Never <code>null</code>. If the passed parameter is
 *         <code>null</code> or empty, {@link SystemHelper#getSystemLocale()}
 *         is returned.
 */
@Nonnull
public static Locale getLocaleFromString (@Nullable final String sLocaleAsString)
{
  if (StringHelper.hasNoText (sLocaleAsString))
  {
    // not specified => getDefault
    return SystemHelper.getSystemLocale ();
  }

  String sLanguage;
  String sCountry;
  String sVariant;

  int i1 = sLocaleAsString.indexOf (LOCALE_SEPARATOR);
  if (i1 < 0)
  {
    // No separator present -> use as is
    sLanguage = sLocaleAsString;
    sCountry = "";
    sVariant = "";
  }
  else
  {
    // Language found
    sLanguage = sLocaleAsString.substring (0, i1);
    ++i1;

    // Find next separator
    final int i2 = sLocaleAsString.indexOf (LOCALE_SEPARATOR, i1);
    if (i2 < 0)
    {
      // No other separator -> country is the rest
      sCountry = sLocaleAsString.substring (i1);
      sVariant = "";
    }
    else
    {
      // We have country and variant
      sCountry = sLocaleAsString.substring (i1, i2);
      sVariant = sLocaleAsString.substring (i2 + 1);
    }
  }

  // Unify elements
  if (sLanguage.length () == 2)
    sLanguage = sLanguage.toLowerCase (Locale.US);
  else
    sLanguage = "";

  if (sCountry.length () == 2)
    sCountry = sCountry.toUpperCase (Locale.US);
  else
    sCountry = "";

  if (sVariant.length () > 0 && (sLanguage.length () == 2 || sCountry.length () == 2))
    sVariant = sVariant.toUpperCase (Locale.US);
  else
    sVariant = "";

  // And now resolve using the locale cache
  return LocaleCache.getInstance ().getLocale (sLanguage, sCountry, sVariant);
}
 
Example 19
Source File: EnumHelper.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Get the enum value with the passed name
 *
 * @param <ENUMTYPE>
 *        The enum type
 * @param aClass
 *        The enum class
 * @param sName
 *        The name to search
 * @param eDefault
 *        The default value to be returned, if the name was not found.
 * @return The default parameter if no enum item with the given name is
 *         present.
 */
@Nullable
public static <ENUMTYPE extends Enum <ENUMTYPE> & IHasName> ENUMTYPE getFromNameOrDefault (@Nonnull final Class <ENUMTYPE> aClass,
                                                                                           @Nullable final String sName,
                                                                                           @Nullable final ENUMTYPE eDefault)
{
  ValueEnforcer.notNull (aClass, "Class");

  if (StringHelper.hasNoText (sName))
    return eDefault;
  return findFirst (aClass, x -> x.getName ().equals (sName), eDefault);
}
 
Example 20
Source File: Version.java    From ph-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new version with 3 integer values and a qualifier.
 *
 * @param nMajor
 *        major version
 * @param nMinor
 *        minor version
 * @param nMicro
 *        micro version
 * @param sQualifier
 *        the version qualifier - may be null. If a qualifier is supplied, it
 *        may neither contain the "." or the "," character since they are used
 *        to determine the fields of a version and to separate 2 versions in a
 *        VersionRange.
 * @throws IllegalArgumentException
 *         if any of the numeric parameters is &lt; 0 or if the qualifier
 *         contains a forbidden character
 */
public Version (@Nonnegative final int nMajor,
                @Nonnegative final int nMinor,
                @Nonnegative final int nMicro,
                @Nullable final String sQualifier)
{
  ValueEnforcer.isGE0 (nMajor, "Major");
  ValueEnforcer.isGE0 (nMinor, "Minor");
  ValueEnforcer.isGE0 (nMicro, "Micro");
  m_nMajor = nMajor;
  m_nMinor = nMinor;
  m_nMicro = nMicro;
  m_sQualifier = StringHelper.hasNoText (sQualifier) ? null : sQualifier;
}