本文整理汇总了Java中com.helger.commons.string.StringParser类的典型用法代码示例。如果您正苦于以下问题:Java StringParser类的具体用法?Java StringParser怎么用?Java StringParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringParser类属于com.helger.commons.string包,在下文中一共展示了StringParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testNullSafeEquals
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Test
public void testNullSafeEquals () throws MalformedURLException
{
_test ("s1", "s2");
_test (StringParser.parseBigDecimal ("12562136756"), StringParser.parseBigDecimal ("67673455"));
_test (Double.valueOf (3.1234d), Double.valueOf (23.456d));
_test (Float.valueOf (3.1234f), Float.valueOf (23.456f));
_test (new URL ("http://www.helger.com"), new URL ("http://www.google.com"));
_test (new boolean [] { true }, new boolean [] { false });
_test (new byte [] { 1 }, new byte [] { 2 });
_test (new char [] { 'a' }, new char [] { 'b' });
_test (new double [] { 2.1 }, new double [] { 2 });
_test (new float [] { 2.1f }, new float [] { 1.9f });
_test (new int [] { 5 }, new int [] { 6 });
_test (new long [] { 7 }, new long [] { 8 });
_test (new short [] { -9 }, new short [] { -10 });
final String s1 = "s1";
final String s2 = "S1";
assertTrue (EqualsHelper.equalsIgnoreCase (s1, s1));
assertTrue (EqualsHelper.equalsIgnoreCase (s1, s2));
assertTrue (EqualsHelper.equalsIgnoreCase (s2, s1));
assertFalse (EqualsHelper.equalsIgnoreCase (s1, null));
assertFalse (EqualsHelper.equalsIgnoreCase (null, s2));
assertTrue (EqualsHelper.equalsIgnoreCase (null, null));
}
示例3: testParseBigDecimal
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Test
public void testParseBigDecimal ()
{
final BigDecimal aBD1M = StringParser.parseBigDecimal ("1000000");
assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1.000.000", L_DE, CGlobal.BIGDEC_MINUS_ONE));
assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", L_EN, CGlobal.BIGDEC_MINUS_ONE));
assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", (DecimalFormat) NumberFormat.getInstance (L_EN)));
assertEquals (new BigDecimal ("1234567.8901"),
LocaleParser.parseBigDecimal ("1.234.567,8901", L_DE, CGlobal.BIGDEC_MINUS_ONE));
assertEquals (CGlobal.BIGDEC_MINUS_ONE,
LocaleParser.parseBigDecimal ("... und denken", L_EN, CGlobal.BIGDEC_MINUS_ONE));
final ChoiceFormat aCF = new ChoiceFormat ("-1#negative|0#zero|1.0#one");
assertEquals (BigDecimal.valueOf (0.0), LocaleParser.parseBigDecimal ("zero", aCF, CGlobal.BIGDEC_MINUS_ONE));
try
{
LocaleParser.parseBigDecimal ("0", (DecimalFormat) null);
fail ();
}
catch (final NullPointerException ex)
{}
}
示例4: testGetIteratorWithConversion
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Test
public void testGetIteratorWithConversion ()
{
final Iterator <Integer> it = new MapperIterator <> (CollectionHelper.newList ("100", "-25"),
StringParser::parseIntObj);
assertNotNull (it);
assertTrue (it.hasNext ());
assertEquals (Integer.valueOf (100), it.next ());
assertTrue (it.hasNext ());
assertEquals (Integer.valueOf (-25), it.next ());
assertFalse (it.hasNext ());
try
{
it.next ();
fail ();
}
catch (final NoSuchElementException ex)
{}
it.remove ();
}
示例5: getValueWithUnit
import com.helger.commons.string.StringParser; //导入依赖的package包/类
/**
* Convert the passed string value with unit into a structured
* {@link CSSSimpleValueWithUnit}. Example: parsing <code>5px</code> will
* result in the numeric value <code>5</code> and the unit
* <code>ECSSUnit.PX</code>. The special value "0" is returned with the unit
* "px".
*
* @param sCSSValue
* The value to be parsed. May be <code>null</code> and is trimmed
* inside this method.
* @param bWithPerc
* <code>true</code> to include the percentage unit, <code>false</code>
* to exclude the percentage unit.
* @return <code>null</code> if the passed value could not be converted to
* value and unit.
*/
@Nullable
public static CSSSimpleValueWithUnit getValueWithUnit (@Nullable final String sCSSValue, final boolean bWithPerc)
{
String sRealValue = StringHelper.trim (sCSSValue);
if (StringHelper.hasText (sRealValue))
{
// Special case for 0!
if (sRealValue.equals ("0"))
return new CSSSimpleValueWithUnit (BigDecimal.ZERO, ECSSUnit.PX);
final ECSSUnit eUnit = bWithPerc ? getMatchingUnitInclPercentage (sRealValue)
: getMatchingUnitExclPercentage (sRealValue);
if (eUnit != null)
{
// Cut the unit off
sRealValue = sRealValue.substring (0, sRealValue.length () - eUnit.getName ().length ()).trim ();
final BigDecimal aValue = StringParser.parseBigDecimal (sRealValue);
if (aValue != null)
return new CSSSimpleValueWithUnit (aValue, eUnit);
}
}
return null;
}
示例6: convertToNative
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Nonnull
public LineDashPatternSpec convertToNative (@Nonnull final IMicroElement aElement)
{
final float fPhase = StringParser.parseFloat (aElement.getAttributeValue (ATTR_PHASE), Float.NaN);
final ICommonsList <IMicroElement> aChildren = aElement.getAllChildElements (ELEMENT_PATTERN);
final float [] aPattern = new float [aChildren.size ()];
int nIndex = 0;
for (final IMicroElement ePattern : aChildren)
{
aPattern[nIndex] = ePattern.getAttributeValueAsFloat (ATTR_ITEM, Float.NaN);
if (Float.isNaN (aPattern[nIndex]))
aPattern[nIndex] = ePattern.getAttributeValueAsFloat ("patternitem", Float.NaN);
nIndex++;
}
return new LineDashPatternSpec (aPattern, fPhase);
}
示例7: convertToNative
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Nonnull
public PModePayloadProfile convertToNative (final IMicroElement aElement)
{
final String sName = aElement.getAttributeValue (ATTR_NAME);
final IMimeType aMimeType = MimeTypeParser.parseMimeType (aElement.getAttributeValue (ATTR_MIME_TYPE));
final String sXSDFilename = aElement.getAttributeValue (ATTR_XSD_FILENAME);
final Integer aMaxSizeKB = aElement.getAttributeValueWithConversion (ATTR_MAX_SIZE_KB, Integer.class);
final EMandatory eMandatory = EMandatory.valueOf (StringParser.parseBool (aElement.getAttributeValue (ATTR_MANDATORY),
false));
return new PModePayloadProfile (sName, aMimeType, sXSDFilename, aMaxSizeKB, eMandatory);
}
示例8: 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);
}
示例9: 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);
}
}
示例10: _extSplit
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Nonnull
@ReturnsMutableCopy
private static String [] _extSplit (@Nonnull final String s)
{
final String [] aDotParts = StringHelper.getExplodedArray ('.', s, 2);
if (aDotParts.length == 2)
{
// Dots always take precedence
return aDotParts;
}
if (StringParser.isInt (aDotParts[0]))
{
// If it is numeric, use the dot parts anyway (e.g. for "5" or "-1")
return aDotParts;
}
final String [] aDashParts = StringHelper.getExplodedArray ('-', s, 2);
if (aDashParts.length == 1)
{
// Neither dot nor dash present
return aDotParts;
}
// More matches for dash split! (e.g. "0-RC1")
return aDashParts;
}
示例11: 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;
}
示例12: readAndUpdateIDCounter
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Override
protected final long readAndUpdateIDCounter (@Nonnegative final int nReserveCount)
{
final String sContent = SimpleFileIO.getFileAsString (m_aFile, CHARSET_TO_USE);
final long nRead = sContent != null ? StringParser.parseLong (sContent.trim (), 0) : 0;
SimpleFileIO.writeFile (m_aFile, Long.toString (nRead + nReserveCount), CHARSET_TO_USE);
return nRead;
}
示例13: testEquals_BigDecimal
import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Test
public void testEquals_BigDecimal ()
{
final BigDecimal bd1 = StringParser.parseBigDecimal ("5.5");
final BigDecimal bd2 = StringParser.parseBigDecimal ("5.49999");
CommonsAssert.assertEquals (bd1, bd1);
CommonsAssert.assertEquals (bd1, StringParser.parseBigDecimal ("5.5000"));
CommonsAssert.assertEquals (bd1, StringParser.parseBigDecimal ("5.50000000000000000"));
CommonsAssert.assertNotEquals (bd1, bd2);
}
示例14: IBANCountryData
import com.helger.commons.string.StringParser; //导入依赖的package包/类
/**
* @param nExpectedLength
* The total expected length. Serves mainly as a checksum field to
* check whether the length of the passed fields matches.
* @param aPattern
* <code>null</code> or the RegEx pattern to valid values of this
* country.
* @param sFixedCheckDigits
* <code>null</code> or fixed check digits (of length 2)
* @param aValidFrom
* Validity start date. May be <code>null</code>.
* @param aValidTo
* Validity end date. May be <code>null</code>.
* @param aElements
* The IBAN elements for this country. May not be <code>null</code>.
*/
public IBANCountryData (@Nonnegative final int nExpectedLength,
@Nullable final Pattern aPattern,
@Nullable final String sFixedCheckDigits,
@Nullable final LocalDate aValidFrom,
@Nullable final LocalDate aValidTo,
@Nonnull final List <IBANElement> aElements)
{
super (aValidFrom, aValidTo);
ValueEnforcer.notNull (aElements, "Elements");
if (sFixedCheckDigits != null)
{
ValueEnforcer.isTrue (sFixedCheckDigits.length () == 2, "Check digits must be length 2!");
ValueEnforcer.isTrue (StringParser.isUnsignedInt (sFixedCheckDigits), "Check digits must be all numeric!");
}
m_nExpectedLength = nExpectedLength;
m_aPattern = aPattern;
m_aElements = new CommonsArrayList <> (aElements);
m_sFixedCheckDigits = sFixedCheckDigits;
int nCalcedLength = 0;
for (final IBANElement aChar : aElements)
nCalcedLength += aChar.getLength ();
if (nCalcedLength != nExpectedLength)
throw new IllegalArgumentException ("Expected length=" + nExpectedLength + "; calced length=" + nCalcedLength);
}
示例15: _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");
}
}