idx
int64 0
165k
| question
stringlengths 73
4.15k
| target
stringlengths 5
918
| len_question
int64 21
890
| len_target
int64 3
255
|
|---|---|---|---|---|
153,800
|
public LargeObject open ( int oid , int mode , boolean commitOnClose ) throws SQLException { return open ( ( long ) oid , mode , commitOnClose ) ; }
|
This opens an existing large object same as previous method but commits the transaction on close if asked .
| 40
| 19
|
153,801
|
public long createLO ( int mode ) throws SQLException { if ( conn . getAutoCommit ( ) ) { throw new PSQLException ( GT . tr ( "Large Objects may not be used in auto-commit mode." ) , PSQLState . NO_ACTIVE_SQL_TRANSACTION ) ; } FastpathArg [ ] args = new FastpathArg [ 1 ] ; args [ 0 ] = new FastpathArg ( mode ) ; return fp . getOID ( "lo_creat" , args ) ; }
|
This creates a large object returning its OID .
| 116
| 10
|
153,802
|
public void delete ( long oid ) throws SQLException { FastpathArg [ ] args = new FastpathArg [ 1 ] ; args [ 0 ] = Fastpath . createOIDArg ( oid ) ; fp . fastpath ( "lo_unlink" , args ) ; }
|
This deletes a large object .
| 63
| 7
|
153,803
|
public boolean ensureBytes ( int n ) throws IOException { int required = n - endIndex + index ; while ( required > 0 ) { if ( ! readMore ( required ) ) { return false ; } required = n - endIndex + index ; } return true ; }
|
Ensures that the buffer contains at least n bytes . This method invalidates the buffer and index fields .
| 57
| 22
|
153,804
|
private boolean readMore ( int wanted ) throws IOException { if ( endIndex == index ) { index = 0 ; endIndex = 0 ; } int canFit = buffer . length - endIndex ; if ( canFit < wanted ) { // would the wanted bytes fit if we compacted the buffer // and still leave some slack if ( index + canFit > wanted + MINIMUM_READ ) { compact ( ) ; } else { doubleBuffer ( ) ; } canFit = buffer . length - endIndex ; } int read = wrapped . read ( buffer , endIndex , canFit ) ; if ( read < 0 ) { return false ; } endIndex += read ; return true ; }
|
Reads more bytes into the buffer .
| 143
| 8
|
153,805
|
private void moveBufferTo ( byte [ ] dest ) { int size = endIndex - index ; System . arraycopy ( buffer , index , dest , 0 , size ) ; index = 0 ; endIndex = size ; }
|
Moves bytes from the buffer to the beginning of the destination buffer . Also sets the index and endIndex variables .
| 46
| 23
|
153,806
|
public String getRawPropertyValue ( String key ) { String value = super . getProperty ( key ) ; if ( value != null ) { return value ; } for ( Properties properties : defaults ) { value = properties . getProperty ( key ) ; if ( value != null ) { return value ; } } return null ; }
|
Returns raw value of a property without any replacements .
| 67
| 10
|
153,807
|
public synchronized void truncate ( long len ) throws SQLException { checkFreed ( ) ; if ( ! conn . haveMinimumServerVersion ( ServerVersion . v8_3 ) ) { throw new PSQLException ( GT . tr ( "Truncation of large objects is only implemented in 8.3 and later servers." ) , PSQLState . NOT_IMPLEMENTED ) ; } if ( len < 0 ) { throw new PSQLException ( GT . tr ( "Cannot truncate LOB to a negative length." ) , PSQLState . INVALID_PARAMETER_VALUE ) ; } if ( len > Integer . MAX_VALUE ) { if ( support64bit ) { getLo ( true ) . truncate64 ( len ) ; } else { throw new PSQLException ( GT . tr ( "PostgreSQL LOBs can only index to: {0}" , Integer . MAX_VALUE ) , PSQLState . INVALID_PARAMETER_VALUE ) ; } } else { getLo ( true ) . truncate ( ( int ) len ) ; } }
|
For Blobs this should be in bytes while for Clobs it should be in characters . Since we really haven t figured out how to handle character sets for Clobs the current implementation uses bytes for both Blobs and Clobs .
| 241
| 46
|
153,808
|
public synchronized long position ( byte [ ] pattern , long start ) throws SQLException { assertPosition ( start , pattern . length ) ; int position = 1 ; int patternIdx = 0 ; long result = - 1 ; int tmpPosition = 1 ; for ( LOIterator i = new LOIterator ( start - 1 ) ; i . hasNext ( ) ; position ++ ) { byte b = i . next ( ) ; if ( b == pattern [ patternIdx ] ) { if ( patternIdx == 0 ) { tmpPosition = position ; } patternIdx ++ ; if ( patternIdx == pattern . length ) { result = tmpPosition ; break ; } } else { patternIdx = 0 ; } } return result ; }
|
Iterate over the buffer looking for the specified pattern .
| 154
| 11
|
153,809
|
protected void assertPosition ( long pos , long len ) throws SQLException { checkFreed ( ) ; if ( pos < 1 ) { throw new PSQLException ( GT . tr ( "LOB positioning offsets start at 1." ) , PSQLState . INVALID_PARAMETER_VALUE ) ; } if ( pos + len - 1 > Integer . MAX_VALUE ) { throw new PSQLException ( GT . tr ( "PostgreSQL LOBs can only index to: {0}" , Integer . MAX_VALUE ) , PSQLState . INVALID_PARAMETER_VALUE ) ; } }
|
Throws an exception if the pos value exceeds the max value by which the large object API can index .
| 137
| 21
|
153,810
|
public String DsMakeSpn ( String serviceClass , String serviceName , String instanceName , short instancePort , String referrer ) throws LastErrorException { IntByReference spnLength = new IntByReference ( 2048 ) ; char [ ] spn = new char [ spnLength . getValue ( ) ] ; final int ret = NTDSAPI . instance . DsMakeSpnW ( new WString ( serviceClass ) , new WString ( serviceName ) , instanceName == null ? null : new WString ( instanceName ) , instancePort , referrer == null ? null : new WString ( referrer ) , spnLength , spn ) ; if ( ret != NTDSAPI . ERROR_SUCCESS ) { /* Should've thrown LastErrorException, but just in case */ throw new RuntimeException ( "NTDSAPI DsMakeSpn call failed with " + ret ) ; } return new String ( spn , 0 , spnLength . getValue ( ) ) ; }
|
Convenience wrapper for NTDSAPI DsMakeSpn with Java friendly string and exception handling .
| 212
| 21
|
153,811
|
public static long int8 ( byte [ ] bytes , int idx ) { return ( ( long ) ( bytes [ idx + 0 ] & 255 ) << 56 ) + ( ( long ) ( bytes [ idx + 1 ] & 255 ) << 48 ) + ( ( long ) ( bytes [ idx + 2 ] & 255 ) << 40 ) + ( ( long ) ( bytes [ idx + 3 ] & 255 ) << 32 ) + ( ( long ) ( bytes [ idx + 4 ] & 255 ) << 24 ) + ( ( long ) ( bytes [ idx + 5 ] & 255 ) << 16 ) + ( ( long ) ( bytes [ idx + 6 ] & 255 ) << 8 ) + ( bytes [ idx + 7 ] & 255 ) ; }
|
Parses a long value from the byte array .
| 163
| 11
|
153,812
|
public static int int4 ( byte [ ] bytes , int idx ) { return ( ( bytes [ idx ] & 255 ) << 24 ) + ( ( bytes [ idx + 1 ] & 255 ) << 16 ) + ( ( bytes [ idx + 2 ] & 255 ) << 8 ) + ( ( bytes [ idx + 3 ] & 255 ) ) ; }
|
Parses an int value from the byte array .
| 78
| 11
|
153,813
|
public static void int8 ( byte [ ] target , int idx , long value ) { target [ idx + 0 ] = ( byte ) ( value >>> 56 ) ; target [ idx + 1 ] = ( byte ) ( value >>> 48 ) ; target [ idx + 2 ] = ( byte ) ( value >>> 40 ) ; target [ idx + 3 ] = ( byte ) ( value >>> 32 ) ; target [ idx + 4 ] = ( byte ) ( value >>> 24 ) ; target [ idx + 5 ] = ( byte ) ( value >>> 16 ) ; target [ idx + 6 ] = ( byte ) ( value >>> 8 ) ; target [ idx + 7 ] = ( byte ) value ; }
|
Encodes a long value to the byte array .
| 152
| 10
|
153,814
|
public static Encoding getJVMEncoding ( String jvmEncoding ) { if ( "UTF-8" . equals ( jvmEncoding ) ) { return new UTF8Encoding ( ) ; } if ( Charset . isSupported ( jvmEncoding ) ) { return new Encoding ( jvmEncoding ) ; } else { return DEFAULT_ENCODING ; } }
|
Construct an Encoding for a given JVM encoding .
| 84
| 11
|
153,815
|
public static Encoding getDatabaseEncoding ( String databaseEncoding ) { if ( "UTF8" . equals ( databaseEncoding ) ) { return UTF8_ENCODING ; } // If the backend encoding is known and there is a suitable // encoding in the JVM we use that. Otherwise we fall back // to the default encoding of the JVM. String [ ] candidates = encodings . get ( databaseEncoding ) ; if ( candidates != null ) { for ( String candidate : candidates ) { LOGGER . log ( Level . FINEST , "Search encoding candidate {0}" , candidate ) ; if ( Charset . isSupported ( candidate ) ) { return new Encoding ( candidate ) ; } } } // Try the encoding name directly -- maybe the charset has been // provided by the user. if ( Charset . isSupported ( databaseEncoding ) ) { return new Encoding ( databaseEncoding ) ; } // Fall back to default JVM encoding. LOGGER . log ( Level . FINEST , "{0} encoding not found, returning default encoding" , databaseEncoding ) ; return DEFAULT_ENCODING ; }
|
Construct an Encoding for a given database encoding .
| 241
| 10
|
153,816
|
public byte [ ] encode ( String s ) throws IOException { if ( s == null ) { return null ; } return s . getBytes ( encoding ) ; }
|
Encode a string to an array of bytes .
| 34
| 10
|
153,817
|
public String decode ( byte [ ] encodedString , int offset , int length ) throws IOException { return new String ( encodedString , offset , length , encoding ) ; }
|
Decode an array of bytes into a string .
| 35
| 10
|
153,818
|
public static Method getFunction ( String functionName ) { return functionMap . get ( "sql" + functionName . toLowerCase ( Locale . US ) ) ; }
|
get Method object implementing the given function .
| 36
| 8
|
153,819
|
public static String sqlconcat ( List < ? > parsedArgs ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( ' ' ) ; for ( int iArg = 0 ; iArg < parsedArgs . size ( ) ; iArg ++ ) { buf . append ( parsedArgs . get ( iArg ) ) ; if ( iArg != ( parsedArgs . size ( ) - 1 ) ) { buf . append ( " || " ) ; } } return buf . append ( ' ' ) . toString ( ) ; }
|
concat translation .
| 113
| 4
|
153,820
|
public static String sqlinsert ( List < ? > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) != 4 ) { throw new PSQLException ( GT . tr ( "{0} function takes four and only four argument." , "insert" ) , PSQLState . SYNTAX_ERROR ) ; } StringBuilder buf = new StringBuilder ( ) ; buf . append ( "overlay(" ) ; buf . append ( parsedArgs . get ( 0 ) ) . append ( " placing " ) . append ( parsedArgs . get ( 3 ) ) ; buf . append ( " from " ) . append ( parsedArgs . get ( 1 ) ) . append ( " for " ) . append ( parsedArgs . get ( 2 ) ) ; return buf . append ( ' ' ) . toString ( ) ; }
|
insert to overlay translation .
| 177
| 5
|
153,821
|
public static String sqllocate ( List < ? > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) == 2 ) { return "position(" + parsedArgs . get ( 0 ) + " in " + parsedArgs . get ( 1 ) + ")" ; } else if ( parsedArgs . size ( ) == 3 ) { String tmp = "position(" + parsedArgs . get ( 0 ) + " in substring(" + parsedArgs . get ( 1 ) + " from " + parsedArgs . get ( 2 ) + "))" ; return "(" + parsedArgs . get ( 2 ) + "*sign(" + tmp + ")+" + tmp + ")" ; } else { throw new PSQLException ( GT . tr ( "{0} function takes two or three arguments." , "locate" ) , PSQLState . SYNTAX_ERROR ) ; } }
|
locate translation .
| 193
| 4
|
153,822
|
public static String sqlsubstring ( List < ? > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) == 2 ) { return "substr(" + parsedArgs . get ( 0 ) + "," + parsedArgs . get ( 1 ) + ")" ; } else if ( parsedArgs . size ( ) == 3 ) { return "substr(" + parsedArgs . get ( 0 ) + "," + parsedArgs . get ( 1 ) + "," + parsedArgs . get ( 2 ) + ")" ; } else { throw new PSQLException ( GT . tr ( "{0} function takes two or three arguments." , "substring" ) , PSQLState . SYNTAX_ERROR ) ; } }
|
substring to substr translation .
| 159
| 6
|
153,823
|
public static String sqlcurdate ( List < ? > parsedArgs ) throws SQLException { if ( ! parsedArgs . isEmpty ( ) ) { throw new PSQLException ( GT . tr ( "{0} function doesn''t take any argument." , "curdate" ) , PSQLState . SYNTAX_ERROR ) ; } return "current_date" ; }
|
curdate to current_date translation .
| 85
| 9
|
153,824
|
public static String sqlmonthname ( List < ? > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) != 1 ) { throw new PSQLException ( GT . tr ( "{0} function takes one and only one argument." , "monthname" ) , PSQLState . SYNTAX_ERROR ) ; } return "to_char(" + parsedArgs . get ( 0 ) + ",'Month')" ; }
|
monthname translation .
| 97
| 4
|
153,825
|
public static String sqltimestampadd ( List < ? > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) != 3 ) { throw new PSQLException ( GT . tr ( "{0} function takes three and only three arguments." , "timestampadd" ) , PSQLState . SYNTAX_ERROR ) ; } String interval = EscapedFunctions . constantToInterval ( parsedArgs . get ( 0 ) . toString ( ) , parsedArgs . get ( 1 ) . toString ( ) ) ; StringBuilder buf = new StringBuilder ( ) ; buf . append ( "(" ) . append ( interval ) . append ( "+" ) ; buf . append ( parsedArgs . get ( 2 ) ) . append ( ")" ) ; return buf . toString ( ) ; }
|
time stamp add .
| 175
| 4
|
153,826
|
public static Method getFunction ( String functionName ) { Method method = FUNCTION_MAP . get ( functionName ) ; if ( method != null ) { return method ; } String nameLower = functionName . toLowerCase ( Locale . US ) ; if ( nameLower == functionName ) { // Input name was in lower case, the function is not there return null ; } method = FUNCTION_MAP . get ( nameLower ) ; if ( method != null && FUNCTION_MAP . size ( ) < 1000 ) { // Avoid OutOfMemoryError in case input function names are randomized // The number of methods is finite, however the number of upper-lower case combinations // is quite a few (e.g. substr, Substr, sUbstr, SUbstr, etc). FUNCTION_MAP . putIfAbsent ( functionName , method ) ; } return method ; }
|
get Method object implementing the given function
| 190
| 7
|
153,827
|
public static void sqlceiling ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "ceil(" , "ceiling" , parsedArgs ) ; }
|
ceiling to ceil translation
| 51
| 6
|
153,828
|
public static void sqllog ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "ln(" , "log" , parsedArgs ) ; }
|
log to ln translation
| 49
| 5
|
153,829
|
public static void sqllog10 ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "log(" , "log10" , parsedArgs ) ; }
|
log10 to log translation
| 51
| 5
|
153,830
|
public static void sqlpower ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { twoArgumentsFunctionCall ( buf , "pow(" , "power" , parsedArgs ) ; }
|
power to pow translation
| 49
| 4
|
153,831
|
public static void sqltruncate ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { twoArgumentsFunctionCall ( buf , "trunc(" , "truncate" , parsedArgs ) ; }
|
truncate to trunc translation
| 53
| 6
|
153,832
|
public static void sqlchar ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "chr(" , "char" , parsedArgs ) ; }
|
char to chr translation
| 49
| 5
|
153,833
|
public static void sqllcase ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "lower(" , "lcase" , parsedArgs ) ; }
|
lcase to lower translation
| 50
| 5
|
153,834
|
public static void sqlucase ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { singleArgumentFunctionCall ( buf , "upper(" , "ucase" , parsedArgs ) ; }
|
ucase to upper translation
| 50
| 5
|
153,835
|
public static void sqlcurdate ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { zeroArgumentFunctionCall ( buf , "current_date" , "curdate" , parsedArgs ) ; }
|
curdate to current_date translation
| 54
| 8
|
153,836
|
public static void sqlcurtime ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { zeroArgumentFunctionCall ( buf , "current_time" , "curtime" , parsedArgs ) ; }
|
curtime to current_time translation
| 52
| 7
|
153,837
|
public static void sqltimestampadd ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) != 3 ) { throw new PSQLException ( GT . tr ( "{0} function takes three and only three arguments." , "timestampadd" ) , PSQLState . SYNTAX_ERROR ) ; } buf . append ( ' ' ) ; appendInterval ( buf , parsedArgs . get ( 0 ) . toString ( ) , parsedArgs . get ( 1 ) . toString ( ) ) ; buf . append ( ' ' ) . append ( parsedArgs . get ( 2 ) ) . append ( ' ' ) ; }
|
time stamp add
| 153
| 3
|
153,838
|
private static boolean areSameTsi ( String a , String b ) { return a . length ( ) == b . length ( ) && b . length ( ) > SQL_TSI_ROOT . length ( ) && a . regionMatches ( true , SQL_TSI_ROOT . length ( ) , b , SQL_TSI_ROOT . length ( ) , b . length ( ) - SQL_TSI_ROOT . length ( ) ) ; }
|
Compares two TSI intervals . It is
| 100
| 9
|
153,839
|
public static void sqltimestampdiff ( StringBuilder buf , List < ? extends CharSequence > parsedArgs ) throws SQLException { if ( parsedArgs . size ( ) != 3 ) { throw new PSQLException ( GT . tr ( "{0} function takes three and only three arguments." , "timestampdiff" ) , PSQLState . SYNTAX_ERROR ) ; } buf . append ( "extract( " ) . append ( constantToDatePart ( buf , parsedArgs . get ( 0 ) . toString ( ) ) ) . append ( " from (" ) . append ( parsedArgs . get ( 2 ) ) . append ( "-" ) . append ( parsedArgs . get ( 1 ) ) . append ( "))" ) ; }
|
time stamp diff
| 164
| 3
|
153,840
|
private void setPGobject ( int parameterIndex , PGobject x ) throws SQLException { String typename = x . getType ( ) ; int oid = connection . getTypeInfo ( ) . getPGType ( typename ) ; if ( oid == Oid . UNSPECIFIED ) { throw new PSQLException ( GT . tr ( "Unknown type {0}." , typename ) , PSQLState . INVALID_PARAMETER_TYPE ) ; } if ( ( x instanceof PGBinaryObject ) && connection . binaryTransferSend ( oid ) ) { PGBinaryObject binObj = ( PGBinaryObject ) x ; byte [ ] data = new byte [ binObj . lengthInBytes ( ) ] ; binObj . toBytes ( data , 0 ) ; bindBytes ( parameterIndex , data , oid ) ; } else { setString ( parameterIndex , x . getValue ( ) , oid ) ; } }
|
Helper method for setting parameters to PGobject subclasses .
| 206
| 11
|
153,841
|
protected synchronized int convertArrayToBaseOid ( int oid ) { Integer i = pgArrayToPgType . get ( oid ) ; if ( i == null ) { return oid ; } return i ; }
|
Return the oid of the array s base element if it s an array if not return the provided oid . This doesn t do any database lookups so it s only useful for the originally provided type mappings . This is fine for it s intended uses where we only have intimate knowledge of types that are already known to the driver .
| 46
| 68
|
153,842
|
public boolean requiresQuotingSqlType ( int sqlType ) throws SQLException { switch ( sqlType ) { case Types . BIGINT : case Types . DOUBLE : case Types . FLOAT : case Types . INTEGER : case Types . REAL : case Types . SMALLINT : case Types . TINYINT : case Types . NUMERIC : case Types . DECIMAL : return false ; } return true ; }
|
Returns true if particular sqlType requires quoting . This method is used internally by the driver so it might disappear without notice .
| 94
| 24
|
153,843
|
public boolean hasMessagePending ( ) throws IOException { if ( pgInput . available ( ) > 0 ) { return true ; } // In certain cases, available returns 0, yet there are bytes long now = System . currentTimeMillis ( ) ; if ( now < nextStreamAvailableCheckTime && minStreamAvailableCheckDelay != 0 ) { // Do not use ".peek" too often return false ; } nextStreamAvailableCheckTime = now + minStreamAvailableCheckDelay ; int soTimeout = getNetworkTimeout ( ) ; setNetworkTimeout ( 1 ) ; try { return pgInput . peek ( ) != - 1 ; } catch ( SocketTimeoutException e ) { return false ; } finally { setNetworkTimeout ( soTimeout ) ; } }
|
Check for pending backend messages without blocking . Might return false when there actually are messages waiting depending on the characteristics of the underlying socket . This is used to detect asynchronous notifies from the backend when available .
| 157
| 40
|
153,844
|
public void setEncoding ( Encoding encoding ) throws IOException { if ( this . encoding != null && this . encoding . name ( ) . equals ( encoding . name ( ) ) ) { return ; } // Close down any old writer. if ( encodingWriter != null ) { encodingWriter . close ( ) ; } this . encoding = encoding ; // Intercept flush() downcalls from the writer; our caller // will call PGStream.flush() as needed. OutputStream interceptor = new FilterOutputStream ( pgOutput ) { public void flush ( ) throws IOException { } public void close ( ) throws IOException { super . flush ( ) ; } } ; encodingWriter = encoding . getEncodingWriter ( interceptor ) ; }
|
Change the encoding used by this connection .
| 153
| 8
|
153,845
|
public void sendInteger4 ( int val ) throws IOException { int4Buf [ 0 ] = ( byte ) ( val >>> 24 ) ; int4Buf [ 1 ] = ( byte ) ( val >>> 16 ) ; int4Buf [ 2 ] = ( byte ) ( val >>> 8 ) ; int4Buf [ 3 ] = ( byte ) ( val ) ; pgOutput . write ( int4Buf ) ; }
|
Sends a 4 - byte integer to the back end .
| 91
| 12
|
153,846
|
public int receiveInteger4 ( ) throws IOException { if ( pgInput . read ( int4Buf ) != 4 ) { throw new EOFException ( ) ; } return ( int4Buf [ 0 ] & 0xFF ) << 24 | ( int4Buf [ 1 ] & 0xFF ) << 16 | ( int4Buf [ 2 ] & 0xFF ) << 8 | int4Buf [ 3 ] & 0xFF ; }
|
Receives a four byte integer from the backend .
| 98
| 11
|
153,847
|
public String receiveString ( int len ) throws IOException { if ( ! pgInput . ensureBytes ( len ) ) { throw new EOFException ( ) ; } String res = encoding . decode ( pgInput . getBuffer ( ) , pgInput . getIndex ( ) , len ) ; pgInput . skip ( len ) ; return res ; }
|
Receives a fixed - size string from the backend .
| 72
| 12
|
153,848
|
public EncodingPredictor . DecodeResult receiveErrorString ( int len ) throws IOException { if ( ! pgInput . ensureBytes ( len ) ) { throw new EOFException ( ) ; } EncodingPredictor . DecodeResult res ; try { String value = encoding . decode ( pgInput . getBuffer ( ) , pgInput . getIndex ( ) , len ) ; // no autodetect warning as the message was converted on its own res = new EncodingPredictor . DecodeResult ( value , null ) ; } catch ( IOException e ) { res = EncodingPredictor . decode ( pgInput . getBuffer ( ) , pgInput . getIndex ( ) , len ) ; if ( res == null ) { Encoding enc = Encoding . defaultEncoding ( ) ; String value = enc . decode ( pgInput . getBuffer ( ) , pgInput . getIndex ( ) , len ) ; res = new EncodingPredictor . DecodeResult ( value , enc . name ( ) ) ; } } pgInput . skip ( len ) ; return res ; }
|
Receives a fixed - size string from the backend and tries to avoid UTF - 8 decode failed errors .
| 234
| 22
|
153,849
|
public String receiveString ( ) throws IOException { int len = pgInput . scanCStringLength ( ) ; String res = encoding . decode ( pgInput . getBuffer ( ) , pgInput . getIndex ( ) , len - 1 ) ; pgInput . skip ( len ) ; return res ; }
|
Receives a null - terminated string from the backend . If we don t see a null then we assume something has gone wrong .
| 63
| 27
|
153,850
|
public byte [ ] [ ] receiveTupleV3 ( ) throws IOException , OutOfMemoryError { // TODO: use msgSize int msgSize = receiveInteger4 ( ) ; int nf = receiveInteger2 ( ) ; byte [ ] [ ] answer = new byte [ nf ] [ ] ; OutOfMemoryError oom = null ; for ( int i = 0 ; i < nf ; ++ i ) { int size = receiveInteger4 ( ) ; if ( size != - 1 ) { try { answer [ i ] = new byte [ size ] ; receive ( answer [ i ] , 0 , size ) ; } catch ( OutOfMemoryError oome ) { oom = oome ; skip ( size ) ; } } } if ( oom != null ) { throw oom ; } return answer ; }
|
Read a tuple from the back end . A tuple is a two dimensional array of bytes . This variant reads the V3 protocol s tuple representation .
| 174
| 29
|
153,851
|
public void receive ( byte [ ] buf , int off , int siz ) throws IOException { int s = 0 ; while ( s < siz ) { int w = pgInput . read ( buf , off + s , siz - s ) ; if ( w < 0 ) { throw new EOFException ( ) ; } s += w ; } }
|
Reads in a given number of bytes from the backend .
| 75
| 12
|
153,852
|
public void sendStream ( InputStream inStream , int remaining ) throws IOException { int expectedLength = remaining ; if ( streamBuffer == null ) { streamBuffer = new byte [ 8192 ] ; } while ( remaining > 0 ) { int count = ( remaining > streamBuffer . length ? streamBuffer . length : remaining ) ; int readCount ; try { readCount = inStream . read ( streamBuffer , 0 , count ) ; if ( readCount < 0 ) { throw new EOFException ( GT . tr ( "Premature end of input stream, expected {0} bytes, but only read {1}." , expectedLength , expectedLength - remaining ) ) ; } } catch ( IOException ioe ) { while ( remaining > 0 ) { send ( streamBuffer , count ) ; remaining -= count ; count = ( remaining > streamBuffer . length ? streamBuffer . length : remaining ) ; } throw new PGBindException ( ioe ) ; } send ( streamBuffer , readCount ) ; remaining -= readCount ; } }
|
Copy data from an input stream to the connection .
| 216
| 10
|
153,853
|
public void receiveEOF ( ) throws SQLException , IOException { int c = pgInput . read ( ) ; if ( c < 0 ) { return ; } throw new PSQLException ( GT . tr ( "Expected an EOF from server, got: {0}" , c ) , PSQLState . COMMUNICATION_ERROR ) ; }
|
Consume an expected EOF from the backend .
| 78
| 10
|
153,854
|
public static void reportHostStatus ( HostSpec hostSpec , HostStatus hostStatus ) { long now = currentTimeMillis ( ) ; synchronized ( hostStatusMap ) { HostSpecStatus hostSpecStatus = hostStatusMap . get ( hostSpec ) ; if ( hostSpecStatus == null ) { hostSpecStatus = new HostSpecStatus ( hostSpec ) ; hostStatusMap . put ( hostSpec , hostSpecStatus ) ; } hostSpecStatus . status = hostStatus ; hostSpecStatus . lastUpdated = now ; } }
|
Store the actual observed host status .
| 109
| 7
|
153,855
|
static List < HostSpec > getCandidateHosts ( HostSpec [ ] hostSpecs , HostRequirement targetServerType , long hostRecheckMillis ) { List < HostSpec > candidates = new ArrayList < HostSpec > ( hostSpecs . length ) ; long latestAllowedUpdate = currentTimeMillis ( ) - hostRecheckMillis ; synchronized ( hostStatusMap ) { for ( HostSpec hostSpec : hostSpecs ) { HostSpecStatus hostInfo = hostStatusMap . get ( hostSpec ) ; // candidates are nodes we do not know about and the nodes with correct type if ( hostInfo == null || hostInfo . lastUpdated < latestAllowedUpdate || targetServerType . allowConnectingTo ( hostInfo . status ) ) { candidates . add ( hostSpec ) ; } } } return candidates ; }
|
Returns a list of candidate hosts that have the required targetServerType .
| 177
| 14
|
153,856
|
@ Override public boolean isSSPISupported ( ) { try { /* * SSPI is windows-only. Attempt to use JNA to identify the platform. If Waffle is missing we * won't have JNA and this will throw a NoClassDefFoundError. */ if ( ! Platform . isWindows ( ) ) { LOGGER . log ( Level . FINE , "SSPI not supported: non-Windows host" ) ; return false ; } /* Waffle must be on the CLASSPATH */ Class . forName ( "waffle.windows.auth.impl.WindowsSecurityContextImpl" ) ; return true ; } catch ( NoClassDefFoundError ex ) { LOGGER . log ( Level . WARNING , "SSPI unavailable (no Waffle/JNA libraries?)" , ex ) ; return false ; } catch ( ClassNotFoundException ex ) { LOGGER . log ( Level . WARNING , "SSPI unavailable (no Waffle/JNA libraries?)" , ex ) ; return false ; } }
|
Test whether we can attempt SSPI authentication . If false do not attempt to call any other SSPIClient methods .
| 222
| 26
|
153,857
|
@ Override public void continueSSPI ( int msgLength ) throws SQLException , IOException { if ( sspiContext == null ) { throw new IllegalStateException ( "Cannot continue SSPI authentication that we didn't begin" ) ; } LOGGER . log ( Level . FINEST , "Continuing SSPI negotiation" ) ; /* Read the response token from the server */ byte [ ] receivedToken = pgStream . receive ( msgLength ) ; SecBufferDesc continueToken = new SecBufferDesc ( Sspi . SECBUFFER_TOKEN , receivedToken ) ; sspiContext . initialize ( sspiContext . getHandle ( ) , continueToken , targetName ) ; /* * Now send the response token. If negotiation is complete there may be zero bytes to send, in * which case we shouldn't send a reply as the server is not expecting one; see fe-auth.c in * libpq for details. */ byte [ ] responseToken = sspiContext . getToken ( ) ; if ( responseToken . length > 0 ) { sendSSPIResponse ( responseToken ) ; LOGGER . log ( Level . FINEST , "Sent SSPI negotiation continuation message" ) ; } else { LOGGER . log ( Level . FINEST , "SSPI authentication complete, no reply required" ) ; } }
|
Continue an existing authentication conversation with the back - end in resonse to an authentication request of type AUTH_REQ_GSS_CONT .
| 289
| 29
|
153,858
|
@ Override public void dispose ( ) { if ( sspiContext != null ) { sspiContext . dispose ( ) ; sspiContext = null ; } if ( clientCredentials != null ) { clientCredentials . dispose ( ) ; clientCredentials = null ; } }
|
Clean up native win32 resources after completion or failure of SSPI authentication . This SSPIClient instance becomes unusable after disposal .
| 64
| 29
|
153,859
|
public Connection getConnection ( String user , String password ) throws SQLException { try { Connection con = DriverManager . getConnection ( getUrl ( ) , user , password ) ; if ( LOGGER . isLoggable ( Level . FINE ) ) { LOGGER . log ( Level . FINE , "Created a {0} for {1} at {2}" , new Object [ ] { getDescription ( ) , user , getUrl ( ) } ) ; } return con ; } catch ( SQLException e ) { LOGGER . log ( Level . FINE , "Failed to create a {0} for {1} at {2}: {3}" , new Object [ ] { getDescription ( ) , user , getUrl ( ) , e } ) ; throw e ; } }
|
Gets a connection to the PostgreSQL database . The database is identified by the DataSource properties serverName databaseName and portNumber . The user to connect as is identified by the arguments user and password which override the DataSource properties by the same name .
| 170
| 51
|
153,860
|
public void toBytes ( byte [ ] b , int offset ) { ByteConverter . float8 ( b , offset , x ) ; ByteConverter . float8 ( b , offset + 8 , y ) ; }
|
Populate the byte array with PGpoint in the binary syntax expected by org . postgresql .
| 47
| 20
|
153,861
|
@ Deprecated public static boolean verifyHostName ( String hostname , String pattern ) { String canonicalHostname ; if ( hostname . startsWith ( "[" ) && hostname . endsWith ( "]" ) ) { // IPv6 address like [2001:db8:0:1:1:1:1:1] canonicalHostname = hostname . substring ( 1 , hostname . length ( ) - 1 ) ; } else { // This converts unicode domain name to ASCII try { canonicalHostname = IDN . toASCII ( hostname ) ; } catch ( IllegalArgumentException e ) { // e.g. hostname is invalid return false ; } } return PGjdbcHostnameVerifier . INSTANCE . verifyHostName ( canonicalHostname , pattern ) ; }
|
Verifies if given hostname matches pattern .
| 169
| 9
|
153,862
|
public String getValue ( ) { StringBuilder b = new StringBuilder ( open ? "[" : "(" ) ; for ( int p = 0 ; p < points . length ; p ++ ) { if ( p > 0 ) { b . append ( "," ) ; } b . append ( points [ p ] . toString ( ) ) ; } b . append ( open ? "]" : ")" ) ; return b . toString ( ) ; }
|
This returns the path in the syntax expected by org . postgresql .
| 95
| 15
|
153,863
|
public static boolean parseDeleteKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 6 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' ; }
|
Parse string to check presence of DELETE keyword regardless of case . The initial character is assumed to have been matched .
| 119
| 25
|
153,864
|
public static boolean parseInsertKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 7 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' ; }
|
Parse string to check presence of INSERT keyword regardless of case .
| 119
| 14
|
153,865
|
public static boolean parseMoveKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 4 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' ; }
|
Parse string to check presence of MOVE keyword regardless of case .
| 91
| 14
|
153,866
|
public static boolean parseReturningKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 9 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' && ( query [ offset + 6 ] | 32 ) == ' ' && ( query [ offset + 7 ] | 32 ) == ' ' && ( query [ offset + 8 ] | 32 ) == ' ' ; }
|
Parse string to check presence of RETURNING keyword regardless of case .
| 162
| 15
|
153,867
|
public static boolean parseSelectKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 6 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' ; }
|
Parse string to check presence of SELECT keyword regardless of case .
| 119
| 13
|
153,868
|
public static boolean parseUpdateKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 6 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' ; }
|
Parse string to check presence of UPDATE keyword regardless of case .
| 119
| 13
|
153,869
|
public static boolean parseValuesKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 6 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' && ( query [ offset + 4 ] | 32 ) == ' ' && ( query [ offset + 5 ] | 32 ) == ' ' ; }
|
Parse string to check presence of VALUES keyword regardless of case .
| 119
| 14
|
153,870
|
public static boolean parseWithKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 4 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' && ( query [ offset + 2 ] | 32 ) == ' ' && ( query [ offset + 3 ] | 32 ) == ' ' ; }
|
Parse string to check presence of WITH keyword regardless of case .
| 91
| 13
|
153,871
|
public static boolean parseAsKeyword ( final char [ ] query , int offset ) { if ( query . length < ( offset + 2 ) ) { return false ; } return ( query [ offset ] | 32 ) == ' ' && ( query [ offset + 1 ] | 32 ) == ' ' ; }
|
Parse string to check presence of AS keyword regardless of case .
| 63
| 13
|
153,872
|
private static boolean subArraysEqual ( final char [ ] arr , final int offA , final int offB , final int len ) { if ( offA < 0 || offB < 0 || offA >= arr . length || offB >= arr . length || offA + len > arr . length || offB + len > arr . length ) { return false ; } for ( int i = 0 ; i < len ; ++ i ) { if ( arr [ offA + i ] != arr [ offB + i ] ) { return false ; } } return true ; }
|
Compares two sub - arrays of the given character array for equalness . If the length is zero the result is true if and only if the offsets are within the bounds of the array .
| 122
| 38
|
153,873
|
private static int escapeFunctionArguments ( StringBuilder newsql , String functionName , char [ ] sql , int i , boolean stdStrings ) throws SQLException { // Maximum arity of functions in EscapedFunctions is 3 List < CharSequence > parsedArgs = new ArrayList < CharSequence > ( 3 ) ; while ( true ) { StringBuilder arg = new StringBuilder ( ) ; int lastPos = i ; i = parseSql ( sql , i , arg , true , stdStrings ) ; if ( i != lastPos ) { parsedArgs . add ( arg ) ; } if ( i >= sql . length // should not happen || sql [ i ] != ' ' ) { break ; } i ++ ; } Method method = EscapedFunctions2 . getFunction ( functionName ) ; if ( method == null ) { newsql . append ( functionName ) ; EscapedFunctions2 . appendCall ( newsql , "(" , "," , ")" , parsedArgs ) ; return i ; } try { method . invoke ( null , newsql , parsedArgs ) ; } catch ( InvocationTargetException e ) { Throwable targetException = e . getTargetException ( ) ; if ( targetException instanceof SQLException ) { throw ( SQLException ) targetException ; } else { throw new PSQLException ( targetException . getMessage ( ) , PSQLState . SYSTEM_ERROR ) ; } } catch ( IllegalAccessException e ) { throw new PSQLException ( e . getMessage ( ) , PSQLState . SYSTEM_ERROR ) ; } return i ; }
|
Generate sql for escaped functions .
| 343
| 7
|
153,874
|
@ Override public Connection getConnection ( ) throws SQLException { Connection conn = super . getConnection ( ) ; // When we're outside an XA transaction, autocommit // is supposed to be true, per usual JDBC convention. // When an XA transaction is in progress, it should be // false. if ( state == State . IDLE ) { conn . setAutoCommit ( true ) ; } /* * Wrap the connection in a proxy to forbid application from fiddling with transaction state * directly during an XA transaction */ ConnectionHandler handler = new ConnectionHandler ( conn ) ; return ( Connection ) Proxy . newProxyInstance ( getClass ( ) . getClassLoader ( ) , new Class [ ] { Connection . class , PGConnection . class } , handler ) ; }
|
XAConnection interface .
| 165
| 7
|
153,875
|
@ Override public void forget ( Xid xid ) throws XAException { throw new PGXAException ( GT . tr ( "Heuristic commit/rollback not supported. forget xid={0}" , xid ) , XAException . XAER_NOTA ) ; }
|
Does nothing since we don t do heuristics .
| 62
| 11
|
153,876
|
@ TargetApi ( Build . VERSION_CODES . JELLY_BEAN ) public static void detach ( Activity activity , ViewTreeObserver . OnGlobalLayoutListener l ) { ViewGroup contentView = activity . findViewById ( android . R . id . content ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN ) { contentView . getViewTreeObserver ( ) . removeOnGlobalLayoutListener ( l ) ; } else { //noinspection deprecation contentView . getViewTreeObserver ( ) . removeGlobalOnLayoutListener ( l ) ; } }
|
Remove the OnGlobalLayoutListener from the activity root view
| 141
| 11
|
153,877
|
public void onClickExtraThemeResolved ( final View view ) { final boolean fullScreenTheme = mFullScreenRb . isChecked ( ) ; Intent i = new Intent ( this , ChattingResolvedHandleByPlaceholderActivity . class ) ; i . putExtra ( KEY_FULL_SCREEN_THEME , fullScreenTheme ) ; startActivity ( i ) ; }
|
Resolved for Full Screen Theme or Translucent Status Theme .
| 83
| 12
|
153,878
|
public static void hidePanelAndKeyboard ( final View panelLayout ) { final Activity activity = ( Activity ) panelLayout . getContext ( ) ; final View focusView = activity . getCurrentFocus ( ) ; if ( focusView != null ) { KeyboardUtil . hideKeyboard ( activity . getCurrentFocus ( ) ) ; focusView . clearFocus ( ) ; } panelLayout . setVisibility ( View . GONE ) ; }
|
Hide the panel and the keyboard .
| 91
| 7
|
153,879
|
public static Typeface getTypeface ( Context context , IconSet iconSet ) { String path = iconSet . fontPath ( ) . toString ( ) ; if ( TYPEFACE_MAP . get ( path ) == null ) { final Typeface font = Typeface . createFromAsset ( context . getAssets ( ) , path ) ; TYPEFACE_MAP . put ( path , font ) ; } return TYPEFACE_MAP . get ( path ) ; }
|
Returns a reference to the requested typeface creating a new instance if none already exists
| 96
| 16
|
153,880
|
public static void registerDefaultIconSets ( ) { final FontAwesome fontAwesome = new FontAwesome ( ) ; final Typicon typicon = new Typicon ( ) ; final MaterialIcons materialIcons = new MaterialIcons ( ) ; REGISTERED_ICON_SETS . put ( fontAwesome . fontPath ( ) , fontAwesome ) ; REGISTERED_ICON_SETS . put ( typicon . fontPath ( ) , typicon ) ; REGISTERED_ICON_SETS . put ( materialIcons . fontPath ( ) , materialIcons ) ; }
|
Registers instances of the Default IconSets so that they are available throughout the whole application . Currently the default icon sets include FontAwesome and Typicon .
| 125
| 31
|
153,881
|
public static IconSet retrieveRegisteredIconSet ( String fontPath , boolean editMode ) { final IconSet iconSet = REGISTERED_ICON_SETS . get ( fontPath ) ; if ( iconSet == null && ! editMode ) { throw new RuntimeException ( String . format ( "Font '%s' not properly registered, please" + " see the README at https://github.com/Bearded-Hen/Android-Bootstrap" , fontPath ) ) ; } return iconSet ; }
|
Retrieves a registered IconSet whose font can be found in the asset directory at the given path
| 108
| 20
|
153,882
|
void onRadioToggle ( int index ) { for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { if ( i != index ) { BootstrapButton b = retrieveButtonChild ( i ) ; b . setSelected ( false ) ; } } }
|
Used for Radio Group Mode - resets all children to an unselected state apart from the calling Button .
| 60
| 21
|
153,883
|
public void startFlashing ( boolean forever , AnimationSpeed speed ) { Animation fadeIn = new AlphaAnimation ( 0 , 1 ) ; //set up extra variables fadeIn . setDuration ( 50 ) ; fadeIn . setRepeatMode ( Animation . REVERSE ) ; //default repeat count is 0, however if user wants, set it up to be infinite fadeIn . setRepeatCount ( 0 ) ; if ( forever ) { fadeIn . setRepeatCount ( Animation . INFINITE ) ; } fadeIn . setStartOffset ( speed . getFlashDuration ( ) ) ; startAnimation ( fadeIn ) ; }
|
Starts a Flashing Animation on the AwesomeTextView
| 127
| 11
|
153,884
|
public void startRotate ( boolean clockwise , AnimationSpeed speed ) { Animation rotate ; //set up the rotation animation if ( clockwise ) { rotate = new RotateAnimation ( 0 , 360 , Animation . RELATIVE_TO_SELF , 0.5f , Animation . RELATIVE_TO_SELF , 0.5f ) ; } else { rotate = new RotateAnimation ( 360 , 0 , Animation . RELATIVE_TO_SELF , 0.5f , Animation . RELATIVE_TO_SELF , 0.5f ) ; } //set up some extra variables rotate . setRepeatCount ( Animation . INFINITE ) ; rotate . setInterpolator ( new LinearInterpolator ( ) ) ; rotate . setStartOffset ( 0 ) ; rotate . setRepeatMode ( Animation . RESTART ) ; rotate . setDuration ( speed . getRotateDuration ( ) ) ; startAnimation ( rotate ) ; }
|
Starts a rotating animation on the AwesomeTextView
| 196
| 10
|
153,885
|
private static IconSet resolveIconSet ( String iconCode ) { CharSequence unicode ; for ( IconSet set : getRegisteredIconSets ( ) ) { if ( set . fontPath ( ) . equals ( FontAwesome . FONT_PATH ) || set . fontPath ( ) . equals ( Typicon . FONT_PATH ) || set . fontPath ( ) . equals ( MaterialIcons . FONT_PATH ) ) { continue ; // already checked previously, ignore } unicode = set . unicodeForKey ( iconCode ) ; if ( unicode != null ) { return set ; } } String message = String . format ( "Could not find FontIcon value for '%s', " + "please ensure that it is mapped to a valid font" , iconCode ) ; throw new IllegalArgumentException ( message ) ; }
|
Searches for the unicode character value for the Font Icon Code . This method searches all active FontIcons in the application .
| 177
| 27
|
153,886
|
private float measureStringWidth ( String text ) { Paint mPaint = new Paint ( ) ; mPaint . setTextSize ( baselineDropDownViewFontSize * bootstrapSize ) ; return ( float ) ( DimenUtils . dpToPixels ( mPaint . measureText ( text ) ) ) ; }
|
Calculating string width
| 68
| 5
|
153,887
|
private String getLongestString ( String [ ] array ) { int maxLength = 0 ; String longestString = null ; for ( String s : array ) { if ( s . length ( ) > maxLength ) { maxLength = s . length ( ) ; longestString = s ; } } return longestString ; }
|
Searching for longest string in array
| 66
| 7
|
153,888
|
private void addEmptyProgressBar ( ) { int whereIsEmpty = - 1 ; for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { if ( retrieveChild ( i ) != null && retrieveChild ( i ) . equals ( emptyProgressBar ) ) { whereIsEmpty = i ; } } if ( whereIsEmpty != getChildCount ( ) - 1 ) { if ( whereIsEmpty != - 1 ) { //the flowing true/false is to stop empty progressbar being added more than once as removeView and addView indirectly call this method isEmptyBeingAdded = true ; removeView ( emptyProgressBar ) ; isEmptyBeingAdded = false ; } if ( ! isEmptyBeingAdded ) { addView ( emptyProgressBar ) ; } } }
|
This looks for instances of emptyProgressBar and removes them if they are not at the end and then adds one at the end if its needed .
| 163
| 29
|
153,889
|
public int getCumulativeProgress ( ) { int numChildren = getChildCount ( ) ; int total = 0 ; for ( int i = 0 ; i < numChildren ; i ++ ) { total += getChildProgress ( i ) ; } checkCumulativeSmallerThanMax ( maxProgress , total ) ; return total ; }
|
This get the total progress of all the children
| 71
| 9
|
153,890
|
@ Override public void setStriped ( boolean striped ) { this . striped = striped ; for ( int i = 0 ; i < getChildCount ( ) ; i ++ ) { retrieveChild ( i ) . setStriped ( striped ) ; } }
|
This will set all children to striped .
| 55
| 8
|
153,891
|
static Drawable bootstrapButton ( Context context , BootstrapBrand brand , int strokeWidth , int cornerRadius , ViewGroupPosition position , boolean showOutline , boolean rounded ) { GradientDrawable defaultGd = new GradientDrawable ( ) ; GradientDrawable activeGd = new GradientDrawable ( ) ; GradientDrawable disabledGd = new GradientDrawable ( ) ; defaultGd . setColor ( showOutline ? Color . TRANSPARENT : brand . defaultFill ( context ) ) ; activeGd . setColor ( showOutline ? brand . activeFill ( context ) : brand . activeFill ( context ) ) ; disabledGd . setColor ( showOutline ? Color . TRANSPARENT : brand . disabledFill ( context ) ) ; defaultGd . setStroke ( strokeWidth , brand . defaultEdge ( context ) ) ; activeGd . setStroke ( strokeWidth , brand . activeEdge ( context ) ) ; disabledGd . setStroke ( strokeWidth , brand . disabledEdge ( context ) ) ; if ( showOutline && brand instanceof DefaultBootstrapBrand ) { DefaultBootstrapBrand db = ( DefaultBootstrapBrand ) brand ; if ( db == DefaultBootstrapBrand . SECONDARY ) { int color = ColorUtils . resolveColor ( R . color . bootstrap_brand_secondary_border , context ) ; defaultGd . setStroke ( strokeWidth , color ) ; activeGd . setStroke ( strokeWidth , color ) ; disabledGd . setStroke ( strokeWidth , color ) ; } } setupDrawableCorners ( position , rounded , cornerRadius , defaultGd , activeGd , disabledGd ) ; return setupStateDrawable ( position , strokeWidth , defaultGd , activeGd , disabledGd ) ; }
|
Generates a background drawable for a Bootstrap Button
| 399
| 11
|
153,892
|
static Drawable bootstrapLabel ( Context context , BootstrapBrand bootstrapBrand , boolean rounded , float height ) { int cornerRadius = ( int ) DimenUtils . pixelsFromDpResource ( context , R . dimen . bootstrap_default_corner_radius ) ; GradientDrawable drawable = new GradientDrawable ( ) ; drawable . setColor ( bootstrapBrand . defaultFill ( context ) ) ; // corner radius should be half height if rounded as a "Pill" label drawable . setCornerRadius ( rounded ? height / 2 : cornerRadius ) ; return drawable ; }
|
Generates a Drawable for a Bootstrap Label background according to state parameters
| 134
| 15
|
153,893
|
static Drawable bootstrapEditText ( Context context , BootstrapBrand bootstrapBrand , float strokeWidth , float cornerRadius , boolean rounded ) { StateListDrawable drawable = new StateListDrawable ( ) ; GradientDrawable activeDrawable = new GradientDrawable ( ) ; GradientDrawable disabledDrawable = new GradientDrawable ( ) ; GradientDrawable defaultDrawable = new GradientDrawable ( ) ; activeDrawable . setColor ( ColorUtils . resolveColor ( android . R . color . white , context ) ) ; disabledDrawable . setColor ( ColorUtils . resolveColor ( android . R . color . white , context ) ) ; defaultDrawable . setColor ( ColorUtils . resolveColor ( android . R . color . white , context ) ) ; if ( rounded ) { activeDrawable . setCornerRadius ( cornerRadius ) ; disabledDrawable . setCornerRadius ( cornerRadius ) ; defaultDrawable . setCornerRadius ( cornerRadius ) ; } // stroke is larger when focused int defaultBorder = ColorUtils . resolveColor ( R . color . bootstrap_brand_secondary_border , context ) ; int disabledBorder = ColorUtils . resolveColor ( R . color . bootstrap_edittext_disabled , context ) ; activeDrawable . setStroke ( ( int ) strokeWidth , bootstrapBrand . defaultEdge ( context ) ) ; disabledDrawable . setStroke ( ( int ) strokeWidth , disabledBorder ) ; defaultDrawable . setStroke ( ( int ) strokeWidth , defaultBorder ) ; drawable . addState ( new int [ ] { android . R . attr . state_focused } , activeDrawable ) ; drawable . addState ( new int [ ] { - android . R . attr . state_enabled } , disabledDrawable ) ; drawable . addState ( new int [ ] { } , defaultDrawable ) ; return drawable ; }
|
Generates a Drawable for a Bootstrap Edit Text background
| 427
| 12
|
153,894
|
static ColorStateList bootstrapButtonText ( Context context , boolean outline , BootstrapBrand brand ) { int defaultColor = outline ? brand . defaultFill ( context ) : brand . defaultTextColor ( context ) ; int activeColor = outline ? ColorUtils . resolveColor ( android . R . color . white , context ) : brand . activeTextColor ( context ) ; int disabledColor = outline ? brand . disabledFill ( context ) : brand . disabledTextColor ( context ) ; if ( outline && brand instanceof DefaultBootstrapBrand ) { // special case DefaultBootstrapBrand db = ( DefaultBootstrapBrand ) brand ; if ( db == DefaultBootstrapBrand . SECONDARY ) { defaultColor = ColorUtils . resolveColor ( R . color . bootstrap_brand_secondary_border , context ) ; disabledColor = defaultColor ; } } return new ColorStateList ( getStateList ( ) , getColorList ( defaultColor , activeColor , disabledColor ) ) ; }
|
Generates a colorstatelist for a bootstrap button
| 203
| 11
|
153,895
|
private static Drawable createArrowIcon ( Context context , int width , int height , int color , ExpandDirection expandDirection ) { Bitmap canvasBitmap = Bitmap . createBitmap ( width , height , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( canvasBitmap ) ; Paint paint = new Paint ( ) ; paint . setStyle ( Paint . Style . FILL_AND_STROKE ) ; paint . setStrokeWidth ( 1 ) ; paint . setColor ( color ) ; paint . setAntiAlias ( true ) ; Path path = new Path ( ) ; path . setFillType ( Path . FillType . EVEN_ODD ) ; switch ( expandDirection ) { case UP : path . moveTo ( 0 , ( height / 3 ) * 2 ) ; path . lineTo ( width , ( height / 3 ) * 2 ) ; path . lineTo ( width / 2 , height / 3 ) ; path . lineTo ( 0 , ( height / 3 ) * 2 ) ; break ; case DOWN : path . moveTo ( 0 , height / 3 ) ; path . lineTo ( width , height / 3 ) ; path . lineTo ( width / 2 , ( height / 3 ) * 2 ) ; path . lineTo ( 0 , height / 3 ) ; break ; } path . close ( ) ; canvas . drawPath ( path , paint ) ; return new BitmapDrawable ( context . getResources ( ) , canvasBitmap ) ; }
|
Creates arrow icon that depends on ExpandDirection
| 321
| 10
|
153,896
|
private void startStripedAnimationIfNeeded ( ) { if ( ! striped || ! animated ) { return ; } clearAnimation ( ) ; progressAnimator = ValueAnimator . ofFloat ( 0 , 0 ) ; progressAnimator . setDuration ( UPDATE_ANIM_MS ) ; progressAnimator . setRepeatCount ( ValueAnimator . INFINITE ) ; progressAnimator . setRepeatMode ( ValueAnimator . RESTART ) ; progressAnimator . setInterpolator ( new LinearInterpolator ( ) ) ; progressAnimator . addUpdateListener ( new ValueAnimator . AnimatorUpdateListener ( ) { @ Override public void onAnimationUpdate ( ValueAnimator animation ) { invalidate ( ) ; } } ) ; progressAnimator . start ( ) ; }
|
Starts an infinite animation cycle which provides the visual effect of stripes moving backwards . The current system time is used to offset tiled bitmaps of the progress background producing the effect that the stripes are moving backwards .
| 165
| 42
|
153,897
|
private static Bitmap createTile ( float h , Paint stripePaint , Paint progressPaint ) { Bitmap bm = Bitmap . createBitmap ( ( int ) h * 2 , ( int ) h , ARGB_8888 ) ; Canvas tile = new Canvas ( bm ) ; float x = 0 ; Path path = new Path ( ) ; path . moveTo ( x , 0 ) ; path . lineTo ( x , h ) ; path . lineTo ( h , h ) ; tile . drawPath ( path , stripePaint ) ; // draw striped triangle path . reset ( ) ; path . moveTo ( x , 0 ) ; path . lineTo ( x + h , h ) ; path . lineTo ( x + ( h * 2 ) , h ) ; path . lineTo ( x + h , 0 ) ; tile . drawPath ( path , progressPaint ) ; // draw progress parallelogram x += h ; path . reset ( ) ; path . moveTo ( x , 0 ) ; path . lineTo ( x + h , 0 ) ; path . lineTo ( x + h , h ) ; tile . drawPath ( path , stripePaint ) ; // draw striped triangle (completing tile) return bm ; }
|
Creates a Bitmap which is a tile of the progress bar background
| 267
| 14
|
153,898
|
public void setMaxProgress ( int newMaxProgress ) { if ( getProgress ( ) <= newMaxProgress ) { maxProgress = newMaxProgress ; } else { throw new IllegalArgumentException ( String . format ( "MaxProgress cant be smaller than the current progress %d<%d" , getProgress ( ) , newMaxProgress ) ) ; } invalidate ( ) ; BootstrapProgressBarGroup parent = ( BootstrapProgressBarGroup ) getParent ( ) ; }
|
Used for settings the maxprogress . Also check if currentProgress is smaller than newMaxProgress .
| 99
| 19
|
153,899
|
@ Override protected Class < ? > [ ] getHandlerInterfaces ( String serviceName ) { Class < ? > remoteInterface = interfaceMap . get ( serviceName ) ; if ( remoteInterface != null ) { return new Class < ? > [ ] { remoteInterface } ; } else if ( Proxy . isProxyClass ( getHandler ( serviceName ) . getClass ( ) ) ) { return getHandler ( serviceName ) . getClass ( ) . getInterfaces ( ) ; } else { return new Class < ? > [ ] { getHandler ( serviceName ) . getClass ( ) } ; } }
|
Returns the handler s class or interfaces . The serviceName is used to look up a registered handler .
| 127
| 20
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.