javax.annotation.RegEx#com.helger.commons.ValueEnforcer源码实例Demo

下面列出了javax.annotation.RegEx#com.helger.commons.ValueEnforcer 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ph-commons   文件: Graph.java
@Nonnull
public EChange removeNodeAndAllRelations (@Nonnull final IMutableGraphNode aNode)
{
  ValueEnforcer.notNull (aNode, "Node");

  if (!m_aNodes.containsKey (aNode.getID ()))
    return EChange.UNCHANGED;

  // Remove all affected relations from all nodes
  for (final IMutableGraphRelation aRelation : aNode.getAllRelations ())
    for (final IMutableGraphNode aNode2 : aRelation.getAllConnectedNodes ())
      aNode2.removeRelation (aRelation);

  // Remove the node itself
  if (removeNode (aNode).isUnchanged ())
    throw new IllegalStateException ("Inconsistency removing node and all relations");
  return EChange.CHANGED;
}
 
源代码2 项目: ph-commons   文件: IAutoSaveAware.java
/**
 * Execute a callback with autosave being disabled. Must be called outside a
 * writeLock, as this method locks itself!
 *
 * @param aCallable
 *        The callback to be executed
 * @return The result of the callback. May be <code>null</code>.
 * @throws EXTYPE
 *         In case of an error
 * @param <RETURNTYPE>
 *        Return type of the callable
 * @param <EXTYPE>
 *        Exception type that may be thrown
 */
@Nullable
default <RETURNTYPE, EXTYPE extends Exception> RETURNTYPE performWithoutAutoSaveThrowing (@Nonnull final IThrowingSupplier <RETURNTYPE, EXTYPE> aCallable) throws EXTYPE
{
  ValueEnforcer.notNull (aCallable, "Callable");

  beginWithoutAutoSave ();
  try
  {
    // Main call of callable
    return aCallable.get ();
  }
  finally
  {
    endWithoutAutoSave ();
  }
}
 
源代码3 项目: ph-commons   文件: FileHelper.java
@Nullable
public static RandomAccessFile getRandomAccessFile (@Nonnull final File aFile,
                                                    @Nonnull final ERandomAccessFileMode eMode)
{
  ValueEnforcer.notNull (aFile, "File");
  ValueEnforcer.notNull (eMode, "Mode");

  try
  {
    return new RandomAccessFile (aFile, eMode.getMode ());
  }
  catch (final FileNotFoundException ex)
  {
    return null;
  }
}
 
源代码4 项目: ph-commons   文件: ByteBuffersInputStream.java
/**
 * Reads as much as possible into the destination buffer.
 *
 * @param aDestByteBuffer
 *        The destination byte buffer to use. May not be <code>null</code>.
 * @return The number of bytes read. Always &ge; 0.
 */
@Nonnegative
public long read (@Nonnull final ByteBuffer aDestByteBuffer)
{
  ValueEnforcer.notNull (aDestByteBuffer, "DestByteBuffer");

  _checkClosed ();
  long nBytesRead = 0;
  while (m_nBufferIndex < m_aBuffers.length)
  {
    final ByteBuffer aByteBuffer = m_aBuffers[m_nBufferIndex];
    if (aByteBuffer.hasRemaining ())
      nBytesRead += ByteBufferHelper.transfer (aByteBuffer, aDestByteBuffer, false);
    if (!aDestByteBuffer.hasRemaining ())
      break;
    // Try next ByteBuffer
    ++m_nBufferIndex;
  }
  return nBytesRead;
}
 
源代码5 项目: ph-commons   文件: XPathHelper.java
/**
 * Create a new XPath expression for evaluation.
 *
 * @param aXPath
 *        The pre-created XPath object. May not be <code>null</code>.
 * @param sXPath
 *        The main XPath string to be evaluated
 * @return The {@link XPathExpression} object to be used.
 * @throws IllegalArgumentException
 *         if the XPath cannot be compiled
 */
@Nonnull
public static XPathExpression createNewXPathExpression (@Nonnull final XPath aXPath,
                                                        @Nonnull @Nonempty final String sXPath)
{
  ValueEnforcer.notNull (aXPath, "XPath");
  ValueEnforcer.notNull (sXPath, "XPathExpression");

  try
  {
    return aXPath.compile (sXPath);
  }
  catch (final XPathExpressionException ex)
  {
    throw new IllegalArgumentException ("Failed to compile XPath expression '" + sXPath + "'", ex);
  }
}
 
