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

The following examples show how to use com.helger.commons.string.StringHelper#endsWith() . 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: StackTraceHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static String getStackAsString (@Nonnull final StackTraceElement [] aStackTraceElements,
                                       final boolean bOmitCommonStackTraceElements,
                                       @Nonnull final String sLineSeparator)
{
  ValueEnforcer.notNull (aStackTraceElements, "StackTraceElements");
  ValueEnforcer.notNull (sLineSeparator, "LineSeparator");

  final StringBuilder aSB = new StringBuilder ();
  _appendSingleStackTraceToString (aSB, aStackTraceElements, null, bOmitCommonStackTraceElements, sLineSeparator);

  // avoid having a separator at the end -> remove if present
  if (sLineSeparator.length () > 0)
    if (StringHelper.endsWith (aSB, sLineSeparator))
      aSB.delete (aSB.length () - sLineSeparator.length (), aSB.length ());

  return aSB.toString ();
}
 
Example 2
Source File: StackTraceHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the stack trace of a throwable as string.
 *
 * @param t
 *        The throwable to be converted. May be <code>null</code>.
 * @param bOmitCommonStackTraceElements
 *        If <code>true</code> the stack trace is cut after certain class
 *        names occurring. If <code>false</code> the complete stack trace is
 *        returned.
 * @param sLineSeparator
 *        The line separator to use. May not be <code>null</code>.
 * @return the stack trace as newline separated string. If the passed
 *         Throwable is <code>null</code> an empty string is returned.
 * @since 9.3.6
 */
@Nonnull
public static String getStackAsString (@Nullable final Throwable t,
                                       final boolean bOmitCommonStackTraceElements,
                                       @Nonnull final String sLineSeparator)
{
  ValueEnforcer.notNull (sLineSeparator, "LineSeparator");

  if (t == null)
    return "";

  // convert call stack to string
  final StringBuilder aCallStack = _getRecursiveStackAsStringBuilder (t,
                                                                      null,
                                                                      null,
                                                                      1,
                                                                      bOmitCommonStackTraceElements,
                                                                      sLineSeparator);

  // avoid having a separator at the end -> remove if present
  if (sLineSeparator.length () > 0)
    if (StringHelper.endsWith (aCallStack, sLineSeparator))
      aCallStack.delete (aCallStack.length () - sLineSeparator.length (), aCallStack.length ());

  // no changes
  return aCallStack.toString ();
}
 
Example 3
Source File: FilenameHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Concatenate a base URL and a sub path incl. the path cleansing. More or
 * less the same as calling <code>getCleanPath (sURL + "/" + sPath)</code>
 *
 * @param sURL
 *        The base URL. May not be <code>null</code>.
 * @param sPath
 *        The path to append. May not be <code>null</code>.
 * @return The combined, cleaned path.
 * @see #getCleanPath(String)
 */
@Nonnull
public static String getCleanConcatenatedUrlPath (@Nonnull final String sURL, @Nonnull final String sPath)
{
  ValueEnforcer.notNull (sURL, "URL");
  ValueEnforcer.notNull (sPath, "Path");

  // If nothing is to be appended, just clean the base URL
  if (StringHelper.hasNoText (sPath))
    return getCleanPath (sURL);

  final String sRealURL = StringHelper.endsWith (sURL, UNIX_SEPARATOR) ? sURL : sURL + UNIX_SEPARATOR;
  final String sRealPath = StringHelper.startsWith (sPath, UNIX_SEPARATOR) ? sPath.substring (1) : sPath;
  return getCleanPath (sRealURL + sRealPath);
}
 
