com.helger.commons.annotation.Nonempty Java Examples

The following examples show how to use com.helger.commons.annotation.Nonempty. 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: LoggingCSSParseErrorHandler.java    From ph-css with Apache License 2.0 6 votes vote down vote up
/**
 * Create a common string to be used for unexpected rules.
 *
 * @param aCurrentToken
 *        The current token that caused an error. Never <code>null</code>.
 * @param sRule
 *        The name of the rule. Always starts with a '@'. May neither be
 *        <code>null</code> nor empty.
 * @param sMsg
 *        The custom error message. Neither <code>null</code> nor empty.
 * @return The concatenated string with source location, rule and message. May
 *         neither be <code>null</code> nor empty.
 */
@Nonnull
@Nonempty
public static String createLoggingStringUnexpectedRule (@Nonnull final Token aCurrentToken,
                                                        @Nonnull @Nonempty final String sRule,
                                                        @Nonnull @Nonempty final String sMsg)
{
  return "[" +
         aCurrentToken.beginLine +
         ":" +
         aCurrentToken.beginColumn +
         "] Unexpected rule '" +
         sRule +
         "': " +
         sMsg;
}
 
Example #2
Source File: CSSSelectorMemberNot.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
  aSettings.checkVersionRequirements (this);

  final boolean bOptimizedOutput = aSettings.isOptimizedOutput ();
  final StringBuilder aSB = new StringBuilder (":not(");
  boolean bFirst = true;
  for (final CSSSelector aNestedSelector : m_aNestedSelectors)
  {
    if (bFirst)
      bFirst = false;
    else
      aSB.append (bOptimizedOutput ? "," : ", ");
    aSB.append (aNestedSelector.getAsCSSString (aSettings, 0));
  }
  return aSB.append (')').toString ();
}
 
Example #3
Source File: CSSNamespaceRule.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
  // Always ignore namespace rules?
  if (!aSettings.isWriteNamespaceRules ())
    return "";

  final StringBuilder aSB = new StringBuilder ();
  aSB.append ("@namespace ");
  if (StringHelper.hasText (m_sPrefix))
    aSB.append (m_sPrefix).append (' ');
  if (StringHelper.hasText (m_sURL))
    aSB.append (CSSURLHelper.getAsCSSURL (m_sURL, false));
  else
    aSB.append ("\"\"");
  return aSB.append (';').append (aSettings.getNewLineString ()).toString ();
}
 
Example #4
Source File: LoggingCSSParseErrorHandler.java    From ph-css with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Nonempty
public static String createLoggingStringBrowserCompliantSkip (@Nullable final ParseException ex,
                                                              @Nonnull final Token aFromToken,
                                                              @Nonnull final Token aToToken)
{
  String ret = "Browser compliant mode skipped CSS from [" +
               aFromToken.beginLine +
               ":" +
               aFromToken.beginColumn +
               "] starting at token '" +
               aFromToken.image +
               "' until [" +
               aToToken.endLine +
               ":" +
               aToToken.endColumn +
               "] to token '" +
               aToToken.image +
               "'";
  if (ex != null)
    ret += " (based on " + ex.getClass ().getName () + ": " + ex.getMessage () + ")";
  return ret;
}
 
Example #5
Source File: VendorInfo.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public static void setVendorEmail (@Nonnull @Nonempty final String sVendorEmail)
{
  ValueEnforcer.notEmpty (sVendorEmail, "VendorEmail");
  ValueEnforcer.isTrue (EmailAddressHelper.isValid (sVendorEmail), () -> "Illegal vendor email: " + sVendorEmail);
  s_sVendorEmail = sVendorEmail;
  s_sVendorEmailSuffix = StringHelper.getFromFirstIncl (sVendorEmail, '@');
}
 
Example #6
Source File: CSSRGBA.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * @return opacity part
 */
@Nonnull
@Nonempty
public String getOpacity ()
{
  return m_sOpacity;
}
 
Example #7
Source File: PDTDisplayHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Nonempty
@Override
public String getYears (@CheckForSigned final int nYears)
{
  // Use "abs" to ensure it is "1 year" and "-1 year"
  return MathHelper.abs (nYears) == 1 ? nYears + " Jahr" : nYears + " Jahre";
}
 
