idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
16,300
public void printUsage ( 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 .
16,301
public EChange registerMimeTypeContent ( final MimeTypeContent aMimeTypeContent ) { ValueEnforcer . notNull ( aMimeTypeContent , "MimeTypeContent" ) ; return m_aRWLock . writeLocked ( ( ) -> m_aMimeTypeContents . addObject ( aMimeTypeContent ) ) ; }
Register a new MIME content type .
16,302
public EChange unregisterMimeTypeContent ( final MimeTypeContent aMimeTypeContent ) { if ( aMimeTypeContent == null ) return EChange . UNCHANGED ; return m_aRWLock . writeLocked ( ( ) -> m_aMimeTypeContents . removeObject ( aMimeTypeContent ) ) ; }
Unregister an existing MIME content type .
16,303
public IMimeType getMimeTypeFromBytes ( final byte [ ] aBytes , 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 ( ) ; return aDefault ; } ) ; }
Try to determine the MIME type from the given byte array .
16,304
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 .
16,305
public void iterateAllCombinations ( final ICommonsList < DATATYPE > aElements , 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 { for ( final ICommonsList < DATATYPE > aPermutation : new CombinationGenerator < > ( aElements , nSlotCount ) ) aCallback . accept ( aPermutation ) ; } } }
Iterate all combination no matter they are unique or not .
16,306
public ICommonsSet < ICommonsList < DATATYPE > > getCombinations ( 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 .
16,307
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 .
16,308
public V put ( final K aKey , final V aValue ) { _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 .
16,309
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 .
16,310
public void write ( final char [ ] aBuf , final int nOfs , 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 .
16,311
public void write ( final String sStr , final int nOfs , 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 .
16,312
public byte [ ] toByteArray ( 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 .
16,313
public String getAsString ( final int nLength ) { ValueEnforcer . isBetweenInclusive ( nLength , "Length" , 0 , m_nCount ) ; return new String ( m_aBuf , 0 , nLength ) ; }
Converts input data to a string .
16,314
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 .
16,315
public VALUETYPE getFromCache ( final KEYTYPE aKey ) { VALUETYPE aValue = getFromCacheNoStats ( aKey ) ; if ( aValue == null ) { m_aRWLock . writeLock ( ) . lock ( ) ; try { aValue = getFromCacheNoStatsNotLocked ( aKey ) ; if ( aValue == null ) { aValue = m_aCacheValueProvider . apply ( aKey ) ; if ( aValue == null ) throw new IllegalStateException ( "The value to cache was null for key '" + aKey + "'" ) ; 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
16,316
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 .
16,317
public void writeTo ( 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 .
16,318
public String getAsString ( 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 .
16,319
public void write ( 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 .
16,320
public static Homoglyph build ( 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 .
16,321
public static Homoglyph build ( 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 .
16,322
public static void setFormattedOutput ( 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 .
16,323
public static void setSchemaLocation ( final Marshaller aMarshaller , final String sSchemaLocation ) { _setProperty ( aMarshaller , Marshaller . JAXB_SCHEMA_LOCATION , sSchemaLocation ) ; }
Set the standard property for setting the namespace schema location
16,324
public static void setNoNamespaceSchemaLocation ( final Marshaller aMarshaller , final String sSchemaLocation ) { _setProperty ( aMarshaller , Marshaller . JAXB_NO_NAMESPACE_SCHEMA_LOCATION , sSchemaLocation ) ; }
Set the standard property for setting the no - namespace schema location
16,325
public static void setFragment ( final Marshaller aMarshaller , final boolean bFragment ) { _setProperty ( aMarshaller , Marshaller . JAXB_FRAGMENT , Boolean . valueOf ( bFragment ) ) ; }
Set the standard property for marshalling a fragment only .
16,326
public static void setSunIndentString ( final Marshaller aMarshaller , final String sIndentString ) { final String sPropertyName = SUN_INDENT_STRING ; _setProperty ( aMarshaller , sPropertyName , sIndentString ) ; }
Set the Sun specific property for the indent string .
16,327
public static void setSunCharacterEscapeHandler ( final Marshaller aMarshaller , final Object aCharacterEscapeHandler ) { final String sPropertyName = SUN_ENCODING_HANDLER2 ; _setProperty ( aMarshaller , sPropertyName , aCharacterEscapeHandler ) ; }
Set the Sun specific encoding handler . Value must implement com . sun . xml . bind . marshaller . CharacterEscapeHandler
16,328
public static void setSunXMLHeaders ( final Marshaller aMarshaller , final String sXMLHeaders ) { final String sPropertyName = SUN_XML_HEADERS ; _setProperty ( aMarshaller , sPropertyName , sXMLHeaders ) ; }
Set the Sun specific XML header string .
16,329
public static boolean isSunJAXB2Marshaller ( final Marshaller aMarshaller ) { if ( aMarshaller == null ) return false ; final String sClassName = aMarshaller . getClass ( ) . getName ( ) ; return sClassName . equals ( JAXB_EXTERNAL_CLASS_NAME ) ; }
Check if the passed Marshaller is a Sun JAXB v2 marshaller . Use this method to determined whether the Sun specific methods may be invoked or not .
16,330
public static DateTimeFormatter getWithLocale ( final DateTimeFormatter aFormatter , final Locale aDisplayLocale ) { DateTimeFormatter ret = aFormatter ; if ( aDisplayLocale != null ) ret = ret . withLocale ( aDisplayLocale ) ; return ret ; }
Assign the passed display locale to the passed date time formatter .
16,331
public static DateTimeFormatter getFormatterDate ( final FormatStyle eStyle , final Locale aDisplayLocale , final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_DATE , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the date formatter for the passed locale .
16,332
public static DateTimeFormatter getFormatterTime ( final FormatStyle eStyle , final Locale aDisplayLocale , final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_TIME , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the time formatter for the passed locale .
16,333
public static DateTimeFormatter getFormatterDateTime ( final FormatStyle eStyle , final Locale aDisplayLocale , final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_DATE_TIME , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the date time formatter for the passed locale .
16,334
public static final void writeEncodeQuotedPrintableByte ( final int b , final OutputStream aOS ) throws IOException { final char cHigh = StringHelper . getHexCharUpperCase ( ( b >> 4 ) & 0xF ) ; final char cLow = StringHelper . getHexCharUpperCase ( b & 0xF ) ; aOS . write ( ESCAPE_CHAR ) ; aOS . write ( cHigh ) ; aOS . write ( cLow ) ; }
Encodes byte into its quoted - printable representation .
16,335
private int _getReadIndex ( final int key ) { int idx = MapHelper . phiMix ( key ) & m_nMask ; if ( m_aKeys [ idx ] == key ) { return idx ; } if ( m_aKeys [ idx ] == FREE_KEY ) { return - 1 ; } final int startIdx = idx ; while ( ( idx = _getNextIndex ( idx ) ) != startIdx ) { if ( m_aKeys [ idx ] == FREE_KEY ) return - 1 ; if ( m_aKeys [ idx ] == key ) return idx ; } return - 1 ; }
Find key position in the map .
16,336
public static String getLocaleDisplayName ( final Locale aLocale , final Locale aContentLocale ) { ValueEnforcer . notNull ( aContentLocale , "ContentLocale" ) ; if ( aLocale == null || aLocale . equals ( LOCALE_INDEPENDENT ) ) return ELocaleName . ID_LANGUAGE_INDEPENDENT . getDisplayText ( aContentLocale ) ; if ( aLocale . equals ( LOCALE_ALL ) ) return ELocaleName . ID_LANGUAGE_ALL . getDisplayText ( aContentLocale ) ; return aLocale . getDisplayName ( aContentLocale ) ; }
Get the display name of the passed language in the currently selected UI language .
16,337
public static ICommonsMap < Locale , String > getAllLocaleDisplayNames ( final Locale aContentLocale ) { ValueEnforcer . notNull ( aContentLocale , "ContentLocale" ) ; return new CommonsHashMap < > ( LocaleCache . getInstance ( ) . getAllLocales ( ) , Function . identity ( ) , aLocale -> getLocaleDisplayName ( aLocale , aContentLocale ) ) ; }
Get all possible locale names in the passed locale
16,338
public static Locale getLocaleFromString ( final String sLocaleAsString ) { if ( StringHelper . hasNoText ( sLocaleAsString ) ) { return SystemHelper . getSystemLocale ( ) ; } String sLanguage ; String sCountry ; String sVariant ; int i1 = sLocaleAsString . indexOf ( LOCALE_SEPARATOR ) ; if ( i1 < 0 ) { sLanguage = sLocaleAsString ; sCountry = "" ; sVariant = "" ; } else { sLanguage = sLocaleAsString . substring ( 0 , i1 ) ; ++ i1 ; final int i2 = sLocaleAsString . indexOf ( LOCALE_SEPARATOR , i1 ) ; if ( i2 < 0 ) { sCountry = sLocaleAsString . substring ( i1 ) ; sVariant = "" ; } else { sCountry = sLocaleAsString . substring ( i1 , i2 ) ; sVariant = sLocaleAsString . substring ( i2 + 1 ) ; } } if ( sLanguage . length ( ) == 2 ) sLanguage = sLanguage . toLowerCase ( Locale . US ) ; else sLanguage = "" ; if ( sCountry . length ( ) == 2 ) sCountry = sCountry . toUpperCase ( Locale . US ) ; else sCountry = "" ; if ( sVariant . length ( ) > 0 && ( sLanguage . length ( ) == 2 || sCountry . length ( ) == 2 ) ) sVariant = sVariant . toUpperCase ( Locale . US ) ; else sVariant = "" ; return LocaleCache . getInstance ( ) . getLocale ( sLanguage , sCountry , sVariant ) ; }
Convert a String in the form language - country - variant to a Locale object . Language needs to have exactly 2 characters . Country is optional but if present needs to have exactly 2 characters . Variant is optional .
16,339
private static String _getWithLeadingOrTrailing ( final String sSrc , final int nMinLen , final char cGap , final boolean bLeading ) { if ( nMinLen <= 0 ) { return getNotNull ( sSrc , "" ) ; } final int nSrcLen = getLength ( sSrc ) ; if ( nSrcLen == 0 ) { return getRepeated ( cGap , nMinLen ) ; } final int nCharsToAdd = nMinLen - nSrcLen ; if ( nCharsToAdd <= 0 ) { return sSrc ; } final StringBuilder aSB = new StringBuilder ( nMinLen ) ; if ( ! bLeading ) aSB . append ( sSrc ) ; for ( int i = 0 ; i < nCharsToAdd ; ++ i ) aSB . append ( cGap ) ; if ( bLeading ) aSB . append ( sSrc ) ; return aSB . toString ( ) ; }
Get the result string with at least the desired length and fill the lead or trail with the provided char
16,340
public static String getWithLeading ( final String sSrc , final int nMinLen , final char cFront ) { return _getWithLeadingOrTrailing ( sSrc , nMinLen , cFront , true ) ; }
Get a string that is filled at the beginning with the passed character until the minimum length is reached . If the input string is empty the result is a string with the provided len only consisting of the passed characters . If the input String is longer than the provided length it is returned unchanged .
16,341
public static String getWithLeading ( final int nValue , final int nMinLen , final char cFront ) { return _getWithLeadingOrTrailing ( Integer . toString ( nValue ) , nMinLen , cFront , true ) ; }
Get a string that is filled at the beginning with the passed character until the minimum length is reached . If the input String is longer than the provided length it is returned unchanged .
16,342
public static String getWithTrailing ( final String sSrc , final int nMinLen , final char cEnd ) { return _getWithLeadingOrTrailing ( sSrc , nMinLen , cEnd , false ) ; }
Get a string that is filled at the end with the passed character until the minimum length is reached . If the input string is empty the result is a string with the provided len only consisting of the passed characters . If the input String is longer than the provided length it is returned unchanged .
16,343
public static String getHexEncoded ( final String sInput , final Charset aCharset ) { ValueEnforcer . notNull ( sInput , "Input" ) ; ValueEnforcer . notNull ( aCharset , "Charset" ) ; return getHexEncoded ( sInput . getBytes ( aCharset ) ) ; }
Convert a string to a byte array and than to a hexadecimal encoded string .
16,344
public static int getLeadingCharCount ( final String s , final char c ) { int ret = 0 ; if ( s != null ) { final int nMax = s . length ( ) ; while ( ret < nMax && s . charAt ( ret ) == c ) ++ ret ; } return ret ; }
Get the number of specified chars the passed string starts with .
16,345
public static int getTrailingCharCount ( final String s , final char c ) { int ret = 0 ; if ( s != null ) { int nLast = s . length ( ) - 1 ; while ( nLast >= 0 && s . charAt ( nLast ) == c ) { ++ ret ; -- nLast ; } } return ret ; }
Get the number of specified chars the passed string ends with .
16,346
public static < ELEMENTTYPE > String getImplodedMapped ( final String sSep , final ELEMENTTYPE [ ] aElements , final Function < ? super ELEMENTTYPE , String > aMapper ) { ValueEnforcer . notNull ( sSep , "Separator" ) ; ValueEnforcer . notNull ( aMapper , "Mapper" ) ; if ( ArrayHelper . isEmpty ( aElements ) ) return "" ; return getImplodedMapped ( sSep , aElements , 0 , aElements . length , aMapper ) ; }
Get a concatenated String from all elements of the passed array separated by the specified separator string .
16,347
public static void explode ( final char cSep , final String sElements , final Consumer < ? super String > aConsumer ) { explode ( cSep , sElements , - 1 , aConsumer ) ; }
Split the provided string by the provided separator and invoke the consumer for each matched element . The number of returned items is unlimited .
16,348
public static < COLLTYPE extends Collection < String > > COLLTYPE getExploded ( final String sSep , final String sElements , final int nMaxItems , final COLLTYPE aCollection ) { explode ( sSep , sElements , nMaxItems , aCollection :: add ) ; return aCollection ; }
Take a concatenated String and return the passed Collection of all elements in the passed string using specified separator string .
16,349
public static void explode ( final String sSep , final String sElements , final Consumer < ? super String > aConsumer ) { explode ( sSep , sElements , - 1 , aConsumer ) ; }
Split the provided string by the provided separator and invoke the consumer for each matched element .
16,350
public static int getIndexOf ( final String sText , final int nFromIndex , final String sSearch ) { return sText != null && sSearch != null && ( sText . length ( ) - nFromIndex ) >= sSearch . length ( ) ? sText . indexOf ( sSearch , nFromIndex ) : STRING_NOT_FOUND ; }
Get the first index of sSearch within sText starting at index nFromIndex .
16,351
public static int getLastIndexOf ( final String sText , final String sSearch ) { return sText != null && sSearch != null && sText . length ( ) >= sSearch . length ( ) ? sText . lastIndexOf ( sSearch ) : STRING_NOT_FOUND ; }
Get the last index of sSearch within sText .
16,352
public static int getIndexOf ( final String sText , final char cSearch ) { return sText != null && sText . length ( ) >= 1 ? sText . indexOf ( cSearch ) : STRING_NOT_FOUND ; }
Get the first index of cSearch within sText .
16,353
public static int getLastIndexOf ( final String sText , final char cSearch ) { return sText != null && sText . length ( ) >= 1 ? sText . lastIndexOf ( cSearch ) : STRING_NOT_FOUND ; }
Get the last index of cSearch within sText .
16,354
public static int getIndexOfIgnoreCase ( final String sText , final int nFromIndex , final String sSearch , final Locale aSortLocale ) { return sText != null && sSearch != null && ( sText . length ( ) - nFromIndex ) >= sSearch . length ( ) ? sText . toLowerCase ( aSortLocale ) . indexOf ( sSearch . toLowerCase ( aSortLocale ) , nFromIndex ) : STRING_NOT_FOUND ; }
Get the first index of sSearch within sText ignoring case starting at index nFromIndex .
16,355
public static int getLastIndexOfIgnoreCase ( final String sText , final String sSearch , final Locale aSortLocale ) { return sText != null && sSearch != null && sText . length ( ) >= sSearch . length ( ) ? sText . toLowerCase ( aSortLocale ) . lastIndexOf ( sSearch . toLowerCase ( aSortLocale ) ) : STRING_NOT_FOUND ; }
Get the last index of sSearch within sText ignoring case .
16,356
public static int getIndexOfIgnoreCase ( final String sText , final char cSearch , final Locale aSortLocale ) { return sText != null && sText . length ( ) >= 1 ? sText . toLowerCase ( aSortLocale ) . indexOf ( Character . toLowerCase ( cSearch ) ) : STRING_NOT_FOUND ; }
Get the first index of cSearch within sText ignoring case .
16,357
public static int getLastIndexOfIgnoreCase ( final String sText , final char cSearch , final Locale aSortLocale ) { return sText != null && sText . length ( ) >= 1 ? sText . toLowerCase ( aSortLocale ) . lastIndexOf ( Character . toLowerCase ( cSearch ) ) : STRING_NOT_FOUND ; }
Get the last index of cSearch within sText ignoring case .
16,358
public static boolean contains ( final String sText , final String sSearch ) { return getIndexOf ( sText , sSearch ) != STRING_NOT_FOUND ; }
Check if sSearch is contained within sText .
16,359
public static boolean containsIgnoreCase ( final String sText , final String sSearch , final Locale aSortLocale ) { return getIndexOfIgnoreCase ( sText , sSearch , aSortLocale ) != STRING_NOT_FOUND ; }
Check if sSearch is contained within sText ignoring case .
16,360
public static boolean containsIgnoreCase ( final String sText , final char cSearch , final Locale aSortLocale ) { return getIndexOfIgnoreCase ( sText , cSearch , aSortLocale ) != STRING_NOT_FOUND ; }
Check if cSearch is contained within sText ignoring case .
16,361
public static boolean containsAny ( final char [ ] aInput , final char [ ] aSearchChars ) { ValueEnforcer . notNull ( aSearchChars , "SearchChars" ) ; if ( aInput != null ) for ( final char cIn : aInput ) if ( ArrayHelper . contains ( aSearchChars , cIn ) ) return true ; return false ; }
Check if any of the passed searched characters is contained in the input char array .
16,362
public static boolean containsAny ( final String sInput , final char [ ] aSearchChars ) { return sInput != null && containsAny ( sInput . toCharArray ( ) , aSearchChars ) ; }
Check if any of the passed searched characters in contained in the input string .
16,363
public static int getOccurrenceCount ( final String sText , final String sSearch ) { int ret = 0 ; final int nTextLength = getLength ( sText ) ; final int nSearchLength = getLength ( sSearch ) ; if ( nSearchLength > 0 && nTextLength >= nSearchLength ) { int nLastIndex = 0 ; int nIndex ; do { nIndex = getIndexOf ( sText , nLastIndex , sSearch ) ; if ( nIndex != STRING_NOT_FOUND ) { ++ ret ; nLastIndex = nIndex + nSearchLength ; } } while ( nIndex != STRING_NOT_FOUND ) ; } return ret ; }
Count the number of occurrences of sSearch within sText .
16,364
public static int getOccurrenceCountIgnoreCase ( final String sText , final String sSearch , final Locale aSortLocale ) { return sText != null && sSearch != null ? getOccurrenceCount ( sText . toLowerCase ( aSortLocale ) , sSearch . toLowerCase ( aSortLocale ) ) : 0 ; }
Count the number of occurrences of sSearch within sText ignoring case .
16,365
public static int getOccurrenceCount ( final String sText , final char cSearch ) { int ret = 0 ; final int nTextLength = getLength ( sText ) ; if ( nTextLength >= 1 ) { int nLastIndex = 0 ; int nIndex ; do { nIndex = getIndexOf ( sText , nLastIndex , cSearch ) ; if ( nIndex != STRING_NOT_FOUND ) { ++ ret ; nLastIndex = nIndex + 1 ; } } while ( nIndex != STRING_NOT_FOUND ) ; } return ret ; }
Count the number of occurrences of cSearch within sText .
16,366
public static int getOccurrenceCountIgnoreCase ( final String sText , final char cSearch , final Locale aSortLocale ) { return sText != null ? getOccurrenceCount ( sText . toLowerCase ( aSortLocale ) , Character . toLowerCase ( cSearch ) ) : 0 ; }
Count the number of occurrences of cSearch within sText ignoring case .
16,367
public static String trimLeadingWhitespaces ( final String s ) { final int n = getLeadingWhitespaceCount ( s ) ; return n == 0 ? s : s . substring ( n , s . length ( ) ) ; }
Remove any leading whitespaces from the passed string .
16,368
public static String trimTrailingWhitespaces ( final String s ) { final int n = getTrailingWhitespaceCount ( s ) ; return n == 0 ? s : s . substring ( 0 , s . length ( ) - n ) ; }
Remove any trailing whitespaces from the passed string .
16,369
public static char getFirstChar ( final CharSequence aCS ) { return hasText ( aCS ) ? aCS . charAt ( 0 ) : CGlobal . ILLEGAL_CHAR ; }
Get the first character of the passed character sequence
16,370
public static char getLastChar ( final CharSequence aCS ) { final int nLength = getLength ( aCS ) ; return nLength > 0 ? aCS . charAt ( nLength - 1 ) : CGlobal . ILLEGAL_CHAR ; }
Get the last character of the passed character sequence
16,371
public static String removeAll ( final String sInputString , final String sRemoveString ) { if ( hasNoText ( sInputString ) ) return sInputString ; final int nRemoveLength = getLength ( sRemoveString ) ; if ( nRemoveLength == 0 ) { return sInputString ; } if ( nRemoveLength == 1 ) { return removeAll ( sInputString , sRemoveString . charAt ( 0 ) ) ; } int nIndex = sInputString . indexOf ( sRemoveString , 0 ) ; if ( nIndex == STRING_NOT_FOUND ) return sInputString ; final StringBuilder ret = new StringBuilder ( sInputString . length ( ) ) ; int nOldIndex = 0 ; do { ret . append ( sInputString , nOldIndex , nIndex ) ; nOldIndex = nIndex + nRemoveLength ; nIndex = sInputString . indexOf ( sRemoveString , nOldIndex ) ; } while ( nIndex != STRING_NOT_FOUND ) ; ret . append ( sInputString , nOldIndex , sInputString . length ( ) ) ; return ret . toString ( ) ; }
Remove all occurrences of the passed character from the specified input string
16,372
public static String getWithoutLeadingChars ( final String sStr , final int nCount ) { ValueEnforcer . isGE0 ( nCount , "Count" ) ; if ( nCount == 0 ) return sStr ; return getLength ( sStr ) <= nCount ? "" : sStr . substring ( nCount ) ; }
Get the passed string without the specified number of leading chars .
16,373
public static String getWithoutTrailingChars ( final String sStr , final int nCount ) { ValueEnforcer . isGE0 ( nCount , "Count" ) ; if ( nCount == 0 ) return sStr ; final int nLength = getLength ( sStr ) ; return nLength <= nCount ? "" : sStr . substring ( 0 , nLength - nCount ) ; }
Get the passed string without the specified number of trailing chars .
16,374
public static String removeMultiple ( final String sInputString , final char [ ] aRemoveChars ) { ValueEnforcer . notNull ( aRemoveChars , "RemoveChars" ) ; if ( hasNoText ( sInputString ) ) return "" ; if ( aRemoveChars . length == 0 ) return sInputString ; final StringBuilder aSB = new StringBuilder ( sInputString . length ( ) ) ; iterateChars ( sInputString , cInput -> { if ( ! ArrayHelper . contains ( aRemoveChars , cInput ) ) aSB . append ( cInput ) ; } ) ; return aSB . toString ( ) ; }
Optimized remove method that removes a set of characters from an input string!
16,375
public static void iterateChars ( final String sInputString , final ICharConsumer aConsumer ) { ValueEnforcer . notNull ( aConsumer , "Consumer" ) ; if ( sInputString != null ) { final char [ ] aInput = sInputString . toCharArray ( ) ; for ( final char cInput : aInput ) aConsumer . accept ( cInput ) ; } }
Iterate all characters and pass them to the provided consumer .
16,376
public void registerProtocol ( final IURLProtocol aProtocol ) { ValueEnforcer . notNull ( aProtocol , "Protocol" ) ; final String sProtocol = aProtocol . getProtocol ( ) ; m_aRWLock . writeLocked ( ( ) -> { if ( m_aProtocols . containsKey ( sProtocol ) ) throw new IllegalArgumentException ( "Another handler for protocol '" + sProtocol + "' is already registered!" ) ; m_aProtocols . put ( sProtocol , aProtocol ) ; } ) ; if ( LOGGER . isDebugEnabled ( ) ) LOGGER . debug ( "Registered new custom URL protocol: " + aProtocol ) ; }
Registers a new protocol
16,377
public static boolean isKnownEOFException ( final Class < ? > aClass ) { if ( aClass == null ) return false ; final String sClass = aClass . getName ( ) ; return sClass . equals ( "java.io.EOFException" ) || sClass . equals ( "org.mortbay.jetty.EofException" ) || sClass . equals ( "org.eclipse.jetty.io.EofException" ) || sClass . equals ( "org.apache.catalina.connector.ClientAbortException" ) ; }
Check if the passed class is a known EOF exception class .
16,378
public static ESuccess closeWithoutFlush ( final AutoCloseable aCloseable ) { if ( aCloseable != null ) { try { aCloseable . close ( ) ; return ESuccess . SUCCESS ; } catch ( final Exception ex ) { if ( ! isKnownEOFException ( ex ) ) LOGGER . error ( "Failed to close object " + aCloseable . getClass ( ) . getName ( ) , ex instanceof IMockException ? null : ex ) ; } } return ESuccess . FAILURE ; }
Close the passed object without trying to call flush on it .
16,379
public static ESuccess copyInputStreamToOutputStreamAndCloseOS ( final InputStream aIS , final OutputStream aOS ) { try { return copyInputStreamToOutputStream ( aIS , aOS , new byte [ DEFAULT_BUFSIZE ] , ( MutableLong ) null , ( Long ) null ) ; } finally { close ( aOS ) ; } }
Pass the content of the given input stream to the given output stream . Both the input stream and the output stream are automatically closed .
16,380
public static int getAvailable ( final InputStream aIS ) { if ( aIS != null ) try { return aIS . available ( ) ; } catch ( final IOException ex ) { } return 0 ; }
Get the number of available bytes in the passed input stream .
16,381
public static ESuccess copyReaderToWriterWithLimitAndCloseWriter ( final Reader aReader , final Writer aWriter , final long nLimit ) { try { return copyReaderToWriter ( aReader , aWriter , new char [ DEFAULT_BUFSIZE ] , ( MutableLong ) null , Long . valueOf ( nLimit ) ) ; } finally { close ( aWriter ) ; } }
Pass the content of the given reader to the given writer . The reader and the writer are automatically closed!
16,382
public static char [ ] getAllCharacters ( final Reader aReader ) { if ( aReader == null ) return null ; return getCopy ( aReader ) . getAsCharArray ( ) ; }
Read all characters from the passed reader into a char array .
16,383
public static String getAllCharactersAsString ( final Reader aReader ) { if ( aReader == null ) return null ; return getCopy ( aReader ) . getAsString ( ) ; }
Read all characters from the passed reader into a String .
16,384
public static void readStreamLines ( final InputStream aIS , final Charset aCharset , final Consumer < ? super String > aLineCallback ) { if ( aIS != null ) readStreamLines ( aIS , aCharset , 0 , CGlobal . ILLEGAL_UINT , aLineCallback ) ; }
Read the complete content of the passed stream and pass each line separately to the passed callback .
16,385
public static void readStreamLines ( final InputStream aIS , final Charset aCharset , final int nLinesToSkip , final int nLinesToRead , final Consumer < ? super String > aLineCallback ) { try { ValueEnforcer . notNull ( aCharset , "Charset" ) ; ValueEnforcer . isGE0 ( nLinesToSkip , "LinesToSkip" ) ; final boolean bReadAllLines = nLinesToRead == CGlobal . ILLEGAL_UINT ; ValueEnforcer . isTrue ( bReadAllLines || nLinesToRead >= 0 , ( ) -> "Line count may not be that negative: " + nLinesToRead ) ; ValueEnforcer . notNull ( aLineCallback , "LineCallback" ) ; if ( aIS != null ) if ( bReadAllLines || nLinesToRead > 0 ) { try ( final NonBlockingBufferedReader aBR = new NonBlockingBufferedReader ( createReader ( aIS , aCharset ) ) ) { _readFromReader ( nLinesToSkip , nLinesToRead , aLineCallback , bReadAllLines , aBR ) ; } catch ( final IOException ex ) { LOGGER . error ( "Failed to read from input stream" , ex instanceof IMockException ? null : ex ) ; } } } finally { close ( aIS ) ; } }
Read the content of the passed stream line by line and invoking a callback on all matching lines .
16,386
public static void skipFully ( final InputStream aIS , final long nBytesToSkip ) throws IOException { ValueEnforcer . notNull ( aIS , "InputStream" ) ; ValueEnforcer . isGE0 ( nBytesToSkip , "BytesToSkip" ) ; long nRemaining = nBytesToSkip ; while ( nRemaining > 0 ) { final long nSkipped = aIS . skip ( nRemaining ) ; if ( nSkipped == 0 ) { if ( aIS . read ( ) == - 1 ) { throw new EOFException ( "Failed to skip a total of " + nBytesToSkip + " bytes on input stream. Only skipped " + ( nBytesToSkip - nRemaining ) + " bytes so far!" ) ; } nRemaining -- ; } else { nRemaining -= nSkipped ; } } }
Fully skip the passed amounts in the input stream . Only forward skipping is possible!
16,387
private ESuccess _perform ( final List < DATATYPE > aObjectsToPerform ) { if ( ! aObjectsToPerform . isEmpty ( ) ) { try { m_aPerformer . runAsync ( aObjectsToPerform ) ; } catch ( final Exception ex ) { LOGGER . error ( "Failed to perform actions on " + aObjectsToPerform . size ( ) + " objects with performer " + m_aPerformer + " - objects are lost!" , ex ) ; return ESuccess . FAILURE ; } aObjectsToPerform . clear ( ) ; } return ESuccess . SUCCESS ; }
Internal method to invoke the performed for the passed list of objects .
16,388
private boolean _anyCharactersAreTheSame ( ) { return _isSameCharacter ( m_cSeparatorChar , m_cQuoteChar ) || _isSameCharacter ( m_cSeparatorChar , m_cEscapeChar ) || _isSameCharacter ( m_cQuoteChar , m_cEscapeChar ) ; }
checks to see if any two of the three characters are the same . This is because in openCSV the separator quote and escape characters must the different .
16,389
public ICommonsList < String > parseLineMulti ( final String sNextLine ) throws IOException { return _parseLine ( sNextLine , true ) ; }
Parses an incoming String and returns an array of elements . This method is used when the data spans multiple lines .
16,390
public ICommonsList < String > parseLine ( final String sNextLine ) throws IOException { return _parseLine ( sNextLine , false ) ; }
Parses an incoming String and returns an array of elements . This method is used when all data is contained in a single line .
16,391
public static String getNodeAsString ( final Node aNode , final IXMLWriterSettings aSettings ) { try ( final NonBlockingStringWriter aWriter = new NonBlockingStringWriter ( 50 * CGlobal . BYTES_PER_KILOBYTE ) ) { if ( writeToWriter ( aNode , aWriter , aSettings ) . isSuccess ( ) ) { s_aSizeHdl . addSize ( aWriter . size ( ) ) ; return aWriter . getAsString ( ) ; } } catch ( final Exception ex ) { if ( LOGGER . isErrorEnabled ( ) ) LOGGER . error ( "Error serializing DOM node with settings " + aSettings . toString ( ) , ex ) ; } return null ; }
Convert the passed DOM node to an XML string using the provided XML writer settings .
16,392
public static MockSupplier createConstant ( final Object aConstant ) { ValueEnforcer . notNull ( aConstant , "Constant" ) ; return new MockSupplier ( aConstant . getClass ( ) , null , aParam -> aConstant ) ; }
Create a mock supplier for a constant value .
16,393
public static < T > MockSupplier createNoParams ( final Class < T > aDstClass , final Supplier < T > aSupplier ) { ValueEnforcer . notNull ( aDstClass , "DstClass" ) ; ValueEnforcer . notNull ( aSupplier , "Supplier" ) ; return new MockSupplier ( aDstClass , null , aParam -> aSupplier . get ( ) ) ; }
Create a mock supplier for a factory without parameters .
16,394
public static < T > MockSupplier create ( final Class < T > aDstClass , final Param [ ] aParams , final Function < IGetterDirectTrait [ ] , T > aSupplier ) { ValueEnforcer . notNull ( aDstClass , "DstClass" ) ; ValueEnforcer . notNull ( aParams , "Params" ) ; ValueEnforcer . notNull ( aSupplier , "Supplier" ) ; return new MockSupplier ( aDstClass , aParams , aSupplier ) ; }
Create a mock supplier with parameters .
16,395
private char [ ] _peekChars ( final int nPos ) { if ( nPos < 0 || nPos >= limit ( ) ) return null ; final char c1 = get ( nPos ) ; if ( Character . isHighSurrogate ( c1 ) && nPos < limit ( ) ) { final char c2 = get ( nPos + 1 ) ; if ( Character . isLowSurrogate ( c2 ) ) return new char [ ] { c1 , c2 } ; throw new InvalidCharacterException ( c2 ) ; } if ( Character . isLowSurrogate ( c1 ) && nPos > 1 ) { final char c2 = get ( nPos - 1 ) ; if ( Character . isHighSurrogate ( c2 ) ) return new char [ ] { c2 , c1 } ; throw new InvalidCharacterException ( c2 ) ; } return new char [ ] { c1 } ; }
Peek the specified chars in the iterator . If the codepoint is not supplemental the char array will have a single member . If the codepoint is supplemental the char array will have two members representing the high and low surrogate chars
16,396
public static XPathExpression createNewXPathExpression ( final XPath aXPath , final String sXPath ) { ValueEnforcer . notNull ( aXPath , "XPath" ) ; ValueEnforcer . notNull ( sXPath , "XPathExpression" ) ; try { return aXPath . compile ( sXPath ) ; } catch ( final XPathExpressionException ex ) { throw new IllegalArgumentException ( "Failed to compile XPath expression '" + sXPath + "'" , ex ) ; } }
Create a new XPath expression for evaluation .
16,397
public static boolean isInvalidXMLNameStartChar ( final EXMLSerializeVersion eXMLVersion , final int c ) { switch ( eXMLVersion ) { case XML_10 : return INVALID_NAME_START_CHAR_XML10 . get ( c ) ; case XML_11 : return INVALID_NAME_START_CHAR_XML11 . get ( c ) ; case HTML : return INVALID_CHAR_HTML . get ( c ) ; default : throw new IllegalArgumentException ( "Unsupported XML version " + eXMLVersion + "!" ) ; } }
Check if the passed character is invalid for an element or attribute name on the first position
16,398
public static boolean isInvalidXMLNameChar ( final EXMLSerializeVersion eXMLVersion , final int c ) { switch ( eXMLVersion ) { case XML_10 : return INVALID_NAME_CHAR_XML10 . get ( c ) ; case XML_11 : return INVALID_NAME_CHAR_XML11 . get ( c ) ; case HTML : return INVALID_CHAR_HTML . get ( c ) ; default : throw new IllegalArgumentException ( "Unsupported XML version " + eXMLVersion + "!" ) ; } }
Check if the passed character is invalid for an element or attribute name after the first position
16,399
public static boolean isInvalidXMLTextChar ( final EXMLSerializeVersion eXMLVersion , final int c ) { switch ( eXMLVersion ) { case XML_10 : return INVALID_VALUE_CHAR_XML10 . get ( c ) ; case XML_11 : return INVALID_TEXT_VALUE_CHAR_XML11 . get ( c ) ; case HTML : return INVALID_CHAR_HTML . get ( c ) ; default : throw new IllegalArgumentException ( "Unsupported XML version " + eXMLVersion + "!" ) ; } }
Check if the passed character is invalid for a text node .