idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
27,400
public void setCurrentPos ( int i ) { if ( ! m_cacheNodes ) throw new RuntimeException ( XSLMessages . createXPATHMessage ( XPATHErrorResources . ER_NODESET_CANNOT_INDEX , null ) ) ; m_next = i ; }
Set the current position in the node set .
27,401
public final static boolean objectEquals ( Object a , Object b ) { return a == null ? b == null ? true : false : b == null ? false : a . equals ( b ) ; }
Convenience utility . Does null checks on objects then calls equals .
27,402
public static < T extends Comparable < T > > int checkCompare ( T a , T b ) { return a == null ? b == null ? 0 : - 1 : b == null ? 1 : a . compareTo ( b ) ; }
Convenience utility . Does null checks on objects then calls compare .
27,403
private static final < T extends Appendable > void appendEncodedByte ( T buffer , byte value , byte [ ] state ) { try { if ( state [ 0 ] != 0 ) { char c = ( char ) ( ( state [ 1 ] << 8 ) | ( ( value ) & 0xFF ) ) ; buffer . append ( c ) ; state [ 0 ] = 0 ; } else { state [ 0 ] = 1 ; state [ 1 ] = value ; } } catch ( IOException e ) { throw new IllegalIcuArgumentException ( e ) ; } }
Append a byte to the given Appendable packing two bytes into each character . The state parameter maintains intermediary data between calls .
27,404
static public final int [ ] RLEStringToIntArray ( String s ) { int length = getInt ( s , 0 ) ; int [ ] array = new int [ length ] ; int ai = 0 , i = 1 ; int maxI = s . length ( ) / 2 ; while ( ai < length && i < maxI ) { int c = getInt ( s , i ++ ) ; if ( c == ESCAPE ) { c = getInt ( s , i ++ ) ; if ( c == ESCAPE ) { array [ ai ++ ] = c ; } else { int runLength = c ; int runValue = getInt ( s , i ++ ) ; for ( int j = 0 ; j < runLength ; ++ j ) { array [ ai ++ ] = runValue ; } } } else { array [ ai ++ ] = c ; } } if ( ai != length || i != maxI ) { throw new IllegalStateException ( "Bad run-length encoded int array" ) ; } return array ; }
Construct an array of ints from a run - length encoded string .
27,405
static public final short [ ] RLEStringToShortArray ( String s ) { int length = ( ( s . charAt ( 0 ) ) << 16 ) | ( s . charAt ( 1 ) ) ; short [ ] array = new short [ length ] ; int ai = 0 ; for ( int i = 2 ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; if ( c == ESCAPE ) { c = s . charAt ( ++ i ) ; if ( c == ESCAPE ) { array [ ai ++ ] = ( short ) c ; } else { int runLength = c ; short runValue = ( short ) s . charAt ( ++ i ) ; for ( int j = 0 ; j < runLength ; ++ j ) array [ ai ++ ] = runValue ; } } else { array [ ai ++ ] = ( short ) c ; } } if ( ai != length ) throw new IllegalStateException ( "Bad run-length encoded short array" ) ; return array ; }
Construct an array of shorts from a run - length encoded string .
27,406
static public final byte [ ] RLEStringToByteArray ( String s ) { int length = ( ( s . charAt ( 0 ) ) << 16 ) | ( s . charAt ( 1 ) ) ; byte [ ] array = new byte [ length ] ; boolean nextChar = true ; char c = 0 ; int node = 0 ; int runLength = 0 ; int i = 2 ; for ( int ai = 0 ; ai < length ; ) { byte b ; if ( nextChar ) { c = s . charAt ( i ++ ) ; b = ( byte ) ( c >> 8 ) ; nextChar = false ; } else { b = ( byte ) ( c & 0xFF ) ; nextChar = true ; } switch ( node ) { case 0 : if ( b == ESCAPE_BYTE ) { node = 1 ; } else { array [ ai ++ ] = b ; } break ; case 1 : if ( b == ESCAPE_BYTE ) { array [ ai ++ ] = ESCAPE_BYTE ; node = 0 ; } else { runLength = b ; if ( runLength < 0 ) runLength += 0x100 ; node = 2 ; } break ; case 2 : for ( int j = 0 ; j < runLength ; ++ j ) array [ ai ++ ] = b ; node = 0 ; break ; } } if ( node != 0 ) throw new IllegalStateException ( "Bad run-length encoded byte array" ) ; if ( i != s . length ( ) ) throw new IllegalStateException ( "Excess data in RLE byte array string" ) ; return array ; }
Construct an array of bytes from a run - length encoded string .
27,407
static public final String format1ForSource ( String s ) { StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( "\"" ) ; for ( int i = 0 ; i < s . length ( ) ; ) { char c = s . charAt ( i ++ ) ; if ( c < '\u0020' || c == '"' || c == '\\' ) { if ( c == '\n' ) { buffer . append ( "\\n" ) ; } else if ( c == '\t' ) { buffer . append ( "\\t" ) ; } else if ( c == '\r' ) { buffer . append ( "\\r" ) ; } else { buffer . append ( '\\' ) ; buffer . append ( HEX_DIGIT [ ( c & 0700 ) >> 6 ] ) ; buffer . append ( HEX_DIGIT [ ( c & 0070 ) >> 3 ] ) ; buffer . append ( HEX_DIGIT [ ( c & 0007 ) ] ) ; } } else if ( c <= '\u007E' ) { buffer . append ( c ) ; } else { buffer . append ( "\\u" ) ; buffer . append ( HEX_DIGIT [ ( c & 0xF000 ) >> 12 ] ) ; buffer . append ( HEX_DIGIT [ ( c & 0x0F00 ) >> 8 ] ) ; buffer . append ( HEX_DIGIT [ ( c & 0x00F0 ) >> 4 ] ) ; buffer . append ( HEX_DIGIT [ ( c & 0x000F ) ] ) ; } } buffer . append ( '"' ) ; return buffer . toString ( ) ; }
Format a String for representation in a source file . Like formatForSource but does not do line breaking .
27,408
public static final String escape ( String s ) { StringBuilder buf = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; ) { int c = Character . codePointAt ( s , i ) ; i += UTF16 . getCharCount ( c ) ; if ( c >= ' ' && c <= 0x007F ) { if ( c == '\\' ) { buf . append ( "\\\\" ) ; } else { buf . append ( ( char ) c ) ; } } else { boolean four = c <= 0xFFFF ; buf . append ( four ? "\\u" : "\\U" ) ; buf . append ( hex ( c , four ? 4 : 8 ) ) ; } } return buf . toString ( ) ; }
Convert characters outside the range U + 0020 to U + 007F to Unicode escapes and convert backslash to a double backslash .
27,409
public static int lookup ( String source , String [ ] target ) { for ( int i = 0 ; i < target . length ; ++ i ) { if ( source . equals ( target [ i ] ) ) return i ; } return - 1 ; }
Look up a given string in a string array . Returns the index at which the first occurrence of the string was found in the array or - 1 if it was not found .
27,410
public static boolean parseChar ( String id , int [ ] pos , char ch ) { int start = pos [ 0 ] ; pos [ 0 ] = PatternProps . skipWhiteSpace ( id , pos [ 0 ] ) ; if ( pos [ 0 ] == id . length ( ) || id . charAt ( pos [ 0 ] ) != ch ) { pos [ 0 ] = start ; return false ; } ++ pos [ 0 ] ; return true ; }
Parse a single non - whitespace character ch optionally preceded by whitespace .
27,411
@ SuppressWarnings ( "fallthrough" ) public static int parsePattern ( String rule , int pos , int limit , String pattern , int [ ] parsedInts ) { int [ ] p = new int [ 1 ] ; int intCount = 0 ; for ( int i = 0 ; i < pattern . length ( ) ; ++ i ) { char cpat = pattern . charAt ( i ) ; char c ; switch ( cpat ) { case ' ' : if ( pos >= limit ) { return - 1 ; } c = rule . charAt ( pos ++ ) ; if ( ! PatternProps . isWhiteSpace ( c ) ) { return - 1 ; } case '~' : pos = PatternProps . skipWhiteSpace ( rule , pos ) ; break ; case '#' : p [ 0 ] = pos ; parsedInts [ intCount ++ ] = parseInteger ( rule , p , limit ) ; if ( p [ 0 ] == pos ) { return - 1 ; } pos = p [ 0 ] ; break ; default : if ( pos >= limit ) { return - 1 ; } c = ( char ) UCharacter . toLowerCase ( rule . charAt ( pos ++ ) ) ; if ( c != cpat ) { return - 1 ; } break ; } } return pos ; }
Parse a pattern string starting at offset pos . Keywords are matched case - insensitively . Spaces may be skipped and may be optional or required . Integer values may be parsed and if they are they will be returned in the given array . If successful the offset of the next non - space character is returned . On failure - 1 is returned .
27,412
public static String parseUnicodeIdentifier ( String str , int [ ] pos ) { StringBuilder buf = new StringBuilder ( ) ; int p = pos [ 0 ] ; while ( p < str . length ( ) ) { int ch = Character . codePointAt ( str , p ) ; if ( buf . length ( ) == 0 ) { if ( UCharacter . isUnicodeIdentifierStart ( ch ) ) { buf . appendCodePoint ( ch ) ; } else { return null ; } } else { if ( UCharacter . isUnicodeIdentifierPart ( ch ) ) { buf . appendCodePoint ( ch ) ; } else { break ; } } p += UTF16 . getCharCount ( ch ) ; } pos [ 0 ] = p ; return buf . toString ( ) ; }
Parse a Unicode identifier from the given string at the given position . Return the identifier or null if there is no identifier .
27,413
public static < T extends Appendable > T appendNumber ( T result , int n , int radix , int minDigits ) { try { if ( radix < 2 || radix > 36 ) { throw new IllegalArgumentException ( "Illegal radix " + radix ) ; } int abs = n ; if ( n < 0 ) { abs = - n ; result . append ( "-" ) ; } recursiveAppendNumber ( result , abs , radix , minDigits ) ; return result ; } catch ( IOException e ) { throw new IllegalIcuArgumentException ( e ) ; } }
Append a number to the given Appendable in the given radix . Standard digits 0 - 9 are used and letters A - Z for radices 11 through 36 .
27,414
public static void appendToRule ( StringBuffer rule , String text , boolean isLiteral , boolean escapeUnprintable , StringBuffer quoteBuf ) { for ( int i = 0 ; i < text . length ( ) ; ++ i ) { appendToRule ( rule , text . charAt ( i ) , isLiteral , escapeUnprintable , quoteBuf ) ; } }
Append the given string to the rule . Calls the single - character version of appendToRule for each character .
27,415
public static final int compareUnsigned ( int source , int target ) { source += MAGIC_UNSIGNED ; target += MAGIC_UNSIGNED ; if ( source < target ) { return - 1 ; } else if ( source > target ) { return 1 ; } return 0 ; }
Compares 2 unsigned integers
27,416
public static final byte highBit ( int n ) { if ( n <= 0 ) { return - 1 ; } byte bit = 0 ; if ( n >= 1 << 16 ) { n >>= 16 ; bit += 16 ; } if ( n >= 1 << 8 ) { n >>= 8 ; bit += 8 ; } if ( n >= 1 << 4 ) { n >>= 4 ; bit += 4 ; } if ( n >= 1 << 2 ) { n >>= 2 ; bit += 2 ; } if ( n >= 1 << 1 ) { n >>= 1 ; bit += 1 ; } return bit ; }
Find the highest bit in a positive integer . This is done by doing a binary search through the bits .
27,417
public void setExpression ( Expression exp ) { if ( null != m_mainExp ) exp . exprSetParent ( m_mainExp . exprGetParent ( ) ) ; m_mainExp = exp ; }
Set the raw expression object for this object .
27,418
final ElemContext push ( ) { ElemContext frame = this . m_next ; if ( frame == null ) { frame = new ElemContext ( this ) ; this . m_next = frame ; } frame . m_startTagOpen = true ; return frame ; }
This method pushes an element stack frame but with no initialization of values in that frame . This method is used for optimization purposes like when pushing a stack frame for an HTML IMG tag which has no children and the stack frame will almost immediately be popped .
27,419
final ElemContext push ( final String uri , final String localName , final String qName ) { ElemContext frame = this . m_next ; if ( frame == null ) { frame = new ElemContext ( this ) ; this . m_next = frame ; } frame . m_elementName = qName ; frame . m_elementLocalName = localName ; frame . m_elementURI = uri ; frame . m_isCdataSection = false ; frame . m_startTagOpen = true ; return frame ; }
Push an element context on the stack . This context keeps track of information gathered about the element .
27,420
public final void clearPassword ( ) { if ( password != null ) { for ( int i = 0 ; i < password . length ; i ++ ) { password [ i ] = ' ' ; } password = null ; } }
Clears the internal copy of the password .
27,421
public void flush ( ) throws IOException { ensureOpen ( ) ; if ( ! inf . finished ( ) ) { try { while ( ! inf . finished ( ) && ! inf . needsInput ( ) ) { int n ; n = inf . inflate ( buf , 0 , buf . length ) ; if ( n < 1 ) { break ; } out . write ( buf , 0 , n ) ; } super . flush ( ) ; } catch ( DataFormatException ex ) { String msg = ex . getMessage ( ) ; if ( msg == null ) { msg = "Invalid ZLIB data format" ; } throw new ZipException ( msg ) ; } } }
Flushes this output stream forcing any pending buffered output bytes to be written .
27,422
public void write ( byte [ ] b , int off , int len ) throws IOException { ensureOpen ( ) ; if ( b == null ) { throw new NullPointerException ( "Null buffer for read" ) ; } else if ( off < 0 || len < 0 || len > b . length - off ) { throw new IndexOutOfBoundsException ( ) ; } else if ( len == 0 ) { return ; } try { for ( ; ; ) { int n ; if ( inf . needsInput ( ) ) { int part ; if ( len < 1 ) { break ; } part = ( len < 512 ? len : 512 ) ; inf . setInput ( b , off , part ) ; off += part ; len -= part ; } do { n = inf . inflate ( buf , 0 , buf . length ) ; if ( n > 0 ) { out . write ( buf , 0 , n ) ; } } while ( n > 0 ) ; if ( inf . finished ( ) ) { break ; } if ( inf . needsDictionary ( ) ) { throw new ZipException ( "ZLIB dictionary missing" ) ; } } } catch ( DataFormatException ex ) { String msg = ex . getMessage ( ) ; if ( msg == null ) { msg = "Invalid ZLIB data format" ; } throw new ZipException ( msg ) ; } }
Writes an array of bytes to the uncompressed output stream .
27,423
public void add ( URI uri , HttpCookie cookie ) { if ( cookie == null ) { throw new NullPointerException ( "cookie is null" ) ; } lock . lock ( ) ; try { if ( cookie . getMaxAge ( ) != 0 ) { addIndex ( uriIndex , getEffectiveURI ( uri ) , cookie ) ; } } finally { lock . unlock ( ) ; } }
Add one cookie into cookie store .
27,424
public List < HttpCookie > getCookies ( ) { List < HttpCookie > rt = new ArrayList < HttpCookie > ( ) ; lock . lock ( ) ; try { for ( List < HttpCookie > list : uriIndex . values ( ) ) { Iterator < HttpCookie > it = list . iterator ( ) ; while ( it . hasNext ( ) ) { HttpCookie cookie = it . next ( ) ; if ( cookie . hasExpired ( ) ) { it . remove ( ) ; } else if ( ! rt . contains ( cookie ) ) { rt . add ( cookie ) ; } } } } finally { rt = Collections . unmodifiableList ( rt ) ; lock . unlock ( ) ; } return rt ; }
Get all cookies in cookie store except those have expired
27,425
public List < URI > getURIs ( ) { List < URI > uris = new ArrayList < URI > ( ) ; lock . lock ( ) ; try { List < URI > result = new ArrayList < URI > ( uriIndex . keySet ( ) ) ; result . remove ( null ) ; return Collections . unmodifiableList ( result ) ; } finally { uris . addAll ( uriIndex . keySet ( ) ) ; lock . unlock ( ) ; } }
Get all URIs which are associated with at least one cookie of this cookie store .
27,426
public boolean remove ( URI uri , HttpCookie ck ) { if ( ck == null ) { throw new NullPointerException ( "cookie is null" ) ; } lock . lock ( ) ; try { uri = getEffectiveURI ( uri ) ; if ( uriIndex . get ( uri ) == null ) { return false ; } else { List < HttpCookie > cookies = uriIndex . get ( uri ) ; if ( cookies != null ) { return cookies . remove ( ck ) ; } else { return false ; } } } finally { lock . unlock ( ) ; } }
Remove a cookie from store
27,427
public boolean removeAll ( ) { lock . lock ( ) ; boolean result = false ; try { result = ! uriIndex . isEmpty ( ) ; uriIndex . clear ( ) ; } finally { lock . unlock ( ) ; } return result ; }
Remove all cookies in this cookie store .
27,428
private < T extends Comparable < T > > void getInternal2 ( List < HttpCookie > cookies , Map < T , List < HttpCookie > > cookieIndex , T comparator ) { for ( T index : cookieIndex . keySet ( ) ) { if ( ( index == comparator ) || ( index != null && comparator . compareTo ( index ) == 0 ) ) { List < HttpCookie > indexedCookies = cookieIndex . get ( index ) ; if ( indexedCookies != null ) { Iterator < HttpCookie > it = indexedCookies . iterator ( ) ; while ( it . hasNext ( ) ) { HttpCookie ck = it . next ( ) ; if ( ! ck . hasExpired ( ) ) { if ( ! cookies . contains ( ck ) ) cookies . add ( ck ) ; } else { it . remove ( ) ; } } } } } }
a cookie in index should be returned
27,429
private < T > void addIndex ( Map < T , List < HttpCookie > > indexStore , T index , HttpCookie cookie ) { List < HttpCookie > cookies = indexStore . get ( index ) ; if ( cookies != null ) { cookies . remove ( cookie ) ; cookies . add ( cookie ) ; } else { cookies = new ArrayList < HttpCookie > ( ) ; cookies . add ( cookie ) ; indexStore . put ( index , cookies ) ; } }
add cookie indexed by index into indexStore
27,430
public String getCurrencyPluralPattern ( String pluralCount ) { String currencyPluralPattern = pluralCountToCurrencyUnitPattern . get ( pluralCount ) ; if ( currencyPluralPattern == null ) { if ( ! pluralCount . equals ( "other" ) ) { currencyPluralPattern = pluralCountToCurrencyUnitPattern . get ( "other" ) ; } if ( currencyPluralPattern == null ) { currencyPluralPattern = defaultCurrencyPluralPattern ; } } return currencyPluralPattern ; }
Given a plural count gets currency plural pattern of this locale used for currency plural format
27,431
private void set ( int pos , String s ) { buffer . delete ( pos , buffer . length ( ) ) ; buffer . insert ( pos , s ) ; }
Set the length of the buffer to pos then append the string .
27,432
private boolean haveKeywordAssign ( ) { for ( int i = index ; i < id . length ; ++ i ) { if ( id [ i ] == KEYWORD_ASSIGN ) { return true ; } } return false ; }
Returns true if a value separator occurs at or after index .
27,433
private int parseLanguage ( ) { int startLength = buffer . length ( ) ; if ( haveExperimentalLanguagePrefix ( ) ) { append ( AsciiUtil . toLower ( id [ 0 ] ) ) ; append ( HYPHEN ) ; index = 2 ; } char c ; while ( ! isTerminatorOrIDSeparator ( c = next ( ) ) ) { append ( AsciiUtil . toLower ( c ) ) ; } -- index ; if ( buffer . length ( ) - startLength == 3 ) { String lang = LocaleIDs . threeToTwoLetterLanguage ( getString ( 0 ) ) ; if ( lang != null ) { set ( 0 , lang ) ; } } return 0 ; }
Advance index past language and accumulate normalized language code in buffer . Index must be at 0 when this is called . Index is left at a terminator or id separator . Returns the start of the language code in the buffer .
27,434
private int parseVariant ( ) { int oldBlen = buffer . length ( ) ; boolean start = true ; boolean needSeparator = true ; boolean skipping = false ; char c ; boolean firstPass = true ; while ( ( c = next ( ) ) != DONE ) { if ( c == DOT ) { start = false ; skipping = true ; } else if ( c == KEYWORD_SEPARATOR ) { if ( haveKeywordAssign ( ) ) { break ; } skipping = false ; start = false ; needSeparator = true ; } else if ( start ) { start = false ; if ( c != UNDERSCORE && c != HYPHEN ) { index -- ; } } else if ( ! skipping ) { if ( needSeparator ) { needSeparator = false ; if ( firstPass && ! hadCountry ) { addSeparator ( ) ; ++ oldBlen ; } addSeparator ( ) ; if ( firstPass ) { ++ oldBlen ; firstPass = false ; } } c = AsciiUtil . toUpper ( c ) ; if ( c == HYPHEN || c == COMMA ) { c = UNDERSCORE ; } append ( c ) ; } } -- index ; return oldBlen ; }
Advance index past variant and accumulate normalized variant in buffer . This ignores the codepage information from POSIX ids . Index must be immediately after the country or script . Index is left at the keyword separator or at the end of the text . Return the start of the variant code in the buffer .
27,435
public String [ ] getLanguageScriptCountryVariant ( ) { reset ( ) ; return new String [ ] { getString ( parseLanguage ( ) ) , getString ( parseScript ( ) ) , getString ( parseCountry ( ) ) , getString ( parseVariant ( ) ) } ; }
Returns the language script country and variant as separate strings .
27,436
private boolean setToKeywordStart ( ) { for ( int i = index ; i < id . length ; ++ i ) { if ( id [ i ] == KEYWORD_SEPARATOR ) { if ( canonicalize ) { for ( int j = ++ i ; j < id . length ; ++ j ) { if ( id [ j ] == KEYWORD_ASSIGN ) { index = i ; return true ; } } } else { if ( ++ i < id . length ) { index = i ; return true ; } } break ; } } return false ; }
If we have keywords advance index to the start of the keywords and return true otherwise return false .
27,437
public Map < String , String > getKeywordMap ( ) { if ( keywords == null ) { TreeMap < String , String > m = null ; if ( setToKeywordStart ( ) ) { do { String key = getKeyword ( ) ; if ( key . length ( ) == 0 ) { break ; } char c = next ( ) ; if ( c != KEYWORD_ASSIGN ) { if ( c == DONE ) { break ; } else { continue ; } } String value = getValue ( ) ; if ( value . length ( ) == 0 ) { continue ; } if ( m == null ) { m = new TreeMap < String , String > ( getKeyComparator ( ) ) ; } else if ( m . containsKey ( key ) ) { continue ; } m . put ( key , value ) ; } while ( next ( ) == ITEM_SEPARATOR ) ; } keywords = m != null ? m : Collections . < String , String > emptyMap ( ) ; } return keywords ; }
Returns a map of the keywords and values or null if there are none .
27,438
private int parseKeywords ( ) { int oldBlen = buffer . length ( ) ; Map < String , String > m = getKeywordMap ( ) ; if ( ! m . isEmpty ( ) ) { boolean first = true ; for ( Map . Entry < String , String > e : m . entrySet ( ) ) { append ( first ? KEYWORD_SEPARATOR : ITEM_SEPARATOR ) ; first = false ; append ( e . getKey ( ) ) ; append ( KEYWORD_ASSIGN ) ; append ( e . getValue ( ) ) ; } if ( first == false ) { ++ oldBlen ; } } return oldBlen ; }
Parse the keywords and return start of the string in the buffer .
27,439
public Iterator < String > getKeywords ( ) { Map < String , String > m = getKeywordMap ( ) ; return m . isEmpty ( ) ? null : m . keySet ( ) . iterator ( ) ; }
Returns an iterator over the keywords or null if we have an empty map .
27,440
public String getKeywordValue ( String keywordName ) { Map < String , String > m = getKeywordMap ( ) ; return m . isEmpty ( ) ? null : m . get ( AsciiUtil . toLowerString ( keywordName . trim ( ) ) ) ; }
Returns the value for the named keyword or null if the keyword is not present .
27,441
public void applyPattern ( String pattern ) { this . pattern = pattern ; if ( msgPattern == null ) { msgPattern = new MessagePattern ( ) ; } try { msgPattern . parsePluralStyle ( pattern ) ; offset = msgPattern . getPluralOffset ( 0 ) ; } catch ( RuntimeException e ) { resetPattern ( ) ; throw e ; } }
Sets the pattern used by this plural format . The method parses the pattern and creates a map of format strings for the plural rules . Patterns and their interpretation are specified in the class description .
27,442
private byte [ ] decode ( DerInputStream in ) throws IOException { DerValue val = in . getDerValue ( ) ; byte [ ] derEncoding = val . toByteArray ( ) ; derEncoding [ 0 ] = DerValue . tag_SetOf ; DerInputStream derIn = new DerInputStream ( derEncoding ) ; DerValue [ ] derVals = derIn . getSet ( 3 , true ) ; PKCS9Attribute attrib ; ObjectIdentifier oid ; boolean reuseEncoding = true ; for ( int i = 0 ; i < derVals . length ; i ++ ) { try { attrib = new PKCS9Attribute ( derVals [ i ] ) ; } catch ( ParsingException e ) { if ( ignoreUnsupportedAttributes ) { reuseEncoding = false ; continue ; } else { throw e ; } } oid = attrib . getOID ( ) ; if ( attributes . get ( oid ) != null ) throw new IOException ( "Duplicate PKCS9 attribute: " + oid ) ; if ( permittedAttributes != null && ! permittedAttributes . containsKey ( oid ) ) throw new IOException ( "Attribute " + oid + " not permitted in this attribute set" ) ; attributes . put ( oid , attrib ) ; } return reuseEncoding ? derEncoding : generateDerEncoding ( ) ; }
Decode this set of PKCS9 attributes from the contents of its DER encoding . Ignores unsupported attributes when directed .
27,443
public void encode ( byte tag , OutputStream out ) throws IOException { out . write ( tag ) ; out . write ( derEncoding , 1 , derEncoding . length - 1 ) ; }
Put the DER encoding of this PKCS9 attribute set on an DerOutputStream tagged with the given implicit tag .
27,444
public PKCS9Attribute [ ] getAttributes ( ) { PKCS9Attribute [ ] attribs = new PKCS9Attribute [ attributes . size ( ) ] ; ObjectIdentifier oid ; int j = 0 ; for ( int i = 1 ; i < PKCS9Attribute . PKCS9_OIDS . length && j < attribs . length ; i ++ ) { attribs [ j ] = getAttribute ( PKCS9Attribute . PKCS9_OIDS [ i ] ) ; if ( attribs [ j ] != null ) j ++ ; } return attribs ; }
Get an array of all attributes in this set in order of OID .
27,445
public Object getAttributeValue ( ObjectIdentifier oid ) throws IOException { try { Object value = getAttribute ( oid ) . getValue ( ) ; return value ; } catch ( NullPointerException ex ) { throw new IOException ( "No value found for attribute " + oid ) ; } }
Get an attribute value by OID .
27,446
public Object getAttributeValue ( String name ) throws IOException { ObjectIdentifier oid = PKCS9Attribute . getOID ( name ) ; if ( oid == null ) throw new IOException ( "Attribute name " + name + " not recognized or not supported." ) ; return getAttributeValue ( oid ) ; }
Get an attribute value by type name .
27,447
public void roll ( int field , int amount ) { switch ( field ) { case WEEK_OF_YEAR : { int woy = get ( WEEK_OF_YEAR ) ; int isoYear = get ( YEAR_WOY ) ; int isoDoy = internalGet ( DAY_OF_YEAR ) ; if ( internalGet ( MONTH ) == Calendar . JANUARY ) { if ( woy >= 52 ) { isoDoy += handleGetYearLength ( isoYear ) ; } } else { if ( woy == 1 ) { isoDoy -= handleGetYearLength ( isoYear - 1 ) ; } } woy += amount ; if ( woy < 1 || woy > 52 ) { int lastDoy = handleGetYearLength ( isoYear ) ; int lastRelDow = ( lastDoy - isoDoy + internalGet ( DAY_OF_WEEK ) - getFirstDayOfWeek ( ) ) % 7 ; if ( lastRelDow < 0 ) lastRelDow += 7 ; if ( ( 6 - lastRelDow ) >= getMinimalDaysInFirstWeek ( ) ) lastDoy -= 7 ; int lastWoy = weekNumber ( lastDoy , lastRelDow + 1 ) ; woy = ( ( woy + lastWoy - 1 ) % lastWoy ) + 1 ; } set ( WEEK_OF_YEAR , woy ) ; set ( YEAR , isoYear ) ; return ; } default : super . roll ( field , amount ) ; return ; } }
Roll a field by a signed amount .
27,448
public int getActualMaximum ( int field ) { switch ( field ) { case YEAR : { Calendar cal = ( Calendar ) clone ( ) ; cal . setLenient ( true ) ; int era = cal . get ( ERA ) ; Date d = cal . getTime ( ) ; int lowGood = LIMITS [ YEAR ] [ 1 ] ; int highBad = LIMITS [ YEAR ] [ 2 ] + 1 ; while ( ( lowGood + 1 ) < highBad ) { int y = ( lowGood + highBad ) / 2 ; cal . set ( YEAR , y ) ; if ( cal . get ( YEAR ) == y && cal . get ( ERA ) == era ) { lowGood = y ; } else { highBad = y ; cal . setTime ( d ) ; } } return lowGood ; } default : return super . getActualMaximum ( field ) ; } }
Return the maximum value that this field could have given the current date . For example with the date Feb 3 1997 and the DAY_OF_MONTH field the actual maximum would be 28 ; for Feb 3 1996 it s 29 . Similarly for a Hebrew calendar for some years the actual maximum for MONTH is 12 and for others 13 .
27,449
public void check ( Certificate cert , Collection < String > unresCritExts ) throws CertPathValidatorException { X509Certificate currCert = ( X509Certificate ) cert ; remainingCerts -- ; if ( remainingCerts == 0 ) { if ( targetConstraints != null && targetConstraints . match ( currCert ) == false ) { throw new CertPathValidatorException ( "target certificate " + "constraints check failed" ) ; } } else { verifyCAKeyUsage ( currCert ) ; } if ( unresCritExts != null && ! unresCritExts . isEmpty ( ) ) { unresCritExts . remove ( KeyUsage_Id . toString ( ) ) ; unresCritExts . remove ( ExtendedKeyUsage_Id . toString ( ) ) ; unresCritExts . remove ( SubjectAlternativeName_Id . toString ( ) ) ; } }
Checks that keyUsage and target constraints are satisfied by the specified certificate .
27,450
private void unbox ( Expression expr , PrimitiveType primitiveType ) { TypeElement boxedClass = findBoxedSuperclass ( expr . getTypeMirror ( ) ) ; if ( primitiveType == null && boxedClass != null ) { primitiveType = typeUtil . unboxedType ( boxedClass . asType ( ) ) ; } if ( primitiveType == null ) { return ; } ExecutableElement valueMethod = ElementUtil . findMethod ( boxedClass , TypeUtil . getName ( primitiveType ) + VALUE_METHOD ) ; assert valueMethod != null : "could not find value method for " + boxedClass ; MethodInvocation invocation = new MethodInvocation ( new ExecutablePair ( valueMethod ) , null ) ; expr . replaceWith ( invocation ) ; invocation . setExpression ( expr ) ; }
Convert a wrapper class instance to a specified primitive equivalent .
27,451
public static Integer getInteger ( String nm , int val ) { Integer result = getInteger ( nm , null ) ; return ( result == null ) ? Integer . valueOf ( val ) : result ; }
Determines the integer value of the system property with the specified name .
27,452
public final StringBuffer format ( Object obj , StringBuffer toAppendTo , FieldPosition fieldPosition ) { if ( obj instanceof Calendar ) return format ( ( Calendar ) obj , toAppendTo , fieldPosition ) ; else if ( obj instanceof Date ) return format ( ( Date ) obj , toAppendTo , fieldPosition ) ; else if ( obj instanceof Number ) return format ( new Date ( ( ( Number ) obj ) . longValue ( ) ) , toAppendTo , fieldPosition ) ; else throw new IllegalArgumentException ( "Cannot format given Object (" + obj . getClass ( ) . getName ( ) + ") as a Date" ) ; }
Formats a time object into a time string . Examples of time objects are a time value expressed in milliseconds and a Date object .
27,453
public final static DateFormat getDateInstance ( int style , Locale aLocale ) { return get ( style , - 1 , ULocale . forLocale ( aLocale ) , null ) ; }
Returns the date formatter with the given formatting style for the given locale .
27,454
public DateFormat setBooleanAttribute ( BooleanAttribute key , boolean value ) { if ( key . equals ( DateFormat . BooleanAttribute . PARSE_PARTIAL_MATCH ) ) { key = DateFormat . BooleanAttribute . PARSE_PARTIAL_LITERAL_MATCH ; } if ( value ) { booleanAttributes . add ( key ) ; } else { booleanAttributes . remove ( key ) ; } return this ; }
Sets a boolean attribute for this instance . Aspects of DateFormat leniency are controlled by boolean attributes .
27,455
public boolean getBooleanAttribute ( BooleanAttribute key ) { if ( key == DateFormat . BooleanAttribute . PARSE_PARTIAL_MATCH ) { key = DateFormat . BooleanAttribute . PARSE_PARTIAL_LITERAL_MATCH ; } return booleanAttributes . contains ( key ) ; }
Returns the current value for the specified BooleanAttribute for this instance
27,456
public static boolean check ( LocPathIterator path ) { HasPositionalPredChecker hppc = new HasPositionalPredChecker ( ) ; path . callVisitors ( null , hppc ) ; return hppc . m_hasPositionalPred ; }
Process the LocPathIterator to see if it contains variables or functions that may make it context dependent .
27,457
@ SuppressWarnings ( "unchecked" ) static < T > Node < T > emptyNode ( StreamShape shape ) { switch ( shape ) { case REFERENCE : return ( Node < T > ) EMPTY_NODE ; case INT_VALUE : return ( Node < T > ) EMPTY_INT_NODE ; case LONG_VALUE : return ( Node < T > ) EMPTY_LONG_NODE ; case DOUBLE_VALUE : return ( Node < T > ) EMPTY_DOUBLE_NODE ; default : throw new IllegalStateException ( "Unknown shape " + shape ) ; } }
Produces an empty node whose count is zero has no children and no content .
27,458
public final boolean getSet ( char src [ ] , int srcStart ) { array = null ; arrayOffset = bmpLength = length = 0 ; length = src [ srcStart ++ ] ; if ( ( length & 0x8000 ) != 0 ) { length &= 0x7fff ; if ( src . length < ( srcStart + 1 + length ) ) { length = 0 ; throw new IndexOutOfBoundsException ( ) ; } bmpLength = src [ srcStart ++ ] ; } else { if ( src . length < ( srcStart + length ) ) { length = 0 ; throw new IndexOutOfBoundsException ( ) ; } bmpLength = length ; } array = new char [ length ] ; System . arraycopy ( src , srcStart , array , 0 , length ) ; return true ; }
Fill in the given serialized set object .
27,459
public final boolean getRange ( int rangeIndex , int [ ] range ) { if ( rangeIndex < 0 ) { return false ; } if ( array == null ) { array = new char [ 8 ] ; } if ( range == null || range . length < 2 ) { throw new IllegalArgumentException ( ) ; } rangeIndex *= 2 ; if ( rangeIndex < bmpLength ) { range [ 0 ] = array [ rangeIndex ++ ] ; if ( rangeIndex < bmpLength ) { range [ 1 ] = array [ rangeIndex ] - 1 ; } else if ( rangeIndex < length ) { range [ 1 ] = ( ( ( ( int ) array [ rangeIndex ] ) << 16 ) | array [ rangeIndex + 1 ] ) - 1 ; } else { range [ 1 ] = 0x10ffff ; } return true ; } else { rangeIndex -= bmpLength ; rangeIndex *= 2 ; int suppLength = length - bmpLength ; if ( rangeIndex < suppLength ) { int offset = arrayOffset + bmpLength ; range [ 0 ] = ( ( ( int ) array [ offset + rangeIndex ] ) << 16 ) | array [ offset + rangeIndex + 1 ] ; rangeIndex += 2 ; if ( rangeIndex < suppLength ) { range [ 1 ] = ( ( ( ( int ) array [ offset + rangeIndex ] ) << 16 ) | array [ offset + rangeIndex + 1 ] ) - 1 ; } else { range [ 1 ] = 0x10ffff ; } return true ; } else { return false ; } } }
Returns a range of characters contained in the given serialized set .
27,460
public final boolean contains ( int c ) { if ( c > 0x10ffff ) { return false ; } if ( c <= 0xffff ) { int i ; for ( i = 0 ; i < bmpLength && ( char ) c >= array [ i ] ; ++ i ) { } return ( ( i & 1 ) != 0 ) ; } else { int i ; char high = ( char ) ( c >> 16 ) , low = ( char ) c ; for ( i = bmpLength ; i < length && ( high > array [ i ] || ( high == array [ i ] && low >= array [ i + 1 ] ) ) ; i += 2 ) { } return ( ( ( i + bmpLength ) & 2 ) != 0 ) ; } }
Returns true if the given USerializedSet contains the given character .
27,461
public void set ( V newReference , int newStamp ) { Pair < V > current = pair ; if ( newReference != current . reference || newStamp != current . stamp ) this . pair = Pair . of ( newReference , newStamp ) ; }
Unconditionally sets the value of both the reference and stamp .
27,462
private static void checkValidity ( ECField field , BigInteger c , String cName ) { if ( field instanceof ECFieldFp ) { BigInteger p = ( ( ECFieldFp ) field ) . getP ( ) ; if ( p . compareTo ( c ) != 1 ) { throw new IllegalArgumentException ( cName + " is too large" ) ; } else if ( c . signum ( ) < 0 ) { throw new IllegalArgumentException ( cName + " is negative" ) ; } } else if ( field instanceof ECFieldF2m ) { int m = ( ( ECFieldF2m ) field ) . getM ( ) ; if ( c . bitLength ( ) > m ) { throw new IllegalArgumentException ( cName + " is too large" ) ; } } }
Check coefficient c is a valid element in ECField field .
27,463
private static void checkName ( String zoneId ) { int n = zoneId . length ( ) ; if ( n < 2 ) { throw new DateTimeException ( "Invalid ID for region-based ZoneId, invalid format: " + zoneId ) ; } for ( int i = 0 ; i < n ; i ++ ) { char c = zoneId . charAt ( i ) ; if ( c >= 'a' && c <= 'z' ) continue ; if ( c >= 'A' && c <= 'Z' ) continue ; if ( c == '/' && i != 0 ) continue ; if ( c >= '0' && c <= '9' && i != 0 ) continue ; if ( c == '~' && i != 0 ) continue ; if ( c == '.' && i != 0 ) continue ; if ( c == '_' && i != 0 ) continue ; if ( c == '+' && i != 0 ) continue ; if ( c == '-' && i != 0 ) continue ; throw new DateTimeException ( "Invalid ID for region-based ZoneId, invalid format: " + zoneId ) ; } }
Checks that the given string is a legal ZondId name .
27,464
@ SuppressWarnings ( "unchecked" ) final int compare ( Object k1 , Object k2 ) { return comparator == null ? ( ( Comparable < ? super K > ) k1 ) . compareTo ( ( K ) k2 ) : comparator . compare ( ( K ) k1 , ( K ) k2 ) ; }
Compares two keys using the correct comparison method for this TreeMap .
27,465
void readTreeSet ( int size , java . io . ObjectInputStream s , V defaultVal ) throws java . io . IOException , ClassNotFoundException { buildFromSorted ( size , null , s , defaultVal ) ; }
Intended to be called only from TreeSet . readObject
27,466
static < K > Spliterator < K > keySpliteratorFor ( NavigableMap < K , ? > m ) { if ( m instanceof TreeMap ) { @ SuppressWarnings ( "unchecked" ) TreeMap < K , Object > t = ( TreeMap < K , Object > ) m ; return t . keySpliterator ( ) ; } if ( m instanceof DescendingSubMap ) { @ SuppressWarnings ( "unchecked" ) DescendingSubMap < K , ? > dm = ( DescendingSubMap < K , ? > ) m ; TreeMap < K , ? > tm = dm . m ; if ( dm == tm . descendingMap ) { @ SuppressWarnings ( "unchecked" ) TreeMap < K , Object > t = ( TreeMap < K , Object > ) tm ; return t . descendingKeySpliterator ( ) ; } } @ SuppressWarnings ( "unchecked" ) NavigableSubMap < K , ? > sm = ( NavigableSubMap < K , ? > ) m ; return sm . keySpliterator ( ) ; }
Currently we support Spliterator - based versions only for the full map in either plain of descending form otherwise relying on defaults because size estimation for submaps would dominate costs . The type tests needed to check these for key views are not very nice but avoid disrupting existing class structures . Callers must use plain default spliterators if this returns null .
27,467
public static StringPrep getInstance ( int profile ) { if ( profile < 0 || profile > MAX_PROFILE ) { throw new IllegalArgumentException ( "Bad profile type" ) ; } StringPrep instance = null ; synchronized ( CACHE ) { WeakReference < StringPrep > ref = CACHE [ profile ] ; if ( ref != null ) { instance = ref . get ( ) ; } if ( instance == null ) { ByteBuffer bytes = ICUBinary . getRequiredData ( PROFILE_NAMES [ profile ] + ".spp" ) ; if ( bytes != null ) { try { instance = new StringPrep ( bytes ) ; } catch ( IOException e ) { throw new ICUUncheckedIOException ( e ) ; } } if ( instance != null ) { CACHE [ profile ] = new WeakReference < StringPrep > ( instance ) ; } } } return instance ; }
Gets a StringPrep instance for the specified profile
27,468
private static List < X509Certificate > parsePKIPATH ( InputStream is ) throws CertificateException { List < X509Certificate > certList = null ; CertificateFactory certFac = null ; if ( is == null ) { throw new CertificateException ( "input stream is null" ) ; } try { DerInputStream dis = new DerInputStream ( readAllBytes ( is ) ) ; DerValue [ ] seq = dis . getSequence ( 3 ) ; if ( seq . length == 0 ) { return Collections . < X509Certificate > emptyList ( ) ; } certFac = CertificateFactory . getInstance ( "X.509" ) ; certList = new ArrayList < X509Certificate > ( seq . length ) ; for ( int i = seq . length - 1 ; i >= 0 ; i -- ) { certList . add ( ( X509Certificate ) certFac . generateCertificate ( new ByteArrayInputStream ( seq [ i ] . toByteArray ( ) ) ) ) ; } return Collections . unmodifiableList ( certList ) ; } catch ( IOException ioe ) { throw new CertificateException ( "IOException parsing PkiPath data: " + ioe , ioe ) ; } }
Parse a PKIPATH format CertPath from an InputStream . Return an unmodifiable List of the certificates .
27,469
private byte [ ] encodePKIPATH ( ) throws CertificateEncodingException { ListIterator < X509Certificate > li = certs . listIterator ( certs . size ( ) ) ; try { DerOutputStream bytes = new DerOutputStream ( ) ; while ( li . hasPrevious ( ) ) { X509Certificate cert = li . previous ( ) ; if ( certs . lastIndexOf ( cert ) != certs . indexOf ( cert ) ) { throw new CertificateEncodingException ( "Duplicate Certificate" ) ; } byte [ ] encoded = cert . getEncoded ( ) ; bytes . write ( encoded ) ; } DerOutputStream derout = new DerOutputStream ( ) ; derout . write ( DerValue . tag_SequenceOf , bytes ) ; return derout . toByteArray ( ) ; } catch ( IOException ioe ) { throw new CertificateEncodingException ( "IOException encoding " + "PkiPath data: " + ioe , ioe ) ; } }
Encode the CertPath using PKIPATH format .
27,470
public byte [ ] getEncoded ( String encoding ) throws CertificateEncodingException { switch ( encoding ) { case PKIPATH_ENCODING : return encodePKIPATH ( ) ; case PKCS7_ENCODING : return encodePKCS7 ( ) ; default : throw new CertificateEncodingException ( "unsupported encoding" ) ; } }
Returns the encoded form of this certification path using the specified encoding .
27,471
private boolean enqueueLocked ( Reference < ? extends T > r ) { if ( r . queueNext != null ) { return false ; } if ( tail == null ) { head = r ; } else { tail . queueNext = r ; } tail = r ; tail . queueNext = SENTINEL ; return true ; }
Enqueue the given reference onto this queue . The caller is responsible for ensuring the lock is held on this queue and for calling notifyAll on this queue after the reference has been enqueued . Returns true if the reference was enqueued successfully false if the reference had already been enqueued .
27,472
boolean isEnqueued ( Reference < ? extends T > reference ) { synchronized ( lock ) { return reference . queueNext != null && reference . queueNext != sQueueNextUnenqueued ; } }
Test if the given reference object has been enqueued but not yet removed from the queue assuming this is the reference object s queue .
27,473
boolean enqueue ( Reference < ? extends T > reference ) { synchronized ( lock ) { if ( enqueueLocked ( reference ) ) { lock . notifyAll ( ) ; return true ; } return false ; } }
Enqueue the reference object on the receiver .
27,474
public Reference < ? extends T > remove ( long timeout ) throws IllegalArgumentException , InterruptedException { if ( timeout < 0 ) { throw new IllegalArgumentException ( "Negative timeout value" ) ; } synchronized ( lock ) { Reference < ? extends T > r = reallyPollLocked ( ) ; if ( r != null ) return r ; long start = ( timeout == 0 ) ? 0 : System . nanoTime ( ) ; for ( ; ; ) { lock . wait ( timeout ) ; r = reallyPollLocked ( ) ; if ( r != null ) return r ; if ( timeout != 0 ) { long end = System . nanoTime ( ) ; timeout -= ( end - start ) / 1000_000 ; if ( timeout <= 0 ) return null ; start = end ; } } } }
Removes the next reference object in this queue blocking until either one becomes available or the given timeout period expires .
27,475
public synchronized void flush ( ) throws IOException { if ( sink != null ) { if ( sink . closedByReader || closed ) { throw new IOException ( "Pipe closed" ) ; } synchronized ( sink ) { sink . notifyAll ( ) ; } } }
Flushes this output stream and forces any buffered output characters to be written out . This will notify any readers that characters are waiting in the pipe .
27,476
public static ULocale getDefault ( Category category ) { synchronized ( ULocale . class ) { int idx = category . ordinal ( ) ; if ( defaultCategoryULocales [ idx ] == null ) { return ULocale . ROOT ; } if ( JDKLocaleHelper . hasLocaleCategories ( ) ) { Locale currentCategoryDefault = JDKLocaleHelper . getDefault ( category ) ; if ( ! defaultCategoryLocales [ idx ] . equals ( currentCategoryDefault ) ) { defaultCategoryLocales [ idx ] = currentCategoryDefault ; defaultCategoryULocales [ idx ] = forLocale ( currentCategoryDefault ) ; } } else { Locale currentDefault = Locale . getDefault ( ) ; if ( ! defaultLocale . equals ( currentDefault ) ) { defaultLocale = currentDefault ; defaultULocale = forLocale ( currentDefault ) ; for ( Category cat : Category . values ( ) ) { int tmpIdx = cat . ordinal ( ) ; defaultCategoryLocales [ tmpIdx ] = currentDefault ; defaultCategoryULocales [ tmpIdx ] = forLocale ( currentDefault ) ; } } } return defaultCategoryULocales [ idx ] ; } }
Returns the current default ULocale for the specified category .
27,477
private static void appendTag ( String tag , StringBuilder buffer ) { if ( buffer . length ( ) != 0 ) { buffer . append ( UNDERSCORE ) ; } buffer . append ( tag ) ; }
Append a tag to a StringBuilder adding the separator if necessary . The tag must not be a zero - length string .
27,478
private static String createTagString ( String lang , String script , String region , String trailing , String alternateTags ) { LocaleIDParser parser = null ; boolean regionAppended = false ; StringBuilder tag = new StringBuilder ( ) ; if ( ! isEmptyString ( lang ) ) { appendTag ( lang , tag ) ; } else if ( isEmptyString ( alternateTags ) ) { appendTag ( UNDEFINED_LANGUAGE , tag ) ; } else { parser = new LocaleIDParser ( alternateTags ) ; String alternateLang = parser . getLanguage ( ) ; appendTag ( ! isEmptyString ( alternateLang ) ? alternateLang : UNDEFINED_LANGUAGE , tag ) ; } if ( ! isEmptyString ( script ) ) { appendTag ( script , tag ) ; } else if ( ! isEmptyString ( alternateTags ) ) { if ( parser == null ) { parser = new LocaleIDParser ( alternateTags ) ; } String alternateScript = parser . getScript ( ) ; if ( ! isEmptyString ( alternateScript ) ) { appendTag ( alternateScript , tag ) ; } } if ( ! isEmptyString ( region ) ) { appendTag ( region , tag ) ; regionAppended = true ; } else if ( ! isEmptyString ( alternateTags ) ) { if ( parser == null ) { parser = new LocaleIDParser ( alternateTags ) ; } String alternateRegion = parser . getCountry ( ) ; if ( ! isEmptyString ( alternateRegion ) ) { appendTag ( alternateRegion , tag ) ; regionAppended = true ; } } if ( trailing != null && trailing . length ( ) > 1 ) { int separators = 0 ; if ( trailing . charAt ( 0 ) == UNDERSCORE ) { if ( trailing . charAt ( 1 ) == UNDERSCORE ) { separators = 2 ; } } else { separators = 1 ; } if ( regionAppended ) { if ( separators == 2 ) { tag . append ( trailing . substring ( 1 ) ) ; } else { tag . append ( trailing ) ; } } else { if ( separators == 1 ) { tag . append ( UNDERSCORE ) ; } tag . append ( trailing ) ; } } return tag . toString ( ) ; }
Create a tag string from the supplied parameters . The lang script and region parameters may be null references .
27,479
static String createTagString ( String lang , String script , String region , String trailing ) { return createTagString ( lang , script , region , trailing , null ) ; }
Create a tag string from the supplied parameters . The lang script and region parameters may be null references . If the lang parameter is an empty string the default value for an unknown language is written to the output buffer .
27,480
private static int parseTagString ( String localeID , String tags [ ] ) { LocaleIDParser parser = new LocaleIDParser ( localeID ) ; String lang = parser . getLanguage ( ) ; String script = parser . getScript ( ) ; String region = parser . getCountry ( ) ; if ( isEmptyString ( lang ) ) { tags [ 0 ] = UNDEFINED_LANGUAGE ; } else { tags [ 0 ] = lang ; } if ( script . equals ( UNDEFINED_SCRIPT ) ) { tags [ 1 ] = "" ; } else { tags [ 1 ] = script ; } if ( region . equals ( UNDEFINED_REGION ) ) { tags [ 2 ] = "" ; } else { tags [ 2 ] = region ; } String variant = parser . getVariant ( ) ; if ( ! isEmptyString ( variant ) ) { int index = localeID . indexOf ( variant ) ; return index > 0 ? index - 1 : index ; } else { int index = localeID . indexOf ( '@' ) ; return index == - 1 ? localeID . length ( ) : index ; } }
Parse the language script and region subtags from a tag string and return the results .
27,481
private Expression convertWithoutParens ( ExpressionTree condition , TreePath parent ) { Expression result = ( Expression ) convert ( condition , parent ) ; if ( result . getKind ( ) == TreeNode . Kind . PARENTHESIZED_EXPRESSION ) { result = TreeUtil . remove ( ( ( ParenthesizedExpression ) result ) . getExpression ( ) ) ; } return result ; }
javac uses a ParenthesizedExpression for the if do and while statements while JDT doesn t .
27,482
private SourcePosition getNamePosition ( Tree node ) { int start = ( int ) sourcePositions . getStartPosition ( unit , node ) ; if ( start == - 1 ) { return SourcePosition . NO_POSITION ; } String src = newUnit . getSource ( ) ; Kind kind = node . getKind ( ) ; if ( kind == Kind . ANNOTATION_TYPE || kind == Kind . CLASS || kind == Kind . ENUM || kind == Kind . INTERFACE ) { while ( src . charAt ( start ++ ) != ' ' ) { } } else if ( kind != Kind . METHOD && kind != Kind . VARIABLE ) { return getPosition ( node ) ; } if ( ! Character . isJavaIdentifierStart ( src . charAt ( start ) ) ) { return getPosition ( node ) ; } int endPos = start + 1 ; while ( Character . isJavaIdentifierPart ( src . charAt ( endPos ) ) ) { endPos ++ ; } return getSourcePosition ( start , endPos ) ; }
Return best guess for the position of a declaration node s name .
27,483
private static ListMultimap < TreeNode , Comment > findBlockComments ( CompilationUnit unit ) { ListMultimap < TreeNode , Comment > blockComments = MultimapBuilder . hashKeys ( ) . arrayListValues ( ) . build ( ) ; for ( Comment comment : unit . getCommentList ( ) ) { if ( ! comment . isBlockComment ( ) ) { continue ; } int commentPos = comment . getStartPosition ( ) ; AbstractTypeDeclaration containingType = null ; int containingTypePos = - 1 ; for ( AbstractTypeDeclaration type : unit . getTypes ( ) ) { int typePos = type . getStartPosition ( ) ; if ( typePos < 0 ) { continue ; } int typeEnd = typePos + type . getLength ( ) ; if ( commentPos > typePos && commentPos < typeEnd && typePos > containingTypePos ) { containingType = type ; containingTypePos = typePos ; } } blockComments . put ( containingType != null ? containingType : unit , comment ) ; } return blockComments ; }
Finds all block comments and associates them with their containing type . This is trickier than you might expect because of inner types .
27,484
private static void findMethodSignatures ( String code , Set < String > signatures ) { if ( code == null ) { return ; } Matcher matcher = OBJC_METHOD_DECL_PATTERN . matcher ( code ) ; while ( matcher . find ( ) ) { StringBuilder signature = new StringBuilder ( ) ; signature . append ( matcher . group ( 1 ) ) ; if ( matcher . group ( 2 ) != null ) { signature . append ( ':' ) ; String additionalParams = matcher . group ( 3 ) ; if ( additionalParams != null ) { Matcher paramsMatcher = ADDITIONAL_PARAM_PATTERN . matcher ( additionalParams ) ; while ( paramsMatcher . find ( ) ) { signature . append ( paramsMatcher . group ( 1 ) ) . append ( ':' ) ; } } } signatures . add ( signature . toString ( ) ) ; } }
Finds the signatures of methods defined in the native code .
27,485
private static int escape ( char [ ] cc , char c , int index ) { cc [ index ++ ] = '%' ; cc [ index ++ ] = Character . forDigit ( ( c >> 4 ) & 0xF , 16 ) ; cc [ index ++ ] = Character . forDigit ( c & 0xF , 16 ) ; return index ; }
Appends the URL escape sequence for the specified char to the specified StringBuffer .
27,486
private static byte unescape ( String s , int i ) { return ( byte ) Integer . parseInt ( s . substring ( i + 1 , i + 3 ) , 16 ) ; }
Un - escape and return the character at position i in string s .
27,487
public static String decode ( String s ) { int n = s . length ( ) ; if ( ( n == 0 ) || ( s . indexOf ( '%' ) < 0 ) ) return s ; StringBuilder sb = new StringBuilder ( n ) ; ByteBuffer bb = ByteBuffer . allocate ( n ) ; CharBuffer cb = CharBuffer . allocate ( n ) ; CharsetDecoder dec = ThreadLocalCoders . decoderFor ( "UTF-8" ) . onMalformedInput ( CodingErrorAction . REPORT ) . onUnmappableCharacter ( CodingErrorAction . REPORT ) ; char c = s . charAt ( 0 ) ; for ( int i = 0 ; i < n ; ) { assert c == s . charAt ( i ) ; if ( c != '%' ) { sb . append ( c ) ; if ( ++ i >= n ) break ; c = s . charAt ( i ) ; continue ; } bb . clear ( ) ; int ui = i ; for ( ; ; ) { assert ( n - i >= 2 ) ; try { bb . put ( unescape ( s , i ) ) ; } catch ( NumberFormatException e ) { throw new IllegalArgumentException ( ) ; } i += 3 ; if ( i >= n ) break ; c = s . charAt ( i ) ; if ( c != '%' ) break ; } bb . flip ( ) ; cb . clear ( ) ; dec . reset ( ) ; CoderResult cr = dec . decode ( bb , cb , true ) ; if ( cr . isError ( ) ) throw new IllegalArgumentException ( "Error decoding percent encoded characters" ) ; cr = dec . flush ( cb ) ; if ( cr . isError ( ) ) throw new IllegalArgumentException ( "Error decoding percent encoded characters" ) ; sb . append ( cb . flip ( ) . toString ( ) ) ; } return sb . toString ( ) ; }
Returns a new String constructed from the specified String by replacing the URL escape sequences and UTF8 encoding with the characters they represent .
27,488
public String canonizeString ( String file ) { int i = 0 ; int lim = file . length ( ) ; while ( ( i = file . indexOf ( "/../" ) ) >= 0 ) { if ( ( lim = file . lastIndexOf ( '/' , i - 1 ) ) >= 0 ) { file = file . substring ( 0 , lim ) + file . substring ( i + 3 ) ; } else { file = file . substring ( i + 3 ) ; } } while ( ( i = file . indexOf ( "/./" ) ) >= 0 ) { file = file . substring ( 0 , i ) + file . substring ( i + 2 ) ; } while ( file . endsWith ( "/.." ) ) { i = file . indexOf ( "/.." ) ; if ( ( lim = file . lastIndexOf ( '/' , i - 1 ) ) >= 0 ) { file = file . substring ( 0 , lim + 1 ) ; } else { file = file . substring ( 0 , i ) ; } } if ( file . endsWith ( "/." ) ) file = file . substring ( 0 , file . length ( ) - 1 ) ; return file ; }
Returns a canonical version of the specified string .
27,489
private static boolean match ( char c , long lowMask , long highMask ) { if ( c < 64 ) return ( ( 1L << c ) & lowMask ) != 0 ; if ( c < 128 ) return ( ( 1L << ( c - 64 ) ) & highMask ) != 0 ; return false ; }
Tell whether the given character is permitted by the given mask pair
27,490
private static long lowMask ( char first , char last ) { long m = 0 ; int f = Math . max ( Math . min ( first , 63 ) , 0 ) ; int l = Math . max ( Math . min ( last , 63 ) , 0 ) ; for ( int i = f ; i <= l ; i ++ ) m |= 1L << i ; return m ; }
between first and last inclusive
27,491
private static long lowMask ( String chars ) { int n = chars . length ( ) ; long m = 0 ; for ( int i = 0 ; i < n ; i ++ ) { char c = chars . charAt ( i ) ; if ( c < 64 ) m |= ( 1L << c ) ; } return m ; }
Compute the low - order mask for the characters in the given string
27,492
static Inet4Address anyInet4Address ( final NetworkInterface interf ) { return AccessController . doPrivileged ( new PrivilegedAction < Inet4Address > ( ) { public Inet4Address run ( ) { Enumeration < InetAddress > addrs = interf . getInetAddresses ( ) ; while ( addrs . hasMoreElements ( ) ) { InetAddress addr = addrs . nextElement ( ) ; if ( addr instanceof Inet4Address ) { return ( Inet4Address ) addr ; } } return null ; } } ) ; }
Returns any IPv4 address of the given network interface or null if the interface does not have any IPv4 addresses .
27,493
static int inet4AsInt ( InetAddress ia ) { if ( ia instanceof Inet4Address ) { byte [ ] addr = ia . getAddress ( ) ; int address = addr [ 3 ] & 0xFF ; address |= ( ( addr [ 2 ] << 8 ) & 0xFF00 ) ; address |= ( ( addr [ 1 ] << 16 ) & 0xFF0000 ) ; address |= ( ( addr [ 0 ] << 24 ) & 0xFF000000 ) ; return address ; } throw new AssertionError ( "Should not reach here" ) ; }
Returns an IPv4 address as an int .
27,494
static InetAddress inet4FromInt ( int address ) { byte [ ] addr = new byte [ 4 ] ; addr [ 0 ] = ( byte ) ( ( address >>> 24 ) & 0xFF ) ; addr [ 1 ] = ( byte ) ( ( address >>> 16 ) & 0xFF ) ; addr [ 2 ] = ( byte ) ( ( address >>> 8 ) & 0xFF ) ; addr [ 3 ] = ( byte ) ( address & 0xFF ) ; try { return InetAddress . getByAddress ( addr ) ; } catch ( UnknownHostException uhe ) { throw new AssertionError ( "Should not reach here" ) ; } }
Returns an InetAddress from the given IPv4 address represented as an int .
27,495
static byte [ ] inet6AsByteArray ( InetAddress ia ) { if ( ia instanceof Inet6Address ) { return ia . getAddress ( ) ; } if ( ia instanceof Inet4Address ) { byte [ ] ip4address = ia . getAddress ( ) ; byte [ ] address = new byte [ 16 ] ; address [ 10 ] = ( byte ) 0xff ; address [ 11 ] = ( byte ) 0xff ; address [ 12 ] = ip4address [ 0 ] ; address [ 13 ] = ip4address [ 1 ] ; address [ 14 ] = ip4address [ 2 ] ; address [ 15 ] = ip4address [ 3 ] ; return address ; } throw new AssertionError ( "Should not reach here" ) ; }
Returns an IPv6 address as a byte array
27,496
static int join4 ( FileDescriptor fd , int group , int interf , int source ) throws IOException { return joinOrDrop4 ( true , fd , group , interf , source ) ; }
Join IPv4 multicast group
27,497
static void drop4 ( FileDescriptor fd , int group , int interf , int source ) throws IOException { joinOrDrop4 ( false , fd , group , interf , source ) ; }
Drop membership of IPv4 multicast group
27,498
static int block4 ( FileDescriptor fd , int group , int interf , int source ) throws IOException { return blockOrUnblock4 ( true , fd , group , interf , source ) ; }
Block IPv4 source
27,499
static int join6 ( FileDescriptor fd , byte [ ] group , int index , byte [ ] source ) throws IOException { return joinOrDrop6 ( true , fd , group , index , source ) ; }
Join IPv6 multicast group