• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java StringParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.helger.commons.string.StringParser的典型用法代码示例。如果您正苦于以下问题:Java StringParser类的具体用法?Java StringParser怎么用?Java StringParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StringParser类属于com.helger.commons.string包,在下文中一共展示了StringParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:22,代码来源:ReIndexWorkItemMicroTypeConverter.java


示例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));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:EqualsHelperTest.java


示例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)
  {}
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:LocaleParserTest.java


示例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 ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:MapperIteratorTest.java


示例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;
}
 
开发者ID:phax,项目名称:ph-css,代码行数:40,代码来源:CSSNumberHelper.java


示例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);
}
 
开发者ID:phax,项目名称:ph-pdf-layout,代码行数:18,代码来源:LineDashPatternSpecMicroTypeConverter.java


示例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);
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:13,代码来源:PModePayloadProfileMicroTypeConverter.java


示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:10,代码来源:ColorMicroTypeConverter.java


示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:40,代码来源:HomoglyphBuilder.java


示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:Version.java


示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:9,代码来源:FileIntIDFactory.java


示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:9,代码来源:FileLongIDFactory.java


示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:11,代码来源:EqualsHelperTest.java


示例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);
}
 
开发者ID:phax,项目名称:ph-masterdata,代码行数:43,代码来源:IBANCountryData.java


示例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");
  }
}
 
开发者ID:phax,项目名称:ph-masterdata,代码行数:30,代码来源:UnitManager.java


示例16: main

import com.helger.commons.string.StringParser; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
  final String sRevision = "20130209";
  final String sSource = "http://dev.maxmind.com/geoip/codes/state_latlon";

  try (final CSVReader aReader = new CSVReader (FileHelper.getReader (new File ("src/test/resources/state_latlon-" +
                                                                                sRevision +
                                                                                ".csv"),
                                                                      StandardCharsets.ISO_8859_1)))
  {
    // Skip one row
    aReader.readNext ();

    final IMicroDocument aDoc = new MicroDocument ();
    final IMicroElement eRoot = aDoc.appendElement ("root");
    final IMicroElement eHeader = eRoot.appendElement ("header");
    eHeader.appendElement ("source").appendText (sSource);
    eHeader.appendElement ("revision").appendText (sRevision);

    List <String> aLine;
    while ((aLine = aReader.readNext ()) != null)
    {
      final String sISO = aLine.get (0);
      final BigDecimal aLatitude = StringParser.parseBigDecimal (aLine.get (1));
      final BigDecimal aLongitude = StringParser.parseBigDecimal (aLine.get (2));
      eRoot.appendElement ("entry")
           .setAttribute ("id", sISO)
           .setAttributeWithConversion ("latitude", aLatitude)
           .setAttributeWithConversion ("longitude", aLongitude);
    }
    MicroWriter.writeToFile (aDoc,
                             new File ("src/main/resources/codelists/latitude-longitude-us-" + sRevision + ".xml"));
  }
  s_aLogger.info ("Done");
}
 
开发者ID:phax,项目名称:ph-masterdata,代码行数:36,代码来源:MainReadLatLonState.java


示例17: main

import com.helger.commons.string.StringParser; //导入依赖的package包/类
public static void main (final String [] args) throws IOException
{
  final String sRevision = "20130209";
  final String sSource = "http://dev.maxmind.com/geoip/codes/country_latlon";

  try (final CSVReader aReader = new CSVReader (FileHelper.getReader (new File ("src/test/resources/country_latlon-" +
                                                                                sRevision +
                                                                                ".csv"),
                                                                      StandardCharsets.ISO_8859_1)))
  {
    // Skip one row
    aReader.readNext ();

    final IMicroDocument aDoc = new MicroDocument ();
    final IMicroElement eRoot = aDoc.appendElement ("root");
    final IMicroElement eHeader = eRoot.appendElement ("header");
    eHeader.appendElement ("source").appendText (sSource);
    eHeader.appendElement ("revision").appendText (sRevision);

    List <String> aLine;
    while ((aLine = aReader.readNext ()) != null)
    {
      final String sISO = aLine.get (0);
      final BigDecimal aLatitude = StringParser.parseBigDecimal (aLine.get (1));
      final BigDecimal aLongitude = StringParser.parseBigDecimal (aLine.get (2));
      eRoot.appendElement ("entry")
           .setAttribute ("id", sISO)
           .setAttributeWithConversion ("latitude", aLatitude)
           .setAttributeWithConversion ("longitude", aLongitude);
    }
    MicroWriter.writeToFile (aDoc,
                             new File ("src/main/resources/codelists/latitude-longitude-country-" +
                                       sRevision +
                                       ".xml"));
  }
  s_aLogger.info ("Done");
}
 
