idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
16,200 | @ Nonnull public EChange add ( @ Nonnull final CALLBACKTYPE aCallback ) { ValueEnforcer . notNull ( aCallback , "Callback" ) ; return m_aRWLock . writeLocked ( ( ) -> m_aCallbacks . addObject ( aCallback ) ) ; } | Add a callback . | 63 | 4 |
16,201 | @ Nonnull public EChange removeObject ( @ Nullable final CALLBACKTYPE aCallback ) { if ( aCallback == null ) return EChange . UNCHANGED ; return m_aRWLock . writeLocked ( ( ) -> m_aCallbacks . removeObject ( aCallback ) ) ; } | Remove the specified callback | 65 | 4 |
16,202 | public static void debugLogDOMFeatures ( ) { for ( final Map . Entry < EXMLDOMFeatureVersion , ICommonsList < String > > aEntry : s_aSupportedFeatures . entrySet ( ) ) for ( final String sFeature : aEntry . getValue ( ) ) if ( LOGGER . isInfoEnabled ( ) ) LOGGER . info ( "DOM " + aEntry . getKey ( ) . getID ( ) + " feature '" + sFeature + "' is present" ) ; } | Emit all supported features to the logger . | 108 | 9 |
16,203 | @ Nullable public static Document getOwnerDocument ( @ Nullable final Node aNode ) { if ( aNode == null ) return null ; if ( aNode instanceof Document ) return ( Document ) aNode ; return aNode . getOwnerDocument ( ) ; } | Get the owner document of the passed node . If the node itself is a document only a cast is performed . | 55 | 22 |
16,204 | @ Nullable public static Element getFirstChildElement ( @ Nullable final Node aStartNode ) { if ( aStartNode == null ) return null ; return NodeListIterator . createChildNodeIterator ( aStartNode ) . findFirstMapped ( filterNodeIsElement ( ) , x -> ( Element ) x ) ; } | Get the first direct child element of the passed element . | 68 | 11 |
16,205 | public static boolean hasChildElementNodes ( @ Nullable final Node aStartNode ) { if ( aStartNode == null ) return false ; return NodeListIterator . createChildNodeIterator ( aStartNode ) . containsAny ( filterNodeIsElement ( ) ) ; } | Check if the passed node has at least one direct child element or not . | 57 | 15 |
16,206 | @ Nonnull public EChange removeParameterWithName ( @ Nullable final String sParamName ) { if ( StringHelper . hasText ( sParamName ) ) { final int nMax = m_aParameters . size ( ) ; for ( int i = 0 ; i < nMax ; ++ i ) { final MimeTypeParameter aParam = m_aParameters . get ( i ) ; if ( aParam . getAttribute ( ) . equals ( sParamName ) ) { m_aParameters . remove ( i ) ; return EChange . CHANGED ; } } } return EChange . UNCHANGED ; } | Remove the parameter with the specified name . | 132 | 8 |
16,207 | @ Nonnull public static Matcher getMatcher ( @ Nonnull @ RegEx final String sRegEx , @ Nonnull final String sValue ) { ValueEnforcer . notNull ( sValue , "Value" ) ; return RegExCache . getPattern ( sRegEx ) . matcher ( sValue ) ; } | Get the Java Matcher object for the passed pair of regular expression and value . | 68 | 16 |
16,208 | public static boolean stringMatchesPattern ( @ Nonnull @ RegEx final String sRegEx , @ Nonnull final String sValue ) { return getMatcher ( sRegEx , sValue ) . matches ( ) ; } | A shortcut helper method to determine whether a string matches a certain regular expression or not . | 47 | 17 |
16,209 | public boolean containsCountry ( @ Nullable final String sCountry ) { if ( sCountry == null ) return false ; final String sValidCountry = LocaleHelper . getValidCountryCode ( sCountry ) ; if ( sValidCountry == null ) return false ; return m_aRWLock . readLocked ( ( ) -> m_aCountries . contains ( sValidCountry ) ) ; } | Check if the passed country is known . | 83 | 8 |
16,210 | public static int append ( final int nPrevHashCode , @ Nullable final Object x ) { return append ( nPrevHashCode , HashCodeImplementationRegistry . getHashCode ( x ) ) ; } | Object hash code generation . | 44 | 5 |
16,211 | @ Nonnull @ ReturnsMutableCopy public static HasInputStream multiple ( @ Nonnull final ISupplier < ? extends InputStream > aISP ) { return new HasInputStream ( aISP , true ) ; } | Create a new object with a supplier that can read multiple times . | 47 | 13 |
16,212 | @ Nonnull @ ReturnsMutableCopy public static HasInputStream once ( @ Nonnull final ISupplier < ? extends InputStream > aISP ) { return new HasInputStream ( aISP , false ) ; } | Create a new object with a supplier that can be read only once . | 47 | 14 |
16,213 | private static int _getDistance111 ( @ Nonnull final char [ ] aStr1 , @ Nonnegative final int nLen1 , @ Nonnull final char [ ] aStr2 , @ Nonnegative final int nLen2 ) { // previous cost array, horizontally int [ ] aPrevRow = new int [ nLen1 + 1 ] ; // cost array, horizontally int [ ] aCurRow = new int [ nLen1 + 1 ] ; // init for ( int i = 0 ; i <= nLen1 ; i ++ ) aPrevRow [ i ] = i ; for ( int j = 0 ; j < nLen2 ; j ++ ) { final int ch2 = aStr2 [ j ] ; aCurRow [ 0 ] = j + 1 ; for ( int i = 0 ; i < nLen1 ; i ++ ) { final int nSubstVal = aStr1 [ i ] == ch2 ? 0 : 1 ; aCurRow [ i + 1 ] = Math . min ( Math . min ( aCurRow [ i ] + 1 , aPrevRow [ i + 1 ] + 1 ) , aPrevRow [ i ] + nSubstVal ) ; } // swap current distance counts to 'previous row' distance counts final int [ ] tmp = aPrevRow ; aPrevRow = aCurRow ; aCurRow = tmp ; } // our last action in the above loop was to switch d and p, so p now // actually has the most recent cost counts return aPrevRow [ nLen1 ] ; } | Main generic Levenshtein implementation that uses 1 for all costs! | 326 | 14 |
16,214 | private static int _getDistance ( @ Nonnull final char [ ] aStr1 , @ Nonnegative final int nLen1 , @ Nonnull final char [ ] aStr2 , @ Nonnegative final int nLen2 , @ Nonnegative final int nCostInsert , @ Nonnegative final int nCostDelete , @ Nonnegative final int nCostSubstitution ) { // previous cost array, horizontally int [ ] aPrevRow = new int [ nLen1 + 1 ] ; // cost array, horizontally int [ ] aCurRow = new int [ nLen1 + 1 ] ; // init for ( int i = 0 ; i <= nLen1 ; i ++ ) aPrevRow [ i ] = i * nCostInsert ; for ( int j = 0 ; j < nLen2 ; j ++ ) { final int ch2 = aStr2 [ j ] ; aCurRow [ 0 ] = ( j + 1 ) * nCostDelete ; for ( int i = 0 ; i < nLen1 ; i ++ ) { final int nSubstCost = aStr1 [ i ] == ch2 ? 0 : nCostSubstitution ; aCurRow [ i + 1 ] = Math . min ( Math . min ( aCurRow [ i ] + nCostInsert , aPrevRow [ i + 1 ] + nCostDelete ) , aPrevRow [ i ] + nSubstCost ) ; } // swap current distance counts to 'previous row' distance counts final int [ ] tmp = aPrevRow ; aPrevRow = aCurRow ; aCurRow = tmp ; } // our last action in the above loop was to switch d and p, so p now // actually has the most recent cost counts return aPrevRow [ nLen1 ] ; } | Main generic Levenshtein implementation . Assume all preconditions are checked . | 372 | 17 |
16,215 | @ Nullable public static String getUnifiedEmailAddress ( @ Nullable final String sEmailAddress ) { return sEmailAddress == null ? null : sEmailAddress . trim ( ) . toLowerCase ( Locale . US ) ; } | Get the unified version of an email address . It trims leading and trailing spaces and lower - cases the email address . | 50 | 24 |
16,216 | public static boolean isValid ( @ Nullable final String sEmailAddress ) { if ( sEmailAddress == null ) return false ; // Unify (lowercase) final String sUnifiedEmail = getUnifiedEmailAddress ( sEmailAddress ) ; // Pattern matching return s_aPattern . matcher ( sUnifiedEmail ) . matches ( ) ; } | Checks if a value is a valid e - mail address according to a certain regular expression . | 75 | 19 |
16,217 | @ Nonnull public static ESuccess writeMap ( @ Nonnull final Map < String , String > aMap , @ Nonnull @ WillClose final OutputStream aOS ) { ValueEnforcer . notNull ( aMap , "Map" ) ; ValueEnforcer . notNull ( aOS , "OutputStream" ) ; try { final IMicroDocument aDoc = createMapDocument ( aMap ) ; return MicroWriter . writeToStream ( aDoc , aOS , XMLWriterSettings . DEFAULT_XML_SETTINGS ) ; } finally { StreamHelper . close ( aOS ) ; } } | Write the passed map to the passed output stream using the predefined XML layout . | 127 | 16 |
16,218 | @ Nullable public static Transformer newTransformer ( @ Nonnull final TransformerFactory aTransformerFactory ) { ValueEnforcer . notNull ( aTransformerFactory , "TransformerFactory" ) ; try { return aTransformerFactory . newTransformer ( ) ; } catch ( final TransformerConfigurationException ex ) { LOGGER . error ( "Failed to create transformer" , ex ) ; return null ; } } | Create a new XSLT transformer for no specific resource . | 89 | 12 |
16,219 | @ Nonnull public String getRest ( ) { final String ret = m_sInput . substring ( m_nCurIndex ) ; m_nCurIndex = m_nMaxIndex ; return ret ; } | Get all remaining chars and set the index to the end of the input string | 45 | 15 |
16,220 | @ Nonnull public String getUntil ( final char cEndExcl ) { final int nStart = m_nCurIndex ; while ( m_nCurIndex < m_nMaxIndex && getCurrentChar ( ) != cEndExcl ) ++ m_nCurIndex ; return m_sInput . substring ( nStart , m_nCurIndex ) ; } | Get the string until the specified end character but excluding the end character . | 79 | 14 |
16,221 | @ Nullable public DATATYPE getIfChanged ( @ Nullable final DATATYPE aUnchangedValue ) { return m_eChange . isChanged ( ) ? m_aObj : aUnchangedValue ; } | Get the store value if this is a change . Otherwise the passed unchanged value is returned . | 50 | 18 |
16,222 | @ Nullable public DATATYPE getIfUnchanged ( @ Nullable final DATATYPE aChangedValue ) { return m_eChange . isUnchanged ( ) ? m_aObj : aChangedValue ; } | Get the store value if this is unchanged . Otherwise the passed changed value is returned . | 50 | 17 |
16,223 | @ Nonnull public static < DATATYPE > ChangeWithValue < DATATYPE > createChanged ( @ Nullable final DATATYPE aValue ) { return new ChangeWithValue <> ( EChange . CHANGED , aValue ) ; } | Create a new changed object with the given value . | 58 | 10 |
16,224 | @ Nonnull public static < DATATYPE > ChangeWithValue < DATATYPE > createUnchanged ( @ Nullable final DATATYPE aValue ) { return new ChangeWithValue <> ( EChange . UNCHANGED , aValue ) ; } | Create a new unchanged object with the given value . | 60 | 10 |
16,225 | @ Nonnull public static ICommonsList < IAuthToken > getAllTokensOfSubject ( @ Nonnull final IAuthSubject aSubject ) { ValueEnforcer . notNull ( aSubject , "Subject" ) ; return s_aRWLock . readLocked ( ( ) -> CommonsArrayList . createFiltered ( s_aMap . values ( ) , aToken -> aToken . getIdentification ( ) . hasAuthSubject ( aSubject ) ) ) ; } | Get all tokens of the specified auth subject . All tokens are returned no matter whether they are expired or not . | 100 | 22 |
16,226 | @ Nonnegative public static int removeAllTokensOfSubject ( @ Nonnull final IAuthSubject aSubject ) { ValueEnforcer . notNull ( aSubject , "Subject" ) ; // get all token IDs matching a given subject // Note: required IAuthSubject to implement equals! final ICommonsList < String > aDelTokenIDs = new CommonsArrayList <> ( ) ; s_aRWLock . readLocked ( ( ) -> { for ( final Map . Entry < String , AuthToken > aEntry : s_aMap . entrySet ( ) ) if ( aEntry . getValue ( ) . getIdentification ( ) . hasAuthSubject ( aSubject ) ) aDelTokenIDs . add ( aEntry . getKey ( ) ) ; } ) ; for ( final String sDelTokenID : aDelTokenIDs ) removeToken ( sDelTokenID ) ; return aDelTokenIDs . size ( ) ; } | Remove all tokens of the given subject | 196 | 7 |
16,227 | @ Nullable public static < ENUMTYPE extends Enum < ENUMTYPE > & IHasName > ENUMTYPE getFromNameCaseInsensitiveOrNull ( @ Nonnull final Class < ENUMTYPE > aClass , @ Nullable final String sName ) { return getFromNameCaseInsensitiveOrDefault ( aClass , sName , null ) ; } | Get the enum value with the passed name case insensitive | 76 | 10 |
16,228 | @ Nonnull public static String getEnumID ( @ Nonnull final Enum < ? > aEnum ) { // No explicit null check, because this method is used heavily in // locale resolving, so we want to spare some CPU cycles :) return aEnum . getClass ( ) . getName ( ) + ' ' + aEnum . name ( ) ; } | Get the unique name of the passed enum entry . | 78 | 10 |
16,229 | @ OverrideOnDemand @ Nullable protected IReadableResource internalResolveResource ( @ Nonnull @ Nonempty final String sType , @ Nullable final String sNamespaceURI , @ Nullable final String sPublicId , @ Nullable final String sSystemId , @ Nullable final String sBaseURI ) throws Exception { if ( DEBUG_RESOLVE ) if ( LOGGER . isInfoEnabled ( ) ) LOGGER . info ( "internalResolveResource (" + sType + ", " + sNamespaceURI + ", " + sPublicId + ", " + sSystemId + ", " + sBaseURI + ")" ) ; return DefaultResourceResolver . getResolvedResource ( sSystemId , sBaseURI , getClassLoader ( ) ) ; } | Internal resource resolving | 163 | 3 |
16,230 | @ Override @ Nullable public final LSInput mainResolveResource ( @ Nonnull @ Nonempty final String sType , @ Nullable final String sNamespaceURI , @ Nullable final String sPublicId , @ Nullable final String sSystemId , @ Nullable final String sBaseURI ) { try { // Try to get the resource final IReadableResource aResolvedResource = internalResolveResource ( sType , sNamespaceURI , sPublicId , sSystemId , sBaseURI ) ; return new ResourceLSInput ( aResolvedResource ) ; } catch ( final Exception ex ) { throw new IllegalStateException ( "Failed to resolve resource '" + sType + "', '" + sNamespaceURI + "', '" + sPublicId + "', '" + sSystemId + "', '" + sBaseURI + "'" , ex ) ; } } | Resolve a resource with the passed parameters | 191 | 8 |
16,231 | @ Nonnull @ ReturnsMutableCopy public static < ELEMENTTYPE > NonBlockingStack < ELEMENTTYPE > newStack ( @ Nullable final ELEMENTTYPE aValue ) { final NonBlockingStack < ELEMENTTYPE > ret = newStack ( ) ; ret . push ( aValue ) ; return ret ; } | Create a new stack with a single element . | 67 | 9 |
16,232 | @ Nonnull @ ReturnsMutableCopy @ SafeVarargs public static < ELEMENTTYPE > NonBlockingStack < ELEMENTTYPE > newStack ( @ Nullable final ELEMENTTYPE ... aValues ) { return new NonBlockingStack <> ( aValues ) ; } | Create a new stack from the given array . | 57 | 9 |
16,233 | @ Nonnull @ ReturnsMutableCopy public static < ELEMENTTYPE > NonBlockingStack < ELEMENTTYPE > newStack ( @ Nullable final Collection < ? extends ELEMENTTYPE > aValues ) { return new NonBlockingStack <> ( aValues ) ; } | Create a new stack from the given collection . | 57 | 9 |
16,234 | @ OverrideOnDemand protected void validateOutgoingBusinessDocument ( @ Nonnull final Element aXML ) throws AS2ClientBuilderException { if ( m_aVESRegistry == null ) { // Create lazily m_aVESRegistry = createValidationRegistry ( ) ; } final IValidationExecutorSet aVES = m_aVESRegistry . getOfID ( m_aVESID ) ; if ( aVES == null ) throw new AS2ClientBuilderException ( "The validation executor set ID " + m_aVESID . getAsSingleID ( ) + " is unknown!" ) ; final ValidationExecutionManager aVEM = aVES . createExecutionManager ( ) ; final ValidationResultList aValidationResult = aVEM . executeValidation ( ValidationSource . create ( null , aXML ) , ( Locale ) null ) ; if ( aValidationResult . containsAtLeastOneError ( ) ) throw new AS2ClientBuilderValidationException ( aValidationResult ) ; } | Perform the standard PEPPOL validation of the outgoing business document before sending takes place . In case validation fails an exception is thrown . The validation is configured using the validation key . This method is only called when a validation key was set . | 231 | 48 |
16,235 | @ Nullable public ISessionScope getSessionScopeOfID ( @ Nullable final String sScopeID ) { if ( StringHelper . hasNoText ( sScopeID ) ) return null ; return m_aRWLock . readLocked ( ( ) -> m_aSessionScopes . get ( sScopeID ) ) ; } | Get the session scope with the specified ID . If no such scope exists no further actions are taken . | 70 | 20 |
16,236 | public void onScopeEnd ( @ Nonnull final ISessionScope aSessionScope ) { ValueEnforcer . notNull ( aSessionScope , "SessionScope" ) ; // Only handle scopes that are not yet destructed if ( aSessionScope . isValid ( ) ) { final String sSessionID = aSessionScope . getID ( ) ; final boolean bCanDestroyScope = m_aRWLock . writeLocked ( ( ) -> { boolean bWLCanDestroyScope = false ; // Only if we're not just in destruction of exactly this session if ( m_aSessionsInDestruction . add ( sSessionID ) ) { // Remove from map final ISessionScope aRemovedScope = m_aSessionScopes . remove ( sSessionID ) ; if ( ! EqualsHelper . identityEqual ( aRemovedScope , aSessionScope ) ) { LOGGER . error ( "Ending an unknown session with ID '" + sSessionID + "'" ) ; LOGGER . error ( " Scope to be removed: " + aSessionScope ) ; LOGGER . error ( " Removed scope: " + aRemovedScope ) ; } bWLCanDestroyScope = true ; } else LOGGER . info ( "Already destructing session '" + sSessionID + "'" ) ; return bWLCanDestroyScope ; } ) ; if ( bCanDestroyScope ) { // Destroy scope outside of write lock try { // Invoke SPIs ScopeSPIManager . getInstance ( ) . onSessionScopeEnd ( aSessionScope ) ; // Destroy the scope aSessionScope . destroyScope ( ) ; } finally { // Remove from "in destruction" list m_aRWLock . writeLocked ( ( ) -> m_aSessionsInDestruction . remove ( sSessionID ) ) ; } } } } | Close the passed session scope gracefully . Each managed scope is guaranteed to be destroyed only once . First the SPI manager is invoked and afterwards the scope is destroyed . | 386 | 32 |
16,237 | public void destroyAllSessions ( ) { // destroy all session scopes (use a copy, because we're invalidating // the sessions internally!) for ( final ISessionScope aSessionScope : getAllSessionScopes ( ) ) { // Unfortunately we need a special handling here if ( aSessionScope . selfDestruct ( ) . isContinue ( ) ) { // Remove from map onScopeEnd ( aSessionScope ) ; } // Else the destruction was already started! } // Sanity check in case something went wrong _checkIfAnySessionsExist ( ) ; } | Destroy all known session scopes . After this method it is ensured that the internal session map is empty . | 119 | 21 |
16,238 | @ Nonnull public static IGlobalScope onGlobalBegin ( @ Nonnull @ Nonempty final String sScopeID ) { return onGlobalBegin ( sScopeID , GlobalScope :: new ) ; } | This method is used to set the initial global scope . | 41 | 11 |
16,239 | public static void onGlobalEnd ( ) { s_aGlobalLock . locked ( ( ) -> { /** * This code removes all attributes set for the global context. This is * necessary, since the attributes would survive a Tomcat servlet context * reload if we don't kill them manually.<br> * Global scope variable may be null if onGlobalBegin() was never called! */ if ( s_aGlobalScope != null ) { // Invoke SPI ScopeSPIManager . getInstance ( ) . onGlobalScopeEnd ( s_aGlobalScope ) ; // Destroy and invalidate scope final String sDestroyedScopeID = s_aGlobalScope . getID ( ) ; s_aGlobalScope . destroyScope ( ) ; s_aGlobalScope = null ; // done if ( ScopeHelper . debugGlobalScopeLifeCycle ( LOGGER ) ) LOGGER . info ( "Global scope '" + sDestroyedScopeID + "' shut down!" , ScopeHelper . getDebugStackTrace ( ) ) ; } else LOGGER . warn ( "No global scope present that could be shut down!" ) ; } ) ; } | To be called when the singleton global context is to be destroyed . | 237 | 14 |
16,240 | public static void destroySessionScope ( @ Nonnull final ISessionScope aSessionScope ) { ValueEnforcer . notNull ( aSessionScope , "SessionScope" ) ; ScopeSessionManager . getInstance ( ) . onScopeEnd ( aSessionScope ) ; } | Manually destroy the passed session scope . | 55 | 8 |
16,241 | public static void onRequestEnd ( ) { final IRequestScope aRequestScope = getRequestScopeOrNull ( ) ; try { // Do we have something to destroy? if ( aRequestScope != null ) { _destroyRequestScope ( aRequestScope ) ; } else { // Happens after an internal redirect happened in a web-application // (e.g. for 404 page) for the original scope LOGGER . warn ( "No request scope present that could be ended!" ) ; } } finally { // Remove from ThreadLocal internalClearRequestScope ( ) ; } } | To be called after a request finished . | 119 | 8 |
16,242 | public void onDocumentType ( @ Nonnull final String sQualifiedElementName , @ Nullable final String sPublicID , @ Nullable final String sSystemID ) { ValueEnforcer . notNull ( sQualifiedElementName , "QualifiedElementName" ) ; final String sDocType = getDocTypeXMLRepresentation ( m_eXMLVersion , m_aXMLWriterSettings . getIncorrectCharacterHandling ( ) , sQualifiedElementName , sPublicID , sSystemID ) ; _append ( sDocType ) ; newLine ( ) ; } | On XML document type . | 124 | 5 |
16,243 | public void onProcessingInstruction ( @ Nonnull final String sTarget , @ Nullable final String sData ) { _append ( PI_START ) . _append ( sTarget ) ; if ( StringHelper . hasText ( sData ) ) _append ( ' ' ) . _append ( sData ) ; _append ( PI_END ) ; newLine ( ) ; } | On processing instruction | 81 | 3 |
16,244 | public void onEntityReference ( @ Nonnull final String sEntityRef ) { _append ( ER_START ) . _append ( sEntityRef ) . _append ( ER_END ) ; } | On entity reference . | 42 | 4 |
16,245 | public void onContentElementWhitespace ( @ Nullable final CharSequence aWhitespaces ) { if ( StringHelper . hasText ( aWhitespaces ) ) _append ( aWhitespaces . toString ( ) ) ; } | Ignorable whitespace characters . | 51 | 6 |
16,246 | public void onComment ( @ Nullable final String sComment ) { if ( StringHelper . hasText ( sComment ) ) { if ( isThrowExceptionOnNestedComments ( ) ) if ( sComment . contains ( COMMENT_START ) || sComment . contains ( COMMENT_END ) ) throw new IllegalArgumentException ( "XML comment contains nested XML comment: " + sComment ) ; _append ( COMMENT_START ) . _append ( sComment ) . _append ( COMMENT_END ) ; } } | Comment node . | 114 | 3 |
16,247 | public void onText ( @ Nonnull final char [ ] aText , @ Nonnegative final int nOfs , @ Nonnegative final int nLen ) { onText ( aText , nOfs , nLen , true ) ; } | XML text node . | 50 | 5 |
16,248 | public void onCDATA ( @ Nullable final String sText ) { if ( StringHelper . hasText ( sText ) ) { if ( sText . indexOf ( CDATA_END ) >= 0 ) { // Split CDATA sections if they contain the illegal "]]>" marker final ICommonsList < String > aParts = StringHelper . getExploded ( CDATA_END , sText ) ; final int nParts = aParts . size ( ) ; for ( int i = 0 ; i < nParts ; ++ i ) { _append ( CDATA_START ) ; if ( i > 0 ) _append ( ' ' ) ; _appendMasked ( EXMLCharMode . CDATA , aParts . get ( i ) ) ; if ( i < nParts - 1 ) _append ( "]]" ) ; _append ( CDATA_END ) ; } } else { // No special handling required _append ( CDATA_START ) . _appendMasked ( EXMLCharMode . CDATA , sText ) . _append ( CDATA_END ) ; } } } | CDATA node . | 233 | 4 |
16,249 | public void onElementStart ( @ Nullable final String sNamespacePrefix , @ Nonnull final String sTagName , @ Nullable final Map < QName , String > aAttrs , @ Nonnull final EXMLSerializeBracketMode eBracketMode ) { elementStartOpen ( sNamespacePrefix , sTagName ) ; if ( aAttrs != null && ! aAttrs . isEmpty ( ) ) { if ( m_bOrderAttributesAndNamespaces ) { // first separate in NS and non-NS attributes // Sort namespace attributes by assigned prefix final ICommonsSortedMap < QName , String > aNamespaceAttrs = new CommonsTreeMap <> ( CXML . getComparatorQNameForNamespacePrefix ( ) ) ; final ICommonsSortedMap < QName , String > aNonNamespaceAttrs = new CommonsTreeMap <> ( CXML . getComparatorQNameNamespaceURIBeforeLocalPart ( ) ) ; for ( final Map . Entry < QName , String > aEntry : aAttrs . entrySet ( ) ) { final QName aAttrName = aEntry . getKey ( ) ; if ( XMLConstants . XMLNS_ATTRIBUTE_NS_URI . equals ( aAttrName . getNamespaceURI ( ) ) ) aNamespaceAttrs . put ( aAttrName , aEntry . getValue ( ) ) ; else aNonNamespaceAttrs . put ( aAttrName , aEntry . getValue ( ) ) ; } // emit namespace attributes first for ( final Map . Entry < QName , String > aEntry : aNamespaceAttrs . entrySet ( ) ) { final QName aAttrName = aEntry . getKey ( ) ; elementAttr ( aAttrName . getPrefix ( ) , aAttrName . getLocalPart ( ) , aEntry . getValue ( ) ) ; } // emit non-namespace attributes afterwards for ( final Map . Entry < QName , String > aEntry : aNonNamespaceAttrs . entrySet ( ) ) { final QName aAttrName = aEntry . getKey ( ) ; elementAttr ( aAttrName . getPrefix ( ) , aAttrName . getLocalPart ( ) , aEntry . getValue ( ) ) ; } } else { // assuming that the order of the passed attributes is consistent! // Emit all attributes for ( final Map . Entry < QName , String > aEntry : aAttrs . entrySet ( ) ) { final QName aAttrName = aEntry . getKey ( ) ; elementAttr ( aAttrName . getPrefix ( ) , aAttrName . getLocalPart ( ) , aEntry . getValue ( ) ) ; } } } elementStartClose ( eBracketMode ) ; } | Start of an element . | 614 | 5 |
16,250 | public void onElementEnd ( @ Nullable final String sNamespacePrefix , @ Nonnull final String sTagName , @ Nonnull final EXMLSerializeBracketMode eBracketMode ) { if ( eBracketMode . isOpenClose ( ) ) { _append ( "</" ) ; if ( StringHelper . hasText ( sNamespacePrefix ) ) _appendMasked ( EXMLCharMode . ELEMENT_NAME , sNamespacePrefix ) . _append ( CXML . XML_PREFIX_NAMESPACE_SEP ) ; _appendMasked ( EXMLCharMode . ELEMENT_NAME , sTagName ) . _append ( ' ' ) ; } } | End of an element . | 153 | 5 |
16,251 | private void _registerTypeConverter ( @ Nonnull final Class < ? > aSrcClass , @ Nonnull final Class < ? > aDstClass , @ Nonnull final ITypeConverter < ? , ? > aConverter ) { ValueEnforcer . notNull ( aSrcClass , "SrcClass" ) ; ValueEnforcer . isTrue ( ClassHelper . isPublic ( aSrcClass ) , ( ) -> "Source " + aSrcClass + " is no public class!" ) ; ValueEnforcer . notNull ( aDstClass , "DstClass" ) ; ValueEnforcer . isTrue ( ClassHelper . isPublic ( aDstClass ) , ( ) -> "Destination " + aDstClass + " is no public class!" ) ; ValueEnforcer . isFalse ( aSrcClass . equals ( aDstClass ) , "Source and destination class are equal and therefore no converter is required." ) ; ValueEnforcer . notNull ( aConverter , "Converter" ) ; ValueEnforcer . isFalse ( aConverter instanceof ITypeConverterRule , "Type converter rules must be registered via registerTypeConverterRule" ) ; if ( ClassHelper . areConvertibleClasses ( aSrcClass , aDstClass ) ) if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "No type converter needed between " + aSrcClass + " and " + aDstClass + " because types are convertible!" ) ; // The main class should not already be registered final Map < Class < ? > , ITypeConverter < ? , ? > > aSrcMap = _getOrCreateConverterMap ( aSrcClass ) ; if ( aSrcMap . containsKey ( aDstClass ) ) throw new IllegalArgumentException ( "A mapping from " + aSrcClass + " to " + aDstClass + " is already defined!" ) ; m_aRWLock . writeLocked ( ( ) -> { // Automatically register the destination class, and all parent // classes/interfaces for ( final WeakReference < Class < ? > > aCurWRDstClass : ClassHierarchyCache . getClassHierarchyIterator ( aDstClass ) ) { final Class < ? > aCurDstClass = aCurWRDstClass . get ( ) ; if ( aCurDstClass != null ) if ( ! aSrcMap . containsKey ( aCurDstClass ) ) { if ( aSrcMap . put ( aCurDstClass , aConverter ) != null ) { if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Overwriting converter from " + aSrcClass + " to " + aCurDstClass ) ; } else { if ( LOGGER . isTraceEnabled ( ) ) LOGGER . trace ( "Registered type converter from '" + aSrcClass . toString ( ) + "' to '" + aCurDstClass . toString ( ) + "'" ) ; } } } } ) ; } | Register a default type converter . | 680 | 6 |
16,252 | private void _iterateFuzzyConverters ( @ Nonnull final Class < ? > aSrcClass , @ Nonnull final Class < ? > aDstClass , @ Nonnull final ITypeConverterCallback aCallback ) { // For all possible source classes for ( final WeakReference < Class < ? > > aCurWRSrcClass : ClassHierarchyCache . getClassHierarchyIterator ( aSrcClass ) ) { final Class < ? > aCurSrcClass = aCurWRSrcClass . get ( ) ; if ( aCurSrcClass != null ) { // Do we have a source converter? final Map < Class < ? > , ITypeConverter < ? , ? > > aConverterMap = m_aConverter . get ( aCurSrcClass ) ; if ( aConverterMap != null ) { // Check explicit destination classes final ITypeConverter < ? , ? > aConverter = aConverterMap . get ( aDstClass ) ; if ( aConverter != null ) { // We found a match -> invoke the callback! if ( aCallback . call ( aCurSrcClass , aDstClass , aConverter ) . isBreak ( ) ) break ; } } } } } | Iterate all possible fuzzy converters from source class to destination class . | 280 | 14 |
16,253 | public void iterateAllRegisteredTypeConverters ( @ Nonnull final ITypeConverterCallback aCallback ) { // Create a copy of the map final Map < Class < ? > , Map < Class < ? > , ITypeConverter < ? , ? > > > aCopy = m_aRWLock . readLocked ( ( ) -> new CommonsHashMap <> ( m_aConverter ) ) ; // And iterate the copy outer : for ( final Map . Entry < Class < ? > , Map < Class < ? > , ITypeConverter < ? , ? > > > aSrcEntry : aCopy . entrySet ( ) ) { final Class < ? > aSrcClass = aSrcEntry . getKey ( ) ; for ( final Map . Entry < Class < ? > , ITypeConverter < ? , ? > > aDstEntry : aSrcEntry . getValue ( ) . entrySet ( ) ) if ( aCallback . call ( aSrcClass , aDstEntry . getKey ( ) , aDstEntry . getValue ( ) ) . isBreak ( ) ) break outer ; } } | Iterate all registered type converters . For informational purposes only . | 250 | 13 |
16,254 | @ Nonnull public static Class < ? > [ ] getClassArray ( @ Nullable final Object ... aObjs ) { if ( ArrayHelper . isEmpty ( aObjs ) ) return EMPTY_CLASS_ARRAY ; final Class < ? > [ ] ret = new Class < ? > [ aObjs . length ] ; for ( int i = 0 ; i < aObjs . length ; ++ i ) ret [ i ] = aObjs [ i ] . getClass ( ) ; return ret ; } | Get an array with all the classes of the passed object array . | 109 | 13 |
16,255 | @ Nullable public static < RETURNTYPE > RETURNTYPE invokeMethod ( @ Nonnull final Object aSrcObj , @ Nonnull final String sMethodName , @ Nullable final Object ... aArgs ) throws NoSuchMethodException , IllegalAccessException , InvocationTargetException { return GenericReflection . < RETURNTYPE > invokeMethod ( aSrcObj , sMethodName , getClassArray ( aArgs ) , aArgs ) ; } | This method dynamically invokes the method with the given name on the given object . | 94 | 16 |
16,256 | @ Nonnull public static < DATATYPE > DATATYPE newInstance ( @ Nonnull final DATATYPE aObj ) throws IllegalAccessException , NoSuchMethodException , InvocationTargetException , InstantiationException { return findConstructor ( aObj ) . newInstance ( ) ; } | Create a new instance of the class identified by the passed object . The default constructor will be invoked . | 66 | 20 |
16,257 | @ Nonnull public static final < T extends AbstractRequestSingleton > T getRequestSingleton ( @ Nonnull final Class < T > aClass ) { return getSingleton ( _getStaticScope ( true ) , aClass ) ; } | Get the singleton object in the current request scope using the passed class . If the singleton is not yet instantiated a new instance is created . | 50 | 30 |
16,258 | public static void forAllClassPathEntries ( @ Nonnull final Consumer < ? super String > aConsumer ) { StringHelper . explode ( SystemProperties . getPathSeparator ( ) , SystemProperties . getJavaClassPath ( ) , aConsumer ) ; } | Add all class path entries into the provided target list . | 57 | 11 |
16,259 | public static void printClassPathEntries ( @ Nonnull final PrintStream aPS , @ Nonnull final String sItemSeparator ) { forAllClassPathEntries ( x -> { aPS . print ( x ) ; aPS . print ( sItemSeparator ) ; } ) ; } | Print all class path entries on the passed print stream using the passed separator | 64 | 15 |
16,260 | @ Nonnull public static ESuccess writeToStream ( @ Nonnull final IMicroNode aNode , @ Nonnull @ WillClose final OutputStream aOS ) { return writeToStream ( aNode , aOS , XMLWriterSettings . DEFAULT_XML_SETTINGS ) ; } | Write a Micro Node to an output stream using the default settings . | 61 | 13 |
16,261 | @ 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 Exception ex ) { if ( LOGGER . isErrorEnabled ( ) ) LOGGER . error ( "Error serializing MicroDOM with settings " + aSettings . toString ( ) , ex ) ; } return null ; } | Convert the passed micro node to an XML string using the provided settings . | 185 | 15 |
16,262 | @ 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 Exception ex ) { if ( LOGGER . isErrorEnabled ( ) ) LOGGER . error ( "Error serializing MicroDOM with settings " + aSettings . toString ( ) , ex ) ; } return null ; } | Convert the passed micro node to an XML byte array using the provided settings . | 194 | 16 |
16,263 | public static < KEYTYPE , DATATYPE , ITEMTYPE extends ITreeItemWithID < KEYTYPE , DATATYPE , ITEMTYPE > > void sortByID ( @ Nonnull final IBasicTree < DATATYPE , ITEMTYPE > aTree , @ Nonnull final Comparator < ? super KEYTYPE > aKeyComparator ) { _sort ( aTree , Comparator . comparing ( IHasID :: getID , aKeyComparator ) ) ; } | Sort each level of the passed tree on the ID with the specified comparator . | 106 | 16 |
16,264 | public static < KEYTYPE , DATATYPE , ITEMTYPE extends ITreeItemWithID < KEYTYPE , DATATYPE , ITEMTYPE > > void sortByValue ( @ Nonnull final IBasicTree < DATATYPE , ITEMTYPE > aTree , @ Nonnull final Comparator < ? super DATATYPE > aValueComparator ) { _sort ( aTree , Comparator . comparing ( IBasicTreeItem :: getData , aValueComparator ) ) ; } | Sort each level of the passed tree on the value with the specified comparator . | 110 | 16 |
16,265 | @ Nonnull public final EChange start ( ) { // Already started? if ( m_nStartDT > 0 ) return EChange . UNCHANGED ; m_nStartDT = getCurrentNanoTime ( ) ; return EChange . CHANGED ; } | Start the stop watch . | 57 | 5 |
16,266 | @ Nonnull public EChange stop ( ) { // Already stopped? if ( m_nStartDT == 0 ) return EChange . UNCHANGED ; final long nCurrentNanoTime = getCurrentNanoTime ( ) ; m_nDurationNanos += ( nCurrentNanoTime - m_nStartDT ) ; m_nStartDT = 0 ; return EChange . CHANGED ; } | Stop the stop watch . | 87 | 5 |
16,267 | @ Nonnull public static TimeValue runMeasured ( @ Nonnull final Runnable aRunnable ) { final StopWatch aSW = createdStarted ( ) ; aRunnable . run ( ) ; final long nNanos = aSW . stopAndGetNanos ( ) ; return new TimeValue ( TimeUnit . NANOSECONDS , nNanos ) ; } | Run the passed runnable and measure the time . | 83 | 11 |
16,268 | @ Nonnull public ErrorTextProvider addItem ( @ Nonnull final EField eField , @ Nonnull @ Nonempty final String sText ) { return addItem ( new FormattableItem ( eField , sText ) ) ; } | Add an error item to be disabled . | 50 | 8 |
16,269 | public int compareTo ( @ Nonnull final Version rhs ) { ValueEnforcer . notNull ( rhs , "Rhs" ) ; // compare major version int ret = m_nMajor - rhs . m_nMajor ; if ( ret == 0 ) { // compare minor version ret = m_nMinor - rhs . m_nMinor ; if ( ret == 0 ) { // compare micro version ret = m_nMicro - rhs . m_nMicro ; if ( ret == 0 ) { // check qualifier if ( m_sQualifier != null ) { if ( rhs . m_sQualifier != null ) { ret = m_sQualifier . compareTo ( rhs . m_sQualifier ) ; // convert to -1/0/+1 if ( ret < 0 ) ret = - 1 ; else if ( ret > 0 ) ret = + 1 ; } else ret = 1 ; } else if ( rhs . m_sQualifier != null ) { // only this qualifier == null ret = - 1 ; } else { // both qualifier are null ret = 0 ; } } } } return ret ; } | Compares two Version objects . | 243 | 6 |
16,270 | @ Nonnull public String getAsString ( final boolean bPrintZeroElements , final boolean bPrintAtLeastMajorAndMinor ) { // Build from back to front final StringBuilder aSB = new StringBuilder ( m_sQualifier != null ? m_sQualifier : "" ) ; if ( m_nMicro > 0 || aSB . length ( ) > 0 || bPrintZeroElements ) { // Micro version if ( aSB . length ( ) > 0 ) aSB . insert ( 0 , ' ' ) ; aSB . insert ( 0 , m_nMicro ) ; } if ( bPrintAtLeastMajorAndMinor || m_nMinor > 0 || aSB . length ( ) > 0 || bPrintZeroElements ) { // Minor version if ( aSB . length ( ) > 0 ) aSB . insert ( 0 , ' ' ) ; aSB . insert ( 0 , m_nMinor ) ; } if ( bPrintAtLeastMajorAndMinor || m_nMajor > 0 || aSB . length ( ) > 0 || bPrintZeroElements ) { // Major version if ( aSB . length ( ) > 0 ) aSB . insert ( 0 , ' ' ) ; aSB . insert ( 0 , m_nMajor ) ; } return aSB . length ( ) > 0 ? aSB . toString ( ) : DEFAULT_VERSION_STRING ; } | Get the string representation of the version number . | 299 | 9 |
16,271 | @ Nonnull public static Version parse ( @ Nullable final String sVersionString , final boolean bOldVersion ) { final String s = sVersionString == null ? "" : sVersionString . trim ( ) ; if ( s . length ( ) == 0 ) return DEFAULT_VERSION ; int nMajor ; int nMinor ; int nMicro ; String sQualifier ; if ( bOldVersion ) { // old version // split each token final String [ ] aParts = StringHelper . getExplodedArray ( ' ' , s , 4 ) ; if ( aParts . length > 0 ) nMajor = StringParser . parseInt ( aParts [ 0 ] , 0 ) ; else nMajor = 0 ; if ( aParts . length > 1 ) nMinor = StringParser . parseInt ( aParts [ 1 ] , 0 ) ; else nMinor = 0 ; if ( aParts . length > 2 ) nMicro = StringParser . parseInt ( aParts [ 2 ] , 0 ) ; else nMicro = 0 ; if ( aParts . length > 3 ) sQualifier = StringHelper . hasNoText ( aParts [ 3 ] ) ? null : aParts [ 3 ] ; else sQualifier = null ; } else { // Complex parsing Integer aMajor ; Integer aMinor = null ; Integer aMicro = null ; boolean bDone = false ; // Extract major version number String [ ] aParts = _extSplit ( s ) ; aMajor = StringParser . parseIntObj ( aParts [ 0 ] ) ; if ( aMajor == null && StringHelper . hasText ( aParts [ 0 ] ) ) { // Major version is not numeric, so everything is the qualifier sQualifier = s ; bDone = true ; } else sQualifier = null ; String sRest = ! bDone && aParts . length > 1 ? aParts [ 1 ] : null ; if ( StringHelper . hasText ( sRest ) ) { // Parse minor version number part aParts = _extSplit ( sRest ) ; aMinor = StringParser . parseIntObj ( aParts [ 0 ] ) ; if ( aMinor == null && StringHelper . hasText ( aParts [ 0 ] ) ) { // Minor version is not numeric, so everything is the qualifier sQualifier = sRest ; bDone = true ; } sRest = ! bDone && aParts . length > 1 ? aParts [ 1 ] : null ; if ( StringHelper . hasText ( sRest ) ) { // Parse micro version number part aParts = _extSplit ( sRest ) ; aMicro = StringParser . parseIntObj ( aParts [ 0 ] ) ; if ( aMicro == null && StringHelper . hasText ( aParts [ 0 ] ) ) { // Micro version is not numeric, so everything is the qualifier sQualifier = sRest ; bDone = true ; } if ( ! bDone && aParts . length > 1 ) { // Some qualifier left! sQualifier = aParts [ 1 ] ; } } } nMajor = aMajor == null ? 0 : aMajor . intValue ( ) ; nMinor = aMinor == null ? 0 : aMinor . intValue ( ) ; nMicro = aMicro == null ? 0 : aMicro . intValue ( ) ; sQualifier = StringHelper . hasNoText ( sQualifier ) ? null : sQualifier ; } return new Version ( nMajor , nMinor , nMicro , sQualifier ) ; } | Construct a version object from a string . | 731 | 8 |
16,272 | private void _appendOptionGroup ( final StringBuilder aSB , final OptionGroup aGroup ) { if ( ! aGroup . isRequired ( ) ) aSB . append ( ' ' ) ; final ICommonsList < Option > optList = aGroup . getAllOptions ( ) ; if ( m_aOptionComparator != null ) optList . sort ( m_aOptionComparator ) ; // for each option in the OptionGroup final Iterator < Option > it = optList . iterator ( ) ; while ( it . hasNext ( ) ) { // whether the option is required or not is handled at group level _appendOption ( aSB , it . next ( ) , true ) ; if ( it . hasNext ( ) ) aSB . append ( " | " ) ; } if ( ! aGroup . isRequired ( ) ) aSB . append ( ' ' ) ; } | Appends the usage clause for an OptionGroup to a StringBuilder . The clause is wrapped in square brackets if the group is required . The display of the options is handled by appendOption | 187 | 37 |
16,273 | public void printUsage ( @ Nonnull final PrintWriter aPW , final int nWidth , final String sCmdLineSyntax ) { final int nArgPos = sCmdLineSyntax . indexOf ( ' ' ) + 1 ; printWrapped ( aPW , nWidth , getSyntaxPrefix ( ) . length ( ) + nArgPos , getSyntaxPrefix ( ) + sCmdLineSyntax ) ; } | Print the sCmdLineSyntax to the specified writer using the specified width . | 93 | 16 |
16,274 | @ Nonnull public EChange registerMimeTypeContent ( @ Nonnull final MimeTypeContent aMimeTypeContent ) { ValueEnforcer . notNull ( aMimeTypeContent , "MimeTypeContent" ) ; return m_aRWLock . writeLocked ( ( ) -> m_aMimeTypeContents . addObject ( aMimeTypeContent ) ) ; } | Register a new MIME content type . | 82 | 8 |
16,275 | @ Nonnull public EChange unregisterMimeTypeContent ( @ Nullable final MimeTypeContent aMimeTypeContent ) { if ( aMimeTypeContent == null ) return EChange . UNCHANGED ; return m_aRWLock . writeLocked ( ( ) -> m_aMimeTypeContents . removeObject ( aMimeTypeContent ) ) ; } | Unregister an existing MIME content type . | 81 | 9 |
16,276 | @ Nullable public IMimeType getMimeTypeFromBytes ( @ Nullable final byte [ ] aBytes , @ Nullable final IMimeType aDefault ) { if ( aBytes == null || aBytes . length == 0 ) return aDefault ; return m_aRWLock . readLocked ( ( ) -> { for ( final MimeTypeContent aMTC : m_aMimeTypeContents ) if ( aMTC . matchesBeginning ( aBytes ) ) return aMTC . getMimeType ( ) ; // default fallback return aDefault ; } ) ; } | Try to determine the MIME type from the given byte array . | 124 | 13 |
16,277 | public void reinitialize ( ) { m_aRWLock . writeLocked ( ( ) -> { m_aMimeTypeContents . clear ( ) ; _registerDefaultMimeTypeContents ( ) ; } ) ; if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Reinitialized " + MimeTypeDeterminator . class . getName ( ) ) ; } | Reset the MimeTypeContent cache to the initial state . | 84 | 13 |
16,278 | public void iterateAllCombinations ( @ Nonnull final ICommonsList < DATATYPE > aElements , @ Nonnull final Consumer < ? super ICommonsList < DATATYPE > > aCallback ) { ValueEnforcer . notNull ( aElements , "Elements" ) ; ValueEnforcer . notNull ( aCallback , "Callback" ) ; for ( int nSlotCount = m_bAllowEmpty ? 0 : 1 ; nSlotCount <= m_nSlotCount ; nSlotCount ++ ) { if ( aElements . isEmpty ( ) ) { aCallback . accept ( new CommonsArrayList <> ( ) ) ; } else { // Add all permutations for the current slot count for ( final ICommonsList < DATATYPE > aPermutation : new CombinationGenerator <> ( aElements , nSlotCount ) ) aCallback . accept ( aPermutation ) ; } } } | Iterate all combination no matter they are unique or not . | 206 | 12 |
16,279 | @ Nonnull @ ReturnsMutableCopy public ICommonsSet < ICommonsList < DATATYPE > > getCombinations ( @ Nonnull final ICommonsList < DATATYPE > aElements ) { ValueEnforcer . notNull ( aElements , "Elements" ) ; final ICommonsSet < ICommonsList < DATATYPE > > aAllResults = new CommonsHashSet <> ( ) ; iterateAllCombinations ( aElements , aAllResults :: add ) ; return aAllResults ; } | Generate all combinations without duplicates . | 121 | 8 |
16,280 | private void _processQueue ( ) { SoftValue < K , V > aSoftValue ; while ( ( aSoftValue = GenericReflection . uncheckedCast ( m_aQueue . poll ( ) ) ) != null ) { m_aSrcMap . remove ( aSoftValue . m_aKey ) ; } } | Here we go through the ReferenceQueue and remove garbage collected SoftValue objects from the HashMap by looking them up using the SoftValue . m_aKey data member . | 68 | 34 |
16,281 | @ Override public V put ( final K aKey , final V aValue ) { // throw out garbage collected values first _processQueue ( ) ; final SoftValue < K , V > aOld = m_aSrcMap . put ( aKey , new SoftValue <> ( aKey , aValue , m_aQueue ) ) ; return aOld == null ? null : aOld . get ( ) ; } | Here we put the key value pair into the HashMap using a SoftValue object . | 89 | 17 |
16,282 | @ Override public void write ( final int c ) { final int nNewCount = m_nCount + 1 ; if ( nNewCount > m_aBuf . length ) m_aBuf = Arrays . copyOf ( m_aBuf , Math . max ( m_aBuf . length << 1 , nNewCount ) ) ; m_aBuf [ m_nCount ] = ( char ) c ; m_nCount = nNewCount ; } | Writes a character to the buffer . | 104 | 8 |
16,283 | @ Override public void write ( @ Nonnull final char [ ] aBuf , @ Nonnegative final int nOfs , @ Nonnegative final int nLen ) { ValueEnforcer . isArrayOfsLen ( aBuf , nOfs , nLen ) ; if ( nLen > 0 ) { final int nNewCount = m_nCount + nLen ; if ( nNewCount > m_aBuf . length ) m_aBuf = Arrays . copyOf ( m_aBuf , Math . max ( m_aBuf . length << 1 , nNewCount ) ) ; System . arraycopy ( aBuf , nOfs , m_aBuf , m_nCount , nLen ) ; m_nCount = nNewCount ; } } | Writes characters to the buffer . | 171 | 7 |
16,284 | @ Override public void write ( @ Nonnull final String sStr , @ Nonnegative final int nOfs , @ Nonnegative final int nLen ) { if ( nLen > 0 ) { final int newcount = m_nCount + nLen ; if ( newcount > m_aBuf . length ) { m_aBuf = Arrays . copyOf ( m_aBuf , Math . max ( m_aBuf . length << 1 , newcount ) ) ; } sStr . getChars ( nOfs , nOfs + nLen , m_aBuf , m_nCount ) ; m_nCount = newcount ; } } | Write a portion of a string to the buffer . | 146 | 10 |
16,285 | @ Nonnull @ ReturnsMutableCopy public byte [ ] toByteArray ( @ Nonnull final Charset aCharset ) { return StringHelper . encodeCharToBytes ( m_aBuf , 0 , m_nCount , aCharset ) ; } | Returns a copy of the input data as bytes in the correct charset . | 58 | 15 |
16,286 | @ Nonnull public String getAsString ( @ Nonnegative final int nLength ) { ValueEnforcer . isBetweenInclusive ( nLength , "Length" , 0 , m_nCount ) ; return new String ( m_aBuf , 0 , nLength ) ; } | Converts input data to a string . | 59 | 8 |
16,287 | @ Nonnull @ ReturnsMutableCopy @ OverrideOnDemand @ CodingStyleguideUnaware protected ICommonsMap < KEYTYPE , VALUETYPE > createCache ( ) { return hasMaxSize ( ) ? new SoftLinkedHashMap <> ( m_nMaxSize ) : new SoftHashMap <> ( ) ; } | Create a new cache map . This is the internal map that is used to store the items . | 75 | 19 |
16,288 | public VALUETYPE getFromCache ( final KEYTYPE aKey ) { VALUETYPE aValue = getFromCacheNoStats ( aKey ) ; if ( aValue == null ) { // No old value in the cache m_aRWLock . writeLock ( ) . lock ( ) ; try { // Read again, in case the value was set between the two locking // sections // Note: do not increase statistics in this second try aValue = getFromCacheNoStatsNotLocked ( aKey ) ; if ( aValue == null ) { // Call the abstract method to create the value to cache aValue = m_aCacheValueProvider . apply ( aKey ) ; // Just a consistency check if ( aValue == null ) throw new IllegalStateException ( "The value to cache was null for key '" + aKey + "'" ) ; // Put the new value into the cache putInCacheNotLocked ( aKey , aValue ) ; m_aCacheAccessStats . cacheMiss ( ) ; } else m_aCacheAccessStats . cacheHit ( ) ; } finally { m_aRWLock . writeLock ( ) . unlock ( ) ; } } else m_aCacheAccessStats . cacheHit ( ) ; return aValue ; } | Here Nonnull but derived class may be Nullable | 268 | 10 |
16,289 | @ Nonnull @ ReturnsMutableCopy public byte [ ] getAsByteArray ( ) { final byte [ ] aArray = m_aBuffer . array ( ) ; final int nOfs = m_aBuffer . arrayOffset ( ) ; final int nLength = m_aBuffer . position ( ) ; return ArrayHelper . getCopy ( aArray , nOfs , nLength ) ; } | Get everything as a big byte array without altering the ByteBuffer . This works only if the contained ByteBuffer has a backing array . | 84 | 26 |
16,290 | public void writeTo ( @ Nonnull @ WillNotClose final OutputStream aOS , final boolean bClearBuffer ) throws IOException { ValueEnforcer . notNull ( aOS , "OutputStream" ) ; aOS . write ( m_aBuffer . array ( ) , m_aBuffer . arrayOffset ( ) , m_aBuffer . position ( ) ) ; if ( bClearBuffer ) m_aBuffer . clear ( ) ; } | Write everything to the passed output stream and optionally clear the contained buffer . This works only if the contained ByteBuffer has a backing array . | 94 | 27 |
16,291 | @ Nonnull public String getAsString ( @ Nonnull final Charset aCharset ) { return new String ( m_aBuffer . array ( ) , m_aBuffer . arrayOffset ( ) , m_aBuffer . position ( ) , aCharset ) ; } | Get the content as a string without modifying the buffer . This works only if the contained ByteBuffer has a backing array . | 61 | 24 |
16,292 | public void write ( @ Nonnull final ByteBuffer aSrcBuffer ) { ValueEnforcer . notNull ( aSrcBuffer , "SourceBuffer" ) ; if ( m_bCanGrow && aSrcBuffer . remaining ( ) > m_aBuffer . remaining ( ) ) _growBy ( aSrcBuffer . remaining ( ) ) ; m_aBuffer . put ( aSrcBuffer ) ; } | Write the content from the passed byte buffer to this output stream . | 89 | 13 |
16,293 | @ Nonnull public static Homoglyph build ( @ Nonnull final IReadableResource aRes ) throws IOException { ValueEnforcer . notNull ( aRes , "Resource" ) ; return build ( aRes . getReader ( StandardCharsets . ISO_8859_1 ) ) ; } | Parses the specified resource and uses it to construct a populated Homoglyph object . | 64 | 18 |
16,294 | @ 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 ) ; } } | Consumes the supplied Reader and uses it to construct a populated Homoglyph object . | 244 | 17 |
16,295 | public static void setFormattedOutput ( @ Nonnull final Marshaller aMarshaller , final boolean bFormattedOutput ) { _setProperty ( aMarshaller , Marshaller . JAXB_FORMATTED_OUTPUT , Boolean . valueOf ( bFormattedOutput ) ) ; } | Set the standard property for formatting the output or not . | 64 | 11 |
16,296 | public static void setSchemaLocation ( @ Nonnull final Marshaller aMarshaller , @ Nullable final String sSchemaLocation ) { _setProperty ( aMarshaller , Marshaller . JAXB_SCHEMA_LOCATION , sSchemaLocation ) ; } | Set the standard property for setting the namespace schema location | 60 | 10 |
16,297 | public static void setNoNamespaceSchemaLocation ( @ Nonnull final Marshaller aMarshaller , @ Nullable final String sSchemaLocation ) { _setProperty ( aMarshaller , Marshaller . JAXB_NO_NAMESPACE_SCHEMA_LOCATION , sSchemaLocation ) ; } | Set the standard property for setting the no - namespace schema location | 70 | 12 |
16,298 | public static void setFragment ( @ Nonnull final Marshaller aMarshaller , final boolean bFragment ) { _setProperty ( aMarshaller , Marshaller . JAXB_FRAGMENT , Boolean . valueOf ( bFragment ) ) ; } | Set the standard property for marshalling a fragment only . | 57 | 11 |
16,299 | public static void setSunIndentString ( @ Nonnull final Marshaller aMarshaller , @ Nullable final String sIndentString ) { final String sPropertyName = SUN_INDENT_STRING ; _setProperty ( aMarshaller , sPropertyName , sIndentString ) ; } | Set the Sun specific property for the indent string . | 65 | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.