idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
23,900
protected String extractFirstName ( String name ) { if ( StringUtils . isBlank ( name ) ) { return null ; } int lastIndexOf = name . lastIndexOf ( ' ' ) ; if ( lastIndexOf == - 1 ) return null ; else return name . substring ( 0 , lastIndexOf ) ; }
Extracts a first name of full name string
70
10
23,901
protected Response createNotFound ( String message ) { ErrorResponse entity = new ErrorResponse ( ) ; entity . setMessage ( message ) ; return Response . status ( Response . Status . NOT_FOUND ) . entity ( entity ) . build ( ) ; }
Constructs not found response
53
5
23,902
protected Response createForbidden ( String message ) { ErrorResponse entity = new ErrorResponse ( ) ; entity . setMessage ( message ) ; return Response . status ( Response . Status . FORBIDDEN ) . entity ( entity ) . build ( ) ; }
Constructs forbidden response
53
4
23,903
protected Response createBadRequest ( String message ) { ErrorResponse entity = new ErrorResponse ( ) ; entity . setMessage ( message ) ; return Response . status ( Response . Status . BAD_REQUEST ) . entity ( entity ) . build ( ) ; }
Constructs bad request response
53
5
23,904
protected Response createInternalServerError ( String message ) { ErrorResponse entity = new ErrorResponse ( ) ; entity . setMessage ( message ) ; return Response . status ( Response . Status . INTERNAL_SERVER_ERROR ) . entity ( entity ) . build ( ) ; }
Constructs internal server error response
58
6
23,905
protected Response streamResponse ( byte [ ] data , String type ) { try ( InputStream byteStream = new ByteArrayInputStream ( data ) ) { return streamResponse ( type , byteStream , data . length ) ; } catch ( IOException e ) { logger . error ( "Failed to stream data to client" , e ) ; return createInternalServerError ( "Failed to stream data to client" ) ; } }
Creates streamed response from byte array
89
7
23,906
protected Response streamResponse ( String type , InputStream inputStream , int contentLength ) { return Response . ok ( new StreamingOutputImpl ( inputStream ) , type ) . header ( "Content-Length" , contentLength ) . build ( ) ; }
Creates streamed response from input stream
52
7
23,907
protected UUID getLoggedUserId ( ) { HttpServletRequest httpServletRequest = getHttpServletRequest ( ) ; String remoteUser = httpServletRequest . getRemoteUser ( ) ; if ( remoteUser == null ) { return null ; } return UUID . fromString ( remoteUser ) ; }
Returns logged user id
68
4
23,908
protected User getLoggedUser ( ) { UUID userId = getLoggedUserId ( ) ; if ( userId == null ) { return null ; } return userController . findUserByKeycloakId ( userId ) ; }
Returns logged user
51
3
23,909
private String getAnswerValue ( QueryQuestionNumericAnswer answer ) { return answer != null && answer . getData ( ) != null ? String . valueOf ( Math . round ( answer . getData ( ) ) ) : null ; }
Returns answer value
49
3
23,910
public static PaytrailService createPaytrailService ( ) { IOHandler ioHandler = new HttpClientIOHandler ( ) ; Marshaller marshaller = new JacksonMarshaller ( ) ; String merchantId = SystemUtils . getSettingValue ( "paytrail.merchantId" ) ; String merchantSecret = SystemUtils . getSettingValue ( "paytrail.merchantSecret" ) ; return new PaytrailService ( ioHandler , marshaller , merchantId , merchantSecret ) ; }
Creates a paytrail service instance
112
8
23,911
@ SuppressWarnings ( "squid:S00107" ) public static Chart createBubbleChart ( String chartCaption , String xLabel , List < String > xTickLabels , String yLabel , List < String > yTickLabels , int xAxisLabelRotation , int yAxisLabelRotation , Double [ ] [ ] values ) { return createBubbleChart ( chartCaption , xLabel , xTickLabels , yLabel , yTickLabels , xAxisLabelRotation , yAxisLabelRotation , values , null , null , null , null , null , null , null , null , null , null ) ; }
Creates a bubble chart without averages and quartiles
149
10
23,912
private static void addMarkerLine ( String label , Double value , Double offset , Axis axis ) { if ( value != null ) { MarkerLine markerLine = MarkerLineImpl . create ( axis , NumberDataElementImpl . create ( value + ( offset != null ? offset : 0d ) ) ) ; markerLine . getLineAttributes ( ) . setStyle ( LineStyle . DASHED_LITERAL ) ; markerLine . getLabel ( ) . getCaption ( ) . setValue ( label ) ; markerLine . setLabelAnchor ( Anchor . NORTH_EAST_LITERAL ) ; } }
Creates a marker line into specified axis if value is not null .
134
14
23,913
private static Double translateMarkerToRange ( double size , Double min , Double max , Double value ) { if ( value != null && min != null && max != null ) { return ( size / ( max - min ) ) * ( value - min ) ; } return value ; }
Translates marker value to be correct in given range
59
11
23,914
public String findTextByQueryReplyAndQueryField ( QueryReply queryReply , QueryField queryField ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < String > criteria = criteriaBuilder . createQuery ( String . class ) ; Root < QueryQuestionOptionAnswer > root = criteria . from ( QueryQuestionOptionAnswer . class ) ; Join < QueryQuestionOptionAnswer , QueryOptionFieldOption > option = root . join ( QueryQuestionOptionAnswer_ . option ) ; criteria . select ( option . get ( QueryOptionFieldOption_ . text ) ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( root . get ( QueryQuestionOptionAnswer_ . queryField ) , queryField ) , criteriaBuilder . equal ( root . get ( QueryQuestionOptionAnswer_ . queryReply ) , queryReply ) ) ) ; return getSingleResult ( entityManager . createQuery ( criteria ) ) ; }
Finds answer text by query reply and query field
207
10
23,915
public Long countByQueryFieldQueryRepliesInAndData ( QueryField queryField , Collection < QueryReply > queryReplies , Double data ) { if ( queryReplies == null || queryReplies . isEmpty ( ) ) { return 0l ; } EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < Long > criteria = criteriaBuilder . createQuery ( Long . class ) ; Root < QueryQuestionNumericAnswer > root = criteria . from ( QueryQuestionNumericAnswer . class ) ; Join < QueryQuestionNumericAnswer , QueryReply > replyJoin = root . join ( QueryQuestionNumericAnswer_ . queryReply ) ; criteria . select ( criteriaBuilder . count ( root ) ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( root . get ( QueryQuestionNumericAnswer_ . queryField ) , queryField ) , root . get ( QueryQuestionNumericAnswer_ . queryReply ) . in ( queryReplies ) , criteriaBuilder . equal ( root . get ( QueryQuestionNumericAnswer_ . data ) , data ) , criteriaBuilder . equal ( replyJoin . get ( QueryReply_ . archived ) , Boolean . FALSE ) ) ) ; return entityManager . createQuery ( criteria ) . getSingleResult ( ) ; }
Counts query question numeric answers
283
6
23,916
public User findUserByKeycloakId ( UUID userId ) { AuthSource authSource = authSourceDAO . findByStrategy ( KEYCLOAK_AUTH_SOURCE ) ; if ( authSource == null ) { logger . error ( "Could not find Keycloak auth source" ) ; } UserIdentification userIdentification = userIdentificationDAO . findByExternalId ( userId . toString ( ) , authSource ) ; if ( userIdentification != null ) { return userIdentification . getUser ( ) ; } return null ; }
Finds user by Keycloak id
121
8
23,917
@ Override public void writePostCommitResponse ( int statusCode ) throws Exception { if ( statusCode == StatusCode . OK ) { if ( fileName != null ) { getResponse ( ) . setHeader ( "Content-Disposition" , "attachment; filename=" + fileName ) ; } if ( contentType != null && content != null ) { getResponse ( ) . setContentType ( contentType ) ; getResponse ( ) . getOutputStream ( ) . write ( content ) ; } else if ( ! StringUtils . isBlank ( contentUrl ) ) { handleContentUrl ( ) ; } } else { // TODO Error handing switch ( statusCode ) { case StatusCode . UNAUTHORIZED : case StatusCode . NOT_LOGGED_IN : getResponse ( ) . setStatus ( 403 ) ; break ; default : getResponse ( ) . setStatus ( 500 ) ; break ; } } }
Writes the response to the binary request .
198
9
23,918
protected Map < Long , Map < String , String > > getRequestAnswerMap ( RequestContext requestContext ) { @ SuppressWarnings ( "unchecked" ) Map < Long , Map < String , String > > answers = ( Map < Long , Map < String , String > > ) requestContext . getRequest ( ) . getAttribute ( "commentAnswers" ) ; if ( answers == null ) { answers = new HashMap <> ( ) ; requestContext . getRequest ( ) . setAttribute ( "commentAnswers" , answers ) ; } return answers ; }
Returns comment answers map from the request context . If map is not yet defined new is created .
121
19
23,919
public String getLanguage ( String text ) { String language = null ; TextObject textObject = textObjectFactory . forText ( text ) ; com . google . common . base . Optional < LdLocale > lang = languageDetector . detect ( textObject ) ; if ( lang . isPresent ( ) ) { language = lang . get ( ) . toString ( ) ; } return language ; }
Get language from string
84
4
23,920
protected void renderComments ( PageRequestContext requestContext , QueryPage queryPage , QueryReply queryReply , boolean commentable , boolean viewDiscussion ) { Query query = queryPage . getQuerySection ( ) . getQuery ( ) ; Panel panel = ResourceUtils . getResourcePanel ( query ) ; RequiredQueryFragment queryFragment = new RequiredQueryFragment ( "comments" ) ; queryFragment . addAttribute ( "panelId" , panel . getId ( ) . toString ( ) ) ; queryFragment . addAttribute ( "queryId" , query . getId ( ) . toString ( ) ) ; queryFragment . addAttribute ( "pageId" , queryPage . getId ( ) . toString ( ) ) ; if ( queryReply != null ) { queryFragment . addAttribute ( "queryReplyId" , queryReply . getId ( ) . toString ( ) ) ; } queryFragment . addAttribute ( "queryPageCommentable" , commentable ? "true" : "false" ) ; queryFragment . addAttribute ( "queryViewDiscussion" , viewDiscussion ? "true" : "false" ) ; addRequiredFragment ( requestContext , queryFragment ) ; }
Renders comment list and comment editor
257
7
23,921
public boolean hasDelfoiAccess ( User user , DelfoiActionName actionName ) { if ( isSuperUser ( user ) ) { return true ; } DelfoiAction action = delfoiActionDAO . findByActionName ( actionName . toString ( ) ) ; if ( action == null ) { logger . info ( String . format ( "ActionUtils.hasDelfoiAccess - undefined action: '%s'" , actionName ) ) ; return false ; } UserRole userRole = getDelfoiRole ( user ) ; return hasDelfoiAccess ( action , userRole ) ; }
Returns whether user has required delfoi action access
132
10
23,922
public boolean hasPanelAccess ( Panel panel , User user , DelfoiActionName actionName ) { if ( panel == null ) { logger . warn ( "Panel was null when checking panel access" ) ; return false ; } if ( user == null ) { logger . warn ( "User was null when checking panel access" ) ; return false ; } if ( isSuperUser ( user ) ) { return true ; } UserRole userRole = getPanelRole ( user , panel ) ; if ( userRole == null ) { return false ; } DelfoiAction action = delfoiActionDAO . findByActionName ( actionName . toString ( ) ) ; if ( action == null ) { logger . info ( String . format ( "ActionUtils.hasDelfoiAccess - undefined action: '%s'" , actionName ) ) ; return false ; } return hasPanelAccess ( panel , action , userRole ) ; }
Returns whether user has required panel action access
197
8
23,923
private UserRole getPanelRole ( User user , Panel panel ) { if ( panel != null ) { PanelUserDAO panelUserDAO = new PanelUserDAO ( ) ; PanelUser panelUser = panelUserDAO . findByPanelAndUserAndStamp ( panel , user , panel . getCurrentStamp ( ) ) ; return panelUser == null ? getEveryoneRole ( ) : panelUser . getRole ( ) ; } return getEveryoneRole ( ) ; }
Returns user s panel role
100
5
23,924
private UserRole getDelfoiRole ( User user ) { Delfoi delfoi = getDelfoi ( ) ; if ( delfoi != null ) { DelfoiUserDAO delfoiUserDAO = new DelfoiUserDAO ( ) ; DelfoiUser delfoiUser = delfoiUserDAO . findByDelfoiAndUser ( delfoi , user ) ; return delfoiUser == null ? getEveryoneRole ( ) : delfoiUser . getRole ( ) ; } return getEveryoneRole ( ) ; }
Returns user s Delfoi role
123
7
23,925
public MqttSettings getMqttSettings ( ) { MqttSettings settings = new MqttSettings ( ) ; settings . setServerUrl ( getSettingValue ( "mqtt.serverUrl" ) ) ; settings . setClientUrl ( getSettingValue ( "mqtt.clientUrl" ) ) ; settings . setTopic ( getSettingValue ( "mqtt.topic" ) ) ; settings . setWildcard ( getSettingValue ( "mqtt.wildcard" ) ) ; return settings ; }
Returns MQTT settings
113
5
23,926
private String getSettingValue ( String key ) { SettingKey settingKey = settingKeyDAO . findByName ( key ) ; if ( settingKey == null ) { return null ; } Setting setting = settingDAO . findByKey ( settingKey ) ; return setting != null ? setting . getValue ( ) : null ; }
Returns a setting value for given key
69
7
23,927
public List < UserIdentification > listByUserAndAuthSource ( User user , AuthSource authSource ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < UserIdentification > criteria = criteriaBuilder . createQuery ( UserIdentification . class ) ; Root < UserIdentification > root = criteria . from ( UserIdentification . class ) ; criteria . select ( root ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( root . get ( UserIdentification_ . user ) , user ) , criteriaBuilder . equal ( root . get ( UserIdentification_ . authSource ) , authSource ) ) ) ; return entityManager . createQuery ( criteria ) . getResultList ( ) ; }
Lists user identifications by user and auth source
169
10
23,928
public void initialize ( AuthSource authSource ) { this . authSource = authSource ; AuthSourceSettingDAO authSourceSettingDAO = new AuthSourceSettingDAO ( ) ; List < AuthSourceSetting > authSourceSettings = authSourceSettingDAO . listByAuthSource ( authSource ) ; this . settings = new HashMap <> ( ) ; for ( AuthSourceSetting setting : authSourceSettings ) { settings . put ( setting . getKey ( ) , setting . getValue ( ) ) ; } }
Initializes this authentication strategy to work as per the given authentication source .
108
14
23,929
public AuthSource findByStrategy ( String strategy ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < AuthSource > criteria = criteriaBuilder . createQuery ( AuthSource . class ) ; Root < AuthSource > root = criteria . from ( AuthSource . class ) ; criteria . select ( root ) ; criteria . where ( criteriaBuilder . equal ( root . get ( AuthSource_ . strategy ) , strategy ) ) ; return getSingleResult ( entityManager . createQuery ( criteria ) ) ; }
Finds an auth source by strategy
124
7
23,930
private static void publish ( MqttSettings settings , String subtopic , byte [ ] payload , int qos , boolean retained ) throws MqttException { getClient ( settings ) . publish ( String . format ( "%s/%s" , settings . getTopic ( ) , subtopic ) , payload , qos , retained ) ; }
Publishes message into given MQTT topic
72
9
23,931
private static synchronized IMqttClient getClient ( MqttSettings settings ) throws MqttException { if ( CLIENT == null ) { CLIENT = new MqttClient ( settings . getServerUrl ( ) , PUBLISHER_ID ) ; MqttConnectOptions options = new MqttConnectOptions ( ) ; options . setAutomaticReconnect ( true ) ; options . setCleanSession ( true ) ; options . setConnectionTimeout ( 10 ) ; CLIENT . connect ( options ) ; } return CLIENT ; }
Returns client instance
111
3
23,932
private String getUserEmail ( Long userId ) { UserDAO userDAO = new UserDAO ( ) ; User user = userDAO . findById ( userId ) ; return user . getDefaultEmailAsString ( ) ; }
Returns user s default email address by user id
51
9
23,933
public QueryQuestionComment createQueryQuestionComment ( QueryReply queryReply , QueryPage queryPage , QueryQuestionComment parentComment , String comment , Boolean hidden , User creator , Date created ) { return queryQuestionCommentDAO . create ( queryReply , queryPage , parentComment , comment , hidden , creator , created , creator , created ) ; }
Creates new query question comment
70
6
23,934
public List < QueryQuestionComment > listQueryQuestionComments ( Panel panel , PanelStamp stamp , QueryPage queryPage , Query query , QueryQuestionComment parentComment , User user , boolean onlyRootComments ) { if ( stamp == null ) { stamp = panel . getCurrentStamp ( ) ; } return queryQuestionCommentDAO . list ( queryPage , stamp , query , panel . getRootFolder ( ) , parentComment , onlyRootComments , user , Boolean . FALSE ) ; }
Lists not archived comments by given parameters .
101
9
23,935
public QueryQuestionComment updateQueryQuestionComment ( QueryQuestionComment queryQuestionComment , String comment , Boolean hidden , User modifier , Date modified ) { queryQuestionCommentDAO . updateHidden ( queryQuestionComment , hidden , modifier ) ; return queryQuestionCommentDAO . updateComment ( queryQuestionComment , comment , modifier , modified ) ; }
Updates query question comment
69
5
23,936
public boolean isQueryQuestionCommentArchived ( QueryQuestionComment comment ) { if ( comment == null || comment . getArchived ( ) ) { return true ; } if ( comment . getParentComment ( ) != null && isQueryQuestionCommentArchived ( comment . getParentComment ( ) ) ) { return true ; } if ( comment . getQueryReply ( ) . getArchived ( ) ) { return true ; } return queryController . isQueryPageArchived ( comment . getQueryPage ( ) ) ; }
Returns whether query question comment is archived or not
108
9
23,937
public boolean isPanelsComment ( QueryQuestionComment comment , Panel panel ) { Panel queryPanel = resourceController . getResourcePanel ( comment . getQueryPage ( ) . getQuerySection ( ) . getQuery ( ) ) ; if ( queryPanel == null || panel == null ) { return false ; } return queryPanel . getId ( ) . equals ( panel . getId ( ) ) ; }
Returns whether comment belongs to given panel
83
7
23,938
protected void synchronizeFieldCaption ( QueryPage queryPage , String fieldName , String fieldCaption ) { QueryFieldDAO queryFieldDAO = new QueryFieldDAO ( ) ; QueryOptionField queryField = ( QueryOptionField ) queryFieldDAO . findByQueryPageAndName ( queryPage , fieldName ) ; if ( queryField != null ) queryFieldDAO . updateCaption ( queryField , fieldCaption ) ; }
Updates field caption if field can be found . Used only when query already contains replies .
95
18
23,939
public List < QueryQuestionComment > listByQueryPageAndStamp ( QueryPage queryPage , PanelStamp stamp ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < QueryQuestionComment > criteria = criteriaBuilder . createQuery ( QueryQuestionComment . class ) ; Root < QueryQuestionComment > root = criteria . from ( QueryQuestionComment . class ) ; Join < QueryQuestionComment , QueryReply > qqJoin = root . join ( QueryQuestionComment_ . queryReply ) ; criteria . select ( root ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( qqJoin . get ( QueryReply_ . stamp ) , stamp ) , criteriaBuilder . equal ( root . get ( QueryQuestionComment_ . queryPage ) , queryPage ) , criteriaBuilder . equal ( root . get ( QueryQuestionComment_ . archived ) , Boolean . FALSE ) ) ) ; return entityManager . createQuery ( criteria ) . getResultList ( ) ; }
Lists all nonarchived comments left on the given query page in the given panel stamp .
221
19
23,940
public Map < Long , List < QueryQuestionComment > > listTreesByQueryPage ( QueryPage queryPage ) { Map < Long , List < QueryQuestionComment > > result = new HashMap <> ( ) ; EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < QueryQuestionComment > criteria = criteriaBuilder . createQuery ( QueryQuestionComment . class ) ; Root < QueryQuestionComment > root = criteria . from ( QueryQuestionComment . class ) ; criteria . select ( root ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( root . get ( QueryQuestionComment_ . queryPage ) , queryPage ) , criteriaBuilder . equal ( root . get ( QueryQuestionComment_ . archived ) , Boolean . FALSE ) , criteriaBuilder . isNotNull ( root . get ( QueryQuestionComment_ . parentComment ) ) ) ) ; List < QueryQuestionComment > allChildren = entityManager . createQuery ( criteria ) . getResultList ( ) ; for ( QueryQuestionComment comment : allChildren ) { Long parentCommentId = comment . getParentComment ( ) . getId ( ) ; List < QueryQuestionComment > children = result . get ( parentCommentId ) ; if ( children == null ) { children = new ArrayList <> ( ) ; result . put ( parentCommentId , children ) ; } children . add ( comment ) ; } return result ; }
Lists all non - root comments on page and orders them to map with parentComment . id as key and list of comments directly below parentComment as value .
309
32
23,941
@ Override protected void service ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , java . io . IOException { if ( sessionSynchronization ) { String syncKey = getSyncKey ( request ) ; synchronized ( getSyncObject ( syncKey ) ) { try { doService ( request , response ) ; } finally { removeSyncObject ( syncKey ) ; } } } else { doService ( request , response ) ; } }
Processes all application requests delegating them to their corresponding page binary and JSON controllers .
99
17
23,942
public boolean isQueryPageArchived ( QueryPage queryPage ) { if ( queryPage . getArchived ( ) ) { return true ; } QuerySection querySection = queryPage . getQuerySection ( ) ; if ( querySection . getArchived ( ) ) { return true ; } return isQueryArchived ( querySection . getQuery ( ) ) ; }
Returns whether query page is archived or not
76
8
23,943
public boolean isQueryArchived ( Query query ) { if ( query . getArchived ( ) ) { return true ; } return resourceController . isFolderArchived ( query . getParentFolder ( ) ) ; }
Returns whether query is archived
45
5
23,944
public boolean isPanelsQuery ( Query query , Panel panel ) { Panel queryPanel = resourceController . getResourcePanel ( query ) ; if ( queryPanel == null || panel == null ) { return false ; } return queryPanel . getId ( ) . equals ( panel . getId ( ) ) ; }
Returns whether query belongs to given panel
64
7
23,945
public PanelUser create ( Panel panel , User user , PanelUserRole role , PanelUserJoinType joinType , PanelStamp stamp , User creator ) { Date now = new Date ( ) ; PanelUser panelUser = new PanelUser ( ) ; panelUser . setPanel ( panel ) ; panelUser . setUser ( user ) ; panelUser . setRole ( role ) ; panelUser . setJoinType ( joinType ) ; panelUser . setStamp ( stamp ) ; panelUser . setCreated ( now ) ; panelUser . setCreator ( creator ) ; panelUser . setLastModified ( now ) ; panelUser . setLastModifier ( creator ) ; panelUser . setArchived ( Boolean . FALSE ) ; return persist ( panelUser ) ; }
Creates new panel user
160
5
23,946
public PanelUser updateJoinType ( PanelUser panelUser , PanelUserJoinType joinType , User modifier ) { panelUser . setJoinType ( joinType ) ; panelUser . setLastModified ( new Date ( ) ) ; panelUser . setLastModifier ( modifier ) ; return persist ( panelUser ) ; }
Updates panel user s join type
67
7
23,947
public PanelUser updateRole ( PanelUser panelUser , PanelUserRole panelUserRole , User modifier ) { panelUser . setRole ( panelUserRole ) ; panelUser . setLastModified ( new Date ( ) ) ; panelUser . setLastModifier ( modifier ) ; return persist ( panelUser ) ; }
Updates panel user s role
66
6
23,948
public Long countByPanelStateUserAndRole ( User user , DelfoiAction action , PanelState state ) { EntityManager entityManager = getEntityManager ( ) ; CriteriaBuilder criteriaBuilder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < Long > criteria = criteriaBuilder . createQuery ( Long . class ) ; Root < PanelUser > panelUserRoot = criteria . from ( PanelUser . class ) ; Root < PanelUserRoleAction > roleActionRoot = criteria . from ( PanelUserRoleAction . class ) ; Join < PanelUser , Panel > panelJoin = panelUserRoot . join ( PanelUser_ . panel ) ; criteria . select ( criteriaBuilder . countDistinct ( panelJoin ) ) ; criteria . where ( criteriaBuilder . and ( criteriaBuilder . equal ( panelJoin , roleActionRoot . get ( PanelUserRoleAction_ . panel ) ) , criteriaBuilder . equal ( roleActionRoot . get ( PanelUserRoleAction_ . delfoiAction ) , action ) , criteriaBuilder . equal ( panelUserRoot . get ( PanelUser_ . role ) , roleActionRoot . get ( PanelUserRoleAction_ . userRole ) ) , criteriaBuilder . equal ( panelJoin . get ( Panel_ . state ) , state ) , criteriaBuilder . equal ( panelUserRoot . get ( PanelUser_ . user ) , user ) , criteriaBuilder . equal ( panelUserRoot . get ( PanelUser_ . archived ) , Boolean . FALSE ) , criteriaBuilder . equal ( panelJoin . get ( Panel_ . archived ) , Boolean . FALSE ) ) ) ; return entityManager . createQuery ( criteria ) . getSingleResult ( ) ; }
Returns count of panels in specific state where user has permission to perform specific action
348
15
23,949
public Panel getResourcePanel ( Resource resource ) { List < Folder > resourceFolders = new ArrayList < Folder > ( ) ; Resource current = resource ; Folder folder = current instanceof Folder ? ( Folder ) current : current == null ? null : current . getParentFolder ( ) ; while ( folder != null ) { resourceFolders . add ( folder ) ; current = folder ; folder = current . getParentFolder ( ) ; } Folder panelFolder = null ; int panelIndex = resourceFolders . size ( ) - 2 ; if ( panelIndex >= 0 ) { panelFolder = resourceFolders . get ( panelIndex ) ; } if ( panelFolder != null ) { return panelDAO . findByRootFolder ( panelFolder ) ; } return null ; }
Returns a panel for given resource
163
6
23,950
public boolean isFolderArchived ( Folder folder ) { if ( folder . getArchived ( ) ) { return true ; } Folder parentFolder = folder . getParentFolder ( ) ; if ( parentFolder != null ) { return isFolderArchived ( parentFolder ) ; } else { Panel panel = panelDAO . findByRootFolder ( parentFolder ) ; if ( panel != null ) { return panelController . isPanelArchived ( panel ) ; } } return false ; }
Returns whether folder is archived
100
5
23,951
public void registerAuthenticationProvider ( Class < ? extends AuthenticationProvider > providerClass ) { AuthenticationProvider provider = instantiateProvider ( providerClass ) ; authenticationProviders . put ( provider . getName ( ) , providerClass ) ; credentialAuths . put ( provider . getName ( ) , provider . requiresCredentials ( ) ) ; }
Registers an authentication provider to this class .
71
9
23,952
public static boolean isChartInRuntime ( Chart cm ) { if ( cm instanceof ChartWithAxes ) { Axis bAxis = ( ( ChartWithAxes ) cm ) . getAxes ( ) . get ( 0 ) ; EList < Axis > oAxes = bAxis . getAssociatedAxes ( ) ; for ( int i = 0 ; i < oAxes . size ( ) ; i ++ ) { Axis oAxis = oAxes . get ( i ) ; EList < SeriesDefinition > oSeries = oAxis . getSeriesDefinitions ( ) ; for ( int j = 0 ; j < oSeries . size ( ) ; j ++ ) { SeriesDefinition sd = oSeries . get ( j ) ; if ( sd . getRunTimeSeries ( ) . size ( ) > 0 ) { return true ; } } } } else if ( cm instanceof ChartWithoutAxes ) { SeriesDefinition bsd = ( ( ChartWithoutAxes ) cm ) . getSeriesDefinitions ( ) . get ( 0 ) ; EList < SeriesDefinition > osds = bsd . getSeriesDefinitions ( ) ; for ( int i = 0 ; i < osds . size ( ) ; i ++ ) { SeriesDefinition osd = osds . get ( i ) ; if ( osd . getRunTimeSeries ( ) . size ( ) > 0 ) { return true ; } } } return false ; }
Checks if current chart has runtime data sets .
301
10
23,953
public static byte [ ] exportQueryCommentsAsCsv ( Locale locale , ReplierExportStrategy replierExportStrategy , List < QueryReply > replies , Query query , PanelStamp stamp ) throws IOException { QueryPageDAO queryPageDAO = new QueryPageDAO ( ) ; List < QueryPage > queryPages = queryPageDAO . listByQuery ( query ) ; Collections . sort ( queryPages , new QueryPageNumberComparator ( ) ) ; String [ ] columnHeaders = new String [ ] { getReplierExportStrategyLabel ( locale , replierExportStrategy ) , Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvCommentAnswerColumn" ) , Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvCommentCommentColumn" ) , Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvCommentReplyColumn" ) , } ; List < String [ ] > rows = new ArrayList <> ( ) ; for ( QueryPage queryPage : queryPages ) { List < String [ ] > pageRows = exportQueryPageCommentsAsCsv ( replierExportStrategy , replies , stamp , queryPage ) ; if ( ! pageRows . isEmpty ( ) ) { rows . add ( new String [ ] { "" , "" , "" , "" } ) ; rows . add ( new String [ ] { queryPage . getTitle ( ) , "" , "" , "" } ) ; rows . add ( new String [ ] { "" , "" , "" , "" } ) ; rows . addAll ( pageRows ) ; } } return writeCsv ( columnHeaders , rows ) ; }
Export query comments into CSV byte array
372
7
23,954
private static List < String [ ] > exportQueryPageCommentsAsCsv ( ReplierExportStrategy replierExportStrategy , List < QueryReply > replies , PanelStamp stamp , QueryPage queryPage ) { QueryPageHandler queryPageHandler = QueryPageHandlerFactory . getInstance ( ) . buildPageHandler ( queryPage . getPageType ( ) ) ; if ( queryPageHandler != null ) { ReportPageCommentProcessor processor = queryPageHandler . exportComments ( queryPage , stamp , replies ) ; if ( processor != null ) { return exportQueryPageCommentsAsCsv ( replierExportStrategy , queryPage , processor ) ; } } return Collections . emptyList ( ) ; }
Exports single query page into CSV rows
146
8
23,955
private static List < String [ ] > exportQueryPageCommentsAsCsv ( ReplierExportStrategy replierExportStrategy , QueryPage queryPage , ReportPageCommentProcessor processor ) { QueryQuestionCommentDAO queryQuestionCommentDAO = new QueryQuestionCommentDAO ( ) ; List < String [ ] > rows = new ArrayList <> ( ) ; processor . processComments ( ) ; List < QueryQuestionComment > rootComments = processor . getRootComments ( ) ; if ( rootComments != null && ! rootComments . isEmpty ( ) ) { Map < Long , List < QueryQuestionComment > > childCommentMap = queryQuestionCommentDAO . listTreesByQueryPage ( queryPage ) ; for ( QueryQuestionComment rootComment : rootComments ) { String rootUser = getReplierExportStrategyValue ( replierExportStrategy , rootComment . getQueryReply ( ) ) ; String rootLabel = processor . getCommentLabel ( rootComment . getId ( ) ) ; rows . add ( new String [ ] { rootUser , rootLabel , rootComment . getComment ( ) , "" } ) ; List < QueryQuestionComment > childComments = childCommentMap . get ( rootComment . getId ( ) ) ; if ( childComments != null ) { childComments . forEach ( childComment -> { String childUser = getReplierExportStrategyValue ( replierExportStrategy , childComment . getQueryReply ( ) ) ; rows . add ( new String [ ] { childUser , "" , "" , childComment . getComment ( ) } ) ; } ) ; } } } return rows ; }
Exports single query page into CSV rows using comment processor
341
11
23,956
private static String getReplierExportStrategyLabel ( Locale locale , ReplierExportStrategy replierExportStrategy ) { switch ( replierExportStrategy ) { case NONE : break ; case HASH : return Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvReplierIdColumn" ) ; case NAME : return Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvReplierNameColumn" ) ; case EMAIL : return Messages . getInstance ( ) . getText ( locale , "panelAdmin.query.export.csvReplierEmailColumn" ) ; } return null ; }
Returns label for given replier export strategy
146
8
23,957
private static String getReplierExportStrategyValue ( ReplierExportStrategy replierExportStrategy , QueryReply queryReply ) { if ( queryReply != null ) { User user = queryReply . getUser ( ) ; if ( user != null ) { switch ( replierExportStrategy ) { case NONE : break ; case HASH : return RequestUtils . md5EncodeString ( String . valueOf ( user . getId ( ) ) ) ; case NAME : return user . getFullName ( true , false ) ; case EMAIL : return user . getDefaultEmailAsString ( ) ; } } } return "-" ; }
Returns user identifier for given replier export strategy
137
9
23,958
public static void appendQueryPageComments ( RequestContext requestContext , QueryPage queryPage ) { QueryQuestionCommentDAO queryQuestionCommentDAO = new QueryQuestionCommentDAO ( ) ; PanelStamp activeStamp = RequestUtils . getActiveStamp ( requestContext ) ; List < QueryQuestionComment > rootComments = queryQuestionCommentDAO . listRootCommentsByQueryPageAndStampOrderByCreated ( queryPage , activeStamp ) ; Map < Long , List < QueryQuestionComment > > childComments = queryQuestionCommentDAO . listTreesByQueryPageAndStampOrderByCreated ( queryPage , activeStamp ) ; QueryUtils . appendQueryPageRootComments ( requestContext , queryPage . getId ( ) , rootComments ) ; QueryUtils . appendQueryPageChildComments ( requestContext , childComments ) ; int commentCount = rootComments . size ( ) ; for ( Object key : childComments . keySet ( ) ) { List < QueryQuestionComment > childCommentList = childComments . get ( key ) ; if ( childCommentList != null ) commentCount += childCommentList . size ( ) ; } requestContext . getRequest ( ) . setAttribute ( "queryPageCommentCount" , commentCount ) ; }
Loads the whole comment tree and appends it to requestContext for JSP to read .
264
19
23,959
public static LocalDocument findIndexPageDocument ( Delfoi delfoi , Locale locale ) { String urlName = String . format ( "%s-%s" , INDEX_PAGE_URLNAME , locale . getLanguage ( ) ) ; return findLocalDocumentByParentAndUrlName ( delfoi . getRootFolder ( ) , urlName ) ; }
Finds delfoi index page document
78
8
23,960
public static LocalDocument createIndexPageDocument ( Delfoi delfoi , Locale locale , User user ) { LocalDocumentDAO localDocumentDAO = new LocalDocumentDAO ( ) ; String urlName = String . format ( "%s-%s" , INDEX_PAGE_URLNAME , locale . getLanguage ( ) ) ; return localDocumentDAO . create ( urlName , urlName , delfoi . getRootFolder ( ) , user , 0 ) ; }
Creates index page document
103
5
23,961
public static LocalDocument findLocalDocumentByParentAndUrlName ( Folder parentFolder , String urlName ) { ResourceDAO resourceDAO = new ResourceDAO ( ) ; Resource resource = resourceDAO . findByUrlNameAndParentFolder ( urlName , parentFolder ) ; if ( resource instanceof LocalDocument ) { return ( LocalDocument ) resource ; } return null ; }
Returns local document by parent folder and URL name
79
9
23,962
protected OffsetDateTime translateDate ( Date date ) { if ( date == null ) { return null ; } return OffsetDateTime . ofInstant ( date . toInstant ( ) , ZoneId . systemDefault ( ) ) ; }
Translates date into offset date time
49
8
23,963
protected UUID translateUserId ( User user ) { if ( user == null ) { return null ; } return userController . getUserKeycloakId ( user ) ; }
Translates user into user id
37
7
23,964
public String getCommentLabel ( Long id ) { Map < String , String > valueMap = answers . get ( id ) ; if ( valueMap != null && ! valueMap . isEmpty ( ) ) { Set < Entry < String , String > > entrySet = valueMap . entrySet ( ) ; List < String > labels = entrySet . stream ( ) . map ( entry -> String . format ( "%s / %s" , entry . getKey ( ) , entry . getValue ( ) ) ) . collect ( Collectors . toList ( ) ) ; return StringUtils . join ( labels , " - " ) ; } return null ; }
Returns comment label as string
137
5
23,965
protected void setCommentLabel ( Long id , String caption , String value ) { Map < String , String > valueMap = answers . get ( id ) ; if ( valueMap == null ) { valueMap = new LinkedHashMap <> ( ) ; } valueMap . put ( caption , value ) ; answers . put ( id , valueMap ) ; }
Sets a label for a specified comment
75
8
23,966
private List < QueryQuestionComment > listRootComments ( ) { QueryQuestionCommentDAO queryQuestionCommentDAO = new QueryQuestionCommentDAO ( ) ; return queryQuestionCommentDAO . listRootCommentsByQueryPageAndStampOrderByCreated ( queryPage , panelStamp ) ; }
Lists page s root comments
62
6
23,967
private boolean isPanelUser ( JdbcConnection connection , Long panelId , String email ) throws CustomChangeException { try ( PreparedStatement statement = connection . prepareStatement ( "SELECT id FROM PANELUSER WHERE panel_id = ? AND user_id = (SELECT id FROM USEREMAIL WHERE address = ?)" ) ) { statement . setLong ( 1 , panelId ) ; statement . setString ( 2 , email ) ; try ( ResultSet resultSet = statement . executeQuery ( ) ) { return resultSet . next ( ) ; } } catch ( Exception e ) { throw new CustomChangeException ( e ) ; } }
Returns whether user by email is a PanelUser or not
133
11
23,968
private void deleteInvitation ( JdbcConnection connection , Long id ) throws CustomChangeException { try ( PreparedStatement statement = connection . prepareStatement ( "DELETE FROM PANELINVITATION WHERE id = ?" ) ) { statement . setLong ( 1 , id ) ; statement . execute ( ) ; } catch ( Exception e ) { throw new CustomChangeException ( e ) ; } }
Deletes an invitation
85
4
23,969
public Double getQuantile ( int quantile , int base ) { if ( getCount ( ) == 0 ) return null ; if ( ( quantile > base ) || ( quantile <= 0 ) || ( base <= 0 ) ) throw new IllegalArgumentException ( "Incorrect quantile/base specified." ) ; double quantileFraq = ( double ) quantile / base ; int index = ( int ) Math . round ( quantileFraq * ( getCount ( ) - 1 ) ) ; return ( double ) data . get ( index ) + shift ; }
Returns quantile over base value .
119
7
23,970
private QueryFieldDataStatistics createStatistics ( List < Double > data , double min , double max , double step ) { Map < Double , String > dataNames = new HashMap <> ( ) ; for ( double d = min ; d <= max ; d += step ) { String caption = step % 1 == 0 ? Long . toString ( Math . round ( d ) ) : Double . toString ( d ) ; dataNames . put ( d , caption ) ; } return ReportUtils . getStatistics ( data , dataNames ) ; }
Creates statistics object
113
4
23,971
@ Deprecated public List < List < String > > getParsedArgs ( String [ ] args ) throws InvalidFormatException { for ( int i = 0 ; i < args . length ; i ++ ) { if ( ! args [ i ] . startsWith ( "-" ) ) { if ( this . params . size ( ) > 0 ) { List < String > option = new ArrayList < String > ( ) ; option . add ( this . params . get ( 0 ) . longOption ) ; this . params . remove ( 0 ) ; option . add ( args [ i ] ) ; sortedArgs . add ( option ) ; } else { throw new InvalidFormatException ( "Expected command line option, found " + args [ i ] + " instead." ) ; } } else { for ( Argument option : this . args ) { if ( option . matchesFlag ( args [ i ] ) ) { List < String > command = new ArrayList < String > ( ) ; command . add ( noDashes ( args [ i ] ) ) ; if ( option . takesValue ) { try { if ( args [ i + 1 ] . startsWith ( "-" ) ) { if ( option . valueRequired ) throw new InvalidFormatException ( "Invalid command line format: -" + option . option + " or --" + option . longOption + " requires a parameter, found " + args [ i + 1 ] + " instead." ) ; } else { command . add ( args [ ++ i ] ) ; } } catch ( ArrayIndexOutOfBoundsException e ) { } } sortedArgs . add ( command ) ; break ; } } } } return sortedArgs ; }
Get the parsed and checked command line arguments for this parser
351
11
23,972
@ Deprecated public void addArguments ( String [ ] argList ) throws DuplicateOptionException , InvalidFormatException { for ( String arg : argList ) { Argument f = new Argument ( ) ; String [ ] breakdown = arg . split ( "," ) ; for ( String s : breakdown ) { s = s . trim ( ) ; if ( s . startsWith ( "--" ) ) { f . longOption = noDashes ( s ) ; } else if ( s . startsWith ( "-h" ) ) { f . helpText = s . substring ( 2 ) ; } else if ( s . startsWith ( "-" ) ) { f . option = noDashes ( s ) ; } else if ( s . equals ( "+" ) ) { f . takesValue = true ; f . valueRequired = true ; } else if ( s . equals ( "?" ) ) { f . isParam = true ; f . takesValue = true ; params . add ( f ) ; } else if ( s . equals ( "*" ) ) { f . takesValue = true ; } else { throw new InvalidFormatException ( s + " in " + arg + " is not formatted correctly." ) ; } } addArgument ( f ) ; } }
adds options for this command line parser
267
8
23,973
@ Deprecated public void addArgument ( char shortForm , String longForm , String helpText , boolean isParameter , boolean takesValue , boolean valueRequired ) throws DuplicateOptionException { Argument f = new Argument ( ) ; f . option = "" + shortForm ; f . longOption = longForm ; f . takesValue = takesValue ; f . valueRequired = valueRequired ; f . helpText = helpText ; f . isParam = isParameter ; if ( isParameter ) params . add ( f ) ; addArgument ( f ) ; }
Add an argument for this command line parser . Options should not be prepended by dashes .
116
19
23,974
public void add ( JDesktopPaneLayout child , Object constraints , int index ) { if ( child . parent != this ) { throw new IllegalArgumentException ( "Layout is not a child of this layout" ) ; } container . add ( child . container , constraints , index ) ; }
Add the given desktop pane layout as a child to this one
61
12
23,975
public void remove ( JDesktopPaneLayout child ) { if ( child . parent != this ) { throw new IllegalArgumentException ( "Layout is not a child of this layout" ) ; } container . remove ( child . container ) ; }
Remove the given child layout
51
5
23,976
public void validate ( ) { Dimension size = desktopPane . getSize ( ) ; size . height -= computeDesktopIconsSpace ( ) ; layoutInternalFrames ( size ) ; }
Validate the layout after internal frames have been added or removed
38
12
23,977
private int computeDesktopIconsSpace ( ) { for ( JInternalFrame f : frameToComponent . keySet ( ) ) { if ( f . isIcon ( ) ) { JDesktopIcon desktopIcon = f . getDesktopIcon ( ) ; return desktopIcon . getPreferredSize ( ) . height ; } } return 0 ; }
Compute the space for iconified desktop icons
70
9
23,978
private void callDoLayout ( Container container ) { container . doLayout ( ) ; int n = container . getComponentCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Component component = container . getComponent ( i ) ; if ( component instanceof Container ) { Container subContainer = ( Container ) component ; callDoLayout ( subContainer ) ; } } }
Recursively call doLayout on the container and all its sub - containers
82
15
23,979
private void applyLayout ( ) { int n = container . getComponentCount ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Component component = container . getComponent ( i ) ; if ( component instanceof FrameComponent ) { FrameComponent frameComponent = ( FrameComponent ) component ; JInternalFrame internalFrame = frameComponent . getInternalFrame ( ) ; Rectangle bounds = SwingUtilities . convertRectangle ( container , component . getBounds ( ) , rootContainer ) ; //System.out.println( // "Set bounds of "+internalFrame.getTitle()+" to "+bounds); internalFrame . setBounds ( bounds ) ; } else { LayoutContainer childLayoutContainer = ( LayoutContainer ) component ; //System.out.println( // "Child with "+childLayoutContainer.getLayout()); childLayoutContainer . owner . applyLayout ( ) ; } } }
Apply the current layout to the internal frames
189
8
23,980
public void addData ( final BenchmarkMethod meth , final AbstractMeter meter , final double data ) { final Class < ? > clazz = meth . getMethodToBench ( ) . getDeclaringClass ( ) ; if ( ! elements . containsKey ( clazz ) ) { elements . put ( clazz , new ClassResult ( clazz ) ) ; } final ClassResult clazzResult = elements . get ( clazz ) ; if ( ! clazzResult . elements . containsKey ( meth ) ) { clazzResult . elements . put ( meth , new MethodResult ( meth ) ) ; } final MethodResult methodResult = clazzResult . elements . get ( meth ) ; methodResult . addData ( meter , data ) ; clazzResult . addData ( meter , data ) ; this . addData ( meter , data ) ; for ( final AbstractOutput output : outputs ) { output . listenToResultSet ( meth , meter , data ) ; } }
Adding a dataset to a given meter and adapting the underlaying result model .
202
16
23,981
public void addException ( final AbstractPerfidixMethodException exec ) { this . getExceptions ( ) . add ( exec ) ; for ( final AbstractOutput output : outputs ) { output . listenToException ( exec ) ; } }
Adding an exception to this result .
50
7
23,982
static Action create ( Runnable command ) { Objects . requireNonNull ( command , "The command may not be null" ) ; return new AbstractAction ( ) { /** * Serial UID */ private static final long serialVersionUID = 8693271079128413874L ; @ Override public void actionPerformed ( ActionEvent e ) { command . run ( ) ; } } ; }
Create a new action that simply executes the given command
83
10
23,983
public void doAESEncryption ( ) throws Exception { if ( ! initAESDone ) initAES ( ) ; cipher = Cipher . getInstance ( "AES/CBC/PKCS5Padding" ) ; //System.out.println(secretKey.getEncoded()); cipher . init ( Cipher . ENCRYPT_MODE , secretKey ) ; AlgorithmParameters params = cipher . getParameters ( ) ; iv = params . getParameterSpec ( IvParameterSpec . class ) . getIV ( ) ; secretCipher = cipher . doFinal ( secretPlain ) ; clearPlain ( ) ; }
clears all plaintext passwords and secrets . password secret and initAES must all be set before re - using
131
23
23,984
public static JPanel wrapTitled ( String title , JComponent component ) { JPanel p = new JPanel ( new GridLayout ( 1 , 1 ) ) ; p . setBorder ( BorderFactory . createTitledBorder ( title ) ) ; p . add ( component ) ; return p ; }
Wrap the given component into a panel with a titled border with the given title
62
16
23,985
public static JPanel wrapFlow ( JComponent component ) { JPanel p = new JPanel ( new FlowLayout ( FlowLayout . CENTER , 0 , 0 ) ) ; p . add ( component ) ; return p ; }
Wrap the given component into a panel with flow layout
47
11
23,986
public static void setDeepEnabled ( Component component , boolean enabled ) { component . setEnabled ( enabled ) ; if ( component instanceof Container ) { Container container = ( Container ) component ; for ( Component c : container . getComponents ( ) ) { setDeepEnabled ( c , enabled ) ; } } }
Enables or disables the given component and all its children recursively
64
15
23,987
static int indexOf ( String source , String target , int startIndex , boolean ignoreCase ) { if ( ignoreCase ) { return indexOf ( source , target , startIndex , IGNORING_CASE ) ; } return indexOf ( source , target , startIndex , ( c0 , c1 ) -> Integer . compare ( c0 , c1 ) ) ; }
Returns the index of the first appearance of the given target in the given source starting at the given index . Returns - 1 if the target string is not found .
78
32
23,988
private static int indexOf ( String source , String target , int startIndex , IntBinaryOperator comparator ) { return indexOf ( source , 0 , source . length ( ) , target , 0 , target . length ( ) , startIndex , comparator ) ; }
Returns the index of the first appearance of the given target in the given source starting at the given index using the given comparator for characters . Returns - 1 if the target string is not found .
57
39
23,989
private static int indexOf ( String source , int sourceOffset , int sourceCount , String target , int targetOffset , int targetCount , int startIndex , IntBinaryOperator comparator ) { int fromIndex = startIndex ; // Adapted from String#indexOf if ( fromIndex >= sourceCount ) { return ( targetCount == 0 ? sourceCount : - 1 ) ; } if ( fromIndex < 0 ) { fromIndex = 0 ; } if ( targetCount == 0 ) { return fromIndex ; } char first = target . charAt ( targetOffset ) ; int max = sourceOffset + ( sourceCount - targetCount ) ; for ( int i = sourceOffset + fromIndex ; i <= max ; i ++ ) { if ( comparator . applyAsInt ( source . charAt ( i ) , first ) != 0 ) { while ( ++ i <= max && comparator . applyAsInt ( source . charAt ( i ) , first ) != 0 ) { // Empty } } if ( i <= max ) { int j = i + 1 ; int end = j + targetCount - 1 ; for ( int k = targetOffset + 1 ; j < end && comparator . applyAsInt ( source . charAt ( j ) , target . charAt ( k ) ) == 0 ; j ++ , k ++ ) { // Empty } if ( j == end ) { return i - sourceOffset ; } } } return - 1 ; }
Returns the index of the first appearance of the given range of the target in the given range of the source source starting at the given index using the given comparator for characters . Returns - 1 if the target string is not found .
302
46
23,990
private static int lastIndexOf ( String source , String target , int startIndex , IntBinaryOperator comparator ) { return lastIndexOf ( source , 0 , source . length ( ) , target , 0 , target . length ( ) , startIndex , comparator ) ; }
Returns the index of the previous appearance of the given target in the given source starting at the given index using the given comparator for characters . Returns - 1 if the target string is not found .
59
39
23,991
static int lastIndexOf ( String source , int sourceOffset , int sourceCount , String target , int targetOffset , int targetCount , int startIndex , IntBinaryOperator comparator ) { int fromIndex = startIndex ; // Adapted from String#lastIndexOf int rightIndex = sourceCount - targetCount ; if ( fromIndex < 0 ) { return - 1 ; } if ( fromIndex > rightIndex ) { fromIndex = rightIndex ; } if ( targetCount == 0 ) { return fromIndex ; } int strLastIndex = targetOffset + targetCount - 1 ; char strLastChar = target . charAt ( strLastIndex ) ; int min = sourceOffset + targetCount - 1 ; int i = min + fromIndex ; startSearchForLastChar : while ( true ) { while ( i >= min && comparator . applyAsInt ( source . charAt ( i ) , strLastChar ) != 0 ) { i -- ; } if ( i < min ) { return - 1 ; } int j = i - 1 ; int start = j - ( targetCount - 1 ) ; int k = strLastIndex - 1 ; while ( j > start ) { if ( comparator . applyAsInt ( source . charAt ( j -- ) , target . charAt ( k -- ) ) != 0 ) { i -- ; continue startSearchForLastChar ; } } return start - sourceOffset + 1 ; } }
Returns the index of the previous appearance of the given range of the target in the given range of the source source starting at the given index using the given comparator for characters . Returns - 1 if the target string is not found .
300
46
23,992
Observable < ComapiResult < MessagesQueryResponse > > doQueryMessages ( @ NonNull final String token , @ NonNull final String conversationId , final Long from , @ NonNull final Integer limit ) { return wrapObservable ( service . queryMessages ( AuthManager . addAuthPrefix ( token ) , apiSpaceId , conversationId , from , limit ) . map ( mapToComapiResult ( ) ) , log , "Querying messages in " + conversationId ) ; }
Query messages in a conversation .
106
6
23,993
Observable < ComapiResult < Void > > doIsTyping ( @ NonNull final String token , @ NonNull final String conversationId , final boolean isTyping ) { if ( isTyping ) { return wrapObservable ( service . isTyping ( AuthManager . addAuthPrefix ( token ) , apiSpaceId , conversationId ) . map ( mapToComapiResult ( ) ) , log , "Sending is typing." ) ; } else { return wrapObservable ( service . isNotTyping ( AuthManager . addAuthPrefix ( token ) , apiSpaceId , conversationId ) . map ( mapToComapiResult ( ) ) , log , "Sending is not typing" ) ; } }
Send information if user started or stopped typing message in a conversation .
156
13
23,994
@ Override public void init ( Key key , IvParameterSpec iv ) throws InvalidKeyException { if ( ! ( key instanceof SecretKey ) ) throw new InvalidKeyException ( ) ; int ivLength = iv . getIV ( ) . length ; if ( key . getEncoded ( ) . length < MIN_KEY_SIZE || key . getEncoded ( ) . length < ivLength ) throw new InvalidKeyException ( "Key must be longer than " + MIN_KEY_SIZE + " bytes and key must be longer than IV." ) ; this . key = key . getEncoded ( ) ; this . iv = iv ; prehash = Misc . XORintoA ( this . key . length == ivLength ? iv . getIV ( ) : Arrays . copyOf ( iv . getIV ( ) , this . key . length ) , this . key ) ; blockNo = 0 ; buffer = new ByteQueue ( getBlockSize ( ) * 2 ) ; buffer . setResizable ( true ) ; cfg = true ; }
Initializes the cipher with key and iv
219
8
23,995
private void onParticipantIsTyping ( ParticipantTypingEvent event ) { handler . post ( ( ) -> listener . onParticipantIsTyping ( event ) ) ; log ( "Event published " + event . toString ( ) ) ; }
Dispatch conversation participant is typing event .
52
7
23,996
private void onParticipantTypingOff ( ParticipantTypingOffEvent event ) { handler . post ( ( ) -> listener . onParticipantTypingOff ( event ) ) ; log ( "Event published " + event . toString ( ) ) ; }
Dispatch conversation participant stopped typing event .
53
7
23,997
private void onProfileUpdate ( ProfileUpdateEvent event ) { handler . post ( ( ) -> listener . onProfileUpdate ( event ) ) ; log ( "Event published " + event . toString ( ) ) ; }
Dispatch profile update event .
45
5
23,998
private void onMessageSent ( MessageSentEvent event ) { handler . post ( ( ) -> listener . onMessageSent ( event ) ) ; log ( "Event published " + event . toString ( ) ) ; }
Dispatch conversation message event .
45
5
23,999
private void onSocketStarted ( SocketStartEvent event ) { handler . post ( ( ) -> listener . onSocketStarted ( event ) ) ; log ( "Event published " + event . toString ( ) ) ; }
Dispatch socket info event .
47
5