idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
10,200 | public void setAmbientLight ( int i , Color color , boolean enableColor ) { float ambient [ ] = { ( float ) color . getRed ( ) , ( float ) color . getGreen ( ) , ( float ) color . getBlue ( ) , ( float ) color . getAlpha ( ) } ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 + i ) ; if ( enableColor ) gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_AMBIENT , ambient , 0 ) ; } | Sets the color value of the No . i ambientLight | 135 | 12 |
10,201 | public void setAmbientLight ( int i , Color color , boolean enableColor , Vector3D v ) { float ambient [ ] = { ( float ) color . getRed ( ) , ( float ) color . getGreen ( ) , ( float ) color . getBlue ( ) , ( float ) color . getAlpha ( ) } ; float position [ ] = { ( float ) v . getX ( ) , ( float ) v . getY ( ) , ( float ) v . getZ ( ) , 1.0f } ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 + i ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_POSITION , position , 0 ) ; if ( enableColor ) gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_AMBIENT , ambient , 0 ) ; } | Sets the color value and the position of the No . i ambientLight | 213 | 15 |
10,202 | public void setSpotLight ( int i , Color color , boolean enableColor , Vector3D v , float nx , float ny , float nz , float angle ) { float spotColor [ ] = { ( float ) color . getRed ( ) , ( float ) color . getGreen ( ) , ( float ) color . getBlue ( ) , ( float ) color . getAlpha ( ) } ; float pos [ ] = { ( float ) v . getX ( ) , ( float ) v . getY ( ) , ( float ) v . getZ ( ) , 0.0f } ; float direction [ ] = { nx , ny , nz } ; float a [ ] = { angle } ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 + i ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_POSITION , pos , 0 ) ; if ( enableColor ) gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_DIFFUSE , spotColor , 0 ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_SPOT_DIRECTION , direction , 0 ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_SPOT_CUTOFF , a , 0 ) ; } | Sets the color value position direction and the angle of the spotlight cone of the No . i spotLight | 324 | 21 |
10,203 | public void setLightAttenuation ( int i , float constant , float liner , float quadratic ) { float c [ ] = { constant } ; float l [ ] = { liner } ; float q [ ] = { quadratic } ; gl . glEnable ( GL2 . GL_LIGHTING ) ; gl . glEnable ( GL2 . GL_LIGHT0 + i ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_CONSTANT_ATTENUATION , c , 0 ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_LINEAR_ATTENUATION , l , 0 ) ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_QUADRATIC_ATTENUATION , q , 0 ) ; } | Set attenuation rates for point lights spot lights and ambient lights . | 197 | 13 |
10,204 | public void setLightSpecular ( int i , Color color ) { float [ ] tmpColor = { ( float ) color . getRed ( ) , ( float ) color . getGreen ( ) , ( float ) color . getBlue ( ) , ( float ) color . getAlpha ( ) } ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_SPECULAR , tmpColor , 0 ) ; } | Sets the specular color for No . i light . | 95 | 12 |
10,205 | public void setLightDiffuse ( int i , Color color ) { float [ ] tmpColor = { ( float ) color . getRed ( ) , ( float ) color . getGreen ( ) , ( float ) color . getBlue ( ) , ( float ) color . getAlpha ( ) } ; gl . glLightfv ( GL2 . GL_LIGHT0 + i , GL2 . GL_DIFFUSE , tmpColor , 0 ) ; } | Sets the diffuse color for No . i light . | 96 | 11 |
10,206 | private static float [ ] normalize ( float [ ] in ) { float [ ] out = new float [ in . length ] ; for ( int i = 0 ; i < in . length ; i ++ ) { out [ i ] = ( in [ i ] / 255.0f ) ; } return out ; } | Returns the array normalized from 0 - 255 to 0 - 1 . 0 . | 66 | 15 |
10,207 | public void setPerspective ( double fov , double aspect , double zNear , double zFar ) { matrixMode ( MatrixMode . PROJECTION ) ; resetMatrix ( ) ; glu . gluPerspective ( fov , aspect , zNear , zFar ) ; matrixMode ( MatrixMode . MODELVIEW ) ; resetMatrix ( ) ; } | Sets a perspective projection applying foreshortening making distant objects appear smaller than closer ones . The parameters define a viewing volume with the shape of truncated pyramid . Objects near to the front of the volume appear their actual size while farther objects appear smaller . This projection simulates the perspective of the world more accurately than orthographic projection . | 77 | 66 |
10,208 | public void setPerspective ( ) { double cameraZ = ( ( height / 2.0 ) / Math . tan ( Math . PI * 60.0 / 360.0 ) ) ; matrixMode ( MatrixMode . PROJECTION ) ; resetMatrix ( ) ; glu . gluPerspective ( Math . PI / 3.0 , this . width / this . height , cameraZ / 10.0 , cameraZ * 10.0 ) ; matrixMode ( MatrixMode . MODELVIEW ) ; resetMatrix ( ) ; } | Sets a default perspective . | 113 | 6 |
10,209 | public void setOrtho ( double left , double right , double bottom , double top , double near , double far ) { matrixMode ( MatrixMode . PROJECTION ) ; resetMatrix ( ) ; gl . glOrtho ( left , right , bottom , top , near , far ) ; matrixMode ( MatrixMode . MODELVIEW ) ; resetMatrix ( ) ; } | Sets an orthographic projection and defines a parallel clipping volume . All objects with the same dimension appear the same size regardless of whether they are near or far from the camera . The parameters to this function specify the clipping volume where left and right are the minimum and maximum x values top and bottom are the minimum and maximum y values and near and far are the minimum and maximum z values . | 79 | 77 |
10,210 | public void setOrtho ( ) { matrixMode ( MatrixMode . PROJECTION ) ; resetMatrix ( ) ; gl . glOrtho ( 0 , this . width , 0 , this . height , - 1.0e10 , 1.0e10 ) ; matrixMode ( MatrixMode . MODELVIEW ) ; resetMatrix ( ) ; } | Sets the default orthographic projection . | 75 | 8 |
10,211 | public void setFrustum ( double left , double right , double bottom , double top , double near , double far ) { matrixMode ( MatrixMode . PROJECTION ) ; resetMatrix ( ) ; gl . glFrustum ( left , right , bottom , top , near , far ) ; matrixMode ( MatrixMode . MODELVIEW ) ; resetMatrix ( ) ; } | Sets a perspective matrix defined through the parameters . Works like glFrustum except it wipes out the current perspective matrix rather than multiplying itself with it . | 79 | 31 |
10,212 | public void setCamera ( ) { glu . gluLookAt ( width / 2.0 , height / 2.0 , ( height / 2.0 ) / Math . tan ( Math . PI * 60.0 / 360.0 ) , width / 2.0 , height / 2.0 , 0 , 0 , 1 , 0 ) ; } | Sets the default camera position . | 74 | 7 |
10,213 | public Key getKey ( ) { final Key ret = new Key ( ) . setPersonId ( getPersonId ( ) ) . setCompanyId ( getCompanyId ( ) ) . setTypeId ( getTypeId ( ) ) ; return ret ; } | Gets the key . | 53 | 5 |
10,214 | @ Override public String getTag ( ) throws IOException { URLConnection urlConnection = url . openConnection ( ) ; String tag = urlConnection . getHeaderField ( ETAG ) ; if ( tag == null ) { String key = url . toString ( ) + "@" + urlConnection . getLastModified ( ) ; tag = md5Cache . getIfPresent ( key ) ; if ( tag == null ) { try ( InputStream urlStream = urlConnection . getInputStream ( ) ) { byte [ ] data = ByteStreams . toByteArray ( urlConnection . getInputStream ( ) ) ; tag = Hashing . md5 ( ) . hashBytes ( data ) . toString ( ) ; md5Cache . put ( key , tag ) ; } } } return tag ; } | Gets the tag using either the ETAG header of the URL connection or calculates it and caches it based on the URL & last modified date | 168 | 28 |
10,215 | private List < Pair < Id , GuiceSupplier > > getSuppliers ( ) { ImmutableList . Builder < Pair < Id , GuiceSupplier > > suppliersBuilder = ImmutableList . builder ( ) ; for ( Binding < GuiceRegistration > registrationBinding : injector . findBindingsByType ( TypeLiteral . get ( GuiceRegistration . class ) ) ) { Key < ? > key = registrationBinding . getProvider ( ) . get ( ) . key ( ) ; suppliersBuilder . add ( newPair ( key ) ) ; } return suppliersBuilder . build ( ) ; } | enforce load all providers before register them | 130 | 8 |
10,216 | public SQLSelect column ( final String _name ) { columns . add ( new Column ( tablePrefix , null , _name ) ) ; return this ; } | Appends a selected column . | 33 | 6 |
10,217 | public int columnIndex ( final int _tableIndex , final String _columnName ) { final Optional < Column > colOpt = getColumns ( ) . stream ( ) . filter ( column -> column . tableIndex == _tableIndex && column . columnName . equals ( _columnName ) ) . findFirst ( ) ; final int ret ; if ( colOpt . isPresent ( ) ) { ret = getColumns ( ) . indexOf ( colOpt . get ( ) ) ; } else { columns . add ( new Column ( tablePrefix , _tableIndex , _columnName ) ) ; ret = getColumnIdx ( ) ; } return ret ; } | Column index . | 139 | 3 |
10,218 | public String getSQL ( ) { final StringBuilder cmd = new StringBuilder ( ) . append ( " " ) . append ( Context . getDbType ( ) . getSQLPart ( SQLPart . SELECT ) ) . append ( " " ) ; if ( distinct ) { cmd . append ( Context . getDbType ( ) . getSQLPart ( SQLPart . DISTINCT ) ) . append ( " " ) ; } boolean first = true ; for ( final Column column : columns ) { if ( first ) { first = false ; } else { cmd . append ( Context . getDbType ( ) . getSQLPart ( SQLPart . COMMA ) ) ; } column . appendSQL ( cmd ) ; } cmd . append ( " " ) . append ( Context . getDbType ( ) . getSQLPart ( SQLPart . FROM ) ) . append ( " " ) ; first = true ; for ( final FromTable fromTable : fromTables ) { fromTable . appendSQL ( first , cmd ) ; if ( first ) { first = false ; } } cmd . append ( " " ) ; boolean whereAdded = false ; for ( final SQLSelectPart part : parts ) { part . appendSQL ( cmd ) ; cmd . append ( " " ) ; whereAdded = whereAdded || ! whereAdded && SQLPart . WHERE . equals ( part . sqlpart ) ; } if ( where != null ) { where . setStarted ( whereAdded ) ; where . appendSQL ( tablePrefix , cmd ) ; } if ( order != null ) { order . appendSQL ( tablePrefix , cmd ) ; } return cmd . toString ( ) ; } | Returns the depending SQL statement . | 347 | 6 |
10,219 | public SQLSelect addColumnPart ( final Integer _tableIndex , final String _columnName ) { parts . add ( new Column ( tablePrefix , _tableIndex , _columnName ) ) ; return this ; } | Add a column as part . | 45 | 6 |
10,220 | public SQLSelect addTablePart ( final String _tableName , final Integer _tableIndex ) { parts . add ( new FromTable ( tablePrefix , _tableName , _tableIndex ) ) ; return this ; } | Add a table as part . | 46 | 6 |
10,221 | public SQLSelect addTimestampValue ( final String _isoDateTime ) { parts . add ( new Value ( Context . getDbType ( ) . getTimestampValue ( _isoDateTime ) ) ) ; return this ; } | Add a timestamp value to the select . | 48 | 8 |
10,222 | public static CachedPrintQuery get4Request ( final Instance _instance ) throws EFapsException { return new CachedPrintQuery ( _instance , Context . getThreadContext ( ) . getRequestId ( ) ) . setLifespan ( 5 ) . setLifespanUnit ( TimeUnit . MINUTES ) ; } | Get a CachedPrintQuery that will only cache during a request . | 71 | 14 |
10,223 | @ Override protected void prepare ( final AbstractSQLInsertUpdate < ? > _insertUpdate , final Attribute _attribute , final Object ... _values ) throws SQLException { checkSQLColumnSize ( _attribute , 1 ) ; try { _insertUpdate . column ( _attribute . getSqlColNames ( ) . get ( 0 ) , Context . getThreadContext ( ) . getPerson ( ) . getId ( ) ) ; } catch ( final EFapsException e ) { throw new SQLException ( "could not fetch current context person id" , e ) ; } } | The instance method sets the value in the insert statement to the id of the current context user . | 123 | 19 |
10,224 | protected void addMapping ( final ColumnType _columnType , final String _writeTypeName , final String _nullValueSelect , final String ... _readTypeNames ) { this . writeColTypeMap . put ( _columnType , _writeTypeName ) ; this . nullValueColTypeMap . put ( _columnType , _nullValueSelect ) ; for ( final String readTypeName : _readTypeNames ) { Set < AbstractDatabase . ColumnType > colTypes = this . readColTypeMap . get ( readTypeName ) ; if ( colTypes == null ) { colTypes = new HashSet <> ( ) ; this . readColTypeMap . put ( readTypeName , colTypes ) ; } colTypes . add ( _columnType ) ; } } | Adds a new mapping for given eFaps column type used for mapping from and to the SQL database . | 163 | 21 |
10,225 | public boolean existsView ( final Connection _con , final String _viewName ) throws SQLException { boolean ret = false ; final DatabaseMetaData metaData = _con . getMetaData ( ) ; // first test with lower case final ResultSet rs = metaData . getTables ( null , null , _viewName . toLowerCase ( ) , new String [ ] { "VIEW" } ) ; if ( rs . next ( ) ) { ret = true ; } rs . close ( ) ; // then test with upper case if ( ! ret ) { final ResultSet rsUC = metaData . getTables ( null , null , _viewName . toUpperCase ( ) , new String [ ] { "VIEW" } ) ; if ( rsUC . next ( ) ) { ret = true ; } rsUC . close ( ) ; } return ret ; } | The method tests if a view with given name exists . | 184 | 11 |
10,226 | public T updateColumn ( final Connection _con , final String _tableName , final String _columnName , final ColumnType _columnType , final int _length , final int _scale ) throws SQLException { final StringBuilder cmd = new StringBuilder ( ) ; cmd . append ( "alter table " ) . append ( getTableQuote ( ) ) . append ( _tableName ) . append ( getTableQuote ( ) ) . append ( getAlterColumn ( _columnName , _columnType ) ) ; if ( _length > 0 ) { cmd . append ( "(" ) . append ( _length ) ; if ( _scale > 0 ) { cmd . append ( "," ) . append ( _scale ) ; } cmd . append ( ")" ) ; } AbstractDatabase . LOG . debug ( " ..SQL> " + cmd . toString ( ) ) ; final Statement stmt = _con . createStatement ( ) ; try { stmt . execute ( cmd . toString ( ) ) ; } finally { stmt . close ( ) ; } @ SuppressWarnings ( "unchecked" ) final T ret = ( T ) this ; return ret ; } | Adds a column to a SQL table . | 247 | 8 |
10,227 | public T addUniqueKey ( final Connection _con , final String _tableName , final String _uniqueKeyName , final String _columns ) throws SQLException { final StringBuilder cmd = new StringBuilder ( ) ; cmd . append ( "alter table " ) . append ( _tableName ) . append ( " " ) . append ( "add constraint " ) . append ( _uniqueKeyName ) . append ( " " ) . append ( "unique(" ) . append ( _columns ) . append ( ")" ) ; AbstractDatabase . LOG . debug ( " ..SQL> " + cmd . toString ( ) ) ; final Statement stmt = _con . createStatement ( ) ; try { stmt . execute ( cmd . toString ( ) ) ; } finally { stmt . close ( ) ; } @ SuppressWarnings ( "unchecked" ) final T ret = ( T ) this ; return ret ; } | Adds a new unique key to given table name . | 197 | 10 |
10,228 | public T addForeignKey ( final Connection _con , final String _tableName , final String _foreignKeyName , final String _key , final String _reference , final boolean _cascade ) throws InstallationException { final StringBuilder cmd = new StringBuilder ( ) . append ( "alter table " ) . append ( _tableName ) . append ( " " ) . append ( "add constraint " ) . append ( _foreignKeyName ) . append ( " " ) . append ( "foreign key(" ) . append ( _key ) . append ( ") " ) . append ( "references " ) . append ( _reference ) ; if ( _cascade ) { cmd . append ( " on delete cascade" ) ; } AbstractDatabase . LOG . debug ( " ..SQL> " + cmd . toString ( ) ) ; try { final Statement stmt = _con . createStatement ( ) ; try { stmt . execute ( cmd . toString ( ) ) ; } finally { stmt . close ( ) ; } } catch ( final SQLException e ) { throw new InstallationException ( "Foreign key could not be created. SQL statement was:\n" + cmd . toString ( ) , e ) ; } @ SuppressWarnings ( "unchecked" ) final T ret = ( T ) this ; return ret ; } | Adds a foreign key to given SQL table . | 281 | 9 |
10,229 | public void addCheckKey ( final Connection _con , final String _tableName , final String _checkKeyName , final String _condition ) throws SQLException { final StringBuilder cmd = new StringBuilder ( ) . append ( "alter table " ) . append ( _tableName ) . append ( " " ) . append ( "add constraint " ) . append ( _checkKeyName ) . append ( " " ) . append ( "check(" ) . append ( _condition ) . append ( ")" ) ; AbstractDatabase . LOG . debug ( " ..SQL> " + cmd . toString ( ) ) ; // excecute statement final Statement stmt = _con . createStatement ( ) ; try { stmt . execute ( cmd . toString ( ) ) ; } finally { stmt . close ( ) ; } } | Adds a new check key to given SQL table . | 174 | 10 |
10,230 | public static AbstractDatabase < ? > findByClassName ( final String _dbClassName ) throws ClassNotFoundException , InstantiationException , IllegalAccessException { return ( AbstractDatabase < ? > ) Class . forName ( _dbClassName ) . newInstance ( ) ; } | Instantiate the given DB class name and returns them . | 58 | 11 |
10,231 | private Collection < Observable < Attachment > > upload ( RxComapiClient client , List < Attachment > data ) { Collection < Observable < Attachment >> obsList = new ArrayList <> ( ) ; for ( Attachment a : data ) { obsList . add ( upload ( client , a ) ) ; } return obsList ; } | Create list of upload attachment observables . | 73 | 8 |
10,232 | private Observable < Attachment > upload ( RxComapiClient client , Attachment a ) { return client . service ( ) . messaging ( ) . uploadContent ( a . getFolder ( ) , a . getData ( ) ) . map ( response -> a . updateWithUploadDetails ( response . getResult ( ) ) ) . doOnError ( t -> log . e ( "Error uploading attachment. " + t . getLocalizedMessage ( ) ) ) . onErrorReturn ( a :: setError ) ; } | Upload single attachment and update the details in it from the response . | 108 | 13 |
10,233 | public void set ( double left , double right , double bottom , double top , double near , double far ) { this . left = left ; this . right = right ; this . bottom = bottom ; this . top = top ; this . near = near ; this . far = far ; } | Sets the clipping plane . | 60 | 6 |
10,234 | public static AbstractStmt getStatement ( final CharSequence _stmt ) { AbstractStmt ret = null ; final IStatement < ? > stmt = parse ( _stmt ) ; if ( stmt instanceof IPrintStatement ) { ret = PrintStmt . get ( ( IPrintStatement < ? > ) stmt ) ; } else if ( stmt instanceof IDeleteStatement ) { ret = DeleteStmt . get ( ( IDeleteStatement < ? > ) stmt ) ; } else if ( stmt instanceof IInsertStatement ) { ret = InsertStmt . get ( ( IInsertStatement ) stmt ) ; } else if ( stmt instanceof IUpdateStatement ) { ret = UpdateStmt . get ( ( IUpdateStatement < ? > ) stmt ) ; } return ret ; } | Parses the stmt . | 174 | 7 |
10,235 | public static List < Instance > getInstances ( final AbstractQueryPart _queryPart ) throws EFapsException { return getQueryBldr ( _queryPart ) . getQuery ( ) . execute ( ) ; } | Gets the instances . | 46 | 5 |
10,236 | public static BigDecimal parseLocalized ( final String _value ) throws EFapsException { final DecimalFormat format = ( DecimalFormat ) NumberFormat . getInstance ( Context . getThreadContext ( ) . getLocale ( ) ) ; format . setParseBigDecimal ( true ) ; try { return ( BigDecimal ) format . parse ( _value ) ; } catch ( final ParseException e ) { throw new EFapsException ( DecimalType . class , "ParseException" , e ) ; } } | Method to parse a localized String to an BigDecimal . | 112 | 12 |
10,237 | public void update ( String cacheName , Cache cache ) { cacheManager . enableManagement ( cacheName , cache . isManagementEnabled ( ) ) ; updateStatistics ( cacheName , cache ) ; } | Update mutable information of cache configuration such as management and statistics support | 40 | 13 |
10,238 | public void setStatistics ( boolean enabled ) { all ( ) . forEach ( cache -> updateStatistics ( cache . getName ( ) , new Cache ( false , enabled ) ) ) ; } | Enable or disable statistics for all caches | 39 | 7 |
10,239 | public Optional < CacheStatistics > getStatistics ( String cacheName ) { javax . cache . Cache cache = cacheManager . getCache ( cacheName ) ; if ( cache == null ) { return Optional . empty ( ) ; } if ( ( ( CompleteConfiguration ) cache . getConfiguration ( CompleteConfiguration . class ) ) . isStatisticsEnabled ( ) && cache instanceof ICache ) { com . hazelcast . cache . CacheStatistics stats = ( ( ICache ) cache ) . getLocalCacheStatistics ( ) ; CacheStatistics statistics = new CacheStatistics ( stats . getCacheHits ( ) , stats . getCacheMisses ( ) , stats . getCacheHitPercentage ( ) , stats . getCacheMissPercentage ( ) , stats . getCacheGets ( ) , stats . getCachePuts ( ) , stats . getCacheRemovals ( ) , stats . getCacheEvictions ( ) , stats . getAverageGetTime ( ) , stats . getAveragePutTime ( ) , stats . getAverageRemoveTime ( ) ) ; return Optional . of ( statistics ) ; } return Optional . empty ( ) ; } | Get a cache statistic information if available | 235 | 7 |
10,240 | private void setAttrValue ( final AttrName _attrName , final String _value ) { synchronized ( this . attrValues ) { this . attrValues . put ( _attrName , _value ) ; } } | The method sets the attribute values in the cache for given attribute name to given new attribute value . | 48 | 19 |
10,241 | public Locale getLocale ( ) { final Locale ret ; if ( this . attrValues . get ( Person . AttrName . LOCALE ) != null ) { final String localeStr = this . attrValues . get ( Person . AttrName . LOCALE ) ; final String [ ] countries = localeStr . split ( "_" ) ; if ( countries . length == 2 ) { ret = new Locale ( countries [ 0 ] , countries [ 1 ] ) ; } else if ( countries . length == 3 ) { ret = new Locale ( countries [ 0 ] , countries [ 1 ] , countries [ 2 ] ) ; } else { ret = new Locale ( localeStr ) ; } } else { ret = Locale . ENGLISH ; } return ret ; } | Method to get the Locale of this Person . Default is the English Locale . | 165 | 17 |
10,242 | public String getLanguage ( ) { return this . attrValues . get ( Person . AttrName . LANGUAGE ) != null ? this . attrValues . get ( Person . AttrName . LANGUAGE ) : Locale . ENGLISH . getISO3Language ( ) ; } | Method to get the Language of the UserInterface for this Person . Default is english . | 65 | 17 |
10,243 | public DateTimeZone getTimeZone ( ) { return this . attrValues . get ( Person . AttrName . TIMZONE ) != null ? DateTimeZone . forID ( this . attrValues . get ( Person . AttrName . TIMZONE ) ) : DateTimeZone . UTC ; } | Method to get the Timezone of this Person . Default is the UTC Timezone . | 66 | 17 |
10,244 | public ChronologyType getChronologyType ( ) { final String chronoKey = this . attrValues . get ( Person . AttrName . CHRONOLOGY ) ; final ChronologyType chronoType ; if ( chronoKey != null ) { chronoType = ChronologyType . getByKey ( chronoKey ) ; } else { chronoType = ChronologyType . ISO8601 ; } return chronoType ; } | Method to get the ChronologyType of this Person . Default is the ISO8601 ChronologyType . | 93 | 21 |
10,245 | public boolean checkPassword ( final String _passwd ) throws EFapsException { boolean ret = false ; final PrintQuery query = new PrintQuery ( CIAdminUser . Person . getType ( ) , getId ( ) ) ; query . addAttribute ( CIAdminUser . Person . Password , CIAdminUser . Person . LastLogin , CIAdminUser . Person . LoginTry , CIAdminUser . Person . LoginTriesCounter , CIAdminUser . Person . Status ) ; if ( query . executeWithoutAccessCheck ( ) ) { final PasswordStore pwd = query . < PasswordStore > getAttribute ( CIAdminUser . Person . Password ) ; if ( pwd . checkCurrent ( _passwd ) ) { ret = query . < Boolean > getAttribute ( CIAdminUser . Person . Status ) ; } else { setFalseLogin ( query . < DateTime > getAttribute ( CIAdminUser . Person . LoginTry ) , query . < Integer > getAttribute ( CIAdminUser . Person . LoginTriesCounter ) ) ; } } return ret ; } | The instance method checks if the given password is the same password as the password in the database . | 220 | 19 |
10,246 | private void setFalseLogin ( final DateTime _logintry , final int _count ) throws EFapsException { if ( _count > 0 ) { final DateTime now = new DateTime ( DateTimeUtil . getCurrentTimeFromDB ( ) . getTime ( ) ) ; final SystemConfiguration kernelConfig = EFapsSystemConfiguration . get ( ) ; final int minutes = kernelConfig . getAttributeValueAsInteger ( KernelSettings . LOGIN_TIME_RETRY ) ; final int maxtries = kernelConfig . getAttributeValueAsInteger ( KernelSettings . LOGIN_MAX_TRIES ) ; final int count = _count + 1 ; if ( minutes > 0 && _logintry . minusMinutes ( minutes ) . isBefore ( now ) ) { updateFalseLoginDB ( 1 ) ; } else { updateFalseLoginDB ( count ) ; } if ( maxtries > 0 && count > maxtries && getStatus ( ) ) { setStatusInDB ( false ) ; } } else { updateFalseLoginDB ( 1 ) ; } } | Method that sets the time and the number of failed logins . | 223 | 13 |
10,247 | private void updateFalseLoginDB ( final int _tries ) throws EFapsException { Connection con = null ; try { con = Context . getConnection ( ) ; Statement stmt = null ; final StringBuilder cmd = new StringBuilder ( ) ; try { cmd . append ( "update T_USERPERSON " ) . append ( "set LOGINTRY=" ) . append ( Context . getDbType ( ) . getCurrentTimeStamp ( ) ) . append ( ", LOGINTRIES=" ) . append ( _tries ) . append ( " where ID=" ) . append ( getId ( ) ) ; stmt = con . createStatement ( ) ; final int rows = stmt . executeUpdate ( cmd . toString ( ) ) ; if ( rows == 0 ) { Person . LOG . error ( "could not execute '" + cmd . toString ( ) + "' to update last login information for person '" + toString ( ) + "'" ) ; throw new EFapsException ( getClass ( ) , "updateLastLogin.NotUpdated" , cmd . toString ( ) , getName ( ) ) ; } } catch ( final SQLException e ) { Person . LOG . error ( "could not execute '" + cmd . toString ( ) + "' to update last login information for person '" + toString ( ) + "'" , e ) ; throw new EFapsException ( getClass ( ) , "updateLastLogin.SQLException" , e , cmd . toString ( ) , getName ( ) ) ; } finally { try { if ( stmt != null ) { stmt . close ( ) ; } } catch ( final SQLException e ) { throw new EFapsException ( getClass ( ) , "updateLastLogin.SQLException" , e , cmd . toString ( ) , getName ( ) ) ; } } con . commit ( ) ; con . close ( ) ; } catch ( final SQLException e ) { // TODO Auto-generated catch block e . printStackTrace ( ) ; } } | Method to set the number of false Login tries in the eFaps - DataBase . | 443 | 18 |
10,248 | public Status setPassword ( final String _newPasswd ) throws EFapsException { final Type type = CIAdminUser . Person . getType ( ) ; if ( _newPasswd . length ( ) == 0 ) { throw new EFapsException ( getClass ( ) , "PassWordLength" , 1 , _newPasswd . length ( ) ) ; } final Update update = new Update ( type , "" + getId ( ) ) ; final Status status = update . add ( CIAdminUser . Person . Password , _newPasswd ) ; if ( status . isOk ( ) ) { update . execute ( ) ; update . close ( ) ; } else { Person . LOG . error ( "Password could not be set by the Update, due to restrictions " + "e.g. length???" ) ; throw new EFapsException ( getClass ( ) , "TODO" ) ; } return status ; } | The instance method sets the new password for the current context user . Before the new password is set some checks are made . | 194 | 24 |
10,249 | protected void readFromDB ( ) throws EFapsException { readFromDBAttributes ( ) ; this . roles . clear ( ) ; for ( final Role role : getRolesFromDB ( ) ) { add ( role ) ; } this . groups . clear ( ) ; for ( final Group group : getGroupsFromDB ( null ) ) { add ( group ) ; } this . companies . clear ( ) ; for ( final Company company : getCompaniesFromDB ( null ) ) { add ( company ) ; } this . associations . clear ( ) ; for ( final Association association : getAssociationsFromDB ( null ) ) { add ( association ) ; } } | The instance method reads all information from the database . | 141 | 10 |
10,250 | private void readFromDBAttributes ( ) throws EFapsException { Connection con = null ; try { con = Context . getConnection ( ) ; Statement stmt = null ; try { stmt = con . createStatement ( ) ; final StringBuilder cmd = new StringBuilder ( "select " ) ; for ( final AttrName attrName : Person . AttrName . values ( ) ) { cmd . append ( attrName . sqlColumn ) . append ( "," ) ; } cmd . append ( "0 as DUMMY " ) . append ( "from V_USERPERSON " ) . append ( "where V_USERPERSON.ID=" ) . append ( getId ( ) ) ; final ResultSet resultset = stmt . executeQuery ( cmd . toString ( ) ) ; if ( resultset . next ( ) ) { for ( final AttrName attrName : Person . AttrName . values ( ) ) { final String tmp = resultset . getString ( attrName . sqlColumn ) ; setAttrValue ( attrName , tmp == null ? null : tmp . trim ( ) ) ; } } resultset . close ( ) ; } catch ( final SQLException e ) { Person . LOG . error ( "read attributes for person with SQL statement is not " + "possible" , e ) ; throw new EFapsException ( Person . class , "readFromDBAttributes.SQLException" , e , getName ( ) , getId ( ) ) ; } finally { try { if ( stmt != null ) { stmt . close ( ) ; } con . commit ( ) ; } catch ( final SQLException e ) { Person . LOG . error ( "close of SQL statement is not possible" , e ) ; } } } finally { try { if ( con != null && ! con . isClosed ( ) ) { con . close ( ) ; } } catch ( final SQLException e ) { throw new CacheReloadException ( "could not read child type ids" , e ) ; } } } | All attributes from this person are read from the database . | 446 | 11 |
10,251 | public void setGroups ( final JAASSystem _jaasSystem , final Set < Group > _groups ) throws EFapsException { if ( _jaasSystem == null ) { throw new EFapsException ( getClass ( ) , "setGroups.nojaasSystem" , getName ( ) ) ; } if ( _groups == null ) { throw new EFapsException ( getClass ( ) , "setGroups.noGroups" , getName ( ) ) ; } for ( final Group group : _groups ) { add ( group ) ; } // current groups final Set < Group > groupsInDb = getGroupsFromDB ( _jaasSystem ) ; // compare new roles with current groups (add missing groups) for ( final Group group : _groups ) { if ( ! groupsInDb . contains ( group ) ) { assignGroupInDb ( _jaasSystem , group ) ; } } // compare current roles with new groups (remove groups which are to // much) for ( final Group group : groupsInDb ) { if ( ! _groups . contains ( group ) ) { unassignGroupInDb ( _jaasSystem , group ) ; } } } | The depending groups for the user are set for the given JAAS system . All groups are added to the loaded groups in the cache of this person . | 250 | 30 |
10,252 | public void assignGroupInDb ( final JAASSystem _jaasSystem , final Group _group ) throws EFapsException { assignToUserObjectInDb ( CIAdminUser . Person2Group . getType ( ) , _jaasSystem , _group ) ; } | For this person a group is assigned for the given JAAS system . | 56 | 14 |
10,253 | public void unassignGroupInDb ( final JAASSystem _jaasSystem , final Group _group ) throws EFapsException { unassignFromUserObjectInDb ( CIAdminUser . Person2Group . getType ( ) , _jaasSystem , _group ) ; } | The given group is unassigned for the given JAAS system from this person . | 60 | 17 |
10,254 | public static void reset ( final String _key ) throws EFapsException { final Person person ; if ( UUIDUtil . isUUID ( _key ) ) { person = Person . get ( UUID . fromString ( _key ) ) ; } else { person = Person . get ( _key ) ; } if ( person != null ) { InfinispanCache . get ( ) . < Long , Person > getCache ( Person . IDCACHE ) . remove ( person . getId ( ) ) ; InfinispanCache . get ( ) . < String , Person > getCache ( Person . NAMECACHE ) . remove ( person . getName ( ) ) ; if ( person . getUUID ( ) != null ) { InfinispanCache . get ( ) . < UUID , Person > getCache ( Person . UUIDCACHE ) . remove ( person . getUUID ( ) ) ; } } } | Reset a person . Meaning ti will be removed from all Caches . | 198 | 15 |
10,255 | public void preparePostUpload ( final List < Attachment > attachments ) { tempParts . clear ( ) ; if ( ! attachments . isEmpty ( ) ) { for ( Attachment a : attachments ) { if ( a . getError ( ) != null ) { errorParts . add ( createErrorPart ( a ) ) ; } else { publicParts . add ( createPart ( a ) ) ; } } } } | Replace temporary attachment parts with final parts with upload details or error message . | 86 | 15 |
10,256 | private Part createErrorPart ( Attachment a ) { return Part . builder ( ) . setName ( String . valueOf ( a . hashCode ( ) ) ) . setSize ( 0 ) . setType ( Attachment . LOCAL_PART_TYPE_ERROR ) . setUrl ( null ) . setData ( a . getError ( ) . getLocalizedMessage ( ) ) . build ( ) ; } | Create message part based on attachment upload error details . | 86 | 10 |
10,257 | private Part createTempPart ( Attachment a ) { return Part . builder ( ) . setName ( String . valueOf ( a . hashCode ( ) ) ) . setSize ( 0 ) . setType ( Attachment . LOCAL_PART_TYPE_UPLOADING ) . setUrl ( null ) . setData ( null ) . build ( ) ; } | Create message part based on attachment upload . This is a temporary message to indicate that one of the attachments for this message is being uploaded . | 77 | 27 |
10,258 | private Part createPart ( Attachment a ) { return Part . builder ( ) . setName ( a . getName ( ) != null ? a . getName ( ) : a . getId ( ) ) . setSize ( a . getSize ( ) ) . setType ( a . getType ( ) ) . setUrl ( a . getUrl ( ) ) . build ( ) ; } | Create message part based on attachment details . | 82 | 8 |
10,259 | public MessageToSend prepareMessageToSend ( ) { originalMessage . getParts ( ) . clear ( ) ; originalMessage . getParts ( ) . addAll ( publicParts ) ; return originalMessage ; } | Prepare message to be sent through messaging service . | 43 | 10 |
10,260 | public ChatMessage createFinalMessage ( MessageSentResponse response ) { return ChatMessage . builder ( ) . setMessageId ( response . getId ( ) ) . setSentEventId ( response . getEventId ( ) ) . setConversationId ( conversationId ) . setSentBy ( sender ) . setFromWhom ( new Sender ( sender , sender ) ) . setSentOn ( System . currentTimeMillis ( ) ) . setParts ( getAllParts ( ) ) . setMetadata ( originalMessage . getMetadata ( ) ) . build ( ) ; } | Create a final message for a conversation . At this point we know message id and sent event id . | 122 | 20 |
10,261 | private void addTables ( ) { for ( final SQLTable table : getType ( ) . getTables ( ) ) { if ( ! getTable2values ( ) . containsKey ( table ) ) { getTable2values ( ) . put ( table , new ArrayList < Value > ( ) ) ; } } } | Add all tables of the type to the expressions because for the type an insert must be made for all tables!!! | 68 | 22 |
10,262 | private void addCreateUpdateAttributes ( ) throws EFapsException { final Iterator < ? > iter = getType ( ) . getAttributes ( ) . entrySet ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { final Map . Entry < ? , ? > entry = ( Map . Entry < ? , ? > ) iter . next ( ) ; final Attribute attr = ( Attribute ) entry . getValue ( ) ; final AttributeType attrType = attr . getAttributeType ( ) ; if ( attrType . isCreateUpdate ( ) ) { addInternal ( attr , false , ( Object ) null ) ; } if ( attr . getDefaultValue ( ) != null ) { addInternal ( attr , false , attr . getDefaultValue ( ) ) ; } } } | Add all attributes of the type which must be always updated and the default values . | 174 | 16 |
10,263 | public Insert setExchangeIds ( final Long _exchangeSystemId , final Long _exchangeId ) { this . exchangeSystemId = _exchangeSystemId ; this . exchangeId = _exchangeId ; return this ; } | Set the exchangeids for the new object . | 50 | 9 |
10,264 | @ Override public void executeWithoutTrigger ( ) throws EFapsException { final Context context = Context . getThreadContext ( ) ; ConnectionResource con = null ; try { con = context . getConnectionResource ( ) ; final SQLTable mainTable = getType ( ) . getMainTable ( ) ; final long id = executeOneStatement ( con , mainTable , getTable2values ( ) . get ( mainTable ) , 0 ) ; setInstance ( Instance . get ( getInstance ( ) . getType ( ) , id ) ) ; getInstance ( ) . setExchangeId ( this . exchangeId ) ; getInstance ( ) . setExchangeSystemId ( this . exchangeSystemId ) ; GeneralInstance . insert ( getInstance ( ) , con ) ; for ( final Entry < SQLTable , List < Value > > entry : getTable2values ( ) . entrySet ( ) ) { final SQLTable table = entry . getKey ( ) ; if ( ! table . equals ( mainTable ) && ! table . isReadOnly ( ) ) { executeOneStatement ( con , table , entry . getValue ( ) , id ) ; } } Queue . registerUpdate ( getInstance ( ) ) ; } finally { } } | The insert is done without calling triggers and check of access rights . | 258 | 13 |
10,265 | public static final Vector3D randVertex2d ( ) { float theta = random ( ( float ) ( Math . PI * 2.0 ) ) ; return new Vector3D ( Math . cos ( theta ) , Math . sin ( theta ) ) ; } | returns a random Vertex that represents a point on the unit circle | 58 | 14 |
10,266 | @ SuppressLint ( "UseSparseArrays" ) public void addStatusUpdate ( ChatMessageStatus status ) { int unique = ( status . getMessageId ( ) + status . getProfileId ( ) + status . getMessageStatus ( ) . name ( ) ) . hashCode ( ) ; if ( statusUpdates == null ) { statusUpdates = new HashMap <> ( ) ; } statusUpdates . put ( unique , status ) ; } | Update status list with a new status . | 98 | 8 |
10,267 | public static void put ( Map < String , Object > structure , String name , Object object ) { if ( name != null && object != null ) { structure . put ( name , object ) ; } } | Puts an object into a map | 42 | 7 |
10,268 | protected long createTaskInternal ( final String name , final String channel , final String data , final String key1 , final String key2 , final Long batchId , int postponeSec , TedStatus status ) { final String sqlLogId = "create_task" ; if ( status == null ) status = TedStatus . NEW ; String nextts = ( status == TedStatus . NEW ? dbType . sql . now ( ) + " + " + dbType . sql . intervalSeconds ( postponeSec ) : "null" ) ; String sql = " insert into tedtask (taskId, `system`, name, channel, bno, status, createTs, nextTs, retries, data, key1, key2, batchId)" + " values(null, '$sys', ?, ?, null, '$status', $now, $nextts, 0, ?, ?, ?, ?)" + " " ; sql = sql . replace ( "$nextTaskId" , dbType . sql . sequenceSql ( "SEQ_TEDTASK_ID" ) ) ; sql = sql . replace ( "$now" , dbType . sql . now ( ) ) ; sql = sql . replace ( "$sys" , thisSystem ) ; sql = sql . replace ( "$nextts" , nextts ) ; sql = sql . replace ( "$status" , status . toString ( ) ) ; final String finalSql = sql ; Long taskId = JdbcSelectTed . runInConn ( dataSource , new ExecInConn < Long > ( ) { @ Override public Long execute ( Connection connection ) throws SQLException { int res = JdbcSelectTedImpl . executeUpdate ( connection , finalSql , asList ( sqlParam ( name , JetJdbcParamType . STRING ) , sqlParam ( channel , JetJdbcParamType . STRING ) , sqlParam ( data , JetJdbcParamType . STRING ) , sqlParam ( key1 , JetJdbcParamType . STRING ) , sqlParam ( key2 , JetJdbcParamType . STRING ) , sqlParam ( batchId , JetJdbcParamType . LONG ) ) ) ; if ( res != 1 ) throw new IllegalStateException ( "expected 1 insert" ) ; String sql = "select last_insert_id()" ; return JdbcSelectTedImpl . selectSingleLong ( connection , sql , Collections . < SqlParam > emptyList ( ) ) ; } } ) ; logger . trace ( "Task {} {} created successfully. " , name , taskId ) ; return taskId ; } | taskid is autonumber in MySql | 559 | 10 |
10,269 | public static String escape ( String literal ) { StringBuilder sb = new StringBuilder ( ) ; for ( int ii = 0 ; ii < literal . length ( ) ; ii ++ ) { char cc = literal . charAt ( ii ) ; switch ( cc ) { case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : case ' ' : sb . append ( "\\" ) . append ( cc ) ; break ; default : sb . append ( cc ) ; break ; } } return sb . toString ( ) ; } | Escapes all regex control characters returning expression suitable for literal parsing . | 164 | 13 |
10,270 | public boolean isMatch ( CharSequence text ) { try { if ( text . length ( ) == 0 ) { return acceptEmpty ; } InputReader reader = Input . getInstance ( text ) ; return isMatch ( reader ) ; } catch ( IOException ex ) { throw new IllegalArgumentException ( "can't happen" ) ; } } | Return true if text matches the regex | 72 | 7 |
10,271 | public boolean isMatch ( PushbackReader input , int size ) throws IOException { InputReader reader = Input . getInstance ( input , size ) ; return isMatch ( reader ) ; } | Return true if input matches the regex | 39 | 7 |
10,272 | public boolean isMatch ( InputReader reader ) throws IOException { int rc = match ( reader ) ; return ( rc == 1 && reader . read ( ) == - 1 ) ; } | Return true if input matches the regex . | 38 | 8 |
10,273 | public String match ( CharSequence text ) { try { if ( text . length ( ) == 0 ) { if ( acceptEmpty ) { return "" ; } else { throw new SyntaxErrorException ( "empty string not accepted" ) ; } } InputReader reader = Input . getInstance ( text ) ; int rc = match ( reader ) ; if ( rc == 1 && reader . read ( ) == - 1 ) { return reader . getString ( ) ; } else { throw new SyntaxErrorException ( "syntax error" + "\n" + reader . getLineNumber ( ) + ": " + reader . getLine ( ) + "\n" + pointer ( reader . getColumnNumber ( ) + 2 ) ) ; } } catch ( IOException ex ) { throw new IllegalArgumentException ( "can't happen" ) ; } } | Attempts to match input to regex | 178 | 6 |
10,274 | public String lookingAt ( CharSequence text ) { try { if ( text . length ( ) == 0 ) { if ( acceptEmpty ) { return "" ; } else { throw new SyntaxErrorException ( "empty string not accepted" ) ; } } InputReader reader = Input . getInstance ( text ) ; return lookingAt ( reader ) ; } catch ( IOException ex ) { throw new IllegalArgumentException ( "can't happen" ) ; } } | Matches the start of text and returns the matched string | 96 | 11 |
10,275 | public String replace ( CharSequence text , CharSequence replacement ) { try { if ( text . length ( ) == 0 ) { if ( acceptEmpty ) { return "" ; } } CharArrayWriter caw = new CharArrayWriter ( ) ; InputReader reader = Input . getInstance ( text ) ; ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer ( replacement ) ; replace ( reader , caw , fsp ) ; return caw . toString ( ) ; } catch ( IOException ex ) { throw new IllegalArgumentException ( "can't happen" , ex ) ; } } | Replaces regular expression matches in text with replacement string | 128 | 10 |
10,276 | public String replace ( CharSequence text , ObsoleteReplacer replacer ) throws IOException { if ( text . length ( ) == 0 ) { return "" ; } CharArrayWriter caw = new CharArrayWriter ( ) ; InputReader reader = Input . getInstance ( text ) ; replace ( reader , caw , replacer ) ; return caw . toString ( ) ; } | Replaces regular expression matches in text using replacer | 81 | 10 |
10,277 | public void replace ( PushbackReader in , int bufferSize , Writer out , String format ) throws IOException { InputReader reader = Input . getInstance ( in , bufferSize ) ; ObsoleteSimpleReplacer fsp = new ObsoleteSimpleReplacer ( format ) ; replace ( reader , out , fsp ) ; } | Writes in to out replacing every match with a string | 67 | 11 |
10,278 | public void replace ( PushbackReader in , int bufferSize , Writer out , ObsoleteReplacer replacer ) throws IOException { InputReader reader = Input . getInstance ( in , bufferSize ) ; replace ( reader , out , replacer ) ; } | Replaces regular expression matches in input using replacer | 53 | 10 |
10,279 | public static Regex literal ( String expression , Option ... options ) throws IOException { return compile ( escape ( expression ) , options ) ; } | Compiles a literal string into RegexImpl class . This is ok for testing . use RegexBuilder ant task for release classes | 29 | 26 |
10,280 | public static DFA < Integer > createDFA ( String expression , int reducer , Option ... options ) { NFA < Integer > nfa = createNFA ( new Scope < NFAState < Integer > > ( expression ) , expression , reducer , options ) ; DFA < Integer > dfa = nfa . constructDFA ( new Scope < DFAState < Integer > > ( expression ) ) ; return dfa ; } | Creates a DFA from regular expression | 92 | 8 |
10,281 | static < T > List < T > executeOraBlock ( Connection connection , String sql , Class < T > clazz , List < SqlParam > sqlParams ) throws SQLException { String cursorParam = null ; List < T > list = new ArrayList < T > ( ) ; //boolean autoCommitOrig = connection.getAutoCommit(); //if (autoCommitOrig == true) { // connection.setAutoCommit(false); // to able to read from temp-tables //} CallableStatement stmt = null ; ResultSet resultSet = null ; try { stmt = connection . prepareCall ( sql ) ; cursorParam = stmtAssignSqlParams ( stmt , sqlParams ) ; boolean hasRs = stmt . execute ( ) ; if ( cursorParam != null ) { resultSet = ( ResultSet ) stmt . getObject ( cursorParam ) ; list = resultSetToList ( resultSet , clazz ) ; } } finally { try { if ( resultSet != null ) resultSet . close ( ) ; } catch ( Exception e ) { logger . error ( "Cannot close resultSet" , e ) ; } ; //if (autoCommitOrig == true) // connection.setAutoCommit(autoCommitOrig); try { if ( stmt != null ) stmt . close ( ) ; } catch ( Exception e ) { logger . error ( "Cannot close statement" , e ) ; } ; } return list ; } | Execute sql block or stored procedure . If exists output parameter with type CURSOR then return resultSet as List of clazz type objects . | 320 | 30 |
10,282 | Observable < List < ChatConversationBase > > loadAllConversations ( ) { return Observable . create ( emitter -> storeFactory . execute ( new StoreTransaction < ChatStore > ( ) { @ Override protected void execute ( ChatStore store ) { store . open ( ) ; List < ChatConversationBase > conversations = store . getAllConversations ( ) ; store . close ( ) ; emitter . onNext ( conversations ) ; emitter . onCompleted ( ) ; } } ) , Emitter . BackpressureMode . LATEST ) ; } | Wraps loading all conversations from store implementation into an Observable . | 122 | 13 |
10,283 | Observable < ComapiResult < MessagesQueryResponse > > processOrphanedEvents ( ComapiResult < MessagesQueryResponse > result , final ChatController . OrphanedEventsToRemoveListener removeListener ) { if ( result . isSuccessful ( ) && result . getResult ( ) != null ) { final MessagesQueryResponse response = result . getResult ( ) ; final List < MessageReceived > messages = response . getMessages ( ) ; final String [ ] ids = new String [ messages . size ( ) ] ; if ( ! messages . isEmpty ( ) ) { for ( int i = 0 ; i < messages . size ( ) ; i ++ ) { ids [ i ] = messages . get ( i ) . getMessageId ( ) ; } } return db . save ( response . getOrphanedEvents ( ) ) . flatMap ( count -> db . queryOrphanedEvents ( ids ) ) . flatMap ( toDelete -> Observable . create ( emitter -> storeFactory . execute ( new StoreTransaction < ChatStore > ( ) { @ Override protected void execute ( ChatStore store ) { if ( ! toDelete . isEmpty ( ) ) { storeFactory . execute ( new StoreTransaction < ChatStore > ( ) { @ Override protected void execute ( ChatStore store ) { List < ChatMessageStatus > statuses = modelAdapter . adaptEvents ( toDelete ) ; store . beginTransaction ( ) ; if ( ! statuses . isEmpty ( ) ) { for ( ChatMessageStatus status : statuses ) { store . update ( status ) ; } } String [ ] ids = new String [ toDelete . size ( ) ] ; for ( int i = 0 ; i < toDelete . size ( ) ; i ++ ) { ids [ i ] = toDelete . get ( i ) . id ( ) ; } removeListener . remove ( ids ) ; store . endTransaction ( ) ; emitter . onNext ( result ) ; emitter . onCompleted ( ) ; } } ) ; } else { emitter . onNext ( result ) ; emitter . onCompleted ( ) ; } } } ) , Emitter . BackpressureMode . BUFFER ) ) ; } else { return Observable . fromCallable ( ( ) -> result ) ; } } | Handle orphaned events related to message query . | 483 | 9 |
10,284 | public Observable < Boolean > updateStoreWithNewMessage ( final ChatMessage message , final ChatController . NoConversationListener noConversationListener ) { return asObservable ( new Executor < Boolean > ( ) { @ Override protected void execute ( ChatStore store , Emitter < Boolean > emitter ) { boolean isSuccessful = true ; store . beginTransaction ( ) ; ChatConversationBase conversation = store . getConversation ( message . getConversationId ( ) ) ; String tempId = ( String ) ( message . getMetadata ( ) != null ? message . getMetadata ( ) . get ( MESSAGE_METADATA_TEMP_ID ) : null ) ; if ( ! TextUtils . isEmpty ( tempId ) ) { store . deleteMessage ( message . getConversationId ( ) , tempId ) ; } if ( message . getSentEventId ( ) == null ) { message . setSentEventId ( - 1L ) ; } if ( message . getSentEventId ( ) == - 1L ) { if ( conversation != null && conversation . getLastLocalEventId ( ) != - 1L ) { message . setSentEventId ( conversation . getLastLocalEventId ( ) + 1 ) ; } message . addStatusUpdate ( ChatMessageStatus . builder ( ) . populate ( message . getConversationId ( ) , message . getMessageId ( ) , message . getFromWhom ( ) . getId ( ) , LocalMessageStatus . sent , System . currentTimeMillis ( ) , null ) . build ( ) ) ; isSuccessful = store . upsert ( message ) ; } else { isSuccessful = store . upsert ( message ) ; } if ( ! doUpdateConversationFromEvent ( store , message . getConversationId ( ) , message . getSentEventId ( ) , message . getSentOn ( ) ) && noConversationListener != null ) { noConversationListener . getConversation ( message . getConversationId ( ) ) ; } store . endTransaction ( ) ; emitter . onNext ( isSuccessful ) ; emitter . onCompleted ( ) ; } } ) ; } | Deletes temporary message and inserts provided one . If no associated conversation exists will trigger GET from server . | 476 | 20 |
10,285 | public Observable < Boolean > updateStoreForSentError ( String conversationId , String tempId , String profileId ) { return asObservable ( new Executor < Boolean > ( ) { @ Override protected void execute ( ChatStore store , Emitter < Boolean > emitter ) { store . beginTransaction ( ) ; boolean isSuccess = store . update ( ChatMessageStatus . builder ( ) . populate ( conversationId , tempId , profileId , LocalMessageStatus . error , System . currentTimeMillis ( ) , null ) . build ( ) ) ; store . endTransaction ( ) ; emitter . onNext ( isSuccess ) ; emitter . onCompleted ( ) ; } } ) ; } | Insert error message status if sending message failed . | 147 | 9 |
10,286 | private boolean doUpdateConversationFromEvent ( ChatStore store , String conversationId , Long eventId , Long updatedOn ) { ChatConversationBase conversation = store . getConversation ( conversationId ) ; if ( conversation != null ) { ChatConversationBase . Builder builder = ChatConversationBase . baseBuilder ( ) . populate ( conversation ) ; if ( eventId != null ) { if ( conversation . getLastRemoteEventId ( ) < eventId ) { builder . setLastRemoteEventId ( eventId ) ; } if ( conversation . getLastLocalEventId ( ) < eventId ) { builder . setLastLocalEventId ( eventId ) ; } if ( conversation . getFirstLocalEventId ( ) == - 1 ) { builder . setFirstLocalEventId ( eventId ) ; } if ( conversation . getUpdatedOn ( ) < updatedOn ) { builder . setUpdatedOn ( updatedOn ) ; } } return store . update ( builder . build ( ) ) ; } return false ; } | Update conversation state with received event details . This should be called only inside transaction . | 215 | 16 |
10,287 | public Observable < Boolean > upsertConversation ( ChatConversation conversation ) { List < ChatConversation > conversations = new ArrayList <> ( ) ; conversations . add ( conversation ) ; return upsertConversations ( conversations ) ; } | Insert or update conversation in the store . | 54 | 8 |
10,288 | private < T > Observable < T > asObservable ( Executor < T > transaction ) { return Observable . create ( emitter -> storeFactory . execute ( new StoreTransaction < ChatStore > ( ) { @ Override protected void execute ( ChatStore store ) { try { transaction . execute ( store , emitter ) ; } finally { emitter . onCompleted ( ) ; } } } ) , Emitter . BackpressureMode . BUFFER ) ; } | Executes transaction callback ass an observable . | 98 | 8 |
10,289 | @ Override public void setCharset ( Charset cs , boolean fixedCharset ) { if ( includeLevel . in instanceof ModifiableCharset ) { ModifiableCharset sr = ( ModifiableCharset ) includeLevel . in ; sr . setCharset ( cs , fixedCharset ) ; } else { throw new UnsupportedOperationException ( "setting charset not supported with current input " + includeLevel . in ) ; } } | Set current character set . Only supported with byte input! | 100 | 11 |
10,290 | @ Override public void release ( ) throws IOException { if ( includeLevel . in != null && end != cursor ) { if ( end % size < cursor % size ) { buffer2 . position ( 0 ) ; buffer2 . limit ( ( int ) ( end % size ) ) ; buffer1 . position ( ( int ) ( cursor % size ) ) ; buffer1 . limit ( size ) ; } else { buffer2 . position ( ( int ) ( cursor % size ) ) ; buffer2 . limit ( ( int ) ( end % size ) ) ; buffer1 . position ( size ) ; } if ( features . contains ( UsePushback ) ) { if ( includeLevel . in instanceof Pushbackable ) { Pushbackable p = ( Pushbackable ) includeLevel . in ; p . pushback ( array2 ) ; } else { unread ( includeLevel . in ) ; } } else { if ( includeLevel . in instanceof Rewindable ) { Rewindable rewindable = ( Rewindable ) includeLevel . in ; rewindable . rewind ( ( int ) ( end - cursor ) ) ; } else { unread ( includeLevel . in ) ; } } buffer1 . clear ( ) ; buffer2 . clear ( ) ; end = cursor ; } } | Synchronizes actual reader to current cursor position | 271 | 9 |
10,291 | @ Override public int peek ( int offset ) throws IOException { long target = cursor + offset - 1 ; if ( target - end > size || target < end - size || target < 0 ) { throw new IllegalArgumentException ( "offset " + offset + " out of buffer" ) ; } if ( target >= end ) { int la = 0 ; while ( target >= end ) { int cc = read ( ) ; if ( cc == - 1 ) { if ( target + la == end ) { return - 1 ; } else { throw new IOException ( "eof" ) ; } } la ++ ; } rewind ( la ) ; } return get ( target ) ; } | get a char from input buffer . | 144 | 7 |
10,292 | @ Override public void rewind ( int count ) throws IOException { if ( count < 0 ) { throw new IllegalArgumentException ( "negative rewind " + count ) ; } cursor -= count ; if ( cursor < end - size || cursor < 0 ) { throw new IOException ( "insufficient room in the pushback buffer" ) ; } length -= count ; if ( length < 0 ) { throw new IOException ( "rewinding past input" ) ; } int ld = 0 ; for ( int ii = 0 ; ii < count ; ii ++ ) { if ( get ( ( cursor + ii ) ) == ' ' ) { ld ++ ; } } if ( ld > 0 ) { int l = includeLevel . line ; includeLevel . line = l - ld ; int c = 0 ; long start = Math . max ( 0 , end - size ) ; for ( long ii = cursor ; ii >= start ; ii -- ) { if ( get ( ii ) == ' ' ) { break ; } c ++ ; } includeLevel . column = c ; } else { int c = includeLevel . column ; includeLevel . column = c - count ; } } | Rewinds cursor position count characters . Used for unread . | 248 | 13 |
10,293 | @ Override public final int read ( ) throws IOException { assert cursor <= end ; if ( cursor >= end ) { if ( includeLevel . in == null ) { return - 1 ; } int cp = ( int ) ( cursor % size ) ; long len = size - ( cursor - waterMark ) ; int il ; if ( len > size - cp ) { buffer1 . position ( cp ) ; buffer1 . limit ( size ) ; buffer2 . position ( 0 ) ; buffer2 . limit ( ( int ) ( len - ( size - cp ) ) ) ; if ( ! buffer1 . hasRemaining ( ) && ! buffer2 . hasRemaining ( ) ) { throw new UnderflowException ( "Buffer size=" + size + " too small for operation" ) ; } il = fill ( includeLevel . in , array2 ) ; } else { buffer1 . position ( cp ) ; buffer1 . limit ( ( int ) ( cp + len ) ) ; if ( ! buffer1 . hasRemaining ( ) ) { throw new UnderflowException ( "Buffer size=" + size + " too small for operation" ) ; } il = fill ( includeLevel . in , array1 ) ; } if ( il == - 1 ) { if ( includeStack != null ) { while ( ! includeStack . isEmpty ( ) && il == - 1 ) { close ( includeLevel . in ) ; includeLevel = includeStack . pop ( ) ; return read ( ) ; } } return - 1 ; } if ( il == 0 ) { throw new IOException ( "No input! Use blocking mode?" ) ; } buffer1 . clear ( ) ; buffer2 . clear ( ) ; end += il ; if ( end < 0 ) { throw new IOException ( "end = " + end ) ; } } int rc = get ( cursor ++ ) ; if ( cursor < 0 ) { throw new IOException ( "cursor = " + cursor ) ; } includeLevel . forward ( rc ) ; length ++ ; if ( length > size ) { throw new IOException ( "input size " + length + " exceeds buffer size " + size ) ; } if ( checksum != null ) { checksum . update ( cursor - 1 , rc ) ; } return rc ; } | Reads from ring buffer or from actual reader . | 474 | 10 |
10,294 | @ Override public int parseInt ( long s , int l , int radix ) { return Primitives . parseInt ( getCharSequence ( s , l ) , radix ) ; } | Converts binary to int | 41 | 5 |
10,295 | @ GET public Response compile ( @ QueryParam ( "type" ) final String _type ) { boolean success = false ; try { if ( hasAccess ( ) ) { AbstractRest . LOG . info ( "===Starting Compiler via REST===" ) ; if ( "java" . equalsIgnoreCase ( _type ) ) { AbstractRest . LOG . info ( "==Compiling Java==" ) ; new ESJPCompiler ( getClassPathElements ( ) ) . compile ( null , false ) ; } else if ( "css" . equalsIgnoreCase ( _type ) ) { AbstractRest . LOG . info ( "==Compiling CSS==" ) ; new CSSCompiler ( ) . compile ( ) ; } else if ( "js" . equalsIgnoreCase ( _type ) ) { AbstractRest . LOG . info ( "==Compiling Javascript==" ) ; new JavaScriptCompiler ( ) . compile ( ) ; } else if ( "wiki" . equalsIgnoreCase ( _type ) ) { AbstractRest . LOG . info ( "==Compiling Wiki==" ) ; new WikiCompiler ( ) . compile ( ) ; } else if ( "jasper" . equalsIgnoreCase ( _type ) ) { AbstractRest . LOG . info ( "==Compiling JasperReports==" ) ; new JasperReportCompiler ( getClassPathElements ( ) ) . compile ( ) ; } success = true ; AbstractRest . LOG . info ( "===Ending Compiler via REST===" ) ; } } catch ( final InstallationException e ) { AbstractRest . LOG . error ( "InstallationException" , e ) ; } catch ( final EFapsException e ) { AbstractRest . LOG . error ( "EFapsException" , e ) ; } return success ? Response . ok ( ) . build ( ) : Response . noContent ( ) . build ( ) ; } | Called to compile java css etc . | 399 | 9 |
10,296 | @ Override public void supplierChanged ( SupplierEvent supplierEvent ) { SupplierEvent . Type type = supplierEvent . type ( ) ; @ SuppressWarnings ( "unchecked" ) Supplier < T > supplier = ( Supplier < T > ) supplierEvent . supplier ( ) ; switch ( type ) { case ADD : if ( supplierReference . compareAndSet ( null , supplier ) ) { supplierFutureRef . get ( ) . complete ( supplier ) ; } break ; case REMOVE : if ( supplierReference . compareAndSet ( supplier , null ) ) { supplierFutureRef . set ( new CompletableFuture <> ( ) ) ; } break ; default : throw new IllegalStateException ( "Unknown supplier event: " + supplierEvent ) ; } } | there no thread safety issue because the supplierFutureRef is only used for the asynchronous approach . The risk is small enough to avoid to introduce more complexity . | 162 | 30 |
10,297 | private String getLabel ( final UIValue _uiValue , final Boolean _key ) throws CacheReloadException { String ret = BooleanUtils . toStringTrueFalse ( _key ) ; if ( _uiValue . getAttribute ( ) != null && DBProperties . hasProperty ( _uiValue . getAttribute ( ) . getKey ( ) + "." + BooleanUtils . toStringTrueFalse ( _key ) ) ) { ret = DBProperties . getProperty ( _uiValue . getAttribute ( ) . getKey ( ) + "." + BooleanUtils . toStringTrueFalse ( _key ) ) ; } else if ( DBProperties . hasProperty ( _uiValue . getField ( ) . getLabel ( ) + "." + BooleanUtils . toStringTrueFalse ( _key ) ) ) { ret = DBProperties . getProperty ( _uiValue . getField ( ) . getLabel ( ) + "." + BooleanUtils . toStringTrueFalse ( _key ) ) ; } return ret ; } | Method to evaluate a String representation for the boolean . | 221 | 10 |
10,298 | public void addObject ( final Object [ ] _row ) throws SQLException { // store the ids also this . idList . add ( ( Long ) _row [ 0 ] ) ; if ( getFromSelect ( ) != null ) { final int column = "id" . equals ( this . valueSelect . getValueType ( ) ) ? this . valueSelect . getColIndexs ( ) . get ( 0 ) : 2 ; this . relIdList . add ( ( Long ) _row [ column - 1 ] ) ; // this means that it is a chained LinkFromSelect, but exclude // AttributeSets if ( ! getSelectParts ( ) . isEmpty ( ) && getSelectParts ( ) . get ( 0 ) instanceof LinkFromSelect . LinkFromSelectPart && ! ( ( ( LinkFromSelect . LinkFromSelectPart ) getSelectParts ( ) . get ( 0 ) ) . getType ( ) instanceof AttributeSet ) ) { this . idList . set ( this . idList . size ( ) - 1 , ( Long ) _row [ 1 ] ) ; } } Object object = null ; final AbstractValueSelect tmpValueSelect ; if ( this . valueSelect == null ) { tmpValueSelect = this . fromSelect . getMainOneSelect ( ) . getValueSelect ( ) ; } else { tmpValueSelect = this . valueSelect ; } if ( tmpValueSelect . getParentSelectPart ( ) != null ) { tmpValueSelect . getParentSelectPart ( ) . addObject ( _row ) ; } if ( tmpValueSelect . getColIndexs ( ) . size ( ) > 1 ) { final Object [ ] objArray = new Object [ tmpValueSelect . getColIndexs ( ) . size ( ) ] ; int i = 0 ; for ( final Integer colIndex : tmpValueSelect . getColIndexs ( ) ) { objArray [ i ] = _row [ colIndex - 1 ] ; i ++ ; } object = objArray ; } else if ( tmpValueSelect . getColIndexs ( ) . size ( ) > 0 ) { object = _row [ tmpValueSelect . getColIndexs ( ) . get ( 0 ) - 1 ] ; } this . objectList . add ( object ) ; } | Add an Object for this OneSelect . | 479 | 8 |
10,299 | public void addFileSelectPart ( ) throws EFapsException { final Type type ; // if a previous select exists it is based on the previous select, // else it is based on the basic table if ( this . selectParts . size ( ) > 0 ) { type = this . selectParts . get ( this . selectParts . size ( ) - 1 ) . getType ( ) ; } else { type = this . query . getMainType ( ) ; } final FileSelectPart linkto = new FileSelectPart ( type ) ; this . selectParts . add ( linkto ) ; } | Add the select part to connect the general store . | 123 | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.