id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
155,800
pip-services3-java/pip-services3-commons-java
src/org/pipservices3/commons/reflect/ObjectReader.java
ObjectReader.hasProperty
@SuppressWarnings("unchecked") public static boolean hasProperty(Object obj, String name) { if (obj == null || name == null) { return false; } else if (obj instanceof Map<?, ?>) { Map<Object, Object> map = (Map<Object, Object>) obj; for (Object key : map.keySet()) { if (name.equalsIgnoreCase(key.toString())) return true; } return false; } else if (obj instanceof List<?>) { Integer index = IntegerConverter.toNullableInteger(name); List<Object> list = (List<Object>) obj; return index != null && index.intValue() >= 0 && index.intValue() < list.size(); } else if (obj.getClass().isArray()) { Integer index = IntegerConverter.toNullableInteger(name); int length = Array.getLength(obj); return index != null && index.intValue() >= 0 && index.intValue() < length; } else { return PropertyReflector.hasProperty(obj, name); } }
java
@SuppressWarnings("unchecked") public static boolean hasProperty(Object obj, String name) { if (obj == null || name == null) { return false; } else if (obj instanceof Map<?, ?>) { Map<Object, Object> map = (Map<Object, Object>) obj; for (Object key : map.keySet()) { if (name.equalsIgnoreCase(key.toString())) return true; } return false; } else if (obj instanceof List<?>) { Integer index = IntegerConverter.toNullableInteger(name); List<Object> list = (List<Object>) obj; return index != null && index.intValue() >= 0 && index.intValue() < list.size(); } else if (obj.getClass().isArray()) { Integer index = IntegerConverter.toNullableInteger(name); int length = Array.getLength(obj); return index != null && index.intValue() >= 0 && index.intValue() < length; } else { return PropertyReflector.hasProperty(obj, name); } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "boolean", "hasProperty", "(", "Object", "obj", ",", "String", "name", ")", "{", "if", "(", "obj", "==", "null", "||", "name", "==", "null", ")", "{", "return", "false", ";", "}", "else", "if", "(", "obj", "instanceof", "Map", "<", "?", ",", "?", ">", ")", "{", "Map", "<", "Object", ",", "Object", ">", "map", "=", "(", "Map", "<", "Object", ",", "Object", ">", ")", "obj", ";", "for", "(", "Object", "key", ":", "map", ".", "keySet", "(", ")", ")", "{", "if", "(", "name", ".", "equalsIgnoreCase", "(", "key", ".", "toString", "(", ")", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}", "else", "if", "(", "obj", "instanceof", "List", "<", "?", ">", ")", "{", "Integer", "index", "=", "IntegerConverter", ".", "toNullableInteger", "(", "name", ")", ";", "List", "<", "Object", ">", "list", "=", "(", "List", "<", "Object", ">", ")", "obj", ";", "return", "index", "!=", "null", "&&", "index", ".", "intValue", "(", ")", ">=", "0", "&&", "index", ".", "intValue", "(", ")", "<", "list", ".", "size", "(", ")", ";", "}", "else", "if", "(", "obj", ".", "getClass", "(", ")", ".", "isArray", "(", ")", ")", "{", "Integer", "index", "=", "IntegerConverter", ".", "toNullableInteger", "(", "name", ")", ";", "int", "length", "=", "Array", ".", "getLength", "(", "obj", ")", ";", "return", "index", "!=", "null", "&&", "index", ".", "intValue", "(", ")", ">=", "0", "&&", "index", ".", "intValue", "(", ")", "<", "length", ";", "}", "else", "{", "return", "PropertyReflector", ".", "hasProperty", "(", "obj", ",", "name", ")", ";", "}", "}" ]
Checks if object has a property with specified name. The object can be a user defined object, map or array. The property name correspondently must be object property, map key or array index. @param obj an object to introspect. @param name a name of the property to check. @return true if the object has the property and false if it doesn't.
[ "Checks", "if", "object", "has", "a", "property", "with", "specified", "name", "." ]
a8a0c3e5ec58f0663c295aa855c6b3afad2af86a
https://github.com/pip-services3-java/pip-services3-commons-java/blob/a8a0c3e5ec58f0663c295aa855c6b3afad2af86a/src/org/pipservices3/commons/reflect/ObjectReader.java#L71-L93
155,801
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.sendTextToNextAlert
public void sendTextToNextAlert(String text) { Alert alert = driver.switchTo().alert(); alert.sendKeys(text); alert.accept(); }
java
public void sendTextToNextAlert(String text) { Alert alert = driver.switchTo().alert(); alert.sendKeys(text); alert.accept(); }
[ "public", "void", "sendTextToNextAlert", "(", "String", "text", ")", "{", "Alert", "alert", "=", "driver", ".", "switchTo", "(", ")", ".", "alert", "(", ")", ";", "alert", ".", "sendKeys", "(", "text", ")", ";", "alert", ".", "accept", "(", ")", ";", "}" ]
Enters the specified text into the upcoming input alert. @param text the text to be entered
[ "Enters", "the", "specified", "text", "into", "the", "upcoming", "input", "alert", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L149-L154
155,802
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.authenticateOnNextAlert
public void authenticateOnNextAlert(String username, String password) { Credentials credentials = new UserAndPassword(username, password); Alert alert = driver.switchTo().alert(); alert.authenticateUsing(credentials); }
java
public void authenticateOnNextAlert(String username, String password) { Credentials credentials = new UserAndPassword(username, password); Alert alert = driver.switchTo().alert(); alert.authenticateUsing(credentials); }
[ "public", "void", "authenticateOnNextAlert", "(", "String", "username", ",", "String", "password", ")", "{", "Credentials", "credentials", "=", "new", "UserAndPassword", "(", "username", ",", "password", ")", ";", "Alert", "alert", "=", "driver", ".", "switchTo", "(", ")", ".", "alert", "(", ")", ";", "alert", ".", "authenticateUsing", "(", "credentials", ")", ";", "}" ]
Authenticates the user using the given username and password. This will work only if the credentials are requested through an alert window. @param username the user name @param password the password
[ "Authenticates", "the", "user", "using", "the", "given", "username", "and", "password", ".", "This", "will", "work", "only", "if", "the", "credentials", "are", "requested", "through", "an", "alert", "window", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L165-L170
155,803
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.takeScreenshot
public void takeScreenshot(String filename) throws IOException { File screenshot = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File(filename)); }
java
public void takeScreenshot(String filename) throws IOException { File screenshot = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File(filename)); }
[ "public", "void", "takeScreenshot", "(", "String", "filename", ")", "throws", "IOException", "{", "File", "screenshot", "=", "(", "(", "TakesScreenshot", ")", "driver", ")", ".", "getScreenshotAs", "(", "OutputType", ".", "FILE", ")", ";", "FileUtils", ".", "copyFile", "(", "screenshot", ",", "new", "File", "(", "filename", ")", ")", ";", "}" ]
Takes a screenshot of the current screen. @param filename the name of the file where the screenshot will be saved @throws IOException if something goes wrong while saving the screenshot
[ "Takes", "a", "screenshot", "of", "the", "current", "screen", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L187-L191
155,804
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.verifyCookiePresentByName
public boolean verifyCookiePresentByName(final String cookieName) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); return true; } } LOG.info("Cookie: " + cookieName + " NOT found!"); return false; }
java
public boolean verifyCookiePresentByName(final String cookieName) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); return true; } } LOG.info("Cookie: " + cookieName + " NOT found!"); return false; }
[ "public", "boolean", "verifyCookiePresentByName", "(", "final", "String", "cookieName", ")", "{", "Set", "<", "Cookie", ">", "cookies", "=", "driver", ".", "manage", "(", ")", ".", "getCookies", "(", ")", ";", "for", "(", "Cookie", "cookie", ":", "cookies", ")", "{", "if", "(", "cookie", ".", "getName", "(", ")", ".", "equals", "(", "cookieName", ")", ")", "{", "LOG", ".", "info", "(", "\"Cookie: \"", "+", "cookieName", "+", "\" was found with value: \"", "+", "cookie", ".", "getValue", "(", ")", ")", ";", "return", "true", ";", "}", "}", "LOG", ".", "info", "(", "\"Cookie: \"", "+", "cookieName", "+", "\" NOT found!\"", ")", ";", "return", "false", ";", "}" ]
Checks if the given cookie name exists in the current session. This method is also logging the result. The match is CASE SENSITIVE. @param cookieName the name of the cookie @return true if the cookie exists or false otherwise
[ "Checks", "if", "the", "given", "cookie", "name", "exists", "in", "the", "current", "session", ".", "This", "method", "is", "also", "logging", "the", "result", ".", "The", "match", "is", "CASE", "SENSITIVE", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L254-L267
155,805
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.verifyText
public boolean verifyText(final By by, final String text) { WebElement element = driver.findElement(by); if (element.getText().equals(text)) { LOG.info("Element: " + element + " contains the given text: " + text); return true; } LOG.info("Element: " + element + " does NOT contain the given text: " + text); return false; }
java
public boolean verifyText(final By by, final String text) { WebElement element = driver.findElement(by); if (element.getText().equals(text)) { LOG.info("Element: " + element + " contains the given text: " + text); return true; } LOG.info("Element: " + element + " does NOT contain the given text: " + text); return false; }
[ "public", "boolean", "verifyText", "(", "final", "By", "by", ",", "final", "String", "text", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "by", ")", ";", "if", "(", "element", ".", "getText", "(", ")", ".", "equals", "(", "text", ")", ")", "{", "LOG", ".", "info", "(", "\"Element: \"", "+", "element", "+", "\" contains the given text: \"", "+", "text", ")", ";", "return", "true", ";", "}", "LOG", ".", "info", "(", "\"Element: \"", "+", "element", "+", "\" does NOT contain the given text: \"", "+", "text", ")", ";", "return", "false", ";", "}" ]
Verifies that the given element contains the given text. @param by the method of identifying the element @param text the text to be matched @return true if the given element contains the given text or false otherwise
[ "Verifies", "that", "the", "given", "element", "contains", "the", "given", "text", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L308-L321
155,806
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.verifyChecked
public boolean verifyChecked(final By checkboxBy) { WebElement element = driver.findElement(checkboxBy); if (element.isSelected()) { LOG.info("Checkbox: " + element + " is checked!"); return true; } LOG.info("Checkbox: " + element + " is NOT checked!"); return false; }
java
public boolean verifyChecked(final By checkboxBy) { WebElement element = driver.findElement(checkboxBy); if (element.isSelected()) { LOG.info("Checkbox: " + element + " is checked!"); return true; } LOG.info("Checkbox: " + element + " is NOT checked!"); return false; }
[ "public", "boolean", "verifyChecked", "(", "final", "By", "checkboxBy", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "checkboxBy", ")", ";", "if", "(", "element", ".", "isSelected", "(", ")", ")", "{", "LOG", ".", "info", "(", "\"Checkbox: \"", "+", "element", "+", "\" is checked!\"", ")", ";", "return", "true", ";", "}", "LOG", ".", "info", "(", "\"Checkbox: \"", "+", "element", "+", "\" is NOT checked!\"", ")", ";", "return", "false", ";", "}" ]
Verifies that the given checkbox is checked. @param checkboxBy the method of identifying the checkbox @return true if the given checkbox is checked or false otherwise
[ "Verifies", "that", "the", "given", "checkbox", "is", "checked", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L330-L340
155,807
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.assertCookiePresentByName
public void assertCookiePresentByName(final String cookieName) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); Assert.assertEquals(cookieName, cookie.getName()); return; } } Assert.fail("The given cookie name: " + cookieName + " is not present within the current session!"); }
java
public void assertCookiePresentByName(final String cookieName) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); Assert.assertEquals(cookieName, cookie.getName()); return; } } Assert.fail("The given cookie name: " + cookieName + " is not present within the current session!"); }
[ "public", "void", "assertCookiePresentByName", "(", "final", "String", "cookieName", ")", "{", "Set", "<", "Cookie", ">", "cookies", "=", "driver", ".", "manage", "(", ")", ".", "getCookies", "(", ")", ";", "for", "(", "Cookie", "cookie", ":", "cookies", ")", "{", "if", "(", "cookie", ".", "getName", "(", ")", ".", "equals", "(", "cookieName", ")", ")", "{", "LOG", ".", "info", "(", "\"Cookie: \"", "+", "cookieName", "+", "\" was found with value: \"", "+", "cookie", ".", "getValue", "(", ")", ")", ";", "Assert", ".", "assertEquals", "(", "cookieName", ",", "cookie", ".", "getName", "(", ")", ")", ";", "return", ";", "}", "}", "Assert", ".", "fail", "(", "\"The given cookie name: \"", "+", "cookieName", "+", "\" is not present within the current session!\"", ")", ";", "}" ]
Checks if the given cookie name exists in the current session. This method is also logging the result. The match is CASE SENSITIVE. Please not that the method will do a JUNIT Assert causing the test to fail. @param cookieName the name of the cookie
[ "Checks", "if", "the", "given", "cookie", "name", "exists", "in", "the", "current", "session", ".", "This", "method", "is", "also", "logging", "the", "result", ".", "The", "match", "is", "CASE", "SENSITIVE", ".", "Please", "not", "that", "the", "method", "will", "do", "a", "JUNIT", "Assert", "causing", "the", "test", "to", "fail", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L351-L364
155,808
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.assertCookie
public void assertCookie(final String cookieName, final String cookieValue) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName) && cookie.getValue().equals(cookieValue)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); return; } } Assert.fail("Cookie: " + cookieName + " with value: " + cookieValue + " NOT found!"); }
java
public void assertCookie(final String cookieName, final String cookieValue) { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equals(cookieName) && cookie.getValue().equals(cookieValue)) { LOG.info("Cookie: " + cookieName + " was found with value: " + cookie.getValue()); return; } } Assert.fail("Cookie: " + cookieName + " with value: " + cookieValue + " NOT found!"); }
[ "public", "void", "assertCookie", "(", "final", "String", "cookieName", ",", "final", "String", "cookieValue", ")", "{", "Set", "<", "Cookie", ">", "cookies", "=", "driver", ".", "manage", "(", ")", ".", "getCookies", "(", ")", ";", "for", "(", "Cookie", "cookie", ":", "cookies", ")", "{", "if", "(", "cookie", ".", "getName", "(", ")", ".", "equals", "(", "cookieName", ")", "&&", "cookie", ".", "getValue", "(", ")", ".", "equals", "(", "cookieValue", ")", ")", "{", "LOG", ".", "info", "(", "\"Cookie: \"", "+", "cookieName", "+", "\" was found with value: \"", "+", "cookie", ".", "getValue", "(", ")", ")", ";", "return", ";", "}", "}", "Assert", ".", "fail", "(", "\"Cookie: \"", "+", "cookieName", "+", "\" with value: \"", "+", "cookieValue", "+", "\" NOT found!\"", ")", ";", "}" ]
Verifies that the given cookie name has the given cookie value. This method is also add logging info. Please not that the method will do a JUNIT Assert causing the test to fail. @param cookieName the cookie name @param cookieValue the cookie value
[ "Verifies", "that", "the", "given", "cookie", "name", "has", "the", "given", "cookie", "value", ".", "This", "method", "is", "also", "add", "logging", "info", ".", "Please", "not", "that", "the", "method", "will", "do", "a", "JUNIT", "Assert", "causing", "the", "test", "to", "fail", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L376-L391
155,809
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.assertText
public void assertText(final By by, final String text) { WebElement element = driver.findElement(by); Assert.assertEquals("Element: " + element + " does NOT contain the given text: " + text, text, element.getText()); }
java
public void assertText(final By by, final String text) { WebElement element = driver.findElement(by); Assert.assertEquals("Element: " + element + " does NOT contain the given text: " + text, text, element.getText()); }
[ "public", "void", "assertText", "(", "final", "By", "by", ",", "final", "String", "text", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "by", ")", ";", "Assert", ".", "assertEquals", "(", "\"Element: \"", "+", "element", "+", "\" does NOT contain the given text: \"", "+", "text", ",", "text", ",", "element", ".", "getText", "(", ")", ")", ";", "}" ]
Verifies that the given element contains the given text. Please not that the method will do a JUNIT Assert causing the test to fail. @param by the method of identifying the element @param text the text to be matched
[ "Verifies", "that", "the", "given", "element", "contains", "the", "given", "text", ".", "Please", "not", "that", "the", "method", "will", "do", "a", "JUNIT", "Assert", "causing", "the", "test", "to", "fail", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L402-L408
155,810
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.assertChecked
public void assertChecked(final By checkboxBy) { WebElement element = driver.findElement(checkboxBy); Assert.assertTrue("Checkbox: " + element + " is NOT checked!", element.isSelected()); }
java
public void assertChecked(final By checkboxBy) { WebElement element = driver.findElement(checkboxBy); Assert.assertTrue("Checkbox: " + element + " is NOT checked!", element.isSelected()); }
[ "public", "void", "assertChecked", "(", "final", "By", "checkboxBy", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "checkboxBy", ")", ";", "Assert", ".", "assertTrue", "(", "\"Checkbox: \"", "+", "element", "+", "\" is NOT checked!\"", ",", "element", ".", "isSelected", "(", ")", ")", ";", "}" ]
Verifies that the given checkbox is checked. Please not that the method will do a JUNIT Assert causing the test to fail. @param checkboxBy the method of identifying the checkbox
[ "Verifies", "that", "the", "given", "checkbox", "is", "checked", ".", "Please", "not", "that", "the", "method", "will", "do", "a", "JUNIT", "Assert", "causing", "the", "test", "to", "fail", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L418-L423
155,811
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.isElementPresent
public boolean isElementPresent(final By by) { try { driver.findElement(by); } catch (Exception e) { return false; } return true; }
java
public boolean isElementPresent(final By by) { try { driver.findElement(by); } catch (Exception e) { return false; } return true; }
[ "public", "boolean", "isElementPresent", "(", "final", "By", "by", ")", "{", "try", "{", "driver", ".", "findElement", "(", "by", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if the specified element is present into the page. @param by method of identifying the element @return true if the element is present or false otherwise
[ "Checks", "if", "the", "specified", "element", "is", "present", "into", "the", "page", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L432-L439
155,812
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.waitForElementPresent
public void waitForElementPresent(final By by, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.presenceOfElementLocated((by))); }
java
public void waitForElementPresent(final By by, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.presenceOfElementLocated((by))); }
[ "public", "void", "waitForElementPresent", "(", "final", "By", "by", ",", "final", "int", "maximumSeconds", ")", "{", "WebDriverWait", "wait", "=", "new", "WebDriverWait", "(", "driver", ",", "maximumSeconds", ")", ";", "wait", ".", "until", "(", "ExpectedConditions", ".", "presenceOfElementLocated", "(", "(", "by", ")", ")", ")", ";", "}" ]
Waits until an element will be displayed into the page. @param by the method of identifying the element @param maximumSeconds maximum number of methods to wait for the element to be present
[ "Waits", "until", "an", "element", "will", "be", "displayed", "into", "the", "page", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L470-L473
155,813
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.waitForTextPresentWithinPage
public void waitForTextPresentWithinPage(final String text, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.textToBePresentInElement( By.tagName("body"), text)); }
java
public void waitForTextPresentWithinPage(final String text, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.textToBePresentInElement( By.tagName("body"), text)); }
[ "public", "void", "waitForTextPresentWithinPage", "(", "final", "String", "text", ",", "final", "int", "maximumSeconds", ")", "{", "WebDriverWait", "wait", "=", "new", "WebDriverWait", "(", "driver", ",", "maximumSeconds", ")", ";", "wait", ".", "until", "(", "ExpectedConditions", ".", "textToBePresentInElement", "(", "By", ".", "tagName", "(", "\"body\"", ")", ",", "text", ")", ")", ";", "}" ]
Waits until a text will be displayed within the page. @param text text to wait for @param maximumSeconds maximum number of seconds to wait for the text to be present
[ "Waits", "until", "a", "text", "will", "be", "displayed", "within", "the", "page", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L483-L488
155,814
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.waitForElementToBeVisible
public void waitForElementToBeVisible(final By by, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(by)); }
java
public void waitForElementToBeVisible(final By by, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(by)); }
[ "public", "void", "waitForElementToBeVisible", "(", "final", "By", "by", ",", "final", "int", "maximumSeconds", ")", "{", "WebDriverWait", "wait", "=", "new", "WebDriverWait", "(", "driver", ",", "maximumSeconds", ")", ";", "wait", ".", "until", "(", "ExpectedConditions", ".", "visibilityOfElementLocated", "(", "by", ")", ")", ";", "}" ]
Waits until a WebElement will be displayed into the page. @param by the method of identifying the element @param maximumSeconds the maximum number of seconds to wait
[ "Waits", "until", "a", "WebElement", "will", "be", "displayed", "into", "the", "page", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L498-L501
155,815
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.waitForElementToContainText
public void waitForElementToContainText(final By by, final int maximumSeconds) { (new WebDriverWait(driver, maximumSeconds)) .until(new ExpectedCondition<Boolean>() { public Boolean apply(final WebDriver error1) { return !driver.findElement(by).getText().isEmpty(); } }); }
java
public void waitForElementToContainText(final By by, final int maximumSeconds) { (new WebDriverWait(driver, maximumSeconds)) .until(new ExpectedCondition<Boolean>() { public Boolean apply(final WebDriver error1) { return !driver.findElement(by).getText().isEmpty(); } }); }
[ "public", "void", "waitForElementToContainText", "(", "final", "By", "by", ",", "final", "int", "maximumSeconds", ")", "{", "(", "new", "WebDriverWait", "(", "driver", ",", "maximumSeconds", ")", ")", ".", "until", "(", "new", "ExpectedCondition", "<", "Boolean", ">", "(", ")", "{", "public", "Boolean", "apply", "(", "final", "WebDriver", "error1", ")", "{", "return", "!", "driver", ".", "findElement", "(", "by", ")", ".", "getText", "(", ")", ".", "isEmpty", "(", ")", ";", "}", "}", ")", ";", "}" ]
Waits for an element to contain some text. @param by the method of identifying the element @param maximumSeconds the maximum number of seconds to wait
[ "Waits", "for", "an", "element", "to", "contain", "some", "text", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L511-L519
155,816
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.waitForElementToContainSpecificText
public void waitForElementToContainSpecificText(final By by, final String text, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.textToBePresentInElement(by, text)); }
java
public void waitForElementToContainSpecificText(final By by, final String text, final int maximumSeconds) { WebDriverWait wait = new WebDriverWait(driver, maximumSeconds); wait.until(ExpectedConditions.textToBePresentInElement(by, text)); }
[ "public", "void", "waitForElementToContainSpecificText", "(", "final", "By", "by", ",", "final", "String", "text", ",", "final", "int", "maximumSeconds", ")", "{", "WebDriverWait", "wait", "=", "new", "WebDriverWait", "(", "driver", ",", "maximumSeconds", ")", ";", "wait", ".", "until", "(", "ExpectedConditions", ".", "textToBePresentInElement", "(", "by", ",", "text", ")", ")", ";", "}" ]
Waits until an element contains a specific text. @param by method of identifying the element @param text the element text to wait for @param maximumSeconds the maximum number of seconds to wait for
[ "Waits", "until", "an", "element", "contains", "a", "specific", "text", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L531-L535
155,817
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.isTextPresentInPage
public boolean isTextPresentInPage(final String text) { WebElement body = driver.findElement(By.tagName("body")); return body.getText().contains(text); }
java
public boolean isTextPresentInPage(final String text) { WebElement body = driver.findElement(By.tagName("body")); return body.getText().contains(text); }
[ "public", "boolean", "isTextPresentInPage", "(", "final", "String", "text", ")", "{", "WebElement", "body", "=", "driver", ".", "findElement", "(", "By", ".", "tagName", "(", "\"body\"", ")", ")", ";", "return", "body", ".", "getText", "(", ")", ".", "contains", "(", "text", ")", ";", "}" ]
Checks for presence of the text in a html page. @param text the text to be searched for @return true if the text is present within the page or false otherwise
[ "Checks", "for", "presence", "of", "the", "text", "in", "a", "html", "page", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L544-L547
155,818
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.selectOptionFromDropdownByValue
public void selectOptionFromDropdownByValue(final By by, final String value) { Select select = new Select(driver.findElement(by)); select.selectByValue(value); }
java
public void selectOptionFromDropdownByValue(final By by, final String value) { Select select = new Select(driver.findElement(by)); select.selectByValue(value); }
[ "public", "void", "selectOptionFromDropdownByValue", "(", "final", "By", "by", ",", "final", "String", "value", ")", "{", "Select", "select", "=", "new", "Select", "(", "driver", ".", "findElement", "(", "by", ")", ")", ";", "select", ".", "selectByValue", "(", "value", ")", ";", "}" ]
Select a value from a drop down list based on the actual value, NOT DISPLAYED TEXT. @param by the method of identifying the drop-down @param value the value to select
[ "Select", "a", "value", "from", "a", "drop", "down", "list", "based", "on", "the", "actual", "value", "NOT", "DISPLAYED", "TEXT", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L605-L608
155,819
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.selectOptionFromDropdownByDisplayText
public void selectOptionFromDropdownByDisplayText(final By by, final String displayText) { Select select = new Select(driver.findElement(by)); select.selectByVisibleText(displayText); }
java
public void selectOptionFromDropdownByDisplayText(final By by, final String displayText) { Select select = new Select(driver.findElement(by)); select.selectByVisibleText(displayText); }
[ "public", "void", "selectOptionFromDropdownByDisplayText", "(", "final", "By", "by", ",", "final", "String", "displayText", ")", "{", "Select", "select", "=", "new", "Select", "(", "driver", ".", "findElement", "(", "by", ")", ")", ";", "select", ".", "selectByVisibleText", "(", "displayText", ")", ";", "}" ]
Select text from a drop down list based on the displayed text. @param by the method of identifying the drop-down @param displayText the text based on which the value will be selected
[ "Select", "text", "from", "a", "drop", "down", "list", "based", "on", "the", "displayed", "text", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L619-L623
155,820
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.isTextSelectedInDropDown
public boolean isTextSelectedInDropDown(final By by, final String displayText) { WebElement element = driver.findElement(by); List<WebElement> options = element.findElements(By .xpath(".//option[normalize-space(.) = " + escapeQuotes(displayText) + "]")); for (WebElement opt : options) { if (opt.isSelected()) { return true; } } return false; }
java
public boolean isTextSelectedInDropDown(final By by, final String displayText) { WebElement element = driver.findElement(by); List<WebElement> options = element.findElements(By .xpath(".//option[normalize-space(.) = " + escapeQuotes(displayText) + "]")); for (WebElement opt : options) { if (opt.isSelected()) { return true; } } return false; }
[ "public", "boolean", "isTextSelectedInDropDown", "(", "final", "By", "by", ",", "final", "String", "displayText", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "by", ")", ";", "List", "<", "WebElement", ">", "options", "=", "element", ".", "findElements", "(", "By", ".", "xpath", "(", "\".//option[normalize-space(.) = \"", "+", "escapeQuotes", "(", "displayText", ")", "+", "\"]\"", ")", ")", ";", "for", "(", "WebElement", "opt", ":", "options", ")", "{", "if", "(", "opt", ".", "isSelected", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if a text is selected in a drop down list. This will consider the display text not the actual value. @param by the method of identifying the drop-down @param displayText the text to search for @return true if the text is selected or false otherwise
[ "Checks", "if", "a", "text", "is", "selected", "in", "a", "drop", "down", "list", ".", "This", "will", "consider", "the", "display", "text", "not", "the", "actual", "value", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L636-L650
155,821
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getSelectedValue
public String getSelectedValue(final By by) { Select select = new Select(driver.findElement(by)); String defaultSelectedValue = select.getFirstSelectedOption().getText(); return defaultSelectedValue; }
java
public String getSelectedValue(final By by) { Select select = new Select(driver.findElement(by)); String defaultSelectedValue = select.getFirstSelectedOption().getText(); return defaultSelectedValue; }
[ "public", "String", "getSelectedValue", "(", "final", "By", "by", ")", "{", "Select", "select", "=", "new", "Select", "(", "driver", ".", "findElement", "(", "by", ")", ")", ";", "String", "defaultSelectedValue", "=", "select", ".", "getFirstSelectedOption", "(", ")", ".", "getText", "(", ")", ";", "return", "defaultSelectedValue", ";", "}" ]
Returns the first selected value from a drop down list. @param by the method of identifying the element @return the first selected option from a drop-down
[ "Returns", "the", "first", "selected", "value", "from", "a", "drop", "down", "list", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L659-L665
155,822
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.isValueSelectedInDropDown
public boolean isValueSelectedInDropDown(final By by, final String value) { WebElement element = driver.findElement(by); StringBuilder builder = new StringBuilder(".//option[@value = "); builder.append(escapeQuotes(value)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder .toString())); for (WebElement opt : options) { if (opt.isSelected()) { return true; } } return false; }
java
public boolean isValueSelectedInDropDown(final By by, final String value) { WebElement element = driver.findElement(by); StringBuilder builder = new StringBuilder(".//option[@value = "); builder.append(escapeQuotes(value)); builder.append("]"); List<WebElement> options = element.findElements(By.xpath(builder .toString())); for (WebElement opt : options) { if (opt.isSelected()) { return true; } } return false; }
[ "public", "boolean", "isValueSelectedInDropDown", "(", "final", "By", "by", ",", "final", "String", "value", ")", "{", "WebElement", "element", "=", "driver", ".", "findElement", "(", "by", ")", ";", "StringBuilder", "builder", "=", "new", "StringBuilder", "(", "\".//option[@value = \"", ")", ";", "builder", ".", "append", "(", "escapeQuotes", "(", "value", ")", ")", ";", "builder", ".", "append", "(", "\"]\"", ")", ";", "List", "<", "WebElement", ">", "options", "=", "element", ".", "findElements", "(", "By", ".", "xpath", "(", "builder", ".", "toString", "(", ")", ")", ")", ";", "for", "(", "WebElement", "opt", ":", "options", ")", "{", "if", "(", "opt", ".", "isSelected", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if a value is selected in a drop down list. @param by the method of identifying the element @param value the value to search for @return true if the value is selected or false otherwise
[ "Checks", "if", "a", "value", "is", "selected", "in", "a", "drop", "down", "list", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L677-L693
155,823
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.selectRadioButtonByValue
public void selectRadioButtonByValue(final String radioButtonName, final String value) { List<WebElement> radioGroup = driver.findElements(By .name(radioButtonName)); for (WebElement button : radioGroup) { if (button.getAttribute("value").equalsIgnoreCase(value)) { button.click(); break; } } }
java
public void selectRadioButtonByValue(final String radioButtonName, final String value) { List<WebElement> radioGroup = driver.findElements(By .name(radioButtonName)); for (WebElement button : radioGroup) { if (button.getAttribute("value").equalsIgnoreCase(value)) { button.click(); break; } } }
[ "public", "void", "selectRadioButtonByValue", "(", "final", "String", "radioButtonName", ",", "final", "String", "value", ")", "{", "List", "<", "WebElement", ">", "radioGroup", "=", "driver", ".", "findElements", "(", "By", ".", "name", "(", "radioButtonName", ")", ")", ";", "for", "(", "WebElement", "button", ":", "radioGroup", ")", "{", "if", "(", "button", ".", "getAttribute", "(", "\"value\"", ")", ".", "equalsIgnoreCase", "(", "value", ")", ")", "{", "button", ".", "click", "(", ")", ";", "break", ";", "}", "}", "}" ]
Select the supplied value from a radio button group. @param radioButtonName the name of the radio button @param value the value to be selected
[ "Select", "the", "supplied", "value", "from", "a", "radio", "button", "group", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L715-L725
155,824
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.isRadioButtonValueSelected
public boolean isRadioButtonValueSelected(final String radioButtonName, final String value) { List<WebElement> radioGroup = driver.findElements(By .name(radioButtonName)); for (WebElement button : radioGroup) { if (button.getAttribute("value").equalsIgnoreCase(value) && button.isSelected()) { return true; } } return false; }
java
public boolean isRadioButtonValueSelected(final String radioButtonName, final String value) { List<WebElement> radioGroup = driver.findElements(By .name(radioButtonName)); for (WebElement button : radioGroup) { if (button.getAttribute("value").equalsIgnoreCase(value) && button.isSelected()) { return true; } } return false; }
[ "public", "boolean", "isRadioButtonValueSelected", "(", "final", "String", "radioButtonName", ",", "final", "String", "value", ")", "{", "List", "<", "WebElement", ">", "radioGroup", "=", "driver", ".", "findElements", "(", "By", ".", "name", "(", "radioButtonName", ")", ")", ";", "for", "(", "WebElement", "button", ":", "radioGroup", ")", "{", "if", "(", "button", ".", "getAttribute", "(", "\"value\"", ")", ".", "equalsIgnoreCase", "(", "value", ")", "&&", "button", ".", "isSelected", "(", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if a radio button group has the supplied value selected. @param radioButtonName the name of the radio button group @param value the value for check for @return true if the value is selected or false otherwise
[ "Checks", "if", "a", "radio", "button", "group", "has", "the", "supplied", "value", "selected", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L737-L750
155,825
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.selectWindowByTitle
public void selectWindowByTitle(final String title) { String currentWindow = driver.getWindowHandle(); Set<String> handles = driver.getWindowHandles(); if (!handles.isEmpty()) { for (String windowId : handles) { if (!driver.switchTo().window(windowId).getTitle() .equals(title)) { driver.switchTo().window(currentWindow); } } } }
java
public void selectWindowByTitle(final String title) { String currentWindow = driver.getWindowHandle(); Set<String> handles = driver.getWindowHandles(); if (!handles.isEmpty()) { for (String windowId : handles) { if (!driver.switchTo().window(windowId).getTitle() .equals(title)) { driver.switchTo().window(currentWindow); } } } }
[ "public", "void", "selectWindowByTitle", "(", "final", "String", "title", ")", "{", "String", "currentWindow", "=", "driver", ".", "getWindowHandle", "(", ")", ";", "Set", "<", "String", ">", "handles", "=", "driver", ".", "getWindowHandles", "(", ")", ";", "if", "(", "!", "handles", ".", "isEmpty", "(", ")", ")", "{", "for", "(", "String", "windowId", ":", "handles", ")", "{", "if", "(", "!", "driver", ".", "switchTo", "(", ")", ".", "window", "(", "windowId", ")", ".", "getTitle", "(", ")", ".", "equals", "(", "title", ")", ")", "{", "driver", ".", "switchTo", "(", ")", ".", "window", "(", "currentWindow", ")", ";", "}", "}", "}", "}" ]
Used to switch to a window by title. @param title the title of the window to switch to
[ "Used", "to", "switch", "to", "a", "window", "by", "title", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L758-L769
155,826
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getDriverWithProxy
public static WebDriver getDriverWithProxy(final String proxyURL, final String port, final WebDriver driver) { org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); proxy.setHttpProxy(proxyURL + ":" + port) .setFtpProxy(proxyURL + ":" + port) .setSslProxy(proxyURL + ":" + port); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); try { Constructor<?> c = driver.getClass().getConstructor( Capabilities.class); return (WebDriver) c.newInstance(cap); } catch (Exception e) { LOG.error( "Exception while creating a driver with the specified proxy", e); } return driver; }
java
public static WebDriver getDriverWithProxy(final String proxyURL, final String port, final WebDriver driver) { org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); proxy.setHttpProxy(proxyURL + ":" + port) .setFtpProxy(proxyURL + ":" + port) .setSslProxy(proxyURL + ":" + port); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.PROXY, proxy); try { Constructor<?> c = driver.getClass().getConstructor( Capabilities.class); return (WebDriver) c.newInstance(cap); } catch (Exception e) { LOG.error( "Exception while creating a driver with the specified proxy", e); } return driver; }
[ "public", "static", "WebDriver", "getDriverWithProxy", "(", "final", "String", "proxyURL", ",", "final", "String", "port", ",", "final", "WebDriver", "driver", ")", "{", "org", ".", "openqa", ".", "selenium", ".", "Proxy", "proxy", "=", "new", "org", ".", "openqa", ".", "selenium", ".", "Proxy", "(", ")", ";", "proxy", ".", "setHttpProxy", "(", "proxyURL", "+", "\":\"", "+", "port", ")", ".", "setFtpProxy", "(", "proxyURL", "+", "\":\"", "+", "port", ")", ".", "setSslProxy", "(", "proxyURL", "+", "\":\"", "+", "port", ")", ";", "DesiredCapabilities", "cap", "=", "new", "DesiredCapabilities", "(", ")", ";", "cap", ".", "setCapability", "(", "CapabilityType", ".", "PROXY", ",", "proxy", ")", ";", "try", "{", "Constructor", "<", "?", ">", "c", "=", "driver", ".", "getClass", "(", ")", ".", "getConstructor", "(", "Capabilities", ".", "class", ")", ";", "return", "(", "WebDriver", ")", "c", ".", "newInstance", "(", "cap", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "LOG", ".", "error", "(", "\"Exception while creating a driver with the specified proxy\"", ",", "e", ")", ";", "}", "return", "driver", ";", "}" ]
Returns a WebDriver object that has the proxy server set. @param proxyURL the proxy host @param port the proxy port @param driver the drive class @return a new driver with the proxy settings configured
[ "Returns", "a", "WebDriver", "object", "that", "has", "the", "proxy", "server", "set", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L782-L802
155,827
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getFirefoxDriverWithUserAgent
public static WebDriver getFirefoxDriverWithUserAgent(final String userAgent) { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); profile.setPreference("general.useragent.override", userAgent); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(true); WebDriver driver = new FirefoxDriver(profile); return driver; }
java
public static WebDriver getFirefoxDriverWithUserAgent(final String userAgent) { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); profile.setPreference("general.useragent.override", userAgent); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(true); WebDriver driver = new FirefoxDriver(profile); return driver; }
[ "public", "static", "WebDriver", "getFirefoxDriverWithUserAgent", "(", "final", "String", "userAgent", ")", "{", "ProfilesIni", "allProfiles", "=", "new", "ProfilesIni", "(", ")", ";", "FirefoxProfile", "profile", "=", "allProfiles", ".", "getProfile", "(", "\"default\"", ")", ";", "profile", ".", "setPreference", "(", "\"general.useragent.override\"", ",", "userAgent", ")", ";", "profile", ".", "setAcceptUntrustedCertificates", "(", "true", ")", ";", "profile", ".", "setAssumeUntrustedCertificateIssuer", "(", "true", ")", ";", "WebDriver", "driver", "=", "new", "FirefoxDriver", "(", "profile", ")", ";", "return", "driver", ";", "}" ]
Creates a FirefoxDriver that has the supplied user agent. @param userAgent the user agent @return a new FirefoxDriver instance containing the specified user agent settings
[ "Creates", "a", "FirefoxDriver", "that", "has", "the", "supplied", "user", "agent", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L813-L822
155,828
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getFirefoxDriverWithExistingProfile
public static WebDriver getFirefoxDriverWithExistingProfile( final String pathToProfile) { FirefoxProfile profile = new FirefoxProfile(new File(pathToProfile)); return new FirefoxDriver(profile); }
java
public static WebDriver getFirefoxDriverWithExistingProfile( final String pathToProfile) { FirefoxProfile profile = new FirefoxProfile(new File(pathToProfile)); return new FirefoxDriver(profile); }
[ "public", "static", "WebDriver", "getFirefoxDriverWithExistingProfile", "(", "final", "String", "pathToProfile", ")", "{", "FirefoxProfile", "profile", "=", "new", "FirefoxProfile", "(", "new", "File", "(", "pathToProfile", ")", ")", ";", "return", "new", "FirefoxDriver", "(", "profile", ")", ";", "}" ]
Returns a new WebDriver instance and loads an existing profile from the disk. You must pass the path to the profile. @param pathToProfile the path to the profile folder @return a new FirefoxDriver that loads the supplied profile
[ "Returns", "a", "new", "WebDriver", "instance", "and", "loads", "an", "existing", "profile", "from", "the", "disk", ".", "You", "must", "pass", "the", "path", "to", "the", "profile", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L832-L837
155,829
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.escapeQuotes
public String escapeQuotes(final String toEscape) { if (toEscape.indexOf("\"") > -1 && toEscape.indexOf("'") > -1) { boolean quoteIsLast = false; if (toEscape.indexOf("\"") == toEscape.length() - 1) { quoteIsLast = true; } String[] substrings = toEscape.split("\""); StringBuilder quoted = new StringBuilder("concat("); for (int i = 0; i < substrings.length; i++) { quoted.append("\"").append(substrings[i]).append("\""); quoted.append(((i == substrings.length - 1) ? (quoteIsLast ? ", '\"')" : ")") : ", '\"', ")); } return quoted.toString(); } if (toEscape.indexOf("\"") > -1) { return String.format("'%s'", toEscape); } return String.format("\"%s\"", toEscape); }
java
public String escapeQuotes(final String toEscape) { if (toEscape.indexOf("\"") > -1 && toEscape.indexOf("'") > -1) { boolean quoteIsLast = false; if (toEscape.indexOf("\"") == toEscape.length() - 1) { quoteIsLast = true; } String[] substrings = toEscape.split("\""); StringBuilder quoted = new StringBuilder("concat("); for (int i = 0; i < substrings.length; i++) { quoted.append("\"").append(substrings[i]).append("\""); quoted.append(((i == substrings.length - 1) ? (quoteIsLast ? ", '\"')" : ")") : ", '\"', ")); } return quoted.toString(); } if (toEscape.indexOf("\"") > -1) { return String.format("'%s'", toEscape); } return String.format("\"%s\"", toEscape); }
[ "public", "String", "escapeQuotes", "(", "final", "String", "toEscape", ")", "{", "if", "(", "toEscape", ".", "indexOf", "(", "\"\\\"\"", ")", ">", "-", "1", "&&", "toEscape", ".", "indexOf", "(", "\"'\"", ")", ">", "-", "1", ")", "{", "boolean", "quoteIsLast", "=", "false", ";", "if", "(", "toEscape", ".", "indexOf", "(", "\"\\\"\"", ")", "==", "toEscape", ".", "length", "(", ")", "-", "1", ")", "{", "quoteIsLast", "=", "true", ";", "}", "String", "[", "]", "substrings", "=", "toEscape", ".", "split", "(", "\"\\\"\"", ")", ";", "StringBuilder", "quoted", "=", "new", "StringBuilder", "(", "\"concat(\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "substrings", ".", "length", ";", "i", "++", ")", "{", "quoted", ".", "append", "(", "\"\\\"\"", ")", ".", "append", "(", "substrings", "[", "i", "]", ")", ".", "append", "(", "\"\\\"\"", ")", ";", "quoted", ".", "append", "(", "(", "(", "i", "==", "substrings", ".", "length", "-", "1", ")", "?", "(", "quoteIsLast", "?", "\", '\\\"')\"", ":", "\")\"", ")", ":", "\", '\\\"', \"", ")", ")", ";", "}", "return", "quoted", ".", "toString", "(", ")", ";", "}", "if", "(", "toEscape", ".", "indexOf", "(", "\"\\\"\"", ")", ">", "-", "1", ")", "{", "return", "String", ".", "format", "(", "\"'%s'\"", ",", "toEscape", ")", ";", "}", "return", "String", ".", "format", "(", "\"\\\"%s\\\"\"", ",", "toEscape", ")", ";", "}" ]
Escapes the quotes for the supplied string. @param toEscape string to be escaped @return an escaped string
[ "Escapes", "the", "quotes", "for", "the", "supplied", "string", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L846-L869
155,830
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getFirefoxDriverWithJSSettings
public static WebDriver getFirefoxDriverWithJSSettings( final String userAgent, final boolean javascriptEnabled) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("general.useragent.override", userAgent); profile.setPreference("javascript.enabled", javascriptEnabled); WebDriver driver = new FirefoxDriver(profile); return driver; }
java
public static WebDriver getFirefoxDriverWithJSSettings( final String userAgent, final boolean javascriptEnabled) { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("general.useragent.override", userAgent); profile.setPreference("javascript.enabled", javascriptEnabled); WebDriver driver = new FirefoxDriver(profile); return driver; }
[ "public", "static", "WebDriver", "getFirefoxDriverWithJSSettings", "(", "final", "String", "userAgent", ",", "final", "boolean", "javascriptEnabled", ")", "{", "FirefoxProfile", "profile", "=", "new", "FirefoxProfile", "(", ")", ";", "profile", ".", "setPreference", "(", "\"general.useragent.override\"", ",", "userAgent", ")", ";", "profile", ".", "setPreference", "(", "\"javascript.enabled\"", ",", "javascriptEnabled", ")", ";", "WebDriver", "driver", "=", "new", "FirefoxDriver", "(", "profile", ")", ";", "return", "driver", ";", "}" ]
Gets a profile with a specific user agent with or without javascript enabled. @param userAgent the user agent @param javascriptEnabled javascript enabled or not @return a FirefoxDriver instance with javascript and user agent seetigs configured
[ "Gets", "a", "profile", "with", "a", "specific", "user", "agent", "with", "or", "without", "javascript", "enabled", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L882-L890
155,831
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getDriverInstance
private static WebDriver getDriverInstance( final DesiredCapabilities capabilities, final Builder builder) { WebDriver driver = null; try { Class<?> clazz = Class.forName("org.openqa.selenium." + builder.browserPackage + "." + StringUtils.capitalize(builder.browser + "Driver")); LOG.info("Driver class to be returned: " + clazz); Constructor<?> c = clazz.getConstructor(Capabilities.class); LOG.info("Driver constructor to be called: " + c); driver = (WebDriver) c.newInstance(new Object[] { capabilities }); LOG.info("Driver initialized: " + driver); } catch (Exception e) { throw new IllegalArgumentException("Browser " + builder.browser + " is not a valid name!", e); } LOG.info("Returned driver instance: " + driver); return driver; }
java
private static WebDriver getDriverInstance( final DesiredCapabilities capabilities, final Builder builder) { WebDriver driver = null; try { Class<?> clazz = Class.forName("org.openqa.selenium." + builder.browserPackage + "." + StringUtils.capitalize(builder.browser + "Driver")); LOG.info("Driver class to be returned: " + clazz); Constructor<?> c = clazz.getConstructor(Capabilities.class); LOG.info("Driver constructor to be called: " + c); driver = (WebDriver) c.newInstance(new Object[] { capabilities }); LOG.info("Driver initialized: " + driver); } catch (Exception e) { throw new IllegalArgumentException("Browser " + builder.browser + " is not a valid name!", e); } LOG.info("Returned driver instance: " + driver); return driver; }
[ "private", "static", "WebDriver", "getDriverInstance", "(", "final", "DesiredCapabilities", "capabilities", ",", "final", "Builder", "builder", ")", "{", "WebDriver", "driver", "=", "null", ";", "try", "{", "Class", "<", "?", ">", "clazz", "=", "Class", ".", "forName", "(", "\"org.openqa.selenium.\"", "+", "builder", ".", "browserPackage", "+", "\".\"", "+", "StringUtils", ".", "capitalize", "(", "builder", ".", "browser", "+", "\"Driver\"", ")", ")", ";", "LOG", ".", "info", "(", "\"Driver class to be returned: \"", "+", "clazz", ")", ";", "Constructor", "<", "?", ">", "c", "=", "clazz", ".", "getConstructor", "(", "Capabilities", ".", "class", ")", ";", "LOG", ".", "info", "(", "\"Driver constructor to be called: \"", "+", "c", ")", ";", "driver", "=", "(", "WebDriver", ")", "c", ".", "newInstance", "(", "new", "Object", "[", "]", "{", "capabilities", "}", ")", ";", "LOG", ".", "info", "(", "\"Driver initialized: \"", "+", "driver", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Browser \"", "+", "builder", ".", "browser", "+", "\" is not a valid name!\"", ",", "e", ")", ";", "}", "LOG", ".", "info", "(", "\"Returned driver instance: \"", "+", "driver", ")", ";", "return", "driver", ";", "}" ]
Returns a web driver instance based on capabilities. @param capabilities the desired capabilities @param builder the Builder instance @return a new WebDriver instance with the desired capabilities specified
[ "Returns", "a", "web", "driver", "instance", "based", "on", "capabilities", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L937-L958
155,832
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.addSpecificBrowserSettings
private static void addSpecificBrowserSettings( final DesiredCapabilities capabilities, final Builder builder) { if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.FIREFOX)) { LOG.info("Browser is Firefox. Getting local profile"); FirefoxProfile profile = null; if (builder.profileLocation != null && !"".equalsIgnoreCase(builder.profileLocation)) { profile = new FirefoxProfile(new File(builder.profileLocation)); LOG.info("Firefox profile: " + builder.profileLocation); } else { LOG.info("Loading Firefox default sprofile"); ProfilesIni allProfiles = new ProfilesIni(); allProfiles.getProfile("default"); } capabilities.setCapability(FirefoxDriver.PROFILE, profile); if (builder.userAgent != null) { profile.setPreference("general.useragent.override", builder.userAgent); } } else if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.CHROME)) { ChromeOptions options = new ChromeOptions(); if (builder.userAgent != null) { options.addArguments("user-agent=" + builder.userAgent); } capabilities.setCapability(ChromeOptions.CAPABILITY, options); } else if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.IE)) { capabilities .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, builder.flakinessForIe); } LOG.info("Finished adding specific browser settings"); }
java
private static void addSpecificBrowserSettings( final DesiredCapabilities capabilities, final Builder builder) { if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.FIREFOX)) { LOG.info("Browser is Firefox. Getting local profile"); FirefoxProfile profile = null; if (builder.profileLocation != null && !"".equalsIgnoreCase(builder.profileLocation)) { profile = new FirefoxProfile(new File(builder.profileLocation)); LOG.info("Firefox profile: " + builder.profileLocation); } else { LOG.info("Loading Firefox default sprofile"); ProfilesIni allProfiles = new ProfilesIni(); allProfiles.getProfile("default"); } capabilities.setCapability(FirefoxDriver.PROFILE, profile); if (builder.userAgent != null) { profile.setPreference("general.useragent.override", builder.userAgent); } } else if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.CHROME)) { ChromeOptions options = new ChromeOptions(); if (builder.userAgent != null) { options.addArguments("user-agent=" + builder.userAgent); } capabilities.setCapability(ChromeOptions.CAPABILITY, options); } else if (capabilities.getBrowserName().equalsIgnoreCase( Constants.Browsers.IE)) { capabilities .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, builder.flakinessForIe); } LOG.info("Finished adding specific browser settings"); }
[ "private", "static", "void", "addSpecificBrowserSettings", "(", "final", "DesiredCapabilities", "capabilities", ",", "final", "Builder", "builder", ")", "{", "if", "(", "capabilities", ".", "getBrowserName", "(", ")", ".", "equalsIgnoreCase", "(", "Constants", ".", "Browsers", ".", "FIREFOX", ")", ")", "{", "LOG", ".", "info", "(", "\"Browser is Firefox. Getting local profile\"", ")", ";", "FirefoxProfile", "profile", "=", "null", ";", "if", "(", "builder", ".", "profileLocation", "!=", "null", "&&", "!", "\"\"", ".", "equalsIgnoreCase", "(", "builder", ".", "profileLocation", ")", ")", "{", "profile", "=", "new", "FirefoxProfile", "(", "new", "File", "(", "builder", ".", "profileLocation", ")", ")", ";", "LOG", ".", "info", "(", "\"Firefox profile: \"", "+", "builder", ".", "profileLocation", ")", ";", "}", "else", "{", "LOG", ".", "info", "(", "\"Loading Firefox default sprofile\"", ")", ";", "ProfilesIni", "allProfiles", "=", "new", "ProfilesIni", "(", ")", ";", "allProfiles", ".", "getProfile", "(", "\"default\"", ")", ";", "}", "capabilities", ".", "setCapability", "(", "FirefoxDriver", ".", "PROFILE", ",", "profile", ")", ";", "if", "(", "builder", ".", "userAgent", "!=", "null", ")", "{", "profile", ".", "setPreference", "(", "\"general.useragent.override\"", ",", "builder", ".", "userAgent", ")", ";", "}", "}", "else", "if", "(", "capabilities", ".", "getBrowserName", "(", ")", ".", "equalsIgnoreCase", "(", "Constants", ".", "Browsers", ".", "CHROME", ")", ")", "{", "ChromeOptions", "options", "=", "new", "ChromeOptions", "(", ")", ";", "if", "(", "builder", ".", "userAgent", "!=", "null", ")", "{", "options", ".", "addArguments", "(", "\"user-agent=\"", "+", "builder", ".", "userAgent", ")", ";", "}", "capabilities", ".", "setCapability", "(", "ChromeOptions", ".", "CAPABILITY", ",", "options", ")", ";", "}", "else", "if", "(", "capabilities", ".", "getBrowserName", "(", ")", ".", "equalsIgnoreCase", "(", "Constants", ".", "Browsers", ".", "IE", ")", ")", "{", "capabilities", ".", "setCapability", "(", "InternetExplorerDriver", ".", "INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS", ",", "builder", ".", "flakinessForIe", ")", ";", "}", "LOG", ".", "info", "(", "\"Finished adding specific browser settings\"", ")", ";", "}" ]
This method adds browser specific capabilities like FirefoxProfile and ChromeOptions. @param capabilities specific capabilities @param builder the builder object containing the properties
[ "This", "method", "adds", "browser", "specific", "capabilities", "like", "FirefoxProfile", "and", "ChromeOptions", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L969-L1009
155,833
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getDriver
private static WebDriver getDriver(final Builder builder) { // this is the default value DesiredCapabilities capabilities = getCapabilitiesBrowser(builder.browser); WebDriver driver = null; /** * Setting the proxy */ LOG.info("Proxy seetings set"); org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); if (builder.proxyHost != null && !builder.proxyHost.isEmpty()) { if (!builder.proxyHost.equals("direct")) { proxy.setAutodetect(false); proxy.setHttpProxy(builder.proxyHost + ":" + builder.proxyPort) .setFtpProxy( builder.proxyHost + ":" + builder.proxyPort) .setSslProxy( builder.proxyHost + ":" + builder.proxyPort) .setNoProxy(builder.noProxyFor); } else { proxy.setProxyType(ProxyType.DIRECT); } capabilities.setCapability(CapabilityType.PROXY, proxy); } /** * the Driver will take screenshots */ LOG.info("Screenshot capability set"); capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true); /** * setting the platform: LINUX, MAC or Windows. Remember that sometimes * the browsers are linked to a platform like IE for example */ if (builder.platform != null) { capabilities.setCapability(CapabilityType.PLATFORM, builder.platform); } if (builder.browserVersion != null) { capabilities.setCapability(CapabilityType.VERSION, builder.browserVersion); } /** * set if javascript is enabled */ capabilities.setJavascriptEnabled(builder.jsEnabled); /** * set if the browser will accept all certificates, including the * self-signed ones */ capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, builder.acceptAllCertificates); /** * this will actually create firefox profiles, chrome options and others */ LOG.info("Adding specific browser settings"); addSpecificBrowserSettings(capabilities, builder); /** * getting an actual WebDriver implementation now */ LOG.info("Detecting running mode"); if (builder.runMode.equalsIgnoreCase(Constants.RunMode.GRID)) { LOG.info("Run mode GRID. Setting GRID properties"); try { driver = new RemoteWebDriver(new URL(builder.gridUrl), capabilities); ((RemoteWebDriver) driver).setLogLevel(Level.SEVERE); } catch (Exception e) { LOG.debug("Exception while initiating remote driver:", e); } } else { LOG.info("Normal run mode. Getting driver instance"); driver = getDriverInstance(capabilities, builder); } LOG.info("Returning the following driver: " + driver); LOG.info("With capabilities: " + capabilities); return driver; }
java
private static WebDriver getDriver(final Builder builder) { // this is the default value DesiredCapabilities capabilities = getCapabilitiesBrowser(builder.browser); WebDriver driver = null; /** * Setting the proxy */ LOG.info("Proxy seetings set"); org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); if (builder.proxyHost != null && !builder.proxyHost.isEmpty()) { if (!builder.proxyHost.equals("direct")) { proxy.setAutodetect(false); proxy.setHttpProxy(builder.proxyHost + ":" + builder.proxyPort) .setFtpProxy( builder.proxyHost + ":" + builder.proxyPort) .setSslProxy( builder.proxyHost + ":" + builder.proxyPort) .setNoProxy(builder.noProxyFor); } else { proxy.setProxyType(ProxyType.DIRECT); } capabilities.setCapability(CapabilityType.PROXY, proxy); } /** * the Driver will take screenshots */ LOG.info("Screenshot capability set"); capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true); /** * setting the platform: LINUX, MAC or Windows. Remember that sometimes * the browsers are linked to a platform like IE for example */ if (builder.platform != null) { capabilities.setCapability(CapabilityType.PLATFORM, builder.platform); } if (builder.browserVersion != null) { capabilities.setCapability(CapabilityType.VERSION, builder.browserVersion); } /** * set if javascript is enabled */ capabilities.setJavascriptEnabled(builder.jsEnabled); /** * set if the browser will accept all certificates, including the * self-signed ones */ capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, builder.acceptAllCertificates); /** * this will actually create firefox profiles, chrome options and others */ LOG.info("Adding specific browser settings"); addSpecificBrowserSettings(capabilities, builder); /** * getting an actual WebDriver implementation now */ LOG.info("Detecting running mode"); if (builder.runMode.equalsIgnoreCase(Constants.RunMode.GRID)) { LOG.info("Run mode GRID. Setting GRID properties"); try { driver = new RemoteWebDriver(new URL(builder.gridUrl), capabilities); ((RemoteWebDriver) driver).setLogLevel(Level.SEVERE); } catch (Exception e) { LOG.debug("Exception while initiating remote driver:", e); } } else { LOG.info("Normal run mode. Getting driver instance"); driver = getDriverInstance(capabilities, builder); } LOG.info("Returning the following driver: " + driver); LOG.info("With capabilities: " + capabilities); return driver; }
[ "private", "static", "WebDriver", "getDriver", "(", "final", "Builder", "builder", ")", "{", "// this is the default value", "DesiredCapabilities", "capabilities", "=", "getCapabilitiesBrowser", "(", "builder", ".", "browser", ")", ";", "WebDriver", "driver", "=", "null", ";", "/**\n\t\t * Setting the proxy\n\t\t */", "LOG", ".", "info", "(", "\"Proxy seetings set\"", ")", ";", "org", ".", "openqa", ".", "selenium", ".", "Proxy", "proxy", "=", "new", "org", ".", "openqa", ".", "selenium", ".", "Proxy", "(", ")", ";", "if", "(", "builder", ".", "proxyHost", "!=", "null", "&&", "!", "builder", ".", "proxyHost", ".", "isEmpty", "(", ")", ")", "{", "if", "(", "!", "builder", ".", "proxyHost", ".", "equals", "(", "\"direct\"", ")", ")", "{", "proxy", ".", "setAutodetect", "(", "false", ")", ";", "proxy", ".", "setHttpProxy", "(", "builder", ".", "proxyHost", "+", "\":\"", "+", "builder", ".", "proxyPort", ")", ".", "setFtpProxy", "(", "builder", ".", "proxyHost", "+", "\":\"", "+", "builder", ".", "proxyPort", ")", ".", "setSslProxy", "(", "builder", ".", "proxyHost", "+", "\":\"", "+", "builder", ".", "proxyPort", ")", ".", "setNoProxy", "(", "builder", ".", "noProxyFor", ")", ";", "}", "else", "{", "proxy", ".", "setProxyType", "(", "ProxyType", ".", "DIRECT", ")", ";", "}", "capabilities", ".", "setCapability", "(", "CapabilityType", ".", "PROXY", ",", "proxy", ")", ";", "}", "/**\n\t\t * the Driver will take screenshots\n\t\t */", "LOG", ".", "info", "(", "\"Screenshot capability set\"", ")", ";", "capabilities", ".", "setCapability", "(", "CapabilityType", ".", "TAKES_SCREENSHOT", ",", "true", ")", ";", "/**\n\t\t * setting the platform: LINUX, MAC or Windows. Remember that sometimes\n\t\t * the browsers are linked to a platform like IE for example\n\t\t */", "if", "(", "builder", ".", "platform", "!=", "null", ")", "{", "capabilities", ".", "setCapability", "(", "CapabilityType", ".", "PLATFORM", ",", "builder", ".", "platform", ")", ";", "}", "if", "(", "builder", ".", "browserVersion", "!=", "null", ")", "{", "capabilities", ".", "setCapability", "(", "CapabilityType", ".", "VERSION", ",", "builder", ".", "browserVersion", ")", ";", "}", "/**\n\t\t * set if javascript is enabled\n\t\t */", "capabilities", ".", "setJavascriptEnabled", "(", "builder", ".", "jsEnabled", ")", ";", "/**\n\t\t * set if the browser will accept all certificates, including the\n\t\t * self-signed ones\n\t\t */", "capabilities", ".", "setCapability", "(", "CapabilityType", ".", "ACCEPT_SSL_CERTS", ",", "builder", ".", "acceptAllCertificates", ")", ";", "/**\n\t\t * this will actually create firefox profiles, chrome options and others\n\t\t */", "LOG", ".", "info", "(", "\"Adding specific browser settings\"", ")", ";", "addSpecificBrowserSettings", "(", "capabilities", ",", "builder", ")", ";", "/**\n\t\t * getting an actual WebDriver implementation now\n\t\t */", "LOG", ".", "info", "(", "\"Detecting running mode\"", ")", ";", "if", "(", "builder", ".", "runMode", ".", "equalsIgnoreCase", "(", "Constants", ".", "RunMode", ".", "GRID", ")", ")", "{", "LOG", ".", "info", "(", "\"Run mode GRID. Setting GRID properties\"", ")", ";", "try", "{", "driver", "=", "new", "RemoteWebDriver", "(", "new", "URL", "(", "builder", ".", "gridUrl", ")", ",", "capabilities", ")", ";", "(", "(", "RemoteWebDriver", ")", "driver", ")", ".", "setLogLevel", "(", "Level", ".", "SEVERE", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "LOG", ".", "debug", "(", "\"Exception while initiating remote driver:\"", ",", "e", ")", ";", "}", "}", "else", "{", "LOG", ".", "info", "(", "\"Normal run mode. Getting driver instance\"", ")", ";", "driver", "=", "getDriverInstance", "(", "capabilities", ",", "builder", ")", ";", "}", "LOG", ".", "info", "(", "\"Returning the following driver: \"", "+", "driver", ")", ";", "LOG", ".", "info", "(", "\"With capabilities: \"", "+", "capabilities", ")", ";", "return", "driver", ";", "}" ]
This method returns a fully configured WebDriver instance based on the parameters sent. @param builder the Builder used to construct the WebDriver instance @return a fully configured FirefoxDriver instance
[ "This", "method", "returns", "a", "fully", "configured", "WebDriver", "instance", "based", "on", "the", "parameters", "sent", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L1019-L1103
155,834
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.goToUrlWithCookie
public void goToUrlWithCookie(final String url, final String cookieName, final String cookieValue) { // we'll do a trick to prevent Selenium falsely reporting a cross // domain cookie attempt LOG.info("Getting: " + url + " with cookieName: " + cookieName + " and cookieValue: " + cookieValue); driver.get(url + "/404.html"); // this should display 404 not found driver.manage().deleteAllCookies(); driver.manage().addCookie(new Cookie(cookieName, cookieValue)); driver.get(url); }
java
public void goToUrlWithCookie(final String url, final String cookieName, final String cookieValue) { // we'll do a trick to prevent Selenium falsely reporting a cross // domain cookie attempt LOG.info("Getting: " + url + " with cookieName: " + cookieName + " and cookieValue: " + cookieValue); driver.get(url + "/404.html"); // this should display 404 not found driver.manage().deleteAllCookies(); driver.manage().addCookie(new Cookie(cookieName, cookieValue)); driver.get(url); }
[ "public", "void", "goToUrlWithCookie", "(", "final", "String", "url", ",", "final", "String", "cookieName", ",", "final", "String", "cookieValue", ")", "{", "// we'll do a trick to prevent Selenium falsely reporting a cross", "// domain cookie attempt", "LOG", ".", "info", "(", "\"Getting: \"", "+", "url", "+", "\" with cookieName: \"", "+", "cookieName", "+", "\" and cookieValue: \"", "+", "cookieValue", ")", ";", "driver", ".", "get", "(", "url", "+", "\"/404.html\"", ")", ";", "// this should display 404 not found", "driver", ".", "manage", "(", ")", ".", "deleteAllCookies", "(", ")", ";", "driver", ".", "manage", "(", ")", ".", "addCookie", "(", "new", "Cookie", "(", "cookieName", ",", "cookieValue", ")", ")", ";", "driver", ".", "get", "(", "url", ")", ";", "}" ]
Opens the specified URL using the specified cookie. @param url the url you want to open @param cookieName the cookie name @param cookieValue the cookie value
[ "Opens", "the", "specified", "URL", "using", "the", "specified", "cookie", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L1115-L1125
155,835
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.goToUrlWithCookies
public void goToUrlWithCookies(final String url, final Map<String, String> cookieNamesValues) { LOG.info("Getting: " + url + " with cookies: " + cookieNamesValues); driver.get(url + "/404.html"); // this should display 404 not found driver.manage().deleteAllCookies(); Set<Entry<String, String>> entries = cookieNamesValues.entrySet(); for (Entry<String, String> cookieEntry : entries) { driver.manage().addCookie( new Cookie(cookieEntry.getKey(), cookieEntry.getValue())); } driver.get(url); }
java
public void goToUrlWithCookies(final String url, final Map<String, String> cookieNamesValues) { LOG.info("Getting: " + url + " with cookies: " + cookieNamesValues); driver.get(url + "/404.html"); // this should display 404 not found driver.manage().deleteAllCookies(); Set<Entry<String, String>> entries = cookieNamesValues.entrySet(); for (Entry<String, String> cookieEntry : entries) { driver.manage().addCookie( new Cookie(cookieEntry.getKey(), cookieEntry.getValue())); } driver.get(url); }
[ "public", "void", "goToUrlWithCookies", "(", "final", "String", "url", ",", "final", "Map", "<", "String", ",", "String", ">", "cookieNamesValues", ")", "{", "LOG", ".", "info", "(", "\"Getting: \"", "+", "url", "+", "\" with cookies: \"", "+", "cookieNamesValues", ")", ";", "driver", ".", "get", "(", "url", "+", "\"/404.html\"", ")", ";", "// this should display 404 not found", "driver", ".", "manage", "(", ")", ".", "deleteAllCookies", "(", ")", ";", "Set", "<", "Entry", "<", "String", ",", "String", ">", ">", "entries", "=", "cookieNamesValues", ".", "entrySet", "(", ")", ";", "for", "(", "Entry", "<", "String", ",", "String", ">", "cookieEntry", ":", "entries", ")", "{", "driver", ".", "manage", "(", ")", ".", "addCookie", "(", "new", "Cookie", "(", "cookieEntry", ".", "getKey", "(", ")", ",", "cookieEntry", ".", "getValue", "(", ")", ")", ")", ";", "}", "driver", ".", "get", "(", "url", ")", ";", "}" ]
Opens the specified URL using the specified cookies list. @param url the URL you want to open @param cookieNamesValues the cookies list you want to pass
[ "Opens", "the", "specified", "URL", "using", "the", "specified", "cookies", "list", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L1135-L1147
155,836
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getTableAsList
public List<List<String>> getTableAsList(final By tableBy) { List<List<String>> all = new ArrayList<List<String>>(); WebElement table = driver.findElement(tableBy); List<WebElement> rows = table.findElements(By.tagName("tr")); for (WebElement row : rows) { List<String> toAdd = new ArrayList<String>(); List<WebElement> columns = row.findElements(By.tagName("td")); for (WebElement column : columns) { toAdd.add(column.getText()); } all.add(toAdd); } return all; }
java
public List<List<String>> getTableAsList(final By tableBy) { List<List<String>> all = new ArrayList<List<String>>(); WebElement table = driver.findElement(tableBy); List<WebElement> rows = table.findElements(By.tagName("tr")); for (WebElement row : rows) { List<String> toAdd = new ArrayList<String>(); List<WebElement> columns = row.findElements(By.tagName("td")); for (WebElement column : columns) { toAdd.add(column.getText()); } all.add(toAdd); } return all; }
[ "public", "List", "<", "List", "<", "String", ">", ">", "getTableAsList", "(", "final", "By", "tableBy", ")", "{", "List", "<", "List", "<", "String", ">>", "all", "=", "new", "ArrayList", "<", "List", "<", "String", ">", ">", "(", ")", ";", "WebElement", "table", "=", "driver", ".", "findElement", "(", "tableBy", ")", ";", "List", "<", "WebElement", ">", "rows", "=", "table", ".", "findElements", "(", "By", ".", "tagName", "(", "\"tr\"", ")", ")", ";", "for", "(", "WebElement", "row", ":", "rows", ")", "{", "List", "<", "String", ">", "toAdd", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "List", "<", "WebElement", ">", "columns", "=", "row", ".", "findElements", "(", "By", ".", "tagName", "(", "\"td\"", ")", ")", ";", "for", "(", "WebElement", "column", ":", "columns", ")", "{", "toAdd", ".", "add", "(", "column", ".", "getText", "(", ")", ")", ";", "}", "all", ".", "add", "(", "toAdd", ")", ";", "}", "return", "all", ";", "}" ]
Returns the contents of the table as a list. Each item in the list contains a table row. @param tableBy the method of identifying the table @return a list containing all the items within the table
[ "Returns", "the", "contents", "of", "the", "table", "as", "a", "list", ".", "Each", "item", "in", "the", "list", "contains", "a", "table", "row", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L1157-L1171
155,837
ludovicianul/selenium-on-steroids
src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java
WebDriverHelper.getTableColumn
public List<String> getTableColumn(final By tableBy, final int columnNumber) { List<String> result = new ArrayList<String>(); List<List<String>> table = this.getTableAsList(tableBy); for (List<String> line : table) { result.add(line.get(columnNumber)); } return result; }
java
public List<String> getTableColumn(final By tableBy, final int columnNumber) { List<String> result = new ArrayList<String>(); List<List<String>> table = this.getTableAsList(tableBy); for (List<String> line : table) { result.add(line.get(columnNumber)); } return result; }
[ "public", "List", "<", "String", ">", "getTableColumn", "(", "final", "By", "tableBy", ",", "final", "int", "columnNumber", ")", "{", "List", "<", "String", ">", "result", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "List", "<", "List", "<", "String", ">", ">", "table", "=", "this", ".", "getTableAsList", "(", "tableBy", ")", ";", "for", "(", "List", "<", "String", ">", "line", ":", "table", ")", "{", "result", ".", "add", "(", "line", ".", "get", "(", "columnNumber", ")", ")", ";", "}", "return", "result", ";", "}" ]
Returns the values for a specific column from a HTML table. @param tableBy the way to identify the table @param columnNumber the column number @return a list with all the values corresponding to the specified column
[ "Returns", "the", "values", "for", "a", "specific", "column", "from", "a", "HTML", "table", "." ]
f89d91c59f686114f94624bfc55712f278005bfa
https://github.com/ludovicianul/selenium-on-steroids/blob/f89d91c59f686114f94624bfc55712f278005bfa/src/main/java/com/insidecoding/sos/webdriver/WebDriverHelper.java#L1182-L1190
155,838
morimekta/utils
io-util/src/main/java/net/morimekta/util/ExtraCollectors.java
ExtraCollectors.inBatchesOf
public static <T> Collector<T, LinkedList<List<T>>, Stream<List<T>>> inBatchesOf(int itemsPerBatch) { return Collector.of(// instantiation LinkedList::new, // accumulator (l, i) -> { if (l.isEmpty() || l.peekLast().size() >= itemsPerBatch) { l.add(new ArrayList<>(itemsPerBatch)); } l.peekLast().add(i); }, // combiner (a, b) -> { // Merge the two lists so the batches matches the order // of the non-parallel inBatchesOf with (a1..an) + (b1..bn) // as the set of items. It's not extremely efficient, but // works fine as this is not optimized for parallel streams. while (!b.isEmpty()) { for (T i : b.peekFirst()) { if (a.peekLast().size() >= itemsPerBatch) { a.add(new ArrayList<>(itemsPerBatch)); } a.peekLast().add(i); } b.pollFirst(); } return a; }, // finalizer Collection::stream); }
java
public static <T> Collector<T, LinkedList<List<T>>, Stream<List<T>>> inBatchesOf(int itemsPerBatch) { return Collector.of(// instantiation LinkedList::new, // accumulator (l, i) -> { if (l.isEmpty() || l.peekLast().size() >= itemsPerBatch) { l.add(new ArrayList<>(itemsPerBatch)); } l.peekLast().add(i); }, // combiner (a, b) -> { // Merge the two lists so the batches matches the order // of the non-parallel inBatchesOf with (a1..an) + (b1..bn) // as the set of items. It's not extremely efficient, but // works fine as this is not optimized for parallel streams. while (!b.isEmpty()) { for (T i : b.peekFirst()) { if (a.peekLast().size() >= itemsPerBatch) { a.add(new ArrayList<>(itemsPerBatch)); } a.peekLast().add(i); } b.pollFirst(); } return a; }, // finalizer Collection::stream); }
[ "public", "static", "<", "T", ">", "Collector", "<", "T", ",", "LinkedList", "<", "List", "<", "T", ">", ">", ",", "Stream", "<", "List", "<", "T", ">", ">", ">", "inBatchesOf", "(", "int", "itemsPerBatch", ")", "{", "return", "Collector", ".", "of", "(", "// instantiation", "LinkedList", "::", "new", ",", "// accumulator", "(", "l", ",", "i", ")", "->", "{", "if", "(", "l", ".", "isEmpty", "(", ")", "||", "l", ".", "peekLast", "(", ")", ".", "size", "(", ")", ">=", "itemsPerBatch", ")", "{", "l", ".", "add", "(", "new", "ArrayList", "<>", "(", "itemsPerBatch", ")", ")", ";", "}", "l", ".", "peekLast", "(", ")", ".", "add", "(", "i", ")", ";", "}", ",", "// combiner", "(", "a", ",", "b", ")", "->", "{", "// Merge the two lists so the batches matches the order", "// of the non-parallel inBatchesOf with (a1..an) + (b1..bn)", "// as the set of items. It's not extremely efficient, but", "// works fine as this is not optimized for parallel streams.", "while", "(", "!", "b", ".", "isEmpty", "(", ")", ")", "{", "for", "(", "T", "i", ":", "b", ".", "peekFirst", "(", ")", ")", "{", "if", "(", "a", ".", "peekLast", "(", ")", ".", "size", "(", ")", ">=", "itemsPerBatch", ")", "{", "a", ".", "add", "(", "new", "ArrayList", "<>", "(", "itemsPerBatch", ")", ")", ";", "}", "a", ".", "peekLast", "(", ")", ".", "add", "(", "i", ")", ";", "}", "b", ".", "pollFirst", "(", ")", ";", "}", "return", "a", ";", "}", ",", "// finalizer", "Collection", "::", "stream", ")", ";", "}" ]
Collect into batches of max N items per batch. Creates a stream of lists as response. @param itemsPerBatch Maximum number of items per batch. @param <T> The item type. @return The stream of batched entries.
[ "Collect", "into", "batches", "of", "max", "N", "items", "per", "batch", ".", "Creates", "a", "stream", "of", "lists", "as", "response", "." ]
dc987485902f1a7d58169c89c61db97425a6226d
https://github.com/morimekta/utils/blob/dc987485902f1a7d58169c89c61db97425a6226d/io-util/src/main/java/net/morimekta/util/ExtraCollectors.java#L42-L71
155,839
morimekta/utils
io-util/src/main/java/net/morimekta/util/ExtraCollectors.java
ExtraCollectors.inNumBatches
public static <T> Collector<T, ArrayList<List<T>>, Stream<List<T>>> inNumBatches(int numBatches) { // Keep the position separate from the possible threads to enable parallel // collection. AtomicInteger nextPos = new AtomicInteger(0); AtomicInteger numTotal = new AtomicInteger(0); return Collector.of(// instantiation () -> { ArrayList<List<T>> batches = new ArrayList<>(numBatches); for (int i = 0; i < numBatches; ++i) { batches.add(new ArrayList<>()); } return batches; }, // accumulator (batches, item) -> { int pos = nextPos.getAndUpdate(i -> (++i) % numBatches); batches.get(pos).add(item); numTotal.incrementAndGet(); }, // combiner (a, b) -> { // Merge the two lists so the batches matches the order // of the non-parallel inBatchesOf with (a1..an) + (b1..bn) // as the set of items. It's not extremely efficient, but // works fine as this is not optimized for parallel streams. for (int i = 0; i < numBatches; ++i) { List<T> al = a.get(i); List<T> bl = b.get(i); al.addAll(bl); } return a; }, // finalizer batches -> { if (numTotal.get() < numBatches) { return batches.subList(0, numTotal.get()).stream(); } return batches.stream(); }); }
java
public static <T> Collector<T, ArrayList<List<T>>, Stream<List<T>>> inNumBatches(int numBatches) { // Keep the position separate from the possible threads to enable parallel // collection. AtomicInteger nextPos = new AtomicInteger(0); AtomicInteger numTotal = new AtomicInteger(0); return Collector.of(// instantiation () -> { ArrayList<List<T>> batches = new ArrayList<>(numBatches); for (int i = 0; i < numBatches; ++i) { batches.add(new ArrayList<>()); } return batches; }, // accumulator (batches, item) -> { int pos = nextPos.getAndUpdate(i -> (++i) % numBatches); batches.get(pos).add(item); numTotal.incrementAndGet(); }, // combiner (a, b) -> { // Merge the two lists so the batches matches the order // of the non-parallel inBatchesOf with (a1..an) + (b1..bn) // as the set of items. It's not extremely efficient, but // works fine as this is not optimized for parallel streams. for (int i = 0; i < numBatches; ++i) { List<T> al = a.get(i); List<T> bl = b.get(i); al.addAll(bl); } return a; }, // finalizer batches -> { if (numTotal.get() < numBatches) { return batches.subList(0, numTotal.get()).stream(); } return batches.stream(); }); }
[ "public", "static", "<", "T", ">", "Collector", "<", "T", ",", "ArrayList", "<", "List", "<", "T", ">", ">", ",", "Stream", "<", "List", "<", "T", ">", ">", ">", "inNumBatches", "(", "int", "numBatches", ")", "{", "// Keep the position separate from the possible threads to enable parallel", "// collection.", "AtomicInteger", "nextPos", "=", "new", "AtomicInteger", "(", "0", ")", ";", "AtomicInteger", "numTotal", "=", "new", "AtomicInteger", "(", "0", ")", ";", "return", "Collector", ".", "of", "(", "// instantiation", "(", ")", "->", "{", "ArrayList", "<", "List", "<", "T", ">>", "batches", "=", "new", "ArrayList", "<>", "(", "numBatches", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numBatches", ";", "++", "i", ")", "{", "batches", ".", "add", "(", "new", "ArrayList", "<>", "(", ")", ")", ";", "}", "return", "batches", ";", "}", ",", "// accumulator", "(", "batches", ",", "item", ")", "->", "{", "int", "pos", "=", "nextPos", ".", "getAndUpdate", "(", "i", "->", "(", "++", "i", ")", "%", "numBatches", ")", ";", "batches", ".", "get", "(", "pos", ")", ".", "add", "(", "item", ")", ";", "numTotal", ".", "incrementAndGet", "(", ")", ";", "}", ",", "// combiner", "(", "a", ",", "b", ")", "->", "{", "// Merge the two lists so the batches matches the order", "// of the non-parallel inBatchesOf with (a1..an) + (b1..bn)", "// as the set of items. It's not extremely efficient, but", "// works fine as this is not optimized for parallel streams.", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numBatches", ";", "++", "i", ")", "{", "List", "<", "T", ">", "al", "=", "a", ".", "get", "(", "i", ")", ";", "List", "<", "T", ">", "bl", "=", "b", ".", "get", "(", "i", ")", ";", "al", ".", "addAll", "(", "bl", ")", ";", "}", "return", "a", ";", "}", ",", "// finalizer", "batches", "->", "{", "if", "(", "numTotal", ".", "get", "(", ")", "<", "numBatches", ")", "{", "return", "batches", ".", "subList", "(", "0", ",", "numTotal", ".", "get", "(", ")", ")", ".", "stream", "(", ")", ";", "}", "return", "batches", ".", "stream", "(", ")", ";", "}", ")", ";", "}" ]
Collect into N batches of approximate equal size. Creates a stream of lists as response. @param numBatches Number of batch to split between. @param <T> The item type. @return The stream of batched entries.
[ "Collect", "into", "N", "batches", "of", "approximate", "equal", "size", ".", "Creates", "a", "stream", "of", "lists", "as", "response", "." ]
dc987485902f1a7d58169c89c61db97425a6226d
https://github.com/morimekta/utils/blob/dc987485902f1a7d58169c89c61db97425a6226d/io-util/src/main/java/net/morimekta/util/ExtraCollectors.java#L80-L119
155,840
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getData
NodeData getData() { if (null == data) { synchronized (this) { if (null == data) { this.data = this.trie.nodes.get(index); } } } return data; }
java
NodeData getData() { if (null == data) { synchronized (this) { if (null == data) { this.data = this.trie.nodes.get(index); } } } return data; }
[ "NodeData", "getData", "(", ")", "{", "if", "(", "null", "==", "data", ")", "{", "synchronized", "(", "this", ")", "{", "if", "(", "null", "==", "data", ")", "{", "this", ".", "data", "=", "this", ".", "trie", ".", "nodes", ".", "get", "(", "index", ")", ";", "}", "}", "}", "return", "data", ";", "}" ]
Gets data. @return the data
[ "Gets", "data", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L84-L93
155,841
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.godparent
public TrieNode godparent() { if (0 == getDepth()) return null; TrieNode root = trie.root(); if (1 == getDepth()) return root; if (null != trie.godparentIndex && trie.godparentIndex.length > index) { int godparentIndex = trie.godparentIndex[this.index]; if (godparentIndex >= 0) { return newNode(godparentIndex); } } TrieNode parent = this.getParent(); TrieNode godparent; if (null == parent) { godparent = root; } else { TrieNode greatgodparent = parent.godparent(); if (null == greatgodparent) { godparent = root; } else { godparent = greatgodparent.getChild(getChar()) .map(x -> (TrieNode) x).orElseGet(() -> root); } //assert(getString().isEmpty() || getString().substring(1).equals(godparent.getString())); } if (null != godparent && null != trie.godparentIndex && trie.godparentIndex.length > index) { trie.godparentIndex[this.index] = godparent.index; } return godparent; }
java
public TrieNode godparent() { if (0 == getDepth()) return null; TrieNode root = trie.root(); if (1 == getDepth()) return root; if (null != trie.godparentIndex && trie.godparentIndex.length > index) { int godparentIndex = trie.godparentIndex[this.index]; if (godparentIndex >= 0) { return newNode(godparentIndex); } } TrieNode parent = this.getParent(); TrieNode godparent; if (null == parent) { godparent = root; } else { TrieNode greatgodparent = parent.godparent(); if (null == greatgodparent) { godparent = root; } else { godparent = greatgodparent.getChild(getChar()) .map(x -> (TrieNode) x).orElseGet(() -> root); } //assert(getString().isEmpty() || getString().substring(1).equals(godparent.getString())); } if (null != godparent && null != trie.godparentIndex && trie.godparentIndex.length > index) { trie.godparentIndex[this.index] = godparent.index; } return godparent; }
[ "public", "TrieNode", "godparent", "(", ")", "{", "if", "(", "0", "==", "getDepth", "(", ")", ")", "return", "null", ";", "TrieNode", "root", "=", "trie", ".", "root", "(", ")", ";", "if", "(", "1", "==", "getDepth", "(", ")", ")", "return", "root", ";", "if", "(", "null", "!=", "trie", ".", "godparentIndex", "&&", "trie", ".", "godparentIndex", ".", "length", ">", "index", ")", "{", "int", "godparentIndex", "=", "trie", ".", "godparentIndex", "[", "this", ".", "index", "]", ";", "if", "(", "godparentIndex", ">=", "0", ")", "{", "return", "newNode", "(", "godparentIndex", ")", ";", "}", "}", "TrieNode", "parent", "=", "this", ".", "getParent", "(", ")", ";", "TrieNode", "godparent", ";", "if", "(", "null", "==", "parent", ")", "{", "godparent", "=", "root", ";", "}", "else", "{", "TrieNode", "greatgodparent", "=", "parent", ".", "godparent", "(", ")", ";", "if", "(", "null", "==", "greatgodparent", ")", "{", "godparent", "=", "root", ";", "}", "else", "{", "godparent", "=", "greatgodparent", ".", "getChild", "(", "getChar", "(", ")", ")", ".", "map", "(", "x", "->", "(", "TrieNode", ")", "x", ")", ".", "orElseGet", "(", "(", ")", "->", "root", ")", ";", "}", "//assert(getString().isEmpty() || getString().substring(1).equals(godparent.getString()));", "}", "if", "(", "null", "!=", "godparent", "&&", "null", "!=", "trie", ".", "godparentIndex", "&&", "trie", ".", "godparentIndex", ".", "length", ">", "index", ")", "{", "trie", ".", "godparentIndex", "[", "this", ".", "index", "]", "=", "godparent", ".", "index", ";", "}", "return", "godparent", ";", "}" ]
Godparent trie node. @return the trie node
[ "Godparent", "trie", "node", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L100-L130
155,842
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getDebugString
public String getDebugString(TrieNode root) { if (this == root) return ""; String parentStr = null == getParent() ? "" : getParent().getDebugString(root); return parentStr + getDebugToken(); }
java
public String getDebugString(TrieNode root) { if (this == root) return ""; String parentStr = null == getParent() ? "" : getParent().getDebugString(root); return parentStr + getDebugToken(); }
[ "public", "String", "getDebugString", "(", "TrieNode", "root", ")", "{", "if", "(", "this", "==", "root", ")", "return", "\"\"", ";", "String", "parentStr", "=", "null", "==", "getParent", "(", ")", "?", "\"\"", ":", "getParent", "(", ")", ".", "getDebugString", "(", "root", ")", ";", "return", "parentStr", "+", "getDebugToken", "(", ")", ";", "}" ]
Gets debug string. @param root the root @return the debug string
[ "Gets", "debug", "string", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L197-L201
155,843
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getDebugToken
public String getDebugToken() { char asChar = getChar(); if (asChar == NodewalkerCodec.FALLBACK) return "<STOP>"; if (asChar == NodewalkerCodec.END_OF_STRING) return "<NULL>"; if (asChar == NodewalkerCodec.ESCAPE) return "<ESC>"; if (asChar == '\\') return "\\\\"; if (asChar == '\n') return "\\n"; return new String(new char[]{asChar}); }
java
public String getDebugToken() { char asChar = getChar(); if (asChar == NodewalkerCodec.FALLBACK) return "<STOP>"; if (asChar == NodewalkerCodec.END_OF_STRING) return "<NULL>"; if (asChar == NodewalkerCodec.ESCAPE) return "<ESC>"; if (asChar == '\\') return "\\\\"; if (asChar == '\n') return "\\n"; return new String(new char[]{asChar}); }
[ "public", "String", "getDebugToken", "(", ")", "{", "char", "asChar", "=", "getChar", "(", ")", ";", "if", "(", "asChar", "==", "NodewalkerCodec", ".", "FALLBACK", ")", "return", "\"<STOP>\"", ";", "if", "(", "asChar", "==", "NodewalkerCodec", ".", "END_OF_STRING", ")", "return", "\"<NULL>\"", ";", "if", "(", "asChar", "==", "NodewalkerCodec", ".", "ESCAPE", ")", "return", "\"<ESC>\"", ";", "if", "(", "asChar", "==", "'", "'", ")", "return", "\"\\\\\\\\\"", ";", "if", "(", "asChar", "==", "'", "'", ")", "return", "\"\\\\n\"", ";", "return", "new", "String", "(", "new", "char", "[", "]", "{", "asChar", "}", ")", ";", "}" ]
Gets debug token. @return the debug token
[ "Gets", "debug", "token", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L208-L216
155,844
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getDepth
public short getDepth() { if (0 == index) return 0; if (-1 == depth) { synchronized (this) { if (-1 == depth) { TrieNode parent = getParent(); assert (null == parent || parent.index < index); depth = (short) (null == parent ? 0 : (parent.getDepth() + 1)); } } } return depth; }
java
public short getDepth() { if (0 == index) return 0; if (-1 == depth) { synchronized (this) { if (-1 == depth) { TrieNode parent = getParent(); assert (null == parent || parent.index < index); depth = (short) (null == parent ? 0 : (parent.getDepth() + 1)); } } } return depth; }
[ "public", "short", "getDepth", "(", ")", "{", "if", "(", "0", "==", "index", ")", "return", "0", ";", "if", "(", "-", "1", "==", "depth", ")", "{", "synchronized", "(", "this", ")", "{", "if", "(", "-", "1", "==", "depth", ")", "{", "TrieNode", "parent", "=", "getParent", "(", ")", ";", "assert", "(", "null", "==", "parent", "||", "parent", ".", "index", "<", "index", ")", ";", "depth", "=", "(", "short", ")", "(", "null", "==", "parent", "?", "0", ":", "(", "parent", ".", "getDepth", "(", ")", "+", "1", ")", ")", ";", "}", "}", "}", "return", "depth", ";", "}" ]
Gets depth. @return the depth
[ "Gets", "depth", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L254-L266
155,845
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.visitFirst
public TrieNode visitFirst(Consumer<? super TrieNode> visitor) { visitor.accept(this); TrieNode refresh = refresh(); refresh.getChildren().forEach(n -> n.visitFirst(visitor)); return refresh; }
java
public TrieNode visitFirst(Consumer<? super TrieNode> visitor) { visitor.accept(this); TrieNode refresh = refresh(); refresh.getChildren().forEach(n -> n.visitFirst(visitor)); return refresh; }
[ "public", "TrieNode", "visitFirst", "(", "Consumer", "<", "?", "super", "TrieNode", ">", "visitor", ")", "{", "visitor", ".", "accept", "(", "this", ")", ";", "TrieNode", "refresh", "=", "refresh", "(", ")", ";", "refresh", ".", "getChildren", "(", ")", ".", "forEach", "(", "n", "->", "n", ".", "visitFirst", "(", "visitor", ")", ")", ";", "return", "refresh", ";", "}" ]
Visit first trie node. @param visitor the visitor @return the trie node
[ "Visit", "first", "trie", "node", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L292-L297
155,846
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.visitLast
public TrieNode visitLast(Consumer<? super TrieNode> visitor) { getChildren().forEach(n -> n.visitLast(visitor)); visitor.accept(this); return refresh(); }
java
public TrieNode visitLast(Consumer<? super TrieNode> visitor) { getChildren().forEach(n -> n.visitLast(visitor)); visitor.accept(this); return refresh(); }
[ "public", "TrieNode", "visitLast", "(", "Consumer", "<", "?", "super", "TrieNode", ">", "visitor", ")", "{", "getChildren", "(", ")", ".", "forEach", "(", "n", "->", "n", ".", "visitLast", "(", "visitor", ")", ")", ";", "visitor", ".", "accept", "(", "this", ")", ";", "return", "refresh", "(", ")", ";", "}" ]
Visit last trie node. @param visitor the visitor @return the trie node
[ "Visit", "last", "trie", "node", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L305-L309
155,847
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getChildren
public Stream<? extends TrieNode> getChildren() { if (getData().firstChildIndex >= 0) { return IntStream.range(0, getData().numberOfChildren) .mapToObj(i -> new TrieNode(this.trie, getData().firstChildIndex + i, TrieNode.this)); } else { return Stream.empty(); } }
java
public Stream<? extends TrieNode> getChildren() { if (getData().firstChildIndex >= 0) { return IntStream.range(0, getData().numberOfChildren) .mapToObj(i -> new TrieNode(this.trie, getData().firstChildIndex + i, TrieNode.this)); } else { return Stream.empty(); } }
[ "public", "Stream", "<", "?", "extends", "TrieNode", ">", "getChildren", "(", ")", "{", "if", "(", "getData", "(", ")", ".", "firstChildIndex", ">=", "0", ")", "{", "return", "IntStream", ".", "range", "(", "0", ",", "getData", "(", ")", ".", "numberOfChildren", ")", ".", "mapToObj", "(", "i", "->", "new", "TrieNode", "(", "this", ".", "trie", ",", "getData", "(", ")", ".", "firstChildIndex", "+", "i", ",", "TrieNode", ".", "this", ")", ")", ";", "}", "else", "{", "return", "Stream", ".", "empty", "(", ")", ";", "}", "}" ]
Gets children. @return the children
[ "Gets", "children", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L316-L324
155,848
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getChild
public Optional<? extends TrieNode> getChild(char token) { NodeData data = getData(); int min = data.firstChildIndex; int max = data.firstChildIndex + data.numberOfChildren - 1; while (min <= max) { int i = (min + max) / 2; TrieNode node = new TrieNode(this.trie, i, TrieNode.this); char c = node.getChar(); int compare = Character.compare(c, token); if (c < token) { // node.getChar() < token min = i + 1; } else if (c > token) { // node.getChar() > token max = i - 1; } else { return Optional.of(node); } } //assert !getChildren().keywords(x -> x.getChar() == token).findFirst().isPresent(); return Optional.empty(); }
java
public Optional<? extends TrieNode> getChild(char token) { NodeData data = getData(); int min = data.firstChildIndex; int max = data.firstChildIndex + data.numberOfChildren - 1; while (min <= max) { int i = (min + max) / 2; TrieNode node = new TrieNode(this.trie, i, TrieNode.this); char c = node.getChar(); int compare = Character.compare(c, token); if (c < token) { // node.getChar() < token min = i + 1; } else if (c > token) { // node.getChar() > token max = i - 1; } else { return Optional.of(node); } } //assert !getChildren().keywords(x -> x.getChar() == token).findFirst().isPresent(); return Optional.empty(); }
[ "public", "Optional", "<", "?", "extends", "TrieNode", ">", "getChild", "(", "char", "token", ")", "{", "NodeData", "data", "=", "getData", "(", ")", ";", "int", "min", "=", "data", ".", "firstChildIndex", ";", "int", "max", "=", "data", ".", "firstChildIndex", "+", "data", ".", "numberOfChildren", "-", "1", ";", "while", "(", "min", "<=", "max", ")", "{", "int", "i", "=", "(", "min", "+", "max", ")", "/", "2", ";", "TrieNode", "node", "=", "new", "TrieNode", "(", "this", ".", "trie", ",", "i", ",", "TrieNode", ".", "this", ")", ";", "char", "c", "=", "node", ".", "getChar", "(", ")", ";", "int", "compare", "=", "Character", ".", "compare", "(", "c", ",", "token", ")", ";", "if", "(", "c", "<", "token", ")", "{", "// node.getChar() < token", "min", "=", "i", "+", "1", ";", "}", "else", "if", "(", "c", ">", "token", ")", "{", "// node.getChar() > token", "max", "=", "i", "-", "1", ";", "}", "else", "{", "return", "Optional", ".", "of", "(", "node", ")", ";", "}", "}", "//assert !getChildren().keywords(x -> x.getChar() == token).findFirst().isPresent();", "return", "Optional", ".", "empty", "(", ")", ";", "}" ]
Gets child. @param token the token @return the child
[ "Gets", "child", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L332-L355
155,849
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.decrementCursorCount
protected void decrementCursorCount(long count) { this.trie.nodes.update(index, data -> data.setCursorCount(Math.max(data.cursorCount - count, 0))); if (null != getParent()) { getParent().decrementCursorCount(count); } }
java
protected void decrementCursorCount(long count) { this.trie.nodes.update(index, data -> data.setCursorCount(Math.max(data.cursorCount - count, 0))); if (null != getParent()) { getParent().decrementCursorCount(count); } }
[ "protected", "void", "decrementCursorCount", "(", "long", "count", ")", "{", "this", ".", "trie", ".", "nodes", ".", "update", "(", "index", ",", "data", "->", "data", ".", "setCursorCount", "(", "Math", ".", "max", "(", "data", ".", "cursorCount", "-", "count", ",", "0", ")", ")", ")", ";", "if", "(", "null", "!=", "getParent", "(", ")", ")", "{", "getParent", "(", ")", ".", "decrementCursorCount", "(", "count", ")", ";", "}", "}" ]
Decrement cursor count. @param count the count
[ "Decrement", "cursor", "count", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L362-L367
155,850
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.containsCursor
public boolean containsCursor(long cursorId) { if (cursorId < getData().firstCursorIndex) { return false; } return cursorId < (getData().firstCursorIndex + getData().cursorCount); }
java
public boolean containsCursor(long cursorId) { if (cursorId < getData().firstCursorIndex) { return false; } return cursorId < (getData().firstCursorIndex + getData().cursorCount); }
[ "public", "boolean", "containsCursor", "(", "long", "cursorId", ")", "{", "if", "(", "cursorId", "<", "getData", "(", ")", ".", "firstCursorIndex", ")", "{", "return", "false", ";", "}", "return", "cursorId", "<", "(", "getData", "(", ")", ".", "firstCursorIndex", "+", "getData", "(", ")", ".", "cursorCount", ")", ";", "}" ]
Contains cursor boolean. @param cursorId the cursor id @return the boolean
[ "Contains", "cursor", "boolean", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L388-L393
155,851
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.bitsTo
public Bits bitsTo(TrieNode toNode) { if (index == toNode.index) return Bits.NULL; return intervalTo(toNode).toBits(); }
java
public Bits bitsTo(TrieNode toNode) { if (index == toNode.index) return Bits.NULL; return intervalTo(toNode).toBits(); }
[ "public", "Bits", "bitsTo", "(", "TrieNode", "toNode", ")", "{", "if", "(", "index", "==", "toNode", ".", "index", ")", "return", "Bits", ".", "NULL", ";", "return", "intervalTo", "(", "toNode", ")", ".", "toBits", "(", ")", ";", "}" ]
Bits to bits. @param toNode the to node @return the bits
[ "Bits", "to", "bits", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L422-L425
155,852
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.intervalTo
public Interval intervalTo(TrieNode toNode) { return new Interval(toNode.getCursorIndex() - this.getCursorIndex(), toNode.getCursorCount(), this.getCursorCount()); }
java
public Interval intervalTo(TrieNode toNode) { return new Interval(toNode.getCursorIndex() - this.getCursorIndex(), toNode.getCursorCount(), this.getCursorCount()); }
[ "public", "Interval", "intervalTo", "(", "TrieNode", "toNode", ")", "{", "return", "new", "Interval", "(", "toNode", ".", "getCursorIndex", "(", ")", "-", "this", ".", "getCursorIndex", "(", ")", ",", "toNode", ".", "getCursorCount", "(", ")", ",", "this", ".", "getCursorCount", "(", ")", ")", ";", "}" ]
Interval to interval. @param toNode the to node @return the interval
[ "Interval", "to", "interval", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L433-L436
155,853
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.update
NodeData update(Function<NodeData, NodeData> update) { data = trie.nodes.update(index, update); return data; }
java
NodeData update(Function<NodeData, NodeData> update) { data = trie.nodes.update(index, update); return data; }
[ "NodeData", "update", "(", "Function", "<", "NodeData", ",", "NodeData", ">", "update", ")", "{", "data", "=", "trie", ".", "nodes", ".", "update", "(", "index", ",", "update", ")", ";", "return", "data", ";", "}" ]
Update node data. @param update the update @return the node data
[ "Update", "node", "data", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L453-L456
155,854
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.isStringTerminal
public boolean isStringTerminal() { if (getChar() == NodewalkerCodec.END_OF_STRING) return true; if (getChar() == NodewalkerCodec.FALLBACK && null != getParent()) return getParent().isStringTerminal(); return false; }
java
public boolean isStringTerminal() { if (getChar() == NodewalkerCodec.END_OF_STRING) return true; if (getChar() == NodewalkerCodec.FALLBACK && null != getParent()) return getParent().isStringTerminal(); return false; }
[ "public", "boolean", "isStringTerminal", "(", ")", "{", "if", "(", "getChar", "(", ")", "==", "NodewalkerCodec", ".", "END_OF_STRING", ")", "return", "true", ";", "if", "(", "getChar", "(", ")", "==", "NodewalkerCodec", ".", "FALLBACK", "&&", "null", "!=", "getParent", "(", ")", ")", "return", "getParent", "(", ")", ".", "isStringTerminal", "(", ")", ";", "return", "false", ";", "}" ]
Is string terminal boolean. @return the boolean
[ "Is", "string", "terminal", "boolean", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L472-L476
155,855
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.streamDecendents
public Stream<? extends TrieNode> streamDecendents(int level) { assert (level > 0); if (level == 1) { return getChildren(); } else { return getChildren().flatMap(child -> child.streamDecendents(level - 1)); } }
java
public Stream<? extends TrieNode> streamDecendents(int level) { assert (level > 0); if (level == 1) { return getChildren(); } else { return getChildren().flatMap(child -> child.streamDecendents(level - 1)); } }
[ "public", "Stream", "<", "?", "extends", "TrieNode", ">", "streamDecendents", "(", "int", "level", ")", "{", "assert", "(", "level", ">", "0", ")", ";", "if", "(", "level", "==", "1", ")", "{", "return", "getChildren", "(", ")", ";", "}", "else", "{", "return", "getChildren", "(", ")", ".", "flatMap", "(", "child", "->", "child", ".", "streamDecendents", "(", "level", "-", "1", ")", ")", ";", "}", "}" ]
Stream decendents stream. @param level the level @return the stream
[ "Stream", "decendents", "stream", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L484-L492
155,856
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.writeChildren
void writeChildren(TreeMap<Character, Long> counts) { int firstIndex = trie.nodes.length(); counts.forEach((k, v) -> { if (v > 0) trie.nodes.add(new NodeData(k, (short) -1, -1, v, -1)); }); short length = (short) (trie.nodes.length() - firstIndex); trie.ensureParentIndexCapacity(firstIndex, length, index); update(n -> n.setFirstChildIndex(firstIndex).setNumberOfChildren(length)); data = null; }
java
void writeChildren(TreeMap<Character, Long> counts) { int firstIndex = trie.nodes.length(); counts.forEach((k, v) -> { if (v > 0) trie.nodes.add(new NodeData(k, (short) -1, -1, v, -1)); }); short length = (short) (trie.nodes.length() - firstIndex); trie.ensureParentIndexCapacity(firstIndex, length, index); update(n -> n.setFirstChildIndex(firstIndex).setNumberOfChildren(length)); data = null; }
[ "void", "writeChildren", "(", "TreeMap", "<", "Character", ",", "Long", ">", "counts", ")", "{", "int", "firstIndex", "=", "trie", ".", "nodes", ".", "length", "(", ")", ";", "counts", ".", "forEach", "(", "(", "k", ",", "v", ")", "->", "{", "if", "(", "v", ">", "0", ")", "trie", ".", "nodes", ".", "add", "(", "new", "NodeData", "(", "k", ",", "(", "short", ")", "-", "1", ",", "-", "1", ",", "v", ",", "-", "1", ")", ")", ";", "}", ")", ";", "short", "length", "=", "(", "short", ")", "(", "trie", ".", "nodes", ".", "length", "(", ")", "-", "firstIndex", ")", ";", "trie", ".", "ensureParentIndexCapacity", "(", "firstIndex", ",", "length", ",", "index", ")", ";", "update", "(", "n", "->", "n", ".", "setFirstChildIndex", "(", "firstIndex", ")", ".", "setNumberOfChildren", "(", "length", ")", ")", ";", "data", "=", "null", ";", "}" ]
Write children. @param counts the counts
[ "Write", "children", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L499-L508
155,857
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getChildrenMap
public TreeMap<Character, ? extends TrieNode> getChildrenMap() { TreeMap<Character, TrieNode> map = new TreeMap<>(); getChildren().forEach(x -> map.put(x.getChar(), x)); return map; }
java
public TreeMap<Character, ? extends TrieNode> getChildrenMap() { TreeMap<Character, TrieNode> map = new TreeMap<>(); getChildren().forEach(x -> map.put(x.getChar(), x)); return map; }
[ "public", "TreeMap", "<", "Character", ",", "?", "extends", "TrieNode", ">", "getChildrenMap", "(", ")", "{", "TreeMap", "<", "Character", ",", "TrieNode", ">", "map", "=", "new", "TreeMap", "<>", "(", ")", ";", "getChildren", "(", ")", ".", "forEach", "(", "x", "->", "map", ".", "put", "(", "x", ".", "getChar", "(", ")", ",", "x", ")", ")", ";", "return", "map", ";", "}" ]
Gets children map. @return the children map
[ "Gets", "children", "map", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L515-L519
155,858
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getGodChildren
public Map<Character, TrieNode> getGodChildren() { String postContext = this.getString().substring(1); return trie.tokens().stream().collect(Collectors.toMap(x -> x, token -> { TrieNode traverse = trie.traverse(token + postContext); return traverse.getString().equals(token + postContext) ? traverse : null; })).entrySet().stream().filter(e -> null != e.getValue()).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); }
java
public Map<Character, TrieNode> getGodChildren() { String postContext = this.getString().substring(1); return trie.tokens().stream().collect(Collectors.toMap(x -> x, token -> { TrieNode traverse = trie.traverse(token + postContext); return traverse.getString().equals(token + postContext) ? traverse : null; })).entrySet().stream().filter(e -> null != e.getValue()).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); }
[ "public", "Map", "<", "Character", ",", "TrieNode", ">", "getGodChildren", "(", ")", "{", "String", "postContext", "=", "this", ".", "getString", "(", ")", ".", "substring", "(", "1", ")", ";", "return", "trie", ".", "tokens", "(", ")", ".", "stream", "(", ")", ".", "collect", "(", "Collectors", ".", "toMap", "(", "x", "->", "x", ",", "token", "->", "{", "TrieNode", "traverse", "=", "trie", ".", "traverse", "(", "token", "+", "postContext", ")", ";", "return", "traverse", ".", "getString", "(", ")", ".", "equals", "(", "token", "+", "postContext", ")", "?", "traverse", ":", "null", ";", "}", ")", ")", ".", "entrySet", "(", ")", ".", "stream", "(", ")", ".", "filter", "(", "e", "->", "null", "!=", "e", ".", "getValue", "(", ")", ")", ".", "collect", "(", "Collectors", ".", "toMap", "(", "e", "->", "e", ".", "getKey", "(", ")", ",", "e", "->", "e", ".", "getValue", "(", ")", ")", ")", ";", "}" ]
Gets god children. @return the god children
[ "Gets", "god", "children", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L526-L532
155,859
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getParent
public TrieNode getParent() { if (0 == index) return null; if (null == parent && -1 == depth) { synchronized (this) { if (null == parent) { parent = newNode(trie.parentIndex[index]); assert (parent.index < index); } } } return parent; }
java
public TrieNode getParent() { if (0 == index) return null; if (null == parent && -1 == depth) { synchronized (this) { if (null == parent) { parent = newNode(trie.parentIndex[index]); assert (parent.index < index); } } } return parent; }
[ "public", "TrieNode", "getParent", "(", ")", "{", "if", "(", "0", "==", "index", ")", "return", "null", ";", "if", "(", "null", "==", "parent", "&&", "-", "1", "==", "depth", ")", "{", "synchronized", "(", "this", ")", "{", "if", "(", "null", "==", "parent", ")", "{", "parent", "=", "newNode", "(", "trie", ".", "parentIndex", "[", "index", "]", ")", ";", "assert", "(", "parent", ".", "index", "<", "index", ")", ";", "}", "}", "}", "return", "parent", ";", "}" ]
Gets parent. @return the parent
[ "Gets", "parent", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L554-L565
155,860
SimiaCryptus/utilities
java-util/src/main/java/com/simiacryptus/text/TrieNode.java
TrieNode.getContinuation
public TrieNode getContinuation(char c) { return ((Optional<TrieNode>) getChild(c)).orElseGet(() -> { TrieNode godparent = godparent(); if (null == godparent) return null; return godparent.getContinuation(c); }); }
java
public TrieNode getContinuation(char c) { return ((Optional<TrieNode>) getChild(c)).orElseGet(() -> { TrieNode godparent = godparent(); if (null == godparent) return null; return godparent.getContinuation(c); }); }
[ "public", "TrieNode", "getContinuation", "(", "char", "c", ")", "{", "return", "(", "(", "Optional", "<", "TrieNode", ">", ")", "getChild", "(", "c", ")", ")", ".", "orElseGet", "(", "(", ")", "->", "{", "TrieNode", "godparent", "=", "godparent", "(", ")", ";", "if", "(", "null", "==", "godparent", ")", "return", "null", ";", "return", "godparent", ".", "getContinuation", "(", "c", ")", ";", "}", ")", ";", "}" ]
Gets continuation. @param c the c @return the continuation
[ "Gets", "continuation", "." ]
b5a5e73449aae57de7dbfca2ed7a074432c5b17e
https://github.com/SimiaCryptus/utilities/blob/b5a5e73449aae57de7dbfca2ed7a074432c5b17e/java-util/src/main/java/com/simiacryptus/text/TrieNode.java#L573-L579
155,861
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.mapToPtPath
public static String mapToPtPath(final String aID) { Objects.requireNonNull(aID); final String encodedID = encodeID(aID); final List<String> shorties = new ArrayList<>(); int start = 0; while (start < encodedID.length()) { int end = start + myShortyLength; if (end > encodedID.length()) { end = encodedID.length(); } shorties.add(encodedID.substring(start, end)); start = end; } return concat(shorties.toArray(new String[0])); }
java
public static String mapToPtPath(final String aID) { Objects.requireNonNull(aID); final String encodedID = encodeID(aID); final List<String> shorties = new ArrayList<>(); int start = 0; while (start < encodedID.length()) { int end = start + myShortyLength; if (end > encodedID.length()) { end = encodedID.length(); } shorties.add(encodedID.substring(start, end)); start = end; } return concat(shorties.toArray(new String[0])); }
[ "public", "static", "String", "mapToPtPath", "(", "final", "String", "aID", ")", "{", "Objects", ".", "requireNonNull", "(", "aID", ")", ";", "final", "String", "encodedID", "=", "encodeID", "(", "aID", ")", ";", "final", "List", "<", "String", ">", "shorties", "=", "new", "ArrayList", "<>", "(", ")", ";", "int", "start", "=", "0", ";", "while", "(", "start", "<", "encodedID", ".", "length", "(", ")", ")", "{", "int", "end", "=", "start", "+", "myShortyLength", ";", "if", "(", "end", ">", "encodedID", ".", "length", "(", ")", ")", "{", "end", "=", "encodedID", ".", "length", "(", ")", ";", "}", "shorties", ".", "add", "(", "encodedID", ".", "substring", "(", "start", ",", "end", ")", ")", ";", "start", "=", "end", ";", "}", "return", "concat", "(", "shorties", ".", "toArray", "(", "new", "String", "[", "0", "]", ")", ")", ";", "}" ]
Maps the supplied ID to a Pairtree path. @param aID An ID to map to a Pairtree path @return The Pairtree path for the supplied ID
[ "Maps", "the", "supplied", "ID", "to", "a", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L135-L155
155,862
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.mapToID
public static String mapToID(final String aBasePath, final String aPtPath) throws InvalidPathException { return mapToID(removeBasePath(aBasePath, aPtPath)); }
java
public static String mapToID(final String aBasePath, final String aPtPath) throws InvalidPathException { return mapToID(removeBasePath(aBasePath, aPtPath)); }
[ "public", "static", "String", "mapToID", "(", "final", "String", "aBasePath", ",", "final", "String", "aPtPath", ")", "throws", "InvalidPathException", "{", "return", "mapToID", "(", "removeBasePath", "(", "aBasePath", ",", "aPtPath", ")", ")", ";", "}" ]
Maps the supplied base path to an ID using the supplied Pairtree path. @param aBasePath A base path to use for the mapping @param aPtPath A Pairtree path to map to an ID @return The ID that is a result of the mapping @throws InvalidPathException If there is trouble mapping the path
[ "Maps", "the", "supplied", "base", "path", "to", "an", "ID", "using", "the", "supplied", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L198-L200
155,863
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.mapToID
public static String mapToID(final String aPtPath) throws InvalidPathException { final String encapsulatingDir = getEncapsulatingDir(aPtPath); String id = aPtPath; if (id.endsWith(Character.toString(mySeparator))) { id = id.substring(0, id.length() - 1); } if (encapsulatingDir != null) { id = id.substring(0, id.length() - encapsulatingDir.length()); } id = id.replace(Character.toString(mySeparator), ""); id = decodeID(id); return id; }
java
public static String mapToID(final String aPtPath) throws InvalidPathException { final String encapsulatingDir = getEncapsulatingDir(aPtPath); String id = aPtPath; if (id.endsWith(Character.toString(mySeparator))) { id = id.substring(0, id.length() - 1); } if (encapsulatingDir != null) { id = id.substring(0, id.length() - encapsulatingDir.length()); } id = id.replace(Character.toString(mySeparator), ""); id = decodeID(id); return id; }
[ "public", "static", "String", "mapToID", "(", "final", "String", "aPtPath", ")", "throws", "InvalidPathException", "{", "final", "String", "encapsulatingDir", "=", "getEncapsulatingDir", "(", "aPtPath", ")", ";", "String", "id", "=", "aPtPath", ";", "if", "(", "id", ".", "endsWith", "(", "Character", ".", "toString", "(", "mySeparator", ")", ")", ")", "{", "id", "=", "id", ".", "substring", "(", "0", ",", "id", ".", "length", "(", ")", "-", "1", ")", ";", "}", "if", "(", "encapsulatingDir", "!=", "null", ")", "{", "id", "=", "id", ".", "substring", "(", "0", ",", "id", ".", "length", "(", ")", "-", "encapsulatingDir", ".", "length", "(", ")", ")", ";", "}", "id", "=", "id", ".", "replace", "(", "Character", ".", "toString", "(", "mySeparator", ")", ",", "\"\"", ")", ";", "id", "=", "decodeID", "(", "id", ")", ";", "return", "id", ";", "}" ]
Maps the supplied base path to an ID. @param aPtPath A Pairtree path to map to an ID @return The ID that is a result of the mapping @throws InvalidPathException If there is trouble mapping the path
[ "Maps", "the", "supplied", "base", "path", "to", "an", "ID", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L209-L226
155,864
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.getEncapsulatingDir
public static String getEncapsulatingDir(final String aBasePath, final String aPtPath) throws InvalidPathException { return getEncapsulatingDir(removeBasePath(aBasePath, aPtPath)); }
java
public static String getEncapsulatingDir(final String aBasePath, final String aPtPath) throws InvalidPathException { return getEncapsulatingDir(removeBasePath(aBasePath, aPtPath)); }
[ "public", "static", "String", "getEncapsulatingDir", "(", "final", "String", "aBasePath", ",", "final", "String", "aPtPath", ")", "throws", "InvalidPathException", "{", "return", "getEncapsulatingDir", "(", "removeBasePath", "(", "aBasePath", ",", "aPtPath", ")", ")", ";", "}" ]
Extracts the encapsulating directory from the supplied Pairtree path, using the supplied base path. @param aBasePath A base path for the Pairtree path @param aPtPath The Pairtree path @return The name of the encapsulating directory @throws InvalidPathException If there is a problem extracting the encapsulating directory
[ "Extracts", "the", "encapsulating", "directory", "from", "the", "supplied", "Pairtree", "path", "using", "the", "supplied", "base", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L236-L239
155,865
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.getEncapsulatingDir
public static String getEncapsulatingDir(final String aPtPath) throws InvalidPathException { Objects.requireNonNull(aPtPath, LOGGER.getMessage(MessageCodes.PT_003)); // Walk the Pairtree path looking for first non-shorty final String[] pPathParts = aPtPath.split("\\" + mySeparator); // If there is only 1 part if (pPathParts.length == SINGLE_PART) { // If part <= shorty length then no encapsulating directory if (pPathParts[0].length() <= myShortyLength) { return null; } else { // Else no Pairtree path throw new InvalidPathException(MessageCodes.PT_001, aPtPath); } } // All parts up to next to last and last should have shorty length for (int index = 0; index < pPathParts.length - 2; index++) { if (pPathParts[index].length() != myShortyLength) { throw new InvalidPathException(MessageCodes.PT_002, myShortyLength, pPathParts[index].length(), aPtPath); } } final String nextToLastPart = pPathParts[pPathParts.length - 2]; // Next to last should have shorty length or less if (nextToLastPart.length() > myShortyLength) { throw new InvalidPathException(MessageCodes.PT_005, aPtPath); } String lastPart = pPathParts[pPathParts.length - 1]; // If next to last has shorty length if (nextToLastPart.length() == myShortyLength) { // If last has length > shorty length then encapsulating directory if (lastPart.length() > myShortyLength) { lastPart = decodeID(lastPart); } else { // Else no encapsulating directory lastPart = null; } } // Else last is encapsulating directory return lastPart == null ? null : decodeID(lastPart); }
java
public static String getEncapsulatingDir(final String aPtPath) throws InvalidPathException { Objects.requireNonNull(aPtPath, LOGGER.getMessage(MessageCodes.PT_003)); // Walk the Pairtree path looking for first non-shorty final String[] pPathParts = aPtPath.split("\\" + mySeparator); // If there is only 1 part if (pPathParts.length == SINGLE_PART) { // If part <= shorty length then no encapsulating directory if (pPathParts[0].length() <= myShortyLength) { return null; } else { // Else no Pairtree path throw new InvalidPathException(MessageCodes.PT_001, aPtPath); } } // All parts up to next to last and last should have shorty length for (int index = 0; index < pPathParts.length - 2; index++) { if (pPathParts[index].length() != myShortyLength) { throw new InvalidPathException(MessageCodes.PT_002, myShortyLength, pPathParts[index].length(), aPtPath); } } final String nextToLastPart = pPathParts[pPathParts.length - 2]; // Next to last should have shorty length or less if (nextToLastPart.length() > myShortyLength) { throw new InvalidPathException(MessageCodes.PT_005, aPtPath); } String lastPart = pPathParts[pPathParts.length - 1]; // If next to last has shorty length if (nextToLastPart.length() == myShortyLength) { // If last has length > shorty length then encapsulating directory if (lastPart.length() > myShortyLength) { lastPart = decodeID(lastPart); } else { // Else no encapsulating directory lastPart = null; } } // Else last is encapsulating directory return lastPart == null ? null : decodeID(lastPart); }
[ "public", "static", "String", "getEncapsulatingDir", "(", "final", "String", "aPtPath", ")", "throws", "InvalidPathException", "{", "Objects", ".", "requireNonNull", "(", "aPtPath", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_003", ")", ")", ";", "// Walk the Pairtree path looking for first non-shorty", "final", "String", "[", "]", "pPathParts", "=", "aPtPath", ".", "split", "(", "\"\\\\\"", "+", "mySeparator", ")", ";", "// If there is only 1 part", "if", "(", "pPathParts", ".", "length", "==", "SINGLE_PART", ")", "{", "// If part <= shorty length then no encapsulating directory", "if", "(", "pPathParts", "[", "0", "]", ".", "length", "(", ")", "<=", "myShortyLength", ")", "{", "return", "null", ";", "}", "else", "{", "// Else no Pairtree path", "throw", "new", "InvalidPathException", "(", "MessageCodes", ".", "PT_001", ",", "aPtPath", ")", ";", "}", "}", "// All parts up to next to last and last should have shorty length", "for", "(", "int", "index", "=", "0", ";", "index", "<", "pPathParts", ".", "length", "-", "2", ";", "index", "++", ")", "{", "if", "(", "pPathParts", "[", "index", "]", ".", "length", "(", ")", "!=", "myShortyLength", ")", "{", "throw", "new", "InvalidPathException", "(", "MessageCodes", ".", "PT_002", ",", "myShortyLength", ",", "pPathParts", "[", "index", "]", ".", "length", "(", ")", ",", "aPtPath", ")", ";", "}", "}", "final", "String", "nextToLastPart", "=", "pPathParts", "[", "pPathParts", ".", "length", "-", "2", "]", ";", "// Next to last should have shorty length or less", "if", "(", "nextToLastPart", ".", "length", "(", ")", ">", "myShortyLength", ")", "{", "throw", "new", "InvalidPathException", "(", "MessageCodes", ".", "PT_005", ",", "aPtPath", ")", ";", "}", "String", "lastPart", "=", "pPathParts", "[", "pPathParts", ".", "length", "-", "1", "]", ";", "// If next to last has shorty length", "if", "(", "nextToLastPart", ".", "length", "(", ")", "==", "myShortyLength", ")", "{", "// If last has length > shorty length then encapsulating directory", "if", "(", "lastPart", ".", "length", "(", ")", ">", "myShortyLength", ")", "{", "lastPart", "=", "decodeID", "(", "lastPart", ")", ";", "}", "else", "{", "// Else no encapsulating directory", "lastPart", "=", "null", ";", "}", "}", "// Else last is encapsulating directory", "return", "lastPart", "==", "null", "?", "null", ":", "decodeID", "(", "lastPart", ")", ";", "}" ]
Extracts the encapsulating directory from the supplied Pairtree path. @param aPtPath The Pairtree path from which to extract the encapsulating directory @return The name of the encapsulating directory @throws InvalidPathException If there is a problem extracting the encapsulating directory
[ "Extracts", "the", "encapsulating", "directory", "from", "the", "supplied", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L248-L295
155,866
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.concat
private static String concat(final String... aPathsVarargs) { final String path; Objects.requireNonNull(aPathsVarargs); if (aPathsVarargs.length == 0) { path = ""; } else { final StringBuffer pathBuf = new StringBuffer(); Character lastChar = null; for (final String aPathsVararg : aPathsVarargs) { if (aPathsVararg != null) { final int length; if (lastChar != null && !mySeparator.equals(lastChar)) { pathBuf.append(mySeparator); } pathBuf.append(aPathsVararg); length = aPathsVararg.length(); lastChar = aPathsVararg.charAt(length - 1); } } path = pathBuf.toString(); } return path; }
java
private static String concat(final String... aPathsVarargs) { final String path; Objects.requireNonNull(aPathsVarargs); if (aPathsVarargs.length == 0) { path = ""; } else { final StringBuffer pathBuf = new StringBuffer(); Character lastChar = null; for (final String aPathsVararg : aPathsVarargs) { if (aPathsVararg != null) { final int length; if (lastChar != null && !mySeparator.equals(lastChar)) { pathBuf.append(mySeparator); } pathBuf.append(aPathsVararg); length = aPathsVararg.length(); lastChar = aPathsVararg.charAt(length - 1); } } path = pathBuf.toString(); } return path; }
[ "private", "static", "String", "concat", "(", "final", "String", "...", "aPathsVarargs", ")", "{", "final", "String", "path", ";", "Objects", ".", "requireNonNull", "(", "aPathsVarargs", ")", ";", "if", "(", "aPathsVarargs", ".", "length", "==", "0", ")", "{", "path", "=", "\"\"", ";", "}", "else", "{", "final", "StringBuffer", "pathBuf", "=", "new", "StringBuffer", "(", ")", ";", "Character", "lastChar", "=", "null", ";", "for", "(", "final", "String", "aPathsVararg", ":", "aPathsVarargs", ")", "{", "if", "(", "aPathsVararg", "!=", "null", ")", "{", "final", "int", "length", ";", "if", "(", "lastChar", "!=", "null", "&&", "!", "mySeparator", ".", "equals", "(", "lastChar", ")", ")", "{", "pathBuf", ".", "append", "(", "mySeparator", ")", ";", "}", "pathBuf", ".", "append", "(", "aPathsVararg", ")", ";", "length", "=", "aPathsVararg", ".", "length", "(", ")", ";", "lastChar", "=", "aPathsVararg", ".", "charAt", "(", "length", "-", "1", ")", ";", "}", "}", "path", "=", "pathBuf", ".", "toString", "(", ")", ";", "}", "return", "path", ";", "}" ]
Concatenates the Pairtree paths varargs. @param aPathsVarargs The Pairtree paths varargs @return The concatenated Pairtree paths
[ "Concatenates", "the", "Pairtree", "paths", "varargs", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L303-L333
155,867
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.removePrefix
public static String removePrefix(final String aPrefix, final String aID) { Objects.requireNonNull(aPrefix, LOGGER.getMessage(MessageCodes.PT_006)); Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final String id; if (aID.indexOf(aPrefix) == 0) { id = aID.substring(aPrefix.length()); } else { id = aID; } return id; }
java
public static String removePrefix(final String aPrefix, final String aID) { Objects.requireNonNull(aPrefix, LOGGER.getMessage(MessageCodes.PT_006)); Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final String id; if (aID.indexOf(aPrefix) == 0) { id = aID.substring(aPrefix.length()); } else { id = aID; } return id; }
[ "public", "static", "String", "removePrefix", "(", "final", "String", "aPrefix", ",", "final", "String", "aID", ")", "{", "Objects", ".", "requireNonNull", "(", "aPrefix", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_006", ")", ")", ";", "Objects", ".", "requireNonNull", "(", "aID", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_004", ")", ")", ";", "final", "String", "id", ";", "if", "(", "aID", ".", "indexOf", "(", "aPrefix", ")", "==", "0", ")", "{", "id", "=", "aID", ".", "substring", "(", "aPrefix", ".", "length", "(", ")", ")", ";", "}", "else", "{", "id", "=", "aID", ";", "}", "return", "id", ";", "}" ]
Removes the supplied Pairtree prefix from the supplied ID. @param aPrefix A Pairtree prefix @param aID An ID @return The ID without the Pairtree prefix prepended to it @throws PairtreeRuntimeException If the supplied prefix or ID is null
[ "Removes", "the", "supplied", "Pairtree", "prefix", "from", "the", "supplied", "ID", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L343-L356
155,868
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.removeBasePath
public static String removeBasePath(final String aBasePath, final String aPtPath) { Objects.requireNonNull(aBasePath, LOGGER.getMessage(MessageCodes.PT_007)); Objects.requireNonNull(aPtPath, LOGGER.getMessage(MessageCodes.PT_003)); String newPath = aPtPath; if (aPtPath.startsWith(aBasePath)) { newPath = newPath.substring(aBasePath.length()); if (newPath.startsWith(Character.toString(mySeparator))) { newPath = newPath.substring(1); } } return newPath; }
java
public static String removeBasePath(final String aBasePath, final String aPtPath) { Objects.requireNonNull(aBasePath, LOGGER.getMessage(MessageCodes.PT_007)); Objects.requireNonNull(aPtPath, LOGGER.getMessage(MessageCodes.PT_003)); String newPath = aPtPath; if (aPtPath.startsWith(aBasePath)) { newPath = newPath.substring(aBasePath.length()); if (newPath.startsWith(Character.toString(mySeparator))) { newPath = newPath.substring(1); } } return newPath; }
[ "public", "static", "String", "removeBasePath", "(", "final", "String", "aBasePath", ",", "final", "String", "aPtPath", ")", "{", "Objects", ".", "requireNonNull", "(", "aBasePath", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_007", ")", ")", ";", "Objects", ".", "requireNonNull", "(", "aPtPath", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_003", ")", ")", ";", "String", "newPath", "=", "aPtPath", ";", "if", "(", "aPtPath", ".", "startsWith", "(", "aBasePath", ")", ")", "{", "newPath", "=", "newPath", ".", "substring", "(", "aBasePath", ".", "length", "(", ")", ")", ";", "if", "(", "newPath", ".", "startsWith", "(", "Character", ".", "toString", "(", "mySeparator", ")", ")", ")", "{", "newPath", "=", "newPath", ".", "substring", "(", "1", ")", ";", "}", "}", "return", "newPath", ";", "}" ]
Removes the base path from the supplied Pairtree path. @param aBasePath A base path for a Pairtree path @param aPtPath A Pairtree path @return The Pairtree path without the base path @throws PairtreeRuntimeException If the supplied base path or Pairtree path are null
[ "Removes", "the", "base", "path", "from", "the", "supplied", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L366-L381
155,869
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.encodeID
@SuppressWarnings("checkstyle:BooleanExpressionComplexity") public static String encodeID(final String aID) { Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final byte[] bytes; try { bytes = aID.getBytes("utf-8"); } catch (final UnsupportedEncodingException details) { throw new PairtreeRuntimeException(MessageCodes.PT_008, details); } final StringBuffer idBuffer = new StringBuffer(); for (final byte b : bytes) { final int i = b & 0xff; if (i < 0x21 || i > 0x7e || i == 0x22 || i == 0x2a || i == 0x2b || i == 0x2c || i == 0x3c || i == 0x3d || i == 0x3e || i == 0x3f || i == 0x5c || i == 0x5e || i == 0x7c) { // Encode idBuffer.append(HEX_INDICATOR); idBuffer.append(Integer.toHexString(i)); } else { // Don't encode final char[] chars = Character.toChars(i); assert chars.length == 1; idBuffer.append(chars[0]); } } for (int index = 0; index < idBuffer.length(); index++) { final char character = idBuffer.charAt(index); // Encode characters that need to be encoded according to Pairtree specification if (character == PATH_SEP) { idBuffer.setCharAt(index, EQUALS_SIGN); } else if (character == COLON) { idBuffer.setCharAt(index, PLUS_SIGN); } else if (character == PERIOD) { idBuffer.setCharAt(index, COMMA); } } return idBuffer.toString(); }
java
@SuppressWarnings("checkstyle:BooleanExpressionComplexity") public static String encodeID(final String aID) { Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final byte[] bytes; try { bytes = aID.getBytes("utf-8"); } catch (final UnsupportedEncodingException details) { throw new PairtreeRuntimeException(MessageCodes.PT_008, details); } final StringBuffer idBuffer = new StringBuffer(); for (final byte b : bytes) { final int i = b & 0xff; if (i < 0x21 || i > 0x7e || i == 0x22 || i == 0x2a || i == 0x2b || i == 0x2c || i == 0x3c || i == 0x3d || i == 0x3e || i == 0x3f || i == 0x5c || i == 0x5e || i == 0x7c) { // Encode idBuffer.append(HEX_INDICATOR); idBuffer.append(Integer.toHexString(i)); } else { // Don't encode final char[] chars = Character.toChars(i); assert chars.length == 1; idBuffer.append(chars[0]); } } for (int index = 0; index < idBuffer.length(); index++) { final char character = idBuffer.charAt(index); // Encode characters that need to be encoded according to Pairtree specification if (character == PATH_SEP) { idBuffer.setCharAt(index, EQUALS_SIGN); } else if (character == COLON) { idBuffer.setCharAt(index, PLUS_SIGN); } else if (character == PERIOD) { idBuffer.setCharAt(index, COMMA); } } return idBuffer.toString(); }
[ "@", "SuppressWarnings", "(", "\"checkstyle:BooleanExpressionComplexity\"", ")", "public", "static", "String", "encodeID", "(", "final", "String", "aID", ")", "{", "Objects", ".", "requireNonNull", "(", "aID", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_004", ")", ")", ";", "final", "byte", "[", "]", "bytes", ";", "try", "{", "bytes", "=", "aID", ".", "getBytes", "(", "\"utf-8\"", ")", ";", "}", "catch", "(", "final", "UnsupportedEncodingException", "details", ")", "{", "throw", "new", "PairtreeRuntimeException", "(", "MessageCodes", ".", "PT_008", ",", "details", ")", ";", "}", "final", "StringBuffer", "idBuffer", "=", "new", "StringBuffer", "(", ")", ";", "for", "(", "final", "byte", "b", ":", "bytes", ")", "{", "final", "int", "i", "=", "b", "&", "0xff", ";", "if", "(", "i", "<", "0x21", "||", "i", ">", "0x7e", "||", "i", "==", "0x22", "||", "i", "==", "0x2a", "||", "i", "==", "0x2b", "||", "i", "==", "0x2c", "||", "i", "==", "0x3c", "||", "i", "==", "0x3d", "||", "i", "==", "0x3e", "||", "i", "==", "0x3f", "||", "i", "==", "0x5c", "||", "i", "==", "0x5e", "||", "i", "==", "0x7c", ")", "{", "// Encode", "idBuffer", ".", "append", "(", "HEX_INDICATOR", ")", ";", "idBuffer", ".", "append", "(", "Integer", ".", "toHexString", "(", "i", ")", ")", ";", "}", "else", "{", "// Don't encode", "final", "char", "[", "]", "chars", "=", "Character", ".", "toChars", "(", "i", ")", ";", "assert", "chars", ".", "length", "==", "1", ";", "idBuffer", ".", "append", "(", "chars", "[", "0", "]", ")", ";", "}", "}", "for", "(", "int", "index", "=", "0", ";", "index", "<", "idBuffer", ".", "length", "(", ")", ";", "index", "++", ")", "{", "final", "char", "character", "=", "idBuffer", ".", "charAt", "(", "index", ")", ";", "// Encode characters that need to be encoded according to Pairtree specification", "if", "(", "character", "==", "PATH_SEP", ")", "{", "idBuffer", ".", "setCharAt", "(", "index", ",", "EQUALS_SIGN", ")", ";", "}", "else", "if", "(", "character", "==", "COLON", ")", "{", "idBuffer", ".", "setCharAt", "(", "index", ",", "PLUS_SIGN", ")", ";", "}", "else", "if", "(", "character", "==", "PERIOD", ")", "{", "idBuffer", ".", "setCharAt", "(", "index", ",", "COMMA", ")", ";", "}", "}", "return", "idBuffer", ".", "toString", "(", ")", ";", "}" ]
Cleans an ID for use in a Pairtree path. @param aID An idea to be cleaned @return The cleaned ID for use in a Pairtree path @throws PairtreeRuntimeException If the supplied ID is null
[ "Cleans", "an", "ID", "for", "use", "in", "a", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L390-L435
155,870
ksclarke/vertx-pairtree
src/main/java/info/freelibrary/pairtree/PairtreeUtils.java
PairtreeUtils.decodeID
public static String decodeID(final String aID) { Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final StringBuilder idBuf = new StringBuilder(); for (int index = 0; index < aID.length(); index++) { final char character = aID.charAt(index); // Decode characters that need to be decoded according to Pairtree specification if (character == EQUALS_SIGN) { idBuf.append(PATH_SEP); } else if (character == PLUS_SIGN) { idBuf.append(COLON); } else if (character == COMMA) { idBuf.append(PERIOD); } else if (character == HEX_INDICATOR) { /* Get the next two characters since they are hex characters */ final String hex = aID.substring(index + 1, index + 3); final char[] chars = Character.toChars(Integer.parseInt(hex, 16)); assert chars.length == 1; idBuf.append(chars[0]); index = index + 2; } else { idBuf.append(character); } } return idBuf.toString(); }
java
public static String decodeID(final String aID) { Objects.requireNonNull(aID, LOGGER.getMessage(MessageCodes.PT_004)); final StringBuilder idBuf = new StringBuilder(); for (int index = 0; index < aID.length(); index++) { final char character = aID.charAt(index); // Decode characters that need to be decoded according to Pairtree specification if (character == EQUALS_SIGN) { idBuf.append(PATH_SEP); } else if (character == PLUS_SIGN) { idBuf.append(COLON); } else if (character == COMMA) { idBuf.append(PERIOD); } else if (character == HEX_INDICATOR) { /* Get the next two characters since they are hex characters */ final String hex = aID.substring(index + 1, index + 3); final char[] chars = Character.toChars(Integer.parseInt(hex, 16)); assert chars.length == 1; idBuf.append(chars[0]); index = index + 2; } else { idBuf.append(character); } } return idBuf.toString(); }
[ "public", "static", "String", "decodeID", "(", "final", "String", "aID", ")", "{", "Objects", ".", "requireNonNull", "(", "aID", ",", "LOGGER", ".", "getMessage", "(", "MessageCodes", ".", "PT_004", ")", ")", ";", "final", "StringBuilder", "idBuf", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "index", "=", "0", ";", "index", "<", "aID", ".", "length", "(", ")", ";", "index", "++", ")", "{", "final", "char", "character", "=", "aID", ".", "charAt", "(", "index", ")", ";", "// Decode characters that need to be decoded according to Pairtree specification", "if", "(", "character", "==", "EQUALS_SIGN", ")", "{", "idBuf", ".", "append", "(", "PATH_SEP", ")", ";", "}", "else", "if", "(", "character", "==", "PLUS_SIGN", ")", "{", "idBuf", ".", "append", "(", "COLON", ")", ";", "}", "else", "if", "(", "character", "==", "COMMA", ")", "{", "idBuf", ".", "append", "(", "PERIOD", ")", ";", "}", "else", "if", "(", "character", "==", "HEX_INDICATOR", ")", "{", "/* Get the next two characters since they are hex characters */", "final", "String", "hex", "=", "aID", ".", "substring", "(", "index", "+", "1", ",", "index", "+", "3", ")", ";", "final", "char", "[", "]", "chars", "=", "Character", ".", "toChars", "(", "Integer", ".", "parseInt", "(", "hex", ",", "16", ")", ")", ";", "assert", "chars", ".", "length", "==", "1", ";", "idBuf", ".", "append", "(", "chars", "[", "0", "]", ")", ";", "index", "=", "index", "+", "2", ";", "}", "else", "{", "idBuf", ".", "append", "(", "character", ")", ";", "}", "}", "return", "idBuf", ".", "toString", "(", ")", ";", "}" ]
Unclean the ID from the Pairtree path. @param aID A cleaned ID to unclean @return The unclean ID
[ "Unclean", "the", "ID", "from", "the", "Pairtree", "path", "." ]
b2ea1e32057e5df262e9265540d346a732b718df
https://github.com/ksclarke/vertx-pairtree/blob/b2ea1e32057e5df262e9265540d346a732b718df/src/main/java/info/freelibrary/pairtree/PairtreeUtils.java#L443-L473
155,871
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.reset
private final void reset() { backtrackStack.clear(); actionStack.clear(); stateStack.clear(); parserErrors.clear(); streamPosition = 0; stepCounter = 0; stateStack.push(0); maxPosition = 0; shiftIgnoredTokens(); }
java
private final void reset() { backtrackStack.clear(); actionStack.clear(); stateStack.clear(); parserErrors.clear(); streamPosition = 0; stepCounter = 0; stateStack.push(0); maxPosition = 0; shiftIgnoredTokens(); }
[ "private", "final", "void", "reset", "(", ")", "{", "backtrackStack", ".", "clear", "(", ")", ";", "actionStack", ".", "clear", "(", ")", ";", "stateStack", ".", "clear", "(", ")", ";", "parserErrors", ".", "clear", "(", ")", ";", "streamPosition", "=", "0", ";", "stepCounter", "=", "0", ";", "stateStack", ".", "push", "(", "0", ")", ";", "maxPosition", "=", "0", ";", "shiftIgnoredTokens", "(", ")", ";", "}" ]
This method is called just before running the parser to reset all internal values and to clean all stacks.
[ "This", "method", "is", "called", "just", "before", "running", "the", "parser", "to", "reset", "all", "internal", "values", "and", "to", "clean", "all", "stacks", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L167-L177
155,872
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.shiftIgnoredTokens
private final void shiftIgnoredTokens() { if (streamPosition == getTokenStream().size()) { return; } Token token = getTokenStream().get(streamPosition); while (token.getVisibility() == Visibility.IGNORED) { streamPosition++; if (streamPosition == getTokenStream().size()) { break; } token = getTokenStream().get(streamPosition); } }
java
private final void shiftIgnoredTokens() { if (streamPosition == getTokenStream().size()) { return; } Token token = getTokenStream().get(streamPosition); while (token.getVisibility() == Visibility.IGNORED) { streamPosition++; if (streamPosition == getTokenStream().size()) { break; } token = getTokenStream().get(streamPosition); } }
[ "private", "final", "void", "shiftIgnoredTokens", "(", ")", "{", "if", "(", "streamPosition", "==", "getTokenStream", "(", ")", ".", "size", "(", ")", ")", "{", "return", ";", "}", "Token", "token", "=", "getTokenStream", "(", ")", ".", "get", "(", "streamPosition", ")", ";", "while", "(", "token", ".", "getVisibility", "(", ")", "==", "Visibility", ".", "IGNORED", ")", "{", "streamPosition", "++", ";", "if", "(", "streamPosition", "==", "getTokenStream", "(", ")", ".", "size", "(", ")", ")", "{", "break", ";", "}", "token", "=", "getTokenStream", "(", ")", ".", "get", "(", "streamPosition", ")", ";", "}", "}" ]
This method treats all ignored tokens during a shift. The ignored tokens are just skipped by moving the stream position variable forward.
[ "This", "method", "treats", "all", "ignored", "tokens", "during", "a", "shift", ".", "The", "ignored", "tokens", "are", "just", "skipped", "by", "moving", "the", "stream", "position", "variable", "forward", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L183-L195
155,873
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.parse
private final ParseTreeNode parse() throws ParserException { try { createActionStack(); return LRTokenStreamConverter.convert(getTokenStream(), getGrammar(), actionStack); } catch (GrammarException e) { logger.error(e.getMessage(), e); throw new ParserException(e.getMessage()); } }
java
private final ParseTreeNode parse() throws ParserException { try { createActionStack(); return LRTokenStreamConverter.convert(getTokenStream(), getGrammar(), actionStack); } catch (GrammarException e) { logger.error(e.getMessage(), e); throw new ParserException(e.getMessage()); } }
[ "private", "final", "ParseTreeNode", "parse", "(", ")", "throws", "ParserException", "{", "try", "{", "createActionStack", "(", ")", ";", "return", "LRTokenStreamConverter", ".", "convert", "(", "getTokenStream", "(", ")", ",", "getGrammar", "(", ")", ",", "actionStack", ")", ";", "}", "catch", "(", "GrammarException", "e", ")", "{", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "throw", "new", "ParserException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
This method does the actual parsing. @return The result AST is returned. @throws ParserException
[ "This", "method", "does", "the", "actual", "parsing", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L203-L211
155,874
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.checkTimeout
private void checkTimeout() throws ParserException { if (timeout > 0) { if (System.currentTimeMillis() - startTime > timeout * 1000) { throw new ParserException("Timeout after " + timeout + " seconds near '" + getTokenStream().getCodeSample(maxPosition) + "'!"); } } }
java
private void checkTimeout() throws ParserException { if (timeout > 0) { if (System.currentTimeMillis() - startTime > timeout * 1000) { throw new ParserException("Timeout after " + timeout + " seconds near '" + getTokenStream().getCodeSample(maxPosition) + "'!"); } } }
[ "private", "void", "checkTimeout", "(", ")", "throws", "ParserException", "{", "if", "(", "timeout", ">", "0", ")", "{", "if", "(", "System", ".", "currentTimeMillis", "(", ")", "-", "startTime", ">", "timeout", "*", "1000", ")", "{", "throw", "new", "ParserException", "(", "\"Timeout after \"", "+", "timeout", "+", "\" seconds near '\"", "+", "getTokenStream", "(", ")", ".", "getCodeSample", "(", "maxPosition", ")", "+", "\"'!\"", ")", ";", "}", "}", "}" ]
This method checks for the timeout. If the time ran out, an ParserException is thrown and the parser process is finished. @throws ParserException is thrown if the time ran out.
[ "This", "method", "checks", "for", "the", "timeout", ".", "If", "the", "time", "ran", "out", "an", "ParserException", "is", "thrown", "and", "the", "parser", "process", "is", "finished", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L273-L280
155,875
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.getAction
private final ParserAction getAction(ParserActionSet actionSet) throws GrammarException { if (actionSet.getActionNumber() == 1) { /* * action is not ambiguous, therefore, the action is easily returned... */ return actionSet.getAction(); } if (!backtrackEnabled) { /* * Backtracking is disabled and action set is ambiguous. Throw exception due to * illegal state... */ logger.trace("Action set '" + actionSet + "' is ambiguous and back tracking is disabled!"); throw new GrammarException("Grammar is ambiguous!"); } if ((!backtrackStack.isEmpty()) && (backtrackStack.peek().getStepCounter() == stepCounter)) { /* * We are currently at a step with stored backtracking information, so we just * returned from a backtrack. Trying next alternative... */ if (logger.isTraceEnabled()) { logger.trace("Action set '" + actionSet + "' is ambiguous and back tracking was performed already. Trying new alternative..."); } BacktrackLocation location = backtrackStack.pop(); int stepAhead = 1; if (location.getLastAlternative() + stepAhead >= actionSet.getActionNumber()) { logger.trace("No alternative left. Abort."); return new ParserAction(ActionType.ERROR, -1); } addBacktrackLocation(location.getLastAlternative() + stepAhead); return actionSet.getAction(location.getLastAlternative() + stepAhead); } /* * We have a new ambiguous state. We store backtracking information and try * first alternative... */ if (logger.isTraceEnabled()) { logger.trace("Action set '" + actionSet + "' is ambiguous. Installing back tracking location in stack..."); } addBacktrackLocation(0); return actionSet.getAction(0); }
java
private final ParserAction getAction(ParserActionSet actionSet) throws GrammarException { if (actionSet.getActionNumber() == 1) { /* * action is not ambiguous, therefore, the action is easily returned... */ return actionSet.getAction(); } if (!backtrackEnabled) { /* * Backtracking is disabled and action set is ambiguous. Throw exception due to * illegal state... */ logger.trace("Action set '" + actionSet + "' is ambiguous and back tracking is disabled!"); throw new GrammarException("Grammar is ambiguous!"); } if ((!backtrackStack.isEmpty()) && (backtrackStack.peek().getStepCounter() == stepCounter)) { /* * We are currently at a step with stored backtracking information, so we just * returned from a backtrack. Trying next alternative... */ if (logger.isTraceEnabled()) { logger.trace("Action set '" + actionSet + "' is ambiguous and back tracking was performed already. Trying new alternative..."); } BacktrackLocation location = backtrackStack.pop(); int stepAhead = 1; if (location.getLastAlternative() + stepAhead >= actionSet.getActionNumber()) { logger.trace("No alternative left. Abort."); return new ParserAction(ActionType.ERROR, -1); } addBacktrackLocation(location.getLastAlternative() + stepAhead); return actionSet.getAction(location.getLastAlternative() + stepAhead); } /* * We have a new ambiguous state. We store backtracking information and try * first alternative... */ if (logger.isTraceEnabled()) { logger.trace("Action set '" + actionSet + "' is ambiguous. Installing back tracking location in stack..."); } addBacktrackLocation(0); return actionSet.getAction(0); }
[ "private", "final", "ParserAction", "getAction", "(", "ParserActionSet", "actionSet", ")", "throws", "GrammarException", "{", "if", "(", "actionSet", ".", "getActionNumber", "(", ")", "==", "1", ")", "{", "/*\n\t * action is not ambiguous, therefore, the action is easily returned...\n\t */", "return", "actionSet", ".", "getAction", "(", ")", ";", "}", "if", "(", "!", "backtrackEnabled", ")", "{", "/*\n\t * Backtracking is disabled and action set is ambiguous. Throw exception due to\n\t * illegal state...\n\t */", "logger", ".", "trace", "(", "\"Action set '\"", "+", "actionSet", "+", "\"' is ambiguous and back tracking is disabled!\"", ")", ";", "throw", "new", "GrammarException", "(", "\"Grammar is ambiguous!\"", ")", ";", "}", "if", "(", "(", "!", "backtrackStack", ".", "isEmpty", "(", ")", ")", "&&", "(", "backtrackStack", ".", "peek", "(", ")", ".", "getStepCounter", "(", ")", "==", "stepCounter", ")", ")", "{", "/*\n\t * We are currently at a step with stored backtracking information, so we just\n\t * returned from a backtrack. Trying next alternative...\n\t */", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "\"Action set '\"", "+", "actionSet", "+", "\"' is ambiguous and back tracking was performed already. Trying new alternative...\"", ")", ";", "}", "BacktrackLocation", "location", "=", "backtrackStack", ".", "pop", "(", ")", ";", "int", "stepAhead", "=", "1", ";", "if", "(", "location", ".", "getLastAlternative", "(", ")", "+", "stepAhead", ">=", "actionSet", ".", "getActionNumber", "(", ")", ")", "{", "logger", ".", "trace", "(", "\"No alternative left. Abort.\"", ")", ";", "return", "new", "ParserAction", "(", "ActionType", ".", "ERROR", ",", "-", "1", ")", ";", "}", "addBacktrackLocation", "(", "location", ".", "getLastAlternative", "(", ")", "+", "stepAhead", ")", ";", "return", "actionSet", ".", "getAction", "(", "location", ".", "getLastAlternative", "(", ")", "+", "stepAhead", ")", ";", "}", "/*\n\t * We have a new ambiguous state. We store backtracking information and try\n\t * first alternative...\n\t */", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "\"Action set '\"", "+", "actionSet", "+", "\"' is ambiguous. Installing back tracking location in stack...\"", ")", ";", "}", "addBacktrackLocation", "(", "0", ")", ";", "return", "actionSet", ".", "getAction", "(", "0", ")", ";", "}" ]
This mehtod returns the currently to be processed action. This method also takes care for ambiguous grammars and backtracking. @param actionSet @return @throws GrammarException
[ "This", "mehtod", "returns", "the", "currently", "to", "be", "processed", "action", ".", "This", "method", "also", "takes", "care", "for", "ambiguous", "grammars", "and", "backtracking", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L290-L332
155,876
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.addBacktrackLocation
@SuppressWarnings("unchecked") private final void addBacktrackLocation(int usedAlternative) { backtrackStack.push(new BacktrackLocation((Stack<Integer>) stateStack.clone(), actionStack.size(), streamPosition, stepCounter, usedAlternative)); if (backtrackDepth > 0) { while (backtrackStack.size() > backtrackDepth) { backtrackStack.remove(0); } } }
java
@SuppressWarnings("unchecked") private final void addBacktrackLocation(int usedAlternative) { backtrackStack.push(new BacktrackLocation((Stack<Integer>) stateStack.clone(), actionStack.size(), streamPosition, stepCounter, usedAlternative)); if (backtrackDepth > 0) { while (backtrackStack.size() > backtrackDepth) { backtrackStack.remove(0); } } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "final", "void", "addBacktrackLocation", "(", "int", "usedAlternative", ")", "{", "backtrackStack", ".", "push", "(", "new", "BacktrackLocation", "(", "(", "Stack", "<", "Integer", ">", ")", "stateStack", ".", "clone", "(", ")", ",", "actionStack", ".", "size", "(", ")", ",", "streamPosition", ",", "stepCounter", ",", "usedAlternative", ")", ")", ";", "if", "(", "backtrackDepth", ">", "0", ")", "{", "while", "(", "backtrackStack", ".", "size", "(", ")", ">", "backtrackDepth", ")", "{", "backtrackStack", ".", "remove", "(", "0", ")", ";", "}", "}", "}" ]
This method adds the backtracking information for the current step. @param usedAlternative is the number of the alternative which is the next to be tried.
[ "This", "method", "adds", "the", "backtracking", "information", "for", "the", "current", "step", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L340-L349
155,877
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.shift
private final void shift(ParserAction action) { stateStack.push(action.getParameter()); actionStack.add(action); streamPosition++; shiftIgnoredTokens(); }
java
private final void shift(ParserAction action) { stateStack.push(action.getParameter()); actionStack.add(action); streamPosition++; shiftIgnoredTokens(); }
[ "private", "final", "void", "shift", "(", "ParserAction", "action", ")", "{", "stateStack", ".", "push", "(", "action", ".", "getParameter", "(", ")", ")", ";", "actionStack", ".", "add", "(", "action", ")", ";", "streamPosition", "++", ";", "shiftIgnoredTokens", "(", ")", ";", "}" ]
This method is called for shift actions. @param newState is the new state id after shift. @param token is the current token in token stream. @throws ParserException
[ "This", "method", "is", "called", "for", "shift", "actions", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L360-L365
155,878
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.reduce
private final void reduce(ParserAction action) throws ParserException { try { Production production = getGrammar().getProduction(action.getParameter()); for (int i = 0; i < production.getConstructions().size(); i++) { /* * The for loop is run as many times as the production contains constructions * which are added up for an AST node. */ stateStack.pop(); } actionStack.add(action); ParserAction gotoAction = parserTable.getAction(stateStack.peek(), new NonTerminal(production.getName())); if (gotoAction.getAction() == ActionType.ERROR) { error(); return; } stateStack.push(gotoAction.getParameter()); } catch (GrammarException e) { logger.error(e.getMessage(), e); throw new ParserException(e.getMessage()); } }
java
private final void reduce(ParserAction action) throws ParserException { try { Production production = getGrammar().getProduction(action.getParameter()); for (int i = 0; i < production.getConstructions().size(); i++) { /* * The for loop is run as many times as the production contains constructions * which are added up for an AST node. */ stateStack.pop(); } actionStack.add(action); ParserAction gotoAction = parserTable.getAction(stateStack.peek(), new NonTerminal(production.getName())); if (gotoAction.getAction() == ActionType.ERROR) { error(); return; } stateStack.push(gotoAction.getParameter()); } catch (GrammarException e) { logger.error(e.getMessage(), e); throw new ParserException(e.getMessage()); } }
[ "private", "final", "void", "reduce", "(", "ParserAction", "action", ")", "throws", "ParserException", "{", "try", "{", "Production", "production", "=", "getGrammar", "(", ")", ".", "getProduction", "(", "action", ".", "getParameter", "(", ")", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "production", ".", "getConstructions", "(", ")", ".", "size", "(", ")", ";", "i", "++", ")", "{", "/*\n\t\t * The for loop is run as many times as the production contains constructions\n\t\t * which are added up for an AST node.\n\t\t */", "stateStack", ".", "pop", "(", ")", ";", "}", "actionStack", ".", "add", "(", "action", ")", ";", "ParserAction", "gotoAction", "=", "parserTable", ".", "getAction", "(", "stateStack", ".", "peek", "(", ")", ",", "new", "NonTerminal", "(", "production", ".", "getName", "(", ")", ")", ")", ";", "if", "(", "gotoAction", ".", "getAction", "(", ")", "==", "ActionType", ".", "ERROR", ")", "{", "error", "(", ")", ";", "return", ";", "}", "stateStack", ".", "push", "(", "gotoAction", ".", "getParameter", "(", ")", ")", ";", "}", "catch", "(", "GrammarException", "e", ")", "{", "logger", ".", "error", "(", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "throw", "new", "ParserException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
This method is called for reduce actions. @param grammarRuleId is the rule id which is to be applied for reduction. @throws ParserException is thrown if the rule can not successfully be applied.
[ "This", "method", "is", "called", "for", "reduce", "actions", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L375-L396
155,879
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.error
private final void error() throws ParserException { Integer currentState = stateStack.peek(); parserErrors.addError(currentState); if (backtrackEnabled && !backtrackStack.isEmpty()) { trackBack(); return; } if (!backtrackEnabled) { logger.trace("No valid action available and back tracking is disabled. Aborting near '" + getTokenStream().getCodeSample(maxPosition) + "'..."); } else { logger.trace("No valid action available and back tracking stack is empty. Aborting near '" + getTokenStream().getCodeSample(maxPosition) + "'..."); } throw new ParserException( "Error! Could not parse the token stream near '" + getTokenStream().getCodeSample(maxPosition) + "'!"); }
java
private final void error() throws ParserException { Integer currentState = stateStack.peek(); parserErrors.addError(currentState); if (backtrackEnabled && !backtrackStack.isEmpty()) { trackBack(); return; } if (!backtrackEnabled) { logger.trace("No valid action available and back tracking is disabled. Aborting near '" + getTokenStream().getCodeSample(maxPosition) + "'..."); } else { logger.trace("No valid action available and back tracking stack is empty. Aborting near '" + getTokenStream().getCodeSample(maxPosition) + "'..."); } throw new ParserException( "Error! Could not parse the token stream near '" + getTokenStream().getCodeSample(maxPosition) + "'!"); }
[ "private", "final", "void", "error", "(", ")", "throws", "ParserException", "{", "Integer", "currentState", "=", "stateStack", ".", "peek", "(", ")", ";", "parserErrors", ".", "addError", "(", "currentState", ")", ";", "if", "(", "backtrackEnabled", "&&", "!", "backtrackStack", ".", "isEmpty", "(", ")", ")", "{", "trackBack", "(", ")", ";", "return", ";", "}", "if", "(", "!", "backtrackEnabled", ")", "{", "logger", ".", "trace", "(", "\"No valid action available and back tracking is disabled. Aborting near '\"", "+", "getTokenStream", "(", ")", ".", "getCodeSample", "(", "maxPosition", ")", "+", "\"'...\"", ")", ";", "}", "else", "{", "logger", ".", "trace", "(", "\"No valid action available and back tracking stack is empty. Aborting near '\"", "+", "getTokenStream", "(", ")", ".", "getCodeSample", "(", "maxPosition", ")", "+", "\"'...\"", ")", ";", "}", "throw", "new", "ParserException", "(", "\"Error! Could not parse the token stream near '\"", "+", "getTokenStream", "(", ")", ".", "getCodeSample", "(", "maxPosition", ")", "+", "\"'!\"", ")", ";", "}" ]
This method is called for an error action. @param token @throws ParserException
[ "This", "method", "is", "called", "for", "an", "error", "action", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L419-L435
155,880
PureSolTechnologies/parsers
parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java
AbstractLRParser.trackBack
private final void trackBack() { logger.trace("No valid action available. Perform back tracking..."); BacktrackLocation backtrackLocation = backtrackStack.peek(); streamPosition = backtrackLocation.getStreamPosition(); stepCounter = backtrackLocation.getStepCounter(); while (actionStack.size() > backtrackLocation.getActionStackSize()) { actionStack.remove(actionStack.size() - 1); } stateStack = backtrackLocation.getStateStack(); stepCounter--; }
java
private final void trackBack() { logger.trace("No valid action available. Perform back tracking..."); BacktrackLocation backtrackLocation = backtrackStack.peek(); streamPosition = backtrackLocation.getStreamPosition(); stepCounter = backtrackLocation.getStepCounter(); while (actionStack.size() > backtrackLocation.getActionStackSize()) { actionStack.remove(actionStack.size() - 1); } stateStack = backtrackLocation.getStateStack(); stepCounter--; }
[ "private", "final", "void", "trackBack", "(", ")", "{", "logger", ".", "trace", "(", "\"No valid action available. Perform back tracking...\"", ")", ";", "BacktrackLocation", "backtrackLocation", "=", "backtrackStack", ".", "peek", "(", ")", ";", "streamPosition", "=", "backtrackLocation", ".", "getStreamPosition", "(", ")", ";", "stepCounter", "=", "backtrackLocation", ".", "getStepCounter", "(", ")", ";", "while", "(", "actionStack", ".", "size", "(", ")", ">", "backtrackLocation", ".", "getActionStackSize", "(", ")", ")", "{", "actionStack", ".", "remove", "(", "actionStack", ".", "size", "(", ")", "-", "1", ")", ";", "}", "stateStack", "=", "backtrackLocation", ".", "getStateStack", "(", ")", ";", "stepCounter", "--", ";", "}" ]
This method perform the back tracking by popping all relevant information from the stacks.
[ "This", "method", "perform", "the", "back", "tracking", "by", "popping", "all", "relevant", "information", "from", "the", "stacks", "." ]
61077223b90d3768ff9445ae13036343c98b63cd
https://github.com/PureSolTechnologies/parsers/blob/61077223b90d3768ff9445ae13036343c98b63cd/parsers/src/main/java/com/puresoltechnologies/parsers/parser/lr/AbstractLRParser.java#L441-L451
155,881
foundation-runtime/service-directory
2.0/sd-api/src/main/java/com/cisco/oss/foundation/directory/impl/CachedDirectoryLookupService.java
CachedDirectoryLookupService.getCache
private ServiceDirectoryCache<String, ModelService> getCache(){ if(cache == null){ synchronized (this) { if (this.cache == null) { this.cache = new ServiceDirectoryCache<String, ModelService>(); } } } return this.cache; }
java
private ServiceDirectoryCache<String, ModelService> getCache(){ if(cache == null){ synchronized (this) { if (this.cache == null) { this.cache = new ServiceDirectoryCache<String, ModelService>(); } } } return this.cache; }
[ "private", "ServiceDirectoryCache", "<", "String", ",", "ModelService", ">", "getCache", "(", ")", "{", "if", "(", "cache", "==", "null", ")", "{", "synchronized", "(", "this", ")", "{", "if", "(", "this", ".", "cache", "==", "null", ")", "{", "this", ".", "cache", "=", "new", "ServiceDirectoryCache", "<", "String", ",", "ModelService", ">", "(", ")", ";", "}", "}", "}", "return", "this", ".", "cache", ";", "}" ]
Get the ServiceDirectoryCache that caches Services, it is lazy initialized. It is thread safe. @return the ServiceDirectoryCache.
[ "Get", "the", "ServiceDirectoryCache", "that", "caches", "Services", "it", "is", "lazy", "initialized", "." ]
a7bdefe173dc99e75eff4a24e07e6407e62f2ed4
https://github.com/foundation-runtime/service-directory/blob/a7bdefe173dc99e75eff4a24e07e6407e62f2ed4/2.0/sd-api/src/main/java/com/cisco/oss/foundation/directory/impl/CachedDirectoryLookupService.java#L178-L187
155,882
konvergeio/cofoja
src/main/java/com/google/java/contract/core/util/JavaTokenizer.java
JavaTokenizer.getNextToken
public Token getNextToken() { if (nextToken == null) { try { if (!lex()) { throw new NoSuchElementException(); } } catch (IOException e) { errorMessage = e.getMessage(); hasErrors_ = true; throw new NoSuchElementException(); } } return nextToken; }
java
public Token getNextToken() { if (nextToken == null) { try { if (!lex()) { throw new NoSuchElementException(); } } catch (IOException e) { errorMessage = e.getMessage(); hasErrors_ = true; throw new NoSuchElementException(); } } return nextToken; }
[ "public", "Token", "getNextToken", "(", ")", "{", "if", "(", "nextToken", "==", "null", ")", "{", "try", "{", "if", "(", "!", "lex", "(", ")", ")", "{", "throw", "new", "NoSuchElementException", "(", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "errorMessage", "=", "e", ".", "getMessage", "(", ")", ";", "hasErrors_", "=", "true", ";", "throw", "new", "NoSuchElementException", "(", ")", ";", "}", "}", "return", "nextToken", ";", "}" ]
Returns the next token without consuming it.
[ "Returns", "the", "next", "token", "without", "consuming", "it", "." ]
6ded58fa05eb5bf85f16353c8dd4c70bee59121a
https://github.com/konvergeio/cofoja/blob/6ded58fa05eb5bf85f16353c8dd4c70bee59121a/src/main/java/com/google/java/contract/core/util/JavaTokenizer.java#L254-L267
155,883
james-hu/jabb-core
src/main/java/net/sf/jabb/util/state/StartStopStateMachine.java
StartStopStateMachine.getStateAsString
public String getStateAsString(){ Integer state = getState(); if (STOPPED.equals(state)){ return "Stopped"; } if (STARTING.equals(state)){ return "Starting"; } if (RUNNING.equals(state)){ return "Running"; } if (STOPPING.equals(state)){ return "Stopping"; } throw new IllegalStateException("Unknown state: " + state); }
java
public String getStateAsString(){ Integer state = getState(); if (STOPPED.equals(state)){ return "Stopped"; } if (STARTING.equals(state)){ return "Starting"; } if (RUNNING.equals(state)){ return "Running"; } if (STOPPING.equals(state)){ return "Stopping"; } throw new IllegalStateException("Unknown state: " + state); }
[ "public", "String", "getStateAsString", "(", ")", "{", "Integer", "state", "=", "getState", "(", ")", ";", "if", "(", "STOPPED", ".", "equals", "(", "state", ")", ")", "{", "return", "\"Stopped\"", ";", "}", "if", "(", "STARTING", ".", "equals", "(", "state", ")", ")", "{", "return", "\"Starting\"", ";", "}", "if", "(", "RUNNING", ".", "equals", "(", "state", ")", ")", "{", "return", "\"Running\"", ";", "}", "if", "(", "STOPPING", ".", "equals", "(", "state", ")", ")", "{", "return", "\"Stopping\"", ";", "}", "throw", "new", "IllegalStateException", "(", "\"Unknown state: \"", "+", "state", ")", ";", "}" ]
Get the name of current state @return Stopped/Starting/Running/Stopping
[ "Get", "the", "name", "of", "current", "state" ]
bceed441595c5e5195a7418795f03b69fa7b61e4
https://github.com/james-hu/jabb-core/blob/bceed441595c5e5195a7418795f03b69fa7b61e4/src/main/java/net/sf/jabb/util/state/StartStopStateMachine.java#L88-L103
155,884
pip-services3-java/pip-services3-commons-java
src/org/pipservices3/commons/validate/ObjectSchema.java
ObjectSchema.withProperty
public ObjectSchema withProperty(PropertySchema schema) { _properties = _properties != null ? _properties : new ArrayList<PropertySchema>(); _properties.add(schema); return this; }
java
public ObjectSchema withProperty(PropertySchema schema) { _properties = _properties != null ? _properties : new ArrayList<PropertySchema>(); _properties.add(schema); return this; }
[ "public", "ObjectSchema", "withProperty", "(", "PropertySchema", "schema", ")", "{", "_properties", "=", "_properties", "!=", "null", "?", "_properties", ":", "new", "ArrayList", "<", "PropertySchema", ">", "(", ")", ";", "_properties", ".", "add", "(", "schema", ")", ";", "return", "this", ";", "}" ]
Adds a validation schema for an object property. This method returns reference to this exception to implement Builder pattern to chain additional calls. @param schema a property validation schema to be added. @return this validation schema. @see PropertySchema
[ "Adds", "a", "validation", "schema", "for", "an", "object", "property", "." ]
a8a0c3e5ec58f0663c295aa855c6b3afad2af86a
https://github.com/pip-services3-java/pip-services3-commons-java/blob/a8a0c3e5ec58f0663c295aa855c6b3afad2af86a/src/org/pipservices3/commons/validate/ObjectSchema.java#L100-L104
155,885
pip-services3-java/pip-services3-commons-java
src/org/pipservices3/commons/validate/ObjectSchema.java
ObjectSchema.withRequiredProperty
public ObjectSchema withRequiredProperty(String name, Object type, IValidationRule... rules) { _properties = _properties != null ? _properties : new ArrayList<PropertySchema>(); PropertySchema schema = new PropertySchema(name, type); schema.setRules(Arrays.asList(rules)); schema.makeRequired(); return withProperty(schema); }
java
public ObjectSchema withRequiredProperty(String name, Object type, IValidationRule... rules) { _properties = _properties != null ? _properties : new ArrayList<PropertySchema>(); PropertySchema schema = new PropertySchema(name, type); schema.setRules(Arrays.asList(rules)); schema.makeRequired(); return withProperty(schema); }
[ "public", "ObjectSchema", "withRequiredProperty", "(", "String", "name", ",", "Object", "type", ",", "IValidationRule", "...", "rules", ")", "{", "_properties", "=", "_properties", "!=", "null", "?", "_properties", ":", "new", "ArrayList", "<", "PropertySchema", ">", "(", ")", ";", "PropertySchema", "schema", "=", "new", "PropertySchema", "(", "name", ",", "type", ")", ";", "schema", ".", "setRules", "(", "Arrays", ".", "asList", "(", "rules", ")", ")", ";", "schema", ".", "makeRequired", "(", ")", ";", "return", "withProperty", "(", "schema", ")", ";", "}" ]
Adds a validation schema for a required object property. @param name a property name. @param type (optional) a property schema or type. @param rules (optional) a list of property validation rules. @return the validation schema
[ "Adds", "a", "validation", "schema", "for", "a", "required", "object", "property", "." ]
a8a0c3e5ec58f0663c295aa855c6b3afad2af86a
https://github.com/pip-services3-java/pip-services3-commons-java/blob/a8a0c3e5ec58f0663c295aa855c6b3afad2af86a/src/org/pipservices3/commons/validate/ObjectSchema.java#L114-L120
155,886
iorga-group/iraj
irajblank-web/src/main/java/com/iorga/irajblank/bootstrap/DataInitializer.java
DataInitializer.createSampleDatas
public void createSampleDatas() throws NamingException { final Context ctx = new InitialContext(); final BeanManager beanManager = (BeanManager) ctx.lookup("java:comp/env/BeanManager"); final EntityManagerFactory entityManagerFactory = BeanManagerUtils.getOrCreateInstance(beanManager, EntityManagerFactory.class); final EntityManager entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); entityManager.createQuery("delete from User").executeUpdate(); entityManager.createQuery("delete from Profile").executeUpdate(); final Profile adminProfile = new Profile("Administrator", "admin"); entityManager.persist(adminProfile); final Profile userProfile = new Profile("User", "user"); entityManager.persist(userProfile); // final UserService userService = BeanManagerUtils.getOrCreateInstance(beanManager, UserService.class); entityManager.persist(new User("user", UserService.digestPassword("user", "user"), "User", "user", userProfile)); entityManager.persist(new User("admin", UserService.digestPassword("admin", "admin"), "Admin", "admin", adminProfile)); for (int i = 1; i <= MAX_ORDER; i++) { final Profile profile = new Profile("User"+i, "user"+i); entityManager.persist(profile); for (int j = 1; j <= MAX_ORDER; j++) { final int id = i*MAX_ORDER + j; entityManager.persist(new User("user"+id, UserService.digestPassword("user"+id, "user"+id), "User"+id, "user"+id, profile)); } } entityManager.getTransaction().commit(); }
java
public void createSampleDatas() throws NamingException { final Context ctx = new InitialContext(); final BeanManager beanManager = (BeanManager) ctx.lookup("java:comp/env/BeanManager"); final EntityManagerFactory entityManagerFactory = BeanManagerUtils.getOrCreateInstance(beanManager, EntityManagerFactory.class); final EntityManager entityManager = entityManagerFactory.createEntityManager(); entityManager.getTransaction().begin(); entityManager.createQuery("delete from User").executeUpdate(); entityManager.createQuery("delete from Profile").executeUpdate(); final Profile adminProfile = new Profile("Administrator", "admin"); entityManager.persist(adminProfile); final Profile userProfile = new Profile("User", "user"); entityManager.persist(userProfile); // final UserService userService = BeanManagerUtils.getOrCreateInstance(beanManager, UserService.class); entityManager.persist(new User("user", UserService.digestPassword("user", "user"), "User", "user", userProfile)); entityManager.persist(new User("admin", UserService.digestPassword("admin", "admin"), "Admin", "admin", adminProfile)); for (int i = 1; i <= MAX_ORDER; i++) { final Profile profile = new Profile("User"+i, "user"+i); entityManager.persist(profile); for (int j = 1; j <= MAX_ORDER; j++) { final int id = i*MAX_ORDER + j; entityManager.persist(new User("user"+id, UserService.digestPassword("user"+id, "user"+id), "User"+id, "user"+id, profile)); } } entityManager.getTransaction().commit(); }
[ "public", "void", "createSampleDatas", "(", ")", "throws", "NamingException", "{", "final", "Context", "ctx", "=", "new", "InitialContext", "(", ")", ";", "final", "BeanManager", "beanManager", "=", "(", "BeanManager", ")", "ctx", ".", "lookup", "(", "\"java:comp/env/BeanManager\"", ")", ";", "final", "EntityManagerFactory", "entityManagerFactory", "=", "BeanManagerUtils", ".", "getOrCreateInstance", "(", "beanManager", ",", "EntityManagerFactory", ".", "class", ")", ";", "final", "EntityManager", "entityManager", "=", "entityManagerFactory", ".", "createEntityManager", "(", ")", ";", "entityManager", ".", "getTransaction", "(", ")", ".", "begin", "(", ")", ";", "entityManager", ".", "createQuery", "(", "\"delete from User\"", ")", ".", "executeUpdate", "(", ")", ";", "entityManager", ".", "createQuery", "(", "\"delete from Profile\"", ")", ".", "executeUpdate", "(", ")", ";", "final", "Profile", "adminProfile", "=", "new", "Profile", "(", "\"Administrator\"", ",", "\"admin\"", ")", ";", "entityManager", ".", "persist", "(", "adminProfile", ")", ";", "final", "Profile", "userProfile", "=", "new", "Profile", "(", "\"User\"", ",", "\"user\"", ")", ";", "entityManager", ".", "persist", "(", "userProfile", ")", ";", "//\t\tfinal UserService userService = BeanManagerUtils.getOrCreateInstance(beanManager, UserService.class);", "entityManager", ".", "persist", "(", "new", "User", "(", "\"user\"", ",", "UserService", ".", "digestPassword", "(", "\"user\"", ",", "\"user\"", ")", ",", "\"User\"", ",", "\"user\"", ",", "userProfile", ")", ")", ";", "entityManager", ".", "persist", "(", "new", "User", "(", "\"admin\"", ",", "UserService", ".", "digestPassword", "(", "\"admin\"", ",", "\"admin\"", ")", ",", "\"Admin\"", ",", "\"admin\"", ",", "adminProfile", ")", ")", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<=", "MAX_ORDER", ";", "i", "++", ")", "{", "final", "Profile", "profile", "=", "new", "Profile", "(", "\"User\"", "+", "i", ",", "\"user\"", "+", "i", ")", ";", "entityManager", ".", "persist", "(", "profile", ")", ";", "for", "(", "int", "j", "=", "1", ";", "j", "<=", "MAX_ORDER", ";", "j", "++", ")", "{", "final", "int", "id", "=", "i", "*", "MAX_ORDER", "+", "j", ";", "entityManager", ".", "persist", "(", "new", "User", "(", "\"user\"", "+", "id", ",", "UserService", ".", "digestPassword", "(", "\"user\"", "+", "id", ",", "\"user\"", "+", "id", ")", ",", "\"User\"", "+", "id", ",", "\"user\"", "+", "id", ",", "profile", ")", ")", ";", "}", "}", "entityManager", ".", "getTransaction", "(", ")", ".", "commit", "(", ")", ";", "}" ]
private UserService userService;
[ "private", "UserService", "userService", ";" ]
5fdee26464248f29833610de402275eb64505542
https://github.com/iorga-group/iraj/blob/5fdee26464248f29833610de402275eb64505542/irajblank-web/src/main/java/com/iorga/irajblank/bootstrap/DataInitializer.java#L29-L61
155,887
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.setSystemPropertyIfIsNull
public static void setSystemPropertyIfIsNull(String key, Object value) { if (!System.getProperties().containsKey(key)) System.setProperty(key, value.toString()); }
java
public static void setSystemPropertyIfIsNull(String key, Object value) { if (!System.getProperties().containsKey(key)) System.setProperty(key, value.toString()); }
[ "public", "static", "void", "setSystemPropertyIfIsNull", "(", "String", "key", ",", "Object", "value", ")", "{", "if", "(", "!", "System", ".", "getProperties", "(", ")", ".", "containsKey", "(", "key", ")", ")", "System", ".", "setProperty", "(", "key", ",", "value", ".", "toString", "(", ")", ")", ";", "}" ]
Sets system property if is null. @param key the key @param value the value
[ "Sets", "system", "property", "if", "is", "null", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L31-L34
155,888
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getURL
public static URL getURL(String classpathOrFilePath) { try { return getURI(classpathOrFilePath).toURL(); } catch (MalformedURLException e) { return JMExceptionManager.handleExceptionAndReturnNull(log, e, "getURL", classpathOrFilePath); } }
java
public static URL getURL(String classpathOrFilePath) { try { return getURI(classpathOrFilePath).toURL(); } catch (MalformedURLException e) { return JMExceptionManager.handleExceptionAndReturnNull(log, e, "getURL", classpathOrFilePath); } }
[ "public", "static", "URL", "getURL", "(", "String", "classpathOrFilePath", ")", "{", "try", "{", "return", "getURI", "(", "classpathOrFilePath", ")", ".", "toURL", "(", ")", ";", "}", "catch", "(", "MalformedURLException", "e", ")", "{", "return", "JMExceptionManager", ".", "handleExceptionAndReturnNull", "(", "log", ",", "e", ",", "\"getURL\"", ",", "classpathOrFilePath", ")", ";", "}", "}" ]
Gets url. @param classpathOrFilePath the classpath or file path @return the url
[ "Gets", "url", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L62-L69
155,889
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getResourceURI
public static URI getResourceURI(String classpath) { try { return getResourceURL(classpath).toURI(); } catch (Exception e) { return JMExceptionManager.handleExceptionAndReturnNull(log, e, "getResourceURI", classpath); } }
java
public static URI getResourceURI(String classpath) { try { return getResourceURL(classpath).toURI(); } catch (Exception e) { return JMExceptionManager.handleExceptionAndReturnNull(log, e, "getResourceURI", classpath); } }
[ "public", "static", "URI", "getResourceURI", "(", "String", "classpath", ")", "{", "try", "{", "return", "getResourceURL", "(", "classpath", ")", ".", "toURI", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "JMExceptionManager", ".", "handleExceptionAndReturnNull", "(", "log", ",", "e", ",", "\"getResourceURI\"", ",", "classpath", ")", ";", "}", "}" ]
Gets resource uri. @param classpath the classpath @return the resource uri
[ "Gets", "resource", "uri", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L77-L84
155,890
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getURI
public static URI getURI(String classpathOrFilePath) { return Optional.ofNullable(getResourceURI(classpathOrFilePath)) .orElseGet(() -> new File(classpathOrFilePath).toURI()); }
java
public static URI getURI(String classpathOrFilePath) { return Optional.ofNullable(getResourceURI(classpathOrFilePath)) .orElseGet(() -> new File(classpathOrFilePath).toURI()); }
[ "public", "static", "URI", "getURI", "(", "String", "classpathOrFilePath", ")", "{", "return", "Optional", ".", "ofNullable", "(", "getResourceURI", "(", "classpathOrFilePath", ")", ")", ".", "orElseGet", "(", "(", ")", "->", "new", "File", "(", "classpathOrFilePath", ")", ".", "toURI", "(", ")", ")", ";", "}" ]
Gets uri. @param classpathOrFilePath the classpath or file path @return the uri
[ "Gets", "uri", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L92-L95
155,891
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.saveProperties
public static boolean saveProperties(Properties inProperties, File saveFile, String comment) { try { if (!saveFile.exists()) JMFiles.createEmptyFile(saveFile); BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile)); inProperties.store(writer, comment); writer.close(); return true; } catch (IOException e) { return JMExceptionManager.handleExceptionAndReturnFalse(log, e, "saveProperties", inProperties, saveFile, comment); } }
java
public static boolean saveProperties(Properties inProperties, File saveFile, String comment) { try { if (!saveFile.exists()) JMFiles.createEmptyFile(saveFile); BufferedWriter writer = new BufferedWriter(new FileWriter(saveFile)); inProperties.store(writer, comment); writer.close(); return true; } catch (IOException e) { return JMExceptionManager.handleExceptionAndReturnFalse(log, e, "saveProperties", inProperties, saveFile, comment); } }
[ "public", "static", "boolean", "saveProperties", "(", "Properties", "inProperties", ",", "File", "saveFile", ",", "String", "comment", ")", "{", "try", "{", "if", "(", "!", "saveFile", ".", "exists", "(", ")", ")", "JMFiles", ".", "createEmptyFile", "(", "saveFile", ")", ";", "BufferedWriter", "writer", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "saveFile", ")", ")", ";", "inProperties", ".", "store", "(", "writer", ",", "comment", ")", ";", "writer", ".", "close", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "JMExceptionManager", ".", "handleExceptionAndReturnFalse", "(", "log", ",", "e", ",", "\"saveProperties\"", ",", "inProperties", ",", "saveFile", ",", "comment", ")", ";", "}", "}" ]
Save properties boolean. @param inProperties the in properties @param saveFile the save file @param comment the comment @return the boolean
[ "Save", "properties", "boolean", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L208-L223
155,892
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.readStringForZip
public static String readStringForZip(String zipFilePathOrClasspath, String entryName, String charsetName) { return JMInputStream.toString( getResourceInputStreamForZip(zipFilePathOrClasspath, entryName), charsetName); }
java
public static String readStringForZip(String zipFilePathOrClasspath, String entryName, String charsetName) { return JMInputStream.toString( getResourceInputStreamForZip(zipFilePathOrClasspath, entryName), charsetName); }
[ "public", "static", "String", "readStringForZip", "(", "String", "zipFilePathOrClasspath", ",", "String", "entryName", ",", "String", "charsetName", ")", "{", "return", "JMInputStream", ".", "toString", "(", "getResourceInputStreamForZip", "(", "zipFilePathOrClasspath", ",", "entryName", ")", ",", "charsetName", ")", ";", "}" ]
Read string for zip string. @param zipFilePathOrClasspath the zip file path or classpath @param entryName the entry name @param charsetName the charset name @return the string
[ "Read", "string", "for", "zip", "string", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L233-L238
155,893
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.readLinesForZip
public static List<String> readLinesForZip(String zipFilePathOrClasspath, String entryName) { return JMInputStream.readLines( getResourceInputStreamForZip(zipFilePathOrClasspath, entryName)); }
java
public static List<String> readLinesForZip(String zipFilePathOrClasspath, String entryName) { return JMInputStream.readLines( getResourceInputStreamForZip(zipFilePathOrClasspath, entryName)); }
[ "public", "static", "List", "<", "String", ">", "readLinesForZip", "(", "String", "zipFilePathOrClasspath", ",", "String", "entryName", ")", "{", "return", "JMInputStream", ".", "readLines", "(", "getResourceInputStreamForZip", "(", "zipFilePathOrClasspath", ",", "entryName", ")", ")", ";", "}" ]
Read lines for zip list. @param zipFilePathOrClasspath the zip file path or classpath @param entryName the entry name @return the list
[ "Read", "lines", "for", "zip", "list", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L312-L317
155,894
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getStringWithClasspathOrFilePath
public static String getStringWithClasspathOrFilePath( String classpathOrFilePath, String charsetName) { return getStringAsOptWithClasspath(classpathOrFilePath, charsetName) .orElseGet(() -> getStringAsOptWithFilePath (classpathOrFilePath, charsetName).orElse(null)); }
java
public static String getStringWithClasspathOrFilePath( String classpathOrFilePath, String charsetName) { return getStringAsOptWithClasspath(classpathOrFilePath, charsetName) .orElseGet(() -> getStringAsOptWithFilePath (classpathOrFilePath, charsetName).orElse(null)); }
[ "public", "static", "String", "getStringWithClasspathOrFilePath", "(", "String", "classpathOrFilePath", ",", "String", "charsetName", ")", "{", "return", "getStringAsOptWithClasspath", "(", "classpathOrFilePath", ",", "charsetName", ")", ".", "orElseGet", "(", "(", ")", "->", "getStringAsOptWithFilePath", "(", "classpathOrFilePath", ",", "charsetName", ")", ".", "orElse", "(", "null", ")", ")", ";", "}" ]
Gets string with classpath or file path. @param classpathOrFilePath the classpath or file path @param charsetName the charset name @return the string with classpath or file path
[ "Gets", "string", "with", "classpath", "or", "file", "path", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L352-L357
155,895
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.readLinesWithClasspathOrFilePath
public static List<String> readLinesWithClasspathOrFilePath( String classpathOrFilePath) { return getStringListAsOptWithClasspath(classpathOrFilePath) .filter(JMPredicate.getGreaterSize(0)) .orElseGet(() -> JMFiles.readLines(classpathOrFilePath)); }
java
public static List<String> readLinesWithClasspathOrFilePath( String classpathOrFilePath) { return getStringListAsOptWithClasspath(classpathOrFilePath) .filter(JMPredicate.getGreaterSize(0)) .orElseGet(() -> JMFiles.readLines(classpathOrFilePath)); }
[ "public", "static", "List", "<", "String", ">", "readLinesWithClasspathOrFilePath", "(", "String", "classpathOrFilePath", ")", "{", "return", "getStringListAsOptWithClasspath", "(", "classpathOrFilePath", ")", ".", "filter", "(", "JMPredicate", ".", "getGreaterSize", "(", "0", ")", ")", ".", "orElseGet", "(", "(", ")", "->", "JMFiles", ".", "readLines", "(", "classpathOrFilePath", ")", ")", ";", "}" ]
Read lines with classpath or file path list. @param classpathOrFilePath the classpath or file path @return the list
[ "Read", "lines", "with", "classpath", "or", "file", "path", "list", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L365-L370
155,896
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getStringListAsOptWithClasspath
public static Optional<List<String>> getStringListAsOptWithClasspath( String classpathOrFilePath) { return getResourceInputStreamAsOpt(classpathOrFilePath) .map(JMInputStream::readLines); }
java
public static Optional<List<String>> getStringListAsOptWithClasspath( String classpathOrFilePath) { return getResourceInputStreamAsOpt(classpathOrFilePath) .map(JMInputStream::readLines); }
[ "public", "static", "Optional", "<", "List", "<", "String", ">", ">", "getStringListAsOptWithClasspath", "(", "String", "classpathOrFilePath", ")", "{", "return", "getResourceInputStreamAsOpt", "(", "classpathOrFilePath", ")", ".", "map", "(", "JMInputStream", "::", "readLines", ")", ";", "}" ]
Gets string list as opt with classpath. @param classpathOrFilePath the classpath or file path @return the string list as opt with classpath
[ "Gets", "string", "list", "as", "opt", "with", "classpath", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L378-L382
155,897
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.readLinesWithFilePathOrClasspath
public static List<String> readLinesWithFilePathOrClasspath( String filePathOrClasspath) { return JMOptional .getOptional(JMFiles.readLines(filePathOrClasspath)) .orElseGet(() -> getStringListAsOptWithClasspath( filePathOrClasspath) .orElseGet(Collections::emptyList)); }
java
public static List<String> readLinesWithFilePathOrClasspath( String filePathOrClasspath) { return JMOptional .getOptional(JMFiles.readLines(filePathOrClasspath)) .orElseGet(() -> getStringListAsOptWithClasspath( filePathOrClasspath) .orElseGet(Collections::emptyList)); }
[ "public", "static", "List", "<", "String", ">", "readLinesWithFilePathOrClasspath", "(", "String", "filePathOrClasspath", ")", "{", "return", "JMOptional", ".", "getOptional", "(", "JMFiles", ".", "readLines", "(", "filePathOrClasspath", ")", ")", ".", "orElseGet", "(", "(", ")", "->", "getStringListAsOptWithClasspath", "(", "filePathOrClasspath", ")", ".", "orElseGet", "(", "Collections", "::", "emptyList", ")", ")", ";", "}" ]
Read lines with file path or classpath list. @param filePathOrClasspath the file path or classpath @return the list
[ "Read", "lines", "with", "file", "path", "or", "classpath", "list", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L390-L397
155,898
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getStringWithFilePathOrClasspath
public static String getStringWithFilePathOrClasspath( String filePathOrClasspath, String charsetName) { return getStringAsOptWithFilePath(filePathOrClasspath, charsetName) .orElseGet( () -> getStringAsOptWithClasspath( filePathOrClasspath, charsetName).orElse(null)); }
java
public static String getStringWithFilePathOrClasspath( String filePathOrClasspath, String charsetName) { return getStringAsOptWithFilePath(filePathOrClasspath, charsetName) .orElseGet( () -> getStringAsOptWithClasspath( filePathOrClasspath, charsetName).orElse(null)); }
[ "public", "static", "String", "getStringWithFilePathOrClasspath", "(", "String", "filePathOrClasspath", ",", "String", "charsetName", ")", "{", "return", "getStringAsOptWithFilePath", "(", "filePathOrClasspath", ",", "charsetName", ")", ".", "orElseGet", "(", "(", ")", "->", "getStringAsOptWithClasspath", "(", "filePathOrClasspath", ",", "charsetName", ")", ".", "orElse", "(", "null", ")", ")", ";", "}" ]
Gets string with file path or classpath. @param filePathOrClasspath the file path or classpath @param charsetName the charset name @return the string with file path or classpath
[ "Gets", "string", "with", "file", "path", "or", "classpath", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L406-L413
155,899
JM-Lab/utils-java8
src/main/java/kr/jm/utils/helper/JMResources.java
JMResources.getStringAsOptWithFilePath
public static Optional<String> getStringAsOptWithFilePath( String filePath, String charsetName) { return JMOptional .getOptional(JMFiles.readString(filePath, charsetName)); }
java
public static Optional<String> getStringAsOptWithFilePath( String filePath, String charsetName) { return JMOptional .getOptional(JMFiles.readString(filePath, charsetName)); }
[ "public", "static", "Optional", "<", "String", ">", "getStringAsOptWithFilePath", "(", "String", "filePath", ",", "String", "charsetName", ")", "{", "return", "JMOptional", ".", "getOptional", "(", "JMFiles", ".", "readString", "(", "filePath", ",", "charsetName", ")", ")", ";", "}" ]
Gets string as opt with file path. @param filePath the file path @param charsetName the charset name @return the string as opt with file path
[ "Gets", "string", "as", "opt", "with", "file", "path", "." ]
9e407b3f28a7990418a1e877229fa8344f4d78a5
https://github.com/JM-Lab/utils-java8/blob/9e407b3f28a7990418a1e877229fa8344f4d78a5/src/main/java/kr/jm/utils/helper/JMResources.java#L434-L438