本文整理汇总了Java中com.helger.commons.CGlobal类的典型用法代码示例。如果您正苦于以下问题:Java CGlobal类的具体用法?Java CGlobal怎么用?Java CGlobal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGlobal类属于com.helger.commons包,在下文中一共展示了CGlobal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _getPeriodText
import com.helger.commons.CGlobal; //导入依赖的package包/类
private static String _getPeriodText (@Nonnull final LocalDateTime aNowLDT, @Nonnull final LocalDateTime aNotAfter)
{
final Period aPeriod = Period.between (aNowLDT.toLocalDate (), aNotAfter.toLocalDate ());
final Duration aDuration = Duration.between (aNowLDT.toLocalTime (),
aNotAfter.plus (1, ChronoUnit.DAYS).toLocalTime ());
long nSecs = aDuration.getSeconds ();
final long nHours = nSecs / CGlobal.SECONDS_PER_HOUR;
nSecs -= nHours * CGlobal.SECONDS_PER_HOUR;
final long nMinutes = nSecs / CGlobal.SECONDS_PER_MINUTE;
nSecs -= nMinutes * CGlobal.SECONDS_PER_MINUTE;
return aPeriod.getYears () +
" years, " +
aPeriod.getMonths () +
" months, " +
aPeriod.getDays () +
" days, " +
nHours +
" hours, " +
nMinutes +
" minutes and " +
nSecs +
" seconds";
}
示例2: _timedSearch
import com.helger.commons.CGlobal; //导入依赖的package包/类
private static void _timedSearch (@Nonnull final IThrowingRunnable <IOException> aRunnable,
@Nonnull final Query aQuery) throws IOException
{
final StopWatch aSW = StopWatch.createdStarted ();
try
{
aRunnable.run ();
}
finally
{
final long nMillis = aSW.stopAndGetMillis ();
s_aStatsQueryTimer.addTime (aQuery.toString (), nMillis);
if (nMillis > CGlobal.MILLISECONDS_PER_SECOND)
s_aLogger.warn ("Lucene Query " + aQuery + " took too long: " + nMillis + "ms");
}
}
示例3: getNodeAsBytes
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Convert the passed DOM node to an XML byte array using the provided XML
* writer settings.
*
* @param aNode
* The node to be converted to a byte array. May not be
* <code>null</code>.
* @param aSettings
* The XML writer settings to be used. May not be <code>null</code>.
* @return The byte array representation of the passed node.
* @since 8.6.3
*/
@Nullable
public static byte [] getNodeAsBytes (@Nonnull final Node aNode, @Nonnull final IXMLWriterSettings aSettings)
{
ValueEnforcer.notNull (aNode, "Node");
ValueEnforcer.notNull (aSettings, "Settings");
try (final NonBlockingByteArrayOutputStream aWriter = new NonBlockingByteArrayOutputStream (50 *
CGlobal.BYTES_PER_KILOBYTE))
{
// start serializing
if (writeToStream (aNode, aWriter, aSettings).isSuccess ())
return aWriter.toByteArray ();
}
catch (final Throwable t)
{
s_aLogger.error ("Error serializing DOM node with settings " + aSettings.toString (), t);
}
return null;
}
示例4: getNodeAsString
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Convert the passed micro node to an XML string using the provided settings.
*
* @param aNode
* The node to be converted to a string. May not be <code>null</code> .
* @param aSettings
* The XML writer settings to use. May not be <code>null</code>.
* @return The string representation of the passed node.
*/
@Nullable
public static String getNodeAsString (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
ValueEnforcer.notNull (aNode, "Node");
ValueEnforcer.notNull (aSettings, "Settings");
try (final NonBlockingStringWriter aWriter = new NonBlockingStringWriter (50 * CGlobal.BYTES_PER_KILOBYTE))
{
// start serializing
if (writeToWriter (aNode, aWriter, aSettings).isSuccess ())
return aWriter.getAsString ();
}
catch (final Throwable t)
{
s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
}
return null;
}
示例5: getNodeAsBytes
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Convert the passed micro node to an XML byte array using the provided
* settings.
*
* @param aNode
* The node to be converted to a byte array. May not be
* <code>null</code> .
* @param aSettings
* The XML writer settings to use. May not be <code>null</code>.
* @return The byte array representation of the passed node.
* @since 8.6.3
*/
@Nullable
public static byte [] getNodeAsBytes (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
ValueEnforcer.notNull (aNode, "Node");
ValueEnforcer.notNull (aSettings, "Settings");
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 *
CGlobal.BYTES_PER_KILOBYTE))
{
// start serializing
if (writeToStream (aNode, aBAOS, aSettings).isSuccess ())
return aBAOS.toByteArray ();
}
catch (final Throwable t)
{
s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
}
return null;
}
示例6: generateKey
import com.helger.commons.CGlobal; //导入依赖的package包/类
@Nonnull
public static SecretKey generateKey ()
{
final int nKeyLengthBytes = CryptoPolicy.isUnlimitedStrengthCryptoAvailable () ? 32 : 16;
try
{
// Use JCA
final KeyGenerator aKeyGen = KeyGenerator.getInstance ("AES");
aKeyGen.init (nKeyLengthBytes * CGlobal.BITS_PER_BYTE);
return aKeyGen.generateKey ();
}
catch (final GeneralSecurityException ex)
{
// Why so ever - create an AES key on our own!
final byte [] aBytes = new byte [nKeyLengthBytes];
RandomHelper.getRandom ().nextBytes (aBytes);
return new AESSecretKey (aBytes);
}
}
示例7: testGetChildTextContentWithConversionAndNS
import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testGetChildTextContentWithConversionAndNS ()
{
final String sNSURI = "my-namespace-uri";
final IMicroElement e = new MicroElement (sNSURI, "x");
assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
final IMicroElement y = e.appendElement (sNSURI, "y");
assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
y.appendText ("100");
assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
y.appendElement ("a");
assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
y.appendCDATA ("234");
assertEquals (BigInteger.valueOf (100234),
MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
}
示例8: CombinationGenerator
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Ctor
*
* @param aElements
* the elements to fill into the slots for creating all combinations
* (must not be empty!)
* @param nSlotCount
* the number of slots to use (must not be greater than the element
* count!)
*/
public CombinationGenerator (@Nonnull @Nonempty final ICommonsList <DATATYPE> aElements,
@Nonnegative final int nSlotCount)
{
ValueEnforcer.notEmpty (aElements, "Elements");
ValueEnforcer.isBetweenInclusive (nSlotCount, "SlotCount", 0, aElements.size ());
m_aElements = GenericReflection.uncheckedCast (aElements.toArray ());
m_aIndexResult = new int [nSlotCount];
final BigInteger aElementFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length);
final BigInteger aSlotFactorial = FactorialHelper.getAnyFactorialLinear (nSlotCount);
final BigInteger aOverflowFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length - nSlotCount);
m_aTotalCombinations = aElementFactorial.divide (aSlotFactorial.multiply (aOverflowFactorial));
// Can we use the fallback to long? Is much faster than using BigInteger
m_bUseLong = m_aTotalCombinations.compareTo (CGlobal.BIGINT_MAX_LONG) < 0;
m_nTotalCombinations = m_bUseLong ? m_aTotalCombinations.longValue () : CGlobal.ILLEGAL_ULONG;
reset ();
}
示例9: getWithoutPath
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Get the name of the passed file without any eventually leading path.
*
* @param sAbsoluteFilename
* The fully qualified file name. May be <code>null</code>.
* @return The name only or <code>null</code> if the passed parameter is
* <code>null</code>.
* @see #getIndexOfLastSeparator(String)
*/
@Nullable
public static String getWithoutPath (@Nullable final String sAbsoluteFilename)
{
/**
* Note: do not use <code>new File (sFilename).getName ()</code> since this
* only invokes the underlying FileSystem implementation which handles path
* handling only correctly on the native platform. Problem arose when
* running application on a Linux server and making a file upload from a
* Windows machine.
*/
if (sAbsoluteFilename == null)
return null;
final int nLastSepIndex = getIndexOfLastSeparator (sAbsoluteFilename);
return nLastSepIndex == CGlobal.ILLEGAL_UINT ? sAbsoluteFilename : sAbsoluteFilename.substring (nLastSepIndex + 1);
}
示例10: enableSoapLogging
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Enable the JAX-WS SOAP debugging. This shows the exchanged SOAP messages in
* the log file. By default this logging is disabled.
*
* @param bServerDebug
* <code>true</code> to enable server debugging, <code>false</code> to
* disable it.
* @param bClientDebug
* <code>true</code> to enable client debugging, <code>false</code> to
* disable it.
*/
public static void enableSoapLogging (final boolean bServerDebug, final boolean bClientDebug)
{
// Server debug mode
String sDebug = Boolean.toString (bServerDebug);
SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", sDebug);
SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", sDebug);
// Client debug mode
sDebug = Boolean.toString (bClientDebug);
SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.HttpTransportPipe.dump", sDebug);
SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.HttpTransportPipe.dump", sDebug);
// Enlarge dump size
if (bServerDebug || bClientDebug)
{
final String sValue = Integer.toString (2 * CGlobal.BYTES_PER_MEGABYTE);
SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.HttpAdapter.dumpTreshold", sValue);
SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold", sValue);
}
else
{
SystemProperties.removePropertyValue ("com.sun.xml.ws.transport.http.HttpAdapter.dumpTreshold");
SystemProperties.removePropertyValue ("com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold");
}
}
示例11: testGetAsTB
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Test method getAsTB
*/
@Test
public void testGetAsTB ()
{
// Use fixed locale for constant decimal separator
final SizeHelper aSH = SizeHelper.getSizeHelperOfLocale (Locale.ENGLISH);
// default
assertEquals ("0TB", aSH.getAsTB (0));
assertEquals ("5TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE));
// with decimals
assertEquals ("0.00TB", aSH.getAsTB (0, 2));
assertEquals ("5TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 0));
assertEquals ("5.0TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 1));
assertEquals ("5.00TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 2));
assertEquals ("5.000TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 3));
assertEquals ("5.0000TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 4));
}
示例12: getExtractedIntValue
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Extract the int representation of the passed bit set. To avoid loss of
* data, the bit set may not have more than 32 bits.
*
* @param aBS
* The bit set to extract the value from. May not be <code>null</code>.
* @return The extracted value. May be negative if the bit set has 32
* elements, the highest order bit is set.
*/
public static int getExtractedIntValue (@Nonnull final BitSet aBS)
{
ValueEnforcer.notNull (aBS, "BitSet");
final int nMax = aBS.length ();
ValueEnforcer.isTrue (nMax <= CGlobal.BITS_PER_INT,
() -> "Can extract only up to " + CGlobal.BITS_PER_INT + " bits");
int ret = 0;
for (int i = nMax - 1; i >= 0; --i)
{
ret <<= 1;
if (aBS.get (i))
ret += CGlobal.BIT_SET;
}
return ret;
}
示例13: getExtractedLongValue
import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
* Extract the long representation of the passed bit set. To avoid loss of
* data, the bit set may not have more than 64 bits.
*
* @param aBS
* The bit set to extract the value from. May not be <code>null</code>.
* @return The extracted value. May be negative if the bit set has 64
* elements, the highest order bit is set.
*/
public static long getExtractedLongValue (@Nonnull final BitSet aBS)
{
ValueEnforcer.notNull (aBS, "BitSet");
final int nMax = aBS.length ();
ValueEnforcer.isTrue (nMax <= CGlobal.BITS_PER_LONG,
() -> "Can extract only up to " + CGlobal.BITS_PER_LONG + " bits");
long ret = 0;
for (int i = nMax - 1; i >= 0; --i)
{
ret <<= 1;
if (aBS.get (i))
ret += CGlobal.BIT_SET;
}
return ret;
}
示例14: testAll
import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testAll ()
{
for (final EProcessorArchitecture e : EProcessorArchitecture.values ())
{
assertSame (e, EProcessorArchitecture.valueOf (e.name ()));
assertSame (e, EProcessorArchitecture.forBits (e.getBits ()));
}
final EProcessorArchitecture eArch = EProcessorArchitecture.getCurrentArchitecture ();
assertNotNull (eArch);
assertTrue (eArch.getBits () > 0);
assertTrue (eArch.getBytes () > 0);
if (EJVMVendor.getCurrentVendor ().isSun ())
{
// For Sun JVMs the architecture must be determined!
assertNotSame (eArch, EProcessorArchitecture.UNKNOWN);
}
assertEquals (CGlobal.ILLEGAL_UINT, EProcessorArchitecture.UNKNOWN.getBytes ());
assertEquals (CGlobal.ILLEGAL_UINT, EProcessorArchitecture.UNKNOWN.getBits ());
assertSame (EProcessorArchitecture.UNKNOWN, EProcessorArchitecture.forBits (1));
}
示例15: testGetWithoutTrailingZeroes
import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testGetWithoutTrailingZeroes ()
{
assertNull (MathHelper.getWithoutTrailingZeroes ((String) null));
assertNull (MathHelper.getWithoutTrailingZeroes ((BigDecimal) null));
assertEquals (BigDecimal.ZERO, MathHelper.getWithoutTrailingZeroes (BigDecimal.ZERO));
assertEquals (BigDecimal.ONE, MathHelper.getWithoutTrailingZeroes (BigDecimal.ONE));
assertEquals (BigDecimal.TEN, MathHelper.getWithoutTrailingZeroes (BigDecimal.TEN));
assertEquals (BigDecimal.ONE, MathHelper.getWithoutTrailingZeroes ("1.0000"));
assertEquals (CGlobal.BIGDEC_100, MathHelper.getWithoutTrailingZeroes ("100.000"));
assertEquals (new BigDecimal ("100.01"), MathHelper.getWithoutTrailingZeroes ("100.0100"));
assertEquals (new BigDecimal ("600"), MathHelper.getWithoutTrailingZeroes ("6e2"));
assertEquals (new BigDecimal ("0.1"), MathHelper.getWithoutTrailingZeroes ("0.1000"));
assertEquals (new BigDecimal ("0.001"), MathHelper.getWithoutTrailingZeroes ("0.001000"));
assertEquals (BigDecimal.ZERO, MathHelper.getWithoutTrailingZeroes ("0.00000"));
}