idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
16,500
public void findDeadlockedThreads ( ) { final long [ ] aThreadIDs = m_aMBean . isSynchronizerUsageSupported ( ) ? m_aMBean . findDeadlockedThreads ( ) : m_aMBean . findMonitorDeadlockedThreads ( ) ; if ( ArrayHelper . isNotEmpty ( aThreadIDs ) ) { final Map < Thread , StackTraceElement [ ] > aAllStackTraces = Thread . getAllStackTraces ( ) ; Arrays . sort ( aThreadIDs ) ; final ThreadDeadlockInfo [ ] aThreadInfos = new ThreadDeadlockInfo [ aThreadIDs . length ] ; for ( int i = 0 ; i < aThreadInfos . length ; i ++ ) { final ThreadInfo aThreadInfo = m_aMBean . getThreadInfo ( aThreadIDs [ i ] ) ; Thread aFoundThread = null ; StackTraceElement [ ] aFoundStackTrace = null ; for ( final Map . Entry < Thread , StackTraceElement [ ] > aEnrty : aAllStackTraces . entrySet ( ) ) if ( aEnrty . getKey ( ) . getId ( ) == aThreadInfo . getThreadId ( ) ) { aFoundThread = aEnrty . getKey ( ) ; aFoundStackTrace = aEnrty . getValue ( ) ; break ; } if ( aFoundThread == null ) throw new IllegalStateException ( "Deadlocked Thread not found as defined by " + aThreadInfo . toString ( ) ) ; aThreadInfos [ i ] = new ThreadDeadlockInfo ( aThreadInfo , aFoundThread , aFoundStackTrace ) ; } if ( m_aCallbacks . isEmpty ( ) ) { if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Found a deadlock of " + aThreadInfos . length + " threads but no callbacks are present!" ) ; } else m_aCallbacks . forEach ( x -> x . onDeadlockDetected ( aThreadInfos ) ) ; } }
This is the main method to be invoked to find deadlocked threads . In case a deadlock is found all registered callbacks are invoked .
16,501
public static String getUnifiedURL ( final String sURL ) { return sURL == null ? null : sURL . trim ( ) . toLowerCase ( Locale . US ) ; }
Get the unified version of a URL . It trims leading and trailing spaces and lower - cases the URL .
16,502
public static boolean isValid ( final String sURL ) { if ( StringHelper . hasNoText ( sURL ) ) return false ; final String sUnifiedURL = getUnifiedURL ( sURL ) ; return PATTERN . matcher ( sUnifiedURL ) . matches ( ) ; }
Checks if a value is a valid URL .
16,503
public static void setEnabled ( final boolean bEnabled ) { s_aEnabled . set ( bEnabled ) ; if ( LOGGER . isInfoEnabled ( ) ) LOGGER . info ( "ValueEnforcer checks are now " + ( bEnabled ? "enabled" : "disabled" ) ) ; }
Enable or disable the checks . By default checks are enabled .
16,504
public void write ( final int b ) throws IOException { if ( m_nCount >= m_aBuf . length ) _flushBuffer ( ) ; m_aBuf [ m_nCount ++ ] = ( byte ) b ; }
Writes the specified byte to this buffered output stream .
16,505
public void parse ( ) throws JsonParseException { _readValue ( ) ; _skipSpaces ( ) ; final IJsonParsePosition aStartPos = m_aPos . getClone ( ) ; final int c = _readChar ( ) ; if ( c != EOI ) throw _parseEx ( aStartPos , "Invalid character " + _getPrintableChar ( c ) + " after JSON root object" ) ; }
Main parsing routine
16,506
public CSVWriter setLineEnd ( final String sLineEnd ) { ValueEnforcer . notNull ( sLineEnd , "LineEnd" ) ; m_sLineEnd = sLineEnd ; return this ; }
Set the line delimiting string .
16,507
public static KeyStore createKeyStoreWithOnlyOneItem ( final KeyStore aBaseKeyStore , final String sAliasToCopy , final char [ ] aAliasPassword ) throws GeneralSecurityException , IOException { ValueEnforcer . notNull ( aBaseKeyStore , "BaseKeyStore" ) ; ValueEnforcer . notNull ( sAliasToCopy , "AliasToCopy" ) ; final KeyStore aKeyStore = getSimiliarKeyStore ( aBaseKeyStore ) ; aKeyStore . load ( null , null ) ; ProtectionParameter aPP = null ; if ( aAliasPassword != null ) aPP = new PasswordProtection ( aAliasPassword ) ; aKeyStore . setEntry ( sAliasToCopy , aBaseKeyStore . getEntry ( sAliasToCopy , aPP ) , aPP ) ; return aKeyStore ; }
Create a new key store based on an existing key store
16,508
public static LoadedKeyStore loadKeyStore ( final IKeyStoreType aKeyStoreType , final String sKeyStorePath , final String sKeyStorePassword ) { ValueEnforcer . notNull ( aKeyStoreType , "KeyStoreType" ) ; if ( StringHelper . hasNoText ( sKeyStorePath ) ) return new LoadedKeyStore ( null , EKeyStoreLoadError . KEYSTORE_NO_PATH ) ; KeyStore aKeyStore = null ; try { aKeyStore = loadKeyStoreDirect ( aKeyStoreType , sKeyStorePath , sKeyStorePassword ) ; } catch ( final IllegalArgumentException ex ) { if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "No such key store '" + sKeyStorePath + "': " + ex . getMessage ( ) , ex . getCause ( ) ) ; return new LoadedKeyStore ( null , EKeyStoreLoadError . KEYSTORE_LOAD_ERROR_NON_EXISTING , sKeyStorePath , ex . getMessage ( ) ) ; } catch ( final Exception ex ) { final boolean bInvalidPW = ex instanceof IOException && ex . getCause ( ) instanceof UnrecoverableKeyException ; if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Failed to load key store '" + sKeyStorePath + "': " + ex . getMessage ( ) , bInvalidPW ? null : ex . getCause ( ) ) ; return new LoadedKeyStore ( null , bInvalidPW ? EKeyStoreLoadError . KEYSTORE_INVALID_PASSWORD : EKeyStoreLoadError . KEYSTORE_LOAD_ERROR_FORMAT_ERROR , sKeyStorePath , ex . getMessage ( ) ) ; } return new LoadedKeyStore ( aKeyStore , null ) ; }
Load the provided key store in a safe manner .
16,509
public static LoadedKey < KeyStore . SecretKeyEntry > loadSecretKey ( final KeyStore aKeyStore , final String sKeyStorePath , final String sKeyStoreKeyAlias , final char [ ] aKeyStoreKeyPassword ) { return _loadKey ( aKeyStore , sKeyStorePath , sKeyStoreKeyAlias , aKeyStoreKeyPassword , KeyStore . SecretKeyEntry . class ) ; }
Load the specified secret key entry from the provided key store .
16,510
private static boolean _match ( final byte [ ] aSrcBytes , final int nSrcOffset , final byte [ ] aCmpBytes ) { final int nEnd = aCmpBytes . length ; for ( int i = 0 ; i < nEnd ; ++ i ) if ( aSrcBytes [ nSrcOffset + i ] != aCmpBytes [ i ] ) return false ; return true ; }
Byte array match method
16,511
public static Charset determineXMLCharset ( final byte [ ] aBytes ) { ValueEnforcer . notNull ( aBytes , "Bytes" ) ; Charset aParseCharset = null ; int nSearchOfs = 0 ; if ( aBytes . length > 0 ) { try ( NonBlockingByteArrayInputStream aIS = new NonBlockingByteArrayInputStream ( aBytes , 0 , Math . min ( EUnicodeBOM . getMaximumByteCount ( ) , aBytes . length ) ) ) { final InputStreamAndCharset aISC = CharsetHelper . getInputStreamAndCharsetFromBOM ( aIS ) ; if ( aISC . hasBOM ( ) ) { nSearchOfs = aISC . getBOM ( ) . getByteCount ( ) ; } if ( aISC . hasCharset ( ) ) { aParseCharset = aISC . getCharset ( ) ; } } } if ( aParseCharset == null && aBytes . length - nSearchOfs >= 4 ) if ( _match ( aBytes , nSearchOfs , CS_UTF32_BE ) ) aParseCharset = CHARSET_UTF_32BE ; else if ( _match ( aBytes , nSearchOfs , CS_UTF32_LE ) ) aParseCharset = CHARSET_UTF_32LE ; else if ( _match ( aBytes , nSearchOfs , CS_UTF16_BE ) ) aParseCharset = StandardCharsets . UTF_16BE ; else if ( _match ( aBytes , nSearchOfs , CS_UTF16_LE ) ) aParseCharset = StandardCharsets . UTF_16LE ; else if ( _match ( aBytes , nSearchOfs , CS_UTF8 ) ) aParseCharset = StandardCharsets . UTF_8 ; else if ( _match ( aBytes , nSearchOfs , CS_EBCDIC ) ) aParseCharset = CHARSET_EBCDIC ; else if ( _match ( aBytes , nSearchOfs , CS_IBM290 ) ) aParseCharset = CHARSET_IBM290 ; if ( aParseCharset == null ) { aParseCharset = FALLBACK_CHARSET ; } return _parseXMLEncoding ( aBytes , nSearchOfs , aParseCharset ) ; }
Determine the XML charset
16,512
public static String getUnifiedValue ( final String sValue ) { final StringBuilder aSB = new StringBuilder ( ) ; StringHelper . replaceMultipleTo ( sValue , new char [ ] { '\r' , '\n' , '\t' } , ' ' , aSB ) ; return aSB . toString ( ) ; }
Avoid having header values spanning multiple lines . This has been deprecated by RFC 7230 and Jetty 9 . 3 refuses to parse these requests with HTTP 400 by default .
16,513
public void setHeader ( final String sName , final String sValue ) { if ( sValue != null ) _setHeader ( sName , sValue ) ; }
Set the passed header as is .
16,514
public void addHeader ( final String sName , final String sValue ) { if ( sValue != null ) _addHeader ( sName , sValue ) ; }
Add the passed header as is .
16,515
public static void enableSoapLogging ( final boolean bServerDebug , final boolean bClientDebug ) { 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 ) ; 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 ) ; 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" ) ; } }
Enable the JAX - WS SOAP debugging . This shows the exchanged SOAP messages in the log file . By default this logging is disabled .
16,516
public static int getUTF8ByteCount ( final String s ) { return s == null ? 0 : getUTF8ByteCount ( s . toCharArray ( ) ) ; }
Get the number of bytes necessary to represent the passed string as an UTF - 8 string .
16,517
public static int getUTF8ByteCount ( final char [ ] aChars ) { int nCount = 0 ; if ( aChars != null ) for ( final char c : aChars ) nCount += getUTF8ByteCount ( c ) ; return nCount ; }
Get the number of bytes necessary to represent the passed char array as an UTF - 8 string .
16,518
public static int getUTF8ByteCount ( final int c ) { ValueEnforcer . isBetweenInclusive ( c , "c" , Character . MIN_VALUE , Character . MAX_VALUE ) ; if ( c == 0 ) return 2 ; if ( c <= 0x7f ) return 1 ; if ( c <= 0x7ff ) return 2 ; if ( c <= 0xd7ff ) return 3 ; return 0 ; }
Get the number of bytes necessary to represent the passed character .
16,519
public static BitSet createBitSet ( final byte nValue ) { final BitSet ret = new BitSet ( CGlobal . BITS_PER_BYTE ) ; for ( int i = 0 ; i < CGlobal . BITS_PER_BYTE ; ++ i ) ret . set ( i , ( ( nValue >> i ) & 1 ) == 1 ) ; return ret ; }
Convert the passed byte value to an bit set of size 8 .
16,520
public static int getExtractedIntValue ( 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 ; }
Extract the int representation of the passed bit set . To avoid loss of data the bit set may not have more than 32 bits .
16,521
public static long getExtractedLongValue ( 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 ; }
Extract the long representation of the passed bit set . To avoid loss of data the bit set may not have more than 64 bits .
16,522
public static Document newDocument ( final DocumentBuilder aDocBuilder , final EXMLVersion eVersion ) { ValueEnforcer . notNull ( aDocBuilder , "DocBuilder" ) ; final Document aDoc = aDocBuilder . newDocument ( ) ; aDoc . setXmlVersion ( ( eVersion != null ? eVersion : EXMLVersion . XML_10 ) . getVersion ( ) ) ; return aDoc ; }
Create a new XML document without document type using a custom document builder .
16,523
public static Document newDocument ( final EXMLVersion eVersion , final String sQualifiedName , final String sPublicId , final String sSystemId ) { return newDocument ( getDocumentBuilder ( ) , eVersion , sQualifiedName , sPublicId , sSystemId ) ; }
Create a new document with a document type using the default document builder .
16,524
public static Document newDocument ( final DocumentBuilder aDocBuilder , final EXMLVersion eVersion , final String sQualifiedName , final String sPublicId , final String sSystemId ) { ValueEnforcer . notNull ( aDocBuilder , "DocBuilder" ) ; final DOMImplementation aDomImpl = aDocBuilder . getDOMImplementation ( ) ; final DocumentType aDocType = aDomImpl . createDocumentType ( sQualifiedName , sPublicId , sSystemId ) ; final Document aDoc = aDomImpl . createDocument ( sSystemId , sQualifiedName , aDocType ) ; aDoc . setXmlVersion ( ( eVersion != null ? eVersion : EXMLVersion . XML_10 ) . getVersion ( ) ) ; return aDoc ; }
Create a new document with a document type using a custom document builder .
16,525
public DATATYPE getIfSuccess ( final DATATYPE aFailureValue ) { return m_eSuccess . isSuccess ( ) ? m_aObj : aFailureValue ; }
Get the store value if this is a success . Otherwise the passed failure value is returned .
16,526
public DATATYPE getIfFailure ( final DATATYPE aSuccessValue ) { return m_eSuccess . isFailure ( ) ? m_aObj : aSuccessValue ; }
Get the store value if this is a failure . Otherwise the passed success value is returned .
16,527
public static < DATATYPE > SuccessWithValue < DATATYPE > create ( final ISuccessIndicator aSuccessIndicator , final DATATYPE aValue ) { return new SuccessWithValue < > ( aSuccessIndicator , aValue ) ; }
Create a new object with the given value .
16,528
public static < DATATYPE > SuccessWithValue < DATATYPE > createSuccess ( final DATATYPE aValue ) { return new SuccessWithValue < > ( ESuccess . SUCCESS , aValue ) ; }
Create a new success object with the given value .
16,529
public static < DATATYPE > SuccessWithValue < DATATYPE > createFailure ( final DATATYPE aValue ) { return new SuccessWithValue < > ( ESuccess . FAILURE , aValue ) ; }
Create a new failure object with the given value .
16,530
public static AuthIdentificationResult validateLoginCredentialsAndCreateToken ( final IAuthCredentials aCredentials ) { ValueEnforcer . notNull ( aCredentials , "Credentials" ) ; final ICredentialValidationResult aValidationResult = AuthCredentialValidatorManager . validateCredentials ( aCredentials ) ; if ( aValidationResult . isFailure ( ) ) { if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Credentials have been rejected: " + aCredentials ) ; return AuthIdentificationResult . createFailure ( aValidationResult ) ; } if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Credentials have been accepted: " + aCredentials ) ; final IAuthSubject aSubject = AuthCredentialToSubjectResolverManager . getSubjectFromCredentials ( aCredentials ) ; if ( aSubject != null ) { if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Credentials " + aCredentials + " correspond to subject " + aSubject ) ; } else { if ( LOGGER . isErrorEnabled ( ) ) LOGGER . error ( "Failed to resolve credentials " + aCredentials + " to an auth subject!" ) ; } final AuthIdentification aIdentification = new AuthIdentification ( aSubject ) ; final IAuthToken aNewAuthToken = AuthTokenRegistry . createToken ( aIdentification , IAuthToken . EXPIRATION_SECONDS_INFINITE ) ; return AuthIdentificationResult . createSuccess ( aNewAuthToken ) ; }
Validate the login credentials try to resolve the subject and create a token upon success .
16,531
public MimeTypeInfoManager read ( final IReadableResource aRes ) { ValueEnforcer . notNull ( aRes , "Resource" ) ; final IMicroDocument aDoc = MicroReader . readMicroXML ( aRes ) ; if ( aDoc == null ) throw new IllegalArgumentException ( "Failed to read MimeTypeInfo resource " + aRes ) ; aDoc . getDocumentElement ( ) . forAllChildElements ( eItem -> { final MimeTypeInfo aInfo = MicroTypeConverter . convertToNative ( eItem , MimeTypeInfo . class ) ; registerMimeType ( aInfo ) ; } ) ; return this ; }
Read the information from the specified resource .
16,532
public EChange clearCache ( ) { return m_aRWLock . writeLocked ( ( ) -> { EChange ret = m_aList . removeAll ( ) ; if ( ! m_aMapExt . isEmpty ( ) ) { m_aMapExt . clear ( ) ; ret = EChange . CHANGED ; } if ( ! m_aMapMimeType . isEmpty ( ) ) { m_aMapMimeType . clear ( ) ; ret = EChange . CHANGED ; } return ret ; } ) ; }
Remove all registered mime types
16,533
public ICommonsList < MimeTypeInfo > getAllInfosOfExtension ( final String sExtension ) { if ( sExtension == null ) return null ; return m_aRWLock . readLocked ( ( ) -> { ICommonsList < MimeTypeInfo > ret = m_aMapExt . get ( sExtension ) ; if ( ret == null ) { ret = m_aMapExt . get ( sExtension . toLowerCase ( Locale . US ) ) ; } return ret == null ? null : ret . getClone ( ) ; } ) ; }
Get all infos associated with the specified filename extension .
16,534
public ICommonsList < MimeTypeInfo > getAllInfosOfMimeType ( final IMimeType aMimeType ) { if ( aMimeType == null ) return null ; final ICommonsList < MimeTypeInfo > ret = m_aRWLock . readLocked ( ( ) -> m_aMapMimeType . get ( aMimeType ) ) ; return ret == null ? null : ret . getClone ( ) ; }
Get all infos associated with the passed mime type .
16,535
public boolean containsMimeTypeForFilename ( final String sFilename ) { ValueEnforcer . notEmpty ( sFilename , "Filename" ) ; final String sExtension = FilenameHelper . getExtension ( sFilename ) ; return containsMimeTypeForExtension ( sExtension ) ; }
Check if any mime type is registered for the extension of the specified filename .
16,536
public boolean containsMimeTypeForExtension ( final String sExtension ) { ValueEnforcer . notNull ( sExtension , "Extension" ) ; final ICommonsList < MimeTypeInfo > aInfos = getAllInfosOfExtension ( sExtension ) ; return CollectionHelper . isNotEmpty ( aInfos ) ; }
Check if any mime type is associated with the passed extension
16,537
public final XMLWriterSettings setSerializeVersion ( final EXMLSerializeVersion eSerializeVersion ) { m_eSerializeVersion = ValueEnforcer . notNull ( eSerializeVersion , "Version" ) ; m_eXMLVersion = eSerializeVersion . getXMLVersionOrDefault ( EXMLVersion . XML_10 ) ; return this ; }
Set the preferred XML version to use .
16,538
public final XMLWriterSettings setSerializeXMLDeclaration ( final EXMLSerializeXMLDeclaration eSerializeXMLDecl ) { m_eSerializeXMLDecl = ValueEnforcer . notNull ( eSerializeXMLDecl , "SerializeXMLDecl" ) ; return this ; }
Set the way how to handle the XML declaration .
16,539
public final XMLWriterSettings setSerializeDocType ( final EXMLSerializeDocType eSerializeDocType ) { m_eSerializeDocType = ValueEnforcer . notNull ( eSerializeDocType , "SerializeDocType" ) ; return this ; }
Set the way how to handle the doc type .
16,540
public final XMLWriterSettings setSerializeComments ( final EXMLSerializeComments eSerializeComments ) { m_eSerializeComments = ValueEnforcer . notNull ( eSerializeComments , "SerializeComments" ) ; return this ; }
Set the way how comments should be handled .
16,541
public final XMLWriterSettings setIncorrectCharacterHandling ( final EXMLIncorrectCharacterHandling eIncorrectCharacterHandling ) { m_eIncorrectCharacterHandling = ValueEnforcer . notNull ( eIncorrectCharacterHandling , "IncorrectCharacterHandling" ) ; return this ; }
Set the way how to handle invalid characters .
16,542
public final XMLWriterSettings setCharset ( final Charset aCharset ) { m_aCharset = ValueEnforcer . notNull ( aCharset , "Charset" ) ; return this ; }
Set the serialization charset .
16,543
public final XMLWriterSettings setNamespaceContext ( final INamespaceContext aNamespaceContext ) { m_aNamespaceContext = aNamespaceContext != null ? aNamespaceContext : new MapBasedNamespaceContext ( ) ; return this ; }
Set the namespace context to be used .
16,544
private static String _getUnifiedDecimal ( final String sStr ) { return StringHelper . replaceAll ( sStr , ',' , '.' ) ; }
Get the unified decimal string for parsing by the runtime library . This is done by replacing with . .
16,545
public static boolean isDouble ( final String sStr ) { return ! Double . isNaN ( parseDouble ( sStr , Double . NaN ) ) ; }
Checks if the given string is a double string that can be converted to a double value .
16,546
public static boolean isFloat ( final String sStr ) { return ! Float . isNaN ( parseFloat ( sStr , Float . NaN ) ) ; }
Checks if the given string is a float string that can be converted to a double value .
16,547
public static < T > boolean identityEqual ( final T aObj1 , final T aObj2 ) { return aObj1 == aObj2 ; }
The only place where objects are compared by identity .
16,548
public ICommonsList < String > next ( ) { final ICommonsList < String > ret = m_aNextLine ; if ( ret == null ) throw new NoSuchElementException ( ) ; try { m_aNextLine = m_aReader . readNext ( ) ; } catch ( final IOException ex ) { throw new IllegalStateException ( "Failed to read next CSV line" , ex ) ; } return ret ; }
Returns the next element in the iterator .
16,549
public static < DATATYPE , ITEMTYPE extends ITreeItemWithID < String , DATATYPE , ITEMTYPE > > IMicroElement getTreeWithStringIDAsXML ( final IBasicTree < DATATYPE , ITEMTYPE > aTree , final IConverterTreeItemToMicroNode < ? super DATATYPE > aConverter ) { return getTreeWithIDAsXML ( aTree , IHasID . getComparatorID ( ) , x -> x , aConverter ) ; }
Specialized conversion method for converting a tree with ID to a standardized XML tree .
16,550
public void forEachResourceError ( final Consumer < ? super IError > aConsumer ) { ValueEnforcer . notNull ( aConsumer , "Consumer" ) ; m_aRWLock . readLocked ( ( ) -> m_aErrors . forEach ( aConsumer ) ) ; }
Call the provided consumer for all contained resource errors .
16,551
@ MustBeLocked ( ELockType . WRITE ) private void _addItem ( final IMPLTYPE aItem , final EDAOActionType eActionType ) { ValueEnforcer . notNull ( aItem , "Item" ) ; ValueEnforcer . isTrue ( eActionType == EDAOActionType . CREATE || eActionType == EDAOActionType . UPDATE , "Invalid action type provided!" ) ; final String sID = aItem . getID ( ) ; final IMPLTYPE aOldItem = m_aMap . get ( sID ) ; if ( eActionType == EDAOActionType . CREATE ) { if ( aOldItem != null ) throw new IllegalArgumentException ( ClassHelper . getClassLocalName ( getDataTypeClass ( ) ) + " with ID '" + sID + "' is already in use and can therefore not be created again. Old item = " + aOldItem + "; New item = " + aItem ) ; } else { if ( aOldItem == null ) throw new IllegalArgumentException ( ClassHelper . getClassLocalName ( getDataTypeClass ( ) ) + " with ID '" + sID + "' is not yet in use and can therefore not be updated! Updated item = " + aItem ) ; } m_aMap . put ( sID , aItem ) ; }
Add or update an item . Must only be invoked inside a write - lock .
16,552
@ IsLocked ( ELockType . READ ) protected final IMPLTYPE getOfID ( final String sID ) { if ( StringHelper . hasNoText ( sID ) ) return null ; return m_aRWLock . readLocked ( ( ) -> m_aMap . get ( sID ) ) ; }
Find the element with the provided ID . Locking is done internally .
16,553
@ IsLocked ( ELockType . READ ) protected final INTERFACETYPE getAtIndex ( final int nIndex ) { return m_aRWLock . readLocked ( ( ) -> CollectionHelper . getAtIndex ( m_aMap . values ( ) , nIndex ) ) ; }
Get the item at the specified index . This method only returns defined results if an ordered map is used for data storage .
16,554
public static int getWeekDays ( final LocalDate aStartDate , final LocalDate aEndDate ) { ValueEnforcer . notNull ( aStartDate , "StartDate" ) ; ValueEnforcer . notNull ( aEndDate , "EndDate" ) ; final boolean bFlip = aStartDate . isAfter ( aEndDate ) ; LocalDate aCurDate = bFlip ? aEndDate : aStartDate ; final LocalDate aRealEndDate = bFlip ? aStartDate : aEndDate ; int ret = 0 ; while ( ! aRealEndDate . isBefore ( aCurDate ) ) { if ( ! isWeekend ( aCurDate ) ) ret ++ ; aCurDate = aCurDate . plusDays ( 1 ) ; } return bFlip ? - 1 * ret : ret ; }
Count all non - weekend days in the range . Does not consider holidays!
16,555
public static int getEndWeekOfMonth ( final LocalDateTime aDT , final Locale aLocale ) { return getWeekOfWeekBasedYear ( aDT . plusMonths ( 1 ) . withDayOfMonth ( 1 ) . minusDays ( 1 ) , aLocale ) ; }
Get the end - week number for the passed year and month .
16,556
public static boolean birthdayEquals ( final LocalDate aDate1 , final LocalDate aDate2 ) { return birthdayCompare ( aDate1 , aDate2 ) == 0 ; }
Check if the two birthdays are equal . Equal birthdays are identified by equal months and equal days .
16,557
public static boolean isInstancableClass ( final Class < ? > aClass ) { if ( ! isPublicClass ( aClass ) ) return false ; try { aClass . getConstructor ( ( Class < ? > [ ] ) null ) ; } catch ( final NoSuchMethodException ex ) { return false ; } return true ; }
Check if the passed class is public instancable and has a no - argument constructor .
16,558
public static boolean isInterface ( final Class < ? > aClass ) { return aClass != null && Modifier . isInterface ( aClass . getModifiers ( ) ) ; }
Check if the passed class is an interface or not . Please note that annotations are also interfaces!
16,559
public static Class < ? > getPrimitiveWrapperClass ( final Class < ? > aClass ) { if ( isPrimitiveWrapperType ( aClass ) ) return aClass ; return PRIMITIVE_TO_WRAPPER . get ( aClass ) ; }
Get the primitive wrapper class of the passed primitive class .
16,560
public static Class < ? > getPrimitiveClass ( final Class < ? > aClass ) { if ( isPrimitiveType ( aClass ) ) return aClass ; return WRAPPER_TO_PRIMITIVE . get ( aClass ) ; }
Get the primitive class of the passed primitive wrapper class .
16,561
public static boolean areConvertibleClasses ( final Class < ? > aSrcClass , final Class < ? > aDstClass ) { ValueEnforcer . notNull ( aSrcClass , "SrcClass" ) ; ValueEnforcer . notNull ( aDstClass , "DstClass" ) ; if ( aDstClass . equals ( aSrcClass ) ) return true ; if ( aDstClass . isAssignableFrom ( aSrcClass ) ) return true ; if ( aDstClass == getPrimitiveWrapperClass ( aSrcClass ) ) return true ; if ( aDstClass == getPrimitiveClass ( aSrcClass ) ) return true ; return false ; }
Check if the passed classes are convertible . Includes conversion checks between primitive types and primitive wrapper types .
16,562
public static String getClassLocalName ( final Object aObject ) { return aObject == null ? null : getClassLocalName ( aObject . getClass ( ) ) ; }
Get the name of the object s class without the package .
16,563
public static String getClassPackageName ( final Object aObject ) { return aObject == null ? null : getClassPackageName ( aObject . getClass ( ) ) ; }
Get the name of the package the passed object resides in .
16,564
public static String getDirectoryFromPackage ( final Package aPackage ) { return aPackage == null ? null : getPathFromClass ( aPackage . getName ( ) ) ; }
Convert a package name to a relative directory name .
16,565
public static String getObjectAddress ( final Object aObject ) { if ( aObject == null ) return "0x00000000" ; return "0x" + StringHelper . getHexStringLeadingZero ( System . identityHashCode ( aObject ) , 8 ) ; }
Get the hex representation of the passed object s address . Note that this method makes no differentiation between 32 and 64 bit architectures . The result is always a hexadecimal value preceded by 0x and followed by exactly 8 characters .
16,566
public static void visitStatistics ( final IStatisticsVisitorCallback aCallback ) { ValueEnforcer . notNull ( aCallback , "Callback" ) ; ICommonsList < String > aHandlers = StatisticsManager . getAllCacheHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerCache aHandler = StatisticsManager . getCacheHandler ( sName ) ; aCallback . onCache ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllTimerHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerTimer aHandler = StatisticsManager . getTimerHandler ( sName ) ; aCallback . onTimer ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllKeyedTimerHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedTimer aHandler = StatisticsManager . getKeyedTimerHandler ( sName ) ; aCallback . onKeyedTimer ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllSizeHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerSize aHandler = StatisticsManager . getSizeHandler ( sName ) ; aCallback . onSize ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllKeyedSizeHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedSize aHandler = StatisticsManager . getKeyedSizeHandler ( sName ) ; aCallback . onKeyedSize ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllCounterHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerCounter aHandler = StatisticsManager . getCounterHandler ( sName ) ; aCallback . onCounter ( sName , aHandler ) ; } aHandlers = StatisticsManager . getAllKeyedCounterHandler ( ) . getSorted ( Comparator . naturalOrder ( ) ) ; for ( final String sName : aHandlers ) { final IStatisticsHandlerKeyedCounter aHandler = StatisticsManager . getKeyedCounterHandler ( sName ) ; aCallback . onKeyedCounter ( sName , aHandler ) ; } }
Walk all available statistics elements with the passed statistics visitor .
16,567
public final void reset ( ) { for ( int i = 0 ; i < m_aIndexResult . length ; i ++ ) m_aIndexResult [ i ] = i ; m_aCombinationsLeft = m_aTotalCombinations ; m_nCombinationsLeft = m_nTotalCombinations ; }
Reset the generator
16,568
public static < DATATYPE > ICommonsList < ICommonsList < DATATYPE > > getAllPermutations ( final ICommonsList < DATATYPE > aInput , final int nSlotCount ) { final ICommonsList < ICommonsList < DATATYPE > > aResultList = new CommonsArrayList < > ( ) ; addAllPermutations ( aInput , nSlotCount , aResultList ) ; return aResultList ; }
Get a list of all permutations of the input elements .
16,569
public static < DATATYPE > void addAllPermutations ( final ICommonsList < DATATYPE > aInput , final int nSlotCount , final Collection < ICommonsList < DATATYPE > > aResultList ) { for ( final ICommonsList < DATATYPE > aPermutation : new CombinationGenerator < > ( aInput , nSlotCount ) ) aResultList . add ( aPermutation ) ; }
Fill a list with all permutations of the input elements .
16,570
protected void onInsertBefore ( final AbstractMicroNode aChildNode , final IMicroNode aSuccessor ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; }
Callback that is invoked once a child is to be inserted before another child .
16,571
protected void onInsertAfter ( final AbstractMicroNode aChildNode , final IMicroNode aPredecessor ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; }
Callback that is invoked once a child is to be inserted after another child .
16,572
protected void onInsertAtIndex ( final int nIndex , final AbstractMicroNode aChildNode ) { throw new MicroException ( "Cannot insert children in class " + getClass ( ) . getName ( ) ) ; }
Callback that is invoked once a child is to be inserted at the specified index .
16,573
public static ByteArrayWrapper create ( final String sText , final Charset aCharset ) { return new ByteArrayWrapper ( sText . getBytes ( aCharset ) , false ) ; }
Wrap the content of a String in a certain charset .
16,574
public static byte [ ] getAllFileBytes ( final File aFile ) { return aFile == null ? null : StreamHelper . getAllBytes ( FileHelper . getInputStream ( aFile ) ) ; }
Get the content of the file as a byte array .
16,575
public static String stripBidi ( final String sStr ) { if ( sStr == null || sStr . length ( ) <= 1 ) return sStr ; String ret = sStr ; if ( isBidi ( ret . charAt ( 0 ) ) ) ret = ret . substring ( 1 ) ; if ( isBidi ( ret . charAt ( ret . length ( ) - 1 ) ) ) ret = ret . substring ( 0 , ret . length ( ) - 1 ) ; return ret ; }
Removes leading and trailing bidi controls from the string
16,576
public static String wrapBidi ( final String sStr , final char cChar ) { switch ( cChar ) { case RLE : return _wrap ( sStr , RLE , PDF ) ; case RLO : return _wrap ( sStr , RLO , PDF ) ; case LRE : return _wrap ( sStr , LRE , PDF ) ; case LRO : return _wrap ( sStr , LRO , PDF ) ; case RLM : return _wrap ( sStr , RLM , RLM ) ; case LRM : return _wrap ( sStr , LRM , LRM ) ; default : return sStr ; } }
Wrap the string with the specified bidi control
16,577
public < T extends OmiseObject > T deserialize ( InputStream input , Class < T > klass ) throws IOException { return objectMapper . readerFor ( klass ) . readValue ( input ) ; }
Deserialize an instance of the given class from the input stream .
16,578
public < T extends OmiseObject > T deserialize ( InputStream input , TypeReference < T > ref ) throws IOException { return objectMapper . readerFor ( ref ) . readValue ( input ) ; }
Deserialize an instance of the given type reference from the input stream .
16,579
public < T extends OmiseObject > T deserializeFromMap ( Map < String , Object > map , Class < T > klass ) { return objectMapper . convertValue ( map , klass ) ; }
Deserialize an instance of the given class from the map .
16,580
public < T extends OmiseObject > T deserializeFromMap ( Map < String , Object > map , TypeReference < T > ref ) { return objectMapper . convertValue ( map , ref ) ; }
Deserialize an instance of the given type reference from the map .
16,581
public < T extends OmiseObject > void serialize ( OutputStream output , T model ) throws IOException { objectMapper . writerFor ( model . getClass ( ) ) . writeValue ( output , model ) ; }
Serializes the given model to the output stream .
16,582
public < T extends Params > void serializeParams ( OutputStream output , T param ) throws IOException { objectMapper . writerFor ( param . getClass ( ) ) . writeValue ( output , param ) ; }
Serializes the given parameter object to the output stream .
16,583
public < T extends OmiseObject > Map < String , Object > serializeToMap ( T model ) { return objectMapper . convertValue ( model , new TypeReference < Map < String , Object > > ( ) { } ) ; }
Serialize the given model to a map with JSON - like structure .
16,584
public < T extends Enum < T > > String serializeToQueryParams ( T value ) { return ( String ) objectMapper . convertValue ( value , String . class ) ; }
Serialize the given model to a representation suitable for using as URL query parameters .
16,585
public static Function < HttpRequest , String > PREFIXED_REQUEST_METHOD_NAME ( final String prefix ) { return ( request ) -> replaceIfNull ( prefix , "" ) + replaceIfNull ( request . getRequestLine ( ) . getMethod ( ) , "unknown" ) ; }
A configurable version of REQUEST_METHOD_NAME
16,586
public static Function < HttpRequest , String > PREFIXED_REQUEST_TARGET_NAME ( final String prefix ) { return ( request ) -> replaceIfNull ( prefix , "" ) + replaceIfNull ( standardizeUri ( request . getRequestLine ( ) . getUri ( ) ) , "unknown" ) ; }
A configurable version of REQUEST_TARGET_NAME
16,587
public static Function < HttpRequest , String > PREFIXED_REQUEST_METHOD_TARGET_NAME ( final String prefix ) { return ( request ) -> replaceIfNull ( prefix , "" ) + replaceIfNull ( request . getRequestLine ( ) . getMethod ( ) , "unknown" ) + " " + replaceIfNull ( standardizeUri ( request . getRequestLine ( ) . getUri ( ) ) , "unknown" ) ; }
A configurable version of REQUEST_METHOD_TARGET_NAME
16,588
private static String standardizeUri ( String uri ) { return ( uri == null ) ? null : regexIDPattern . matcher ( regexTaskIDPattern . matcher ( regexParameterPattern . matcher ( uri ) . replaceFirst ( "" ) ) . replaceAll ( "task_id:\\?" ) ) . replaceAll ( "/\\?$1" ) ; }
Using regexes derived from the Elasticsearch 5 . 6 HTTP API this method removes additional parameters in the request and replaces numerical IDs with ? to reduce granularity .
16,589
private SpanContext extract ( HttpRequest request ) { SpanContext spanContext = tracer . extract ( Format . Builtin . HTTP_HEADERS , new HttpTextMapExtractAdapter ( request ) ) ; if ( spanContext != null ) { return spanContext ; } Span span = tracer . activeSpan ( ) ; if ( span != null ) { return span . context ( ) ; } return null ; }
Extract context from headers or from active Span
16,590
public String build ( Class < ? > clazz ) { String packageName = clazz . getPackage ( ) . getName ( ) ; String formattedPackageName = packageName . replace ( "." , "/" ) ; return formattedPackageName + "/" + clazz . getSimpleName ( ) + "-BeanohContext.xml" ; }
Builds a bootstrap name with the same name as the test plus - BeanohContext . xml .
16,591
public Object intercept ( Object object , Method method , Object [ ] args , MethodProxy methodProxy ) throws Throwable { Method delegateMethod = delegateClass . getMethod ( method . getName ( ) , method . getParameterTypes ( ) ) ; if ( "registerBeanDefinition" . equals ( method . getName ( ) ) ) { if ( beanDefinitionMap . containsKey ( args [ 0 ] ) ) { List < BeanDefinition > definitions = beanDefinitionMap . get ( args [ 0 ] ) ; definitions . add ( ( BeanDefinition ) args [ 1 ] ) ; } else { List < BeanDefinition > beanDefinitions = new ArrayList < BeanDefinition > ( ) ; beanDefinitions . add ( ( BeanDefinition ) args [ 1 ] ) ; beanDefinitionMap . put ( ( String ) args [ 0 ] , beanDefinitions ) ; } } return delegateMethod . invoke ( delegate , args ) ; }
Intercepts method calls to the proxy and calls the corresponding method on the delegate .
16,592
public void assertUniqueBeans ( Set < String > ignoredDuplicateBeanNames ) { for ( BeanohBeanFactoryMethodInterceptor callback : callbacks ) { Map < String , List < BeanDefinition > > beanDefinitionMap = callback . getBeanDefinitionMap ( ) ; for ( String key : beanDefinitionMap . keySet ( ) ) { if ( ! ignoredDuplicateBeanNames . contains ( key ) ) { List < BeanDefinition > definitions = beanDefinitionMap . get ( key ) ; List < String > resourceDescriptions = new ArrayList < String > ( ) ; for ( BeanDefinition definition : definitions ) { String resourceDescription = definition . getResourceDescription ( ) ; if ( resourceDescription == null ) { resourceDescriptions . add ( definition . getBeanClassName ( ) ) ; } else if ( ! resourceDescription . endsWith ( "-BeanohContext.xml]" ) ) { if ( ! resourceDescriptions . contains ( resourceDescription ) ) { resourceDescriptions . add ( resourceDescription ) ; } } } if ( resourceDescriptions . size ( ) > 1 ) { throw new DuplicateBeanDefinitionException ( "Bean '" + key + "' was defined " + resourceDescriptions . size ( ) + " times.\n" + "Either remove duplicate bean definitions or ignore them with the 'ignoredDuplicateBeanNames' method.\n" + "Configuration locations:" + messageUtil . list ( resourceDescriptions ) ) ; } } } } }
This will fail if there are duplicate beans in the Spring context . Beans that are configured in the bootstrap context will not be considered duplicate beans .
16,593
public String list ( List < String > messages ) { List < String > sortedComponents = new ArrayList < String > ( messages ) ; Collections . sort ( sortedComponents ) ; String output = "" ; for ( String component : sortedComponents ) { output += "\n" + component ; } return output ; }
Separates messages on different lines for error messages .
16,594
public synchronized void stopThrow ( ) throws JMException { if ( connector != null ) { try { connector . stop ( ) ; } catch ( IOException e ) { throw createJmException ( "Could not stop our Jmx connector server" , e ) ; } finally { connector = null ; } } if ( rmiRegistry != null ) { try { UnicastRemoteObject . unexportObject ( rmiRegistry , true ) ; } catch ( NoSuchObjectException e ) { throw createJmException ( "Could not unexport our RMI registry" , e ) ; } finally { rmiRegistry = null ; } } if ( serverHostNamePropertySet ) { System . clearProperty ( RMI_SERVER_HOST_NAME_PROPERTY ) ; serverHostNamePropertySet = false ; } }
Stop the JMX server by closing the connector and unpublishing it from the RMI registry . This throws a JMException on any issues .
16,595
public synchronized ObjectName register ( PublishAllBeanWrapper wrapper ) throws JMException { ReflectionMbean mbean ; try { mbean = new ReflectionMbean ( wrapper ) ; } catch ( Exception e ) { throw createJmException ( "Could not build mbean object for publish-all bean: " + wrapper . getTarget ( ) , e ) ; } ObjectName objectName = ObjectNameUtil . makeObjectName ( wrapper . getJmxResourceInfo ( ) ) ; doRegister ( objectName , mbean ) ; return objectName ; }
Register the object parameter for exposure with JMX that is wrapped using the PublishAllBeanWrapper .
16,596
public static Object stringToParam ( String string , String typeString ) throws IllegalArgumentException { if ( typeString . equals ( "boolean" ) || typeString . equals ( "java.lang.Boolean" ) ) { return Boolean . parseBoolean ( string ) ; } else if ( typeString . equals ( "char" ) || typeString . equals ( "java.lang.Character" ) ) { if ( string . length ( ) == 0 ) { return '\0' ; } else { return string . toCharArray ( ) [ 0 ] ; } } else if ( typeString . equals ( "byte" ) || typeString . equals ( "java.lang.Byte" ) ) { return Byte . parseByte ( string ) ; } else if ( typeString . equals ( "short" ) || typeString . equals ( "java.lang.Short" ) ) { return Short . parseShort ( string ) ; } else if ( typeString . equals ( "int" ) || typeString . equals ( "java.lang.Integer" ) ) { return Integer . parseInt ( string ) ; } else if ( typeString . equals ( "long" ) || typeString . equals ( "java.lang.Long" ) ) { return Long . parseLong ( string ) ; } else if ( typeString . equals ( "java.lang.String" ) ) { return string ; } else if ( typeString . equals ( "float" ) || typeString . equals ( "java.lang.Float" ) ) { return Float . parseFloat ( string ) ; } else if ( typeString . equals ( "double" ) || typeString . equals ( "java.lang.Double" ) ) { return Double . parseDouble ( string ) ; } else { Constructor < ? > constr = getConstructor ( typeString ) ; try { return constr . newInstance ( new Object [ ] { string } ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Could not get new instance using string constructor for type " + typeString ) ; } } }
Convert a string to an object based on the type string .
16,597
public static String valueToString ( Object value ) { if ( value == null ) { return "null" ; } else if ( ! value . getClass ( ) . isArray ( ) ) { return value . toString ( ) ; } StringBuilder sb = new StringBuilder ( ) ; valueToString ( sb , value ) ; return sb . toString ( ) ; }
Return the string version of value .
16,598
public static String displayType ( String className , Object value ) { if ( className == null ) { return null ; } boolean array = false ; if ( className . equals ( "[J" ) ) { array = true ; if ( value == null ) { className = "unknown" ; } else if ( value instanceof boolean [ ] ) { className = "boolean" ; } else if ( value instanceof byte [ ] ) { className = "byte" ; } else if ( value instanceof char [ ] ) { className = "char" ; } else if ( value instanceof short [ ] ) { className = "short" ; } else if ( value instanceof int [ ] ) { className = "int" ; } else if ( value instanceof long [ ] ) { className = "long" ; } else if ( value instanceof float [ ] ) { className = "float" ; } else if ( value instanceof double [ ] ) { className = "double" ; } else { className = "unknown" ; } } else if ( className . startsWith ( "[L" ) ) { className = className . substring ( 2 , className . length ( ) - 1 ) ; } if ( className . startsWith ( "java.lang." ) ) { className = className . substring ( 10 ) ; } else if ( className . startsWith ( "javax.management.openmbean." ) ) { className = className . substring ( 27 ) ; } if ( array ) { return "array of " + className ; } else { return className ; } }
Display type string from class name string .
16,599
public void runCommands ( final String [ ] commands ) throws IOException { doLines ( 0 , new LineReader ( ) { private int commandC = 0 ; public String getNextLine ( String prompt ) { if ( commandC >= commands . length ) { return null ; } else { return commands [ commandC ++ ] ; } } } , true ) ; }
Run commands from the String array .