idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
37,900
public Fingerprint circleErrorColor ( int circleError ) { this . circleError = circleError ; this . circleView . setBackgroundTintList ( ColorStateList . valueOf ( getContext ( ) . getColor ( circleError ) ) ) ; return this ; }
Set the fingerprint circular background color in error state .
37,901
public static boolean isAvailable ( Context context ) { FingerprintManager fingerprintManager = ( FingerprintManager ) context . getSystemService ( Context . FINGERPRINT_SERVICE ) ; if ( fingerprintManager != null ) { return ( fingerprintManager . isHardwareDetected ( ) && fingerprintManager . hasEnrolledFingerprints ( ) ) ; } return false ; }
Check if fingerprint authentication is supported by the device and if a fingerprint is enrolled in the device .
37,902
public void authenticate ( ) { if ( fingerprintSecureCallback != null ) { if ( cryptoObject != null ) { throw new RuntimeException ( "If you specify a CryptoObject you have to use FingerprintCallback" ) ; } cryptoObject = cipherHelper . getEncryptionCryptoObject ( ) ; if ( cryptoObject == null ) { fingerprintSecureCallback . onNewFingerprintEnrolled ( new FingerprintToken ( cipherHelper ) ) ; } } else if ( fingerprintCallback == null ) { throw new RuntimeException ( "You must specify a callback." ) ; } cancellationSignal = new CancellationSignal ( ) ; if ( fingerprintManager . isHardwareDetected ( ) && fingerprintManager . hasEnrolledFingerprints ( ) ) { fingerprintManager . authenticate ( cryptoObject , cancellationSignal , 0 , new FingerprintManager . AuthenticationCallback ( ) { public void onAuthenticationError ( int errorCode , CharSequence errString ) { super . onAuthenticationError ( errorCode , errString ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationError ( errorCode , errString . toString ( ) ) ; } else { fingerprintCallback . onAuthenticationError ( errorCode , errString . toString ( ) ) ; } } public void onAuthenticationHelp ( int helpCode , CharSequence helpString ) { super . onAuthenticationHelp ( helpCode , helpString ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationError ( helpCode , helpString . toString ( ) ) ; } else { fingerprintCallback . onAuthenticationError ( helpCode , helpString . toString ( ) ) ; } } public void onAuthenticationSucceeded ( final FingerprintManager . AuthenticationResult result ) { super . onAuthenticationSucceeded ( result ) ; handler . removeCallbacks ( returnToScanning ) ; setStatus ( R . drawable . fingerprint_success , fingerprintSuccess , circleSuccess ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationSucceeded ( ) ; } else { fingerprintCallback . onAuthenticationSucceeded ( ) ; } tryCounter = 0 ; } public void onAuthenticationFailed ( ) { super . onAuthenticationFailed ( ) ; setStatus ( R . drawable . fingerprint_error , fingerprintError , circleError ) ; handler . postDelayed ( returnToScanning , delayAfterError ) ; handler . postDelayed ( checkForLimit , delayAfterError ) ; if ( fingerprintSecureCallback != null ) { fingerprintSecureCallback . onAuthenticationFailed ( ) ; } else { fingerprintCallback . onAuthenticationFailed ( ) ; } } } , null ) ; } else { Log . e ( TAG , "Fingerprint scanner not detected or no fingerprint enrolled. Use FingerprintView#isAvailable(Context) before." ) ; } }
start fingerprint scan
37,903
public static boolean isAvailable ( Context context ) { FingerprintManager manager = ( FingerprintManager ) context . getSystemService ( Context . FINGERPRINT_SERVICE ) ; return ( manager != null && manager . isHardwareDetected ( ) && manager . hasEnrolledFingerprints ( ) ) ; }
Check if a fingerprint scanner is available and if at least one finger is enrolled in the phone .
37,904
public FingerprintDialog callback ( FingerprintDialogSecureCallback fingerprintDialogSecureCallback , String KEY_NAME ) { this . fingerprintDialogSecureCallback = fingerprintDialogSecureCallback ; this . fingerprint . callback ( fingerprintSecureCallback , KEY_NAME ) ; return this ; }
Set a callback for secured authentication .
37,905
public FingerprintDialog tryLimit ( int limit , final FailAuthCounterDialogCallback counterCallback ) { this . fingerprint . tryLimit ( limit , new FailAuthCounterCallback ( ) { public void onTryLimitReached ( Fingerprint fingerprint ) { counterCallback . onTryLimitReached ( FingerprintDialog . this ) ; } } ) ; return this ; }
Set a fail limit . Android blocks automatically when 5 attempts failed .
37,906
public void show ( ) { if ( title == null || message == null ) { throw new RuntimeException ( "Title or message cannot be null." ) ; } dialogView = layoutInflater . inflate ( R . layout . password_dialog , null ) ; ( ( TextView ) dialogView . findViewById ( R . id . password_dialog_title ) ) . setText ( title ) ; ( ( TextView ) dialogView . findViewById ( R . id . password_dialog_message ) ) . setText ( message ) ; final EditText input = dialogView . findViewById ( R . id . password_dialog_input ) ; input . setInputType ( passwordType ) ; dialog = builder . setView ( dialogView ) . setPositiveButton ( R . string . password_confirm , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialogInterface , int i ) { } } ) . setNegativeButton ( R . string . password_cancel , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialogInterface , int i ) { if ( callback != null ) { callback . onPasswordCancel ( ) ; } } } ) . create ( ) ; if ( dialog . getWindow ( ) != null ) { if ( enterAnimation != DialogAnimation . Enter . APPEAR || exitAnimation != DialogAnimation . Exit . DISAPPEAR ) { int style = DialogAnimation . getStyle ( enterAnimation , exitAnimation ) ; if ( style != - 1 ) { dialog . getWindow ( ) . getAttributes ( ) . windowAnimations = style ; } else { Log . w ( TAG , "The animation selected is not available. Default animation will be used." ) ; } } if ( ! dimBackground ) { dialog . getWindow ( ) . clearFlags ( WindowManager . LayoutParams . FLAG_DIM_BEHIND ) ; } } else { Log . w ( TAG , "Could not get window from dialog" ) ; } dialog . setCanceledOnTouchOutside ( cancelOnTouchOutside ) ; dialog . setCancelable ( cancelOnPressBack ) ; dialog . show ( ) ; dialog . getButton ( AlertDialog . BUTTON_POSITIVE ) . setOnClickListener ( new View . OnClickListener ( ) { public void onClick ( View v ) { if ( callback != null ) { String password = input . getText ( ) . toString ( ) ; if ( callback . onPasswordCheck ( password ) ) { dialog . dismiss ( ) ; if ( token != null ) { token . validate ( ) ; } callback . onPasswordSucceeded ( ) ; } else { input . setText ( "" ) ; input . setError ( context . getResources ( ) . getString ( R . string . password_incorrect ) ) ; } } } } ) ; }
Show the password dialog
37,907
public void register ( boolean hasHistory , boolean usingHash , boolean usingColonForParametersInUrl ) { this . hasHistory = hasHistory ; this . usingHash = usingHash ; this . usingColonForParametersInUrl = usingColonForParametersInUrl ; }
Do NOT cll this method!
37,908
public String toDebugString ( ) { String name = this . getClass ( ) . getName ( ) ; name = name . substring ( name . lastIndexOf ( "." ) + 1 ) ; return "event: " + name + ":" ; }
This is a method used primarily for debugging . It gives a string representation of the event details . This does not override the toString method because the compiler cannot always optimize toString out correctly . Event types should override as desired .
37,909
@ SuppressWarnings ( "unchecked" ) public < S extends AbstractCompositeController < ? , ? , ? > > S getComposite ( String name ) { return ( S ) this . getComposites ( ) . get ( name ) ; }
Returns the composite stored under the composite name .
37,910
public boolean extendsClassOrInterface ( Types types , TypeMirror typeMirror , TypeMirror toImplement ) { String clearedToImplement = this . removeGenericsFromClassName ( toImplement . toString ( ) ) ; Set < TypeMirror > setOfSuperType = this . getFlattenedSupertypeHierarchy ( types , typeMirror ) ; for ( TypeMirror mirror : setOfSuperType ) { if ( clearedToImplement . equals ( this . removeGenericsFromClassName ( mirror . toString ( ) ) ) ) { return true ; } } return false ; }
checks if a class or interface is implemented .
37,911
public void removeHandlers ( ) { Iterator < HandlerRegistration > it = registrations . iterator ( ) ; while ( it . hasNext ( ) ) { HandlerRegistration r = it . next ( ) ; it . remove ( ) ; r . removeHandler ( ) ; } }
Remove all handlers that have been added through this wrapper .
37,912
public < C extends AbstractComponentController < ? , ? , ? > > void storeInCache ( C controller ) { ControllerFactory . get ( ) . storeInCache ( controller ) ; controller . setCached ( true ) ; }
Stores the instance of the controller in the cache so that it can be reused the next time the route is called .
37,913
public < C extends AbstractComponentController < ? , ? , ? > > void removeFromCache ( C controller ) { ControllerFactory . get ( ) . removeFromCache ( controller ) ; controller . setCached ( false ) ; }
Removes a controller from the chache
37,914
public static void logNewUrl ( String newUrl ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "Router: new url ->>" ) . append ( newUrl ) . append ( "<<" ) ; ClientLogger . get ( ) . logSimple ( sb . toString ( ) , 0 ) ; }
Log s the new URL on the browser s console
37,915
private void onFinishLoading ( ) { String hashOnStart = this . plugin . getStartRoute ( isUsingHash ( ) ) ; if ( hashOnStart != null && hashOnStart . trim ( ) . length ( ) > 0 ) { ClientLogger . get ( ) . logDetailed ( "AbstractApplication: handle history (hash at start: >>" + hashOnStart + "<<" , 1 ) ; RouteResult routeResult ; try { routeResult = this . router . parse ( hashOnStart ) ; } catch ( RouterException e ) { return ; } this . router . route ( routeResult . getRoute ( ) , routeResult . getParameterValues ( ) . toArray ( new String [ 0 ] ) ) ; } else { ClientLogger . get ( ) . logDetailed ( "AbstractApplication: no history found -> use startRoute: >>" + this . startRoute + "<<" , 1 ) ; this . router . route ( this . startRoute ) ; } ClientLogger . get ( ) . logSimple ( "AbstractApplication: application started" , 0 ) ; }
Once the loader did his job we will continue
37,916
public static void setLocalVar ( ExecutionContext context , String name , Object value ) { LexicalEnvironment localEnv = context . getLexicalEnvironment ( ) ; localEnv . getRecord ( ) . createMutableBinding ( context , name , false ) ; localEnv . getRecord ( ) . setMutableBinding ( context , name , value , false ) ; }
A convenience for module providers . Sets a scoped variable on the provided ExecutionContext .
37,917
public static Object getLocalVar ( ExecutionContext context , String name ) { LexicalEnvironment localEnv = context . getLexicalEnvironment ( ) ; if ( localEnv . getRecord ( ) . hasBinding ( context , name ) ) { return localEnv . getRecord ( ) . getBindingValue ( context , name , false ) ; } return null ; }
A convenience for module providers . Gets a scoped variable from the provided ExecutionContext
37,918
protected String normalizeName ( String originalName ) { if ( originalName == null || originalName . endsWith ( ".js" ) ) { return originalName ; } return originalName + ".js" ; }
Helper method . Since module names should not include the . js extension but the actual modules themselves usually do .
37,919
private BasicBlock buildExitBasicBlock ( Stack < ExceptionRegion > nestedExceptionRegions , BasicBlock firstBB , List < BasicBlock > returnBBs , List < BasicBlock > exceptionBBs , boolean nextIsFallThrough , BasicBlock currBB , BasicBlock entryBB ) { exitBB = createBB ( nestedExceptionRegions ) ; graph . addEdge ( entryBB , exitBB , EdgeType . EXIT ) ; graph . addEdge ( entryBB , firstBB , EdgeType . FALL_THROUGH ) ; for ( BasicBlock rb : returnBBs ) { graph . addEdge ( rb , exitBB , EdgeType . EXIT ) ; } for ( BasicBlock rb : exceptionBBs ) { graph . addEdge ( rb , exitBB , EdgeType . EXIT ) ; } if ( nextIsFallThrough ) graph . addEdge ( currBB , exitBB , EdgeType . EXIT ) ; return exitBB ; }
Create special empty exit BasicBlock that all BasicBlocks will eventually flow into . All Edges to this dummy BasicBlock will get marked with an edge type of EXIT .
37,920
public LocalVariable findVariable ( String name , int depth ) { LocalVariable variable = localVariables . get ( name ) ; if ( variable != null ) { if ( depth != 0 ) { return new LocalVariable ( name , variable . getOffset ( ) , depth ) ; } return variable ; } if ( parent != null ) { return parent . findVariable ( name , depth + 1 ) ; } return null ; }
Tries to find a variable or returns null if it cannot . This will walk all scopes to find a captured variable .
37,921
public Variable acquireLocalVariable ( String name ) { int depth = 0 ; LocalVariable variable = findVariable ( name , depth ) ; if ( variable == null ) { variable = new LocalVariable ( name , localVariablesIndex , 0 ) ; localVariables . put ( name , variable ) ; localVariablesIndex ++ ; } return variable ; }
Return an existing variable or return a new one made in this scope .
37,922
protected File findFile ( List < String > loadPaths , String moduleName ) { String fileName = normalizeName ( moduleName ) ; File file = new File ( moduleName ) ; if ( file . isAbsolute ( ) ) { if ( file . exists ( ) ) { return file ; } } for ( String loadPath : loadPaths ) { file = new File ( loadPath , fileName ) ; if ( file . exists ( ) ) break ; } return file ; }
Finds the module file based on the known load paths .
37,923
private static void addJumpIfNextNotDestination ( CFG cfg , BasicBlock next , Instruction lastInstr , BasicBlock current ) { Iterator < BasicBlock > outs = cfg . getOutgoingDestinations ( current ) . iterator ( ) ; BasicBlock target = outs . hasNext ( ) ? outs . next ( ) : null ; if ( target != null && ! outs . hasNext ( ) ) { if ( ( target != next ) && ( ( lastInstr == null ) || ! lastInstr . transfersControl ( ) ) ) { current . addInstr ( new Jump ( target . getLabel ( ) ) ) ; } } }
If there is no jump at add of block and the next block is not destination insert a valid jump
37,924
public List < Variable > getUsedVariables ( ) { ArrayList < Variable > vars = new ArrayList < Variable > ( ) ; for ( Operand o : getOperands ( ) ) { o . addUsedVariables ( vars ) ; } return vars ; }
List of all variables used by this instruction .
37,925
public static Stream < Integer > range ( final int from , final int to , final int step ) { return new Stream < Integer > ( ) { public Iterator < Integer > iterator ( ) { return new ReadOnlyIterator < Integer > ( ) { int value = from ; public boolean hasNext ( ) { return value < to ; } public Integer next ( ) { final int v = value ; value += step ; return v ; } } ; } } ; }
Creates a stream that contains a given number of integers starting from a given number .
37,926
public static < T > Optional < T > of ( T value ) { return value == null ? ( Optional < T > ) EMPTY : new Optional < > ( value ) ; }
Returns an optional for a given value
37,927
public T or ( Func0 < T > func1 ) { return value != null ? value : func1 . call ( ) ; }
Returns value of uses a given factory if the value does not exist .
37,928
public < R > Optional < R > map ( Func1 < T , R > func1 ) { return value == null ? Optional . < R > empty ( ) : Optional . of ( func1 . call ( value ) ) ; }
Transforms the value if exists returns empty Optional otherwise .
37,929
public static < K , V > SolidMap < K , V > map ( K key , V value , Object ... pairs ) { if ( pairs . length % 2 != 0 ) throw new IllegalArgumentException ( "SolidMap.map(...) takes even number of arguments" ) ; LinkedHashMap < K , V > m = new LinkedHashMap < > ( ) ; m . put ( key , value ) ; for ( int i = 0 ; i < pairs . length ; i += 2 ) m . put ( ( K ) pairs [ i ] , ( V ) pairs [ i + 1 ] ) ; return new SolidMap < > ( m ) ; }
Creates a map using interleaving keys and values .
37,930
public static < T > Stream < T > of ( final T value ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { boolean has = true ; public boolean hasNext ( ) { return has ; } public T next ( ) { has = false ; return value ; } } ; } } ; }
Returns a stream with just one given element .
37,931
public < R > R collect ( Func1 < Iterable < T > , R > collector ) { return collector . call ( this ) ; }
Converts the current stream into any value with a given method .
37,932
public < R > Stream < R > map ( final Func1 < ? super T , ? extends R > func ) { return new Stream < R > ( ) { public Iterator < R > iterator ( ) { return new ReadOnlyIterator < R > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; public boolean hasNext ( ) { return iterator . hasNext ( ) ; } public R next ( ) { return func . call ( iterator . next ( ) ) ; } } ; } } ; }
Returns a new stream that contains items that has been returned by a given function for each item in the current stream .
37,933
public Stream < T > merge ( final T value ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; boolean completed ; public boolean hasNext ( ) { return iterator . hasNext ( ) || ! completed ; } public T next ( ) { if ( iterator . hasNext ( ) ) return iterator . next ( ) ; completed = true ; return value ; } } ; } } ; }
Returns a new stream that contains all items of the current stream with addition of a given item .
37,934
public Stream < T > separate ( final T value ) { return filter ( new Func1 < T , Boolean > ( ) { public Boolean call ( T it ) { return ( ( it == null ) ? ( value != null ) : ! it . equals ( value ) ) ; } } ) ; }
Returns a new stream that contains all items of the current stream except of a given item .
37,935
public Stream < T > merge ( final Iterable < ? extends T > with ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; Iterator < ? extends T > withIterator = with . iterator ( ) ; public boolean hasNext ( ) { return iterator . hasNext ( ) || withIterator . hasNext ( ) ; } public T next ( ) { return iterator . hasNext ( ) ? iterator . next ( ) : withIterator . next ( ) ; } } ; } } ; }
Adds items from another stream to the end of the current stream .
37,936
public < S , R > Stream < R > zipWith ( final Iterable < ? extends S > with , final Func2 < ? super T , ? super S , ? extends R > func ) { return new Stream < R > ( ) { public Iterator < R > iterator ( ) { return new ReadOnlyIterator < R > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; Iterator < ? extends S > withIterator = with . iterator ( ) ; public boolean hasNext ( ) { return iterator . hasNext ( ) && withIterator . hasNext ( ) ; } public R next ( ) { return func . call ( iterator . next ( ) , withIterator . next ( ) ) ; } } ; } } ; }
Returns a new stream that contains items that has been received by sequentially combining items of the streams into pairs and then applying given function to each pair of items .
37,937
public Stream < T > separate ( Iterable < T > from ) { final ArrayList < T > list = ToArrayList . < T > toArrayList ( ) . call ( from ) ; return filter ( new Func1 < T , Boolean > ( ) { public Boolean call ( T it ) { return ! list . contains ( it ) ; } } ) ; }
Returns a stream that includes only that items of the current stream that do not exist in a given stream .
37,938
public Stream < T > take ( final int count ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; int left = count ; public boolean hasNext ( ) { return left > 0 && iterator . hasNext ( ) ; } public T next ( ) { left -- ; return iterator . next ( ) ; } } ; } } ; }
Creates a new stream that contains only the first given amount of items of the current stream .
37,939
public Stream < T > skip ( final int count ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; for ( int skip = count ; skip > 0 && iterator . hasNext ( ) ; skip -- ) iterator . next ( ) ; return iterator ; } } ; }
Creates a new stream that contains elements of the current stream with a given number of them skipped from the beginning .
37,940
public Stream < T > sort ( final Comparator < T > comparator ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { final ArrayList < T > array = ToArrayList . < T > toArrayList ( ) . call ( Stream . this ) ; Collections . sort ( array , comparator ) ; return array . iterator ( ) ; } } ; }
Returns a new stream that contains all items of the current stream in sorted order . The operator creates a list of all items internally .
37,941
public Stream < T > reverse ( ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { final ArrayList < T > array = ToArrayList . < T > toArrayList ( ) . call ( Stream . this ) ; Collections . reverse ( array ) ; return array . iterator ( ) ; } } ; }
Returns a new stream that contains all items of the current stream in reverse order . The operator creates a list of all items internally .
37,942
public < R > Stream < R > cast ( final Class < R > c ) { return map ( new Func1 < T , R > ( ) { public R call ( T obj ) { return c . cast ( obj ) ; } } ) ; }
Returns a stream that contains all values of the original stream that has been casted to a given class type .
37,943
public boolean every ( Func1 < ? super T , Boolean > predicate ) { for ( T item : this ) { if ( ! predicate . call ( item ) ) return false ; } return true ; }
Returns true if all of stream items satisfy a given condition .
37,944
public Stream < T > onNext ( final Action1 < ? super T > action ) { return new Stream < T > ( ) { public Iterator < T > iterator ( ) { return new ReadOnlyIterator < T > ( ) { Iterator < T > iterator = Stream . this . iterator ( ) ; public boolean hasNext ( ) { return iterator . hasNext ( ) ; } public T next ( ) { final T next = iterator . next ( ) ; action . call ( next ) ; return next ; } } ; } } ; }
Executes an action for each item in the stream .
37,945
public static void i ( String msg , Throwable thr ) { if ( DEBUG ) Log . i ( TAG , buildMessage ( msg ) , thr ) ; }
Send a INFO log message and log the exception .
37,946
public static String getDataColumn ( Context context , Uri uri , String selection , String [ ] selectionArgs ) { Cursor cursor = null ; final String column = "_data" ; final String [ ] projection = { column } ; try { cursor = context . getContentResolver ( ) . query ( uri , projection , selection , selectionArgs , null ) ; if ( cursor != null && cursor . moveToFirst ( ) ) { final int index = cursor . getColumnIndexOrThrow ( column ) ; return cursor . getString ( index ) ; } } finally { if ( cursor != null ) cursor . close ( ) ; } return null ; }
Get the value of the data column for this Uri . This is useful for MediaStore Uris and other file - based ContentProviders .
37,947
protected EventType decodeEvent ( EventType nextEventType ) throws EXIException , IOException { endElementPrefix = null ; switch ( nextEventType ) { case START_DOCUMENT : decoder . decodeStartDocument ( ) ; break ; case END_DOCUMENT : decoder . decodeEndDocument ( ) ; break ; case ATTRIBUTE_XSI_NIL : attributes . add ( new AttributeContainer ( decoder . decodeAttributeXsiNil ( ) , decoder . getAttributeValue ( ) , decoder . getAttributePrefix ( ) ) ) ; break ; case ATTRIBUTE_XSI_TYPE : attributes . add ( new AttributeContainer ( decoder . decodeAttributeXsiType ( ) , decoder . getAttributeValue ( ) , decoder . getAttributePrefix ( ) ) ) ; break ; case ATTRIBUTE : case ATTRIBUTE_NS : case ATTRIBUTE_GENERIC : case ATTRIBUTE_GENERIC_UNDECLARED : case ATTRIBUTE_INVALID_VALUE : case ATTRIBUTE_ANY_INVALID_VALUE : attributes . add ( new AttributeContainer ( decoder . decodeAttribute ( ) , decoder . getAttributeValue ( ) , decoder . getAttributePrefix ( ) ) ) ; break ; case NAMESPACE_DECLARATION : decoder . decodeNamespaceDeclaration ( ) ; break ; case SELF_CONTAINED : decoder . decodeStartSelfContainedFragment ( ) ; break ; case START_ELEMENT : case START_ELEMENT_NS : case START_ELEMENT_GENERIC : case START_ELEMENT_GENERIC_UNDECLARED : element = decoder . decodeStartElement ( ) ; break ; case END_ELEMENT : case END_ELEMENT_UNDECLARED : eePrefixes = decoder . getDeclaredPrefixDeclarations ( ) ; endElementPrefix = decoder . getElementPrefix ( ) ; element = decoder . decodeEndElement ( ) ; break ; case CHARACTERS : case CHARACTERS_GENERIC : case CHARACTERS_GENERIC_UNDECLARED : characters = decoder . decodeCharacters ( ) ; break ; case DOC_TYPE : docType = decoder . decodeDocType ( ) ; break ; case ENTITY_REFERENCE : entityReference = decoder . decodeEntityReference ( ) ; break ; case COMMENT : comment = decoder . decodeComment ( ) ; break ; case PROCESSING_INSTRUCTION : processingInstruction = decoder . decodeProcessingInstruction ( ) ; break ; default : throw new RuntimeException ( "Unexpected EXI Event '" + eventType + "' " ) ; } return nextEventType ; }
without further attribute handling
37,948
public static boolean beginOrJoinTransaction ( ) { boolean newTransaction = false ; try { newTransaction = userTransaction . getStatus ( ) == Status . STATUS_NO_TRANSACTION ; if ( newTransaction ) { userTransaction . begin ( ) ; } } catch ( Exception e ) { throw new RuntimeException ( "Unable to start transaction." , e ) ; } return newTransaction ; }
Start or join a transaction .
37,949
public static void commit ( ) { try { if ( ! isDone ( ) ) { userTransaction . commit ( ) ; } else { LOGGER . warn ( "commit() called with no current transaction." ) ; } } catch ( Exception e ) { throw new RuntimeException ( "Transaction commit failed." , e ) ; } }
Commit the current transaction .
37,950
public static void rollback ( ) { try { if ( userTransaction . getStatus ( ) != Status . STATUS_NO_TRANSACTION ) { userTransaction . rollback ( ) ; } else { LOGGER . warn ( "Request to rollback transaction when none was in started." ) ; } } catch ( Exception e ) { LOGGER . warn ( "Transaction rollback failed." , e ) ; } }
Rollback the current transaction .
37,951
public static Transaction suspend ( ) { try { Transaction suspend = transactionManager . suspend ( ) ; return suspend ; } catch ( SystemException e ) { throw new RuntimeException ( "Unable to suspend current transaction" , e ) ; } }
Suspend the current transaction and return it to the caller .
37,952
public static void resume ( Transaction transaction ) { try { transactionManager . resume ( transaction ) ; } catch ( Exception e ) { throw new RuntimeException ( "Unable to resume transaction" , e ) ; } }
Resume the specified transaction . If the transaction was never suspended or was already committed or rolled back a RuntimeException will be thrown wrapping the JTA originated exception .
37,953
public final T execute ( ) { boolean txOwner = ! TransactionElf . hasTransactionManager ( ) || TransactionElf . beginOrJoinTransaction ( ) ; Connection connection = null ; try { connection = ConnectionProxy . wrapConnection ( dataSource . getConnection ( ) ) ; if ( txOwner ) { connection . setAutoCommit ( false ) ; } return ( args == null ) ? execute ( connection ) : execute ( connection , args ) ; } catch ( SQLException e ) { if ( e . getNextException ( ) != null ) { e = e . getNextException ( ) ; } if ( txOwner ) { txOwner = false ; rollback ( connection ) ; } throw new RuntimeException ( e ) ; } catch ( Throwable e ) { if ( txOwner ) { txOwner = false ; rollback ( connection ) ; } throw e ; } finally { try { if ( txOwner ) { commit ( connection ) ; } } finally { quietClose ( connection ) ; } } }
Execute the closure .
37,954
private static PreparedStatement createStatementForUpdate ( final Connection connection , final Introspected introspected , final FieldColumnInfo [ ] fieldColumnInfos , final Set < String > excludedColumns ) throws SQLException { final String sql = createSqlForUpdate ( introspected , fieldColumnInfos , excludedColumns ) ; return connection . prepareStatement ( sql ) ; }
To exclude columns situative . Does not cache the statement .
37,955
private static < T > void setParamsExecute ( final T target , final Introspected introspected , final FieldColumnInfo [ ] fcInfos , final PreparedStatement stmt , final boolean checkExistingId , final Set < String > excludedColumns ) throws SQLException { final int [ ] parameterTypes = getParameterTypes ( stmt ) ; int parameterIndex = setStatementParameters ( target , introspected , fcInfos , stmt , parameterTypes , excludedColumns ) ; if ( parameterIndex <= parameterTypes . length ) { for ( final Object id : introspected . getActualIds ( target ) ) { stmt . setObject ( parameterIndex , id , parameterTypes [ parameterIndex - 1 ] ) ; ++ parameterIndex ; } } stmt . executeUpdate ( ) ; fillGeneratedId ( target , introspected , stmt , checkExistingId ) ; }
You should close stmt by yourself
37,956
private static < T > int setStatementParameters ( final T item , final Introspected introspected , final FieldColumnInfo [ ] fcInfos , final PreparedStatement stmt , final int [ ] parameterTypes , final Set < String > excludedColumns ) throws SQLException { int parameterIndex = 1 ; for ( final FieldColumnInfo fcInfo : fcInfos ) { if ( excludedColumns == null || ! isIgnoredColumn ( excludedColumns , fcInfo . getColumnName ( ) ) ) { final int parameterType = parameterTypes [ parameterIndex - 1 ] ; final Object object = mapSqlType ( introspected . get ( item , fcInfo ) , parameterType ) ; if ( object != null && ! fcInfo . isSelfJoinField ( ) ) { stmt . setObject ( parameterIndex , object , parameterType ) ; } else { stmt . setNull ( parameterIndex , parameterType ) ; } ++ parameterIndex ; } } return parameterIndex ; }
Small helper to set statement parameters from given object
37,957
private static < T > void fillGeneratedId ( final T target , final Introspected introspected , final PreparedStatement stmt , final boolean checkExistingId ) throws SQLException { if ( ! introspected . hasGeneratedId ( ) ) { return ; } final FieldColumnInfo fcInfo = introspected . getGeneratedIdFcInfo ( ) ; if ( checkExistingId ) { final Object idExisting = introspected . get ( target , fcInfo ) ; if ( idExisting != null && ( ! ( idExisting instanceof Integer ) || ( Integer ) idExisting > 0 ) ) { return ; } } try ( final ResultSet generatedKeys = stmt . getGeneratedKeys ( ) ) { if ( generatedKeys . next ( ) ) { introspected . set ( target , fcInfo , generatedKeys . getObject ( 1 ) ) ; } } }
Sets auto - generated ID if not set yet
37,958
void set ( Object target , FieldColumnInfo fcInfo , Object value ) { if ( fcInfo == null ) { throw new RuntimeException ( "FieldColumnInfo must not be null. Type is " + target . getClass ( ) . getCanonicalName ( ) ) ; } try { final Class < ? > fieldType = fcInfo . fieldType ; Class < ? > columnType = value . getClass ( ) ; Object columnValue = value ; if ( fcInfo . getConverter ( ) != null ) { columnValue = fcInfo . getConverter ( ) . convertToEntityAttribute ( columnValue ) ; } else if ( fieldType != columnType ) { if ( fieldType == boolean . class && columnType == Integer . class ) { columnValue = ( ( ( Integer ) columnValue ) != 0 ) ; } else if ( columnType == BigDecimal . class ) { if ( fieldType == BigInteger . class ) { columnValue = ( ( BigDecimal ) columnValue ) . toBigInteger ( ) ; } else if ( fieldType == Integer . class ) { columnValue = ( int ) ( ( BigDecimal ) columnValue ) . longValue ( ) ; } else if ( fieldType == Long . class ) { columnValue = ( ( BigDecimal ) columnValue ) . longValue ( ) ; } else if ( fieldType == Double . class ) { columnValue = ( ( BigDecimal ) columnValue ) . doubleValue ( ) ; } } else if ( columnType == java . util . UUID . class && fieldType == String . class ) { columnValue = columnValue . toString ( ) ; } else if ( fcInfo . enumConstants != null ) { columnValue = fcInfo . enumConstants . get ( columnValue ) ; } else if ( columnValue instanceof Clob ) { columnValue = readClob ( ( Clob ) columnValue ) ; } else if ( "PGobject" . equals ( columnType . getSimpleName ( ) ) && "citext" . equalsIgnoreCase ( ( ( PGobject ) columnValue ) . getType ( ) ) ) { columnValue = ( ( PGobject ) columnValue ) . getValue ( ) ; } } fcInfo . field . set ( target , columnValue ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Set a field value of the specified target object .
37,959
public boolean isInsertableColumn ( final String columnName ) { final FieldColumnInfo [ ] fcInfos = getInsertableFcInfos ( ) ; for ( int i = 0 ; i < fcInfos . length ; i ++ ) { if ( fcInfos [ i ] . getCaseSensitiveColumnName ( ) . equals ( columnName ) ) { return true ; } } return false ; }
Is this specified column insertable?
37,960
public boolean isUpdatableColumn ( final String columnName ) { final FieldColumnInfo [ ] fcInfos = getUpdatableFcInfos ( ) ; for ( int i = 0 ; i < fcInfos . length ; i ++ ) { if ( fcInfos [ i ] . getCaseSensitiveColumnName ( ) . equals ( columnName ) ) { return true ; } } return false ; }
Is this specified column updatable?
37,961
public static < T > void insertListBatched ( Connection connection , Iterable < T > iterable ) throws SQLException { OrmWriter . insertListBatched ( connection , iterable ) ; }
Insert a collection of objects using JDBC batching .
37,962
public static < T > T insertObject ( Connection connection , T target ) throws SQLException { return OrmWriter . insertObject ( connection , target ) ; }
Insert an annotated object into the database .
37,963
public static String getColumnFromProperty ( Class < ? > clazz , String propertyName ) { return Introspector . getIntrospected ( clazz ) . getColumnNameForProperty ( propertyName ) ; }
Gets the column name defined for the given property for the given type .
37,964
public static < T > String getColumnsCsv ( Class < T > clazz , String ... tablePrefix ) { return OrmReader . getColumnsCsv ( clazz , tablePrefix ) ; }
Get a comma separated values list of column names for the given class suitable for inclusion into a SQL SELECT statement .
37,965
public static < T > T refresh ( Connection connection , T target ) throws SQLException { return OrmReader . refresh ( connection , target ) ; }
To refresh all fields in case they have changed in database .
37,966
protected static boolean isIgnoredColumn ( final Set < String > ignoredColumns , final String columnName ) { return ignoredColumns . stream ( ) . anyMatch ( s -> s . equalsIgnoreCase ( columnName ) ) ; }
Case insensitive comparison .
37,967
public static void deinitialize ( ) { SqlClosure . setDefaultDataSource ( null ) ; TransactionElf . setUserTransaction ( null ) ; TransactionElf . setTransactionManager ( null ) ; }
You can reset SansOrm to a fresh state if desired . E . g . if you want to call another initializeXXX method .
37,968
public static < T > T getObjectById ( Class < T > type , Object ... ids ) { return SqlClosure . sqlExecute ( c -> OrmElf . objectById ( c , type , ids ) ) ; }
Gets an object by ID from the database .
37,969
public static < T > T objectFromClause ( Class < T > type , String clause , Object ... args ) { return SqlClosure . sqlExecute ( c -> OrmElf . objectFromClause ( c , type , clause , args ) ) ; }
Gets an object using a from clause .
37,970
public static < T > T insertObject ( T object ) { return SqlClosure . sqlExecute ( c -> OrmElf . insertObject ( c , object ) ) ; }
Inserts the given object into the database .
37,971
public static < T > T updateObject ( T object ) { return SqlClosure . sqlExecute ( c -> OrmElf . updateObject ( c , object ) ) ; }
Updates the given object in the database .
37,972
public static < T > int deleteObject ( T object ) { return SqlClosure . sqlExecute ( c -> OrmElf . deleteObject ( c , object ) ) ; }
Delete the given object in the database .
37,973
public static < T > int deleteObjectById ( Class < T > clazz , Object ... args ) { return SqlClosure . sqlExecute ( c -> OrmElf . deleteObjectById ( c , clazz , args ) ) ; }
Delete an object from the database by ID .
37,974
public static < T > List < T > listFromClause ( Class < T > clazz , String clause , Object ... args ) { return SqlClosure . sqlExecute ( c -> OrmElf . listFromClause ( c , clazz , clause , args ) ) ; }
Gets a list of objects from the database .
37,975
public static < T > int countObjectsFromClause ( Class < T > clazz , String clause , Object ... args ) { return SqlClosure . sqlExecute ( c -> OrmElf . countObjectsFromClause ( c , clazz , clause , args ) ) ; }
Counts the number of rows for the given query .
37,976
public static int executeUpdate ( final String sql , final Object ... args ) { return SqlClosure . sqlExecute ( c -> executeUpdate ( c , sql , args ) ) ; }
Executes an update or insert statement .
37,977
public static String getInClausePlaceholdersForCount ( final int placeholderCount ) { if ( placeholderCount < 0 ) { throw new IllegalArgumentException ( "Placeholder count must be greater than or equal to zero" ) ; } if ( placeholderCount == 0 ) { return " ('s0me n0n-ex1st4nt v4luu') " ; } final StringBuilder sb = new StringBuilder ( 3 + placeholderCount * 2 ) ; sb . append ( " (?" ) ; for ( int i = 1 ; i < placeholderCount ; i ++ ) { sb . append ( ",?" ) ; } return sb . append ( ") " ) . toString ( ) ; }
Get a SQL IN clause for the number of items .
37,978
public static ResultSet executeQuery ( Connection connection , String sql , Object ... args ) throws SQLException { return OrmReader . statementToResultSet ( connection . prepareStatement ( sql ) , args ) ; }
Execute the specified SQL as a PreparedStatement with the specified arguments .
37,979
public static String compile ( File lessFile , boolean compress ) throws IOException { String lessData = new String ( Files . readAllBytes ( lessFile . toPath ( ) ) , StandardCharsets . UTF_8 ) ; return Less . compile ( lessFile . toURI ( ) . toURL ( ) , lessData , compress , new ReaderFactory ( ) ) ; }
Compile the less data from a file .
37,980
void addPosition ( String filename , int line , int column ) { LessFilePosition pos = new LessFilePosition ( filename , line , column ) ; if ( ! positions . contains ( pos ) ) { this . positions . add ( pos ) ; } }
Add a position to the less file stacktrace
37,981
public String replace ( String input , String replacement ) throws ParameterOutOfBoundsException { replacement = REPLACEMENT_BACKSLASH . matcher ( replacement ) . replaceAll ( REPLACEMENT_BACKSLASH_FOR_JAVA ) ; replacement = REPLACEMENT_DOLLAR_AMPERSAND . matcher ( replacement ) . replaceAll ( REPLACEMENT_DOLLAR_AMPERSAND_FOR_JAVA ) ; if ( REPLACEMENT_DOLLAR_APOSTROPHE . matcher ( replacement ) . find ( ) ) { throw new ParameterOutOfBoundsException ( ) ; } replacement = REPLACEMENT_DOLLAR_DOLLAR . matcher ( replacement ) . replaceAll ( REPLACEMENT_DOLLAR_DOLLAR_FOR_JAVA ) ; Matcher matcher = pattern . matcher ( input ) ; return global ? matcher . replaceAll ( replacement ) : matcher . replaceFirst ( replacement ) ; }
Replace the matches in the input with the replacement .
37,982
void appendSubRules ( String [ ] parentSelector , CssFormatter formatter ) { try { if ( important ) { formatter . incImportant ( ) ; } for ( MixinMatch match : getRules ( formatter ) ) { Rule rule = match . getRule ( ) ; formatter . addMixin ( rule , match . getMixinParameters ( ) , rule . getVariables ( ) ) ; rule . appendMixinsTo ( parentSelector , formatter ) ; for ( Rule subMixin : rule . getSubrules ( ) ) { if ( ! subMixin . isMixin ( ) && ( parentSelector == null || ! subMixin . isInlineRule ( formatter ) ) ) { subMixin . appendTo ( parentSelector , formatter ) ; } } formatter . removeMixin ( ) ; } } catch ( LessException ex ) { ex . addPosition ( filename , line , column ) ; throw ex ; } finally { if ( important ) { formatter . decImportant ( ) ; } } }
Append the rules of the mixins to the formatter .
37,983
private List < MixinMatch > getRules ( CssFormatter formatter ) throws LessException { if ( mixinRules != null && stackID == formatter . stackID ( ) ) { return mixinRules ; } List < Rule > rules = formatter . getMixin ( name ) ; if ( rules == null ) { rules = mixins . get ( name ) ; } if ( rules == null ) { int idx = name . indexOf ( '>' ) ; if ( idx > 0 ) { String mainName = name . substring ( 0 , idx ) . trim ( ) ; rules = mixins . get ( mainName ) ; if ( rules != null ) { rules = rules . get ( 0 ) . getMixin ( name . substring ( idx + 1 ) . trim ( ) ) ; } } else { idx = name . indexOf ( '.' ) ; if ( idx > 0 ) { String mainName = name . substring ( 0 , idx ) . trim ( ) ; rules = mixins . get ( mainName ) ; if ( rules != null ) { rules = rules . get ( 0 ) . getMixin ( name . substring ( idx ) . trim ( ) ) ; } } } if ( rules == null ) { throw createException ( "Undefined mixin: " + name ) ; } } stackID = formatter . stackID ( ) ; mixinRules = new ArrayList < > ( ) ; boolean paramMatch = false ; List < Rule > defaultMixins = null ; for ( Rule rule : rules ) { MixinMatch matching = rule . match ( formatter , paramValues , false ) ; if ( matching != null ) { paramMatch = true ; if ( matching . getGuard ( ) ) { mixinRules . add ( matching ) ; } else if ( matching . wasDefault ( ) ) { if ( defaultMixins == null ) { defaultMixins = new ArrayList < > ( ) ; } defaultMixins . add ( rule ) ; } } } if ( ! paramMatch ) { throw createException ( "No matching definition was found for: " + name ) ; } if ( mixinRules . size ( ) == 0 && defaultMixins != null ) { for ( Rule rule : defaultMixins ) { MixinMatch matching = rule . match ( formatter , paramValues , true ) ; if ( matching != null && matching . getGuard ( ) ) { mixinRules . add ( matching ) ; } } } return mixinRules ; }
Get the rules of the mixin
37,984
private void bubbling ( String [ ] mediaSelector , String [ ] blockSelector , CssFormatter formatter ) { if ( properties . size ( ) > 0 ) { String media = mediaSelector [ 0 ] ; if ( media . startsWith ( "@media" ) || media . startsWith ( "@supports" ) || media . startsWith ( "@document" ) ) { int size0 = formatter . getOutputSize ( ) ; CssFormatter block = formatter . startBlock ( mediaSelector ) ; if ( block != formatter ) { size0 = block . getOutputSize ( ) ; } CssFormatter block2 = block . startBlock ( blockSelector ) ; int size1 = block2 . getOutputSize ( ) ; appendPropertiesTo ( block2 ) ; int size2 = block2 . getOutputSize ( ) ; block2 . endBlock ( ) ; int size3 = block . getOutputSize ( ) ; for ( Formattable prop : properties ) { if ( prop instanceof Mixin ) { ( ( Mixin ) prop ) . appendSubRules ( blockSelector , block ) ; } } int size4 = block . getOutputSize ( ) ; block . endBlock ( ) ; if ( size1 == size2 && size3 == size4 ) { block . setOutputSize ( size0 ) ; } } else { CssFormatter block = formatter . startBlock ( mediaSelector ) ; appendPropertiesTo ( block ) ; for ( Rule rule : subrules ) { rule . appendTo ( null , block ) ; } block . endBlock ( ) ; return ; } } for ( Rule rule : subrules ) { final String [ ] ruleSelector = rule . getSelectors ( ) ; String name = ruleSelector [ 0 ] ; name = SelectorUtils . replacePlaceHolder ( formatter , name , this ) ; if ( name . startsWith ( "@media" ) ) { rule . bubbling ( new String [ ] { mediaSelector [ 0 ] + " and " + name . substring ( 6 ) . trim ( ) } , blockSelector , formatter ) ; } else { rule . bubbling ( mediaSelector , SelectorUtils . merge ( blockSelector , ruleSelector ) , formatter ) ; } } }
Nested Directives are bubbling .
37,985
void appendMixinsTo ( String [ ] parentSelector , CssFormatter formatter ) { for ( Formattable prop : properties ) { switch ( prop . getType ( ) ) { case MIXIN : ( ( Mixin ) prop ) . appendSubRules ( parentSelector , formatter ) ; break ; case CSS_AT_RULE : case COMMENT : prop . appendTo ( formatter ) ; break ; } } }
Append the mixins of this rule to current output .
37,986
void appendPropertiesTo ( CssFormatter formatter ) { if ( properties . isEmpty ( ) ) { return ; } formatter . addVariables ( variables ) ; for ( Formattable prop : properties ) { switch ( prop . getType ( ) ) { case Formattable . RULE : Rule rule = ( Rule ) prop ; if ( rule . isValidCSS ( formatter ) && rule . isInlineRule ( formatter ) ) { rule . appendPropertiesTo ( formatter ) ; } break ; default : prop . appendTo ( formatter ) ; } } formatter . removeVariables ( variables ) ; }
Append the properties of the rule .
37,987
List < Rule > getMixin ( String name ) { ArrayList < Rule > rules = null ; for ( Rule rule : subrules ) { for ( String sel : rule . selectors ) { if ( name . equals ( sel ) ) { if ( rules == null ) { rules = new ArrayList < > ( ) ; } rules . add ( rule ) ; break ; } } } return rules ; }
Get a nested mixin of this rule .
37,988
MixinMatch match ( CssFormatter formatter , List < Expression > paramValues , boolean isDefault ) { if ( guard == null && formatter . containsRule ( this ) ) { return null ; } Map < String , Expression > mixinParameters = getMixinParams ( formatter , paramValues ) ; if ( mixinParameters == NO_MATCH ) { return null ; } boolean matching = true ; if ( guard != null ) { formatter . addGuardParameters ( mixinParameters , isDefault ) ; matching = guard . booleanValue ( formatter ) ; formatter . removeGuardParameters ( mixinParameters ) ; } return new MixinMatch ( this , mixinParameters , matching , formatter . wasDefaultFunction ( ) ) ; }
If this mixin match the calling parameters .
37,989
boolean isInlineRule ( CssFormatter formatter ) { if ( selectors . length == 1 && selectors [ 0 ] . equals ( "&" ) ) { return hasOnlyInlineProperties ( formatter ) ; } return false ; }
If there is only a special selector & and also all subrules have only this special selector .
37,990
boolean hasOnlyInlineProperties ( CssFormatter formatter ) { for ( Formattable prop : properties ) { if ( prop instanceof Mixin ) { return false ; } } for ( Rule rule : subrules ) { if ( rule . isValidCSS ( formatter ) && rule . isInlineRule ( formatter ) ) { return false ; } } return true ; }
If there are only properties that should be inlined .
37,991
public static ValueExpression eval ( CssFormatter formatter , Expression expr ) { expr = expr . unpack ( formatter ) ; if ( expr . getClass ( ) == ValueExpression . class ) { return ( ValueExpression ) expr ; } ValueExpression valueEx = new ValueExpression ( expr , expr . stringValue ( formatter ) ) ; valueEx . type = expr . getDataType ( formatter ) ; valueEx . unit = expr . unit ( formatter ) ; switch ( valueEx . type ) { case STRING : case BOOLEAN : break ; case LIST : Operation op = valueEx . op = new Operation ( expr , ' ' ) ; ArrayList < Expression > operants = expr . listValue ( formatter ) . getOperands ( ) ; for ( int j = 0 ; j < operants . size ( ) ; j ++ ) { op . addOperand ( ValueExpression . eval ( formatter , operants . get ( j ) ) ) ; } break ; default : valueEx . value = expr . doubleValue ( formatter ) ; } return valueEx ; }
Create a value expression as parameter for a mixin which not change it value in a different context .
37,992
Expression getValue ( CssFormatter formatter ) { String name = toString ( ) ; Expression value = formatter . getVariable ( name ) ; if ( value != null ) { return value ; } if ( name . startsWith ( "@@" ) ) { name = name . substring ( 1 ) ; value = formatter . getVariable ( name ) ; if ( value != null ) { formatter . setInlineMode ( true ) ; name = '@' + value . stringValue ( formatter ) ; formatter . setInlineMode ( false ) ; value = formatter . getVariable ( name ) ; if ( value != null ) { return value ; } } } throw createException ( "Undefined Variable: " + name ) ; }
Get the referencing expression
37,993
private static void putConvertion ( HashMap < String , Double > group , String unit , double factor ) { UNIT_CONVERSIONS . put ( unit , group ) ; group . put ( unit , factor ) ; }
Helper for creating static unit conversions .
37,994
private int maxOperadType ( CssFormatter formatter ) { int dataType = operands . get ( 0 ) . getDataType ( formatter ) ; for ( int i = 1 ; i < operands . size ( ) ; i ++ ) { dataType = Math . max ( dataType , operands . get ( i ) . getDataType ( formatter ) ) ; } return dataType ; }
Get the highest data type of different operands
37,995
static double unitFactor ( String leftUnit , String rightUnit , boolean fail ) { if ( leftUnit . length ( ) == 0 || rightUnit . length ( ) == 0 || leftUnit . equals ( rightUnit ) ) { return 1 ; } HashMap < String , Double > leftGroup = UNIT_CONVERSIONS . get ( leftUnit ) ; if ( leftGroup != null ) { HashMap < String , Double > rightGroup = UNIT_CONVERSIONS . get ( rightUnit ) ; if ( leftGroup == rightGroup ) { return leftGroup . get ( leftUnit ) / leftGroup . get ( rightUnit ) ; } } if ( fail ) { throw new LessException ( "Incompatible types" ) ; } return 1 ; }
Calculate the factor between 2 units .
37,996
private double doubleValue ( double left , double right ) { switch ( operator ) { case '+' : return left + right ; case '-' : return left - right ; case '*' : return left * right ; case '/' : return left / right ; default : throw createException ( "Not supported Oprator '" + operator + "' for Expression '" + toString ( ) + '\'' ) ; } }
Calculate the number value of two operands if possible .
37,997
private double doubleValueLeftColor ( double color , double right ) { return rgba ( doubleValue ( red ( color ) , right ) , doubleValue ( green ( color ) , right ) , doubleValue ( blue ( color ) , right ) , 1 ) ; }
Calculate a color on left with a number on the right side . The calculation occur for every color channel .
37,998
private double doubleValueRightColor ( double left , double color ) { return rgba ( doubleValue ( left , red ( color ) ) , doubleValue ( left , green ( color ) ) , doubleValue ( left , blue ( color ) ) , 1 ) ; }
Calculate a number on left with a color on the right side . The calculation occur for every color channel .
37,999
private double doubleValue2Colors ( double left , double right ) { return rgba ( doubleValue ( red ( left ) , red ( right ) ) , doubleValue ( green ( left ) , green ( right ) ) , doubleValue ( blue ( left ) , blue ( right ) ) , 1 ) ; }
Calculate two colors . The calculation occur for every color channel .