Example #8
Source File: CSSPropertyEnumOrRect.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSPropertyEnumOrRect (@Nonnull final ECSSProperty eProp,
                              @Nullable final ECSSVendorPrefix eVendorPrefix,
                              @Nullable final ICSSPropertyCustomizer aCustomizer,
                              @Nonnull @Nonempty final String... aEnumValues)
{
  super (eProp, eVendorPrefix, aCustomizer, aEnumValues);
}
 
Example #9
Source File: CSSViewportRule.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * @return The rule declaration string used in the CSS. Neither
 *         <code>null</code> nor empty. Always starting with <code>@</code>
 *         and ending with <code>viewport</code>.
 */
@Nonnull
@Nonempty
public String getDeclaration ()
{
  return m_sDeclaration;
}
 
Example #10
Source File: CSSValue.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * @return The property name including an eventually contained vendor prefix.
 *         Neither <code>null</code> nor empty.
 * @since 3.9.0
 */
@Nonnull
@Nonempty
public String getPropertyName ()
{
  return m_aProperty.getPropertyName ();
}
 
Example #11
Source File: CSSPropertyEnumOrColors.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSPropertyEnumOrColors (@Nonnull final ECSSProperty eProp,
                                @Nonnegative final int nMinNumbers,
                                @Nonnegative final int nMaxNumbers,
                                @Nonnull @Nonempty final String... aEnumValues)
{
  this (eProp, (ICSSPropertyCustomizer) null, nMinNumbers, nMaxNumbers, aEnumValues);
}
 
Example #12
Source File: SimpleGraph.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public IMutableGraphRelation createRelation (@Nonnull @Nonempty final String sRelationID,
                                             @Nonnull final String sFromNodeID,
                                             @Nonnull final String sToNodeID)
{
  final IMutableGraphNode aFromNode = getNodeOfID (sFromNodeID);
  if (aFromNode == null)
    throw new IllegalArgumentException ("Failed to resolve from node ID '" + sFromNodeID + "'");
  final IMutableGraphNode aToNode = getNodeOfID (sToNodeID);
  if (aToNode == null)
    throw new IllegalArgumentException ("Failed to resolve to node ID '" + sToNodeID + "'");
  return createRelation (sRelationID, aFromNode, aToNode);
}
 
Example #13
Source File: MimeTypeInfo.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Nonempty
@ReturnsMutableCopy
public ICommonsSet <MimeTypeWithSource> getAllMimeTypesWithSource ()
{
  return m_aMimeTypes.getClone ();
}
 
Example #14
Source File: CSSParseError.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * @return The error message created by {@link LoggingCSSParseErrorHandler} as
 *         a convenience method. Neither <code>null</code> nor empty.
 */
@Nonnull
@Nonempty
public String getErrorMessage ()
{
  return m_sErrorMessage;
}
 
Example #15
Source File: Dijkstra.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public Result (@Nonnull @Nonempty final ICommonsList <N> aResultNodes, @Nonnegative final int nResultDistance)
{
  ValueEnforcer.notEmpty (aResultNodes, "EesultNodes");
  ValueEnforcer.isGE0 (nResultDistance, "Result Distance");
  m_aResultNodes = aResultNodes;
  m_nResultDistance = nResultDistance;
}
 
Example #16
Source File: StatisticsManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static IMutableStatisticsHandlerSize getSizeHandler (@Nonnull @Nonempty final String sName)
{
  ValueEnforcer.notEmpty (sName, "Name");

  StatisticsHandlerSize aHdl = s_aRWLockSize.readLockedGet ( () -> s_aHdlSize.get (sName));

  if (aHdl == null)
  {
    aHdl = s_aRWLockSize.writeLockedGet ( () -> s_aHdlSize.computeIfAbsent (sName,
                                                                            k -> new StatisticsHandlerSize ()));
  }
  return aHdl;
}
 
Example #17
Source File: CSSReaderSettings.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * @param aFallbackCharset
 *        The charset to be used for reading the CSS file in case neither a
 *        <code>@charset</code> rule nor a BOM is present. May not be
 *        <code>null</code>.
 * @return this
 */
@Nonnull
public CSSReaderSettings setFallbackCharset (@Nonnull @Nonempty final Charset aFallbackCharset)
{
  ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset");
  m_aFallbackCharset = aFallbackCharset;
  return this;
}
 
