idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
1,300
public static String getCharsetFromContentType ( Header header ) { if ( header == null || header . getValue ( ) == null || "" . equals ( header . getValue ( ) ) ) return null ; Matcher m = charsetPattern . matcher ( header . getValue ( ) ) ; if ( m . find ( ) ) { return m . group ( 1 ) . trim ( ) . toUpperCase ( ) ; } return null ; }
Parse out a charset from a content type header .
1,301
public URIBuilder setUserInfo ( final String userInfo ) { this . userInfo = userInfo ; this . encodedSchemeSpecificPart = null ; this . encodedAuthority = null ; this . encodedUserInfo = null ; return this ; }
Sets URI user info . The value is expected to be unescaped and may contain non ASCII characters .
1,302
public URIBuilder setHost ( final String host ) { this . host = host ; this . encodedSchemeSpecificPart = null ; this . encodedAuthority = null ; return this ; }
Sets URI host .
1,303
public URIBuilder setPort ( final int port ) { this . port = port < 0 ? - 1 : port ; this . encodedSchemeSpecificPart = null ; this . encodedAuthority = null ; return this ; }
Sets URI port .
1,304
public URIBuilder setPath ( final String path ) { this . path = path ; this . encodedSchemeSpecificPart = null ; this . encodedPath = null ; return this ; }
Sets URI path . The value is expected to be unescaped and may contain non ASCII characters .
1,305
public String linkRel ( ) { if ( this . linkRel != null ) return this . linkRel ; if ( node . hasAttribute ( "rel" ) ) return node . getAttribute ( "rel" ) ; return node . getName ( ) ; }
the String name of the link relationship from this resource to the resource identified by the link
1,306
@ SuppressWarnings ( "unchecked" ) private < T extends Resource > T submit ( Form form , Parameters parameters ) { RequestBuilder < Resource > request = doRequest ( form . getUri ( ) ) . set ( parameters ) ; boolean doPost = form . isDoPost ( ) ; boolean multiPart = form . isMultiPart ( ) ; if ( doPost && multiPart ) { request . multiPart ( ) ; addFiles ( request , form ) ; } return ( T ) ( doPost ? request . post ( ) : request . get ( ) ) ; }
Returns the page object received as response to the form submit action .
1,307
private Parameters composeParameters ( SubmitButton button , SubmitImage image , int x , int y ) { Parameters params = new Parameters ( ) ; for ( FormElement element : this ) { String name = element . getName ( ) ; String value = element . getValue ( ) ; if ( element instanceof Checkable ) { if ( ( ( Checkable ) element ) . isChecked ( ) ) params . add ( name , value != null ? value : "" ) ; } else if ( element instanceof Select ) { Select select = ( Select ) element ; for ( Select . Option option : select . getOptions ( ) ) if ( option . isSelected ( ) ) params . add ( select . getName ( ) , option . getValue ( ) != null ? option . getValue ( ) : "" ) ; } else if ( ! ( element instanceof SubmitButton ) && ! ( element instanceof SubmitImage ) && ! ( element instanceof Upload ) ) { if ( name != null ) params . add ( name , value != null ? value : "" ) ; } } if ( button != null && button . getName ( ) != null ) params . add ( button . getName ( ) , button . getValue ( ) != null ? button . getValue ( ) : "" ) ; if ( image != null ) { if ( image . getValue ( ) != null && image . getValue ( ) . length ( ) > 1 ) params . add ( image . getName ( ) , image . getValue ( ) ) ; params . add ( image . getName ( ) + ".x" , "" + x ) ; params . add ( image . getName ( ) + ".y" , "" + y ) ; } return params ; }
Returns the parameters containing all name value params beside submit button image button unchecked radio buttons and checkboxes and without Upload information .
1,308
String getBody ( Object object , ContentType contentType ) { if ( contentType == ContentType . APPLICATION_FORM_URLENCODED ) { return jsonToUrlEncodedString ( ( JsonObject ) new JsonParser ( ) . parse ( gson . toJson ( object ) ) ) ; } return gson . toJson ( object ) ; }
This method is used to get a serialized object into its equivalent JSON representation .
1,309
public Map < String , Object > jsonToMap ( String json ) { if ( "200" . equals ( json ) ) { this . responseBody . put ( "code" , 200 ) ; return this . responseBody ; } if ( "400" . equals ( json ) ) { this . responseBody . put ( "code" , 400 ) ; return this . responseBody ; } if ( "404" . equals ( json ) ) { this . responseBody . put ( "code" , 404 ) ; return this . responseBody ; } if ( ! json . equals ( "" ) ) { ObjectMapper mapper = new ObjectMapper ( ) ; try { this . responseBody = mapper . readValue ( json , new TypeReference < Map < String , Object > > ( ) { } ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return this . responseBody ; }
This method is used to receive the JSON returned from API and cast it to a Map .
1,310
public Map < String , Object > deleteCreditCard ( String creditCardId , Setup setup ) { this . requestMaker = new RequestMaker ( setup ) ; RequestProperties props = new RequestPropertiesBuilder ( ) . method ( "DELETE" ) . endpoint ( String . format ( "/v2/fundinginstruments/%s" , creditCardId ) ) . type ( Customers . class ) . contentType ( CONTENT_TYPE ) . build ( ) ; return this . requestMaker . doRequest ( props ) ; }
This method is used to delete a saved credit card of an customer .
1,311
private boolean isTaxDocument ( String argument ) { try { Integer . parseInt ( argument . substring ( 0 , 1 ) ) ; } catch ( Exception ex ) { return false ; } return true ; }
This method is used to validate the argument of bellow method if probably it s a tax document or not .
1,312
public List < Map < String , Object > > listBankAccounts ( String moipAccountId , Setup setup ) { this . requestMaker = new RequestMaker ( setup ) ; RequestProperties props = new RequestPropertiesBuilder ( ) . method ( "GET" ) . endpoint ( String . format ( "%s/%s/bankaccounts" , ENDPOINT , moipAccountId ) ) . type ( BankAccounts . class ) . contentType ( CONTENT_TYPE ) . build ( ) ; return this . requestMaker . getList ( props ) ; }
This method allows you to list all bank account of a Moip account .
1,313
public void reset ( ) { if ( debug ) LogD ( "Count reset" ) ; editor . putInt ( KEY_COUNT , 0 ) ; editor . putBoolean ( KEY_CLICKED , false ) ; editor . putLong ( KEY_LAST_CRASH , 0L ) ; commitEditor ( ) ; }
Reset the count to start over
1,314
public List < Map < String , Object > > list ( Setup setup ) { this . requestMaker = new RequestMaker ( setup ) ; RequestProperties props = new RequestPropertiesBuilder ( ) . method ( "GET" ) . endpoint ( ENDPOINT ) . type ( NotificationPreferences . class ) . contentType ( CONTENT_TYPE ) . build ( ) ; return this . requestMaker . getList ( props ) ; }
This method is used to get all created notification preferences .
1,315
private String acceptBuilder ( String version ) { String acceptValue = "application/json" ; if ( version == "2.1" ) acceptValue += ";version=" + version ; return acceptValue ; }
This method is used to validate and build the accept JSON version .
1,316
public Map < String , Object > release ( String escrowId , Setup setup ) { this . requestMaker = new RequestMaker ( setup ) ; RequestProperties props = new RequestPropertiesBuilder ( ) . method ( "POST" ) . endpoint ( String . format ( "%s/%s/release" , ENDPOINT , escrowId ) ) . type ( Escrows . class ) . contentType ( CONTENT_TYPE ) . build ( ) ; return this . requestMaker . doRequest ( props ) ; }
This method allows you to release a payment with escrow .
1,317
public String buildUrl ( String clientId , String redirectUri , String [ ] scope , Setup setup ) { String url = setup . getEnvironment ( ) + "/oauth/authorize" ; url += String . format ( "?response_type=code&client_id=%s&redirect_uri=%s&scope=" , clientId , redirectUri ) ; for ( Integer index = 0 ; index < scope . length ; ++ index ) { url += scope [ index ] ; if ( ( index + 1 ) < scope . length ) url += ',' ; } return url ; }
This method is used to build the URL to request access permission for your seller .
1,318
public static int convertDPItoPixels ( Context context , int dpi ) { final float scale = context . getResources ( ) . getDisplayMetrics ( ) . density ; return ( int ) ( dpi * scale + 0.5f ) ; }
Convert a size in dp to a size in pixels
1,319
public Map < String , Object > authorize ( String paymentId , int amount , Setup setup ) { if ( setup . getEnvironment ( ) == SANDBOX_URL ) { this . requestMaker = new RequestMaker ( setup ) ; RequestProperties props = new RequestPropertiesBuilder ( ) . method ( "GET" ) . endpoint ( String . format ( "%s?payment_id=%s&amount=%s" , ENDPOINT_TO_AUTHORIZE , paymentId , amount ) ) . type ( Payments . class ) . contentType ( CONTENT_TYPE ) . build ( ) ; return this . requestMaker . doRequest ( props ) ; } else { ErrorBuilder error = new ErrorBuilder ( ) . code ( "404" ) . path ( "" ) . description ( "Wrong environment! Only payments created on Sandbox environment can be manually authorized." ) ; Errors errors = new Errors ( ) ; errors . setError ( error ) ; throw new ValidationException ( 404 , "Not Found" , errors ) ; } }
This method is used to simulate the payment authorization . To make it its necessary send the Moip payment external ID and the amount value .
1,320
public static Map < String , Object > payloadFactory ( Map . Entry < String , Object > ... entries ) { Map < String , Object > map = new HashMap < > ( ) ; for ( Map . Entry < String , Object > entry : entries ) map . put ( entry . getKey ( ) , entry . getValue ( ) ) ; return Collections . unmodifiableMap ( map ) ; }
This method was created to simplify the construction of request payloads . However the use of this method shouldn t be compulsory and you can also use plain old Maps .
1,321
public boolean clickOnTool ( String id ) { ExtJsComponent toolElement = getToolElement ( id ) . setVisibility ( true ) ; return toolElement . click ( ) ; }
click on element with class x - tool - + id
1,322
private static void proposeSolutions ( String [ ] dataSet , int k , int startPosition , String [ ] result , WebLocator webLocator ) throws SolutionFoundException { if ( k == 0 ) { validateSolution ( webLocator , differences ( dataSet , result ) ) ; return ; } for ( int i = startPosition ; i <= dataSet . length - k ; i ++ ) { result [ result . length - k ] = dataSet [ i ] ; proposeSolutions ( dataSet , k - 1 , i + 1 , result , webLocator ) ; } }
Generates combinations of all objects from the dataSet taken k at a time . Each combination is a possible solution that must be validated .
1,323
private static void validateSolution ( WebLocator webLocator , String [ ] differences ) throws SolutionFoundException { StringBuilder sb = new StringBuilder ( ) ; Map < String , Object > backup = new HashMap < > ( ) ; XPathBuilder builder = webLocator . getPathBuilder ( ) ; for ( String fieldName : differences ) { try { Field field = XPathBuilder . class . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; Object fieldValue = field . get ( builder ) ; switch ( fieldName ) { case "root" : field . set ( builder , "//" ) ; break ; case "tag" : field . set ( builder , "*" ) ; break ; case "visibility" : field . set ( builder , false ) ; break ; case "labelTag" : field . set ( builder , "label" ) ; break ; case "labelPosition" : field . set ( builder , WebLocatorConfig . getDefaultLabelPosition ( ) ) ; break ; case "position" : field . set ( builder , - 1 ) ; break ; case "resultIdx" : field . set ( builder , - 1 ) ; break ; default : field . set ( builder , null ) ; } backup . put ( fieldName , fieldValue ) ; sb . append ( String . format ( "set%s(\"%s\") and " , capitalize ( fieldName ) , fieldValue ) ) ; } catch ( IllegalAccessException | NoSuchFieldException e ) { e . printStackTrace ( ) ; } } int matches = webLocator . size ( ) ; if ( matches > 0 ) { if ( sb . lastIndexOf ( "and" ) > 0 ) { sb . replace ( sb . lastIndexOf ( "and" ) , sb . length ( ) , "" ) ; } LOGGER . warn ( "Found {} matches by removing {}: \n{}" , matches , sb . toString ( ) , getMatchedElementsHtml ( webLocator ) ) ; throw new SolutionFoundException ( ) ; } for ( String fieldName : differences ) { try { Field field = XPathBuilder . class . getDeclaredField ( fieldName ) ; field . setAccessible ( true ) ; field . set ( builder , backup . get ( fieldName ) ) ; } catch ( IllegalAccessException | NoSuchFieldException e ) { e . printStackTrace ( ) ; } } }
Nullifies all fields of the builder that are not part of the proposed solution and validates the new xPath .
1,324
private static String [ ] differences ( String [ ] first , String [ ] second ) { String [ ] sortedFirst = Arrays . copyOf ( first , first . length ) ; String [ ] sortedSecond = Arrays . copyOf ( second , second . length ) ; Arrays . sort ( sortedFirst ) ; Arrays . sort ( sortedSecond ) ; int firstIndex = 0 ; int secondIndex = 0 ; LinkedList < String > diffs = new LinkedList < > ( ) ; while ( firstIndex < sortedFirst . length && secondIndex < sortedSecond . length ) { int compare = ( int ) Math . signum ( sortedFirst [ firstIndex ] . compareTo ( sortedSecond [ secondIndex ] ) ) ; switch ( compare ) { case - 1 : diffs . add ( sortedFirst [ firstIndex ] ) ; firstIndex ++ ; break ; case 1 : diffs . add ( sortedSecond [ secondIndex ] ) ; secondIndex ++ ; break ; default : firstIndex ++ ; secondIndex ++ ; } } String [ ] strDups = new String [ diffs . size ( ) ] ; return diffs . toArray ( strDups ) ; }
Returns an array that contains all differences between first and second .
1,325
protected String getBasePathSelector ( ) { List < String > selector = new ArrayList < > ( ) ; CollectionUtils . addIgnoreNull ( selector , getBasePath ( ) ) ; if ( ! WebDriverConfig . isIE ( ) ) { if ( hasStyle ( ) ) { selector . add ( applyTemplate ( "style" , getStyle ( ) ) ) ; } if ( isVisibility ( ) ) { CollectionUtils . addIgnoreNull ( selector , applyTemplate ( "visibility" , isVisibility ( ) ) ) ; } } return selector . isEmpty ( ) ? "" : String . join ( " and " , selector ) ; }
Containing baseCls class name and style
1,326
protected String getItemPath ( boolean disabled ) { String selector = getBaseItemPath ( ) ; String subPath = applyTemplateValue ( disabled ? "disabled" : "enabled" ) ; if ( subPath != null ) { selector += ! Strings . isNullOrEmpty ( selector ) ? " and " + subPath : subPath ; } Map < String , String [ ] > templatesValues = getTemplatesValues ( ) ; String [ ] tagAndPositions = templatesValues . get ( "tagAndPosition" ) ; List < String > tagAndPosition = new ArrayList < > ( ) ; if ( tagAndPositions != null ) { tagAndPosition . addAll ( Arrays . asList ( tagAndPositions ) ) ; tagAndPosition . add ( 0 , getTag ( ) ) ; } String tag ; if ( ! tagAndPosition . isEmpty ( ) ) { tag = applyTemplate ( "tagAndPosition" , tagAndPosition . toArray ( ) ) ; } else { tag = getTag ( ) ; } selector = getRoot ( ) + tag + ( ! Strings . isNullOrEmpty ( selector ) ? "[" + selector + "]" : "" ) ; return selector ; }
this method is meant to be overridden by each component
1,327
public boolean clickWithExtJS ( ) { String id = getAttributeId ( ) ; if ( hasId ( id ) ) { String script = "return (function(){var b = Ext.getCmp('" + id + "'); if(b) {b.onClick({preventDefault:function(){},button:0}); return true;} return false;})()" ; Object object = WebLocatorUtils . doExecuteScript ( script ) ; LOGGER . info ( "clickWithExtJS on {}; result: {}" , toString ( ) , object ) ; return ( Boolean ) object ; } LOGGER . debug ( "id is: " + id ) ; return false ; }
TO Be used in extreme cases when simple . click is not working
1,328
public ExtjsConditionManager addFailConditions ( String ... messages ) { for ( String message : messages ) { if ( message != null && message . length ( ) > 0 ) { this . add ( new MessageBoxFailCondition ( message ) ) ; } } return this ; }
add each message to MessageBoxFailCondition
1,329
public ExtjsConditionManager addSuccessConditions ( String ... messages ) { for ( String message : messages ) { if ( message != null && message . length ( ) > 0 ) { this . add ( new MessageBoxSuccessCondition ( message ) ) ; } } return this ; }
add each message to MessageBoxSuccessCondition
1,330
protected String getAttrId ( ) { String id = getAttributeId ( ) ; assertThat ( MessageFormat . format ( "{0} id is null. The path is: {1}" , getPathBuilder ( ) . getClassName ( ) , getXPath ( ) ) , id , notNullValue ( ) ) ; return id ; }
Will Fail if id is null
1,331
public boolean isCellPresent ( String searchElement , int columnId , SearchType ... searchTypes ) { ready ( ) ; GridCell cell = new GridCell ( columnId , searchElement , searchTypes ) . setContainer ( this ) ; boolean selected ; do { selected = cell . isElementPresent ( ) ; } while ( ! selected && scrollPageDown ( ) ) ; return selected ; }
Scroll Page Down to find the cell . If you found it return true if not return false .
1,332
public boolean isRowPresent ( String searchElement ) { ready ( ) ; boolean found ; GridCell cell = getCell ( searchElement ) ; found = cell . isElementPresent ( ) ; return found ; }
returns if a grid contains a certain element
1,333
public String [ ] getRow ( String searchText ) { String [ ] rowElements = null ; GridRow row = new GridRow ( this , searchText , getSearchColumnId ( ) , SearchType . CONTAINS ) ; String text = row . getText ( ) ; if ( text != null ) { rowElements = text . split ( "\n" ) ; } return rowElements ; }
returns all text elements from a grid
1,334
public boolean checkboxColumnSelect ( String searchText ) { boolean selected = false ; if ( ready ( true ) ) { String path ; int rowIndex = getRowIndex ( searchText ) ; if ( rowIndex != - 1 ) { path = getRow ( rowIndex ) . getXPath ( ) + "//div[contains(@class,'x-grid3-check-col')]" ; WebLocator element = new WebLocator ( ) . setElPath ( path ) ; if ( element . ready ( ) ) { WebLocator locator = new WebLocator ( this ) . setElPath ( "//*[contains(@class,'x-grid3-focus')]" ) ; locator . sendKeys ( Keys . TAB ) ; selected = isCheckBoxColumnSelected ( searchText ) || element . click ( ) ; LOGGER . info ( "Clicking on checkboxColumnSelect corresponding to line : " + searchText ) ; } else { LOGGER . warn ( "Could not click on checkboxColumnSelect corresponding to line : " + searchText + "; path = " + path ) ; return false ; } } } else { LOGGER . warn ( "checkboxColumnSelect: grid is not ready for use: " + toString ( ) ) ; selected = false ; } return selected ; }
clicks in the checkbox found at the beginning of the grid which contains a specific element
1,335
private boolean setValueWithJs ( final String componentId , final String value ) { boolean selected ; String script = "return (function(){var c = Ext.getCmp('" + componentId + "'); var record = c.findRecord(c.displayField, '" + value + "');" + "if(record){c.onSelect(record, c.store.indexOf(record)); return true;} return false;})()" ; log . warn ( "force ComboBox Value with js: " + script ) ; selected = ( Boolean ) WebLocatorUtils . doExecuteScript ( script ) ; log . warn ( "force ComboBox select result: " + selected ) ; return selected ; }
this method is used in case normal flow for selection fails
1,336
public boolean waitToActivate ( int seconds ) { String info = toString ( ) ; int count = 0 ; boolean hasMask ; while ( ( hasMask = hasMask ( ) ) && ( count < seconds ) ) { count ++ ; LOGGER . info ( "waitToActivate:" + ( seconds - count ) + " seconds; " + info ) ; Utils . sleep ( 1000 ) ; } return ! hasMask ; }
Wait for the element to be activated when there is deactivation mask on top of it
1,337
public Long getLastAclChangeSetID ( ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "[getLastAclChangeSetID]" ) ; } return ( Long ) template . selectOne ( SELECT_LAST_ACL_CHANGE_SET_ID ) ; }
Get the last acl change set id from database
1,338
public Long getLastTransactionID ( ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "[getLastTransactionID]" ) ; } return ( Long ) template . selectOne ( SELECT_LAST_TRANSACTION_ID ) ; }
Get the last transaction id from database
1,339
private List < NodeEntity > filterNodes ( List < NodeEntity > nodes ) { List < NodeEntity > filteredNodes = null ; Map < String , Boolean > filters = getFilters ( ) ; if ( filters . values ( ) . contains ( Boolean . TRUE ) ) { filteredNodes = new ArrayList < NodeEntity > ( ) ; for ( NodeEntity node : nodes ) { boolean shouldBeAdded = true ; NodeRef nodeRef = new NodeRef ( node . getStore ( ) . getStoreRef ( ) , node . getUuid ( ) ) ; String nodeType = "{" + node . getTypeNamespace ( ) + "}" + node . getTypeName ( ) ; if ( nodeService . exists ( nodeRef ) ) { if ( filters . get ( SITES_FILTER ) ) { Path pathObj = nodeService . getPath ( nodeRef ) ; String siteName = Utils . getSiteName ( pathObj ) ; shouldBeAdded = siteName != null && this . sites . contains ( siteName ) ; } if ( filters . get ( PROPERTIES_FILTER ) && shouldBeAdded ) { for ( String prop : this . properties ) { int pos = prop . lastIndexOf ( ":" ) ; String qName = null ; String value = null ; if ( pos != - 1 && ( prop . length ( ) - 1 ) > pos ) { qName = prop . substring ( 0 , pos ) ; value = prop . substring ( pos + 1 , prop . length ( ) ) ; } if ( StringUtils . isEmpty ( qName ) || StringUtils . isEmpty ( value ) ) { continue ; } Serializable rawValue = nodeService . getProperty ( nodeRef , QName . createQName ( qName ) ) ; shouldBeAdded = shouldBeAdded && value . equals ( rawValue ) ; } } } else if ( nodeType . equals ( ContentModel . TYPE_DELETED . toString ( ) ) ) { shouldBeAdded = Boolean . TRUE ; } if ( shouldBeAdded ) { filteredNodes . add ( node ) ; } } } else { filteredNodes = nodes ; } return filteredNodes ; }
Filter the nodes based on some parameters
1,340
private Map < String , Boolean > getFilters ( ) { Map < String , Boolean > filters = new HashMap < String , Boolean > ( 2 ) ; filters . put ( SITES_FILTER , this . sites != null && this . sites . size ( ) > 0 ) ; filters . put ( PROPERTIES_FILTER , this . properties != null && this . properties . size ( ) > 0 ) ; return filters ; }
Get existing filters
1,341
public boolean isRowPresent ( String searchElement ) { ready ( ) ; Cell cell = getCell ( searchElement ) ; return cell . isElementPresent ( ) ; }
returns if a table contains a certain element
1,342
public String [ ] getColumnTexts ( int columnIndex ) { int count = getCount ( ) ; if ( count > 0 ) { String [ ] texts = new String [ count ] ; for ( int i = 1 ; i <= count ; i ++ ) { texts [ i - 1 ] = getText ( i , columnIndex ) ; } return texts ; } else { return null ; } }
get all strings as array from specified columnIndex
1,343
public static WebDriver getWebDriver ( String browserProperties , URL remoteUrl ) throws IOException { URL resource = Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( browserProperties ) ; log . debug ( "File: {} " + ( resource != null ? "exists" : "does not exist" ) , browserProperties ) ; if ( resource != null ) { Browser browser = findBrowser ( resource . openStream ( ) ) ; return getDriver ( browser , resource . openStream ( ) , remoteUrl ) ; } return null ; }
Create and return new WebDriver or RemoteWebDriver based on properties file
1,344
public static String switchToLastTab ( ) { int totalTabs ; int time = 0 ; do { Utils . sleep ( 100L ) ; totalTabs = getCountTabs ( ) ; time ++ ; } while ( totalTabs <= 1 && time < 10 ) ; return switchToTab ( totalTabs - 1 ) ; }
Switch driver to last browser tab
1,345
public boolean click ( ) { boolean click = waitToRender ( ) ; assertThat ( "Element was not rendered " + toString ( ) , click ) ; click = executor . click ( this ) ; assertThat ( "Could not click " + toString ( ) , click ) ; LOGGER . info ( "click on {}" , toString ( ) ) ; return click ; }
Click once do you catch exceptions StaleElementReferenceException .
1,346
public WebLocator focus ( ) { boolean focus = waitToRender ( ) ; assertThat ( "Element was not rendered " + toString ( ) , focus ) ; focus = executor . focus ( this ) ; assertThat ( "Could not focus " + toString ( ) , focus ) ; LOGGER . info ( "focus on {}" , toString ( ) ) ; return this ; }
Using XPath only
1,347
public String waitTextToRender ( int seconds , String excludeText ) { String text = null ; if ( seconds == 0 && ( ( text = getText ( true ) ) != null && text . length ( ) > 0 && ! text . equals ( excludeText ) ) ) { return text ; } for ( int i = 0 , count = 5 * seconds ; i < count ; i ++ ) { text = getText ( true ) ; if ( text != null && text . length ( ) > 0 && ! text . equals ( excludeText ) ) { return text ; } if ( i == 0 ) { LOGGER . debug ( "waitTextToRender" ) ; } Utils . sleep ( 200 ) ; } LOGGER . warn ( "No text was found for Element after " + seconds + " sec; " + this ) ; return excludeText . equals ( text ) ? null : text ; }
Waits for the text to be loaded by looking at the content and not take in consideration the excludeText text or what ever text is given as parameter
1,348
public boolean setActive ( ) { String baseTabPath = "//*[" + getPathBuilder ( ) . getBasePath ( ) + "]" ; String titlePath = baseTabPath + getTitlePath ( ) ; WebLocator titleElement = new WebLocator ( getPathBuilder ( ) . getContainer ( ) ) . setElPath ( titlePath ) . setInfoMessage ( getPathBuilder ( ) . getText ( ) + " Tab" ) ; LOGGER . info ( "setActive : " + toString ( ) ) ; boolean activated ; try { activated = titleElement . click ( ) ; } catch ( ElementNotVisibleException e ) { LOGGER . error ( "setActive Exception: " + e . getMessage ( ) ) ; activated = setActiveWithExtJS ( ) ; } if ( activated ) { Utils . sleep ( 300 ) ; } return activated ; }
After the tab is set to active will wait 300ms to make sure tab is rendered
1,349
public String getString ( String str , String tokenSecret , String consumerSecret ) throws InvalidKeyException , NoSuchAlgorithmException { return getString ( str , OAuthParams . HMAC_SHA1 , tokenSecret , consumerSecret ) ; }
produce an encoded signature string
1,350
private void resizeWindowIfNecessary ( int newSize ) { try { int numberOfLinesToLoad = newSize - this . lineQueue . size ( ) ; for ( int i = 0 ; i < numberOfLinesToLoad ; i ++ ) { String nextLine = getNextLine ( ) ; if ( nextLine != null ) { lineQueue . addLast ( nextLine ) ; } else { throw new IndexOutOfBoundsException ( "End of stream has been reached!" ) ; } } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Resizes the sliding window to the given size if necessary .
1,351
private String cutAfterTab ( String line ) { Pattern p = Pattern . compile ( "^(.*)\\t.*$" ) ; Matcher matcher = p . matcher ( line ) ; if ( matcher . matches ( ) ) { return matcher . group ( 1 ) ; } else { return line ; } }
Cuts a TAB and all following characters from a String .
1,352
private void validateValues ( String column , long value , boolean allowZero ) { if ( value < 0 || ( value == 0 && ! allowZero ) ) { throw new GeoPackageException ( column + " value must be greater than " + ( allowZero ? "or equal to " : "" ) + "0: " + value ) ; } }
Validate the long values are greater than 0 or greater than or equal to 0 based upon the allowZero flag
1,353
public static List < String > parseSQLStatements ( String path , String name ) { return parseSQLStatements ( "/" + path + "/" + name ) ; }
Parse the SQL statements for the base resource path and sql file name
1,354
public static List < String > parseSQLStatements ( String resourceName ) { InputStream stream = ResourceIOUtils . class . getResourceAsStream ( resourceName ) ; if ( stream == null ) { throw new GeoPackageException ( "Failed to find resource: " + resourceName ) ; } List < String > statements = parseSQLStatements ( stream ) ; return statements ; }
Parse the SQL statements for the resource name
1,355
public static List < String > parseSQLStatements ( final InputStream stream ) { List < String > statements = new ArrayList < > ( ) ; Scanner s = new Scanner ( stream ) ; try { s . useDelimiter ( Pattern . compile ( "\\n\\s*\\n" ) ) ; while ( s . hasNext ( ) ) { String statement = s . next ( ) . trim ( ) ; statements . add ( statement ) ; } } finally { s . close ( ) ; } return statements ; }
Parse the SQL statements for the input stream
1,356
public ContentsId get ( String tableName ) { ContentsId contentsId = null ; try { if ( contentsIdDao . isTableExists ( ) ) { contentsId = contentsIdDao . queryForTableName ( tableName ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query contents id for GeoPackage: " + geoPackage . getName ( ) + ", Table Name: " + tableName , e ) ; } return contentsId ; }
Get the contents id object
1,357
public Long getId ( String tableName ) { Long id = null ; ContentsId contentsId = get ( tableName ) ; if ( contentsId != null ) { id = contentsId . getId ( ) ; } return id ; }
Get the contents id
1,358
public ContentsId create ( String tableName ) { if ( ! has ( ) ) { getOrCreateExtension ( ) ; } ContentsId contentsId = new ContentsId ( ) ; Contents contents = geoPackage . getTableContents ( tableName ) ; contentsId . setContents ( contents ) ; try { contentsIdDao . create ( contentsId ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to create contents id for GeoPackage: " + geoPackage . getName ( ) + ", Table Name: " + tableName , e ) ; } return contentsId ; }
Create a contents id
1,359
public ContentsId getOrCreate ( String tableName ) { ContentsId contentsId = get ( tableName ) ; if ( contentsId == null ) { contentsId = create ( tableName ) ; } return contentsId ; }
Get or create a contents id
1,360
public boolean delete ( String tableName ) { boolean deleted = false ; try { if ( contentsIdDao . isTableExists ( ) ) { deleted = contentsIdDao . deleteByTableName ( tableName ) > 0 ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete Contents Id extension table. GeoPackage: " + geoPackage . getName ( ) + ", Table Name: " + tableName , e ) ; } return deleted ; }
Delete the contents id for the table
1,361
public int createIds ( String type ) { List < String > tables = getMissing ( type ) ; for ( String tableName : tables ) { getOrCreate ( tableName ) ; } return tables . size ( ) ; }
Create contents ids for contents of the data type and currently without
1,362
public int deleteIds ( ) { int deleted = 0 ; try { if ( contentsIdDao . isTableExists ( ) ) { deleted = contentsIdDao . delete ( contentsIdDao . deleteBuilder ( ) . prepare ( ) ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete all contents ids. GeoPackage: " + geoPackage . getName ( ) , e ) ; } return deleted ; }
Delete all contents ids
1,363
public int deleteIds ( String type ) { int deleted = 0 ; try { if ( contentsIdDao . isTableExists ( ) ) { List < ContentsId > contentsIds = getIds ( type ) ; deleted = contentsIdDao . delete ( contentsIds ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete contents ids by type. GeoPackage: " + geoPackage . getName ( ) + ", Type: " + type , e ) ; } return deleted ; }
Delete contents ids for contents of the data type
1,364
public List < ContentsId > getIds ( ) { List < ContentsId > contentsIds = null ; try { if ( contentsIdDao . isTableExists ( ) ) { contentsIds = contentsIdDao . queryForAll ( ) ; } else { contentsIds = new ArrayList < > ( ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for all contents ids. GeoPackage: " + geoPackage . getName ( ) , e ) ; } return contentsIds ; }
Get all contents ids
1,365
public long count ( ) { long count = 0 ; if ( has ( ) ) { try { count = contentsIdDao . countOf ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to count contents ids. GeoPackage: " + geoPackage . getName ( ) , e ) ; } } return count ; }
Get the count of contents ids
1,366
public List < ContentsId > getIds ( String type ) { List < ContentsId > contentsIds = null ; ContentsDao contentsDao = geoPackage . getContentsDao ( ) ; try { if ( contentsIdDao . isTableExists ( ) ) { QueryBuilder < Contents , String > contentsQueryBuilder = contentsDao . queryBuilder ( ) ; QueryBuilder < ContentsId , Long > contentsIdQueryBuilder = contentsIdDao . queryBuilder ( ) ; contentsQueryBuilder . where ( ) . eq ( Contents . COLUMN_DATA_TYPE , type ) ; contentsIdQueryBuilder . join ( contentsQueryBuilder ) ; contentsIds = contentsIdQueryBuilder . query ( ) ; } else { contentsIds = new ArrayList < > ( ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for contents id by contents data type. GeoPackage: " + geoPackage . getName ( ) + ", Type: " + type , e ) ; } return contentsIds ; }
Get by contents data type
1,367
public List < String > getMissing ( String type ) { List < String > missing = new ArrayList < > ( ) ; ContentsDao contentsDao = geoPackage . getContentsDao ( ) ; GenericRawResults < String [ ] > results = null ; try { StringBuilder query = new StringBuilder ( ) ; query . append ( "SELECT " ) ; query . append ( Contents . COLUMN_TABLE_NAME ) ; query . append ( " FROM " ) ; query . append ( Contents . TABLE_NAME ) ; StringBuilder where = new StringBuilder ( ) ; String [ ] queryArgs ; if ( type != null && ! type . isEmpty ( ) ) { where . append ( Contents . COLUMN_DATA_TYPE ) ; where . append ( " = ?" ) ; queryArgs = new String [ ] { type } ; } else { queryArgs = new String [ ] { } ; type = null ; } if ( contentsIdDao . isTableExists ( ) ) { if ( where . length ( ) > 0 ) { where . append ( " AND " ) ; } where . append ( Contents . COLUMN_TABLE_NAME ) ; where . append ( " NOT IN (SELECT " ) ; where . append ( ContentsId . COLUMN_TABLE_NAME ) ; where . append ( " FROM " ) ; where . append ( ContentsId . TABLE_NAME ) ; where . append ( ")" ) ; } if ( where . length ( ) > 0 ) { query . append ( " WHERE " ) . append ( where ) ; } results = contentsDao . queryRaw ( query . toString ( ) , queryArgs ) ; for ( String [ ] resultRow : results ) { missing . add ( resultRow [ 0 ] ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for missing contents ids. GeoPackage: " + geoPackage . getName ( ) + ", Type: " + type , e ) ; } finally { if ( results != null ) { try { results . close ( ) ; } catch ( IOException e ) { logger . log ( Level . WARNING , "Failed to close generic raw results from missing contents ids query. type: " + type , e ) ; } } } return missing ; }
Get contents by data type without contents ids
1,368
public Extensions getOrCreateExtension ( ) { geoPackage . createContentsIdTable ( ) ; Extensions extension = getOrCreate ( EXTENSION_NAME , null , null , EXTENSION_DEFINITION , ExtensionScopeType . READ_WRITE ) ; return extension ; }
Get or create if needed the extension
1,369
public Projection getProjection ( ) { String authority = getOrganization ( ) ; long code = getOrganizationCoordsysId ( ) ; String definition = getDefinition_12_063 ( ) ; if ( definition == null ) { definition = getDefinition ( ) ; } Projection projection = ProjectionFactory . getProjection ( authority , code , null , definition ) ; return projection ; }
Get the projection for the Spatial Reference System
1,370
public ProjectionTransform getTransformation ( Projection projection ) { Projection projectionTo = getProjection ( ) ; return projection . getTransformation ( projectionTo ) ; }
Get the projection transform from the provided projection to the Spatial Reference System projection
1,371
public GeometryIndex populate ( TableIndex tableIndex , long geomId , GeometryEnvelope envelope ) { GeometryIndex geometryIndex = new GeometryIndex ( ) ; geometryIndex . setTableIndex ( tableIndex ) ; geometryIndex . setGeomId ( geomId ) ; geometryIndex . setMinX ( envelope . getMinX ( ) ) ; geometryIndex . setMaxX ( envelope . getMaxX ( ) ) ; geometryIndex . setMinY ( envelope . getMinY ( ) ) ; geometryIndex . setMaxY ( envelope . getMaxY ( ) ) ; if ( envelope . hasZ ( ) ) { geometryIndex . setMinZ ( envelope . getMinZ ( ) ) ; geometryIndex . setMaxZ ( envelope . getMaxZ ( ) ) ; } if ( envelope . hasM ( ) ) { geometryIndex . setMinM ( envelope . getMinM ( ) ) ; geometryIndex . setMaxM ( envelope . getMaxM ( ) ) ; } return geometryIndex ; }
Populate a new geometry index from an envelope
1,372
public int deleteAll ( ) throws SQLException { int count = 0 ; if ( isTableExists ( ) ) { DeleteBuilder < GeometryIndex , GeometryIndexKey > db = deleteBuilder ( ) ; PreparedDelete < GeometryIndex > deleteQuery = db . prepare ( ) ; count = delete ( deleteQuery ) ; } return count ; }
Delete all geometry indices
1,373
public static boolean hasColumn ( UserTable < ? > table , DublinCoreType type ) { boolean hasColumn = table . hasColumn ( type . getName ( ) ) ; if ( ! hasColumn ) { for ( String synonym : type . getSynonyms ( ) ) { hasColumn = table . hasColumn ( synonym ) ; if ( hasColumn ) { break ; } } } return hasColumn ; }
Check if the table has a column for the Dublin Core Type term
1,374
public static < T extends UserColumn > T getColumn ( UserTable < T > table , DublinCoreType type ) { T column = null ; if ( table . hasColumn ( type . getName ( ) ) ) { column = table . getColumn ( type . getName ( ) ) ; } else { for ( String synonym : type . getSynonyms ( ) ) { if ( table . hasColumn ( synonym ) ) { column = table . getColumn ( synonym ) ; break ; } } } return column ; }
Get the column from the table for the Dublin Core Type term
1,375
public static < T extends UserColumn > T getColumn ( UserCoreRow < T , ? > row , DublinCoreType type ) { return getColumn ( row . getTable ( ) , type ) ; }
Get the column from the row for the Dublin Core Type term
1,376
public static Object getValue ( UserCoreRow < ? , ? > row , DublinCoreType type ) { UserColumn column = getColumn ( row , type ) ; Object value = row . getValue ( column . getIndex ( ) ) ; return value ; }
Get the value from the row for the Dublin Core Type term
1,377
public BoundingBox overlap ( BoundingBox projectedCoverage ) { BoundingBox overlap = null ; if ( point ) { overlap = projectedBoundingBox ; } else { overlap = projectedBoundingBox . overlap ( projectedCoverage ) ; } return overlap ; }
Get the bounding box overlap between the projected bounding box and the coverage data bounding box
1,378
public void link ( String featureTable , String tileTable ) { if ( ! isLinked ( featureTable , tileTable ) ) { getOrCreateExtension ( ) ; try { if ( ! featureTileLinkDao . isTableExists ( ) ) { geoPackage . createFeatureTileLinkTable ( ) ; } FeatureTileLink link = new FeatureTileLink ( ) ; link . setFeatureTableName ( featureTable ) ; link . setTileTableName ( tileTable ) ; featureTileLinkDao . create ( link ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to create feature tile link for GeoPackage: " + geoPackage . getName ( ) + ", Feature Table: " + featureTable + ", Tile Table: " + tileTable , e ) ; } } }
Link a feature and tile table together . Does nothing if already linked .
1,379
public boolean isLinked ( String featureTable , String tileTable ) { FeatureTileLink link = getLink ( featureTable , tileTable ) ; return link != null ; }
Determine if the feature table is linked to the tile table
1,380
public FeatureTileLink getLink ( String featureTable , String tileTable ) { FeatureTileLink link = null ; if ( featureTileLinksActive ( ) ) { FeatureTileLinkKey id = new FeatureTileLinkKey ( featureTable , tileTable ) ; try { link = featureTileLinkDao . queryForId ( id ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to get feature tile link for GeoPackage: " + geoPackage . getName ( ) + ", Feature Table: " + featureTable + ", Tile Table: " + tileTable , e ) ; } } return link ; }
Get the feature and tile table link if it exists
1,381
public List < FeatureTileLink > queryForFeatureTable ( String featureTable ) { List < FeatureTileLink > links = null ; if ( featureTileLinksActive ( ) ) { links = featureTileLinkDao . queryForFeatureTableName ( featureTable ) ; } else { links = new ArrayList < FeatureTileLink > ( ) ; } return links ; }
Query for feature tile links by feature table
1,382
public List < FeatureTileLink > queryForTileTable ( String tileTable ) { List < FeatureTileLink > links = null ; if ( featureTileLinksActive ( ) ) { links = featureTileLinkDao . queryForTileTableName ( tileTable ) ; } else { links = new ArrayList < FeatureTileLink > ( ) ; } return links ; }
Query for feature tile links by tile table
1,383
public boolean deleteLink ( String featureTable , String tileTable ) { boolean deleted = false ; try { if ( featureTileLinkDao . isTableExists ( ) ) { FeatureTileLinkKey id = new FeatureTileLinkKey ( featureTable , tileTable ) ; deleted = featureTileLinkDao . deleteById ( id ) > 0 ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete feature tile link for GeoPackage: " + geoPackage . getName ( ) + ", Feature Table: " + featureTable + ", Tile Table: " + tileTable , e ) ; } return deleted ; }
Delete the feature tile table link
1,384
public int deleteLinks ( String table ) { int deleted = 0 ; try { if ( featureTileLinkDao . isTableExists ( ) ) { deleted = featureTileLinkDao . deleteByTableName ( table ) ; } } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to delete feature tile links for GeoPackage: " + geoPackage . getName ( ) + ", Table: " + table , e ) ; } return deleted ; }
Delete the feature tile table links for the feature or tile table
1,385
private boolean featureTileLinksActive ( ) { boolean active = false ; if ( has ( ) ) { try { active = featureTileLinkDao . isTableExists ( ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to check if the feature tile link table exists for GeoPackage: " + geoPackage . getName ( ) , e ) ; } } return active ; }
Determine if the feature tile link extension and table exists
1,386
public List < String > getTileTablesForFeatureTable ( String featureTable ) { List < String > tileTables = new ArrayList < String > ( ) ; List < FeatureTileLink > links = queryForFeatureTable ( featureTable ) ; for ( FeatureTileLink link : links ) { tileTables . add ( link . getTileTableName ( ) ) ; } return tileTables ; }
Query for the tile table names linked to a feature table
1,387
public List < String > getFeatureTablesForTileTable ( String tileTable ) { List < String > featureTables = new ArrayList < String > ( ) ; List < FeatureTileLink > links = queryForTileTable ( tileTable ) ; for ( FeatureTileLink link : links ) { featureTables . add ( link . getFeatureTableName ( ) ) ; } return featureTables ; }
Query for the feature table names linked to a tile table
1,388
public static String getFileExtension ( File file ) { String fileName = file . getName ( ) ; String extension = null ; int extensionIndex = fileName . lastIndexOf ( "." ) ; if ( extensionIndex > - 1 ) { extension = fileName . substring ( extensionIndex + 1 ) ; } return extension ; }
Get the file extension
1,389
public static File addFileExtension ( File file , String extension ) { return new File ( file . getAbsolutePath ( ) + "." + extension ) ; }
Add a the file extension to the file
1,390
public static String getFileNameWithoutExtension ( File file ) { String name = file . getName ( ) ; int extensionIndex = name . lastIndexOf ( "." ) ; if ( extensionIndex > - 1 ) { name = name . substring ( 0 , extensionIndex ) ; } return name ; }
Get the file name with the extension removed
1,391
public static void copyFile ( File copyFrom , File copyTo ) throws IOException { InputStream from = new FileInputStream ( copyFrom ) ; OutputStream to = new FileOutputStream ( copyTo ) ; copyStream ( from , to ) ; }
Copy a file to a file location
1,392
public static byte [ ] fileBytes ( File file ) throws IOException { FileInputStream fis = new FileInputStream ( file ) ; return streamBytes ( fis ) ; }
Get the file bytes
1,393
public static byte [ ] streamBytes ( InputStream stream ) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ; copyStream ( stream , bytes ) ; return bytes . toByteArray ( ) ; }
Get the stream bytes
1,394
public static String formatBytes ( long bytes ) { double value = bytes ; String unit = "B" ; if ( bytes >= 1024 ) { int exponent = ( int ) ( Math . log ( bytes ) / Math . log ( 1024 ) ) ; exponent = Math . min ( exponent , 4 ) ; switch ( exponent ) { case 1 : unit = "KB" ; break ; case 2 : unit = "MB" ; break ; case 3 : unit = "GB" ; break ; case 4 : unit = "TB" ; break ; } value = bytes / Math . pow ( 1024 , exponent ) ; } DecimalFormat df = new DecimalFormat ( "#.##" ) ; return df . format ( value ) + " " + unit ; }
Format the bytes into readable text
1,395
public List < FeatureTileLink > queryForFeatureTableName ( String featureTableName ) { List < FeatureTileLink > results = null ; try { results = queryForEq ( FeatureTileLink . COLUMN_FEATURE_TABLE_NAME , featureTableName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for Feature Tile Link objects by Feature Table Name: " + featureTableName ) ; } return results ; }
Query by feature table name
1,396
public List < FeatureTileLink > queryForTileTableName ( String tileTableName ) { List < FeatureTileLink > results = null ; try { results = queryForEq ( FeatureTileLink . COLUMN_TILE_TABLE_NAME , tileTableName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to query for Feature Tile Link objects by Tile Table Name: " + tileTableName ) ; } return results ; }
Query by tile table name
1,397
public int deleteByTableName ( String tableName ) throws SQLException { DeleteBuilder < FeatureTileLink , FeatureTileLinkKey > db = deleteBuilder ( ) ; db . where ( ) . eq ( FeatureTileLink . COLUMN_FEATURE_TABLE_NAME , tableName ) . or ( ) . eq ( FeatureTileLink . COLUMN_TILE_TABLE_NAME , tableName ) ; PreparedDelete < FeatureTileLink > deleteQuery = db . prepare ( ) ; int deleted = delete ( deleteQuery ) ; return deleted ; }
Delete by table name either feature or tile table name
1,398
public int deleteAll ( ) throws SQLException { int count = 0 ; if ( isTableExists ( ) ) { DeleteBuilder < FeatureTileLink , FeatureTileLinkKey > db = deleteBuilder ( ) ; PreparedDelete < FeatureTileLink > deleteQuery = db . prepare ( ) ; count = delete ( deleteQuery ) ; } return count ; }
Delete all feature tile links
1,399
private static List < UserCustomColumn > createColumns ( ) { List < UserCustomColumn > columns = new ArrayList < > ( ) ; columns . addAll ( createRequiredColumns ( ) ) ; int index = columns . size ( ) ; columns . add ( UserCustomColumn . createColumn ( index ++ , COLUMN_GEOMETRY_TYPE_NAME , GeoPackageDataType . TEXT , false , null ) ) ; return columns ; }
Create the style mapping columns