Java Code Examples for com.helger.commons.ValueEnforcer#notEmpty()

The following examples show how to use com.helger.commons.ValueEnforcer#notEmpty() . 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: AbstractWALDAO.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called if recovery from the WAL file (partially) failed an
 * analysis might be needed.
 */
final void _maintainWALFileAfterProcessing (@Nonnull @Nonempty final String sWALFilename)
{
  ValueEnforcer.notEmpty (sWALFilename, "WALFilename");
  final File aWALFile = m_aIO.getFile (sWALFilename);
  final File aNewFile = new File (aWALFile.getParentFile (),
                                  aWALFile.getName () + "." + PDTFactory.getCurrentMillis () + ".bup");

  if (FileOperationManager.INSTANCE.renameFile (aWALFile, aNewFile).isFailure ())
  {
    if (LOGGER.isErrorEnabled ())
      LOGGER.error ("Failed to rename WAL file '" +
                    aWALFile.getAbsolutePath () +
                    "' to '" +
                    aNewFile.getAbsolutePath () +
                    "'");
  }
  else
  {
    if (!isSilentMode ())
      if (LOGGER.isInfoEnabled ())
        LOGGER.info ("Maintained WAL file '" +
                     aWALFile.getAbsolutePath () +
                     "' as '" +
                     aNewFile.getAbsolutePath () +
                     "' for debugging purposes");
  }
}
 
Example 2
Source File: CSSSelectorMemberFunctionLike.java    From ph-css with Apache License 2.0 5 votes vote down vote up
public CSSSelectorMemberFunctionLike (@Nonnull @Nonempty final String sFuncName,
                                      @Nonnull final CSSExpression aParamExpr)
{
  ValueEnforcer.notEmpty (sFuncName, "FunctionName");
  if (!sFuncName.endsWith ("("))
    throw new IllegalArgumentException ("function name must end with a '('");
  ValueEnforcer.notNull (aParamExpr, "ParameterExpression");

  m_sFuncName = sFuncName;
  m_aParamExpr = aParamExpr;
}
 
Example 3
Source File: CSSRGB.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSSRGB setBlue (@Nonnull @Nonempty final String sBlue)
{
  ValueEnforcer.notEmpty (sBlue, "Blue");

  m_sBlue = sBlue;
  return this;
}
 
Example 4
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 5
Source File: CSSRect.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * Set the left coordinate.
 *
 * @param sLeft
 *        May neither be <code>null</code> nor empty.
 * @return this
 */
@Nonnull
public CSSRect setLeft (@Nonnull @Nonempty final String sLeft)
{
  ValueEnforcer.notEmpty (sLeft, "Left");

  m_sLeft = sLeft;
  return this;
}
 
Example 6
Source File: IFileFilter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param sFilename
 *        The filename to use. May neither be <code>null</code> nor empty.
 * @return The created {@link IFileFilter}. Never <code>null</code>.
 */
@Nonnull
static IFileFilter filenameEqualsIgnoreCase (@Nonnull @Nonempty final String sFilename)
{
  ValueEnforcer.notEmpty (sFilename, "Filename");
  return aFile -> aFile != null && sFilename.equalsIgnoreCase (FilenameHelper.getSecureFilename (aFile.getName ()));
}
 
Example 7
Source File: CSSExpressionMemberFunction.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param sFunctionName
 *        Function name. May neither be <code>null</code> nor empty.
 * @param aExpression
 *        Optional parameter expression. May be <code>null</code>.
 */
public CSSExpressionMemberFunction (@Nonnull @Nonempty final String sFunctionName,
                                    @Nullable final CSSExpression aExpression)
{
  ValueEnforcer.notEmpty (sFunctionName, "FunctionName");
  // expression may be null

  m_sFunctionName = _skipBracketsAtEnd (sFunctionName);
  m_aExpression = aExpression;
}
 
