idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
38,200
public static String getComponentClientId ( final String componentId ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; UIViewRoot root = context . getViewRoot ( ) ; UIComponent c = findComponent ( root , componentId ) ; if ( c == null ) { return null ; } return c . getClientId ( context ) ; }
Returns the clientId for a component with id = foo .
78
12
38,201
public static UIComponent findComponent ( UIComponent c , String id ) { if ( id . equals ( c . getId ( ) ) ) { return c ; } Iterator < UIComponent > kids = c . getFacetsAndChildren ( ) ; while ( kids . hasNext ( ) ) { UIComponent found = findComponent ( kids . next ( ) , id ) ; if ( found != null ) { return found ; } }...
Finds component with the given id
102
7
38,202
public static String getInitParam ( String param , FacesContext context ) { return context . getExternalContext ( ) . getInitParameter ( param ) ; }
Shortcut for getting context parameters using an already obtained FacesContext .
32
13
38,203
public static String resolveSearchExpressions ( String refItem ) { if ( refItem != null ) { if ( refItem . contains ( "@" ) || refItem . contains ( "*" ) ) { refItem = ExpressionResolver . getComponentIDs ( FacesContext . getCurrentInstance ( ) , FacesContext . getCurrentInstance ( ) . getViewRoot ( ) , refItem ) ; } }...
Resolve the search expression
89
5
38,204
public static boolean isLegacyFeedbackClassesEnabled ( ) { String legacyErrorClasses = getInitParam ( "net.bootsfaces.legacy_error_classes" ) ; legacyErrorClasses = evalELIfPossible ( legacyErrorClasses ) ; return legacyErrorClasses . equalsIgnoreCase ( "true" ) || legacyErrorClasses . equalsIgnoreCase ( "yes" ) ; }
It checks where the framework should place BS feedback classes .
89
11
38,205
private void encodeDefaultLanguageJS ( FacesContext fc ) throws IOException { ResponseWriter rw = fc . getResponseWriter ( ) ; rw . startElement ( "script" , null ) ; rw . write ( "$.datepicker.setDefaults($.datepicker.regional['" + fc . getViewRoot ( ) . getLocale ( ) . getLanguage ( ) + "']);" ) ; rw . endElement ( "...
Generates the default language for the date picker . Originally implemented in the HeadRenderer this code has been moved here to provide better compatibility to PrimeFaces . If multiple date pickers are on the page the script is generated redundantly but this shouldn t do no harm .
106
57
38,206
public static String convertFormat ( String format ) { if ( format == null ) return null ; else { // day of week format = format . replaceAll ( "EEE" , "D" ) ; // year format = format . replaceAll ( "yy" , "y" ) ; // month if ( format . indexOf ( "MMM" ) != - 1 ) { format = format . replaceAll ( "MMM" , "M" ) ; } else ...
Converts a java Date format to a jQuery date format
120
11
38,207
private static String encodeVisibility ( IResponsive r , String value , String prefix ) { if ( value == null ) return "" ; if ( "true" . equals ( value ) || "false" . equals ( value ) ) { throw new FacesException ( "The attributes 'visible' and 'hidden' don't accept boolean values. If you want to show or hide the eleme...
Encode the visible field
136
5
38,208
private static String getSize ( IResponsiveLabel r , Sizes size ) { String colSize = "-1" ; switch ( size ) { case xs : colSize = r . getLabelColXs ( ) ; if ( colSize . equals ( "-1" ) ) colSize = r . getLabelTinyScreen ( ) ; break ; case sm : colSize = r . getLabelColSm ( ) ; if ( colSize . equals ( "-1" ) ) colSize =...
Decode col sizes between two way of definition
207
9
38,209
private static int sizeToInt ( String size ) { if ( size == null ) return - 1 ; if ( "full" . equals ( size ) ) return 12 ; if ( "full-size" . equals ( size ) ) return 12 ; if ( "fullSize" . equals ( size ) ) return 12 ; if ( "full-width" . equals ( size ) ) return 12 ; if ( "fullWidth" . equals ( size ) ) return 12 ; ...
Convert the specified size to int value
298
8
38,210
private static List < String > getSizeRange ( String operation , String size ) { return getSizeRange ( operation , size , null ) ; }
Get the size ranges
30
4
38,211
public static List < String > wonderfulTokenizer ( String tokenString , String [ ] delimiters ) { List < String > tokens = new ArrayList < String > ( ) ; String currentToken = "" ; for ( int i = 0 ; i < tokenString . length ( ) ; i ++ ) { String _currItem = String . valueOf ( tokenString . charAt ( i ) ) ; if ( _currIt...
Tokenize string based on rules
296
6
38,212
public static String getResponsiveLabelClass ( IResponsiveLabel r ) { if ( ! shouldRenderResponsiveClasses ( r ) ) { return "" ; } int colxs = sizeToInt ( getSize ( r , Sizes . xs ) ) ; int colsm = sizeToInt ( getSize ( r , Sizes . sm ) ) ; int colmd = sizeToInt ( getSize ( r , Sizes . md ) ) ; int collg = sizeToInt ( ...
Create the responsive class combination
323
5
38,213
private static boolean shouldRenderResponsiveClasses ( Object r ) { // This method only checks inputs. if ( r instanceof UIComponent && r instanceof IResponsiveLabel ) { UIForm form = AJAXRenderer . getSurroundingForm ( ( UIComponent ) r , true ) ; if ( form instanceof Form ) { if ( ( ( Form ) form ) . isInline ( ) ) {...
Temporal and ugly hack to prevent responsive classes to be applied to inputs inside inline forms .
117
18
38,214
public String getSeverityName ( Severity severity ) { if ( severity . equals ( FacesMessage . SEVERITY_INFO ) ) { return "info" ; } else if ( severity . equals ( FacesMessage . SEVERITY_WARN ) ) { return "warn" ; } else if ( severity . equals ( FacesMessage . SEVERITY_ERROR ) ) { return "error" ; } else if ( severity ....
Returns name of the given severity in lower case .
120
10
38,215
public static ValueExpression createValueExpression ( String p_expression ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( ) ; ValueExpression vex = expression...
Utility method to create a JSF Value expression from the p_expression string
90
16
38,216
public static ValueExpression createValueExpression ( String p_expression , Class < ? > expectedType ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( ) ; if ( ...
Utility method to create a JSF Value expression from p_expression with exprectedType class as return
139
22
38,217
public static MethodExpression createMethodExpression ( String p_expression , Class < ? > returnType , Class < ? > ... parameterTypes ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = c...
Utility method to create a JSF Method expression
109
10
38,218
public static NGBeanAttributeInfo getBeanAttributeInfos ( UIComponent c ) { String core = getCoreValueExpression ( c ) ; synchronized ( beanAttributeInfos ) { if ( beanAttributeInfos . containsKey ( c ) ) { return beanAttributeInfos . get ( c ) ; } } NGBeanAttributeInfo info = new NGBeanAttributeInfo ( c ) ; synchroniz...
Get the bean attributes info
110
5
38,219
public static String getCoreValueExpression ( UIComponent component ) { ValueExpression valueExpression = component . getValueExpression ( "value" ) ; if ( null != valueExpression ) { String v = valueExpression . getExpressionString ( ) ; if ( null != v ) { Matcher matcher = EL_EXPRESSION . matcher ( v ) ; if ( matcher...
Return the core value expression of a specified component
129
9
38,220
public static Annotation [ ] readAnnotations ( UIComponent p_component ) { ValueExpression valueExpression = p_component . getValueExpression ( "value" ) ; if ( valueExpression != null && valueExpression . getExpressionString ( ) != null && valueExpression . getExpressionString ( ) . length ( ) > 0 ) { return readAnnot...
Which annotations are given to an object displayed by a JSF component?
98
14
38,221
public void processEvent ( SystemEvent event ) throws AbortProcessingException { FacesContext context = FacesContext . getCurrentInstance ( ) ; UIViewRoot root = context . getViewRoot ( ) ; // render the resources only if there is at least one bsf component if ( ensureExistBootsfacesComponent ( root , context ) ) { add...
Trigger adding the resources if and only if the event has been fired by UIViewRoot .
101
19
38,222
private boolean ensureExistBootsfacesComponent ( UIViewRoot root , FacesContext context ) { Map < String , Object > viewMap = root . getViewMap ( ) ; // check explicit js request if ( viewMap . get ( RESOURCE_KEY ) != null ) return true ; // check explicit css request if ( viewMap . get ( THEME_RESOURCE_KEY ) != null )...
Check if there is almost one bootsfaces component in page . If yes load the correct items .
148
19
38,223
public static UIComponent findBsfComponent ( UIComponent parent , String targetLib ) { if ( targetLib . equalsIgnoreCase ( ( String ) parent . getAttributes ( ) . get ( "library" ) ) ) { return parent ; } Iterator < UIComponent > kids = parent . getFacetsAndChildren ( ) ; while ( kids . hasNext ( ) ) { UIComponent foun...
Check all components in page to find one that has as resource library the target library . I use this method to check existence of a BsF component because at this level the getComponentResource returns always null
122
41
38,224
private void addMetaTags ( UIViewRoot root , FacesContext context ) { // Check context-param String viewportParam = BsfUtils . getInitParam ( C . P_VIEWPORT , context ) ; viewportParam = evalELIfPossible ( viewportParam ) ; String content = "width=device-width, initial-scale=1" ; if ( ! viewportParam . isEmpty ( ) && i...
Add the viewport meta tag if not disabled from context - param
251
13
38,225
private void addJavascript ( UIViewRoot root , FacesContext context ) { // The following code is needed to diagnose the warning "Unable to save dynamic // action with clientId 'j_id...'" // List<UIComponent> r = root.getComponentResources(context, "head"); // System.out.println("**************"); // for (UIComponent av...
Add the required Javascript files and the FontAwesome CDN link .
561
13
38,226
private void removeDuplicateResources ( UIViewRoot root , FacesContext context ) { List < UIComponent > resourcesToRemove = new ArrayList < UIComponent > ( ) ; Map < String , UIComponent > alreadyThere = new HashMap < String , UIComponent > ( ) ; List < UIComponent > components = new ArrayList < UIComponent > ( root . ...
Remove duplicate resource files . For some reason many resource files are added more than once especially when AJAX is used . The method removes the duplicate files .
446
30
38,227
private void enforceCorrectLoadOrder ( UIViewRoot root , FacesContext context ) { // // first, handle the CSS files. // // Put BootsFaces.css or BootsFaces.min.css first, // // theme.css second // // and everything else behind them. List < UIComponent > resources = new ArrayList < UIComponent > ( ) ; List < UIComponent...
Make sure jQuery is loaded before jQueryUI and that every other Javascript is loaded later . Also make sure that the BootsFaces resource files are loaded prior to other resource files giving the developer the opportunity to overwrite a CSS or JS file .
712
47
38,228
private UIComponent findHeader ( UIViewRoot root ) { for ( UIComponent c : root . getChildren ( ) ) { if ( c instanceof HtmlHead ) return c ; } for ( UIComponent c : root . getChildren ( ) ) { if ( c instanceof HtmlBody ) return null ; if ( c instanceof UIOutput ) if ( c . getFacets ( ) != null ) return c ; } return nu...
Looks for the header in the JSF tree .
100
10
38,229
public static void addResourceToHeadButAfterJQuery ( String library , String resource ) { addResource ( resource , library , library + "#" + resource , RESOURCE_KEY ) ; }
Registers a JS file that needs to be included in the header of the HTML file but after jQuery and AngularJS .
40
24
38,230
public static void addBasicJSResource ( String library , String resource ) { addResource ( resource , library , resource , BASIC_JS_RESOURCE_KEY ) ; }
Registers a core JS file that needs to be included in the header of the HTML file but after jQuery and AngularJS .
36
25
38,231
public static void addThemedCSSResource ( String resource ) { Map < String , Object > viewMap = FacesContext . getCurrentInstance ( ) . getViewRoot ( ) . getViewMap ( ) ; @ SuppressWarnings ( "unchecked" ) List < String > resourceList = ( List < String > ) viewMap . get ( THEME_RESOURCE_KEY ) ; if ( null == resourceLis...
Registers a themed CSS file that needs to be included in the header of the HTML file .
142
19
38,232
public static void addDatatablesResourceIfNecessary ( String defaultFilename , String type ) { boolean loadDatatables = shouldLibraryBeLoaded ( P_GET_DATATABLE_FROM_CDN , true ) ; // Do we have to add datatables.min.{css|js}, or are the resources already there? FacesContext context = FacesContext . getCurrentInstance (...
Add the default datatables . net resource if and only if the user doesn t bring their own copy and if they didn t disallow it in the web . xml by setting the context paramter net . bootsfaces . get_datatable_from_cdn to true .
284
56
38,233
public static Class < ? > getValueType ( FacesContext context , UIComponent uiComponent , Collection < Class < ? > > validTypes ) { Class < ? > valueType = getValueType ( context , uiComponent ) ; if ( valueType != null && isValid ( validTypes , valueType ) ) { return valueType ; } else { for ( UIComponent child : uiCo...
Source adapted from Seam s enumConverter . The goal is to get the type to which this component s value is bound . First check if the valueExpression provides the type . For dropdown - like components this may not work so check for SelectItems children .
261
55
38,234
public static Class < ? > getValueType ( FacesContext context , UIComponent comp ) { ValueExpression expr = comp . getValueExpression ( "value" ) ; Class < ? > valueType = expr == null ? null : expr . getType ( context . getELContext ( ) ) ; return valueType ; }
return the type for the value attribute of the given component if it exists . Return null otherwise .
70
19
38,235
@ SuppressWarnings ( "rawtypes" ) private void removeMisleadingType ( Slider2 slider ) { try { Method method = getClass ( ) . getMethod ( "getPassThroughAttributes" , ( Class [ ] ) null ) ; if ( null != method ) { Object map = method . invoke ( this , ( Object [ ] ) null ) ; if ( null != map ) { Map attributes = ( Map ...
remove wrong type information that may have been added by AngularFaces
136
13
38,236
protected SelectItem createSelectItem ( FacesContext context , UISelectItems uiSelectItems , Object value , Object label ) { String var = ( String ) uiSelectItems . getAttributes ( ) . get ( "var" ) ; Map < String , Object > attrs = uiSelectItems . getAttributes ( ) ; Map < String , Object > requestMap = context . getE...
Copied from the InputRenderer class of PrimeFaces 5 . 1 .
390
17
38,237
private void add_snake_case_properties ( List < PropertyDescriptor > pdl ) throws IntrospectionException { List < PropertyDescriptor > alternatives = new ArrayList < PropertyDescriptor > ( ) ; for ( PropertyDescriptor descriptor : pdl ) { String camelCase = descriptor . getName ( ) ; if ( camelCase . equals ( "renderer...
Method that generates dynamically the snake - case methods from the available camelcase properties found inside the bean list .
383
21
38,238
public static void generateJSEventHandlers ( ResponseWriter rw , UIComponent component ) throws IOException { Map < String , Object > attributes = component . getAttributes ( ) ; String [ ] eventHandlers = { "onclick" , "onblur" , "onmouseover" } ; for ( String event : eventHandlers ) { String handler = A . asString ( ...
Generates the standard Javascript event handlers .
115
8
38,239
@ Override public Object getConvertedValue ( FacesContext context , Object submittedValue ) throws ConverterException { if ( submittedValue == null ) { return null ; } String val = ( String ) submittedValue ; // If the Trimmed submitted value is empty, return null if ( val . trim ( ) . length ( ) == 0 ) { return null ;...
Converts the date from the moment . js format to a java . util . Date .
425
18
38,240
private static Number toNumber ( Object object ) { if ( object instanceof Number ) { return ( Number ) object ; } if ( object instanceof String ) { return Float . valueOf ( ( String ) object ) ; } throw new IllegalArgumentException ( "Use number or string" ) ; }
Convert object to number . To be backwards compatible with bound integers to properties where we now also want to accept floats now .
62
25
38,241
public static final void encodeColumn ( ResponseWriter rw , UIComponent c , int span , int cxs , int csm , int clg , int offset , int oxs , int osm , int olg , String style , String sclass ) throws IOException { rw . startElement ( "div" , c ) ; Map < String , Object > componentAttrs = new HashMap < String , Object > (...
Encodes a Column
623
4
38,242
public static void addClass2FacetComponent ( UIComponent f , String cname , String aclass ) { // If the facet contains only one component, getChildCount()=0 and the // Facet is the UIComponent if ( f . getClass ( ) . getName ( ) . endsWith ( cname ) ) { addClass2Component ( f , aclass ) ; } else { if ( f . getChildCoun...
Adds a CSS class to a component within a facet .
154
11
38,243
protected static void addClass2Component ( UIComponent c , String aclass ) { Map < String , Object > a = c . getAttributes ( ) ; if ( a . containsKey ( "styleClass" ) ) { a . put ( "styleClass" , a . get ( "styleClass" ) + " " + aclass ) ; } else { a . put ( "styleClass" , aclass ) ; } }
Adds a CSS class to a component in the view tree . The class is appended to the styleClass value .
92
23
38,244
public static void decorateFacetComponent ( UIComponent parent , UIComponent comp , FacesContext ctx , ResponseWriter rw ) throws IOException { /* * System.out.println("COMPONENT CLASS = " + comp.getClass().getName()); * System.out.println("FAMILY = " + comp.getFamily()); * System.out.println("CHILD COUNT = " + comp.ge...
Decorate the facet children with a class to render bootstrap like prepend and append sections
375
18
38,245
private static void decorateComponent ( UIComponent parent , UIComponent comp , FacesContext ctx , ResponseWriter rw ) throws IOException { if ( comp instanceof Icon ) ( ( Icon ) comp ) . setAddon ( true ) ; // modifies the id of the icon String classToApply = "input-group-addon" ; if ( comp . getClass ( ) . getName ( ...
Add the correct class
254
4
38,246
public static String findComponentFormId ( FacesContext fc , UIComponent c ) { UIComponent parent = c . getParent ( ) ; while ( parent != null ) { if ( parent instanceof UIForm ) { return parent . getClientId ( fc ) ; } parent = parent . getParent ( ) ; } return null ; }
Finds the Form Id of a component inside a form .
76
12
38,247
public static void renderChildren ( FacesContext fc , UIComponent component ) throws IOException { for ( Iterator < UIComponent > iterator = component . getChildren ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { UIComponent child = ( UIComponent ) iterator . next ( ) ; renderChild ( fc , child ) ; } }
Renders the Childrens of a Component
82
8
38,248
public static void renderChild ( FacesContext fc , UIComponent child ) throws IOException { if ( ! child . isRendered ( ) ) { return ; } child . encodeBegin ( fc ) ; if ( child . getRendersChildren ( ) ) { child . encodeChildren ( fc ) ; } else { renderChildren ( fc , child ) ; } child . encodeEnd ( fc ) ; }
Renders the Child of a Component
89
7
38,249
public static MethodExpression evalAsMethodExpression ( String p_expression ) throws PropertyNotFoundException { FacesContext context = FacesContext . getCurrentInstance ( ) ; ExpressionFactory expressionFactory = context . getApplication ( ) . getExpressionFactory ( ) ; ELContext elContext = context . getELContext ( )...
Evaluates an EL expression into an object .
104
10
38,250
private void checkELSyntax ( String el , ELContext context ) { int pos = el . indexOf ( ' ' ) ; if ( pos < 0 ) { throw new FacesException ( "The EL expression doesn't contain a method call: " + el ) ; } int end = el . indexOf ( ' ' ) ; if ( end < 0 ) end = el . length ( ) ; if ( el . indexOf ( ' ' ) >= 0 ) end = Math ....
Evaluate the expression syntax
230
6
38,251
public void decode ( FacesContext context , UIComponent component , List < String > legalValues , String realEventSourceName ) { InputText inputText = ( InputText ) component ; if ( inputText . isDisabled ( ) || inputText . isReadonly ( ) ) { return ; } decodeBehaviors ( context , inputText ) ; String clientId = inputT...
This method is used by RadioButtons and SelectOneMenus to limit the list of legal values . If another value is sent the input field is considered empty . This comes in useful the the back - end attribute is a primitive type like int which doesn t support null values .
343
56
38,252
private void renderJQueryAfterComponent ( ResponseWriter rw , String clientId , SelectOneMenu menu ) throws IOException { Boolean select2 = menu . isSelect2 ( ) ; if ( select2 != null && select2 ) { rw . startElement ( "script" , menu ) ; rw . writeAttribute ( "type" , "text/javascript" , "script" ) ; StringBuilder buf...
render a jquery javascript block after the component if necessary
217
11
38,253
private SelectItemAndComponent determineSelectedItem ( FacesContext context , SelectOneMenu menu , List < SelectItemAndComponent > items , Converter converter ) { Object submittedValue = menu . getSubmittedValue ( ) ; Object selectedOption ; if ( submittedValue != null ) { selectedOption = submittedValue ; } else { sel...
Compare current selection with items if there is any element selected
236
11
38,254
private String decodeAndEscapeSelectors ( FacesContext context , UIComponent component , String selector ) { selector = ExpressionResolver . getComponentIDs ( context , component , selector ) ; selector = BsfUtils . escapeJQuerySpecialCharsInSelector ( selector ) ; return selector ; }
Decode and escape selectors if necessary
64
8
38,255
public static String getErrorSeverityClass ( String clientId ) { String [ ] levels = { "bf-no-message has-success" , "bf-info" , "bf-warning has-warning" , "bf-error has-error" , "bf-fatal has-error" } ; int level = 0 ; Iterator < FacesMessage > messages = FacesContext . getCurrentInstance ( ) . getMessages ( clientId ...
Returns style matching the severity error .
285
7
38,256
private void saveInitialChildState ( FacesContext facesContext ) { index = - 1 ; initialChildState = new ConcurrentHashMap < String , SavedState > ( ) ; initialClientId = getClientId ( facesContext ) ; if ( getChildCount ( ) > 0 ) { for ( UIComponent child : getChildren ( ) ) { saveInitialChildState ( facesContext , ch...
Save the initial child state .
88
6
38,257
public static Date autoParseDateFormat ( String dateString ) { // STEP 1: try to detect standard locale based java date format for ( Locale locale : DateFormat . getAvailableLocales ( ) ) { for ( int style = DateFormat . FULL ; style <= DateFormat . SHORT ; style ++ ) { DateFormat df = DateFormat . getDateInstance ( st...
Try to auto - parse the date format
206
8
38,258
private static String translateFormat ( String formatString , Map < String , String > mapping , String escapeStart , String escapeEnd , String targetEscapeStart , String targetEscapeEnd ) { int beginIndex = 0 ; int i = 0 ; char lastChar = 0 ; char currentChar = 0 ; String resultString = "" ; char esc1 = escapeStart . c...
Internal method to do translations
355
5
38,259
private static String mapSubformat ( String formatString , Map < String , String > mapping , int beginIndex , int currentIndex , String escapeStart , String escapeEnd , String targetEscapeStart , String targetEscapeEnd ) { String subformat = formatString . substring ( beginIndex , currentIndex ) ; if ( subformat . equa...
Append the new mapping
181
5
38,260
@ Override public Map < String , String > getJQueryEventParameterLists ( ) { Map < String , String > result = new HashMap < String , String > ( ) ; result . put ( "select" , "event, datatable, typeOfSelection, indexes" ) ; result . put ( "deselect" , "event, datatable, typeOfSelection, indexes" ) ; return result ; }
Returns the parameter list of jQuery and other non - standard JS callbacks . If there s no parameter list for a certain event the default is simply event .
91
31
38,261
@ Override public Map < String , String > getJQueryEventParameterListsForAjax ( ) { Map < String , String > result = new HashMap < String , String > ( ) ; result . put ( "select" , "'typeOfSelection':typeOfSelection,'indexes':indexes" ) ; result . put ( "deselect" , "'typeOfSelection':typeOfSelection,'indexes':indexes"...
Returns the subset of the parameter list of jQuery and other non - standard JS callbacks which is sent to the server via AJAX . If there s no parameter list for a certain event the default is simply null .
103
43
38,262
private static < T > Observable < Boolean > commitOrRollbackOnNext ( final boolean isCommit , final Database db , Observable < T > source ) { return source . concatMap ( new Func1 < T , Observable < Boolean > > ( ) { @ Override public Observable < Boolean > call ( T t ) { if ( isCommit ) return db . commit ( ) ; else r...
Emits true for commit and false for rollback .
100
11
38,263
public Database asynchronous ( final Scheduler nonTransactionalScheduler ) { return asynchronous ( new Func0 < Scheduler > ( ) { @ Override public Scheduler call ( ) { return nonTransactionalScheduler ; } } ) ; }
Returns a Database based on the current Database except all non - transactional queries run on the given scheduler .
54
22
38,264
private void connectAndPrepareStatement ( Subscriber < ? super T > subscriber , State state ) throws SQLException { log . debug ( "connectionProvider={}" , query . context ( ) . connectionProvider ( ) ) ; if ( ! subscriber . isUnsubscribed ( ) ) { log . debug ( "getting connection" ) ; state . con = query . context ( )...
Obtains connection creates prepared statement and assigns parameters to the prepared statement .
220
14
38,265
static int parametersCount ( Query query ) { if ( query . names ( ) . isEmpty ( ) ) return countQuestionMarkParameters ( query . sql ( ) ) ; else return query . names ( ) . size ( ) ; }
Count the number of JDBC parameters in a sql statement .
48
12
38,266
private static String getTypeInfo ( List < Object > list ) { StringBuilder s = new StringBuilder ( ) ; for ( Object o : list ) { if ( s . length ( ) > 0 ) s . append ( ", " ) ; if ( o == null ) s . append ( "null" ) ; else { s . append ( o . getClass ( ) . getName ( ) ) ; s . append ( "=" ) ; s . append ( o ) ; } } ret...
Returns debugging info about the types of a list of objects .
110
12
38,267
private static void setBlob ( PreparedStatement ps , int i , Object o , Class < ? > cls ) throws SQLException { final InputStream is ; if ( o instanceof byte [ ] ) { is = new ByteArrayInputStream ( ( byte [ ] ) o ) ; }
Sets a blob parameter for the prepared statement .
63
10
38,268
private static HikariDataSource createPool ( String url , String username , String password , int minPoolSize , int maxPoolSize , long connectionTimeoutMs ) { HikariDataSource ds = new HikariDataSource ( ) ; ds . setJdbcUrl ( url ) ; ds . setUsername ( username ) ; ds . setPassword ( password ) ; ds . setMinimumIdle ( ...
Returns a new pooled data source based on jdbc url .
123
13
38,269
static Observable < List < Parameter > > bufferedParameters ( Query query ) { int numParamsPerQuery = numParamsPerQuery ( query ) ; if ( numParamsPerQuery > 0 ) // we don't check that parameters is empty after this because by // general design we want nothing to happen if a query is passed no // parameters when it expe...
If the number of parameters in a query is > 0 then group the parameters in lists of that number in size but only after the dependencies have been completed . If the number of parameteres is zero then return an observable containing one item being an empty list .
140
52
38,270
public < T > Observable < T > execute ( ResultSetMapper < ? extends T > function ) { return bufferedParameters ( this ) // execute once per set of parameters . concatMap ( executeOnce ( function ) ) ; }
Returns the results of running a select query with all sets of parameters .
50
14
38,271
private void checkSubscription ( Subscriber < ? super T > subscriber ) { if ( subscriber . isUnsubscribed ( ) ) { keepGoing = false ; log . debug ( "unsubscribing" ) ; } }
If subscribe unsubscribed sets keepGoing to false .
48
10
38,272
private void getConnection ( State state ) { state . con = query . context ( ) . connectionProvider ( ) . get ( ) ; debug ( "getting connection" ) ; debug ( "cp={}" , query . context ( ) . connectionProvider ( ) ) ; }
Gets the current connection .
56
6
38,273
private void complete ( Subscriber < ? super T > subscriber ) { if ( ! subscriber . isUnsubscribed ( ) ) { debug ( "onCompleted" ) ; subscriber . onCompleted ( ) ; } else debug ( "unsubscribed" ) ; }
Notify observer that sequence is complete .
55
8
38,274
private void handleException ( Throwable e , Subscriber < ? super T > subscriber ) { debug ( "onError: " , e . getMessage ( ) ) ; Exceptions . throwOrReport ( e , subscriber ) ; }
Notify observer of an error .
49
7
38,275
private void close ( State state ) { // ensure close happens once only to avoid race conditions if ( state . closed . compareAndSet ( false , true ) ) { Util . closeQuietly ( state . ps ) ; if ( isCommit ( ) || isRollback ( ) ) Util . closeQuietly ( state . con ) ; else Util . closeQuietlyIfAutoCommit ( state . con ) ;...
Cancels a running PreparedStatement closing it and the current Connection but only if auto commit mode .
94
21
38,276
< T > void parameters ( Observable < T > params ) { this . parameters = Observable . concat ( parameters , params . map ( Parameter . TO_PARAMETER ) ) ; }
Appends the given parameters to the parameter list for the query . If there are more parameters than required for one execution of the query then more than one execution of the query will occur .
43
37
38,277
void parameter ( Object value ) { // TODO check on supported types? if ( value instanceof Observable ) throw new IllegalArgumentException ( "use parameters() method not the parameter() method for an Observable" ) ; parameters ( Observable . just ( value ) ) ; }
Appends a parameter to the parameter list for the query . If there are more parameters than required for one execution of the query then more than one execution of the query will occur .
59
36
38,278
@ SuppressLint ( "MissingPermission" ) @ RequiresPermission ( allOf = { ACCESS_COARSE_LOCATION , ACCESS_FINE_LOCATION , CHANGE_WIFI_STATE , ACCESS_WIFI_STATE } ) public static Observable < List < ScanResult > > observeWifiAccessPoints ( final Context context ) { @ SuppressLint ( "WifiManagerPotentialLeak" ) final WifiM...
Observes WiFi Access Points . Returns fresh list of Access Points whenever WiFi signal strength changes .
416
18
38,279
@ RequiresPermission ( ACCESS_WIFI_STATE ) public static Observable < WifiSignalLevel > observeWifiSignalLevel ( final Context context ) { return observeWifiSignalLevel ( context , WifiSignalLevel . getMaxLevel ( ) ) . map ( new Function < Integer , WifiSignalLevel > ( ) { @ Override public WifiSignalLevel apply ( Inte...
Observes WiFi signal level with predefined max num levels . Returns WiFi signal level as enum with information about current level
111
23
38,280
@ RequiresPermission ( ACCESS_WIFI_STATE ) public static Observable < Integer > observeWifiSignalLevel ( final Context context , final int numLevels ) { final WifiManager wifiManager = ( WifiManager ) context . getSystemService ( Context . WIFI_SERVICE ) ; final IntentFilter filter = new IntentFilter ( ) ; filter . add...
Observes WiFi signal level . Returns WiFi signal level as an integer
283
13
38,281
@ RequiresPermission ( ACCESS_WIFI_STATE ) public static Observable < WifiState > observeWifiStateChange ( final Context context ) { final IntentFilter filter = new IntentFilter ( ) ; filter . addAction ( WifiManager . WIFI_STATE_CHANGED_ACTION ) ; return Observable . create ( new ObservableOnSubscribe < WifiState > ( ...
Observes WiFi State Change Action Returns wifi state whenever WiFi state changes such like enable disable enabling disabling or Unknown
195
21
38,282
public synchronized DatabaseInfo getDatabaseInfo ( ) { if ( databaseInfo != null ) { return databaseInfo ; } try { _check_mtime ( ) ; boolean hasStructureInfo = false ; byte [ ] delim = new byte [ 3 ] ; // Advance to part of file where database info is stored. file . seek ( file . length ( ) - 3 ) ; for ( int i = 0 ; i...
Returns information about the database .
412
6
38,283
public Location getLocation ( String str ) { InetAddress addr ; try { addr = InetAddress . getByName ( str ) ; } catch ( UnknownHostException e ) { return null ; } return getLocation ( addr ) ; }
for GeoIP City only
50
5
38,284
private synchronized int seekCountryV6 ( InetAddress addr ) { byte [ ] v6vec = addr . getAddress ( ) ; if ( v6vec . length == 4 ) { // sometimes java returns an ipv4 address for IPv6 input // we have to work around that feature // It happens for ::ffff:24.24.24.24 byte [ ] t = new byte [ 16 ] ; System . arraycopy ( v6v...
Finds the country index value given an IPv6 address .
334
12
38,285
private synchronized int seekCountry ( long ipAddress ) { byte [ ] buf = new byte [ 2 * MAX_RECORD_LENGTH ] ; int [ ] x = new int [ 2 ] ; int offset = 0 ; _check_mtime ( ) ; for ( int depth = 31 ; depth >= 0 ; depth -- ) { readNode ( buf , x , offset ) ; if ( ( ipAddress & ( 1 << depth ) ) > 0 ) { if ( x [ 1 ] >= datab...
Finds the country index value given an IP address .
196
11
38,286
private static long bytesToLong ( byte [ ] address ) { long ipnum = 0 ; for ( int i = 0 ; i < 4 ; ++ i ) { long y = address [ i ] ; if ( y < 0 ) { y += 256 ; } ipnum += y << ( ( 3 - i ) * 8 ) ; } return ipnum ; }
Returns the long version of an IP address given an InetAddress object .
75
15
38,287
public Date getDate ( ) { for ( int i = 0 ; i < info . length ( ) - 9 ; i ++ ) { if ( Character . isWhitespace ( info . charAt ( i ) ) ) { String dateString = info . substring ( i + 1 , i + 9 ) ; try { synchronized ( formatter ) { return formatter . parse ( dateString ) ; } } catch ( ParseException pe ) { } break ; } }...
Returns the date of the database .
102
7
38,288
public void swapElements ( int i , int j ) { if ( i != j ) { double s = get ( i ) ; set ( i , get ( j ) ) ; set ( j , s ) ; } }
Swaps the specified elements of this vector .
47
9
38,289
public Vector shuffle ( ) { Vector result = copy ( ) ; // Conduct Fisher-Yates shuffle Random random = new Random ( ) ; for ( int i = 0 ; i < length ; i ++ ) { int j = random . nextInt ( length - i ) + i ; swapElements ( i , j ) ; } return result ; }
Shuffles this vector .
72
6
38,290
public Vector slice ( int from , int until ) { if ( until - from < 0 ) { fail ( "Wrong slice range: [" + from + ".." + until + "]." ) ; } Vector result = blankOfLength ( until - from ) ; for ( int i = from ; i < until ; i ++ ) { result . set ( i - from , get ( i ) ) ; } return result ; }
Retrieves the specified sub - vector of this vector . The sub - vector is specified by interval of indices .
89
23
38,291
public Vector select ( int [ ] indices ) { int newLength = indices . length ; if ( newLength == 0 ) { fail ( "No elements selected." ) ; } Vector result = blankOfLength ( newLength ) ; for ( int i = 0 ; i < newLength ; i ++ ) { result . set ( i , get ( indices [ i ] ) ) ; } return result ; }
Returns a new vector with the selected elements .
83
9
38,292
public String mkString ( NumberFormat formatter , String delimiter ) { StringBuilder sb = new StringBuilder ( ) ; VectorIterator it = iterator ( ) ; while ( it . hasNext ( ) ) { double x = it . next ( ) ; int i = it . index ( ) ; sb . append ( formatter . format ( x ) ) . append ( ( i < length - 1 ? delimiter : "" ) ) ...
Converts this vector into the string representation .
103
9
38,293
@ Override public VectorIterator iterator ( ) { return new VectorIterator ( length ) { private int i = - 1 ; @ Override public int index ( ) { return i ; } @ Override public double get ( ) { return Vector . this . get ( i ) ; } @ Override public void set ( double value ) { Vector . this . set ( i , value ) ; } @ Overri...
Returns a vector iterator .
139
5
38,294
public static VectorAccumulator asSumAccumulator ( final double neutral ) { return new VectorAccumulator ( ) { private BigDecimal result = BigDecimal . valueOf ( neutral ) ; @ Override public void update ( int i , double value ) { result = result . add ( BigDecimal . valueOf ( value ) ) ; } @ Override public double acc...
Creates a sum vector accumulator that calculates the sum of all elements in the vector .
135
18
38,295
public static VectorAccumulator mkMinAccumulator ( ) { return new VectorAccumulator ( ) { private double result = Double . POSITIVE_INFINITY ; @ Override public void update ( int i , double value ) { result = Math . min ( result , value ) ; } @ Override public double accumulate ( ) { double value = result ; result = Do...
Makes a minimum vector accumulator that accumulates the minimum across vector elements .
96
16
38,296
public static VectorAccumulator mkMaxAccumulator ( ) { return new VectorAccumulator ( ) { private double result = Double . NEGATIVE_INFINITY ; @ Override public void update ( int i , double value ) { result = Math . max ( result , value ) ; } @ Override public double accumulate ( ) { double value = result ; result = Do...
Makes a maximum vector accumulator that accumulates the maximum across vector elements .
96
16
38,297
public static VectorProcedure asAccumulatorProcedure ( final VectorAccumulator accumulator ) { return new VectorProcedure ( ) { @ Override public void apply ( int i , double value ) { accumulator . update ( i , value ) ; } } ; }
Creates an accumulator procedure that adapts a vector accumulator for procedure interface . This is useful for reusing a single accumulator for multiple fold operations in multiple vectors .
60
35
38,298
public static MatrixAccumulator mkMinAccumulator ( ) { return new MatrixAccumulator ( ) { private double result = Double . POSITIVE_INFINITY ; @ Override public void update ( int i , int j , double value ) { result = Math . min ( result , value ) ; } @ Override public double accumulate ( ) { double value = result ; res...
Makes a minimum matrix accumulator that accumulates the minimum of matrix elements .
99
16
38,299
public static MatrixAccumulator mkMaxAccumulator ( ) { return new MatrixAccumulator ( ) { private double result = Double . NEGATIVE_INFINITY ; @ Override public void update ( int i , int j , double value ) { result = Math . max ( result , value ) ; } @ Override public double accumulate ( ) { double value = result ; res...
Makes a maximum matrix accumulator that accumulates the maximum of matrix elements .
99
16