源代码6 项目: ph-commons   文件: ICommonsCollection.java
/**
 * Add all passed elements matching the provided filter after performing a
 * mapping using the provided function.
 *
 * @param aElements
 *        The elements to be added after mapping. May be <code>null</code>.
 * @param aMapper
 *        The mapping function to be executed for all provided elements. May
 *        not be <code>null</code>.
 * @param aFilter
 *        The filter to be applied on the mapped element. May be
 *        <code>null</code>.
 * @return {@link EChange#CHANGED} if at least one element was added,
 *         {@link EChange#UNCHANGED}. Never <code>null</code>.
 * @param <SRCTYPE>
 *        The source type to be mapped from
 * @since 8.5.2
 */
@Nonnull
default <SRCTYPE> EChange addAllMapped (@Nullable final SRCTYPE [] aElements,
                                        @Nonnull final Function <? super SRCTYPE, ? extends ELEMENTTYPE> aMapper,
                                        @Nullable final Predicate <? super ELEMENTTYPE> aFilter)
{
  ValueEnforcer.notNull (aMapper, "Mapper");

  if (aFilter == null)
    return addAllMapped (aElements, aMapper);

  EChange eChange = EChange.UNCHANGED;
  if (aElements != null)
    for (final SRCTYPE aValue : aElements)
    {
      final ELEMENTTYPE aMapped = aMapper.apply (aValue);
      if (aFilter.test (aMapped))
        eChange = eChange.or (add (aMapped));
    }
  return eChange;
}
 
源代码7 项目: ph-commons   文件: AbstractXMLSerializer.java
/**
 * Resolve the given namespace URI to a prefix using the known namespaces of
 * this stack.
 *
 * @param sNamespaceURI
 *        The namespace URI to resolve. May not be <code>null</code>. Pass
 *        in an empty string for an empty namespace URI!
 * @return <code>null</code> if no namespace prefix is required.
 */
@Nullable
private String _getUsedPrefixOfNamespace (@Nonnull final String sNamespaceURI)
{
  ValueEnforcer.notNull (sNamespaceURI, "NamespaceURI");

  // find existing prefix (iterate current to root)
  for (final NamespaceLevel aNSLevel : m_aStack)
  {
    final String sPrefix = aNSLevel.getPrefixOfNamespaceURI (sNamespaceURI);
    if (sPrefix != null)
      return sPrefix;
  }

  // no matching prefix found
  return null;
}
 
源代码8 项目: ph-commons   文件: CollectionHelper.java
/**
 * Gets a sublist excerpt of the passed list.
 *
 * @param <ELEMENTTYPE>
 *        Type of elements in list
 * @param aCont
 *        The backing list. May not be <code>null</code>.
 * @param nStartIndex
 *        The start index to use. Needs to be &ge; 0.
 * @param nSectionLength
 *        the length of the desired subset. If list is shorter than that,
 *        aIter will return a shorter section
 * @return The specified section of the passed list, or a shorter list if
 *         nStartIndex + nSectionLength is an invalid index. Never
 *         <code>null</code>.
 */
@Nonnull
@ReturnsMutableCopy
public static <ELEMENTTYPE> CommonsArrayList <ELEMENTTYPE> getSubList (@Nullable final List <ELEMENTTYPE> aCont,
                                                                       @Nonnegative final int nStartIndex,
                                                                       @Nonnegative final int nSectionLength)
{
  ValueEnforcer.isGE0 (nStartIndex, "StartIndex");
  ValueEnforcer.isGE0 (nSectionLength, "SectionLength");

  final int nSize = getSize (aCont);
  if (nSize == 0 || nStartIndex >= nSize)
    return newList (0);

  int nEndIndex = nStartIndex + nSectionLength;
  if (nEndIndex > nSize)
    nEndIndex = nSize;

  // Create a copy of the list because "subList" only returns a view of the
  // original list!
  return newList (aCont.subList (nStartIndex, nEndIndex));
}
 
源代码9 项目: ph-schematron   文件: PreprocessorLookup.java
public PreprocessorLookup (@Nonnull final PSSchema aSchema)
{
  ValueEnforcer.notNull (aSchema, "Schema");

  for (final PSPattern aPattern : aSchema.getAllPatterns ())
  {
    // Only handle abstract patterns
    if (aPattern.isAbstract ())
      m_aPatterns.put (aPattern.getID (), aPattern);

    for (final PSRule aRule : aPattern.getAllRules ())
    {
      // Only handle abstract rules
      if (aRule.isAbstract ())
        m_aRules.put (aRule.getID (), aRule);
    }
  }
}
 
源代码10 项目: ph-commons   文件: PathOperations.java
/**
 * Create a new directory. The direct parent directory already needs to exist.
 *
 * @param aDir
 *        The directory to be created. May not be <code>null</code>.
 * @return A non-<code>null</code> error code.
 */