开发者ID:phax,项目名称:ph-masterdata,代码行数:38,代码来源:MainReadLatLonCountry.java


示例18: createSpecialValue

import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Nullable
public ICSSValue createSpecialValue (@Nonnull final ICSSProperty aProperty,
                                     @Nonnull @Nonempty final String sValue,
                                     final boolean bIsImportant)
{
  final double dValue = StringParser.parseDouble (sValue, Double.NaN);
  if (!Double.isNaN (dValue))
  {
    final int nPerc = (int) (dValue * 100);
    return new CSSValueList (ECSSProperty.OPACITY,
                             new ICSSProperty [] { new CSSPropertyFree (ECSSProperty.FILTER,
                                                                        ECSSVendorPrefix.MICROSOFT),
                                                   new CSSPropertyFree (ECSSProperty.FILTER),
                                                   aProperty.getClone (ECSSVendorPrefix.MOZILLA),
                                                   aProperty.getClone (ECSSVendorPrefix.WEBKIT),
                                                   aProperty },
                             new String [] { "\"progid:DXImageTransform.Microsoft.Alpha(Opacity=" +
                                             nPerc +
                                             ")\"",
                                             "alpha(opacity=" + nPerc + ")",
                                             sValue,
                                             sValue,
                                             sValue },
                             bIsImportant);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-css,代码行数:28,代码来源:CSSPropertyCustomizerOpacity.java


示例19: getTriState

import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Nonnull
protected static ETriState getTriState (@Nullable final String sAttrValue, final boolean bDefault)
{
  return sAttrValue == null ? ETriState.UNDEFINED : ETriState.valueOf (StringParser.parseBool (sAttrValue, bDefault));
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:6,代码来源:AbstractPModeMicroTypeConverter.java


示例20: testViceVersaConversion

import com.helger.commons.string.StringParser; //导入依赖的package包/类
@Test
public void testViceVersaConversion () throws UnsupportedEncodingException
{
  // Name is important!
  final ISettings aSrc = new Settings ("anonymous");
  aSrc.putIn ("field1a", BigInteger.valueOf (1234));
  aSrc.putIn ("field1b", BigInteger.valueOf (-23423424));
  aSrc.putIn ("field2a", BigDecimal.valueOf (12.34));
  aSrc.putIn ("field2b", BigDecimal.valueOf (-2342.334599424));
  aSrc.putIn ("field3a", "My wonderbra string\n(incl newline)");
  aSrc.putIn ("field3b", "");
  aSrc.putIn ("field9a", Boolean.TRUE);
  aSrc.putIn ("field9b", StringParser.parseByteObj ("5"));
  aSrc.putIn ("field9c", Character.valueOf ('ä'));
  aSrc.putIn ("fieldxa", PDTFactory.getCurrentLocalDate ());
  aSrc.putIn ("fieldxb", PDTFactory.getCurrentLocalTime ());
  aSrc.putIn ("fieldxc", PDTFactory.getCurrentLocalDateTime ());
  aSrc.putIn ("fieldxd", PDTFactory.getCurrentZonedDateTime ());
  aSrc.putIn ("fieldxe", Duration.ofHours (5));
  aSrc.putIn ("fieldxf", Period.ofDays (3));
  aSrc.putIn ("fieldxg", "Any byte ärräy".getBytes (StandardCharsets.UTF_8.name ()));

  final SettingsPersistenceProperties aSPP = new SettingsPersistenceProperties ();
  final String sSrc = aSPP.writeSettings (aSrc);
  assertNotNull (sSrc);

  // The created object is different, because now all values are String typed!
  final ISettings aDst1 = aSPP.readSettings (sSrc);
  assertNotNull (aDst1);

  // Reading the String typed version again should result in the same object
  final ISettings aDst2 = aSPP.readSettings (aSPP.writeSettings (aDst1));
  assertNotNull (aDst2);
  assertEquals (aDst1, aDst2);

  assertNotNull (aDst2.getAsLocalDate ("fieldxa"));
  assertNotNull (aDst2.getAsLocalTime ("fieldxb"));
  assertNotNull (aDst2.getAsLocalDateTime ("fieldxc"));
  assertNotNull (aDst2.getConvertedValue ("fieldxd", ZonedDateTime.class));
  assertNotNull (aDst2.getConvertedValue ("fieldxe", Duration.class));
  assertNotNull (aDst2.getConvertedValue ("fieldxf", Period.class));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:43,代码来源:SettingsPersistencePropertiesTest.java



注:本文中的com.helger.commons.string.StringParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Mesh类代码示例发布时间:2022-05-22
下一篇:
Java PropertySet类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap