idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
16,300
public static void setSunCharacterEscapeHandler ( @ Nonnull final Marshaller aMarshaller , @ Nonnull 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
71
26
16,301
public static void setSunXMLHeaders ( @ Nonnull final Marshaller aMarshaller , @ Nonnull final String sXMLHeaders ) { final String sPropertyName = SUN_XML_HEADERS ; _setProperty ( aMarshaller , sPropertyName , sXMLHeaders ) ; }
Set the Sun specific XML header string .
68
8
16,302
public static boolean isSunJAXB2Marshaller ( @ Nullable 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 .
79
34
16,303
@ Nonnull public static DateTimeFormatter getWithLocale ( @ Nonnull final DateTimeFormatter aFormatter , @ Nullable 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 .
75
14
16,304
@ Nonnull public static DateTimeFormatter getFormatterDate ( @ Nonnull final FormatStyle eStyle , @ Nullable final Locale aDisplayLocale , @ Nonnull final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_DATE , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the date formatter for the passed locale .
84
10
16,305
@ Nonnull public static DateTimeFormatter getFormatterTime ( @ Nonnull final FormatStyle eStyle , @ Nullable final Locale aDisplayLocale , @ Nonnull final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_TIME , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the time formatter for the passed locale .
83
10
16,306
@ Nonnull public static DateTimeFormatter getFormatterDateTime ( @ Nonnull final FormatStyle eStyle , @ Nullable final Locale aDisplayLocale , @ Nonnull final EDTFormatterMode eMode ) { return _getFormatter ( new CacheKey ( EDTType . LOCAL_DATE_TIME , aDisplayLocale , eStyle , eMode ) , aDisplayLocale ) ; }
Get the date time formatter for the passed locale .
87
11
16,307
public static final void writeEncodeQuotedPrintableByte ( final int b , @ Nonnull 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 .
110
11
16,308
@ CheckForSigned private int _getReadIndex ( final int key ) { int idx = MapHelper . phiMix ( key ) & m_nMask ; if ( m_aKeys [ idx ] == key ) { // we check FREE prior to this call return idx ; } if ( m_aKeys [ idx ] == FREE_KEY ) { // end of chain already 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 .
161
7
16,309
@ Nonnull public static String getLocaleDisplayName ( @ Nullable final Locale aLocale , @ Nonnull 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 .
159
15
16,310
@ Nonnull @ ReturnsMutableCopy public static ICommonsMap < Locale , String > getAllLocaleDisplayNames ( @ Nonnull 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
110
9
16,311
@ Nonnull public static Locale getLocaleFromString ( @ Nullable final String sLocaleAsString ) { if ( StringHelper . hasNoText ( sLocaleAsString ) ) { // not specified => getDefault return SystemHelper . getSystemLocale ( ) ; } String sLanguage ; String sCountry ; String sVariant ; int i1 = sLocaleAsString . indexOf ( LOCALE_SEPARATOR ) ; if ( i1 < 0 ) { // No separator present -> use as is sLanguage = sLocaleAsString ; sCountry = "" ; sVariant = "" ; } else { // Language found sLanguage = sLocaleAsString . substring ( 0 , i1 ) ; ++ i1 ; // Find next separator final int i2 = sLocaleAsString . indexOf ( LOCALE_SEPARATOR , i1 ) ; if ( i2 < 0 ) { // No other separator -> country is the rest sCountry = sLocaleAsString . substring ( i1 ) ; sVariant = "" ; } else { // We have country and variant sCountry = sLocaleAsString . substring ( i1 , i2 ) ; sVariant = sLocaleAsString . substring ( i2 + 1 ) ; } } // Unify elements 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 = "" ; // And now resolve using the locale cache 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 .
441
43
16,312
@ Nonnull private static String _getWithLeadingOrTrailing ( @ Nullable final String sSrc , @ Nonnegative final int nMinLen , final char cGap , final boolean bLeading ) { if ( nMinLen <= 0 ) { // Requested length is too short - return as is return getNotNull ( sSrc , "" ) ; } final int nSrcLen = getLength ( sSrc ) ; if ( nSrcLen == 0 ) { // Input string is empty return getRepeated ( cGap , nMinLen ) ; } final int nCharsToAdd = nMinLen - nSrcLen ; if ( nCharsToAdd <= 0 ) { // Input string is already longer than requested minimum length 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
254
20
16,313
@ Nonnull public static String getWithLeading ( @ Nullable final String sSrc , @ Nonnegative 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 .
60
57
16,314
@ Nonnull public static String getWithLeading ( final int nValue , @ Nonnegative 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 .
61
35
16,315
@ Nonnull public static String getWithTrailing ( @ Nullable final String sSrc , @ Nonnegative 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 .
60
57
16,316
@ Nonnull public static String getHexEncoded ( @ Nonnull final String sInput , @ Nonnull 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 .
88
19
16,317
@ Nonnegative public static int getLeadingCharCount ( @ Nullable 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 .
72
12
16,318
@ Nonnegative public static int getTrailingCharCount ( @ Nullable 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 .
80
12
16,319
@ Nonnull public static < ELEMENTTYPE > String getImplodedMapped ( @ Nonnull final String sSep , @ Nullable final ELEMENTTYPE [ ] aElements , @ Nonnull 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 .
135
21
16,320
public static void explode ( final char cSep , @ Nullable final String sElements , @ Nonnull 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 .
50
26
16,321
@ Nonnull @ CodingStyleguideUnaware public static < COLLTYPE extends Collection < String > > COLLTYPE getExploded ( @ Nonnull final String sSep , @ Nullable final String sElements , final int nMaxItems , @ Nonnull 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 .
89
24
16,322
public static void explode ( @ Nonnull final String sSep , @ Nullable final String sElements , @ Nonnull 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 .
53
18
16,323
public static int getIndexOf ( @ Nullable final String sText , @ Nonnegative final int nFromIndex , @ Nullable 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 .
87
17
16,324
public static int getLastIndexOf ( @ Nullable final String sText , @ Nullable 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 .
70
11
16,325
public static int getIndexOf ( @ Nullable 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 .
55
11
16,326
public static int getLastIndexOf ( @ Nullable 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 .
57
11
16,327
public static int getIndexOfIgnoreCase ( @ Nullable final String sText , @ Nonnegative final int nFromIndex , @ Nullable final String sSearch , @ Nonnull 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 .
121
19
16,328
public static int getLastIndexOfIgnoreCase ( @ Nullable final String sText , @ Nullable final String sSearch , @ Nonnull 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 .
104
13
16,329
public static int getIndexOfIgnoreCase ( @ Nullable final String sText , final char cSearch , @ Nonnull 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 .
86
13
16,330
public static int getLastIndexOfIgnoreCase ( @ Nullable final String sText , final char cSearch , @ Nonnull 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 .
88
13
16,331
public static boolean contains ( @ Nullable final String sText , @ Nullable final String sSearch ) { return getIndexOf ( sText , sSearch ) != STRING_NOT_FOUND ; }
Check if sSearch is contained within sText .
43
10
16,332
public static boolean containsIgnoreCase ( @ Nullable final String sText , @ Nullable final String sSearch , @ Nonnull final Locale aSortLocale ) { return getIndexOfIgnoreCase ( sText , sSearch , aSortLocale ) != STRING_NOT_FOUND ; }
Check if sSearch is contained within sText ignoring case .
65
12
16,333
public static boolean containsIgnoreCase ( @ Nullable final String sText , final char cSearch , @ Nonnull final Locale aSortLocale ) { return getIndexOfIgnoreCase ( sText , cSearch , aSortLocale ) != STRING_NOT_FOUND ; }
Check if cSearch is contained within sText ignoring case .
62
12
16,334
public static boolean containsAny ( @ Nullable final char [ ] aInput , @ Nonnull 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 .
88
16
16,335
public static boolean containsAny ( @ Nullable final String sInput , @ Nonnull final char [ ] aSearchChars ) { return sInput != null && containsAny ( sInput . toCharArray ( ) , aSearchChars ) ; }
Check if any of the passed searched characters in contained in the input string .
52
15
16,336
@ Nonnegative public static int getOccurrenceCount ( @ Nullable final String sText , @ Nullable 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 { // Start searching from the last result nIndex = getIndexOf ( sText , nLastIndex , sSearch ) ; if ( nIndex != STRING_NOT_FOUND ) { // Match found ++ ret ; // Identify the next starting position (relative index + number of // search strings) nLastIndex = nIndex + nSearchLength ; } } while ( nIndex != STRING_NOT_FOUND ) ; } return ret ; }
Count the number of occurrences of sSearch within sText .
183
12
16,337
@ Nonnegative public static int getOccurrenceCountIgnoreCase ( @ Nullable final String sText , @ Nullable final String sSearch , @ Nonnull 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 .
88
14
16,338
@ Nonnegative public static int getOccurrenceCount ( @ Nullable final String sText , final char cSearch ) { int ret = 0 ; final int nTextLength = getLength ( sText ) ; if ( nTextLength >= 1 ) { int nLastIndex = 0 ; int nIndex ; do { // Start searching from the last result nIndex = getIndexOf ( sText , nLastIndex , cSearch ) ; if ( nIndex != STRING_NOT_FOUND ) { // Match found ++ ret ; // Identify the next starting position (relative index + number of // search strings) nLastIndex = nIndex + 1 ; } } while ( nIndex != STRING_NOT_FOUND ) ; } return ret ; }
Count the number of occurrences of cSearch within sText .
157
12
16,339
@ Nonnegative public static int getOccurrenceCountIgnoreCase ( @ Nullable final String sText , final char cSearch , @ Nonnull 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 .
77
14
16,340
@ Nullable @ CheckReturnValue public static String trimLeadingWhitespaces ( @ Nullable 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 .
62
10
16,341
@ Nullable @ CheckReturnValue public static String trimTrailingWhitespaces ( @ Nullable 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 .
64
10
16,342
public static char getFirstChar ( @ Nullable final CharSequence aCS ) { return hasText ( aCS ) ? aCS . charAt ( 0 ) : CGlobal . ILLEGAL_CHAR ; }
Get the first character of the passed character sequence
46
9
16,343
public static char getLastChar ( @ Nullable 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
59
9
16,344
@ Nullable public static String removeAll ( @ Nullable final String sInputString , @ Nullable final String sRemoveString ) { // Is input string empty? if ( hasNoText ( sInputString ) ) return sInputString ; final int nRemoveLength = getLength ( sRemoveString ) ; if ( nRemoveLength == 0 ) { // Nothing to be removed return sInputString ; } if ( nRemoveLength == 1 ) { // Shortcut to char version return removeAll ( sInputString , sRemoveString . charAt ( 0 ) ) ; } // Does the string occur anywhere? int nIndex = sInputString . indexOf ( sRemoveString , 0 ) ; if ( nIndex == STRING_NOT_FOUND ) return sInputString ; // build output buffer 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
284
12
16,345
@ Nonnull public static String getWithoutLeadingChars ( @ Nullable final String sStr , @ Nonnegative 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 .
81
12
16,346
@ Nonnull public static String getWithoutTrailingChars ( @ Nullable final String sStr , @ Nonnegative 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 .
94
12
16,347
@ Nonnull public static String removeMultiple ( @ Nullable final String sInputString , @ Nonnull final char [ ] aRemoveChars ) { ValueEnforcer . notNull ( aRemoveChars , "RemoveChars" ) ; // Any input text? if ( hasNoText ( sInputString ) ) return "" ; // Anything to remove? 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!
161
16
16,348
public static void iterateChars ( @ Nullable final String sInputString , @ Nonnull 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 .
90
12
16,349
public void registerProtocol ( @ Nonnull 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
161
5
16,350
public static boolean isKnownEOFException ( @ Nullable 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 .
128
13
16,351
@ Nonnull public static ESuccess closeWithoutFlush ( @ Nullable @ WillClose final AutoCloseable aCloseable ) { if ( aCloseable != null ) { try { // close stream 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 .
127
12
16,352
@ Nonnull public static ESuccess copyInputStreamToOutputStreamAndCloseOS ( @ WillClose @ Nullable final InputStream aIS , @ WillClose @ Nullable 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 .
93
26
16,353
public static int getAvailable ( @ Nullable final InputStream aIS ) { if ( aIS != null ) try { return aIS . available ( ) ; } catch ( final IOException ex ) { // Fall through } return 0 ; }
Get the number of available bytes in the passed input stream .
50
12
16,354
@ Nonnull public static ESuccess copyReaderToWriterWithLimitAndCloseWriter ( @ Nullable @ WillClose final Reader aReader , @ Nullable @ WillClose final Writer aWriter , @ Nonnegative 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!
101
21
16,355
@ Nullable public static char [ ] getAllCharacters ( @ Nullable @ WillClose final Reader aReader ) { if ( aReader == null ) return null ; return getCopy ( aReader ) . getAsCharArray ( ) ; }
Read all characters from the passed reader into a char array .
50
12
16,356
@ Nullable public static String getAllCharactersAsString ( @ Nullable @ WillClose final Reader aReader ) { if ( aReader == null ) return null ; return getCopy ( aReader ) . getAsString ( ) ; }
Read all characters from the passed reader into a String .
49
11
16,357
public static void readStreamLines ( @ WillClose @ Nullable final InputStream aIS , @ Nonnull @ Nonempty final Charset aCharset , @ Nonnull 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 .
89
18
16,358
public static void readStreamLines ( @ WillClose @ Nullable final InputStream aIS , @ Nonnull @ Nonempty final Charset aCharset , @ Nonnegative final int nLinesToSkip , final int nLinesToRead , @ Nonnull 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" ) ; // Start the action only if there is something to read if ( aIS != null ) if ( bReadAllLines || nLinesToRead > 0 ) { try ( final NonBlockingBufferedReader aBR = new NonBlockingBufferedReader ( createReader ( aIS , aCharset ) ) ) { // read with the passed charset _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 input stream in case something went wrong with the buffered // reader. close ( aIS ) ; } }
Read the content of the passed stream line by line and invoking a callback on all matching lines .
368
19
16,359
public static void skipFully ( @ Nonnull final InputStream aIS , @ Nonnegative final long nBytesToSkip ) throws IOException { ValueEnforcer . notNull ( aIS , "InputStream" ) ; ValueEnforcer . isGE0 ( nBytesToSkip , "BytesToSkip" ) ; long nRemaining = nBytesToSkip ; while ( nRemaining > 0 ) { // May only return a partial skip final long nSkipped = aIS . skip ( nRemaining ) ; if ( nSkipped == 0 ) { // Check if we're at the end of the file or not // -> blocking read! 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 { // Skipped at least one char nRemaining -= nSkipped ; } } }
Fully skip the passed amounts in the input stream . Only forward skipping is possible!
224
17
16,360
@ Nonnull private ESuccess _perform ( @ Nonnull final List < DATATYPE > aObjectsToPerform ) { if ( ! aObjectsToPerform . isEmpty ( ) ) { try { // Perform the action on the objects, regardless of whether a // "stop queue message" was received or not 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 ; } // clear perform-list anyway aObjectsToPerform . clear ( ) ; } return ESuccess . SUCCESS ; }
Internal method to invoke the performed for the passed list of objects .
178
13
16,361
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 .
73
32
16,362
@ Nullable public ICommonsList < String > parseLineMulti ( @ Nullable 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 .
41
24
16,363
@ Nullable public ICommonsList < String > parseLine ( @ Nullable 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 .
40
27
16,364
@ Nullable public static String getNodeAsString ( @ Nonnull final Node aNode , @ Nonnull final IXMLWriterSettings aSettings ) { // start serializing 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 .
173
17
16,365
@ Nonnull public static MockSupplier createConstant ( @ Nonnull final Object aConstant ) { ValueEnforcer . notNull ( aConstant , "Constant" ) ; return new MockSupplier ( aConstant . getClass ( ) , null , aParam -> aConstant ) ; }
Create a mock supplier for a constant value .
65
9
16,366
@ Nonnull public static < T > MockSupplier createNoParams ( @ Nonnull final Class < T > aDstClass , @ Nonnull 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 .
105
10
16,367
@ Nonnull public static < T > MockSupplier create ( @ Nonnull final Class < T > aDstClass , @ Nonnull final Param [ ] aParams , @ Nonnull 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 .
133
7
16,368
@ Nullable private char [ ] _peekChars ( @ Nonnegative 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
205
47
16,369
@ Nonnull public static XPathExpression createNewXPathExpression ( @ Nonnull final XPath aXPath , @ Nonnull @ Nonempty 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 .
131
9
16,370
public static boolean isInvalidXMLNameStartChar ( @ Nonnull 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
134
17
16,371
public static boolean isInvalidXMLNameChar ( @ Nonnull 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
127
17
16,372
public static boolean isInvalidXMLTextChar ( @ Nonnull 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 .
129
12
16,373
public static boolean isInvalidXMLCDATAChar ( @ Nonnull final EXMLSerializeVersion eXMLVersion , final int c ) { switch ( eXMLVersion ) { case XML_10 : return INVALID_VALUE_CHAR_XML10 . get ( c ) ; case XML_11 : return INVALID_CDATA_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 CDATA node .
130
13
16,374
public static boolean isInvalidXMLAttributeValueChar ( @ Nonnull final EXMLSerializeVersion eXMLVersion , final int c ) { switch ( eXMLVersion ) { case XML_10 : return INVALID_VALUE_CHAR_XML10 . get ( c ) ; case XML_11 : return INVALID_ATTR_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 attribute value node .
131
13
16,375
private void _fill ( ) throws IOException { byte [ ] buffer = _getBufIfOpen ( ) ; if ( m_nMarkPos < 0 ) m_nPos = 0 ; /* no mark: throw away the buffer */ else if ( m_nPos >= buffer . length ) /* no room left in buffer */ if ( m_nMarkPos > 0 ) { /* can throw away early part of the buffer */ final int sz = m_nPos - m_nMarkPos ; System . arraycopy ( buffer , m_nMarkPos , buffer , 0 , sz ) ; m_nPos = sz ; m_nMarkPos = 0 ; } else if ( buffer . length >= m_nMarkLimit ) { /* buffer got too big, invalidate mark */ m_nMarkPos = - 1 ; /* drop buffer contents */ m_nPos = 0 ; } else { /* grow buffer */ int nsz = m_nPos * 2 ; if ( nsz > m_nMarkLimit ) nsz = m_nMarkLimit ; final byte [ ] nbuf = new byte [ nsz ] ; System . arraycopy ( buffer , 0 , nbuf , 0 , m_nPos ) ; if ( ! s_aBufUpdater . compareAndSet ( this , buffer , nbuf ) ) { // Can't replace buf if there was an async close. // Note: This would need to be changed if fill() // is ever made accessible to multiple threads. // But for now, the only way CAS can fail is via close. // assert buf == null; throw new IOException ( "Stream closed" ) ; } buffer = nbuf ; } m_nCount = m_nPos ; // Potentially blocking read final int n = _getInIfOpen ( ) . read ( buffer , m_nPos , buffer . length - m_nPos ) ; if ( n > 0 ) m_nCount = n + m_nPos ; }
Fills the buffer with more data taking into account shuffling and other tricks for dealing with marks . Assumes that it is being called by a method . This method also assumes that all data has already been read in hence pos > count .
423
48
16,376
@ Nonnull public static String getStackAsString ( @ Nullable final Throwable t , final boolean bOmitCommonStackTraceElements ) { if ( t == null ) return "" ; // convert call stack to string final StringBuilder aCallStack = _getRecursiveStackAsStringBuilder ( t , null , null , 1 , bOmitCommonStackTraceElements ) ; // avoid having a separator at the end -> remove the last char if ( StringHelper . getLastChar ( aCallStack ) == STACKELEMENT_LINESEP ) aCallStack . deleteCharAt ( aCallStack . length ( ) - 1 ) ; // no changes return aCallStack . toString ( ) ; }
Get the stack trace of a throwable as string .
153
11
16,377
protected final void handlePutNamespaceContextPrefixInRoot ( @ Nonnull final Map < QName , String > aAttrMap ) { if ( m_aSettings . isEmitNamespaces ( ) && m_aNSStack . size ( ) == 1 && m_aSettings . isPutNamespaceContextPrefixesInRoot ( ) ) { // The only place where the namespace context prefixes are added to the // root element for ( final Map . Entry < String , String > aEntry : m_aRootNSMap . entrySet ( ) ) { aAttrMap . put ( XMLHelper . getXMLNSAttrQName ( aEntry . getKey ( ) ) , aEntry . getValue ( ) ) ; m_aNSStack . addNamespaceMapping ( aEntry . getKey ( ) , aEntry . getValue ( ) ) ; } } }
This method handles the case if all namespace context entries should be emitted on the root element .
189
18
16,378
public int compareTo ( @ Nonnull final VersionRange rhs ) { int i = m_aFloorVersion . compareTo ( rhs . m_aFloorVersion ) ; if ( i == 0 ) { if ( m_bIncludeFloor && ! rhs . m_bIncludeFloor ) { // this < rhs i = - 1 ; } else if ( ! m_bIncludeFloor && rhs . m_bIncludeFloor ) { // this > rhs i = + 1 ; } if ( i == 0 ) { // compare ceiling if ( m_aCeilVersion != null && rhs . m_aCeilVersion == null ) i = - 1 ; else if ( m_aCeilVersion == null && rhs . m_aCeilVersion != null ) i = + 1 ; else if ( m_aCeilVersion != null && rhs . m_aCeilVersion != null ) i = m_aCeilVersion . compareTo ( rhs . m_aCeilVersion ) ; // else i stays 0 if both are null if ( i == 0 ) { if ( m_bIncludeCeil && ! rhs . m_bIncludeCeil ) i = + 1 ; else if ( ! m_bIncludeCeil && rhs . m_bIncludeCeil ) i = - 1 ; } } } return i ; }
Compare this version range to another version range . Returns - 1 if this is &lt ; than the passed version or + 1 if this is &gt ; the passed version range
319
35
16,379
@ Nonnegative public static long channelCopy ( @ Nonnull @ WillNotClose final ReadableByteChannel aSrc , @ Nonnull @ WillNotClose final WritableByteChannel aDest ) throws IOException { ValueEnforcer . notNull ( aSrc , "SourceChannel" ) ; ValueEnforcer . isTrue ( aSrc . isOpen ( ) , "SourceChannel is not open!" ) ; ValueEnforcer . notNull ( aDest , "DestinationChannel" ) ; ValueEnforcer . isTrue ( aDest . isOpen ( ) , "DestinationChannel is not open!" ) ; long nBytesWritten ; if ( USE_COPY_V1 ) nBytesWritten = _channelCopy1 ( aSrc , aDest ) ; else nBytesWritten = _channelCopy2 ( aSrc , aDest ) ; return nBytesWritten ; }
Copy all content from the source channel to the destination channel .
185
12
16,380
@ Nonnull public URLParameterList remove ( @ Nullable final String sName ) { removeIf ( aParam -> aParam . hasName ( sName ) ) ; return this ; }
Remove all parameter with the given name .
39
8
16,381
@ Nonnull public URLParameterList remove ( @ Nullable final String sName , @ Nullable final String sValue ) { removeIf ( aParam -> aParam . hasName ( sName ) && aParam . hasValue ( sValue ) ) ; return this ; }
Remove all parameter with the given name and value .
57
10
16,382
@ Nullable public String getFirstParamValue ( @ Nullable final String sName ) { return sName == null ? null : findFirstMapped ( aParam -> aParam . hasName ( sName ) , URLParameter :: getValue ) ; }
Get the value of the first parameter with the provided name
53
11
16,383
@ Nullable public static IMicroDocument readMicroXML ( @ WillClose @ Nullable final InputSource aInputSource , @ Nullable final ISAXReaderSettings aSettings ) { if ( aInputSource == null ) return null ; final EntityResolver aEntityResolver = aSettings == null ? null : aSettings . getEntityResolver ( ) ; final MicroSAXHandler aMicroHandler = new MicroSAXHandler ( false , aEntityResolver , true ) ; // Copy and modify settings final SAXReaderSettings aRealSettings = SAXReaderSettings . createCloneOnDemand ( aSettings ) ; aRealSettings . setEntityResolver ( aMicroHandler ) . setDTDHandler ( aMicroHandler ) . setContentHandler ( aMicroHandler ) . setLexicalHandler ( aMicroHandler ) ; if ( aRealSettings . getErrorHandler ( ) == null ) { // Use MicroHandler as default error handler if none is specified aRealSettings . setErrorHandler ( aMicroHandler ) ; } if ( aEntityResolver instanceof EntityResolver2 ) { // Ensure to use the new aEntityResolver2 APIs if available aRealSettings . setFeatureValue ( EXMLParserFeature . USE_ENTITY_RESOLVER2 , true ) ; } if ( SAXReader . readXMLSAX ( aInputSource , aRealSettings ) . isFailure ( ) ) return null ; return aMicroHandler . getDocument ( ) ; }
Read the passed input source as MicroXML .
308
10
16,384
public boolean containsLanguage ( @ Nullable final String sLanguage ) { if ( sLanguage == null ) return false ; final String sValidLanguage = LocaleHelper . getValidLanguageCode ( sLanguage ) ; if ( sValidLanguage == null ) return false ; return m_aRWLock . readLocked ( ( ) -> m_aLanguages . contains ( sValidLanguage ) ) ; }
Check if the passed language is known .
83
8
16,385
public void iterateAllRegisteredSerializationConverters ( @ Nonnull final ISerializationConverterCallback aCallback ) { // Create a static (non weak) copy of the map final Map < Class < ? > , ISerializationConverter < ? > > aCopy = m_aRWLock . readLocked ( ( ) -> new CommonsHashMap <> ( m_aMap ) ) ; // And iterate the copy for ( final Map . Entry < Class < ? > , ISerializationConverter < ? > > aEntry : aCopy . entrySet ( ) ) if ( aCallback . call ( aEntry . getKey ( ) , aEntry . getValue ( ) ) . isBreak ( ) ) break ; }
Iterate all registered serialization converters . For informational purposes only .
158
14
16,386
@ Nonnull public static byte [ ] getSerializedByteArray ( @ Nonnull final Serializable aData ) { ValueEnforcer . notNull ( aData , "Data" ) ; try ( final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ( ) ) { // Convert to byte array try ( final ObjectOutputStream aOOS = new ObjectOutputStream ( aBAOS ) ) { aOOS . writeObject ( aData ) ; } // Main sending return aBAOS . toByteArray ( ) ; } catch ( final NotSerializableException ex ) { throw new IllegalArgumentException ( "Not serializable: " + ex . getMessage ( ) , ex ) ; } catch ( final IOException ex ) { throw new IllegalArgumentException ( "Failed to write serializable object " + aData + " of type " + aData . getClass ( ) . getName ( ) , ex ) ; } }
Convert the passed Serializable object to a serialized byte array .
204
14
16,387
@ Nonnull public static < T > T getDeserializedObject ( @ Nonnull final byte [ ] aData ) { ValueEnforcer . notNull ( aData , "Data" ) ; // Read new object from byte array try ( final ObjectInputStream aOIS = new ObjectInputStream ( new NonBlockingByteArrayInputStream ( aData ) ) ) { return GenericReflection . uncheckedCast ( aOIS . readObject ( ) ) ; } catch ( final Exception ex ) { throw new IllegalStateException ( "Failed to read serializable object" , ex ) ; } }
Convert the passed byte array to an object using deserialization .
125
14
16,388
@ Nonnull public static String getLocalDateTimeForFilename ( @ Nonnull final LocalDateTime aDT ) { return PDTToString . getAsString ( PATTERN_DATETIME , aDT ) ; }
Get the passed local date time formatted suitable for a file name .
46
13
16,389
@ OverrideOnDemand protected boolean recurseIntoDirectory ( @ Nonnull final File aDirectory ) { return m_aRecursionFilter == null || m_aRecursionFilter . test ( aDirectory ) ; }
Override this method to manually filter the directories which are recursed into .
46
14
16,390
@ Nonnull public static String getFormatted ( @ Nonnull final BigDecimal aValue , @ Nonnegative final int nFractionDigits , @ Nonnull final Locale aDisplayLocale ) { ValueEnforcer . notNull ( aValue , "Value" ) ; ValueEnforcer . notNull ( aDisplayLocale , "DisplayLocale" ) ; final NumberFormat aNF = NumberFormat . getInstance ( aDisplayLocale ) ; aNF . setMinimumFractionDigits ( nFractionDigits ) ; aNF . setMaximumFractionDigits ( nFractionDigits ) ; return aNF . format ( aValue ) ; }
Format the passed value according to the rules specified by the given locale .
140
14
16,391
@ Nonnull public static String getFormattedWithAllFractionDigits ( @ Nonnull final BigDecimal aValue , @ Nonnull final Locale aDisplayLocale ) { ValueEnforcer . notNull ( aValue , "Value" ) ; ValueEnforcer . notNull ( aDisplayLocale , "DisplayLocale" ) ; final NumberFormat aNF = NumberFormat . getInstance ( aDisplayLocale ) ; aNF . setMaximumFractionDigits ( aValue . scale ( ) ) ; return aNF . format ( aValue ) ; }
Format the passed value according to the rules specified by the given locale . All fraction digits of the passed value are displayed .
119
24
16,392
@ Nonnull public static String getFormattedPercent ( final double dValue , @ Nonnull final Locale aDisplayLocale ) { ValueEnforcer . notNull ( aDisplayLocale , "DisplayLocale" ) ; return NumberFormat . getPercentInstance ( aDisplayLocale ) . format ( dValue ) ; }
Format the given value as percentage . The % sign is automatically appended according to the requested locale . The number of fractional digits depend on the locale .
68
31
16,393
@ Nonnull public static String getFormattedPercent ( final double dValue , @ Nonnegative final int nFractionDigits , @ Nonnull final Locale aDisplayLocale ) { ValueEnforcer . notNull ( aDisplayLocale , "DisplayLocale" ) ; final NumberFormat aNF = NumberFormat . getPercentInstance ( aDisplayLocale ) ; aNF . setMinimumFractionDigits ( nFractionDigits ) ; aNF . setMaximumFractionDigits ( nFractionDigits ) ; return aNF . format ( dValue ) ; }
Format the given value as percentage . The % sign is automatically appended according to the requested locale .
122
20
16,394
@ Nonnull public EChange put ( @ Nullable final ELEMENTTYPE aElement ) { if ( m_nAvailable < m_nCapacity ) { if ( m_nWritePos >= m_nCapacity ) m_nWritePos = 0 ; m_aElements [ m_nWritePos ] = aElement ; m_nWritePos ++ ; m_nAvailable ++ ; return EChange . CHANGED ; } else if ( m_bAllowOverwrite ) { if ( m_nWritePos >= m_nCapacity ) m_nWritePos = 0 ; m_aElements [ m_nWritePos ] = aElement ; m_nWritePos ++ ; return EChange . CHANGED ; } return EChange . UNCHANGED ; }
Add a new element into the ring buffer
168
8
16,395
@ Nullable public ELEMENTTYPE take ( ) { final int nAvailable = m_nAvailable ; if ( nAvailable == 0 ) return null ; int nIndex = m_nWritePos - nAvailable ; if ( nIndex < 0 ) nIndex += m_nCapacity ; final Object ret = m_aElements [ nIndex ] ; m_nAvailable -- ; return GenericReflection . uncheckedCast ( ret ) ; }
Take an element from the ring buffer .
92
8
16,396
@ Nonnull @ OverrideOnDemand protected IErrorLevel getErrorLevel ( final int nSeverity ) { switch ( nSeverity ) { case ValidationEvent . WARNING : return EErrorLevel . WARN ; case ValidationEvent . ERROR : return EErrorLevel . ERROR ; case ValidationEvent . FATAL_ERROR : return EErrorLevel . FATAL_ERROR ; default : if ( LOGGER . isWarnEnabled ( ) ) LOGGER . warn ( "Unknown JAXB validation severity: " + nSeverity + "; defaulting to error" ) ; return EErrorLevel . ERROR ; } }
Get the error level matching the passed JAXB severity .
132
12
16,397
@ Nonnull public static ESuccess readXMLSAX ( @ WillClose @ Nonnull final InputSource aIS , @ Nonnull final ISAXReaderSettings aSettings ) { ValueEnforcer . notNull ( aIS , "InputStream" ) ; ValueEnforcer . notNull ( aSettings , "Settings" ) ; try { boolean bFromPool = false ; org . xml . sax . XMLReader aParser ; if ( aSettings . requiresNewXMLParser ( ) ) { aParser = SAXReaderFactory . createXMLReader ( ) ; } else { // use parser from pool aParser = s_aSAXPool . borrowObject ( ) ; bFromPool = true ; } try { final StopWatch aSW = StopWatch . createdStarted ( ) ; // Apply settings aSettings . applyToSAXReader ( aParser ) ; // Start parsing aParser . parse ( aIS ) ; // Statistics s_aSaxSuccessCounterHdl . increment ( ) ; s_aSaxTimerHdl . addTime ( aSW . stopAndGetMillis ( ) ) ; return ESuccess . SUCCESS ; } finally { if ( bFromPool ) { // Return parser to pool s_aSAXPool . returnObject ( aParser ) ; } } } catch ( final SAXParseException ex ) { boolean bHandled = false ; if ( aSettings . getErrorHandler ( ) != null ) try { aSettings . getErrorHandler ( ) . fatalError ( ex ) ; bHandled = true ; } catch ( final SAXException ex2 ) { // fall-through } if ( ! bHandled ) aSettings . exceptionCallbacks ( ) . forEach ( x -> x . onException ( ex ) ) ; } catch ( final Exception ex ) { aSettings . exceptionCallbacks ( ) . forEach ( x -> x . onException ( ex ) ) ; } finally { // Close both byte stream and character stream, as we don't know which one // was used StreamHelper . close ( aIS . getByteStream ( ) ) ; StreamHelper . close ( aIS . getCharacterStream ( ) ) ; } s_aSaxErrorCounterHdl . increment ( ) ; return ESuccess . FAILURE ; }
Read an XML document via a SAX handler . The streams are closed after reading .
476
17
16,398
@ Nullable @ OverrideOnDemand protected LogMessage createLogMessage ( @ Nonnull final IErrorLevel eErrorLevel , @ Nonnull final Serializable aMsg , @ Nullable final Throwable t ) { return new LogMessage ( eErrorLevel , aMsg , t ) ; }
Override this method to create a different LogMessage object or to filter certain log messages .
60
17
16,399
@ Nonnull public final Validator getValidatorFromSchema ( @ Nonnull final Schema aSchema ) { ValueEnforcer . notNull ( aSchema , "Schema" ) ; final Validator aValidator = aSchema . newValidator ( ) ; aValidator . setErrorHandler ( m_aSchemaFactory . getErrorHandler ( ) ) ; return aValidator ; }
Utility method to get the validator for a given schema using the error handler provided in the constructor .
87
21