Example #18
Source File: CSSDeclarationContainer.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
  final boolean bOptimizedOutput = aSettings.isOptimizedOutput ();

  final StringBuilder aSB = new StringBuilder ();
  final int nDeclCount = getDeclarationCount ();
  if (nDeclCount == 0)
  {
    aSB.append (bOptimizedOutput ? "{}" : " {}");
  }
  else
  {
    if (nDeclCount == 1)
    {
      // A single declaration
      aSB.append (bOptimizedOutput ? "{" : " { ");
      aSB.append (super.getAsCSSString (aSettings, nIndentLevel));
      aSB.append (bOptimizedOutput ? "}" : " }");
    }
    else
    {
      // More than one declaration
      aSB.append (bOptimizedOutput ? "{" : " {" + aSettings.getNewLineString ());
      aSB.append (super.getAsCSSString (aSettings, nIndentLevel));
      if (!bOptimizedOutput)
        aSB.append (aSettings.getIndent (nIndentLevel));
      aSB.append ('}');
    }
  }
  return aSB.toString ();
}
 
Example #19
Source File: CSSPropertyCustomizerBorderBottomRightRadius.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nullable
public ICSSValue createSpecialValue (@Nonnull final ICSSProperty aProperty,
                                     @Nonnull @Nonempty final String sValue,
                                     final boolean bIsImportant)
{
  return new CSSValueMultiProperty (aProperty.getProp (),
                                    new ICSSProperty [] { aProperty,
                                                          aProperty.getClone (ECSSProperty._MOZ_BORDER_RADIUS_BOTTOMRIGHT),
                                                          aProperty.getClone (ECSSVendorPrefix.WEBKIT),
                                                          aProperty.getClone (ECSSVendorPrefix.KHTML) },
                                    sValue,
                                    bIsImportant);
}
 
Example #20
Source File: WritableResourceProviderChain.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Nonempty
@ReturnsMutableCopy
public ICommonsList <IWritableResourceProvider> getAllContainedWritingResourceProviders ()
{
  return m_aWritableResourceProviders.getClone ();
}
 
Example #21
Source File: ScopeManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <T extends IRequestScope> T onRequestBegin (@Nonnull @Nonempty final String sScopeID,
                                                          @Nonnull @Nonempty final String sSessionID,
                                                          @Nonnull final BiFunction <? super String, ? super String, T> aFactory)
{
  final T aRequestScope = aFactory.apply (sScopeID, sSessionID);
  internalSetAndInitRequestScope (aRequestScope);
  return aRequestScope;
}
 
Example #22
Source File: PSQueryBindingRegistry.java    From ph-schematron with Apache License 2.0 5 votes vote down vote up
public static void registerQueryBinding (@Nonnull @Nonempty final String sName,
                                         @Nonnull final IPSQueryBinding aQueryBinding) throws SchematronBindException
{
  ValueEnforcer.notEmpty (sName, "Name");
  ValueEnforcer.notNull (aQueryBinding, "QueryBinding");

  s_aRWLock.writeLockedThrowing ( () -> {
    if (s_aMap.containsKey (sName))
      throw new SchematronBindException ("A queryBinding with the name '" + sName + "' is already registered!");
    s_aMap.put (sName, aQueryBinding);
  });
}
 
Example #23
Source File: CSSExpressionMemberTermSimple.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSSExpressionMemberTermSimple setValue (@Nonnull @Nonempty final String sValue)
{
  ValueEnforcer.notEmpty (sValue, "Value");
  m_sValue = sValue;
  m_sOptimizedValue = CSSExpressionTermOptimizer.getOptimizedValue (sValue);
  return this;
}
 
Example #24
Source File: Option.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return the 'unique' internal Option identifier. Either short or long
 *         option name.
 * @see #getShortOpt()
 * @see #getLongOpt()
 */
@Nonnull
@Nonempty
public final String getKey ()
{
  // if 'opt' is null, then it is a 'long' option
  return hasShortOpt () ? m_sShortOpt : m_sLongOpt;
}
 
Example #25
Source File: StatisticsManager.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static IMutableStatisticsHandlerKeyedSize getKeyedSizeHandler (@Nonnull @Nonempty final String sName)
{
  ValueEnforcer.notEmpty (sName, "Name");

  StatisticsHandlerKeyedSize aHdl = s_aRWLockKeyedSize.readLockedGet ( () -> s_aHdlKeyedSize.get (sName));

  if (aHdl == null)
  {
    aHdl = s_aRWLockKeyedSize.writeLockedGet ( () -> s_aHdlKeyedSize.computeIfAbsent (sName,
                                                                                      k -> new StatisticsHandlerKeyedSize ()));
  }
  return aHdl;
}
 