@Nonnull
public static FileIOError createDir (@Nonnull final Path aDir)
{
  ValueEnforcer.notNull (aDir, "Directory");

  final Path aRealDir = _getUnifiedPath (aDir);
  return FileOperations.createDir (aRealDir.toFile ());

  // // Does the directory already exist?
  // if (Files.exists (aRealDir))
  // return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError
  // (EFileIOOperation.CREATE_DIR, aRealDir);
  //
  // // Is the parent directory writable?
  // final Path aParentDir = aRealDir.getParent ();
  // if (aParentDir != null && Files.exists (aParentDir) && !Files.isWritable
  // (aParentDir))
  // return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError
  // (EFileIOOperation.CREATE_DIR, aRealDir);
  //
  // return _perform (EFileIOOperation.CREATE_DIR, Files::createDirectory,
  // aRealDir);
}
 
源代码11 项目: ph-css   文件: CSSPropertyEnumOrNumbers.java
public CSSPropertyEnumOrNumbers (@Nonnull final ECSSProperty eProp,
                                 @Nullable final ECSSVendorPrefix eVendorPrefix,
                                 @Nullable final ICSSPropertyCustomizer aCustomizer,
                                 final boolean bWithPercentage,
                                 @Nonnegative final int nMinNumbers,
                                 @Nonnegative final int nMaxNumbers,
                                 @Nonnull @Nonempty final Iterable <String> aEnumValues)
{
  super (eProp, eVendorPrefix, aCustomizer, aEnumValues);
  ValueEnforcer.isGT0 (nMinNumbers, "MinNumbers");
  ValueEnforcer.isGT0 (nMaxNumbers, "MaxNumbers");
  if (nMaxNumbers < nMinNumbers)
    throw new IllegalArgumentException ("MaxNumbers (" +
                                        nMaxNumbers +
                                        ") must be >= MinNumbers (" +
                                        nMinNumbers +
                                        ")");
  m_bWithPercentage = bWithPercentage;
  m_nMinNumbers = nMinNumbers;
  m_nMaxNumbers = nMaxNumbers;
}
 
源代码12 项目: ph-css   文件: CSSStyleRule.java
@Nonnull
public CSSStyleRule addSelector (@Nonnegative final int nIndex, @Nonnull final CSSSelector aSelector)
{
  ValueEnforcer.isGE0 (nIndex, "Index");
  ValueEnforcer.notNull (aSelector, "Selector");

  if (nIndex >= getSelectorCount ())
    m_aSelectors.add (aSelector);
  else
    m_aSelectors.add (nIndex, aSelector);
  return this;
}
 
源代码13 项目: ph-commons   文件: IFileFilter.java
/**
 * @param sPrefix
 *        The extension to use. May neither be <code>null</code> nor empty.
 * @return The created {@link IFileFilter}. Never <code>null</code>.
 */
@Nonnull
static IFileFilter filenameStartsWith (@Nonnull @Nonempty final String sPrefix)
{
  ValueEnforcer.notEmpty (sPrefix, "Prefix");
  return aFile -> {
    if (aFile != null)
    {
      final String sSecureFilename = FilenameHelper.getSecureFilename (aFile.getName ());
      if (sSecureFilename != null)
        return sSecureFilename.startsWith (sPrefix);
    }
    return false;
  };
}
 
源代码14 项目: ph-schematron   文件: SchematronTestFile.java
public SchematronTestFile (@Nonnull @Nonempty final String sParentDirBaseName,
                           @Nonnull final IReadableResource aRes,
                           @Nonnull @Nonempty final String sFileBaseName)
{
  ValueEnforcer.notEmpty (sParentDirBaseName, "ParentDirBaseName");
  ValueEnforcer.notNull (aRes, "Resource");
  ValueEnforcer.notEmpty (sFileBaseName, "FileBaseName");

  m_sParentDirBaseName = sParentDirBaseName;
  m_aRes = aRes;
  m_sFileBaseName = sFileBaseName;
}
 
源代码15 项目: ph-css   文件: CSSSupportsConditionNested.java
@Nonnull
public CSSSupportsConditionNested addMember (@Nonnegative final int nIndex,
                                             @Nonnull final ICSSSupportsConditionMember aMember)
{
  ValueEnforcer.isGE0 (nIndex, "Index");
  ValueEnforcer.notNull (aMember, "SupportsConditionMember");

  if (nIndex >= getMemberCount ())
    m_aMembers.add (aMember);
  else
    m_aMembers.add (nIndex, aMember);
  return this;
}
 
源代码16 项目: ph-commons   文件: MutableBigDecimal.java
@Nonnull
public BigDecimal multiply (@Nonnull final BigDecimal aMultiplicand)
{
  ValueEnforcer.notNull (aMultiplicand, "Multiplicand");
  m_aValue = m_aValue.multiply (aMultiplicand);
  onAfterChange ();
  return m_aValue;
}
 
源代码17 项目: ph-css   文件: CSSRGBA.java
@Nonnull
public CSSRGBA setGreen (@Nonnull @Nonempty final String sGreen)
{
  ValueEnforcer.notEmpty (sGreen, "Green");

  m_sGreen = sGreen;
  return this;
}
 
源代码18 项目: ph-commons   文件: IntIntMap.java
public IntIntMap (final int nSize, final float fFillFactor)
{
  ValueEnforcer.isBetweenInclusive (fFillFactor, "FillFactor", 0f, 1f);
  ValueEnforcer.isGT0 (nSize, "Size");
  final int nCapacity = MapHelper.arraySize (nSize, fFillFactor);
  m_nMask = nCapacity - 1;
  m_fFillFactor = fFillFactor;

  m_aKeys = new int [nCapacity];
  m_aValues = _createValueArray (nCapacity);
  m_nThreshold = (int) (nCapacity * fFillFactor);
}
 
源代码19 项目: ph-commons   文件: SettingsPersistenceProperties.java
@Nonnull
public ESuccess writeSettings (@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS)
{
  ValueEnforcer.notNull (aOS, "OutputStream");

  try
  {
    final NonBlockingProperties aProps = new NonBlockingProperties ();
    // Must not be sorted, as Properties sorts them as it wishes...
    for (final Map.Entry <String, Object> aEntry : aSettings.entrySet ())
    {
      final String sName = aEntry.getKey ();
      final Object aValue = aEntry.getValue ();
      if (aValue instanceof ISettings)
        throw new IllegalArgumentException ("When saving settings to a Properties object, it may not contained nested settings! Now the key '" +
                                            sName +
                                            "' is mapped to a nested ISettings object!");
      final String sValue = TypeConverter.convert (aValue, String.class);
      aProps.put (sName, sValue);
    }
    // Does not close the output stream!
    aProps.store (aOS, aSettings.getName ());
    return ESuccess.SUCCESS;
  }
  catch (final IOException ex)
  {
    LOGGER.error ("Failed to write settings to properties file", ex);
    return ESuccess.FAILURE;
  }
  finally
  {
    StreamHelper.close (aOS);
  }
}
 
源代码20 项目: ph-commons   文件: MimeTypeInfoManager.java
/**
 * Get the primary (=first) mime type that is associated to the specified
 * filename extension.
 *
 * @param sExtension
 *        The filename extension to search. May not be <code>null</code>.
 * @return <code>null</code> if no mime type is associated with the passed
 *         extension.
 */
@Nullable
public String getPrimaryMimeTypeStringForExtension (@Nonnull final String sExtension)
{
  ValueEnforcer.notNull (sExtension, "Extension");

  final ICommonsList <MimeTypeInfo> aInfos = getAllInfosOfExtension (sExtension);
  if (aInfos != null && aInfos.isNotEmpty ())
    return aInfos.getFirst ().getPrimaryMimeTypeString ();
  return null;
}
 
源代码21 项目: ph-commons   文件: SizeLong.java
@Nonnull
@CheckReturnValue
public SizeLong getScaledToHeight (@Nonnegative final long nNewHeight)
{
  ValueEnforcer.isGT0 (nNewHeight, "NewHeight");

  if (m_nHeight == nNewHeight)
    return this;
  final double dMultFactory = MathHelper.getDividedDouble (nNewHeight, m_nHeight);
  return new SizeLong ((long) (m_nWidth * dMultFactory), nNewHeight);
}
 
源代码22 项目: ph-commons   文件: StackTraceHelper.java
public static void appendStackToString (@Nonnull final StringBuilder aSB,
                                        @Nonnull final StackTraceElement [] aStackTraceElements,
                                        @Nonnull final String sLineSeparator)
{
  ValueEnforcer.notNull (aSB, "StringBuilder");
  ValueEnforcer.notNull (aStackTraceElements, "StackTraceElements");
  ValueEnforcer.notNull (sLineSeparator, "LineSeparator");

  _appendSingleStackTraceToString (aSB, aStackTraceElements, null, true, sLineSeparator);
}
 