Example 8
Source File: CSSPageMarginBlock.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSSPageMarginBlock setPageMarginSymbol (@Nonnull @Nonempty final String sPargeMarginSymbol)
{
  ValueEnforcer.notEmpty (sPargeMarginSymbol, "PargeMarginSymbol");
  ValueEnforcer.isTrue (StringHelper.startsWith (sPargeMarginSymbol, '@'),
                        "Page margin symbol does not start with '@'!");
  m_sPageMarginSymbol = sPargeMarginSymbol;
  return this;
}
 
Example 9
Source File: CSSRGBA.java    From ph-css with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSSRGBA setGreen (@Nonnull @Nonempty final String sGreen)
{
  ValueEnforcer.notEmpty (sGreen, "Green");

  m_sGreen = sGreen;
  return this;
}
 
Example 10
Source File: CSSRect.java    From ph-css with Apache License 2.0 5 votes vote down vote up
/**
 * Set the bottom coordinate.
 *
 * @param sBottom
 *        May neither be <code>null</code> nor empty.
 * @return this
 */
@Nonnull
public CSSRect setBottom (@Nonnull @Nonempty final String sBottom)
{
  ValueEnforcer.notEmpty (sBottom, "Bottom");

  m_sBottom = sBottom;
  return this;
}
 
Example 11
Source File: MainFindOccurrances.java    From ph-ubl with Apache License 2.0 4 votes vote down vote up
public StackElement (@Nonnull final Class <?> aClass, @Nonnull final String sXMLName)
{
  m_aClass = ValueEnforcer.notNull (aClass, "Class");
  m_sXMLName = ValueEnforcer.notEmpty (sXMLName, "XMLName");
}
 
Example 12
Source File: JAXBDocumentType.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Simple constructor when you know what you are doing.
 *
 * @param aClass
 *        The JAXB generated class of the root element. May not be
 *        <code>null</code>. This class must have the <code>@XmlType</code>
 *        annotation and the package the class resides in must have the
 *        <code>@XmlSchema</code> annotation with a non-null
 *        <code>namespace</code> property!
 * @param aXSDs
 *        The classpath relative paths to the XML Schema. May not be
 *        <code>null</code> but maybe empty. If the main XSD imports another
 *        XSD, the imported XSD must come first in the list. So the XSDs
 *        without any dependencies must come first!
 * @param sNamespaceURI
 *        The namespace URI to use. May be <code>null</code>.
 * @param sLocalName
 *        The locale name of the element. May neither be <code>null</code> nor
 *        empty.
 * @since 9.4.0
 */
public JAXBDocumentType (@Nonnull final Class <?> aClass,
                         @Nullable final List <? extends ClassPathResource> aXSDs,
                         @Nullable final String sNamespaceURI,
                         @Nonnull @Nonempty final String sLocalName)
{
  ValueEnforcer.notNull (aClass, "Class");
  if (aXSDs != null)
  {
    ValueEnforcer.notEmptyNoNullValue (aXSDs, "XSDs");
    for (final ClassPathResource aRes : aXSDs)
      ValueEnforcer.isTrue (aRes.hasClassLoader (),
                            () -> "ClassPathResource " + aRes + " should define its ClassLoader for OSGI handling!");
  }
  ValueEnforcer.notEmpty (sLocalName, "sLocalName");

  // Check whether it is an @XmlType class
  final XmlType aXmlType = aClass.getAnnotation (XmlType.class);
  if (aXmlType == null)
    throw new IllegalArgumentException ("The passed class '" +
                                        aClass.getName () +
                                        "' does not have an @XmlType annotation!");

  // Get the package of the passed Class
  final Package aPackage = aClass.getPackage ();

  // The package must have the annotation "XmlSchema" with the corresponding
  // namespace it supports (maybe empty but not null). If the base XSD does
  // not contain any namespace URI, the XMLSchema annotation might be missing!
  final XmlSchema aXmlSchema = aPackage.getAnnotation (XmlSchema.class);
  if (aXmlSchema != null && aXmlSchema.namespace () == null)
    throw new IllegalArgumentException ("The package '" +
                                        aPackage.getName () +
                                        "' has no namespace URI in the @XmlSchema annotation!");

  m_aClass = aClass;
  if (aXSDs != null)
    m_aXSDs.addAll (aXSDs);
  m_sNamespaceURI = sNamespaceURI;
  m_sLocalName = sLocalName;
}
 