Example #26
Source File: HttpHeaderMap.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
private EChange _addHeader (@Nonnull @Nonempty final String sName, @Nonnull final String sValue)
{
  ValueEnforcer.notEmpty (sName, "Name");
  ValueEnforcer.notNull (sValue, "Value");

  if (LOGGER.isDebugEnabled ())
    LOGGER.debug ("Adding HTTP header: '" + sName + "' = '" + sValue + "'");
  return _getOrCreateHeaderList (sName).addObject (sValue);
}
 
Example #27
Source File: CSSPropertyEnumOrInt.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSPropertyEnumOrInt (@Nonnull final ECSSProperty eProp,
                             @Nullable final ECSSVendorPrefix eVendorPrefix,
                             @Nullable final ICSSPropertyCustomizer aCustomizer,
                             @Nonnull @Nonempty final Iterable <String> aEnumValues)
{
  super (eProp, eVendorPrefix, aCustomizer, aEnumValues);
}
 
Example #28
Source File: PathRelativeIO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
public PathRelativeIO (@Nonnull @Nonempty final String sBasePath)
{
  ValueEnforcer.notEmpty (sBasePath, "BasePath");
  m_sBasePath = sBasePath;

  // Use special base URL if base path is an existing file!
  String sBaseURL = null;
  final File aFile = new File (sBasePath);
  if (aFile.exists ())
    sBaseURL = FileHelper.getAsURLString (aFile);
  m_sBaseURL = sBaseURL != null ? sBaseURL : sBasePath;
}
 
Example #29
Source File: XMLHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnegative
public static int getDirectChildElementCountNS (@Nullable final Element aParent,
                                                @Nullable final String sNamespaceURI,
                                                @Nonnull @Nonempty final String sLocalName)
{
  return aParent == null ? 0
                         : CollectionHelper.getSize (getChildElementIteratorNS (aParent, sNamespaceURI, sLocalName));
}
 
Example #30
Source File: StreamHelper.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Read the content of the passed stream line by line and invoking a callback
 * on all matching lines.
 *
 * @param aIS
 *        The input stream to read from. May be <code>null</code>.
 * @param aCharset
 *        The character set to use. May not be <code>null</code>.
 * @param nLinesToSkip
 *        The 0-based index of the first line to read. Pass in 0 to indicate
 *        to read everything.
 * @param nLinesToRead
 *        The number of lines to read. Pass in {@link CGlobal#ILLEGAL_UINT} to
 *        indicate that all lines should be read. If the number passed here
 *        exceeds the number of lines in the file, nothing happens.
 * @param aLineCallback
 *        The callback that is invoked for all read lines. Each passed line
 *        does NOT contain the line delimiter! Note: it is not invoked for
 *        skipped lines!
 */
public static void readStreamLines (@WillClose @Nullable final InputStream aIS,
                                    @Nonnull @Nonempty final Charset aCharset,
                                    @Nonnegative final int nLinesToSkip,
                                    final int nLinesToRead,
                                    @Nonnull final Consumer <? super String> aLineCallback)
{
  try
  {
    ValueEnforcer.notNull (aCharset, "Charset");
    ValueEnforcer.isGE0 (nLinesToSkip, "LinesToSkip");
    final boolean bReadAllLines = nLinesToRead == CGlobal.ILLEGAL_UINT;
    ValueEnforcer.isTrue (bReadAllLines || nLinesToRead >= 0,
                          () -> "Line count may not be that negative: " + nLinesToRead);
    ValueEnforcer.notNull (aLineCallback, "LineCallback");

    // Start the action only if there is something to read
    if (aIS != null)
      if (bReadAllLines || nLinesToRead > 0)
      {
        try (final NonBlockingBufferedReader aBR = new NonBlockingBufferedReader (createReader (aIS, aCharset)))
        {
          // read with the passed charset
          _readFromReader (nLinesToSkip, nLinesToRead, aLineCallback, bReadAllLines, aBR);
        }
        catch (final IOException ex)
        {
          LOGGER.error ("Failed to read from reader", _propagate (ex));
        }
      }
  }
  finally
  {
    // Close input stream anyway
    close (aIS);
  }
}