当前位置: 首页>>代码示例>>Java>>正文


Java Wrapper类代码示例

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


Wrapper类属于com.helger.commons.wrapper包,在下文中一共展示了Wrapper类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRead

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Override
@Nonnull
protected EChange onRead (@Nonnull final IMicroDocument aDoc)
{
  // Read all child elements independent of the name - soft migration
  final Class <IMPLTYPE> aDataTypeClass = getDataTypeClass ();
  final Wrapper <EChange> aChange = new Wrapper <> (EChange.UNCHANGED);

  aDoc.getDocumentElement ().forAllChildElements (m_aReadElementFilter, eItem -> {
    final IMPLTYPE aItem = MicroTypeConverter.convertToNative (eItem, aDataTypeClass);
    _addItem (aItem, EDAOActionType.CREATE);
    if (aItem instanceof IDAOReadChangeAware)
      if (((IDAOReadChangeAware) aItem).isReadChanged ())
      {
        // Remember that something was changed while reading
        aChange.set (EChange.CHANGED);
      }
  });
  return aChange.get ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:AbstractMapBasedWALDAO.java

示例2: testParseDouble

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseDouble ()
{
  final double dDefault = 3.145667;

  // Object
  CommonsAssert.assertEquals (dDefault, StringParser.parseDouble ((Object) null, dDefault));
  CommonsAssert.assertEquals (1, StringParser.parseDouble (BigDecimal.ONE, dDefault));
  CommonsAssert.assertEquals (dDefault, StringParser.parseDouble (new Wrapper <> ("any"), dDefault));

  // String
  CommonsAssert.assertEquals (dDefault, StringParser.parseDouble ((String) null, dDefault));
  CommonsAssert.assertEquals (dDefault, StringParser.parseDouble ("", dDefault));
  CommonsAssert.assertEquals (1.2, StringParser.parseDouble ("1.2", dDefault));
  CommonsAssert.assertEquals (-1.23456, StringParser.parseDouble ("-1.23456", dDefault));
  CommonsAssert.assertEquals (dDefault, StringParser.parseDouble ("bla", dDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:18,代码来源:StringParserTest.java

示例3: testParseDoubleObj

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseDoubleObj ()
{
  final Double aDefault = Double.valueOf (3.145667);

  // Object
  assertNull (StringParser.parseDoubleObj ((Object) null));
  assertEquals (aDefault, StringParser.parseDoubleObj ((Object) null, aDefault));
  CommonsAssert.assertEquals (1, StringParser.parseDoubleObj (BigDecimal.ONE, aDefault));
  assertEquals (aDefault, StringParser.parseDoubleObj (new Wrapper <> ("any"), aDefault));

  // String
  assertNull (StringParser.parseDoubleObj ("foo"));
  assertEquals (aDefault, StringParser.parseDoubleObj ((String) null, aDefault));
  assertEquals (aDefault, StringParser.parseDoubleObj ("", aDefault));
  CommonsAssert.assertEquals (1.2, StringParser.parseDoubleObj ("1.2", aDefault));
  CommonsAssert.assertEquals (-1.23456, StringParser.parseDoubleObj ("-1.23456", aDefault));
  assertEquals (aDefault, StringParser.parseDoubleObj ("bla", aDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:StringParserTest.java

示例4: testParseFloat

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseFloat ()
{
  final float fDefault = 3.145667f;

  // Object
  CommonsAssert.assertEquals (fDefault, StringParser.parseFloat ((Object) null, fDefault));
  CommonsAssert.assertEquals (1, StringParser.parseFloat (BigDecimal.ONE, fDefault));
  CommonsAssert.assertEquals (fDefault, StringParser.parseFloat (new Wrapper <> ("any"), fDefault));

  // String
  CommonsAssert.assertEquals (fDefault, StringParser.parseFloat ((String) null, fDefault));
  CommonsAssert.assertEquals (fDefault, StringParser.parseFloat ("", fDefault));
  CommonsAssert.assertEquals (1.2, StringParser.parseFloat ("1.2", fDefault));
  CommonsAssert.assertEquals (-1.23456, StringParser.parseFloat ("-1.23456", fDefault));
  CommonsAssert.assertEquals (fDefault, StringParser.parseFloat ("bla", fDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:18,代码来源:StringParserTest.java

示例5: testParseFloatObj

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseFloatObj ()
{
  final Float aDefault = Float.valueOf (3.145667f);

  // Object
  assertNull (StringParser.parseFloatObj ((Object) null));
  assertEquals (aDefault, StringParser.parseFloatObj ((Object) null, aDefault));
  CommonsAssert.assertEquals (1, StringParser.parseFloatObj (BigDecimal.ONE, aDefault));
  assertEquals (aDefault, StringParser.parseFloatObj (new Wrapper <> ("any"), aDefault));

  // String
  assertNull (StringParser.parseFloatObj ("foo"));
  assertEquals (aDefault, StringParser.parseFloatObj ((String) null, aDefault));
  assertEquals (aDefault, StringParser.parseFloatObj ("", aDefault));
  CommonsAssert.assertEquals (1.2f, StringParser.parseFloatObj ("1.2", aDefault));
  CommonsAssert.assertEquals (-1.23456f, StringParser.parseFloatObj ("-1.23456", aDefault));
  assertEquals (aDefault, StringParser.parseFloatObj ("bla", aDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:StringParserTest.java

示例6: getFuzzyConverter

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
/**
 * Get the converter that can convert objects from aSrcClass to aDstClass. If
 * no exact match is found, the super-classes and interface of source and
 * destination class are searched for matching type converters. The first
 * match is returned.
 *
 * @param aSrcClass
 *        Source class. May not be <code>null</code>.
 * @param aDstClass
 *        Destination class. May not be <code>null</code>.
 * @return <code>null</code> if no such type converter exists, the converter
 *         object otherwise.
 */
@Nullable
ITypeConverter <?, ?> getFuzzyConverter (@Nullable final Class <?> aSrcClass, @Nullable final Class <?> aDstClass)
{
  if (aSrcClass == null || aDstClass == null)
    return null;

  return m_aRWLock.readLocked ( () -> {
    if (GlobalDebug.isDebugMode ())
    {
      // Perform a check, whether there is more than one potential converter
      // present!
      final ICommonsList <String> aAllConverters = new CommonsArrayList <> ();
      _iterateFuzzyConverters (aSrcClass, aDstClass, (aCurSrcClass, aCurDstClass, aConverter) -> {
        final boolean bExact = aSrcClass.equals (aCurSrcClass) && aDstClass.equals (aCurDstClass);
        aAllConverters.add ("[" + aCurSrcClass.getName () + "->" + aCurDstClass.getName () + "]");
        return bExact ? EContinue.BREAK : EContinue.CONTINUE;
      });
      if (aAllConverters.size () > 1)
        s_aLogger.warn ("The fuzzy type converter resolver returned more than 1 match for the conversion from " +
                        aSrcClass +
                        " to " +
                        aDstClass +
                        ": " +
                        aAllConverters);
    }

    // Iterate and find the first matching type converter
    final Wrapper <ITypeConverter <?, ?>> ret = new Wrapper <> ();
    _iterateFuzzyConverters (aSrcClass, aDstClass, (aCurSrcClass, aCurDstClass, aConverter) -> {
      ret.set (aConverter);
      return EContinue.BREAK;
    });
    return ret.get ();
  });
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:49,代码来源:TypeConverterRegistry.java

示例7: main

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@SuppressFBWarnings ("DMI_HARDCODED_ABSOLUTE_FILENAME")
public static void main (final String [] args)
{
  int nFilesOK = 0;
  int nFilesError = 0;
  final ICommonsOrderedMap <File, ParseException> aErrors = new CommonsLinkedHashMap<> ();
  final Wrapper <File> aCurrentFile = new Wrapper<> ();
  final ICSSParseExceptionCallback aHdl = ex -> aErrors.put (aCurrentFile.get (), ex);
  for (final File aFile : new FileSystemRecursiveIterator (new File ("/")).withFilter (IFileFilter.filenameEndsWith (".css")))
  {
    if (false)
      s_aLogger.info (aFile.getAbsolutePath ());
    aCurrentFile.set (aFile);
    final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30, aHdl);
    if (aCSS == null)
    {
      nFilesError++;
      s_aLogger.warn ("  " + aFile.getAbsolutePath () + " failed!");
    }
    else
      nFilesOK++;
  }

  s_aLogger.info ("Done");
  for (final Map.Entry <File, ParseException> aEntry : aErrors.entrySet ())
    s_aLogger.info ("  " + aEntry.getKey ().getAbsolutePath () + ":\n" + aEntry.getValue ().getMessage () + "\n");
  s_aLogger.info ("OK: " + nFilesOK + "; Error: " + nFilesError);
}
 
开发者ID:phax,项目名称:ph-css,代码行数:29,代码来源:MainReadAllCSSOnDisc.java

示例8: testParseByte

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseByte ()
{
  // Object
  assertEquals (1, StringParser.parseByte ((Object) "1", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "1.2", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "0", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "0000", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "-129", (byte) 0));
  assertEquals (-128, StringParser.parseByte ((Object) "-128", (byte) 0));
  assertEquals (-1, StringParser.parseByte ((Object) "-1", (byte) 0));
  assertEquals (44, StringParser.parseByte ((Object) "44", (byte) 0));
  assertEquals (127, StringParser.parseByte ((Object) "127", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "128", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "257", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "445566abcdef", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "abcdef445566", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) "", (byte) 0));
  assertEquals (0, StringParser.parseByte ((Object) null, (byte) 0));

  assertEquals (0, StringParser.parseByte (new Wrapper <> ("any"), (byte) 0));

  assertEquals (1, StringParser.parseByte (Byte.valueOf ((byte) 1), (byte) 0));
  assertEquals (1, StringParser.parseByte (Double.valueOf (1), (byte) 0));
  assertEquals (1, StringParser.parseByte (BigDecimal.ONE, (byte) 0));

  // String
  assertEquals (1, StringParser.parseByte ("1", (byte) 0));
  assertEquals (0, StringParser.parseByte ("1.2", (byte) 0));
  assertEquals (0, StringParser.parseByte ("0", (byte) 0));
  assertEquals (0, StringParser.parseByte ("0000", (byte) 0));
  assertEquals (0, StringParser.parseByte ("-129", (byte) 0));
  assertEquals (-128, StringParser.parseByte ("-128", (byte) 0));
  assertEquals (-1, StringParser.parseByte ("-1", (byte) 0));
  assertEquals (44, StringParser.parseByte ("44", (byte) 0));
  assertEquals (127, StringParser.parseByte ("127", (byte) 0));
  assertEquals (0, StringParser.parseByte ("128", (byte) 0));
  assertEquals (0, StringParser.parseByte ("257", (byte) 0));
  assertEquals (0, StringParser.parseByte ("445566", (byte) 0));
  assertEquals (0, StringParser.parseByte ("445566abcdef", (byte) 0));
  assertEquals (0, StringParser.parseByte ("abcdef445566", (byte) 0));
  assertEquals (0, StringParser.parseByte ("", (byte) 0));
  assertEquals (0, StringParser.parseByte (null, (byte) 0));

  final byte nDefault = 17;
  assertEquals (1, StringParser.parseByte ("1", nDefault));
  assertEquals (nDefault, StringParser.parseByte ("1.2", nDefault));
  assertEquals (0, StringParser.parseByte ("0", nDefault));
  assertEquals (0, StringParser.parseByte ("0000", nDefault));
  assertEquals (-1, StringParser.parseByte ("-1", nDefault));
  assertEquals (nDefault, StringParser.parseByte ("445566", nDefault));
  assertEquals (nDefault, StringParser.parseByte ("445566abcdef", nDefault));
  assertEquals (nDefault, StringParser.parseByte ("abcdef445566", nDefault));
  assertEquals (nDefault, StringParser.parseByte ("", nDefault));
  assertEquals (nDefault, StringParser.parseByte (null, nDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:57,代码来源:StringParserTest.java

示例9: testParseByteObj

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseByteObj ()
{
  final Byte b_1 = Byte.valueOf ((byte) -1);
  final Byte b0 = Byte.valueOf ((byte) 0);
  final Byte b1 = Byte.valueOf ((byte) 1);

  // Object
  assertEquals (b1, StringParser.parseByteObj ((Object) "1"));
  assertNull (StringParser.parseByteObj ((Object) "abc"));
  assertEquals (b1, StringParser.parseByteObj ((Object) "1", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "1.2", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "0", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "0000", b0));
  assertEquals (b_1, StringParser.parseByteObj ((Object) "-1", b0));
  assertEquals (Byte.valueOf ((byte) 44), StringParser.parseByteObj ((Object) "44", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "445566abcdef", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "abcdef445566", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) "", b0));
  assertEquals (b0, StringParser.parseByteObj ((Object) null, b0));

  assertEquals (b0, StringParser.parseByteObj (new Wrapper <> ("any"), b0));

  assertEquals (b1, StringParser.parseByteObj (Byte.valueOf ((byte) 1), b0));
  assertEquals (b1, StringParser.parseByteObj (Double.valueOf (1), b0));
  assertEquals (b1, StringParser.parseByteObj (BigDecimal.ONE, b0));

  // String
  assertEquals (b1, StringParser.parseByteObj ("1"));
  assertNull (StringParser.parseByteObj ("abc"));
  assertEquals (b1, StringParser.parseByteObj ("1", b0));
  assertEquals (b0, StringParser.parseByteObj ("1.2", b0));
  assertEquals (b0, StringParser.parseByteObj ("0", b0));
  assertEquals (b0, StringParser.parseByteObj ("0000", b0));
  assertEquals (b_1, StringParser.parseByteObj ("-1", b0));
  assertEquals (Byte.valueOf ((byte) 44), StringParser.parseByteObj ("44", b0));
  assertEquals (b0, StringParser.parseByteObj ("445566abcdef", b0));
  assertEquals (b0, StringParser.parseByteObj ("abcdef445566", b0));
  assertEquals (b0, StringParser.parseByteObj ("", b0));
  assertEquals (b0, StringParser.parseByteObj (null, b0));

  final Byte aDefault = Byte.valueOf ((byte) 17);
  assertEquals (b1, StringParser.parseByteObj ("1", aDefault));
  assertEquals (aDefault, StringParser.parseByteObj ("1.2", aDefault));
  assertEquals (b0, StringParser.parseByteObj ("0", aDefault));
  assertEquals (b0, StringParser.parseByteObj ("0000", aDefault));
  assertEquals (b_1, StringParser.parseByteObj ("-1", aDefault));
  assertEquals (Byte.valueOf ((byte) 44), StringParser.parseByteObj ("44", aDefault));
  assertEquals (aDefault, StringParser.parseByteObj ("445566abcdef", aDefault));
  assertEquals (aDefault, StringParser.parseByteObj ("abcdef445566", aDefault));
  assertEquals (aDefault, StringParser.parseByteObj ("", aDefault));
  assertEquals (aDefault, StringParser.parseByteObj (null, aDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:54,代码来源:StringParserTest.java

示例10: testParseInt

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseInt ()
{
  // Object
  assertEquals (1, StringParser.parseInt ((Object) "1", 0));
  assertEquals (0, StringParser.parseInt ((Object) "1.2", 0));
  assertEquals (0, StringParser.parseInt ((Object) "0", 0));
  assertEquals (0, StringParser.parseInt ((Object) "0000", 0));
  assertEquals (-1, StringParser.parseInt ((Object) "-1", 0));
  assertEquals (445566, StringParser.parseInt ((Object) "445566", 0));
  assertEquals (0, StringParser.parseInt ((Object) "445566abcdef", 0));
  assertEquals (0, StringParser.parseInt ((Object) "abcdef445566", 0));
  assertEquals (0, StringParser.parseInt ((Object) "", 0));
  assertEquals (0, StringParser.parseInt ((Object) null, 0));

  assertEquals (0, StringParser.parseInt (new Wrapper <> ("any"), 0));

  assertEquals (1, StringParser.parseInt (Integer.valueOf (1), 0));
  assertEquals (1, StringParser.parseInt (Double.valueOf (1), 0));
  assertEquals (1, StringParser.parseInt (BigDecimal.ONE, 0));

  // String
  assertEquals (1, StringParser.parseInt ("1", 0));
  assertEquals (0, StringParser.parseInt ("1.2", 0));
  assertEquals (0, StringParser.parseInt ("0", 0));
  assertEquals (0, StringParser.parseInt ("0000", 0));
  assertEquals (-1, StringParser.parseInt ("-1", 0));
  assertEquals (445566, StringParser.parseInt ("445566", 0));
  assertEquals (0, StringParser.parseInt ("445566abcdef", 0));
  assertEquals (0, StringParser.parseInt ("abcdef445566", 0));
  assertEquals (0, StringParser.parseInt ("", 0));
  assertEquals (0, StringParser.parseInt (null, 0));

  final int nDefault = 17;
  assertEquals (1, StringParser.parseInt ("1", nDefault));
  assertEquals (nDefault, StringParser.parseInt ("1.2", nDefault));
  assertEquals (0, StringParser.parseInt ("0", nDefault));
  assertEquals (0, StringParser.parseInt ("0000", nDefault));
  assertEquals (-1, StringParser.parseInt ("-1", nDefault));
  assertEquals (445566, StringParser.parseInt ("445566", nDefault));
  assertEquals (nDefault, StringParser.parseInt ("445566abcdef", nDefault));
  assertEquals (nDefault, StringParser.parseInt ("abcdef445566", nDefault));
  assertEquals (nDefault, StringParser.parseInt ("", nDefault));
  assertEquals (nDefault, StringParser.parseInt (null, nDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:46,代码来源:StringParserTest.java

示例11: testParseIntObj

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseIntObj ()
{
  // Object
  assertEquals (I1, StringParser.parseIntObj ((Object) "1"));
  assertNull (StringParser.parseIntObj ((Object) "abc"));
  assertEquals (I1, StringParser.parseIntObj ((Object) "1", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "1.2", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "0", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "0000", I0));
  assertEquals (I_1, StringParser.parseIntObj ((Object) "-1", I0));
  assertEquals (Integer.valueOf (445566), StringParser.parseIntObj ((Object) "445566", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "445566abcdef", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "abcdef445566", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) "", I0));
  assertEquals (I0, StringParser.parseIntObj ((Object) null, I0));

  assertEquals (I0, StringParser.parseIntObj (new Wrapper <> ("any"), I0));

  assertEquals (I1, StringParser.parseIntObj (Integer.valueOf (1), I0));
  assertEquals (I1, StringParser.parseIntObj (Double.valueOf (1), I0));
  assertEquals (I1, StringParser.parseIntObj (BigDecimal.ONE, I0));

  // String
  assertEquals (I1, StringParser.parseIntObj ("1"));
  assertNull (StringParser.parseIntObj ("abc"));
  assertEquals (I1, StringParser.parseIntObj ("1", I0));
  assertEquals (I0, StringParser.parseIntObj ("1.2", I0));
  assertEquals (I0, StringParser.parseIntObj ("0", I0));
  assertEquals (I0, StringParser.parseIntObj ("0000", I0));
  assertEquals (I_1, StringParser.parseIntObj ("-1", I0));
  assertEquals (Integer.valueOf (445566), StringParser.parseIntObj ("445566", I0));
  assertEquals (I0, StringParser.parseIntObj ("445566abcdef", I0));
  assertEquals (I0, StringParser.parseIntObj ("abcdef445566", I0));
  assertEquals (I0, StringParser.parseIntObj ("", I0));
  assertEquals (I0, StringParser.parseIntObj (null, I0));

  final Integer aDefault = Integer.valueOf (17);
  assertEquals (I1, StringParser.parseIntObj ("1", aDefault));
  assertEquals (aDefault, StringParser.parseIntObj ("1.2", aDefault));
  assertEquals (I0, StringParser.parseIntObj ("0", aDefault));
  assertEquals (I0, StringParser.parseIntObj ("0000", aDefault));
  assertEquals (I_1, StringParser.parseIntObj ("-1", aDefault));
  assertEquals (Integer.valueOf (445566), StringParser.parseIntObj ("445566", aDefault));
  assertEquals (aDefault, StringParser.parseIntObj ("445566abcdef", aDefault));
  assertEquals (aDefault, StringParser.parseIntObj ("abcdef445566", aDefault));
  assertEquals (aDefault, StringParser.parseIntObj ("", aDefault));
  assertEquals (aDefault, StringParser.parseIntObj (null, aDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:50,代码来源:StringParserTest.java

示例12: testParseLong

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseLong ()
{
  // Object
  assertEquals (1L, StringParser.parseLong ((Object) "1", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "1.2", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "0", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "0000", 0));
  assertEquals (-1L, StringParser.parseLong ((Object) "-1", 0));
  assertEquals (445566L, StringParser.parseLong ((Object) "445566", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "445566abcdef", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "abcdef445566", 0));
  assertEquals (0L, StringParser.parseLong ((Object) "", 0));
  assertEquals (0L, StringParser.parseLong ((Object) null, 0));

  assertEquals (0L, StringParser.parseLong (new Wrapper <> ("any"), 0));

  assertEquals (1L, StringParser.parseLong (Integer.valueOf (1), 0));
  assertEquals (1L, StringParser.parseLong (Double.valueOf (1), 0));
  assertEquals (1L, StringParser.parseLong (BigDecimal.ONE, 0));

  // String
  assertEquals (1L, StringParser.parseLong ("1", 0));
  assertEquals (0L, StringParser.parseLong ("1.2", 0));
  assertEquals (0L, StringParser.parseLong ("0", 0));
  assertEquals (0L, StringParser.parseLong ("0000", 0));
  assertEquals (-1L, StringParser.parseLong ("-1", 0));
  assertEquals (445566L, StringParser.parseLong ("445566", 0));
  assertEquals (445566445566L, StringParser.parseLong ("445566445566", 0));
  assertEquals (445566445566445566L, StringParser.parseLong ("445566445566445566", 0));
  assertEquals (0L, StringParser.parseLong ("445566abcdef", 0));
  assertEquals (0L, StringParser.parseLong ("abcdef445566", 0));
  assertEquals (0L, StringParser.parseLong ("", 0));
  assertEquals (0L, StringParser.parseLong (null, 0));

  final long nDefault = 171819171819171819L;
  assertEquals (1L, StringParser.parseLong ("1", nDefault));
  assertEquals (nDefault, StringParser.parseLong ("1.2", nDefault));
  assertEquals (0L, StringParser.parseLong ("0", nDefault));
  assertEquals (0L, StringParser.parseLong ("0000", nDefault));
  assertEquals (-1L, StringParser.parseLong ("-1", nDefault));
  assertEquals (445566L, StringParser.parseLong ("445566", nDefault));
  assertEquals (445566445566L, StringParser.parseLong ("445566445566", nDefault));
  assertEquals (445566445566445566L, StringParser.parseLong ("445566445566445566", nDefault));
  assertEquals (nDefault, StringParser.parseLong ("445566abcdef", nDefault));
  assertEquals (nDefault, StringParser.parseLong ("abcdef445566", nDefault));
  assertEquals (nDefault, StringParser.parseLong ("", nDefault));
  assertEquals (nDefault, StringParser.parseLong (null, nDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:50,代码来源:StringParserTest.java

示例13: testParseLongObj

import com.helger.commons.wrapper.Wrapper; //导入依赖的package包/类
@Test
public void testParseLongObj ()
{
  // Object
  assertEquals (L1, StringParser.parseLongObj ((Object) "1"));
  assertNull (StringParser.parseLongObj ((Object) "abc"));
  assertEquals (L1, StringParser.parseLongObj ((Object) "1", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "1.2", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "0", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "0000", L0));
  assertEquals (L_1, StringParser.parseLongObj ((Object) "-1", L0));
  assertEquals (Long.valueOf (445566), StringParser.parseLongObj ((Object) "445566", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "445566abcdef", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "abcdef445566", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) "", L0));
  assertEquals (L0, StringParser.parseLongObj ((Object) null, L0));

  assertEquals (L0, StringParser.parseLongObj (new Wrapper <> ("any"), L0));

  assertEquals (L1, StringParser.parseLongObj (Integer.valueOf (1), L0));
  assertEquals (L1, StringParser.parseLongObj (Double.valueOf (1), L0));
  assertEquals (L1, StringParser.parseLongObj (BigDecimal.ONE, L0));

  // String
  assertEquals (L1, StringParser.parseLongObj ("1"));
  assertNull (StringParser.parseLongObj ("abc"));
  assertEquals (L1, StringParser.parseLongObj ("1", L0));
  assertEquals (L0, StringParser.parseLongObj ("1.2", L0));
  assertEquals (L0, StringParser.parseLongObj ("0", L0));
  assertEquals (L0, StringParser.parseLongObj ("0000", L0));
  assertEquals (L_1, StringParser.parseLongObj ("-1", L0));
  assertEquals (Long.valueOf (445566), StringParser.parseLongObj ("445566", L0));
  assertEquals (L0, StringParser.parseLongObj ("445566abcdef", L0));
  assertEquals (L0, StringParser.parseLongObj ("abcdef445566", L0));
  assertEquals (L0, StringParser.parseLongObj ("", L0));
  assertEquals (L0, StringParser.parseLongObj (null, L0));

  final Long aDefault = Long.valueOf (-173267823468L);
  assertEquals (L1, StringParser.parseLongObj ("1", aDefault));
  assertEquals (aDefault, StringParser.parseLongObj ("1.2", aDefault));
  assertEquals (L0, StringParser.parseLongObj ("0", aDefault));
  assertEquals (L0, StringParser.parseLongObj ("0000", aDefault));
  assertEquals (L_1, StringParser.parseLongObj ("-1", aDefault));
  assertEquals (Long.valueOf (445566), StringParser.parseLongObj ("445566", aDefault));
  assertEquals (aDefault, StringParser.parseLongObj ("445566abcdef", aDefault));
  assertEquals (aDefault, StringParser.parseLongObj ("abcdef445566", aDefault));
  assertEquals (aDefault, StringParser.parseLongObj ("", aDefault));
  assertEquals (aDefault, StringParser.parseLongObj (null, aDefault));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:50,代码来源:StringParserTest.java


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