Java Code Examples for com.helger.commons.string.StringParser#parseInt()

The following examples show how to use com.helger.commons.string.StringParser#parseInt() . 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: ColorMicroTypeConverter.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Color convertToNative (@Nonnull final IMicroElement aElement)
{
  final int nRed = StringParser.parseInt (aElement.getAttributeValue (ATTR_RED), 0);
  final int nGreen = StringParser.parseInt (aElement.getAttributeValue (ATTR_GREEN), 0);
  final int nBlue = StringParser.parseInt (aElement.getAttributeValue (ATTR_BLUE), 0);
  final int nAlpha = StringParser.parseInt (aElement.getAttributeValue (ATTR_ALPHA), 0xff);
  return new Color (nRed, nGreen, nBlue, nAlpha);
}
 
Example 2
Source File: IMicroAttributeContainer.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
default int getAttributeValueAsInt (@Nullable final String sAttrName, final int nDefault)
{
  return StringParser.parseInt (getAttributeValue (sAttrName), nDefault);
}
 
Example 3
Source File: IMicroAttributeContainer.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
default int getAttributeValueAsInt (@Nullable final String sNamespaceURI,
                                    @Nullable final String sAttrName,
                                    final int nDefault)
{
  return StringParser.parseInt (getAttributeValue (sNamespaceURI, sAttrName), nDefault);
}
 
Example 4
Source File: IMicroAttributeContainer.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
default int getAttributeValueAsInt (@Nullable final IMicroQName aAttrName, final int nDefault)
{
  return StringParser.parseInt (getAttributeValue (aAttrName), nDefault);
}
 
Example 5
Source File: FileIntIDFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Override
@MustBeLocked (ELockType.WRITE)
protected final int readAndUpdateIDCounter (@Nonnegative final int nReserveCount)
{
  // Read the old content
  final String sContent = SimpleFileIO.getFileAsString (m_aFile, CHARSET_TO_USE);
  final int nRead = sContent != null ? StringParser.parseInt (sContent.trim (), 0) : 0;

  // Write the new content to the new file
  // This will fail, if the disk is full
  SimpleFileIO.writeFile (m_aNewFile, Integer.toString (nRead + nReserveCount), CHARSET_TO_USE);

  FileIOError aIOError;
  boolean bRenamedToPrev = false;
  if (m_aFile.exists ())
  {
    // Rename the existing file to the prev file
    aIOError = FileOperationManager.INSTANCE.renameFile (m_aFile, m_aPrevFile);
    bRenamedToPrev = true;
  }
  else
    aIOError = new FileIOError (EFileIOOperation.RENAME_FILE, EFileIOErrorCode.NO_ERROR);
  if (aIOError.isSuccess ())
  {
    // Rename the new file to the destination file
    aIOError = FileOperationManager.INSTANCE.renameFile (m_aNewFile, m_aFile);
    if (aIOError.isSuccess ())
    {
      // Finally delete the prev file (may not be existing for fresh
      // instances)
      aIOError = FileOperationManager.INSTANCE.deleteFileIfExisting (m_aPrevFile);
    }
    else
    {
      // 2nd rename failed
      // -> Revert original rename to stay as consistent as possible
      if (bRenamedToPrev)
        FileOperationManager.INSTANCE.renameFile (m_aPrevFile, m_aFile);
    }
  }
  if (aIOError.isFailure ())
    throw new IllegalStateException ("Error on rename(existing-old)/rename(new-existing)/delete(old): " + aIOError);

  return nRead;
}