本文整理汇总了Java中com.helger.commons.string.StringParser.parseInt方法的典型用法代码示例。如果您正苦于以下问题:Java StringParser.parseInt方法的具体用法?Java StringParser.parseInt怎么用?Java StringParser.parseInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.helger.commons.string.StringParser
的用法示例。
在下文中一共展示了StringParser.parseInt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToNative
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
@Nullable
public ReIndexWorkItem convertToNative (@Nonnull final IMicroElement aElement)
{
final IIndexerWorkItem aWorkItem = MicroTypeConverter.convertToNative (aElement.getFirstChildElement (ELEMENT_WORK_ITEM),
IndexerWorkItem.class);
final LocalDateTime aMaxRetryDT = aElement.getAttributeValueWithConversion (ATTR_MAX_RETRY_DT, LocalDateTime.class);
final String sRetryCount = aElement.getAttributeValue (ATTR_RETRY_COUNT);
final int nRetryCount = StringParser.parseInt (sRetryCount, -1);
if (nRetryCount < 0)
throw new IllegalStateException ("Invalid retry count '" + sRetryCount + "'");
final LocalDateTime aPreviousRetryDT = aElement.getAttributeValueWithConversion (ATTR_PREVIOUS_RETRY_DT,
LocalDateTime.class);
final LocalDateTime aNextRetryDT = aElement.getAttributeValueWithConversion (ATTR_NEXT_RETRY_DT,
LocalDateTime.class);
return new ReIndexWorkItem (aWorkItem, aMaxRetryDT, nRetryCount, aPreviousRetryDT, aNextRetryDT);
}
示例2: convertToNative
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
@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);
}
示例3: build
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
/**
* Consumes the supplied Reader and uses it to construct a populated Homoglyph
* object.
*
* @param aReader
* a Reader object that provides access to homoglyph data (see the
* bundled char_codes.txt file for an example of the required format)
* @return a Homoglyph object populated using the data returned by the Reader
* object
* @throws IOException
* if the specified Reader cannot be read
*/
@Nonnull
public static Homoglyph build (@Nonnull @WillClose final Reader aReader) throws IOException
{
ValueEnforcer.notNull (aReader, "reader");
try (final NonBlockingBufferedReader aBR = new NonBlockingBufferedReader (aReader))
{
final ICommonsList <IntSet> aList = new CommonsArrayList <> ();
String sLine;
while ((sLine = aBR.readLine ()) != null)
{
sLine = sLine.trim ();
if (sLine.startsWith ("#") || sLine.length () == 0)
continue;
final IntSet aSet = new IntSet (sLine.length () / 3);
for (final String sCharCode : StringHelper.getExploded (',', sLine))
{
final int nVal = StringParser.parseInt (sCharCode, 16, -1);
if (nVal >= 0)
aSet.add (nVal);
}
aList.add (aSet);
}
return new Homoglyph (aList);
}
}
示例4: readAndUpdateIDCounter
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
@Override
protected final int readAndUpdateIDCounter (@Nonnegative final int nReserveCount)
{
final String sContent = SimpleFileIO.getFileAsString (m_aFile, CHARSET_TO_USE);
final int nRead = sContent != null ? StringParser.parseInt (sContent.trim (), 0) : 0;
SimpleFileIO.writeFile (m_aFile, Integer.toString (nRead + nReserveCount), CHARSET_TO_USE);
return nRead;
}
示例5: _readFromFile
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
private void _readFromFile (@Nonnull final IReadableResource aRes)
{
final IMicroDocument aDoc = MicroReader.readMicroXML (aRes);
if (aDoc == null)
throw new IllegalArgumentException ("Failed to read " + aRes + " as XML document!");
final IMicroElement eRoot = aDoc.getDocumentElement ();
// Read all sectors
for (final IMicroElement eSector : eRoot.getFirstChildElement ("sectors").getAllChildElements ("sector"))
{
final int nGroupNum = StringParser.parseInt (eSector.getAttributeValue ("groupnum"), CGlobal.ILLEGAL_UINT);
final IMultilingualText aName = MicroTypeConverter.convertToNative (eSector.getFirstChildElement ("name"),
ReadOnlyMultilingualText.class);
final UnitSector aSector = new UnitSector (nGroupNum, aName);
final Integer aKey = aSector.getIDObj ();
if (m_aSectors.containsKey (aKey))
throw new IllegalStateException ("A unit sector with group number " +
aSector.getID () +
" is already contained!");
m_aSectors.put (aKey, aSector);
}
// Read all item
for (final IMicroElement eItem : eRoot.getFirstChildElement ("body").getAllChildElements ("item"))
{
// TODO
eItem.getAttributeValue ("id");
}
}
示例6: getAttributeValueAsInt
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
default int getAttributeValueAsInt (@Nullable final String sAttrName, final int nDefault)
{
return StringParser.parseInt (getAttributeValue (sAttrName), nDefault);
}
示例7: _parseLayout
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
@Nullable
private static Pattern _parseLayout (@Nonnull @Nonempty final String sCountryCode,
@Nonnegative final int nExpectedLength,
@Nullable final String sFixedCheckDigits,
@Nullable final String sLayout)
{
// E.g. Burkina Faso has no layout
if (sLayout == null)
return null;
final StringBuilder aRegEx = new StringBuilder ();
// Always start with country code
// Depending on fixed check digits or not different check
if (sFixedCheckDigits != null)
aRegEx.append (Pattern.quote (sCountryCode + sFixedCheckDigits));
else
{
aRegEx.append (Pattern.quote (sCountryCode));
aRegEx.append ("[0-9]{2}");
}
int nLen = 4;
for (final String sPart : StringHelper.getExploded (',', sLayout))
{
final String [] aParts = RegExHelper.getAllMatchingGroupValues ("([0-9]+)([anc])", sPart);
if (aParts.length != 2)
throw new IllegalArgumentException ("Failed to parse layout part '" + sPart + "'");
final int nPartLen = StringParser.parseInt (aParts[0], CGlobal.ILLEGAL_UINT);
if (nPartLen <= 0)
throw new IllegalArgumentException ("Failed to parse layout part '" + sPart + "' - illegal numeric value");
nLen += nPartLen;
if (aParts[1].length () != 1)
throw new IllegalArgumentException ("Failed to parse layout part '" + sPart + "' - type length is invalid");
final char cType = aParts[1].charAt (0);
if (cType == 'a')
aRegEx.append ("[A-Z]{" + nPartLen + "}");
else
if (cType == 'n')
aRegEx.append ("[0-9]{" + nPartLen + "}");
else
if (cType == 'c')
aRegEx.append ("[a-zA-Z0-9]{" + nPartLen + "}");
else
throw new IllegalArgumentException ("Failed to parse layout part '" + sPart + "' - type is invalid");
}
if (nLen != nExpectedLength)
throw new IllegalArgumentException ("Failed to parse layout - length mismatch. Having " +
nLen +
" but expected " +
nExpectedLength);
return RegExCache.getPattern (aRegEx.toString ());
}
示例8: _readIBANDataFromXML
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
/**
* Read all IBAN country data from a file.
*/
private static void _readIBANDataFromXML ()
{
final IMicroDocument aDoc = MicroReader.readMicroXML (new ClassPathResource ("codelists/iban-country-data.xml"));
if (aDoc == null)
throw new InitializationException ("Failed to read IBAN country data [1]");
if (aDoc.getDocumentElement () == null)
throw new InitializationException ("Failed to read IBAN country data [2]");
final DateTimeFormatter aDTPattern = DateTimeFormatter.ISO_DATE;
for (final IMicroElement eCountry : aDoc.getDocumentElement ().getAllChildElements (ELEMENT_COUNTRY))
{
// get descriptive string
final String sDesc = eCountry.getTextContent ();
final String sCountryCode = sDesc.substring (0, 2);
if (CountryCache.getInstance ().getCountry (sCountryCode) == null)
s_aLogger.warn ("IBAN country data: no such country code '" + sCountryCode + "' - be careful");
LocalDate aValidFrom = null;
if (eCountry.hasAttribute (ATTR_VALIDFROM))
{
// Constant format, conforming to XML date
aValidFrom = PDTFromString.getLocalDateFromString (eCountry.getAttributeValue (ATTR_VALIDFROM), aDTPattern);
}
LocalDate aValidTo = null;
if (eCountry.hasAttribute (ATTR_VALIDUNTIL))
{
// Constant format, conforming to XML date
aValidTo = PDTFromString.getLocalDateFromString (eCountry.getAttributeValue (ATTR_VALIDUNTIL), aDTPattern);
}
final String sLayout = eCountry.getAttributeValue (ATTR_LAYOUT);
final String sCheckDigits = eCountry.getAttributeValue (ATTR_CHECKDIGITS);
// get expected length
final String sLen = eCountry.getAttributeValue (ATTR_LEN);
final int nExpectedLength = StringParser.parseInt (sLen, CGlobal.ILLEGAL_UINT);
if (nExpectedLength == CGlobal.ILLEGAL_UINT)
throw new InitializationException ("Failed to convert length '" + sLen + "' to int!");
if (s_aIBANData.containsKey (sCountryCode))
throw new IllegalArgumentException ("Country " + sCountryCode + " is already contained!");
s_aIBANData.put (sCountryCode,
IBANCountryData.createFromString (sCountryCode,
nExpectedLength,
sLayout,
sCheckDigits,
aValidFrom,
aValidTo,
sDesc));
}
}
示例9: _convertNumericCodes
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
private static String _convertNumericCodes (final String sNumericCode)
{
if (StringHelper.hasNoText (sNumericCode))
return null;
final String sRealNumericCode = StringHelper.replaceAll (sNumericCode, '\n', ' ');
// E.g. "22 to 25", "44 or 45", "21 to 23 or 31 to 33"
final ICommonsList <String> ret = new CommonsArrayList <> ();
// First split by "or"
final String [] aOrParts = RegExHelper.getSplitToArray (sRealNumericCode, " or ");
for (final String sOrPart : aOrParts)
{
if (sOrPart.contains (" to "))
{
// Split by "to"
final String [] aToParts = RegExHelper.getSplitToArray (sOrPart, " to ");
if (aToParts.length != 2)
throw new IllegalStateException (sRealNumericCode +
" ==> " +
Arrays.toString (aToParts) +
" ==> more than 2 parts");
final int nFrom = StringParser.parseInt (aToParts[0].trim (), -1);
final int nTo = StringParser.parseInt (aToParts[1].trim (), -1);
if (nFrom == -1 || nTo == -1)
throw new IllegalStateException (sRealNumericCode +
" ==> " +
Arrays.toString (aToParts) +
" ==> not numeric");
for (int i = nFrom; i <= nTo; ++i)
ret.add (Integer.toString (i));
}
else
{
// Explicit value
final String sRealOrPart = sOrPart.trim ();
if (!StringParser.isInt (sRealOrPart))
throw new IllegalStateException (sRealNumericCode + " ==> " + sRealOrPart + " is not numeric!");
ret.add (sRealOrPart);
}
}
return StringHelper.getImploded (",", ret);
}
示例10: getPlaceholderAsInt
import com.helger.commons.string.StringParser; //导入方法依赖的package包/类
public int getPlaceholderAsInt (@Nullable final String sKey, final int nDefault)
{
return StringParser.parseInt (getPlaceholder (sKey), nDefault);
}