源代码23 项目: ph-schematron   文件: SchematronResourcePure.java
@Nonnull
public EValidity getSchematronValidity (@Nonnull final Node aXMLNode,
                                        @Nullable final String sBaseURI) throws Exception
{
  ValueEnforcer.notNull (aXMLNode, "XMLNode");

  if (!isValidSchematron ())
    return EValidity.INVALID;

  return getOrCreateBoundSchema ().validatePartially (aXMLNode, sBaseURI);
}
 
源代码24 项目: ph-commons   文件: PathOperations.java
/**
 * Rename a file.
 *
 * @param aSourceFile
 *        The original file name. May not be <code>null</code>.
 * @param aTargetFile
 *        The destination file name. May not be <code>null</code>.
 * @return A non-<code>null</code> error code.
 */
@Nonnull
public static FileIOError renameFile (@Nonnull final Path aSourceFile, @Nonnull final Path aTargetFile)
{
  ValueEnforcer.notNull (aSourceFile, "SourceFile");
  ValueEnforcer.notNull (aTargetFile, "TargetFile");

  final Path aRealSourceFile = _getUnifiedPath (aSourceFile);
  final Path aRealTargetFile = _getUnifiedPath (aTargetFile);

  // Does the source file exist?
  if (!aRealSourceFile.toFile ().isFile ())
    return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

  // Are source and target different?
  if (EqualsHelper.equals (aRealSourceFile, aRealTargetFile))
    return EFileIOErrorCode.SOURCE_EQUALS_TARGET.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

  // Does the target file already exist?
  if (aRealTargetFile.toFile ().exists ())
    return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError (EFileIOOperation.RENAME_FILE, aRealTargetFile);

  // Is the source parent directory writable?
  final Path aSourceParentDir = aRealSourceFile.getParent ();
  if (aSourceParentDir != null && !Files.isWritable (aSourceParentDir))
    return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_FILE, aRealSourceFile);

  // Is the target parent directory writable?
  final Path aTargetParentDir = aRealTargetFile.getParent ();
  if (aTargetParentDir != null && aTargetParentDir.toFile ().exists () && !Files.isWritable (aTargetParentDir))
    return EFileIOErrorCode.TARGET_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_FILE, aRealTargetFile);

  // Ensure parent of target directory is present
  PathHelper.ensureParentDirectoryIsPresent (aRealTargetFile);

  return _perform (EFileIOOperation.RENAME_FILE, PathOperations::_atomicMove, aRealSourceFile, aRealTargetFile);
}
 
源代码25 项目: ph-css   文件: CascadingStyleSheet.java
/**
 * Add a new <code>@namespace</code> rule at the end of the
 * <code>@namespace</code> rule list.
 *
 * @param aNamespaceRule
 *        The namespace rule to be added. May not be <code>null</code>.
 * @return this
 */
@Nonnull
public CascadingStyleSheet addNamespaceRule (@Nonnull final CSSNamespaceRule aNamespaceRule)
{
  ValueEnforcer.notNull (aNamespaceRule, "NamespaceRule");

  m_aNamespaceRules.add (aNamespaceRule);
  return this;
}
 
源代码26 项目: ph-schematron   文件: PSDir.java
public void addForeignElement (@Nonnull final IMicroElement aForeignElement)
{
  ValueEnforcer.notNull (aForeignElement, "ForeignElement");
  if (aForeignElement.hasParent ())
    throw new IllegalArgumentException ("ForeignElement already has a parent!");
  m_aContent.add (aForeignElement);
}
 
源代码27 项目: ph-commons   文件: JsonParser.java
@Nonnull
public JsonParser setTabSize (@Nonnegative final int nTabSize)
{
  ValueEnforcer.isGT0 (nTabSize, "TabSize");
  m_nTabSize = nTabSize;
  return this;
}
 
源代码28 项目: ph-commons   文件: StatisticsManager.java
@Nonnull
public static IMutableStatisticsHandlerTimer getTimerHandler (@Nonnull final Class <?> aClass)
{
  ValueEnforcer.notNull (aClass, "Class");

  return getTimerHandler (aClass.getName ());
}
 
源代码29 项目: ph-css   文件: CSSWriterSettings.java
@Nonnull
public final CSSWriterSettings setCSSVersion (@Nonnull final ECSSVersion eCSSVersion)
{
  ValueEnforcer.notNull (eCSSVersion, "CSSVersion");
  m_eCSSVersion = eCSSVersion;
  return this;
}
 
源代码30 项目: ph-commons   文件: MimeType.java
@Nonnull
public String getParametersAsString (@Nonnull final EMimeQuoting eQuotingAlgorithm)
{
  ValueEnforcer.notNull (eQuotingAlgorithm, "QuotingAlgorithm");

  if (m_aParameters.isEmpty ())
    return "";

  return _getParametersAsString (eQuotingAlgorithm);
}