Example 4
Source File: VersionRange.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a version range object from a string.<br>
 * Examples:<br>
 * <ul>
 * <li>[1.2.3, 4.5.6) -- 1.2.3 &lt;= x &lt; 4.5.6</li>
 * <li>[1.2.3, 4.5.6] -- 1.2.3 &lt;= x &lt;= 4.5.6</li>
 * <li>(1.2.3, 4.5.6) -- 1.2.3 &lt; x &lt; 4.5.6</li>
 * <li>(1.2.3, 4.5.6] -- 1.2.3 &lt; x &lt;= 4.5.6</li>
 * <li>1.2.3 -- 1.2.3 &lt;= x</li>
 * <li>[1.2.3 -- 1.2.3 &lt;= x</li>
 * <li>(1.2.3 -- 1.2.3 &lt; x</li>
 * <li><i>null</i> -- 0.0.0 &lt;= x</li>
 * <li>1, 4 -- 1 &lt;= x &lt;= 4</li>
 * </ul>
 *
 * @param sVersionString
 *        the version range in a string format as depicted above
 * @return The parsed {@link VersionRange} object
 * @throws IllegalArgumentException
 *         if the floor version is &lt; than the ceiling version
 */
@Nonnull
public static VersionRange parse (@Nullable final String sVersionString)
{
  final String s = sVersionString == null ? "" : sVersionString.trim ();
  if (s.length () == 0)
  {
    // empty string == range [0.0, infinity)
    return new VersionRange (Version.DEFAULT_VERSION, true, null, false);
  }

  Version aFloorVersion;
  boolean bIncludeFloor;
  Version aCeilVersion;
  boolean bIncludeCeil;

  int i = 0;
  // parse initial token
  if (s.charAt (i) == '[')
  {
    bIncludeFloor = true;
    i++;
  }
  else
    if (s.charAt (i) == '(')
    {
      bIncludeFloor = false;
      i++;
    }
    else
      bIncludeFloor = true;

  // check last token
  int j = 0;
  if (StringHelper.endsWith (s, ']'))
  {
    bIncludeCeil = true;
    j++;
  }
  else
    if (StringHelper.endsWith (s, ')'))
    {
      bIncludeCeil = false;
      j++;
    }
    else
      bIncludeCeil = false;

  // get length of version stuff
  final int nRestLen = s.length () - i - j;
  if (nRestLen == 0)
  {
    // only delimiter braces present?
    aFloorVersion = Version.DEFAULT_VERSION;
    aCeilVersion = null;
  }
  else
  {
    final String [] parts = StringHelper.getExplodedArray (',', s.substring (i, s.length () - j));
    final String sFloor = parts[0].trim ();
    final String sCeiling = parts.length > 1 ? parts[1].trim () : null;

    // get floor version
    aFloorVersion = Version.parse (sFloor);

    if (StringHelper.hasNoText (sCeiling))
      aCeilVersion = null;
    else
      aCeilVersion = Version.parse (sCeiling);
  }

  // check if floor <= ceil
  if (aCeilVersion != null && aFloorVersion.compareTo (aCeilVersion) > 0)
    throw new IllegalArgumentException ("Floor version may not be greater than the ceiling version!");

  return new VersionRange (aFloorVersion, bIncludeFloor, aCeilVersion, bIncludeCeil);
}
 
Example 5
Source File: CSSFilenameHelper.java    From ph-css with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the passed filename is a CSS filename (independent if regular or
 * minified)
 *
 * @param sFilename
 *        The filename to check.
 * @return <code>true</code> if the passed filename is a CSS filename.
 */
public static boolean isCSSFilename (@Nullable final String sFilename)
{
  return StringHelper.endsWith (sFilename, CCSS.FILE_EXTENSION_CSS);
}
 
Example 6
Source File: CSSFilenameHelper.java    From ph-css with Apache License 2.0 2 votes vote down vote up
/**
 * Check if the passed filename is a minified CSS filename
 *
 * @param sFilename
 *        The filename to check.
 * @return <code>true</code> if the passed filename is a minified CSS
 *         filename.
 */
public static boolean isMinifiedCSSFilename (@Nullable final String sFilename)
{
  return StringHelper.endsWith (sFilename, CCSS.FILE_EXTENSION_MIN_CSS);
}