Example 13
Source File: ErrorLevel.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public ErrorLevel (@Nonnull @Nonempty final String sID, @Nonnegative final int nNumericLevel)
{
  m_sID = ValueEnforcer.notEmpty (sID, "ID");
  m_nNumericLevel = nNumericLevel;
}
 
Example 14
Source File: ParsedCmdLine.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
void internalAddUnhandledToken (@Nonnull @Nonempty final String sUnknownToken)
{
  ValueEnforcer.notEmpty (sUnknownToken, "UnknownToken");
  m_aUnknownTokens.add (sUnknownToken);
}
 
Example 15
Source File: HelpFormatter.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Print the help for <code>options</code> with the specified command line
 * syntax.
 *
 * @param aPW
 *        the writer to which the help will be written
 * @param nWidth
 *        the number of characters to be displayed on each line
 * @param sCmdLineSyntax
 *        the syntax for this application
 * @param sHeader
 *        the banner to display at the beginning of the help
 * @param aOptions
 *        the Options instance
 * @param nLeftPad
 *        the number of characters of padding to be prefixed to each line
 * @param nDescPad
 *        the number of characters of padding to be prefixed to each
 *        description line
 * @param sFooter
 *        the banner to display at the end of the help
 * @param bAutoUsage
 *        whether to print an automatically generated usage statement
 * @throws IllegalStateException
 *         if there is no room to print a line
 */
public void printHelp (@Nonnull final PrintWriter aPW,
                       final int nWidth,
                       @Nonnull @Nonempty final String sCmdLineSyntax,
                       @Nullable final String sHeader,
                       @Nonnull final Options aOptions,
                       final int nLeftPad,
                       final int nDescPad,
                       @Nullable final String sFooter,
                       final boolean bAutoUsage)
{
  ValueEnforcer.notEmpty (sCmdLineSyntax, "sCmdLineSyntax");

  if (bAutoUsage)
    printUsage (aPW, nWidth, sCmdLineSyntax, aOptions);
  else
    printUsage (aPW, nWidth, sCmdLineSyntax);

  if (sHeader != null && sHeader.trim ().length () > 0)
    printWrapped (aPW, nWidth, sHeader);

  printOptions (aPW, nWidth, aOptions, nLeftPad, nDescPad);

  if (sFooter != null && sFooter.trim ().length () > 0)
    printWrapped (aPW, nWidth, sFooter);
}
 
Example 16
Source File: JsonValueSerializerConstant.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public JsonValueSerializerConstant (@Nonnull @Nonempty final String sValue)
{
  ValueEnforcer.notEmpty (sValue, "Value");
  m_sValue = sValue;
}
 
Example 17
Source File: MockHasName.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public MockHasName (@Nonnull @Nonempty final String sName)
{
  m_sName = ValueEnforcer.notEmpty (sName, "Name");
}
 
Example 18
Source File: ConfigFileBuilder.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public ConfigFileBuilder addPathFromEnvVar (@Nonnull @Nonempty final String sEnvVarName)
{
  ValueEnforcer.notEmpty (sEnvVarName, "EnvVarName");
  return addPath ( () -> System.getenv ().get (sEnvVarName));
}
 
Example 19
Source File: JsonWriterSettings.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public final JsonWriterSettings setNewlineString (@Nonnull @Nonempty final String sNewlineString)
{
  m_sNewlineString = ValueEnforcer.notEmpty (sNewlineString, "NewlineString");
  return this;
}
 
Example 20
Source File: Base64OutputStream.java    From ph-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Set the newline bytes to be used, so that "\r\n" can be used instead of the
 * default "\n"
 *
 * @param aNewLineBytes
 *        The newline bytes to be used. May neither be <code>null</code> nor
 *        empty.
 * @since 9.3.4
 */
public void setNewLineBytes (@Nonnull @Nonempty final byte [] aNewLineBytes)
{
  ValueEnforcer.notEmpty (aNewLineBytes, "NewLineBytes");
  m_aNewLineBytes = ArrayHelper.getCopy (aNewLineBytes);
}