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
sequence
docstring
stringlengths
3
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
105
339
3,000
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.stripBraceAndQuotation
public static String stripBraceAndQuotation(Object o) { if (null == o) return ""; String s = stripBrace(o); s = stripQuotation(s); return s; }
java
public static String stripBraceAndQuotation(Object o) { if (null == o) return ""; String s = stripBrace(o); s = stripQuotation(s); return s; }
[ "public", "static", "String", "stripBraceAndQuotation", "(", "Object", "o", ")", "{", "if", "(", "null", "==", "o", ")", "return", "\"\"", ";", "String", "s", "=", "stripBrace", "(", "o", ")", ";", "s", "=", "stripQuotation", "(", "s", ")", ";", "return", "s", ";", "}" ]
Strip off both brace and quotation @param o @return the string result
[ "Strip", "off", "both", "brace", "and", "quotation" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L769-L774
3,001
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.shrinkSpace
public static String shrinkSpace(Object o) { if (null == o) return ""; return o.toString().replaceAll("[\r\n]+", "\n").replaceAll("[ \\t\\x0B\\f]+", " "); }
java
public static String shrinkSpace(Object o) { if (null == o) return ""; return o.toString().replaceAll("[\r\n]+", "\n").replaceAll("[ \\t\\x0B\\f]+", " "); }
[ "public", "static", "String", "shrinkSpace", "(", "Object", "o", ")", "{", "if", "(", "null", "==", "o", ")", "return", "\"\"", ";", "return", "o", ".", "toString", "(", ")", ".", "replaceAll", "(", "\"[\\r\\n]+\"", ",", "\"\\n\"", ")", ".", "replaceAll", "(", "\"[ \\\\t\\\\x0B\\\\f]+\"", ",", "\" \"", ")", ";", "}" ]
Shrink spaces in an object's string representation by merge multiple spaces, tabs into one space, and multiple line breaks into one line break @param o @return the string result
[ "Shrink", "spaces", "in", "an", "object", "s", "string", "representation", "by", "merge", "multiple", "spaces", "tabs", "into", "one", "space", "and", "multiple", "line", "breaks", "into", "one", "line", "break" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L783-L786
3,002
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.isDigitsOrAlphabetic
public static boolean isDigitsOrAlphabetic(char c) { int i = (int)c; return digits.include(i) || uppers.include(i) || lowers.include(i); }
java
public static boolean isDigitsOrAlphabetic(char c) { int i = (int)c; return digits.include(i) || uppers.include(i) || lowers.include(i); }
[ "public", "static", "boolean", "isDigitsOrAlphabetic", "(", "char", "c", ")", "{", "int", "i", "=", "(", "int", ")", "c", ";", "return", "digits", ".", "include", "(", "i", ")", "||", "uppers", ".", "include", "(", "i", ")", "||", "lowers", ".", "include", "(", "i", ")", ";", "}" ]
check the given char to be a digit or alphabetic @param c @return true if this is a digit an upper case char or a lowercase char
[ "check", "the", "given", "char", "to", "be", "a", "digit", "or", "alphabetic" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L797-L800
3,003
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.capitalizeWords
@Transformer public static String capitalizeWords(Object o) { if (null == o) return ""; String source = o.toString(); char prevc = ' '; // first char of source is capitalized StringBuilder sb = new StringBuilder(); for (int i = 0; i < source.length(); i++) { char c = source.charAt(i); if (c != ' ' && !isDigitsOrAlphabetic(prevc)) { sb.append(Character.toUpperCase(c)); } else { sb.append(c); } prevc = c; } return sb.toString(); }
java
@Transformer public static String capitalizeWords(Object o) { if (null == o) return ""; String source = o.toString(); char prevc = ' '; // first char of source is capitalized StringBuilder sb = new StringBuilder(); for (int i = 0; i < source.length(); i++) { char c = source.charAt(i); if (c != ' ' && !isDigitsOrAlphabetic(prevc)) { sb.append(Character.toUpperCase(c)); } else { sb.append(c); } prevc = c; } return sb.toString(); }
[ "@", "Transformer", "public", "static", "String", "capitalizeWords", "(", "Object", "o", ")", "{", "if", "(", "null", "==", "o", ")", "return", "\"\"", ";", "String", "source", "=", "o", ".", "toString", "(", ")", ";", "char", "prevc", "=", "'", "'", ";", "// first char of source is capitalized", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "source", ".", "length", "(", ")", ";", "i", "++", ")", "{", "char", "c", "=", "source", ".", "charAt", "(", "i", ")", ";", "if", "(", "c", "!=", "'", "'", "&&", "!", "isDigitsOrAlphabetic", "(", "prevc", ")", ")", "{", "sb", ".", "append", "(", "Character", ".", "toUpperCase", "(", "c", ")", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "c", ")", ";", "}", "prevc", "=", "c", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Capitalize the first character of every word of the specified object's string representation. Words are separated by space @param o @return the string result
[ "Capitalize", "the", "first", "character", "of", "every", "word", "of", "the", "specified", "object", "s", "string", "representation", ".", "Words", "are", "separated", "by", "space" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L809-L825
3,004
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.lowerFirst
@Transformer public static String lowerFirst(Object o) { if (null == o) return ""; String string = o.toString(); if (string.length() == 0) { return string; } return ("" + string.charAt(0)).toLowerCase() + string.substring(1); }
java
@Transformer public static String lowerFirst(Object o) { if (null == o) return ""; String string = o.toString(); if (string.length() == 0) { return string; } return ("" + string.charAt(0)).toLowerCase() + string.substring(1); }
[ "@", "Transformer", "public", "static", "String", "lowerFirst", "(", "Object", "o", ")", "{", "if", "(", "null", "==", "o", ")", "return", "\"\"", ";", "String", "string", "=", "o", ".", "toString", "(", ")", ";", "if", "(", "string", ".", "length", "(", ")", "==", "0", ")", "{", "return", "string", ";", "}", "return", "(", "\"\"", "+", "string", ".", "charAt", "(", "0", ")", ")", ".", "toLowerCase", "(", ")", "+", "string", ".", "substring", "(", "1", ")", ";", "}" ]
Make the first character be lowercase of the given object's string representation @param o @return the string result
[ "Make", "the", "first", "character", "be", "lowercase", "of", "the", "given", "object", "s", "string", "representation" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L847-L855
3,005
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.capFirst
@Transformer public static String capFirst(Object o) { if (null == o) return ""; String string = o.toString(); if (string.length() == 0) { return string; } return ("" + string.charAt(0)).toUpperCase() + string.substring(1); }
java
@Transformer public static String capFirst(Object o) { if (null == o) return ""; String string = o.toString(); if (string.length() == 0) { return string; } return ("" + string.charAt(0)).toUpperCase() + string.substring(1); }
[ "@", "Transformer", "public", "static", "String", "capFirst", "(", "Object", "o", ")", "{", "if", "(", "null", "==", "o", ")", "return", "\"\"", ";", "String", "string", "=", "o", ".", "toString", "(", ")", ";", "if", "(", "string", ".", "length", "(", ")", "==", "0", ")", "{", "return", "string", ";", "}", "return", "(", "\"\"", "+", "string", ".", "charAt", "(", "0", ")", ")", ".", "toUpperCase", "(", ")", "+", "string", ".", "substring", "(", "1", ")", ";", "}" ]
Make the first character be uppercase of the given object's string representation @param o @return the string result
[ "Make", "the", "first", "character", "be", "uppercase", "of", "the", "given", "object", "s", "string", "representation" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L863-L871
3,006
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.camelCase
@Transformer public static String camelCase(Object obj) { if (null == obj) return ""; String string = obj.toString(); //string = noAccents(string); //string = string.replaceAll("[^\\w ]", ""); StringBuilder result = new StringBuilder(string.length()); String[] sa = string.split(" "); int l = sa.length; for (int i = 0; i < l; ++i) { if (i > 0) result.append(" "); for (String s : sa[i].split("_")) { result.append(capFirst(s)); } } return result.toString(); }
java
@Transformer public static String camelCase(Object obj) { if (null == obj) return ""; String string = obj.toString(); //string = noAccents(string); //string = string.replaceAll("[^\\w ]", ""); StringBuilder result = new StringBuilder(string.length()); String[] sa = string.split(" "); int l = sa.length; for (int i = 0; i < l; ++i) { if (i > 0) result.append(" "); for (String s : sa[i].split("_")) { result.append(capFirst(s)); } } return result.toString(); }
[ "@", "Transformer", "public", "static", "String", "camelCase", "(", "Object", "obj", ")", "{", "if", "(", "null", "==", "obj", ")", "return", "\"\"", ";", "String", "string", "=", "obj", ".", "toString", "(", ")", ";", "//string = noAccents(string);", "//string = string.replaceAll(\"[^\\\\w ]\", \"\");", "StringBuilder", "result", "=", "new", "StringBuilder", "(", "string", ".", "length", "(", ")", ")", ";", "String", "[", "]", "sa", "=", "string", ".", "split", "(", "\" \"", ")", ";", "int", "l", "=", "sa", ".", "length", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "l", ";", "++", "i", ")", "{", "if", "(", "i", ">", "0", ")", "result", ".", "append", "(", "\" \"", ")", ";", "for", "(", "String", "s", ":", "sa", "[", "i", "]", ".", "split", "(", "\"_\"", ")", ")", "{", "result", ".", "append", "(", "capFirst", "(", "s", ")", ")", ";", "}", "}", "return", "result", ".", "toString", "(", ")", ";", "}" ]
Turn an object's String representation into Camel Case @param obj @return the string result
[ "Turn", "an", "object", "s", "String", "representation", "into", "Camel", "Case" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L879-L895
3,007
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.len
@Transformer public static int len(Object o) { if (o instanceof Collection) { return ((Collection)o).size(); } else if (o instanceof Map) { return ((Map)o).size(); } else if (o.getClass().isArray()) { return Array.getLength(o); } else { return str(o).length(); } }
java
@Transformer public static int len(Object o) { if (o instanceof Collection) { return ((Collection)o).size(); } else if (o instanceof Map) { return ((Map)o).size(); } else if (o.getClass().isArray()) { return Array.getLength(o); } else { return str(o).length(); } }
[ "@", "Transformer", "public", "static", "int", "len", "(", "Object", "o", ")", "{", "if", "(", "o", "instanceof", "Collection", ")", "{", "return", "(", "(", "Collection", ")", "o", ")", ".", "size", "(", ")", ";", "}", "else", "if", "(", "o", "instanceof", "Map", ")", "{", "return", "(", "(", "Map", ")", "o", ")", ".", "size", "(", ")", ";", "}", "else", "if", "(", "o", ".", "getClass", "(", ")", ".", "isArray", "(", ")", ")", "{", "return", "Array", ".", "getLength", "(", "o", ")", ";", "}", "else", "{", "return", "str", "(", "o", ")", ".", "length", "(", ")", ";", "}", "}" ]
get length of specified object <ul> <li>If o is a Collection or Map, then return size of it</li> <li>If o is an array, then return length of it</li> <li>Otherwise return length() of String representation of the object</li> </ul> @param o @return length
[ "get", "length", "of", "specified", "object" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L939-L950
3,008
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.urlEncode
@Transformer public static String urlEncode(Object data) { if (null == data) return ""; String entity = data.toString(); try { String encoding = "utf-8"; return URLEncoder.encode(entity, encoding); } catch (UnsupportedEncodingException e) { Logger.error(e, entity); } return entity; }
java
@Transformer public static String urlEncode(Object data) { if (null == data) return ""; String entity = data.toString(); try { String encoding = "utf-8"; return URLEncoder.encode(entity, encoding); } catch (UnsupportedEncodingException e) { Logger.error(e, entity); } return entity; }
[ "@", "Transformer", "public", "static", "String", "urlEncode", "(", "Object", "data", ")", "{", "if", "(", "null", "==", "data", ")", "return", "\"\"", ";", "String", "entity", "=", "data", ".", "toString", "(", ")", ";", "try", "{", "String", "encoding", "=", "\"utf-8\"", ";", "return", "URLEncoder", ".", "encode", "(", "entity", ",", "encoding", ")", ";", "}", "catch", "(", "UnsupportedEncodingException", "e", ")", "{", "Logger", ".", "error", "(", "e", ",", "entity", ")", ";", "}", "return", "entity", ";", "}" ]
encode using utf-8 @param data @return encoded
[ "encode", "using", "utf", "-", "8" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L996-L1007
3,009
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
public static String format(ITemplate template, Number number) { return format(template, number, null, null); }
java
public static String format(ITemplate template, Number number) { return format(template, number, null, null); }
[ "public", "static", "String", "format", "(", "ITemplate", "template", ",", "Number", "number", ")", "{", "return", "format", "(", "template", ",", "number", ",", "null", ",", "null", ")", ";", "}" ]
Format number with specified template @param template @param number @return the formatted string
[ "Format", "number", "with", "specified", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1024-L1026
3,010
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
@Transformer(requireTemplate = true) public static String format(Number number, String pattern, Locale locale) { return format(null, number, pattern, locale); }
java
@Transformer(requireTemplate = true) public static String format(Number number, String pattern, Locale locale) { return format(null, number, pattern, locale); }
[ "@", "Transformer", "(", "requireTemplate", "=", "true", ")", "public", "static", "String", "format", "(", "Number", "number", ",", "String", "pattern", ",", "Locale", "locale", ")", "{", "return", "format", "(", "null", ",", "number", ",", "pattern", ",", "locale", ")", ";", "}" ]
Format the number with specified pattern, language and locale @param number @param pattern @param locale @return the formatted String @see DecimalFormatSymbols
[ "Format", "the", "number", "with", "specified", "pattern", "language", "and", "locale" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1036-L1039
3,011
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
public static String format(ITemplate template, Number number, String pattern, Locale locale) { if (null == number) { throw new NullPointerException(); } if (null == locale) { locale = I18N.locale(template); } NumberFormat nf; if (null == pattern) nf = NumberFormat.getNumberInstance(locale); else { DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); nf = new DecimalFormat(pattern, symbols); } return nf.format(number); }
java
public static String format(ITemplate template, Number number, String pattern, Locale locale) { if (null == number) { throw new NullPointerException(); } if (null == locale) { locale = I18N.locale(template); } NumberFormat nf; if (null == pattern) nf = NumberFormat.getNumberInstance(locale); else { DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale); nf = new DecimalFormat(pattern, symbols); } return nf.format(number); }
[ "public", "static", "String", "format", "(", "ITemplate", "template", ",", "Number", "number", ",", "String", "pattern", ",", "Locale", "locale", ")", "{", "if", "(", "null", "==", "number", ")", "{", "throw", "new", "NullPointerException", "(", ")", ";", "}", "if", "(", "null", "==", "locale", ")", "{", "locale", "=", "I18N", ".", "locale", "(", "template", ")", ";", "}", "NumberFormat", "nf", ";", "if", "(", "null", "==", "pattern", ")", "nf", "=", "NumberFormat", ".", "getNumberInstance", "(", "locale", ")", ";", "else", "{", "DecimalFormatSymbols", "symbols", "=", "new", "DecimalFormatSymbols", "(", "locale", ")", ";", "nf", "=", "new", "DecimalFormat", "(", "pattern", ",", "symbols", ")", ";", "}", "return", "nf", ".", "format", "(", "number", ")", ";", "}" ]
Format the number with specified template, pattern, language and locale @param number @param pattern @param locale @return the formatted String @see DecimalFormatSymbols
[ "Format", "the", "number", "with", "specified", "template", "pattern", "language", "and", "locale" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1049-L1065
3,012
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
@Transformer(requireTemplate = true) public static String format(Date date) { return format(date, null, null, null); }
java
@Transformer(requireTemplate = true) public static String format(Date date) { return format(date, null, null, null); }
[ "@", "Transformer", "(", "requireTemplate", "=", "true", ")", "public", "static", "String", "format", "(", "Date", "date", ")", "{", "return", "format", "(", "date", ",", "null", ",", "null", ",", "null", ")", ";", "}" ]
Format a date with engine's default format corresponding to the engine's locale configured @param date @return the formatted String
[ "Format", "a", "date", "with", "engine", "s", "default", "format", "corresponding", "to", "the", "engine", "s", "locale", "configured" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1107-L1110
3,013
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
public static String format(ITemplate template, Date date) { return format(template, date, null, null, null); }
java
public static String format(ITemplate template, Date date) { return format(template, date, null, null, null); }
[ "public", "static", "String", "format", "(", "ITemplate", "template", ",", "Date", "date", ")", "{", "return", "format", "(", "template", ",", "date", ",", "null", ",", "null", ",", "null", ")", ";", "}" ]
Format a date with specified engine's default format corresponding to the engine's locale configured @param date @return the formatted String
[ "Format", "a", "date", "with", "specified", "engine", "s", "default", "format", "corresponding", "to", "the", "engine", "s", "locale", "configured" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1130-L1132
3,014
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.format
public static String format(ITemplate template, Date date, String pattern, Locale locale, String timezone) { if (null == date) throw new NullPointerException(); RythmEngine engine = null == template ? RythmEngine.get() : template.__engine(); DateFormat df = (null == engine ? IDateFormatFactory.DefaultDateFormatFactory.INSTANCE : engine.dateFormatFactory()).createDateFormat(template, pattern, locale, timezone); return df.format(date); }
java
public static String format(ITemplate template, Date date, String pattern, Locale locale, String timezone) { if (null == date) throw new NullPointerException(); RythmEngine engine = null == template ? RythmEngine.get() : template.__engine(); DateFormat df = (null == engine ? IDateFormatFactory.DefaultDateFormatFactory.INSTANCE : engine.dateFormatFactory()).createDateFormat(template, pattern, locale, timezone); return df.format(date); }
[ "public", "static", "String", "format", "(", "ITemplate", "template", ",", "Date", "date", ",", "String", "pattern", ",", "Locale", "locale", ",", "String", "timezone", ")", "{", "if", "(", "null", "==", "date", ")", "throw", "new", "NullPointerException", "(", ")", ";", "RythmEngine", "engine", "=", "null", "==", "template", "?", "RythmEngine", ".", "get", "(", ")", ":", "template", ".", "__engine", "(", ")", ";", "DateFormat", "df", "=", "(", "null", "==", "engine", "?", "IDateFormatFactory", ".", "DefaultDateFormatFactory", ".", "INSTANCE", ":", "engine", ".", "dateFormatFactory", "(", ")", ")", ".", "createDateFormat", "(", "template", ",", "pattern", ",", "locale", ",", "timezone", ")", ";", "return", "df", ".", "format", "(", "date", ")", ";", "}" ]
Format a date with specified pattern, lang, locale and timezone. The locale comes from the engine instance specified @param template @param date @param pattern @param locale @param timezone @return format result
[ "Format", "a", "date", "with", "specified", "pattern", "lang", "locale", "and", "timezone", ".", "The", "locale", "comes", "from", "the", "engine", "instance", "specified" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1363-L1369
3,015
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.formatCurrency
@Transformer(requireTemplate = true) public static String formatCurrency(Object data) { return formatCurrency(null, data, null, null); }
java
@Transformer(requireTemplate = true) public static String formatCurrency(Object data) { return formatCurrency(null, data, null, null); }
[ "@", "Transformer", "(", "requireTemplate", "=", "true", ")", "public", "static", "String", "formatCurrency", "(", "Object", "data", ")", "{", "return", "formatCurrency", "(", "null", ",", "data", ",", "null", ",", "null", ")", ";", "}" ]
Transformer method. Format given data into currency @param data @return the currency See {@link #formatCurrency(org.rythmengine.template.ITemplate,Object,String,java.util.Locale)}
[ "Transformer", "method", ".", "Format", "given", "data", "into", "currency" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1445-L1448
3,016
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.formatCurrency
public static String formatCurrency(ITemplate template, Object data, String currencyCode) { return formatCurrency(template, data, currencyCode, null); }
java
public static String formatCurrency(ITemplate template, Object data, String currencyCode) { return formatCurrency(template, data, currencyCode, null); }
[ "public", "static", "String", "formatCurrency", "(", "ITemplate", "template", ",", "Object", "data", ",", "String", "currencyCode", ")", "{", "return", "formatCurrency", "(", "template", ",", "data", ",", "currencyCode", ",", "null", ")", ";", "}" ]
Transformer method. Format currency using specified parameters @param template @param data @param currencyCode @return the currency string See {@link #formatCurrency(org.rythmengine.template.ITemplate, Object, String, java.util.Locale)}
[ "Transformer", "method", ".", "Format", "currency", "using", "specified", "parameters" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1482-L1484
3,017
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.formatCurrency
public static String formatCurrency(ITemplate template, Object data, String currencyCode, Locale locale) { if (null == data) throw new NullPointerException(); Number number; if (data instanceof Number) { number = (Number)data; } else { number = Double.parseDouble(data.toString()); } if (null == locale) locale = I18N.locale(template); if (null == locale.getCountry() || locale.getCountry().length() != 2) { // try best to guess String lan = locale.getLanguage(); if (eq(lan, "en")) { if (null != currencyCode) { if (eq("AUD", currencyCode)) { locale = new Locale(lan, "AU"); } else if (eq("USD", currencyCode)) { locale = Locale.US; } else if (eq("GBP", currencyCode)) { locale = Locale.UK; } } } else if (eq(lan, "zh")) { locale = Locale.SIMPLIFIED_CHINESE; } } NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); Currency currency = null; if (null == currencyCode) { String country = locale.getCountry(); if (null != country && country.length() == 2) { currency = Currency.getInstance(locale); } if (null == currency) currencyCode = "$"; // default } if (null == currency) { if (currencyCode.length() != 3) { // it must be something like '$' or '¥' etc } else { currency = Currency.getInstance(currencyCode); } } if (null != currency) { numberFormat.setCurrency(currency); numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits()); } else { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setCurrencySymbol(currencyCode); ((DecimalFormat) numberFormat).setDecimalFormatSymbols(dfs); } String s = numberFormat.format(number); if (null != currency) s = s.replace(currency.getCurrencyCode(), currency.getSymbol(locale)); return s; }
java
public static String formatCurrency(ITemplate template, Object data, String currencyCode, Locale locale) { if (null == data) throw new NullPointerException(); Number number; if (data instanceof Number) { number = (Number)data; } else { number = Double.parseDouble(data.toString()); } if (null == locale) locale = I18N.locale(template); if (null == locale.getCountry() || locale.getCountry().length() != 2) { // try best to guess String lan = locale.getLanguage(); if (eq(lan, "en")) { if (null != currencyCode) { if (eq("AUD", currencyCode)) { locale = new Locale(lan, "AU"); } else if (eq("USD", currencyCode)) { locale = Locale.US; } else if (eq("GBP", currencyCode)) { locale = Locale.UK; } } } else if (eq(lan, "zh")) { locale = Locale.SIMPLIFIED_CHINESE; } } NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); Currency currency = null; if (null == currencyCode) { String country = locale.getCountry(); if (null != country && country.length() == 2) { currency = Currency.getInstance(locale); } if (null == currency) currencyCode = "$"; // default } if (null == currency) { if (currencyCode.length() != 3) { // it must be something like '$' or '¥' etc } else { currency = Currency.getInstance(currencyCode); } } if (null != currency) { numberFormat.setCurrency(currency); numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits()); } else { DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setCurrencySymbol(currencyCode); ((DecimalFormat) numberFormat).setDecimalFormatSymbols(dfs); } String s = numberFormat.format(number); if (null != currency) s = s.replace(currency.getCurrencyCode(), currency.getSymbol(locale)); return s; }
[ "public", "static", "String", "formatCurrency", "(", "ITemplate", "template", ",", "Object", "data", ",", "String", "currencyCode", ",", "Locale", "locale", ")", "{", "if", "(", "null", "==", "data", ")", "throw", "new", "NullPointerException", "(", ")", ";", "Number", "number", ";", "if", "(", "data", "instanceof", "Number", ")", "{", "number", "=", "(", "Number", ")", "data", ";", "}", "else", "{", "number", "=", "Double", ".", "parseDouble", "(", "data", ".", "toString", "(", ")", ")", ";", "}", "if", "(", "null", "==", "locale", ")", "locale", "=", "I18N", ".", "locale", "(", "template", ")", ";", "if", "(", "null", "==", "locale", ".", "getCountry", "(", ")", "||", "locale", ".", "getCountry", "(", ")", ".", "length", "(", ")", "!=", "2", ")", "{", "// try best to guess", "String", "lan", "=", "locale", ".", "getLanguage", "(", ")", ";", "if", "(", "eq", "(", "lan", ",", "\"en\"", ")", ")", "{", "if", "(", "null", "!=", "currencyCode", ")", "{", "if", "(", "eq", "(", "\"AUD\"", ",", "currencyCode", ")", ")", "{", "locale", "=", "new", "Locale", "(", "lan", ",", "\"AU\"", ")", ";", "}", "else", "if", "(", "eq", "(", "\"USD\"", ",", "currencyCode", ")", ")", "{", "locale", "=", "Locale", ".", "US", ";", "}", "else", "if", "(", "eq", "(", "\"GBP\"", ",", "currencyCode", ")", ")", "{", "locale", "=", "Locale", ".", "UK", ";", "}", "}", "}", "else", "if", "(", "eq", "(", "lan", ",", "\"zh\"", ")", ")", "{", "locale", "=", "Locale", ".", "SIMPLIFIED_CHINESE", ";", "}", "}", "NumberFormat", "numberFormat", "=", "NumberFormat", ".", "getCurrencyInstance", "(", "locale", ")", ";", "Currency", "currency", "=", "null", ";", "if", "(", "null", "==", "currencyCode", ")", "{", "String", "country", "=", "locale", ".", "getCountry", "(", ")", ";", "if", "(", "null", "!=", "country", "&&", "country", ".", "length", "(", ")", "==", "2", ")", "{", "currency", "=", "Currency", ".", "getInstance", "(", "locale", ")", ";", "}", "if", "(", "null", "==", "currency", ")", "currencyCode", "=", "\"$\"", ";", "// default", "}", "if", "(", "null", "==", "currency", ")", "{", "if", "(", "currencyCode", ".", "length", "(", ")", "!=", "3", ")", "{", "// it must be something like '$' or '¥' etc", "}", "else", "{", "currency", "=", "Currency", ".", "getInstance", "(", "currencyCode", ")", ";", "}", "}", "if", "(", "null", "!=", "currency", ")", "{", "numberFormat", ".", "setCurrency", "(", "currency", ")", ";", "numberFormat", ".", "setMaximumFractionDigits", "(", "currency", ".", "getDefaultFractionDigits", "(", ")", ")", ";", "}", "else", "{", "DecimalFormatSymbols", "dfs", "=", "new", "DecimalFormatSymbols", "(", ")", ";", "dfs", ".", "setCurrencySymbol", "(", "currencyCode", ")", ";", "(", "(", "DecimalFormat", ")", "numberFormat", ")", ".", "setDecimalFormatSymbols", "(", "dfs", ")", ";", "}", "String", "s", "=", "numberFormat", ".", "format", "(", "number", ")", ";", "if", "(", "null", "!=", "currency", ")", "s", "=", "s", ".", "replace", "(", "currency", ".", "getCurrencyCode", "(", ")", ",", "currency", ".", "getSymbol", "(", "locale", ")", ")", ";", "return", "s", ";", "}" ]
Format give data into currency using locale info from the engine specified <p>The method accept any data type. When <code>null</code> is found then <code>NullPointerException</code> will be thrown out; if an <code>Number</code> is passed in, it will be type cast to <code>Number</code>; otherwise a <code>Double.valueOf(data.toString())</code> is used to find out the number</p> @param template @param data @param currencyCode @param locale @return the currency
[ "Format", "give", "data", "into", "currency", "using", "locale", "info", "from", "the", "engine", "specified" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1513-L1567
3,018
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.i18n
@Transformer(requireTemplate = true) public static String i18n(Object key, Object... args) { return i18n(null, key, args); }
java
@Transformer(requireTemplate = true) public static String i18n(Object key, Object... args) { return i18n(null, key, args); }
[ "@", "Transformer", "(", "requireTemplate", "=", "true", ")", "public", "static", "String", "i18n", "(", "Object", "key", ",", "Object", "...", "args", ")", "{", "return", "i18n", "(", "null", ",", "key", ",", "args", ")", ";", "}" ]
Transformer method. Return i18n message of a given key and args. @param key @param args @return the i18n message
[ "Transformer", "method", ".", "Return", "i18n", "message", "of", "a", "given", "key", "and", "args", "." ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1657-L1660
3,019
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/S.java
S.random
public static String random(int len) { final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '$', '#', '^', '&', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '~', '!', '@'}; final int max = chars.length; Random r = new Random(); StringBuilder sb = new StringBuilder(len); while(len-- > 0) { int i = r.nextInt(max); sb.append(chars[i]); } return sb.toString(); }
java
public static String random(int len) { final char[] chars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '$', '#', '^', '&', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '~', '!', '@'}; final int max = chars.length; Random r = new Random(); StringBuilder sb = new StringBuilder(len); while(len-- > 0) { int i = r.nextInt(max); sb.append(chars[i]); } return sb.toString(); }
[ "public", "static", "String", "random", "(", "int", "len", ")", "{", "final", "char", "[", "]", "chars", "=", "{", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", ",", "'", "'", "}", ";", "final", "int", "max", "=", "chars", ".", "length", ";", "Random", "r", "=", "new", "Random", "(", ")", ";", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", "len", ")", ";", "while", "(", "len", "--", ">", "0", ")", "{", "int", "i", "=", "r", ".", "nextInt", "(", "max", ")", ";", "sb", ".", "append", "(", "chars", "[", "i", "]", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}" ]
Generate random string. The generated string is safe to be used as filename @param len @return a random string with specified length
[ "Generate", "random", "string", "." ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/S.java#L1679-L1698
3,020
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__render
protected RawData __render(String template) { if (null == template) return new RawData(""); return S.raw(__engine.sandbox().render(template, __renderArgs)); }
java
protected RawData __render(String template) { if (null == template) return new RawData(""); return S.raw(__engine.sandbox().render(template, __renderArgs)); }
[ "protected", "RawData", "__render", "(", "String", "template", ")", "{", "if", "(", "null", "==", "template", ")", "return", "new", "RawData", "(", "\"\"", ")", ";", "return", "S", ".", "raw", "(", "__engine", ".", "sandbox", "(", ")", ".", "render", "(", "template", ",", "__renderArgs", ")", ")", ";", "}" ]
Render another template from within this template. Using the renderArgs of this template. @param template @return render result as {@link org.rythmengine.utils.RawData} @see #__render(String, Object...)
[ "Render", "another", "template", "from", "within", "this", "template", ".", "Using", "the", "renderArgs", "of", "this", "template", "." ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L293-L296
3,021
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__addLayoutSection
private void __addLayoutSection(String name, String section, boolean def) { Map<String, String> m = def ? layoutSections0 : layoutSections; if (m.containsKey(name)) return; m.put(name, section); }
java
private void __addLayoutSection(String name, String section, boolean def) { Map<String, String> m = def ? layoutSections0 : layoutSections; if (m.containsKey(name)) return; m.put(name, section); }
[ "private", "void", "__addLayoutSection", "(", "String", "name", ",", "String", "section", ",", "boolean", "def", ")", "{", "Map", "<", "String", ",", "String", ">", "m", "=", "def", "?", "layoutSections0", ":", "layoutSections", ";", "if", "(", "m", ".", "containsKey", "(", "name", ")", ")", "return", ";", "m", ".", "put", "(", "name", ",", "section", ")", ";", "}" ]
Add layout section. Should not be used in user application or template @param name @param section
[ "Add", "layout", "section", ".", "Should", "not", "be", "used", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L313-L317
3,022
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__startSection
protected void __startSection(String name) { if (null == name) throw new NullPointerException("section name cannot be null"); if (null != tmpOut) throw new IllegalStateException("section cannot be nested"); tmpCaller = __caller; __caller = null; tmpOut = __buffer; __buffer = new StringBuilder(); section = name; }
java
protected void __startSection(String name) { if (null == name) throw new NullPointerException("section name cannot be null"); if (null != tmpOut) throw new IllegalStateException("section cannot be nested"); tmpCaller = __caller; __caller = null; tmpOut = __buffer; __buffer = new StringBuilder(); section = name; }
[ "protected", "void", "__startSection", "(", "String", "name", ")", "{", "if", "(", "null", "==", "name", ")", "throw", "new", "NullPointerException", "(", "\"section name cannot be null\"", ")", ";", "if", "(", "null", "!=", "tmpOut", ")", "throw", "new", "IllegalStateException", "(", "\"section cannot be nested\"", ")", ";", "tmpCaller", "=", "__caller", ";", "__caller", "=", "null", ";", "tmpOut", "=", "__buffer", ";", "__buffer", "=", "new", "StringBuilder", "(", ")", ";", "section", "=", "name", ";", "}" ]
Start a layout section. Not to be used in user application or template @param name
[ "Start", "a", "layout", "section", ".", "Not", "to", "be", "used", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L328-L336
3,023
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__endSection
protected void __endSection(boolean def) { if (null == tmpOut && null == tmpCaller) throw new IllegalStateException("section has not been started"); __addLayoutSection(section, __buffer.toString(), def); __buffer = tmpOut; __caller = tmpCaller; tmpOut = null; tmpCaller = null; }
java
protected void __endSection(boolean def) { if (null == tmpOut && null == tmpCaller) throw new IllegalStateException("section has not been started"); __addLayoutSection(section, __buffer.toString(), def); __buffer = tmpOut; __caller = tmpCaller; tmpOut = null; tmpCaller = null; }
[ "protected", "void", "__endSection", "(", "boolean", "def", ")", "{", "if", "(", "null", "==", "tmpOut", "&&", "null", "==", "tmpCaller", ")", "throw", "new", "IllegalStateException", "(", "\"section has not been started\"", ")", ";", "__addLayoutSection", "(", "section", ",", "__buffer", ".", "toString", "(", ")", ",", "def", ")", ";", "__buffer", "=", "tmpOut", ";", "__caller", "=", "tmpCaller", ";", "tmpOut", "=", "null", ";", "tmpCaller", "=", "null", ";", "}" ]
End a layout section with a boolean flag mark if it is a default content or not. Not to be used in user application or template @param def
[ "End", "a", "layout", "section", "with", "a", "boolean", "flag", "mark", "if", "it", "is", "a", "default", "content", "or", "not", ".", "Not", "to", "be", "used", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L351-L358
3,024
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__pLayoutSection
protected void __pLayoutSection(String name) { String s = layoutSections.get(name); if (null == s) s = layoutSections0.get(name); else { String s0 = layoutSections0.get(name); if (s0 == null) s0 = ""; s = s.replace("\u0000\u0000inherited\u0000\u0000", s0); } p(s); }
java
protected void __pLayoutSection(String name) { String s = layoutSections.get(name); if (null == s) s = layoutSections0.get(name); else { String s0 = layoutSections0.get(name); if (s0 == null) s0 = ""; s = s.replace("\u0000\u0000inherited\u0000\u0000", s0); } p(s); }
[ "protected", "void", "__pLayoutSection", "(", "String", "name", ")", "{", "String", "s", "=", "layoutSections", ".", "get", "(", "name", ")", ";", "if", "(", "null", "==", "s", ")", "s", "=", "layoutSections0", ".", "get", "(", "name", ")", ";", "else", "{", "String", "s0", "=", "layoutSections0", ".", "get", "(", "name", ")", ";", "if", "(", "s0", "==", "null", ")", "s0", "=", "\"\"", ";", "s", "=", "s", ".", "replace", "(", "\"\\u0000\\u0000inherited\\u0000\\u0000\"", ",", "s0", ")", ";", "}", "p", "(", "s", ")", ";", "}" ]
Print a layout section by name. Not to be used in user application or template @param name
[ "Print", "a", "layout", "section", "by", "name", ".", "Not", "to", "be", "used", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L365-L374
3,025
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__getTemplateClass
public TemplateClass __getTemplateClass(boolean useCaller) { TemplateClass tc = __templateClass; if (useCaller && null == tc) { TemplateBase caller = __caller(); if (null != caller) return caller.__getTemplateClass(true); } return tc; }
java
public TemplateClass __getTemplateClass(boolean useCaller) { TemplateClass tc = __templateClass; if (useCaller && null == tc) { TemplateBase caller = __caller(); if (null != caller) return caller.__getTemplateClass(true); } return tc; }
[ "public", "TemplateClass", "__getTemplateClass", "(", "boolean", "useCaller", ")", "{", "TemplateClass", "tc", "=", "__templateClass", ";", "if", "(", "useCaller", "&&", "null", "==", "tc", ")", "{", "TemplateBase", "caller", "=", "__caller", "(", ")", ";", "if", "(", "null", "!=", "caller", ")", "return", "caller", ".", "__getTemplateClass", "(", "true", ")", ";", "}", "return", "tc", ";", "}" ]
Get the template class of this template. Not to be used in user application or template @param useCaller @return a <code>TemplateClass</code>
[ "Get", "the", "template", "class", "of", "this", "template", ".", "Not", "to", "be", "used", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L522-L529
3,026
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__setOutput
protected void __setOutput(String path) { try { w_ = new BufferedWriter(new FileWriter(path)); } catch (Exception e) { throw new FastRuntimeException(e.getMessage()); } }
java
protected void __setOutput(String path) { try { w_ = new BufferedWriter(new FileWriter(path)); } catch (Exception e) { throw new FastRuntimeException(e.getMessage()); } }
[ "protected", "void", "__setOutput", "(", "String", "path", ")", "{", "try", "{", "w_", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "path", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "FastRuntimeException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Set output file path @param path
[ "Set", "output", "file", "path" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L625-L631
3,027
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__setOutput
protected void __setOutput(File file) { try { w_ = new BufferedWriter(new FileWriter(file)); } catch (Exception e) { throw new FastRuntimeException(e.getMessage()); } }
java
protected void __setOutput(File file) { try { w_ = new BufferedWriter(new FileWriter(file)); } catch (Exception e) { throw new FastRuntimeException(e.getMessage()); } }
[ "protected", "void", "__setOutput", "(", "File", "file", ")", "{", "try", "{", "w_", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "file", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "FastRuntimeException", "(", "e", ".", "getMessage", "(", ")", ")", ";", "}", "}" ]
Set output file @param file
[ "Set", "output", "file" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L638-L644
3,028
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__getAs
protected final <T> T __getAs(String name, Class<T> c) { Object o = __getRenderArg(name); if (null == o) return null; return (T) o; }
java
protected final <T> T __getAs(String name, Class<T> c) { Object o = __getRenderArg(name); if (null == o) return null; return (T) o; }
[ "protected", "final", "<", "T", ">", "T", "__getAs", "(", "String", "name", ",", "Class", "<", "T", ">", "c", ")", "{", "Object", "o", "=", "__getRenderArg", "(", "name", ")", ";", "if", "(", "null", "==", "o", ")", "return", "null", ";", "return", "(", "T", ")", "o", ";", "}" ]
Get render arg and do type cast to the class specified @param name @param c @param <T> @return a render argument
[ "Get", "render", "arg", "and", "do", "type", "cast", "to", "the", "class", "specified" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L1065-L1069
3,029
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__getRenderPropertyAs
protected final <T> T __getRenderPropertyAs(String name, T def) { Object o = __getRenderProperty(name, def); return null == o ? def : (T) o; }
java
protected final <T> T __getRenderPropertyAs(String name, T def) { Object o = __getRenderProperty(name, def); return null == o ? def : (T) o; }
[ "protected", "final", "<", "T", ">", "T", "__getRenderPropertyAs", "(", "String", "name", ",", "T", "def", ")", "{", "Object", "o", "=", "__getRenderProperty", "(", "name", ",", "def", ")", ";", "return", "null", "==", "o", "?", "def", ":", "(", "T", ")", "o", ";", "}" ]
Get render property by name and do type cast to the specified default value. If the render property cannot be found by name, then return the default value @param name @param def @param <T> @return a render property @see #__getRenderProperty(String)
[ "Get", "render", "property", "by", "name", "and", "do", "type", "cast", "to", "the", "specified", "default", "value", ".", "If", "the", "render", "property", "cannot", "be", "found", "by", "name", "then", "return", "the", "default", "value" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L1108-L1111
3,030
rythmengine/rythmengine
src/main/java/org/rythmengine/template/TemplateBase.java
TemplateBase.__handleTemplateExecutionException
protected final void __handleTemplateExecutionException(Exception e) { try { if (!RythmEvents.ON_RENDER_EXCEPTION.trigger(__engine(), F.T2(this, e))) { throw e; } } catch (RuntimeException e0) { throw e0; } catch (Exception e1) { throw new RuntimeException(e1); } }
java
protected final void __handleTemplateExecutionException(Exception e) { try { if (!RythmEvents.ON_RENDER_EXCEPTION.trigger(__engine(), F.T2(this, e))) { throw e; } } catch (RuntimeException e0) { throw e0; } catch (Exception e1) { throw new RuntimeException(e1); } }
[ "protected", "final", "void", "__handleTemplateExecutionException", "(", "Exception", "e", ")", "{", "try", "{", "if", "(", "!", "RythmEvents", ".", "ON_RENDER_EXCEPTION", ".", "trigger", "(", "__engine", "(", ")", ",", "F", ".", "T2", "(", "this", ",", "e", ")", ")", ")", "{", "throw", "e", ";", "}", "}", "catch", "(", "RuntimeException", "e0", ")", "{", "throw", "e0", ";", "}", "catch", "(", "Exception", "e1", ")", "{", "throw", "new", "RuntimeException", "(", "e1", ")", ";", "}", "}" ]
Handle template execution exception. Not to be called in user application or template @param e
[ "Handle", "template", "execution", "exception", ".", "Not", "to", "be", "called", "in", "user", "application", "or", "template" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/template/TemplateBase.java#L1133-L1143
3,031
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClassLoader.java
TemplateClassLoader.getClassDefinition
protected byte[] getClassDefinition(final String name0) { if (typeNotFound(name0)) return null; byte[] ba = null; String name = name0.replace(".", "/") + ".class"; InputStream is = getResourceAsStream(name); if (null != is) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int count; while ((count = is.read(buffer, 0, buffer.length)) > 0) { os.write(buffer, 0, count); } ba = os.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { is.close(); } catch (IOException e) { throw new RuntimeException(e); } } } if (null == ba) { IByteCodeHelper helper = engine.conf().byteCodeHelper(); if (null != helper) { ba = helper.findByteCode(name0); } } if (null == ba) { setTypeNotFound(name0); } return ba; }
java
protected byte[] getClassDefinition(final String name0) { if (typeNotFound(name0)) return null; byte[] ba = null; String name = name0.replace(".", "/") + ".class"; InputStream is = getResourceAsStream(name); if (null != is) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int count; while ((count = is.read(buffer, 0, buffer.length)) > 0) { os.write(buffer, 0, count); } ba = os.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { is.close(); } catch (IOException e) { throw new RuntimeException(e); } } } if (null == ba) { IByteCodeHelper helper = engine.conf().byteCodeHelper(); if (null != helper) { ba = helper.findByteCode(name0); } } if (null == ba) { setTypeNotFound(name0); } return ba; }
[ "protected", "byte", "[", "]", "getClassDefinition", "(", "final", "String", "name0", ")", "{", "if", "(", "typeNotFound", "(", "name0", ")", ")", "return", "null", ";", "byte", "[", "]", "ba", "=", "null", ";", "String", "name", "=", "name0", ".", "replace", "(", "\".\"", ",", "\"/\"", ")", "+", "\".class\"", ";", "InputStream", "is", "=", "getResourceAsStream", "(", "name", ")", ";", "if", "(", "null", "!=", "is", ")", "{", "try", "{", "ByteArrayOutputStream", "os", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "8192", "]", ";", "int", "count", ";", "while", "(", "(", "count", "=", "is", ".", "read", "(", "buffer", ",", "0", ",", "buffer", ".", "length", ")", ")", ">", "0", ")", "{", "os", ".", "write", "(", "buffer", ",", "0", ",", "count", ")", ";", "}", "ba", "=", "os", ".", "toByteArray", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "finally", "{", "try", "{", "is", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}", "}", "if", "(", "null", "==", "ba", ")", "{", "IByteCodeHelper", "helper", "=", "engine", ".", "conf", "(", ")", ".", "byteCodeHelper", "(", ")", ";", "if", "(", "null", "!=", "helper", ")", "{", "ba", "=", "helper", ".", "findByteCode", "(", "name0", ")", ";", "}", "}", "if", "(", "null", "==", "ba", ")", "{", "setTypeNotFound", "(", "name0", ")", ";", "}", "return", "ba", ";", "}" ]
Search for the byte code of the given class.
[ "Search", "for", "the", "byte", "code", "of", "the", "given", "class", "." ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClassLoader.java#L394-L428
3,032
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClassLoader.java
TemplateClassLoader.detectChanges
public void detectChanges() { if (engine.isProdMode()) return; // Now check for file modification List<TemplateClass> modifieds = new ArrayList<TemplateClass>(); for (TemplateClass tc : engine.classes().all()) { if (tc.refresh()) modifieds.add(tc); } Set<TemplateClass> modifiedWithDependencies = new HashSet<TemplateClass>(); modifiedWithDependencies.addAll(modifieds); List<ClassDefinition> newDefinitions = new ArrayList<ClassDefinition>(); boolean dirtySig = false; for (TemplateClass tc : modifiedWithDependencies) { if (tc.compile() == null) { engine.classes().remove(tc); currentState = new TemplateClassloaderState();//show others that we have changed.. } else { int sigChecksum = tc.sigChecksum; tc.enhance(); if (sigChecksum != tc.sigChecksum) { dirtySig = true; } newDefinitions.add(new ClassDefinition(tc.javaClass, tc.enhancedByteCode)); currentState = new TemplateClassloaderState();//show others that we have changed.. } } if (!newDefinitions.isEmpty()) { throw new ClassReloadException("Need Reload"); } // Check signature (variable name & annotations aware !) if (dirtySig) { throw new ClassReloadException("Signature change !"); } // Now check if there is new classCache or removed classCache int hash = computePathHash(); if (hash != this.pathHash) { // Remove class for deleted files !! for (TemplateClass tc : engine.classes().all()) { if (!tc.templateResource.isValid()) { engine.classes().remove(tc); currentState = new TemplateClassloaderState();//show others that we have changed.. } } throw new ClassReloadException("Path has changed"); } }
java
public void detectChanges() { if (engine.isProdMode()) return; // Now check for file modification List<TemplateClass> modifieds = new ArrayList<TemplateClass>(); for (TemplateClass tc : engine.classes().all()) { if (tc.refresh()) modifieds.add(tc); } Set<TemplateClass> modifiedWithDependencies = new HashSet<TemplateClass>(); modifiedWithDependencies.addAll(modifieds); List<ClassDefinition> newDefinitions = new ArrayList<ClassDefinition>(); boolean dirtySig = false; for (TemplateClass tc : modifiedWithDependencies) { if (tc.compile() == null) { engine.classes().remove(tc); currentState = new TemplateClassloaderState();//show others that we have changed.. } else { int sigChecksum = tc.sigChecksum; tc.enhance(); if (sigChecksum != tc.sigChecksum) { dirtySig = true; } newDefinitions.add(new ClassDefinition(tc.javaClass, tc.enhancedByteCode)); currentState = new TemplateClassloaderState();//show others that we have changed.. } } if (!newDefinitions.isEmpty()) { throw new ClassReloadException("Need Reload"); } // Check signature (variable name & annotations aware !) if (dirtySig) { throw new ClassReloadException("Signature change !"); } // Now check if there is new classCache or removed classCache int hash = computePathHash(); if (hash != this.pathHash) { // Remove class for deleted files !! for (TemplateClass tc : engine.classes().all()) { if (!tc.templateResource.isValid()) { engine.classes().remove(tc); currentState = new TemplateClassloaderState();//show others that we have changed.. } } throw new ClassReloadException("Path has changed"); } }
[ "public", "void", "detectChanges", "(", ")", "{", "if", "(", "engine", ".", "isProdMode", "(", ")", ")", "return", ";", "// Now check for file modification", "List", "<", "TemplateClass", ">", "modifieds", "=", "new", "ArrayList", "<", "TemplateClass", ">", "(", ")", ";", "for", "(", "TemplateClass", "tc", ":", "engine", ".", "classes", "(", ")", ".", "all", "(", ")", ")", "{", "if", "(", "tc", ".", "refresh", "(", ")", ")", "modifieds", ".", "add", "(", "tc", ")", ";", "}", "Set", "<", "TemplateClass", ">", "modifiedWithDependencies", "=", "new", "HashSet", "<", "TemplateClass", ">", "(", ")", ";", "modifiedWithDependencies", ".", "addAll", "(", "modifieds", ")", ";", "List", "<", "ClassDefinition", ">", "newDefinitions", "=", "new", "ArrayList", "<", "ClassDefinition", ">", "(", ")", ";", "boolean", "dirtySig", "=", "false", ";", "for", "(", "TemplateClass", "tc", ":", "modifiedWithDependencies", ")", "{", "if", "(", "tc", ".", "compile", "(", ")", "==", "null", ")", "{", "engine", ".", "classes", "(", ")", ".", "remove", "(", "tc", ")", ";", "currentState", "=", "new", "TemplateClassloaderState", "(", ")", ";", "//show others that we have changed..", "}", "else", "{", "int", "sigChecksum", "=", "tc", ".", "sigChecksum", ";", "tc", ".", "enhance", "(", ")", ";", "if", "(", "sigChecksum", "!=", "tc", ".", "sigChecksum", ")", "{", "dirtySig", "=", "true", ";", "}", "newDefinitions", ".", "add", "(", "new", "ClassDefinition", "(", "tc", ".", "javaClass", ",", "tc", ".", "enhancedByteCode", ")", ")", ";", "currentState", "=", "new", "TemplateClassloaderState", "(", ")", ";", "//show others that we have changed..", "}", "}", "if", "(", "!", "newDefinitions", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "ClassReloadException", "(", "\"Need Reload\"", ")", ";", "}", "// Check signature (variable name & annotations aware !)", "if", "(", "dirtySig", ")", "{", "throw", "new", "ClassReloadException", "(", "\"Signature change !\"", ")", ";", "}", "// Now check if there is new classCache or removed classCache", "int", "hash", "=", "computePathHash", "(", ")", ";", "if", "(", "hash", "!=", "this", ".", "pathHash", ")", "{", "// Remove class for deleted files !!", "for", "(", "TemplateClass", "tc", ":", "engine", ".", "classes", "(", ")", ".", "all", "(", ")", ")", "{", "if", "(", "!", "tc", ".", "templateResource", ".", "isValid", "(", ")", ")", "{", "engine", ".", "classes", "(", ")", ".", "remove", "(", "tc", ")", ";", "currentState", "=", "new", "TemplateClassloaderState", "(", ")", ";", "//show others that we have changed..", "}", "}", "throw", "new", "ClassReloadException", "(", "\"Path has changed\"", ")", ";", "}", "}" ]
Detect Template changes
[ "Detect", "Template", "changes" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClassLoader.java#L444-L489
3,033
operasoftware/operaprestodriver
src/com/opera/core/systems/QuickWidget.java
QuickWidget.intersection
private Point intersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { double dem = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); // Solve the intersect point double xi = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / dem; double yi = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / dem; // Check the point isn't off the ends of the lines if ((x1 - xi) * (xi - x2) >= 0 && (x3 - xi) * (xi - x4) >= 0 && (y1 - yi) * (yi - y2) >= 0 && (y3 - yi) * (yi - y4) >= 0) { return new Point((int) xi, (int) yi); } return null; }
java
private Point intersection(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { double dem = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); // Solve the intersect point double xi = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / dem; double yi = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / dem; // Check the point isn't off the ends of the lines if ((x1 - xi) * (xi - x2) >= 0 && (x3 - xi) * (xi - x4) >= 0 && (y1 - yi) * (yi - y2) >= 0 && (y3 - yi) * (yi - y4) >= 0) { return new Point((int) xi, (int) yi); } return null; }
[ "private", "Point", "intersection", "(", "int", "x1", ",", "int", "y1", ",", "int", "x2", ",", "int", "y2", ",", "int", "x3", ",", "int", "y3", ",", "int", "x4", ",", "int", "y4", ")", "{", "double", "dem", "=", "(", "x1", "-", "x2", ")", "*", "(", "y3", "-", "y4", ")", "-", "(", "y1", "-", "y2", ")", "*", "(", "x3", "-", "x4", ")", ";", "// Solve the intersect point", "double", "xi", "=", "(", "(", "x1", "*", "y2", "-", "y1", "*", "x2", ")", "*", "(", "x3", "-", "x4", ")", "-", "(", "x1", "-", "x2", ")", "*", "(", "x3", "*", "y4", "-", "y3", "*", "x4", ")", ")", "/", "dem", ";", "double", "yi", "=", "(", "(", "x1", "*", "y2", "-", "y1", "*", "x2", ")", "*", "(", "y3", "-", "y4", ")", "-", "(", "y1", "-", "y2", ")", "*", "(", "x3", "*", "y4", "-", "y3", "*", "x4", ")", ")", "/", "dem", ";", "// Check the point isn't off the ends of the lines", "if", "(", "(", "x1", "-", "xi", ")", "*", "(", "xi", "-", "x2", ")", ">=", "0", "&&", "(", "x3", "-", "xi", ")", "*", "(", "xi", "-", "x4", ")", ">=", "0", "&&", "(", "y1", "-", "yi", ")", "*", "(", "yi", "-", "y2", ")", ">=", "0", "&&", "(", "y3", "-", "yi", ")", "*", "(", "yi", "-", "y4", ")", ">=", "0", ")", "{", "return", "new", "Point", "(", "(", "int", ")", "xi", ",", "(", "int", ")", "yi", ")", ";", "}", "return", "null", ";", "}" ]
Intersect two lines
[ "Intersect", "two", "lines" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/QuickWidget.java#L78-L91
3,034
operasoftware/operaprestodriver
src/com/opera/core/systems/QuickWidget.java
QuickWidget.intersection
private Point intersection(int x1, int y1, int x2, int y2, DesktopWindowRect rect) { Point bottom = intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX() + rect.getHeight(), rect.getY()); if (bottom != null) { return bottom; } Point right = intersection(x1, y1, x2, y2, rect.getX() + rect.getWidth(), rect.getY(), rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight()); if (right != null) { return right; } Point top = intersection(x1, y1, x2, y2, rect.getX(), rect.getY() + rect.getHeight(), rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight()); if (top != null) { return top; } Point left = intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX(), rect.getY() + rect.getHeight()); if (left != null) { return left; } return null; }
java
private Point intersection(int x1, int y1, int x2, int y2, DesktopWindowRect rect) { Point bottom = intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX() + rect.getHeight(), rect.getY()); if (bottom != null) { return bottom; } Point right = intersection(x1, y1, x2, y2, rect.getX() + rect.getWidth(), rect.getY(), rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight()); if (right != null) { return right; } Point top = intersection(x1, y1, x2, y2, rect.getX(), rect.getY() + rect.getHeight(), rect.getX() + rect.getWidth(), rect.getY() + rect.getHeight()); if (top != null) { return top; } Point left = intersection(x1, y1, x2, y2, rect.getX(), rect.getY(), rect.getX(), rect.getY() + rect.getHeight()); if (left != null) { return left; } return null; }
[ "private", "Point", "intersection", "(", "int", "x1", ",", "int", "y1", ",", "int", "x2", ",", "int", "y2", ",", "DesktopWindowRect", "rect", ")", "{", "Point", "bottom", "=", "intersection", "(", "x1", ",", "y1", ",", "x2", ",", "y2", ",", "rect", ".", "getX", "(", ")", ",", "rect", ".", "getY", "(", ")", ",", "rect", ".", "getX", "(", ")", "+", "rect", ".", "getHeight", "(", ")", ",", "rect", ".", "getY", "(", ")", ")", ";", "if", "(", "bottom", "!=", "null", ")", "{", "return", "bottom", ";", "}", "Point", "right", "=", "intersection", "(", "x1", ",", "y1", ",", "x2", ",", "y2", ",", "rect", ".", "getX", "(", ")", "+", "rect", ".", "getWidth", "(", ")", ",", "rect", ".", "getY", "(", ")", ",", "rect", ".", "getX", "(", ")", "+", "rect", ".", "getWidth", "(", ")", ",", "rect", ".", "getY", "(", ")", "+", "rect", ".", "getHeight", "(", ")", ")", ";", "if", "(", "right", "!=", "null", ")", "{", "return", "right", ";", "}", "Point", "top", "=", "intersection", "(", "x1", ",", "y1", ",", "x2", ",", "y2", ",", "rect", ".", "getX", "(", ")", ",", "rect", ".", "getY", "(", ")", "+", "rect", ".", "getHeight", "(", ")", ",", "rect", ".", "getX", "(", ")", "+", "rect", ".", "getWidth", "(", ")", ",", "rect", ".", "getY", "(", ")", "+", "rect", ".", "getHeight", "(", ")", ")", ";", "if", "(", "top", "!=", "null", ")", "{", "return", "top", ";", "}", "Point", "left", "=", "intersection", "(", "x1", ",", "y1", ",", "x2", ",", "y2", ",", "rect", ".", "getX", "(", ")", ",", "rect", ".", "getY", "(", ")", ",", "rect", ".", "getX", "(", ")", ",", "rect", ".", "getY", "(", ")", "+", "rect", ".", "getHeight", "(", ")", ")", ";", "if", "(", "left", "!=", "null", ")", "{", "return", "left", ";", "}", "return", "null", ";", "}" ]
Intersect a line and a DesktopWindowRect
[ "Intersect", "a", "line", "and", "a", "DesktopWindowRect" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/QuickWidget.java#L94-L128
3,035
operasoftware/operaprestodriver
src/com/opera/core/systems/QuickWidget.java
QuickWidget.dragAndDropOn
public void dragAndDropOn(QuickWidget widget, DropPosition dropPos) { /* * FIXME: Handle MousePosition */ Point currentLocation = getCenterLocation(); Point dropPoint = getDropPoint(widget, dropPos); List<ModifierPressed> alist = new ArrayList<ModifierPressed>(); alist.add(ModifierPressed.NONE); getSystemInputManager().mouseDown(currentLocation, MouseButton.LEFT, alist); getSystemInputManager().mouseMove(dropPoint, MouseButton.LEFT, alist); getSystemInputManager().mouseUp(dropPoint, MouseButton.LEFT, alist); }
java
public void dragAndDropOn(QuickWidget widget, DropPosition dropPos) { /* * FIXME: Handle MousePosition */ Point currentLocation = getCenterLocation(); Point dropPoint = getDropPoint(widget, dropPos); List<ModifierPressed> alist = new ArrayList<ModifierPressed>(); alist.add(ModifierPressed.NONE); getSystemInputManager().mouseDown(currentLocation, MouseButton.LEFT, alist); getSystemInputManager().mouseMove(dropPoint, MouseButton.LEFT, alist); getSystemInputManager().mouseUp(dropPoint, MouseButton.LEFT, alist); }
[ "public", "void", "dragAndDropOn", "(", "QuickWidget", "widget", ",", "DropPosition", "dropPos", ")", "{", "/*\n * FIXME: Handle MousePosition\n */", "Point", "currentLocation", "=", "getCenterLocation", "(", ")", ";", "Point", "dropPoint", "=", "getDropPoint", "(", "widget", ",", "dropPos", ")", ";", "List", "<", "ModifierPressed", ">", "alist", "=", "new", "ArrayList", "<", "ModifierPressed", ">", "(", ")", ";", "alist", ".", "add", "(", "ModifierPressed", ".", "NONE", ")", ";", "getSystemInputManager", "(", ")", ".", "mouseDown", "(", "currentLocation", ",", "MouseButton", ".", "LEFT", ",", "alist", ")", ";", "getSystemInputManager", "(", ")", ".", "mouseMove", "(", "dropPoint", ",", "MouseButton", ".", "LEFT", ",", "alist", ")", ";", "getSystemInputManager", "(", ")", ".", "mouseUp", "(", "dropPoint", ",", "MouseButton", ".", "LEFT", ",", "alist", ")", ";", "}" ]
Drags this widget onto the specified widget at the given drop position @param widget the widget to drop this widget onto @param dropPos the position to drop this widget into, CENTER, EDGE or BETWEEN
[ "Drags", "this", "widget", "onto", "the", "specified", "widget", "at", "the", "given", "drop", "position" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/QuickWidget.java#L136-L149
3,036
operasoftware/operaprestodriver
src/com/opera/core/systems/QuickWidget.java
QuickWidget.getDropPoint
private Point getDropPoint(QuickWidget element, DropPosition pos) { Point dropPoint = new Point(element.getCenterLocation().x, element.getCenterLocation().y); if (pos == DropPosition.CENTER) { return dropPoint; } Point dragPoint = new Point(this.getCenterLocation().x, this.getCenterLocation().y); // Find the side of the DesktopWindowRect of the widget that as the intersect Point dragIntersectPoint = intersection(dragPoint.x, dragPoint.y, dropPoint.x, dropPoint.y, this.getRect()); if (dragIntersectPoint != null) { Point dropIntersectPoint = intersection(dragPoint.x, dragPoint.y, dropPoint.x, dropPoint.y, element.getRect()); if (dropIntersectPoint != null) { if (pos == DropPosition.EDGE) { return dropIntersectPoint; } // Get the mid point of the line return new Point((dragIntersectPoint.x + dropIntersectPoint.x) / 2, (dragIntersectPoint.y + dropIntersectPoint.y) / 2); } } return null; }
java
private Point getDropPoint(QuickWidget element, DropPosition pos) { Point dropPoint = new Point(element.getCenterLocation().x, element.getCenterLocation().y); if (pos == DropPosition.CENTER) { return dropPoint; } Point dragPoint = new Point(this.getCenterLocation().x, this.getCenterLocation().y); // Find the side of the DesktopWindowRect of the widget that as the intersect Point dragIntersectPoint = intersection(dragPoint.x, dragPoint.y, dropPoint.x, dropPoint.y, this.getRect()); if (dragIntersectPoint != null) { Point dropIntersectPoint = intersection(dragPoint.x, dragPoint.y, dropPoint.x, dropPoint.y, element.getRect()); if (dropIntersectPoint != null) { if (pos == DropPosition.EDGE) { return dropIntersectPoint; } // Get the mid point of the line return new Point((dragIntersectPoint.x + dropIntersectPoint.x) / 2, (dragIntersectPoint.y + dropIntersectPoint.y) / 2); } } return null; }
[ "private", "Point", "getDropPoint", "(", "QuickWidget", "element", ",", "DropPosition", "pos", ")", "{", "Point", "dropPoint", "=", "new", "Point", "(", "element", ".", "getCenterLocation", "(", ")", ".", "x", ",", "element", ".", "getCenterLocation", "(", ")", ".", "y", ")", ";", "if", "(", "pos", "==", "DropPosition", ".", "CENTER", ")", "{", "return", "dropPoint", ";", "}", "Point", "dragPoint", "=", "new", "Point", "(", "this", ".", "getCenterLocation", "(", ")", ".", "x", ",", "this", ".", "getCenterLocation", "(", ")", ".", "y", ")", ";", "// Find the side of the DesktopWindowRect of the widget that as the intersect", "Point", "dragIntersectPoint", "=", "intersection", "(", "dragPoint", ".", "x", ",", "dragPoint", ".", "y", ",", "dropPoint", ".", "x", ",", "dropPoint", ".", "y", ",", "this", ".", "getRect", "(", ")", ")", ";", "if", "(", "dragIntersectPoint", "!=", "null", ")", "{", "Point", "dropIntersectPoint", "=", "intersection", "(", "dragPoint", ".", "x", ",", "dragPoint", ".", "y", ",", "dropPoint", ".", "x", ",", "dropPoint", ".", "y", ",", "element", ".", "getRect", "(", ")", ")", ";", "if", "(", "dropIntersectPoint", "!=", "null", ")", "{", "if", "(", "pos", "==", "DropPosition", ".", "EDGE", ")", "{", "return", "dropIntersectPoint", ";", "}", "// Get the mid point of the line", "return", "new", "Point", "(", "(", "dragIntersectPoint", ".", "x", "+", "dropIntersectPoint", ".", "x", ")", "/", "2", ",", "(", "dragIntersectPoint", ".", "y", "+", "dropIntersectPoint", ".", "y", ")", "/", "2", ")", ";", "}", "}", "return", "null", ";", "}" ]
The drop point is on the quick widget passed in
[ "The", "drop", "point", "is", "on", "the", "quick", "widget", "passed", "in" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/QuickWidget.java#L153-L183
3,037
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClassManager.java
TemplateClassManager.getByClassName
public TemplateClass getByClassName(String name) { TemplateClass tc = clsNameIdx.get(name); checkUpdate(tc); return tc; }
java
public TemplateClass getByClassName(String name) { TemplateClass tc = clsNameIdx.get(name); checkUpdate(tc); return tc; }
[ "public", "TemplateClass", "getByClassName", "(", "String", "name", ")", "{", "TemplateClass", "tc", "=", "clsNameIdx", ".", "get", "(", "name", ")", ";", "checkUpdate", "(", "tc", ")", ";", "return", "tc", ";", "}" ]
Get a class by name @param name The fully qualified class name @return The TemplateClass or null
[ "Get", "a", "class", "by", "name" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClassManager.java#L75-L79
3,038
operasoftware/operaprestodriver
src/com/opera/core/systems/internal/WatirUtils.java
WatirUtils.getSystemDoubleClickTimeMs
public static Integer getSystemDoubleClickTimeMs() { Integer DEFAULT_INTERVAL_MS = 500; Toolkit t = Toolkit.getDefaultToolkit(); if (t == null) { return DEFAULT_INTERVAL_MS; } Object o = t.getDesktopProperty("awt.multiClickInterval"); if (o == null) { return DEFAULT_INTERVAL_MS; } return (Integer) o; }
java
public static Integer getSystemDoubleClickTimeMs() { Integer DEFAULT_INTERVAL_MS = 500; Toolkit t = Toolkit.getDefaultToolkit(); if (t == null) { return DEFAULT_INTERVAL_MS; } Object o = t.getDesktopProperty("awt.multiClickInterval"); if (o == null) { return DEFAULT_INTERVAL_MS; } return (Integer) o; }
[ "public", "static", "Integer", "getSystemDoubleClickTimeMs", "(", ")", "{", "Integer", "DEFAULT_INTERVAL_MS", "=", "500", ";", "Toolkit", "t", "=", "Toolkit", ".", "getDefaultToolkit", "(", ")", ";", "if", "(", "t", "==", "null", ")", "{", "return", "DEFAULT_INTERVAL_MS", ";", "}", "Object", "o", "=", "t", ".", "getDesktopProperty", "(", "\"awt.multiClickInterval\"", ")", ";", "if", "(", "o", "==", "null", ")", "{", "return", "DEFAULT_INTERVAL_MS", ";", "}", "return", "(", "Integer", ")", "o", ";", "}" ]
Returns the platform double click timeout, that is the time that separates two clicks treated as a double click from two clicks treated as two single clicks.
[ "Returns", "the", "platform", "double", "click", "timeout", "that", "is", "the", "time", "that", "separates", "two", "clicks", "treated", "as", "a", "double", "click", "from", "two", "clicks", "treated", "as", "two", "single", "clicks", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/internal/WatirUtils.java#L42-L56
3,039
operasoftware/operaprestodriver
src/com/opera/core/systems/internal/WatirUtils.java
WatirUtils.textMatchesWithANY
public static boolean textMatchesWithANY(String haystack, String needle) { haystack = haystack.trim(); needle = needle.trim(); // Make sure we escape every character that is considered to be a special character inside a // regular expression. Matcher.quoteReplacement() takes care of '\\' and '$'. needle = Matcher.quoteReplacement(needle); String chars_to_be_escaped = ".|*?+(){}[]^"; for (char c : chars_to_be_escaped.toCharArray()) { String regex = "\\" + c; String replacement = "\\\\" + c; needle = needle.replaceAll(regex, replacement); } String pattern = needle.replaceAll(ANY_MATCHER, "(?:.+)"); logger.finest("Looking for pattern '" + pattern + "' in '" + haystack + "'"); return haystack.matches(pattern); }
java
public static boolean textMatchesWithANY(String haystack, String needle) { haystack = haystack.trim(); needle = needle.trim(); // Make sure we escape every character that is considered to be a special character inside a // regular expression. Matcher.quoteReplacement() takes care of '\\' and '$'. needle = Matcher.quoteReplacement(needle); String chars_to_be_escaped = ".|*?+(){}[]^"; for (char c : chars_to_be_escaped.toCharArray()) { String regex = "\\" + c; String replacement = "\\\\" + c; needle = needle.replaceAll(regex, replacement); } String pattern = needle.replaceAll(ANY_MATCHER, "(?:.+)"); logger.finest("Looking for pattern '" + pattern + "' in '" + haystack + "'"); return haystack.matches(pattern); }
[ "public", "static", "boolean", "textMatchesWithANY", "(", "String", "haystack", ",", "String", "needle", ")", "{", "haystack", "=", "haystack", ".", "trim", "(", ")", ";", "needle", "=", "needle", ".", "trim", "(", ")", ";", "// Make sure we escape every character that is considered to be a special character inside a", "// regular expression. Matcher.quoteReplacement() takes care of '\\\\' and '$'.", "needle", "=", "Matcher", ".", "quoteReplacement", "(", "needle", ")", ";", "String", "chars_to_be_escaped", "=", "\".|*?+(){}[]^\"", ";", "for", "(", "char", "c", ":", "chars_to_be_escaped", ".", "toCharArray", "(", ")", ")", "{", "String", "regex", "=", "\"\\\\\"", "+", "c", ";", "String", "replacement", "=", "\"\\\\\\\\\"", "+", "c", ";", "needle", "=", "needle", ".", "replaceAll", "(", "regex", ",", "replacement", ")", ";", "}", "String", "pattern", "=", "needle", ".", "replaceAll", "(", "ANY_MATCHER", ",", "\"(?:.+)\"", ")", ";", "logger", ".", "finest", "(", "\"Looking for pattern '\"", "+", "pattern", "+", "\"' in '\"", "+", "haystack", "+", "\"'\"", ")", ";", "return", "haystack", ".", "matches", "(", "pattern", ")", ";", "}" ]
Compares haystack and needle taking into the account that the needle may contain any number of ANY_MATCHER occurrences, that will be matched to any substring in haystack, i.e. "Show _ANY_ more..." will match anything like "Show 1 more...", "Show 2 more..." and so on. @param haystack the text that will be compared, may not contain any ANY_MATCHER occurrence @param needle the text that will be used for comparision, may contain any number of ANY_MATCHER occurrences @return a boolean indicating whether needle matched haystack.
[ "Compares", "haystack", "and", "needle", "taking", "into", "the", "account", "that", "the", "needle", "may", "contain", "any", "number", "of", "ANY_MATCHER", "occurrences", "that", "will", "be", "matched", "to", "any", "substring", "in", "haystack", "i", ".", "e", ".", "Show", "_ANY_", "more", "...", "will", "match", "anything", "like", "Show", "1", "more", "...", "Show", "2", "more", "...", "and", "so", "on", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/internal/WatirUtils.java#L133-L152
3,040
operasoftware/operaprestodriver
src/com/opera/core/systems/scope/stp/services/ScopeEcmascriptDebugger.java
ScopeEcmascriptDebugger.parseEvalReply
protected Object parseEvalReply(EvalResult result) { String status = result.getStatus(); if (!status.equals("completed")) { if (status.equals("unhandled-exception")) { // Would be great give the JS error here, but it appears that by the // time we callFunctionOnObject the error object has gone... throw new ScopeException("Ecmascript exception"); } else if (status.equals("cancelled-by-scheduler")) { // TODO: what is the best approach here? return null; } } String dataType = result.getType(); if (dataType.equals("object")) { return result.getObjectValue(); } else { return parseValue(dataType, result.getValue()); } }
java
protected Object parseEvalReply(EvalResult result) { String status = result.getStatus(); if (!status.equals("completed")) { if (status.equals("unhandled-exception")) { // Would be great give the JS error here, but it appears that by the // time we callFunctionOnObject the error object has gone... throw new ScopeException("Ecmascript exception"); } else if (status.equals("cancelled-by-scheduler")) { // TODO: what is the best approach here? return null; } } String dataType = result.getType(); if (dataType.equals("object")) { return result.getObjectValue(); } else { return parseValue(dataType, result.getValue()); } }
[ "protected", "Object", "parseEvalReply", "(", "EvalResult", "result", ")", "{", "String", "status", "=", "result", ".", "getStatus", "(", ")", ";", "if", "(", "!", "status", ".", "equals", "(", "\"completed\"", ")", ")", "{", "if", "(", "status", ".", "equals", "(", "\"unhandled-exception\"", ")", ")", "{", "// Would be great give the JS error here, but it appears that by the", "// time we callFunctionOnObject the error object has gone...", "throw", "new", "ScopeException", "(", "\"Ecmascript exception\"", ")", ";", "}", "else", "if", "(", "status", ".", "equals", "(", "\"cancelled-by-scheduler\"", ")", ")", "{", "// TODO: what is the best approach here?", "return", "null", ";", "}", "}", "String", "dataType", "=", "result", ".", "getType", "(", ")", ";", "if", "(", "dataType", ".", "equals", "(", "\"object\"", ")", ")", "{", "return", "result", ".", "getObjectValue", "(", ")", ";", "}", "else", "{", "return", "parseValue", "(", "dataType", ",", "result", ".", "getValue", "(", ")", ")", ";", "}", "}" ]
Parses a reply and returns the following types String presentation of number, boolean or string.
[ "Parses", "a", "reply", "and", "returns", "the", "following", "types", "String", "presentation", "of", "number", "boolean", "or", "string", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/scope/stp/services/ScopeEcmascriptDebugger.java#L330-L350
3,041
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/Eval.java
Eval.eval
public static boolean eval(String s) { if (S.isEmpty(s)) return false; if ("false".equalsIgnoreCase(s)) return false; if ("no".equalsIgnoreCase(s)) return false; return true; }
java
public static boolean eval(String s) { if (S.isEmpty(s)) return false; if ("false".equalsIgnoreCase(s)) return false; if ("no".equalsIgnoreCase(s)) return false; return true; }
[ "public", "static", "boolean", "eval", "(", "String", "s", ")", "{", "if", "(", "S", ".", "isEmpty", "(", "s", ")", ")", "return", "false", ";", "if", "(", "\"false\"", ".", "equalsIgnoreCase", "(", "s", ")", ")", "return", "false", ";", "if", "(", "\"no\"", ".", "equalsIgnoreCase", "(", "s", ")", ")", "return", "false", ";", "return", "true", ";", "}" ]
Return true if the specified string does not equals, ignore case, to "false" or "no" @param s @return boolean result
[ "Return", "true", "if", "the", "specified", "string", "does", "not", "equals", "ignore", "case", "to", "false", "or", "no" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/Eval.java#L89-L94
3,042
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/Eval.java
Eval.locale
public static Locale locale(String language) { if (language.contains("_")) { String[] sa = language.split("_"); if (sa.length > 2) { return new Locale(sa[0], sa[1], sa[2]); } else if (sa.length > 1) { return new Locale(sa[0], sa[1]); } else { return new Locale(sa[0]); } } return new Locale(language); }
java
public static Locale locale(String language) { if (language.contains("_")) { String[] sa = language.split("_"); if (sa.length > 2) { return new Locale(sa[0], sa[1], sa[2]); } else if (sa.length > 1) { return new Locale(sa[0], sa[1]); } else { return new Locale(sa[0]); } } return new Locale(language); }
[ "public", "static", "Locale", "locale", "(", "String", "language", ")", "{", "if", "(", "language", ".", "contains", "(", "\"_\"", ")", ")", "{", "String", "[", "]", "sa", "=", "language", ".", "split", "(", "\"_\"", ")", ";", "if", "(", "sa", ".", "length", ">", "2", ")", "{", "return", "new", "Locale", "(", "sa", "[", "0", "]", ",", "sa", "[", "1", "]", ",", "sa", "[", "2", "]", ")", ";", "}", "else", "if", "(", "sa", ".", "length", ">", "1", ")", "{", "return", "new", "Locale", "(", "sa", "[", "0", "]", ",", "sa", "[", "1", "]", ")", ";", "}", "else", "{", "return", "new", "Locale", "(", "sa", "[", "0", "]", ")", ";", "}", "}", "return", "new", "Locale", "(", "language", ")", ";", "}" ]
Eval locale from language string @param language @return new Locale constructed from the language
[ "Eval", "locale", "from", "language", "string" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/Eval.java#L221-L233
3,043
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/Eval.java
Eval.locale
public static Locale locale(String language, String region, String variant) { return new Locale(language, region, variant); }
java
public static Locale locale(String language, String region, String variant) { return new Locale(language, region, variant); }
[ "public", "static", "Locale", "locale", "(", "String", "language", ",", "String", "region", ",", "String", "variant", ")", "{", "return", "new", "Locale", "(", "language", ",", "region", ",", "variant", ")", ";", "}" ]
Eval locale from language, region and variant @param language @param region @param variant @return the new Locale constructed
[ "Eval", "locale", "from", "language", "region", "and", "variant" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/Eval.java#L252-L254
3,044
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaUIElement.java
OperaUIElement.verifyText
public boolean verifyText(String stringId) { String text = desktopUtils.getString(stringId, true /* skipAmpersand */); return getText().equals(text); }
java
public boolean verifyText(String stringId) { String text = desktopUtils.getString(stringId, true /* skipAmpersand */); return getText().equals(text); }
[ "public", "boolean", "verifyText", "(", "String", "stringId", ")", "{", "String", "text", "=", "desktopUtils", ".", "getString", "(", "stringId", ",", "true", "/* skipAmpersand */", ")", ";", "return", "getText", "(", ")", ".", "equals", "(", "text", ")", ";", "}" ]
Checks if widget text equals the text specified by the given string id @return true if text specified by stringId equals widget text
[ "Checks", "if", "widget", "text", "equals", "the", "text", "specified", "by", "the", "given", "string", "id" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaUIElement.java#L104-L108
3,045
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaUIElement.java
OperaUIElement.verifyContainsText
public boolean verifyContainsText(String stringId) { String text = desktopUtils.getString(stringId, true); return getText().indexOf(text) >= 0; }
java
public boolean verifyContainsText(String stringId) { String text = desktopUtils.getString(stringId, true); return getText().indexOf(text) >= 0; }
[ "public", "boolean", "verifyContainsText", "(", "String", "stringId", ")", "{", "String", "text", "=", "desktopUtils", ".", "getString", "(", "stringId", ",", "true", ")", ";", "return", "getText", "(", ")", ".", "indexOf", "(", "text", ")", ">=", "0", ";", "}" ]
Checks if widget text contains the text specified by the given string id @param stringId String id of string @return true if text specified by stringId is contained in widget text
[ "Checks", "if", "widget", "text", "contains", "the", "text", "specified", "by", "the", "given", "string", "id" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaUIElement.java#L116-L119
3,046
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClass.java
TemplateClass.compile
public synchronized byte[] compile() { long start = System.currentTimeMillis(); try { if (null != javaByteCode) { return javaByteCode; } if (null == javaSource) { throw new IllegalStateException("Cannot find java source when compiling " + getKey()); } engine().classes().compiler.compile(new String[]{name}); if (logger.isTraceEnabled()) { logger.trace("%sms to compile template: %s", System.currentTimeMillis() - start, getKey()); } return javaByteCode; } catch (CompileException.CompilerException e) { String cn = e.className; TemplateClass tc = S.isEqual(cn, name) ? this : engine().classes().getByClassName(cn); if (null == tc) { tc = this; } CompileException ce = new CompileException(engine(), tc, e.javaLineNumber, e.message); // init ce before reset java source to get template line info javaSource = null; // force parser to regenerate source. This helps to reload after fixing the tag file compilation failure logger.warn("compile failed for %s at line %d",tc.tagName,e.javaLineNumber); for (TemplateClass itc:this.includedTemplateClasses) { logger.info("\tincluded: %s",itc.tagName); } throw ce; } catch (NullPointerException e) { String clazzName = name; TemplateClass tc = engine().classes().getByClassName(clazzName); if (this != tc) { logger.error("tc is not this"); } if (!this.equals(tc)) { logger.error("tc not match this"); } logger.error("NPE encountered when compiling template class:" + name); throw e; } finally { if (logger.isTraceEnabled()) { logger.trace("%sms to compile template class %s", System.currentTimeMillis() - start, getKey()); } } }
java
public synchronized byte[] compile() { long start = System.currentTimeMillis(); try { if (null != javaByteCode) { return javaByteCode; } if (null == javaSource) { throw new IllegalStateException("Cannot find java source when compiling " + getKey()); } engine().classes().compiler.compile(new String[]{name}); if (logger.isTraceEnabled()) { logger.trace("%sms to compile template: %s", System.currentTimeMillis() - start, getKey()); } return javaByteCode; } catch (CompileException.CompilerException e) { String cn = e.className; TemplateClass tc = S.isEqual(cn, name) ? this : engine().classes().getByClassName(cn); if (null == tc) { tc = this; } CompileException ce = new CompileException(engine(), tc, e.javaLineNumber, e.message); // init ce before reset java source to get template line info javaSource = null; // force parser to regenerate source. This helps to reload after fixing the tag file compilation failure logger.warn("compile failed for %s at line %d",tc.tagName,e.javaLineNumber); for (TemplateClass itc:this.includedTemplateClasses) { logger.info("\tincluded: %s",itc.tagName); } throw ce; } catch (NullPointerException e) { String clazzName = name; TemplateClass tc = engine().classes().getByClassName(clazzName); if (this != tc) { logger.error("tc is not this"); } if (!this.equals(tc)) { logger.error("tc not match this"); } logger.error("NPE encountered when compiling template class:" + name); throw e; } finally { if (logger.isTraceEnabled()) { logger.trace("%sms to compile template class %s", System.currentTimeMillis() - start, getKey()); } } }
[ "public", "synchronized", "byte", "[", "]", "compile", "(", ")", "{", "long", "start", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "try", "{", "if", "(", "null", "!=", "javaByteCode", ")", "{", "return", "javaByteCode", ";", "}", "if", "(", "null", "==", "javaSource", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Cannot find java source when compiling \"", "+", "getKey", "(", ")", ")", ";", "}", "engine", "(", ")", ".", "classes", "(", ")", ".", "compiler", ".", "compile", "(", "new", "String", "[", "]", "{", "name", "}", ")", ";", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "\"%sms to compile template: %s\"", ",", "System", ".", "currentTimeMillis", "(", ")", "-", "start", ",", "getKey", "(", ")", ")", ";", "}", "return", "javaByteCode", ";", "}", "catch", "(", "CompileException", ".", "CompilerException", "e", ")", "{", "String", "cn", "=", "e", ".", "className", ";", "TemplateClass", "tc", "=", "S", ".", "isEqual", "(", "cn", ",", "name", ")", "?", "this", ":", "engine", "(", ")", ".", "classes", "(", ")", ".", "getByClassName", "(", "cn", ")", ";", "if", "(", "null", "==", "tc", ")", "{", "tc", "=", "this", ";", "}", "CompileException", "ce", "=", "new", "CompileException", "(", "engine", "(", ")", ",", "tc", ",", "e", ".", "javaLineNumber", ",", "e", ".", "message", ")", ";", "// init ce before reset java source to get template line info", "javaSource", "=", "null", ";", "// force parser to regenerate source. This helps to reload after fixing the tag file compilation failure", "logger", ".", "warn", "(", "\"compile failed for %s at line %d\"", ",", "tc", ".", "tagName", ",", "e", ".", "javaLineNumber", ")", ";", "for", "(", "TemplateClass", "itc", ":", "this", ".", "includedTemplateClasses", ")", "{", "logger", ".", "info", "(", "\"\\tincluded: %s\"", ",", "itc", ".", "tagName", ")", ";", "}", "throw", "ce", ";", "}", "catch", "(", "NullPointerException", "e", ")", "{", "String", "clazzName", "=", "name", ";", "TemplateClass", "tc", "=", "engine", "(", ")", ".", "classes", "(", ")", ".", "getByClassName", "(", "clazzName", ")", ";", "if", "(", "this", "!=", "tc", ")", "{", "logger", ".", "error", "(", "\"tc is not this\"", ")", ";", "}", "if", "(", "!", "this", ".", "equals", "(", "tc", ")", ")", "{", "logger", ".", "error", "(", "\"tc not match this\"", ")", ";", "}", "logger", ".", "error", "(", "\"NPE encountered when compiling template class:\"", "+", "name", ")", ";", "throw", "e", ";", "}", "finally", "{", "if", "(", "logger", ".", "isTraceEnabled", "(", ")", ")", "{", "logger", ".", "trace", "(", "\"%sms to compile template class %s\"", ",", "System", ".", "currentTimeMillis", "(", ")", "-", "start", ",", "getKey", "(", ")", ")", ";", "}", "}", "}" ]
Compile the class from Java source @return the bytes that comprise the class file
[ "Compile", "the", "class", "from", "Java", "source" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClass.java#L664-L707
3,047
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClass.java
TemplateClass.compiled
public void compiled(byte[] code) { javaByteCode = code; //enhancedByteCode = code; compiled = true; RythmEvents.COMPILED.trigger(engine(), code); enhance(); //compiled(code, false); }
java
public void compiled(byte[] code) { javaByteCode = code; //enhancedByteCode = code; compiled = true; RythmEvents.COMPILED.trigger(engine(), code); enhance(); //compiled(code, false); }
[ "public", "void", "compiled", "(", "byte", "[", "]", "code", ")", "{", "javaByteCode", "=", "code", ";", "//enhancedByteCode = code;", "compiled", "=", "true", ";", "RythmEvents", ".", "COMPILED", ".", "trigger", "(", "engine", "(", ")", ",", "code", ")", ";", "enhance", "(", ")", ";", "//compiled(code, false);", "}" ]
Call back when a class is compiled. @param code The bytecode.
[ "Call", "back", "when", "a", "class", "is", "compiled", "." ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClass.java#L780-L787
3,048
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/compiler/TemplateClass.java
TemplateClass.toCanonicalName
private static String toCanonicalName(String key, String root) { if (key.startsWith("/") || key.startsWith("\\")) { key = key.substring(1); } if (key.startsWith(root)) { key = key.replace(root, ""); } if (key.startsWith("/") || key.startsWith("\\")) { key = key.substring(1); } //if (-1 != pos) key = key.substring(0, pos); key = key.replace('/', '.').replace('\\', '.'); return key; }
java
private static String toCanonicalName(String key, String root) { if (key.startsWith("/") || key.startsWith("\\")) { key = key.substring(1); } if (key.startsWith(root)) { key = key.replace(root, ""); } if (key.startsWith("/") || key.startsWith("\\")) { key = key.substring(1); } //if (-1 != pos) key = key.substring(0, pos); key = key.replace('/', '.').replace('\\', '.'); return key; }
[ "private", "static", "String", "toCanonicalName", "(", "String", "key", ",", "String", "root", ")", "{", "if", "(", "key", ".", "startsWith", "(", "\"/\"", ")", "||", "key", ".", "startsWith", "(", "\"\\\\\"", ")", ")", "{", "key", "=", "key", ".", "substring", "(", "1", ")", ";", "}", "if", "(", "key", ".", "startsWith", "(", "root", ")", ")", "{", "key", "=", "key", ".", "replace", "(", "root", ",", "\"\"", ")", ";", "}", "if", "(", "key", ".", "startsWith", "(", "\"/\"", ")", "||", "key", ".", "startsWith", "(", "\"\\\\\"", ")", ")", "{", "key", "=", "key", ".", "substring", "(", "1", ")", ";", "}", "//if (-1 != pos) key = key.substring(0, pos);", "key", "=", "key", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "return", "key", ";", "}" ]
Convert the key to canonical template name @param key the resource key @param root the resource loader root path @return the canonical name
[ "Convert", "the", "key", "to", "canonical", "template", "name" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/compiler/TemplateClass.java#L845-L858
3,049
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaMouse.java
OperaMouse.tripleClick
public void tripleClick(Coordinates where) { Point p = getPoint(where, "triple click"); exec.mouseAction(p.x, p.y, 3, OperaMouseKeys.LEFT); }
java
public void tripleClick(Coordinates where) { Point p = getPoint(where, "triple click"); exec.mouseAction(p.x, p.y, 3, OperaMouseKeys.LEFT); }
[ "public", "void", "tripleClick", "(", "Coordinates", "where", ")", "{", "Point", "p", "=", "getPoint", "(", "where", ",", "\"triple click\"", ")", ";", "exec", ".", "mouseAction", "(", "p", ".", "x", ",", "p", ".", "y", ",", "3", ",", "OperaMouseKeys", ".", "LEFT", ")", ";", "}" ]
Triple click is an Opera specific way of selecting a sentence. @param where to click
[ "Triple", "click", "is", "an", "Opera", "specific", "way", "of", "selecting", "a", "sentence", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaMouse.java#L57-L60
3,050
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaProxy.java
OperaProxy.setHttpsProxy
public void setHttpsProxy(String host) { setProxyValue(HTTPS_SERVER, host); setProxyValue(USE_HTTPS, host != null); }
java
public void setHttpsProxy(String host) { setProxyValue(HTTPS_SERVER, host); setProxyValue(USE_HTTPS, host != null); }
[ "public", "void", "setHttpsProxy", "(", "String", "host", ")", "{", "setProxyValue", "(", "HTTPS_SERVER", ",", "host", ")", ";", "setProxyValue", "(", "USE_HTTPS", ",", "host", "!=", "null", ")", ";", "}" ]
Specify which proxy to use for HTTPS connections. @param host the proxy host, expected format is <code>hostname:1234</code>
[ "Specify", "which", "proxy", "to", "use", "for", "HTTPS", "connections", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaProxy.java#L121-L124
3,051
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.initDesktopDriver
private void initDesktopDriver() { // super.init(); setServices(); setPrefsPaths(); // Start Opera if it is not already running // If the Opera Binary isn't set we are assuming Opera is up and we // can ask it for the location of itself if (settings.getBinary() == null && !settings.noRestart()) { String operaPath = getOperaPath(); logger.fine("OperaBinaryLocation retrieved from Opera: " + operaPath); if (operaPath.length() > 0) { settings.setBinary(new File(operaPath)); // Now create the OperaLauncherRunner that we have the binary path runner = new OperaLauncherRunner(settings); // Quit and wait for opera to quit properly try { getScopeServices().quit(runner); } catch (IOException e) { throw new WebDriverException(e); } // Delete the profile to start the first test with a clean profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } // Work around stop and restart Opera so the Launcher has control of it now // Initialising the services will start Opera if the OperaLauncherRunner is // setup correctly startOpera(); } } }
java
private void initDesktopDriver() { // super.init(); setServices(); setPrefsPaths(); // Start Opera if it is not already running // If the Opera Binary isn't set we are assuming Opera is up and we // can ask it for the location of itself if (settings.getBinary() == null && !settings.noRestart()) { String operaPath = getOperaPath(); logger.fine("OperaBinaryLocation retrieved from Opera: " + operaPath); if (operaPath.length() > 0) { settings.setBinary(new File(operaPath)); // Now create the OperaLauncherRunner that we have the binary path runner = new OperaLauncherRunner(settings); // Quit and wait for opera to quit properly try { getScopeServices().quit(runner); } catch (IOException e) { throw new WebDriverException(e); } // Delete the profile to start the first test with a clean profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } // Work around stop and restart Opera so the Launcher has control of it now // Initialising the services will start Opera if the OperaLauncherRunner is // setup correctly startOpera(); } } }
[ "private", "void", "initDesktopDriver", "(", ")", "{", "// super.init();", "setServices", "(", ")", ";", "setPrefsPaths", "(", ")", ";", "// Start Opera if it is not already running", "// If the Opera Binary isn't set we are assuming Opera is up and we", "// can ask it for the location of itself", "if", "(", "settings", ".", "getBinary", "(", ")", "==", "null", "&&", "!", "settings", ".", "noRestart", "(", ")", ")", "{", "String", "operaPath", "=", "getOperaPath", "(", ")", ";", "logger", ".", "fine", "(", "\"OperaBinaryLocation retrieved from Opera: \"", "+", "operaPath", ")", ";", "if", "(", "operaPath", ".", "length", "(", ")", ">", "0", ")", "{", "settings", ".", "setBinary", "(", "new", "File", "(", "operaPath", ")", ")", ";", "// Now create the OperaLauncherRunner that we have the binary path", "runner", "=", "new", "OperaLauncherRunner", "(", "settings", ")", ";", "// Quit and wait for opera to quit properly", "try", "{", "getScopeServices", "(", ")", ".", "quit", "(", "runner", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "WebDriverException", "(", "e", ")", ";", "}", "// Delete the profile to start the first test with a clean profile", "if", "(", "!", "profileUtils", ".", "deleteProfile", "(", ")", ")", "{", "logger", ".", "severe", "(", "\"Could not delete profile\"", ")", ";", "}", "// Work around stop and restart Opera so the Launcher has control of it now", "// Initialising the services will start Opera if the OperaLauncherRunner is", "// setup correctly", "startOpera", "(", ")", ";", "}", "}", "}" ]
Initializes services and starts Opera. If OperaBinaryLocation is not set, the binary location is retrieved from the connected Opera instance, before shutting it down, waiting for it to quit properly, and then restarting it under the control of the {@link OperaLauncherRunner}.
[ "Initializes", "services", "and", "starts", "Opera", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L116-L156
3,052
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.getQuickWidgetList
public List<QuickWidget> getQuickWidgetList(String windowName) { int id = getQuickWindowID(windowName); if (id >= 0 || windowName.isEmpty()) { return getQuickWidgetList(id); } return Collections.emptyList(); }
java
public List<QuickWidget> getQuickWidgetList(String windowName) { int id = getQuickWindowID(windowName); if (id >= 0 || windowName.isEmpty()) { return getQuickWidgetList(id); } return Collections.emptyList(); }
[ "public", "List", "<", "QuickWidget", ">", "getQuickWidgetList", "(", "String", "windowName", ")", "{", "int", "id", "=", "getQuickWindowID", "(", "windowName", ")", ";", "if", "(", "id", ">=", "0", "||", "windowName", ".", "isEmpty", "(", ")", ")", "{", "return", "getQuickWidgetList", "(", "id", ")", ";", "}", "return", "Collections", ".", "emptyList", "(", ")", ";", "}" ]
Gets a list of all widgets in the window with the given window name. @param windowName name of window to list widgets inside @return list of widgets in the window with name windowName If windowName is empty, it gets the widgets in the active window
[ "Gets", "a", "list", "of", "all", "widgets", "in", "the", "window", "with", "the", "given", "window", "name", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L232-L239
3,053
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.findWidgetByName
public QuickWidget findWidgetByName(QuickWidgetType type, int windowId, String widgetName) { return desktopWindowManager.getQuickWidget(type, windowId, QuickWidgetSearchType.NAME, widgetName); }
java
public QuickWidget findWidgetByName(QuickWidgetType type, int windowId, String widgetName) { return desktopWindowManager.getQuickWidget(type, windowId, QuickWidgetSearchType.NAME, widgetName); }
[ "public", "QuickWidget", "findWidgetByName", "(", "QuickWidgetType", "type", ",", "int", "windowId", ",", "String", "widgetName", ")", "{", "return", "desktopWindowManager", ".", "getQuickWidget", "(", "type", ",", "windowId", ",", "QuickWidgetSearchType", ".", "NAME", ",", "widgetName", ")", ";", "}" ]
Finds widget by name in the window specified by windowId. @param windowId window id of parent window @param widgetName name of widget to find @return QuickWidget with the given name in the window with id windowId, or null if no such widget exists.
[ "Finds", "widget", "by", "name", "in", "the", "window", "specified", "by", "windowId", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L322-L325
3,054
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.findWidgetByText
public QuickWidget findWidgetByText(QuickWidgetType type, int windowId, String text) { return desktopWindowManager.getQuickWidget(type, windowId, QuickWidgetSearchType.TEXT, text); }
java
public QuickWidget findWidgetByText(QuickWidgetType type, int windowId, String text) { return desktopWindowManager.getQuickWidget(type, windowId, QuickWidgetSearchType.TEXT, text); }
[ "public", "QuickWidget", "findWidgetByText", "(", "QuickWidgetType", "type", ",", "int", "windowId", ",", "String", "text", ")", "{", "return", "desktopWindowManager", ".", "getQuickWidget", "(", "type", ",", "windowId", ",", "QuickWidgetSearchType", ".", "TEXT", ",", "text", ")", ";", "}" ]
Finds widget with the text specified in the window with the given window id. Note, if there are several widgets in this window with the same text, the widget returned can be any one of those @param windowId - id of parent window @param text - text of widget @return QuickWidget with the given text in the specified window, or null if no such widget exists.
[ "Finds", "widget", "with", "the", "text", "specified", "in", "the", "window", "with", "the", "given", "window", "id", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L353-L355
3,055
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.findWidgetByStringId
public QuickWidget findWidgetByStringId(QuickWidgetType type, int windowId, String stringId) { String text = desktopUtils.getString(stringId, true); return findWidgetByText(type, windowId, text); }
java
public QuickWidget findWidgetByStringId(QuickWidgetType type, int windowId, String stringId) { String text = desktopUtils.getString(stringId, true); return findWidgetByText(type, windowId, text); }
[ "public", "QuickWidget", "findWidgetByStringId", "(", "QuickWidgetType", "type", ",", "int", "windowId", ",", "String", "stringId", ")", "{", "String", "text", "=", "desktopUtils", ".", "getString", "(", "stringId", ",", "true", ")", ";", "return", "findWidgetByText", "(", "type", ",", "windowId", ",", "text", ")", ";", "}" ]
Finds widget with the text specified by string id in the window with the given id. @param windowId id of parent window @param stringId string id of the widget @return QuickWidget or null if no matching widget found
[ "Finds", "widget", "with", "the", "text", "specified", "by", "string", "id", "in", "the", "window", "with", "the", "given", "id", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L379-L383
3,056
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.getQuickMenuItemByStringId
public QuickMenuItem getQuickMenuItemByStringId(String stringId) { String text = desktopUtils.getString(stringId, true); return desktopWindowManager.getQuickMenuItemByText(text); }
java
public QuickMenuItem getQuickMenuItemByStringId(String stringId) { String text = desktopUtils.getString(stringId, true); return desktopWindowManager.getQuickMenuItemByText(text); }
[ "public", "QuickMenuItem", "getQuickMenuItemByStringId", "(", "String", "stringId", ")", "{", "String", "text", "=", "desktopUtils", ".", "getString", "(", "stringId", ",", "true", ")", ";", "return", "desktopWindowManager", ".", "getQuickMenuItemByText", "(", "text", ")", ";", "}" ]
Get an item in a language independent way from its stringId. @param stringId StringId as found in standard_menu.ini
[ "Get", "an", "item", "in", "a", "language", "independent", "way", "from", "its", "stringId", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L515-L518
3,057
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.keyPress
public void keyPress(String key, List<ModifierPressed> modifiers) { systemInputManager.keyPress(key, modifiers); }
java
public void keyPress(String key, List<ModifierPressed> modifiers) { systemInputManager.keyPress(key, modifiers); }
[ "public", "void", "keyPress", "(", "String", "key", ",", "List", "<", "ModifierPressed", ">", "modifiers", ")", "{", "systemInputManager", ".", "keyPress", "(", "key", ",", "modifiers", ")", ";", "}" ]
Press Key with modifiers held down. @param key key to press @param modifiers modifiers held
[ "Press", "Key", "with", "modifiers", "held", "down", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L600-L602
3,058
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.keyUp
public void keyUp(String key, List<ModifierPressed> modifiers) { systemInputManager.keyUp(key, modifiers); }
java
public void keyUp(String key, List<ModifierPressed> modifiers) { systemInputManager.keyUp(key, modifiers); }
[ "public", "void", "keyUp", "(", "String", "key", ",", "List", "<", "ModifierPressed", ">", "modifiers", ")", "{", "systemInputManager", ".", "keyUp", "(", "key", ",", "modifiers", ")", ";", "}" ]
Release key. @param key key to press @param modifiers modifiers held
[ "Release", "key", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L610-L612
3,059
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.keyDown
public void keyDown(String key, List<ModifierPressed> modifiers) { systemInputManager.keyDown(key, modifiers); }
java
public void keyDown(String key, List<ModifierPressed> modifiers) { systemInputManager.keyDown(key, modifiers); }
[ "public", "void", "keyDown", "(", "String", "key", ",", "List", "<", "ModifierPressed", ">", "modifiers", ")", "{", "systemInputManager", ".", "keyDown", "(", "key", ",", "modifiers", ")", ";", "}" ]
Press Key. @param key key to press @param modifiers modifiers held
[ "Press", "Key", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L620-L622
3,060
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.operaDesktopAction
public void operaDesktopAction(String using, int data, String dataString, String dataStringParam) { getScopeServices().getExec().action(using, data, dataString, dataStringParam); }
java
public void operaDesktopAction(String using, int data, String dataString, String dataStringParam) { getScopeServices().getExec().action(using, data, dataString, dataStringParam); }
[ "public", "void", "operaDesktopAction", "(", "String", "using", ",", "int", "data", ",", "String", "dataString", ",", "String", "dataStringParam", ")", "{", "getScopeServices", "(", ")", ".", "getExec", "(", ")", ".", "action", "(", "using", ",", "data", ",", "dataString", ",", "dataStringParam", ")", ";", "}" ]
Executes an opera action. @param using - action_name @param data - data parameter @param dataString - data string parameter @param dataStringParam - parameter to data string
[ "Executes", "an", "opera", "action", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L641-L644
3,061
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowShown
public int waitForWindowShown(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices() .waitForDesktopWindowShown(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT.getMs()); }
java
public int waitForWindowShown(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices() .waitForDesktopWindowShown(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT.getMs()); }
[ "public", "int", "waitForWindowShown", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowShown", "(", "windowName", ",", "OperaIntervals", ".", "WINDOW_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the window is shown, and then returns the window id of the window @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "the", "window", "is", "shown", "and", "then", "returns", "the", "window", "id", "of", "the", "window" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L688-L696
3,062
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowUpdated
public int waitForWindowUpdated(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowUpdated(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
java
public int waitForWindowUpdated(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowUpdated(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
[ "public", "int", "waitForWindowUpdated", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowUpdated", "(", "windowName", ",", "OperaIntervals", ".", "WINDOW_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the window is updated, and then returns the window id of the window. @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "the", "window", "is", "updated", "and", "then", "returns", "the", "window", "id", "of", "the", "window", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L704-L713
3,063
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowActivated
public int waitForWindowActivated(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowActivated(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
java
public int waitForWindowActivated(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowActivated(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
[ "public", "int", "waitForWindowActivated", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowActivated", "(", "windowName", ",", "OperaIntervals", ".", "WINDOW_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the window is activated, and then returns the window id of the window. @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "the", "window", "is", "activated", "and", "then", "returns", "the", "window", "id", "of", "the", "window", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L721-L731
3,064
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowClose
public int waitForWindowClose(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowClosed(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
java
public int waitForWindowClose(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowClosed(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
[ "public", "int", "waitForWindowClose", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowClosed", "(", "windowName", ",", "OperaIntervals", ".", "WINDOW_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the window is closed, and then returns the window id of the window. @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "the", "window", "is", "closed", "and", "then", "returns", "the", "window", "id", "of", "the", "window", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L739-L748
3,065
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowPageChanged
public int waitForWindowPageChanged(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowPageChanged(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
java
public int waitForWindowPageChanged(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowPageChanged(windowName, OperaIntervals.WINDOW_EVENT_TIMEOUT .getMs()); }
[ "public", "int", "waitForWindowPageChanged", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowPageChanged", "(", "windowName", ",", "OperaIntervals", ".", "WINDOW_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until new page is shown in the window is shown, and then returns the window id of the window @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "new", "page", "is", "shown", "in", "the", "window", "is", "shown", "and", "then", "returns", "the", "window", "id", "of", "the", "window" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L759-L768
3,066
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForWindowLoaded
public int waitForWindowLoaded(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowLoaded(windowName, OperaIntervals.PAGE_LOAD_TIMEOUT.getMs()); }
java
public int waitForWindowLoaded(String windowName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices().waitForDesktopWindowLoaded(windowName, OperaIntervals.PAGE_LOAD_TIMEOUT.getMs()); }
[ "public", "int", "waitForWindowLoaded", "(", "String", "windowName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForDesktopWindowLoaded", "(", "windowName", ",", "OperaIntervals", ".", "PAGE_LOAD_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the window is loaded and then returns the window id of the window. @param windowName - window to wait for shown event on @return id of window
[ "Waits", "until", "the", "window", "is", "loaded", "and", "then", "returns", "the", "window", "id", "of", "the", "window", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L776-L784
3,067
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForMenuShown
public String waitForMenuShown(String menuName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices() .waitForMenuShown(menuName, OperaIntervals.MENU_EVENT_TIMEOUT.getMs()); }
java
public String waitForMenuShown(String menuName) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a window failed because Opera is not connected."); } return getScopeServices() .waitForMenuShown(menuName, OperaIntervals.MENU_EVENT_TIMEOUT.getMs()); }
[ "public", "String", "waitForMenuShown", "(", "String", "menuName", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a window failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForMenuShown", "(", "menuName", ",", "OperaIntervals", ".", "MENU_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the menu is shown, and then returns the name of the window @param menuName window to wait for shown event on @return id of window
[ "Waits", "until", "the", "menu", "is", "shown", "and", "then", "returns", "the", "name", "of", "the", "window" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L792-L800
3,068
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.waitForMenuItemPressed
public String waitForMenuItemPressed(String menuItemText) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a menu item to be pressed failed because Opera is not connected."); } return getScopeServices().waitForMenuItemPressed(menuItemText, OperaIntervals.MENU_EVENT_TIMEOUT.getMs()); }
java
public String waitForMenuItemPressed(String menuItemText) { if (getScopeServices().getConnection() == null) { throw new CommunicationException( "waiting for a menu item to be pressed failed because Opera is not connected."); } return getScopeServices().waitForMenuItemPressed(menuItemText, OperaIntervals.MENU_EVENT_TIMEOUT.getMs()); }
[ "public", "String", "waitForMenuItemPressed", "(", "String", "menuItemText", ")", "{", "if", "(", "getScopeServices", "(", ")", ".", "getConnection", "(", ")", "==", "null", ")", "{", "throw", "new", "CommunicationException", "(", "\"waiting for a menu item to be pressed failed because Opera is not connected.\"", ")", ";", "}", "return", "getScopeServices", "(", ")", ".", "waitForMenuItemPressed", "(", "menuItemText", ",", "OperaIntervals", ".", "MENU_EVENT_TIMEOUT", ".", "getMs", "(", ")", ")", ";", "}" ]
Waits until the menu item is pressed and then returns the text of the menu item pressed @param menuItemText - window to wait for shown event on @return text of the menu item
[ "Waits", "until", "the", "menu", "item", "is", "pressed", "and", "then", "returns", "the", "text", "of", "the", "menu", "item", "pressed" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L825-L833
3,069
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.resetOperaPrefs
public void resetOperaPrefs(String newPrefs) { // Always delete and copy over a test profile except for when running // the first test which doesn't have a profile to copy over if (!firstTestRun || new File(newPrefs).exists()) { if (!profileUtils.isMainProfile(smallPreferencesPath) && !profileUtils.isMainProfile(largePreferencesPath) && !profileUtils.isMainProfile(cachePreferencesPath)) { // Quit and wait for opera to quit properly quitOpera(); // Due to problems with quitting the Opera desktop application on Windows we introduce this // workaround. This should be fixed in some other way that would allow us to determine in a // reliable way if Opera quit already. if (Platform.getCurrent().is(Platform.WINDOWS)) { try { Thread.sleep(2000); } catch (InterruptedException e) { // fall through } } // Cleanup old profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } // Copy the profile for the test. This method will return false in case the copying fails or // if there is no profile to be copied, so we should check that first here. if (!new File(newPrefs).exists()) { logger.finer("The '" + newPrefs + "' directory doesn't exist, omitting profile copying."); } else if (!profileUtils.copyProfile(newPrefs)) { logger.severe("Failed to copy profile from '" + newPrefs); } else { logger.finer("Profile from '" + newPrefs + "' copied OK"); } // Relaunch Opera and the webdriver service connection startOpera(); } else { logger.warning("Running tests in main user profile"); } } // No longer the first test run firstTestRun = false; }
java
public void resetOperaPrefs(String newPrefs) { // Always delete and copy over a test profile except for when running // the first test which doesn't have a profile to copy over if (!firstTestRun || new File(newPrefs).exists()) { if (!profileUtils.isMainProfile(smallPreferencesPath) && !profileUtils.isMainProfile(largePreferencesPath) && !profileUtils.isMainProfile(cachePreferencesPath)) { // Quit and wait for opera to quit properly quitOpera(); // Due to problems with quitting the Opera desktop application on Windows we introduce this // workaround. This should be fixed in some other way that would allow us to determine in a // reliable way if Opera quit already. if (Platform.getCurrent().is(Platform.WINDOWS)) { try { Thread.sleep(2000); } catch (InterruptedException e) { // fall through } } // Cleanup old profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } // Copy the profile for the test. This method will return false in case the copying fails or // if there is no profile to be copied, so we should check that first here. if (!new File(newPrefs).exists()) { logger.finer("The '" + newPrefs + "' directory doesn't exist, omitting profile copying."); } else if (!profileUtils.copyProfile(newPrefs)) { logger.severe("Failed to copy profile from '" + newPrefs); } else { logger.finer("Profile from '" + newPrefs + "' copied OK"); } // Relaunch Opera and the webdriver service connection startOpera(); } else { logger.warning("Running tests in main user profile"); } } // No longer the first test run firstTestRun = false; }
[ "public", "void", "resetOperaPrefs", "(", "String", "newPrefs", ")", "{", "// Always delete and copy over a test profile except for when running", "// the first test which doesn't have a profile to copy over", "if", "(", "!", "firstTestRun", "||", "new", "File", "(", "newPrefs", ")", ".", "exists", "(", ")", ")", "{", "if", "(", "!", "profileUtils", ".", "isMainProfile", "(", "smallPreferencesPath", ")", "&&", "!", "profileUtils", ".", "isMainProfile", "(", "largePreferencesPath", ")", "&&", "!", "profileUtils", ".", "isMainProfile", "(", "cachePreferencesPath", ")", ")", "{", "// Quit and wait for opera to quit properly", "quitOpera", "(", ")", ";", "// Due to problems with quitting the Opera desktop application on Windows we introduce this", "// workaround. This should be fixed in some other way that would allow us to determine in a", "// reliable way if Opera quit already.", "if", "(", "Platform", ".", "getCurrent", "(", ")", ".", "is", "(", "Platform", ".", "WINDOWS", ")", ")", "{", "try", "{", "Thread", ".", "sleep", "(", "2000", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "// fall through", "}", "}", "// Cleanup old profile", "if", "(", "!", "profileUtils", ".", "deleteProfile", "(", ")", ")", "{", "logger", ".", "severe", "(", "\"Could not delete profile\"", ")", ";", "}", "// Copy the profile for the test. This method will return false in case the copying fails or", "// if there is no profile to be copied, so we should check that first here.", "if", "(", "!", "new", "File", "(", "newPrefs", ")", ".", "exists", "(", ")", ")", "{", "logger", ".", "finer", "(", "\"The '\"", "+", "newPrefs", "+", "\"' directory doesn't exist, omitting profile copying.\"", ")", ";", "}", "else", "if", "(", "!", "profileUtils", ".", "copyProfile", "(", "newPrefs", ")", ")", "{", "logger", ".", "severe", "(", "\"Failed to copy profile from '\"", "+", "newPrefs", ")", ";", "}", "else", "{", "logger", ".", "finer", "(", "\"Profile from '\"", "+", "newPrefs", "+", "\"' copied OK\"", ")", ";", "}", "// Relaunch Opera and the webdriver service connection", "startOpera", "(", ")", ";", "}", "else", "{", "logger", ".", "warning", "(", "\"Running tests in main user profile\"", ")", ";", "}", "}", "// No longer the first test run", "firstTestRun", "=", "false", ";", "}" ]
meaning operaBinaryLocation will be set already
[ "meaning", "operaBinaryLocation", "will", "be", "set", "already" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L850-L895
3,070
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaDesktopDriver.java
OperaDesktopDriver.deleteOperaPrefs
public void deleteOperaPrefs() { // Only delete if Opera is currently not running // Don't delete in no-launcher mode if (runner != null && !runner.isOperaRunning()) { // Will only delete profile if it's not a default main profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } } else { logger.warning("Cannot delete profile while Opera is running"); } }
java
public void deleteOperaPrefs() { // Only delete if Opera is currently not running // Don't delete in no-launcher mode if (runner != null && !runner.isOperaRunning()) { // Will only delete profile if it's not a default main profile if (!profileUtils.deleteProfile()) { logger.severe("Could not delete profile"); } } else { logger.warning("Cannot delete profile while Opera is running"); } }
[ "public", "void", "deleteOperaPrefs", "(", ")", "{", "// Only delete if Opera is currently not running", "// Don't delete in no-launcher mode", "if", "(", "runner", "!=", "null", "&&", "!", "runner", ".", "isOperaRunning", "(", ")", ")", "{", "// Will only delete profile if it's not a default main profile", "if", "(", "!", "profileUtils", ".", "deleteProfile", "(", ")", ")", "{", "logger", ".", "severe", "(", "\"Could not delete profile\"", ")", ";", "}", "}", "else", "{", "logger", ".", "warning", "(", "\"Cannot delete profile while Opera is running\"", ")", ";", "}", "}" ]
Deletes the profile for the connected Opera instance. Should only be called after the given Opera instance has quit
[ "Deletes", "the", "profile", "for", "the", "connected", "Opera", "instance", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaDesktopDriver.java#L902-L913
3,071
operasoftware/operaprestodriver
src/com/opera/core/systems/common/hash/MD5.java
MD5.sum
public static String sum(byte[] bytes) { String result = ""; for (byte b : bytes) { result += Integer.toString((b & 0xff) + 0x100, 16).substring(1); } return result; }
java
public static String sum(byte[] bytes) { String result = ""; for (byte b : bytes) { result += Integer.toString((b & 0xff) + 0x100, 16).substring(1); } return result; }
[ "public", "static", "String", "sum", "(", "byte", "[", "]", "bytes", ")", "{", "String", "result", "=", "\"\"", ";", "for", "(", "byte", "b", ":", "bytes", ")", "{", "result", "+=", "Integer", ".", "toString", "(", "(", "b", "&", "0xff", ")", "+", "0x100", ",", "16", ")", ".", "substring", "(", "1", ")", ";", "}", "return", "result", ";", "}" ]
Return the MD5 HEX sum of a hashed MD5 byte array. @param bytes the hashed MD5 byte array @return HEX version of the byte array
[ "Return", "the", "MD5", "HEX", "sum", "of", "a", "hashed", "MD5", "byte", "array", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/hash/MD5.java#L33-L39
3,072
operasoftware/operaprestodriver
src/com/opera/core/systems/common/hash/MD5.java
MD5.hash
public static byte[] hash(File file) throws IOException { return Files.hash(file, Hashing.md5()).asBytes(); }
java
public static byte[] hash(File file) throws IOException { return Files.hash(file, Hashing.md5()).asBytes(); }
[ "public", "static", "byte", "[", "]", "hash", "(", "File", "file", ")", "throws", "IOException", "{", "return", "Files", ".", "hash", "(", "file", ",", "Hashing", ".", "md5", "(", ")", ")", ".", "asBytes", "(", ")", ";", "}" ]
Get the MD5 hash of the given file. @param file file to compute a hash on @return a byte array of the MD5 hash @throws IOException if file cannot be found
[ "Get", "the", "MD5", "hash", "of", "the", "given", "file", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/hash/MD5.java#L59-L61
3,073
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/Time.java
Time.parseDuration
public static int parseDuration(String duration) { if (duration == null) { return 60 * 60 * 24 * 30; } Integer toAdd = null; if (days.matcher(duration).matches()) { Matcher matcher = days.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60 * 60) * 24; } else if (hours.matcher(duration).matches()) { Matcher matcher = hours.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60 * 60); } else if (minutes.matcher(duration).matches()) { Matcher matcher = minutes.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60); } else if (seconds.matcher(duration).matches()) { Matcher matcher = seconds.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)); } else if ("forever".equals(duration)) { toAdd = -1; } if (toAdd == null) { throw new IllegalArgumentException("Invalid duration pattern : " + duration); } return toAdd; }
java
public static int parseDuration(String duration) { if (duration == null) { return 60 * 60 * 24 * 30; } Integer toAdd = null; if (days.matcher(duration).matches()) { Matcher matcher = days.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60 * 60) * 24; } else if (hours.matcher(duration).matches()) { Matcher matcher = hours.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60 * 60); } else if (minutes.matcher(duration).matches()) { Matcher matcher = minutes.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)) * (60); } else if (seconds.matcher(duration).matches()) { Matcher matcher = seconds.matcher(duration); matcher.matches(); toAdd = Integer.parseInt(matcher.group(1)); } else if ("forever".equals(duration)) { toAdd = -1; } if (toAdd == null) { throw new IllegalArgumentException("Invalid duration pattern : " + duration); } return toAdd; }
[ "public", "static", "int", "parseDuration", "(", "String", "duration", ")", "{", "if", "(", "duration", "==", "null", ")", "{", "return", "60", "*", "60", "*", "24", "*", "30", ";", "}", "Integer", "toAdd", "=", "null", ";", "if", "(", "days", ".", "matcher", "(", "duration", ")", ".", "matches", "(", ")", ")", "{", "Matcher", "matcher", "=", "days", ".", "matcher", "(", "duration", ")", ";", "matcher", ".", "matches", "(", ")", ";", "toAdd", "=", "Integer", ".", "parseInt", "(", "matcher", ".", "group", "(", "1", ")", ")", "*", "(", "60", "*", "60", ")", "*", "24", ";", "}", "else", "if", "(", "hours", ".", "matcher", "(", "duration", ")", ".", "matches", "(", ")", ")", "{", "Matcher", "matcher", "=", "hours", ".", "matcher", "(", "duration", ")", ";", "matcher", ".", "matches", "(", ")", ";", "toAdd", "=", "Integer", ".", "parseInt", "(", "matcher", ".", "group", "(", "1", ")", ")", "*", "(", "60", "*", "60", ")", ";", "}", "else", "if", "(", "minutes", ".", "matcher", "(", "duration", ")", ".", "matches", "(", ")", ")", "{", "Matcher", "matcher", "=", "minutes", ".", "matcher", "(", "duration", ")", ";", "matcher", ".", "matches", "(", ")", ";", "toAdd", "=", "Integer", ".", "parseInt", "(", "matcher", ".", "group", "(", "1", ")", ")", "*", "(", "60", ")", ";", "}", "else", "if", "(", "seconds", ".", "matcher", "(", "duration", ")", ".", "matches", "(", ")", ")", "{", "Matcher", "matcher", "=", "seconds", ".", "matcher", "(", "duration", ")", ";", "matcher", ".", "matches", "(", ")", ";", "toAdd", "=", "Integer", ".", "parseInt", "(", "matcher", ".", "group", "(", "1", ")", ")", ";", "}", "else", "if", "(", "\"forever\"", ".", "equals", "(", "duration", ")", ")", "{", "toAdd", "=", "-", "1", ";", "}", "if", "(", "toAdd", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid duration pattern : \"", "+", "duration", ")", ";", "}", "return", "toAdd", ";", "}" ]
Parse a duration @param duration 3h, 2mn, 7s @return The number of seconds
[ "Parse", "a", "duration" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/Time.java#L34-L62
3,074
operasoftware/operaprestodriver
src/com/opera/core/systems/OperaBinary.java
OperaBinary.find
public static File find(OperaProduct product) { File binary = findBinaryBasedOnEnvironmentVariable(); if (binary != null) { return binary; } return findBinaryBasedOnPlatform(product); }
java
public static File find(OperaProduct product) { File binary = findBinaryBasedOnEnvironmentVariable(); if (binary != null) { return binary; } return findBinaryBasedOnPlatform(product); }
[ "public", "static", "File", "find", "(", "OperaProduct", "product", ")", "{", "File", "binary", "=", "findBinaryBasedOnEnvironmentVariable", "(", ")", ";", "if", "(", "binary", "!=", "null", ")", "{", "return", "binary", ";", "}", "return", "findBinaryBasedOnPlatform", "(", "product", ")", ";", "}" ]
Locate the binary of the given product on the local system. If no binary is found, null is returned. Some products, such as {@link OperaProduct#DESKTOP} offers multiple configurations of the same product (Opera and Opera Next), in which case the first is preferred. @param product the product to find the binary of @return the binary of the product, or null
[ "Locate", "the", "binary", "of", "the", "given", "product", "on", "the", "local", "system", ".", "If", "no", "binary", "is", "found", "null", "is", "returned", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/OperaBinary.java#L78-L84
3,075
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/parser/build_in/ExpressionParser.java
ExpressionParser.assertBasic
public static String assertBasic(String symbol, IContext context) { if (symbol.contains("_utils.sep(\"")) return symbol;// Rythm builtin expression TODO: generalize //String s = Token.stripJavaExtension(symbol, context); //s = S.stripBrace(s); String s = symbol; boolean isSimple = Patterns.VarName.matches(s); IContext ctx = context; if (!isSimple) { throw new TemplateParser.ComplexExpressionException(ctx); } return s; }
java
public static String assertBasic(String symbol, IContext context) { if (symbol.contains("_utils.sep(\"")) return symbol;// Rythm builtin expression TODO: generalize //String s = Token.stripJavaExtension(symbol, context); //s = S.stripBrace(s); String s = symbol; boolean isSimple = Patterns.VarName.matches(s); IContext ctx = context; if (!isSimple) { throw new TemplateParser.ComplexExpressionException(ctx); } return s; }
[ "public", "static", "String", "assertBasic", "(", "String", "symbol", ",", "IContext", "context", ")", "{", "if", "(", "symbol", ".", "contains", "(", "\"_utils.sep(\\\"\"", ")", ")", "return", "symbol", ";", "// Rythm builtin expression TODO: generalize", "//String s = Token.stripJavaExtension(symbol, context);", "//s = S.stripBrace(s);", "String", "s", "=", "symbol", ";", "boolean", "isSimple", "=", "Patterns", ".", "VarName", ".", "matches", "(", "s", ")", ";", "IContext", "ctx", "=", "context", ";", "if", "(", "!", "isSimple", ")", "{", "throw", "new", "TemplateParser", ".", "ComplexExpressionException", "(", "ctx", ")", ";", "}", "return", "s", ";", "}" ]
Return symbol with transformer extension stripped off @param symbol @param context @return the symbol
[ "Return", "symbol", "with", "transformer", "extension", "stripped", "off" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/parser/build_in/ExpressionParser.java#L33-L44
3,076
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/inprocess/ScreenCapture.java
ScreenCapture.take
public void take() throws AWTException { Rectangle area = new Rectangle(dimensions); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(area); data = getByteArray(image); }
java
public void take() throws AWTException { Rectangle area = new Rectangle(dimensions); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(area); data = getByteArray(image); }
[ "public", "void", "take", "(", ")", "throws", "AWTException", "{", "Rectangle", "area", "=", "new", "Rectangle", "(", "dimensions", ")", ";", "Robot", "robot", "=", "new", "Robot", "(", ")", ";", "BufferedImage", "image", "=", "robot", ".", "createScreenCapture", "(", "area", ")", ";", "data", "=", "getByteArray", "(", "image", ")", ";", "}" ]
Takes the screen capture of the designated area. If no dimensions are specified, it will take a screenshot of the full screen by default.
[ "Takes", "the", "screen", "capture", "of", "the", "designated", "area", ".", "If", "no", "dimensions", "are", "specified", "it", "will", "take", "a", "screenshot", "of", "the", "full", "screen", "by", "default", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/inprocess/ScreenCapture.java#L62-L68
3,077
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/inprocess/ScreenCapture.java
ScreenCapture.getMd5
public String getMd5() throws IOException { checkCaptureTaken(); try { return MD5.of(getData()); } catch (IOException e) { throw new IOException("Unable to open stream or file: " + e.getMessage(), e); } }
java
public String getMd5() throws IOException { checkCaptureTaken(); try { return MD5.of(getData()); } catch (IOException e) { throw new IOException("Unable to open stream or file: " + e.getMessage(), e); } }
[ "public", "String", "getMd5", "(", ")", "throws", "IOException", "{", "checkCaptureTaken", "(", ")", ";", "try", "{", "return", "MD5", ".", "of", "(", "getData", "(", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Unable to open stream or file: \"", "+", "e", ".", "getMessage", "(", ")", ",", "e", ")", ";", "}", "}" ]
Get the MD5 hash sum of the byte array of the data of the screen capture. @return the MD5 hash sum of this capture @throws IOException if an I/O exception occurs
[ "Get", "the", "MD5", "hash", "sum", "of", "the", "byte", "array", "of", "the", "data", "of", "the", "screen", "capture", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/inprocess/ScreenCapture.java#L76-L84
3,078
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/inprocess/ScreenCapture.java
ScreenCapture.of
public static ScreenCapture of(Dimension dimensions) throws IOException { ScreenCapture capture = new ScreenCapture(dimensions); try { capture.take(); } catch (AWTException e) { throw new IOException(e); } return capture; }
java
public static ScreenCapture of(Dimension dimensions) throws IOException { ScreenCapture capture = new ScreenCapture(dimensions); try { capture.take(); } catch (AWTException e) { throw new IOException(e); } return capture; }
[ "public", "static", "ScreenCapture", "of", "(", "Dimension", "dimensions", ")", "throws", "IOException", "{", "ScreenCapture", "capture", "=", "new", "ScreenCapture", "(", "dimensions", ")", ";", "try", "{", "capture", ".", "take", "(", ")", ";", "}", "catch", "(", "AWTException", "e", ")", "{", "throw", "new", "IOException", "(", "e", ")", ";", "}", "return", "capture", ";", "}" ]
Takes a screen capture of the given dimensions. @param dimensions the dimensions of which to take a screen capture @return a capture of the designated dimensions @throws IOException if an I/O exception occurs
[ "Takes", "a", "screen", "capture", "of", "the", "given", "dimensions", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/inprocess/ScreenCapture.java#L117-L127
3,079
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/inprocess/ScreenCapture.java
ScreenCapture.getByteArray
private static byte[] getByteArray(BufferedImage image) { checkNotNull(image); ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { ImageIO.write(image, "png", stream); } catch (IOException e) { throw new IllegalStateException(e); } return stream.toByteArray(); }
java
private static byte[] getByteArray(BufferedImage image) { checkNotNull(image); ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { ImageIO.write(image, "png", stream); } catch (IOException e) { throw new IllegalStateException(e); } return stream.toByteArray(); }
[ "private", "static", "byte", "[", "]", "getByteArray", "(", "BufferedImage", "image", ")", "{", "checkNotNull", "(", "image", ")", ";", "ByteArrayOutputStream", "stream", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "try", "{", "ImageIO", ".", "write", "(", "image", ",", "\"png\"", ",", "stream", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "e", ")", ";", "}", "return", "stream", ".", "toByteArray", "(", ")", ";", "}" ]
Get a byte array of the data of a buffered image. @param image the image to retrieve a byte array of @return a byte array of the buffered image's data
[ "Get", "a", "byte", "array", "of", "the", "data", "of", "a", "buffered", "image", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/inprocess/ScreenCapture.java#L135-L146
3,080
operasoftware/operaprestodriver
src/com/opera/core/systems/internal/ProfileUtils.java
ProfileUtils.deleteProfile
public boolean deleteProfile() { String[] profileDirs = {smallPrefsFolder, largePrefsFolder, cachePrefsFolder}; // Assuming if any of those are main profile, skip the whole delete for (String profileDir : profileDirs) { if (isMainProfile(profileDir)) { logger.finer("Skipping profile deletion since '" + profileDir + "' is the main profile."); return false; } } for (String profileDir : profileDirs) { File currentDirHandle = new File(profileDir); if (!currentDirHandle.exists()) { logger.finer("Skipping profile deletion for '" + profileDir + "' since it doesn't exist."); continue; } boolean deleted = deleteFolder(profileDir); if (!deleted) { final int retryIntervalMs = 500; final int retryMaxCount = 10; int retryCount = 0; boolean ok = false; logger.warning("Profile could not be deleted, retrying..."); do { try { Thread.sleep(retryIntervalMs); } catch (InterruptedException e) { // fall through } ok = deleteFolder(profileDir); retryCount++; if (retryCount > retryMaxCount) { break; } } while (!ok); if (!ok) { logger.severe( "Could not delete profile in '" + profileDir + "'. Skipping further deletion."); return false; } else { logger.warning("Deleted profile, retry count = " + retryCount); } } else { logger.finer("Deleted profile in '" + profileDir + "'"); } } return true; }
java
public boolean deleteProfile() { String[] profileDirs = {smallPrefsFolder, largePrefsFolder, cachePrefsFolder}; // Assuming if any of those are main profile, skip the whole delete for (String profileDir : profileDirs) { if (isMainProfile(profileDir)) { logger.finer("Skipping profile deletion since '" + profileDir + "' is the main profile."); return false; } } for (String profileDir : profileDirs) { File currentDirHandle = new File(profileDir); if (!currentDirHandle.exists()) { logger.finer("Skipping profile deletion for '" + profileDir + "' since it doesn't exist."); continue; } boolean deleted = deleteFolder(profileDir); if (!deleted) { final int retryIntervalMs = 500; final int retryMaxCount = 10; int retryCount = 0; boolean ok = false; logger.warning("Profile could not be deleted, retrying..."); do { try { Thread.sleep(retryIntervalMs); } catch (InterruptedException e) { // fall through } ok = deleteFolder(profileDir); retryCount++; if (retryCount > retryMaxCount) { break; } } while (!ok); if (!ok) { logger.severe( "Could not delete profile in '" + profileDir + "'. Skipping further deletion."); return false; } else { logger.warning("Deleted profile, retry count = " + retryCount); } } else { logger.finer("Deleted profile in '" + profileDir + "'"); } } return true; }
[ "public", "boolean", "deleteProfile", "(", ")", "{", "String", "[", "]", "profileDirs", "=", "{", "smallPrefsFolder", ",", "largePrefsFolder", ",", "cachePrefsFolder", "}", ";", "// Assuming if any of those are main profile, skip the whole delete", "for", "(", "String", "profileDir", ":", "profileDirs", ")", "{", "if", "(", "isMainProfile", "(", "profileDir", ")", ")", "{", "logger", ".", "finer", "(", "\"Skipping profile deletion since '\"", "+", "profileDir", "+", "\"' is the main profile.\"", ")", ";", "return", "false", ";", "}", "}", "for", "(", "String", "profileDir", ":", "profileDirs", ")", "{", "File", "currentDirHandle", "=", "new", "File", "(", "profileDir", ")", ";", "if", "(", "!", "currentDirHandle", ".", "exists", "(", ")", ")", "{", "logger", ".", "finer", "(", "\"Skipping profile deletion for '\"", "+", "profileDir", "+", "\"' since it doesn't exist.\"", ")", ";", "continue", ";", "}", "boolean", "deleted", "=", "deleteFolder", "(", "profileDir", ")", ";", "if", "(", "!", "deleted", ")", "{", "final", "int", "retryIntervalMs", "=", "500", ";", "final", "int", "retryMaxCount", "=", "10", ";", "int", "retryCount", "=", "0", ";", "boolean", "ok", "=", "false", ";", "logger", ".", "warning", "(", "\"Profile could not be deleted, retrying...\"", ")", ";", "do", "{", "try", "{", "Thread", ".", "sleep", "(", "retryIntervalMs", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "// fall through", "}", "ok", "=", "deleteFolder", "(", "profileDir", ")", ";", "retryCount", "++", ";", "if", "(", "retryCount", ">", "retryMaxCount", ")", "{", "break", ";", "}", "}", "while", "(", "!", "ok", ")", ";", "if", "(", "!", "ok", ")", "{", "logger", ".", "severe", "(", "\"Could not delete profile in '\"", "+", "profileDir", "+", "\"'. Skipping further deletion.\"", ")", ";", "return", "false", ";", "}", "else", "{", "logger", ".", "warning", "(", "\"Deleted profile, retry count = \"", "+", "retryCount", ")", ";", "}", "}", "else", "{", "logger", ".", "finer", "(", "\"Deleted profile in '\"", "+", "profileDir", "+", "\"'\"", ")", ";", "}", "}", "return", "true", ";", "}" ]
Deletes prefs folders for Does nothing if prefs folders are default main user profile
[ "Deletes", "prefs", "folders", "for", "Does", "nothing", "if", "prefs", "folders", "are", "default", "main", "user", "profile" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/internal/ProfileUtils.java#L126-L181
3,081
operasoftware/operaprestodriver
src/com/opera/core/systems/scope/stp/services/ScopeWindowManager.java
ScopeWindowManager.initializeWindows
private void initializeWindows() { clearFilter(); Response response = executeMessage(WindowManagerMessage.LIST_WINDOWS, null); WindowList.Builder builder = WindowList.newBuilder(); buildPayload(response, builder); WindowList list = builder.build(); List<WindowInfo> windowsList = list.getWindowListList(); windows.clear(); for (WindowInfo window : windowsList) { windows.put(window.getWindowID(), window); } // initialize windowStack windows.putIfAbsent(findActiveWindow().getWindowID(), null); }
java
private void initializeWindows() { clearFilter(); Response response = executeMessage(WindowManagerMessage.LIST_WINDOWS, null); WindowList.Builder builder = WindowList.newBuilder(); buildPayload(response, builder); WindowList list = builder.build(); List<WindowInfo> windowsList = list.getWindowListList(); windows.clear(); for (WindowInfo window : windowsList) { windows.put(window.getWindowID(), window); } // initialize windowStack windows.putIfAbsent(findActiveWindow().getWindowID(), null); }
[ "private", "void", "initializeWindows", "(", ")", "{", "clearFilter", "(", ")", ";", "Response", "response", "=", "executeMessage", "(", "WindowManagerMessage", ".", "LIST_WINDOWS", ",", "null", ")", ";", "WindowList", ".", "Builder", "builder", "=", "WindowList", ".", "newBuilder", "(", ")", ";", "buildPayload", "(", "response", ",", "builder", ")", ";", "WindowList", "list", "=", "builder", ".", "build", "(", ")", ";", "List", "<", "WindowInfo", ">", "windowsList", "=", "list", ".", "getWindowListList", "(", ")", ";", "windows", ".", "clear", "(", ")", ";", "for", "(", "WindowInfo", "window", ":", "windowsList", ")", "{", "windows", ".", "put", "(", "window", ".", "getWindowID", "(", ")", ",", "window", ")", ";", "}", "// initialize windowStack", "windows", ".", "putIfAbsent", "(", "findActiveWindow", "(", ")", ".", "getWindowID", "(", ")", ",", "null", ")", ";", "}" ]
Set the filter to include all windows so we can get a list and maintain a list of windows.
[ "Set", "the", "filter", "to", "include", "all", "windows", "so", "we", "can", "get", "a", "list", "and", "maintain", "a", "list", "of", "windows", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/scope/stp/services/ScopeWindowManager.java#L160-L176
3,082
operasoftware/operaprestodriver
src/com/opera/core/systems/common/lang/OperaStrings.java
OperaStrings.isDouble
public static boolean isDouble(String string) { if (string == null) { return false; } try { Double.parseDouble(string); } catch (NumberFormatException e) { return false; } return true; }
java
public static boolean isDouble(String string) { if (string == null) { return false; } try { Double.parseDouble(string); } catch (NumberFormatException e) { return false; } return true; }
[ "public", "static", "boolean", "isDouble", "(", "String", "string", ")", "{", "if", "(", "string", "==", "null", ")", "{", "return", "false", ";", "}", "try", "{", "Double", ".", "parseDouble", "(", "string", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks whether given string has a double value. @param string the string to check @return true if string resembles a double value, false otherwise
[ "Checks", "whether", "given", "string", "has", "a", "double", "value", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/lang/OperaStrings.java#L45-L57
3,083
operasoftware/operaprestodriver
src/com/opera/core/systems/common/lang/OperaStrings.java
OperaStrings.isInteger
public static boolean isInteger(String string) { if (string == null) { return false; } try { Integer.parseInt(string); } catch (NumberFormatException e) { return false; } return true; }
java
public static boolean isInteger(String string) { if (string == null) { return false; } try { Integer.parseInt(string); } catch (NumberFormatException e) { return false; } return true; }
[ "public", "static", "boolean", "isInteger", "(", "String", "string", ")", "{", "if", "(", "string", "==", "null", ")", "{", "return", "false", ";", "}", "try", "{", "Integer", ".", "parseInt", "(", "string", ")", ";", "}", "catch", "(", "NumberFormatException", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks whether the given string has an integer value. @param string the string to check @return true if string resembles an integer value, false otherwise
[ "Checks", "whether", "the", "given", "string", "has", "an", "integer", "value", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/lang/OperaStrings.java#L65-L77
3,084
operasoftware/operaprestodriver
src/com/opera/core/systems/common/lang/OperaStrings.java
OperaStrings.escapeJsString
public static String escapeJsString(String string, String quote) { // This should be expanded to match all invalid characters (e.g. newlines) but for the moment // we'll trust we'll only get quotes. Pattern escapePattern = Pattern.compile("([^\\\\])" + quote); // Prepend a space so that the regex can match quotes at the beginning of the string Matcher m = escapePattern.matcher(" " + string); StringBuffer sb = new StringBuffer(); while (m.find()) { // $1 -> inserts the character before the quote \\\\\" -> \\", apparently just \" isn't // treated literally. m.appendReplacement(sb, "$1\\\\" + quote); } m.appendTail(sb); // Remove the prepended space. return sb.substring(1); }
java
public static String escapeJsString(String string, String quote) { // This should be expanded to match all invalid characters (e.g. newlines) but for the moment // we'll trust we'll only get quotes. Pattern escapePattern = Pattern.compile("([^\\\\])" + quote); // Prepend a space so that the regex can match quotes at the beginning of the string Matcher m = escapePattern.matcher(" " + string); StringBuffer sb = new StringBuffer(); while (m.find()) { // $1 -> inserts the character before the quote \\\\\" -> \\", apparently just \" isn't // treated literally. m.appendReplacement(sb, "$1\\\\" + quote); } m.appendTail(sb); // Remove the prepended space. return sb.substring(1); }
[ "public", "static", "String", "escapeJsString", "(", "String", "string", ",", "String", "quote", ")", "{", "// This should be expanded to match all invalid characters (e.g. newlines) but for the moment", "// we'll trust we'll only get quotes.", "Pattern", "escapePattern", "=", "Pattern", ".", "compile", "(", "\"([^\\\\\\\\])\"", "+", "quote", ")", ";", "// Prepend a space so that the regex can match quotes at the beginning of the string", "Matcher", "m", "=", "escapePattern", ".", "matcher", "(", "\" \"", "+", "string", ")", ";", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", ")", ";", "while", "(", "m", ".", "find", "(", ")", ")", "{", "// $1 -> inserts the character before the quote \\\\\\\\\\\" -> \\\\\", apparently just \\\" isn't", "// treated literally.", "m", ".", "appendReplacement", "(", "sb", ",", "\"$1\\\\\\\\\"", "+", "quote", ")", ";", "}", "m", ".", "appendTail", "(", "sb", ")", ";", "// Remove the prepended space.", "return", "sb", ".", "substring", "(", "1", ")", ";", "}" ]
Escape characters for safe insertion in a JavaScript string. @param string the string to escape @param quote the type of quote to escape. Either " or ' @return the escaped string
[ "Escape", "characters", "for", "safe", "insertion", "in", "a", "JavaScript", "string", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/lang/OperaStrings.java#L96-L115
3,085
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java
OperaLauncherRunner.captureScreen
public ScreenCaptureReply captureScreen(long timeout, List<String> knownMD5s) throws OperaRunnerException { assertLauncherAlive(); String resultMd5; byte[] resultBytes; boolean blank = false; try { LauncherScreenshotRequest.Builder request = LauncherScreenshotRequest.newBuilder(); request.addAllKnownMD5S(knownMD5s); request.setKnownMD5STimeoutMs((int) timeout); ResponseEncapsulation res = protocol.sendRequest( MessageType.MSG_SCREENSHOT, request.build().toByteArray()); LauncherScreenshotResponse response = (LauncherScreenshotResponse) res.getResponse(); resultMd5 = response.getMd5(); resultBytes = response.getImagedata().toByteArray(); if (response.hasBlank()) { blank = response.getBlank(); } } catch (SocketTimeoutException e) { throw new OperaRunnerException("Could not get screenshot from launcher", e); } catch (IOException e) { throw new OperaRunnerException("Could not get screenshot from launcher", e); } ScreenCaptureReply.Builder builder = ScreenCaptureReply.builder(); builder.setMD5(resultMd5); builder.setPNG(resultBytes); builder.setBlank(blank); builder.setCrashed(this.hasOperaCrashed()); return builder.build(); }
java
public ScreenCaptureReply captureScreen(long timeout, List<String> knownMD5s) throws OperaRunnerException { assertLauncherAlive(); String resultMd5; byte[] resultBytes; boolean blank = false; try { LauncherScreenshotRequest.Builder request = LauncherScreenshotRequest.newBuilder(); request.addAllKnownMD5S(knownMD5s); request.setKnownMD5STimeoutMs((int) timeout); ResponseEncapsulation res = protocol.sendRequest( MessageType.MSG_SCREENSHOT, request.build().toByteArray()); LauncherScreenshotResponse response = (LauncherScreenshotResponse) res.getResponse(); resultMd5 = response.getMd5(); resultBytes = response.getImagedata().toByteArray(); if (response.hasBlank()) { blank = response.getBlank(); } } catch (SocketTimeoutException e) { throw new OperaRunnerException("Could not get screenshot from launcher", e); } catch (IOException e) { throw new OperaRunnerException("Could not get screenshot from launcher", e); } ScreenCaptureReply.Builder builder = ScreenCaptureReply.builder(); builder.setMD5(resultMd5); builder.setPNG(resultBytes); builder.setBlank(blank); builder.setCrashed(this.hasOperaCrashed()); return builder.build(); }
[ "public", "ScreenCaptureReply", "captureScreen", "(", "long", "timeout", ",", "List", "<", "String", ">", "knownMD5s", ")", "throws", "OperaRunnerException", "{", "assertLauncherAlive", "(", ")", ";", "String", "resultMd5", ";", "byte", "[", "]", "resultBytes", ";", "boolean", "blank", "=", "false", ";", "try", "{", "LauncherScreenshotRequest", ".", "Builder", "request", "=", "LauncherScreenshotRequest", ".", "newBuilder", "(", ")", ";", "request", ".", "addAllKnownMD5S", "(", "knownMD5s", ")", ";", "request", ".", "setKnownMD5STimeoutMs", "(", "(", "int", ")", "timeout", ")", ";", "ResponseEncapsulation", "res", "=", "protocol", ".", "sendRequest", "(", "MessageType", ".", "MSG_SCREENSHOT", ",", "request", ".", "build", "(", ")", ".", "toByteArray", "(", ")", ")", ";", "LauncherScreenshotResponse", "response", "=", "(", "LauncherScreenshotResponse", ")", "res", ".", "getResponse", "(", ")", ";", "resultMd5", "=", "response", ".", "getMd5", "(", ")", ";", "resultBytes", "=", "response", ".", "getImagedata", "(", ")", ".", "toByteArray", "(", ")", ";", "if", "(", "response", ".", "hasBlank", "(", ")", ")", "{", "blank", "=", "response", ".", "getBlank", "(", ")", ";", "}", "}", "catch", "(", "SocketTimeoutException", "e", ")", "{", "throw", "new", "OperaRunnerException", "(", "\"Could not get screenshot from launcher\"", ",", "e", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "OperaRunnerException", "(", "\"Could not get screenshot from launcher\"", ",", "e", ")", ";", "}", "ScreenCaptureReply", ".", "Builder", "builder", "=", "ScreenCaptureReply", ".", "builder", "(", ")", ";", "builder", ".", "setMD5", "(", "resultMd5", ")", ";", "builder", ".", "setPNG", "(", "resultBytes", ")", ";", "builder", ".", "setBlank", "(", "blank", ")", ";", "builder", ".", "setCrashed", "(", "this", ".", "hasOperaCrashed", "(", ")", ")", ";", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Take screenshot using external program. Will not trigger a screen repaint. @throws OperaRunnerException if runner is shutdown or not running @inheritDoc
[ "Take", "screenshot", "using", "external", "program", ".", "Will", "not", "trigger", "a", "screen", "repaint", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java#L354-L389
3,086
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java
OperaLauncherRunner.handleStatusMessage
private StatusType handleStatusMessage(GeneratedMessage msg) { LauncherStatusResponse response = (LauncherStatusResponse) msg; // LOG RESULT! logger.finest("[LAUNCHER] Status: " + response.getStatus().toString()); if (response.hasExitcode()) { logger.finest("[LAUNCHER] Status: exitCode=" + response.getExitcode()); } if (response.hasCrashlog()) { logger.finest("[LAUNCHER] Status: crashLog=yes"); } else { logger.finest("[LAUNCHER] Status: crashLog=no"); } if (response.getLogmessagesCount() > 0) { for (String message : response.getLogmessagesList()) { logger.finest("[LAUNCHER LOG] " + message); } } else { logger.finest("[LAUNCHER LOG] No log..."); } // Handle state StatusType status = response.getStatus(); if (status == StatusType.CRASHED) { if (response.hasCrashlog()) { crashlog = response.getCrashlog().toStringUtf8(); } else { crashlog = ""; // != NULL :-| } } else { crashlog = null; } // TODO: send something to the operalistener.... // if(launcherLastKnowStatus == StatusType.RUNNING && status != // StatusType.RUNNING){ // if(operaListener != null) // operaListener.operaBinaryStopped(response.getExitcode()); // } return status; }
java
private StatusType handleStatusMessage(GeneratedMessage msg) { LauncherStatusResponse response = (LauncherStatusResponse) msg; // LOG RESULT! logger.finest("[LAUNCHER] Status: " + response.getStatus().toString()); if (response.hasExitcode()) { logger.finest("[LAUNCHER] Status: exitCode=" + response.getExitcode()); } if (response.hasCrashlog()) { logger.finest("[LAUNCHER] Status: crashLog=yes"); } else { logger.finest("[LAUNCHER] Status: crashLog=no"); } if (response.getLogmessagesCount() > 0) { for (String message : response.getLogmessagesList()) { logger.finest("[LAUNCHER LOG] " + message); } } else { logger.finest("[LAUNCHER LOG] No log..."); } // Handle state StatusType status = response.getStatus(); if (status == StatusType.CRASHED) { if (response.hasCrashlog()) { crashlog = response.getCrashlog().toStringUtf8(); } else { crashlog = ""; // != NULL :-| } } else { crashlog = null; } // TODO: send something to the operalistener.... // if(launcherLastKnowStatus == StatusType.RUNNING && status != // StatusType.RUNNING){ // if(operaListener != null) // operaListener.operaBinaryStopped(response.getExitcode()); // } return status; }
[ "private", "StatusType", "handleStatusMessage", "(", "GeneratedMessage", "msg", ")", "{", "LauncherStatusResponse", "response", "=", "(", "LauncherStatusResponse", ")", "msg", ";", "// LOG RESULT!", "logger", ".", "finest", "(", "\"[LAUNCHER] Status: \"", "+", "response", ".", "getStatus", "(", ")", ".", "toString", "(", ")", ")", ";", "if", "(", "response", ".", "hasExitcode", "(", ")", ")", "{", "logger", ".", "finest", "(", "\"[LAUNCHER] Status: exitCode=\"", "+", "response", ".", "getExitcode", "(", ")", ")", ";", "}", "if", "(", "response", ".", "hasCrashlog", "(", ")", ")", "{", "logger", ".", "finest", "(", "\"[LAUNCHER] Status: crashLog=yes\"", ")", ";", "}", "else", "{", "logger", ".", "finest", "(", "\"[LAUNCHER] Status: crashLog=no\"", ")", ";", "}", "if", "(", "response", ".", "getLogmessagesCount", "(", ")", ">", "0", ")", "{", "for", "(", "String", "message", ":", "response", ".", "getLogmessagesList", "(", ")", ")", "{", "logger", ".", "finest", "(", "\"[LAUNCHER LOG] \"", "+", "message", ")", ";", "}", "}", "else", "{", "logger", ".", "finest", "(", "\"[LAUNCHER LOG] No log...\"", ")", ";", "}", "// Handle state", "StatusType", "status", "=", "response", ".", "getStatus", "(", ")", ";", "if", "(", "status", "==", "StatusType", ".", "CRASHED", ")", "{", "if", "(", "response", ".", "hasCrashlog", "(", ")", ")", "{", "crashlog", "=", "response", ".", "getCrashlog", "(", ")", ".", "toStringUtf8", "(", ")", ";", "}", "else", "{", "crashlog", "=", "\"\"", ";", "// != NULL :-|", "}", "}", "else", "{", "crashlog", "=", "null", ";", "}", "// TODO: send something to the operalistener....", "// if(launcherLastKnowStatus == StatusType.RUNNING && status !=", "// StatusType.RUNNING){", "// if(operaListener != null)", "// operaListener.operaBinaryStopped(response.getExitcode());", "// }", "return", "status", ";", "}" ]
Handle status message, and updates state.
[ "Handle", "status", "message", "and", "updates", "state", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java#L394-L438
3,087
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java
OperaLauncherRunner.assertLauncherGood
public static void assertLauncherGood(File launcher) throws IOException { if (!launcher.exists()) { throw new IOException("Unknown file: " + launcher.getPath()); } if (!launcher.isFile()) { throw new IOException("Not a real file: " + launcher.getPath()); } if (!FileHandler.canExecute(launcher)) { throw new IOException("Not executable: " + launcher.getPath()); } }
java
public static void assertLauncherGood(File launcher) throws IOException { if (!launcher.exists()) { throw new IOException("Unknown file: " + launcher.getPath()); } if (!launcher.isFile()) { throw new IOException("Not a real file: " + launcher.getPath()); } if (!FileHandler.canExecute(launcher)) { throw new IOException("Not executable: " + launcher.getPath()); } }
[ "public", "static", "void", "assertLauncherGood", "(", "File", "launcher", ")", "throws", "IOException", "{", "if", "(", "!", "launcher", ".", "exists", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Unknown file: \"", "+", "launcher", ".", "getPath", "(", ")", ")", ";", "}", "if", "(", "!", "launcher", ".", "isFile", "(", ")", ")", "{", "throw", "new", "IOException", "(", "\"Not a real file: \"", "+", "launcher", ".", "getPath", "(", ")", ")", ";", "}", "if", "(", "!", "FileHandler", ".", "canExecute", "(", "launcher", ")", ")", "{", "throw", "new", "IOException", "(", "\"Not executable: \"", "+", "launcher", ".", "getPath", "(", ")", ")", ";", "}", "}" ]
Asserts whether given launcher exists, is a file and that it's executable. @param launcher the launcher to assert @throws IOException if there is a problem with the provided launcher
[ "Asserts", "whether", "given", "launcher", "exists", "is", "a", "file", "and", "that", "it", "s", "executable", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java#L492-L504
3,088
operasoftware/operaprestodriver
src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java
OperaLauncherRunner.launcherNameForOS
private static String launcherNameForOS() { // TODO(andreastt): It would be nice for OperaLaunchers and OperaDriver to both use Platform switch (Platform.getCurrent()) { case LINUX: case UNIX: // TODO(andreastt): It would be _really nice_ if OperaLaunchers and OperaDriver could both use Architecture: //return String.format("launcher-linux-%s", Architecture.getCurrent()); Architecture architecture = Architecture.getCurrent(); String launcherPrefix = "launcher-linux-%s"; switch (architecture) { case X86: return String.format(launcherPrefix, "i386"); case X64: return String.format(launcherPrefix, "amd64"); case ARM: return String.format(launcherPrefix, "arm"); default: throw new WebDriverException("Unsupported processor architecture: " + architecture); } case MAC: return "launcher-mac"; case WINDOWS: case VISTA: case XP: return "launcher-win32-i86pc.exe"; default: throw new WebDriverException( "Could not find a platform that supports bundled launchers, please set it manually"); } }
java
private static String launcherNameForOS() { // TODO(andreastt): It would be nice for OperaLaunchers and OperaDriver to both use Platform switch (Platform.getCurrent()) { case LINUX: case UNIX: // TODO(andreastt): It would be _really nice_ if OperaLaunchers and OperaDriver could both use Architecture: //return String.format("launcher-linux-%s", Architecture.getCurrent()); Architecture architecture = Architecture.getCurrent(); String launcherPrefix = "launcher-linux-%s"; switch (architecture) { case X86: return String.format(launcherPrefix, "i386"); case X64: return String.format(launcherPrefix, "amd64"); case ARM: return String.format(launcherPrefix, "arm"); default: throw new WebDriverException("Unsupported processor architecture: " + architecture); } case MAC: return "launcher-mac"; case WINDOWS: case VISTA: case XP: return "launcher-win32-i86pc.exe"; default: throw new WebDriverException( "Could not find a platform that supports bundled launchers, please set it manually"); } }
[ "private", "static", "String", "launcherNameForOS", "(", ")", "{", "// TODO(andreastt): It would be nice for OperaLaunchers and OperaDriver to both use Platform", "switch", "(", "Platform", ".", "getCurrent", "(", ")", ")", "{", "case", "LINUX", ":", "case", "UNIX", ":", "// TODO(andreastt): It would be _really nice_ if OperaLaunchers and OperaDriver could both use Architecture:", "//return String.format(\"launcher-linux-%s\", Architecture.getCurrent());", "Architecture", "architecture", "=", "Architecture", ".", "getCurrent", "(", ")", ";", "String", "launcherPrefix", "=", "\"launcher-linux-%s\"", ";", "switch", "(", "architecture", ")", "{", "case", "X86", ":", "return", "String", ".", "format", "(", "launcherPrefix", ",", "\"i386\"", ")", ";", "case", "X64", ":", "return", "String", ".", "format", "(", "launcherPrefix", ",", "\"amd64\"", ")", ";", "case", "ARM", ":", "return", "String", ".", "format", "(", "launcherPrefix", ",", "\"arm\"", ")", ";", "default", ":", "throw", "new", "WebDriverException", "(", "\"Unsupported processor architecture: \"", "+", "architecture", ")", ";", "}", "case", "MAC", ":", "return", "\"launcher-mac\"", ";", "case", "WINDOWS", ":", "case", "VISTA", ":", "case", "XP", ":", "return", "\"launcher-win32-i86pc.exe\"", ";", "default", ":", "throw", "new", "WebDriverException", "(", "\"Could not find a platform that supports bundled launchers, please set it manually\"", ")", ";", "}", "}" ]
Get the launcher's binary file name based on what flavour of operating system and what kind of architecture the user is using. @return the launcher's binary file name
[ "Get", "the", "launcher", "s", "binary", "file", "name", "based", "on", "what", "flavour", "of", "operating", "system", "and", "what", "kind", "of", "architecture", "the", "user", "is", "using", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/runner/launcher/OperaLauncherRunner.java#L512-L542
3,089
operasoftware/operaprestodriver
src/com/opera/core/systems/common/lang/OperaBoolean.java
OperaBoolean.isBoolesque
public static boolean isBoolesque(String string) { checkNotNull(string); assertBoolesque(string); return isFalsy(string) || isTruthy(string); }
java
public static boolean isBoolesque(String string) { checkNotNull(string); assertBoolesque(string); return isFalsy(string) || isTruthy(string); }
[ "public", "static", "boolean", "isBoolesque", "(", "String", "string", ")", "{", "checkNotNull", "(", "string", ")", ";", "assertBoolesque", "(", "string", ")", ";", "return", "isFalsy", "(", "string", ")", "||", "isTruthy", "(", "string", ")", ";", "}" ]
Whether string holds a boolean-like value. It should equal "0", "1", "true" or "false". This method says nothing about whether the object is true or false. @param string string to check @return true if value is "boolesque", false otherwise @throws IllegalArgumentException if parameter is not a boolesque value ("1", "true", "0", "false") @throws NullPointerException if parameter is null
[ "Whether", "string", "holds", "a", "boolean", "-", "like", "value", ".", "It", "should", "equal", "0", "1", "true", "or", "false", ".", "This", "method", "says", "nothing", "about", "whether", "the", "object", "is", "true", "or", "false", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/common/lang/OperaBoolean.java#L54-L58
3,090
rythmengine/rythmengine
src/main/java/org/rythmengine/internal/ExtensionManager.java
ExtensionManager.isJavaExtension
public boolean isJavaExtension(String s) { for (IJavaExtension ext : _extensions) { if (S.isEqual(s, ext.methodName())) { return true; } } return false; }
java
public boolean isJavaExtension(String s) { for (IJavaExtension ext : _extensions) { if (S.isEqual(s, ext.methodName())) { return true; } } return false; }
[ "public", "boolean", "isJavaExtension", "(", "String", "s", ")", "{", "for", "(", "IJavaExtension", "ext", ":", "_extensions", ")", "{", "if", "(", "S", ".", "isEqual", "(", "s", ",", "ext", ".", "methodName", "(", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Is a specified method name a java extension? @param s @return true if the name is a java extension
[ "Is", "a", "specified", "method", "name", "a", "java", "extension?" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/internal/ExtensionManager.java#L46-L53
3,091
rythmengine/rythmengine
src/main/java/org/rythmengine/utils/NamedParams.java
NamedParams.from
public static Map<String, Object> from(Pair... pairs) { Map<String, Object> map = new HashMap<String, Object>(pairs.length); for (Pair p : pairs) { map.put(p.key, p.value); } return map; }
java
public static Map<String, Object> from(Pair... pairs) { Map<String, Object> map = new HashMap<String, Object>(pairs.length); for (Pair p : pairs) { map.put(p.key, p.value); } return map; }
[ "public", "static", "Map", "<", "String", ",", "Object", ">", "from", "(", "Pair", "...", "pairs", ")", "{", "Map", "<", "String", ",", "Object", ">", "map", "=", "new", "HashMap", "<", "String", ",", "Object", ">", "(", "pairs", ".", "length", ")", ";", "for", "(", "Pair", "p", ":", "pairs", ")", "{", "map", ".", "put", "(", "p", ".", "key", ",", "p", ".", "value", ")", ";", "}", "return", "map", ";", "}" ]
construct me from the given pairs @param pairs @return the map
[ "construct", "me", "from", "the", "given", "pairs" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/utils/NamedParams.java#L59-L65
3,092
operasoftware/operaprestodriver
src/com/opera/core/systems/scope/stp/services/desktop/ScopeDesktopUtils.java
ScopeDesktopUtils.getSubstitutedString
public String getSubstitutedString(String[] args, boolean stripAmpersand) { String stringId = args[0]; String rawString = getString(stringId, stripAmpersand); logger.finer(String.format("String \"%s\" fetched as \"%s\"", stringId, rawString)); StringBuffer buf = new StringBuffer(); int curArg = 0; int formattersCount = 0; boolean orderedMode; // Matches %1, %2, ... String orderedFormatterRegexp = "%(\\d+)"; Pattern pattern = Pattern.compile(SUBSTITUTED_STRING_REGEXP); Matcher matcher = pattern.matcher(rawString); // Check if there is at least one "standard" formatter if (matcher.find()) { // There is, assume there are no ordered formatters in the string logger.finer("Parsing with standard formatters"); // Reset the search since we'll also need to substitute the first occurrence later on. matcher.reset(); orderedMode = false; } else { // There is none, assume there are only ordered formatters in the string logger.finer("Parsing with ordered formatters"); pattern = Pattern.compile(orderedFormatterRegexp); matcher = pattern.matcher(rawString); orderedMode = true; } // For each formatter occurrence found in string... while (matcher.find()) { formattersCount++; String replaceStr = matcher.group(); String substitution = ""; if (replaceStr.equals("%%")) { substitution = "%"; } else { if (orderedMode) { // Choose the argument basing on the ordered argument number, i.e. %3 will fetch the third // element from args curArg = Integer.parseInt(replaceStr.substring(1)); } else { // Just go one by one curArg++; } if (curArg < args.length) { // If args is long enough to contain the argument we want, substitute it substitution = args[curArg]; if (substitution.isEmpty()) { substitution = WatirUtils.ANY_MATCHER; } } else { // If args is too short, leave the formatter intact substitution = replaceStr; } } matcher.appendReplacement(buf, substitution); } matcher.appendTail(buf); if (formattersCount != (args.length - 1)) { logger.warning(String.format("Argument count incorrect for %s, got %d, expected %d", stringId, (args.length - 1), formattersCount)); } String result = buf.toString(); logger.finer("Final string: '" + result + "'"); return result; }
java
public String getSubstitutedString(String[] args, boolean stripAmpersand) { String stringId = args[0]; String rawString = getString(stringId, stripAmpersand); logger.finer(String.format("String \"%s\" fetched as \"%s\"", stringId, rawString)); StringBuffer buf = new StringBuffer(); int curArg = 0; int formattersCount = 0; boolean orderedMode; // Matches %1, %2, ... String orderedFormatterRegexp = "%(\\d+)"; Pattern pattern = Pattern.compile(SUBSTITUTED_STRING_REGEXP); Matcher matcher = pattern.matcher(rawString); // Check if there is at least one "standard" formatter if (matcher.find()) { // There is, assume there are no ordered formatters in the string logger.finer("Parsing with standard formatters"); // Reset the search since we'll also need to substitute the first occurrence later on. matcher.reset(); orderedMode = false; } else { // There is none, assume there are only ordered formatters in the string logger.finer("Parsing with ordered formatters"); pattern = Pattern.compile(orderedFormatterRegexp); matcher = pattern.matcher(rawString); orderedMode = true; } // For each formatter occurrence found in string... while (matcher.find()) { formattersCount++; String replaceStr = matcher.group(); String substitution = ""; if (replaceStr.equals("%%")) { substitution = "%"; } else { if (orderedMode) { // Choose the argument basing on the ordered argument number, i.e. %3 will fetch the third // element from args curArg = Integer.parseInt(replaceStr.substring(1)); } else { // Just go one by one curArg++; } if (curArg < args.length) { // If args is long enough to contain the argument we want, substitute it substitution = args[curArg]; if (substitution.isEmpty()) { substitution = WatirUtils.ANY_MATCHER; } } else { // If args is too short, leave the formatter intact substitution = replaceStr; } } matcher.appendReplacement(buf, substitution); } matcher.appendTail(buf); if (formattersCount != (args.length - 1)) { logger.warning(String.format("Argument count incorrect for %s, got %d, expected %d", stringId, (args.length - 1), formattersCount)); } String result = buf.toString(); logger.finer("Final string: '" + result + "'"); return result; }
[ "public", "String", "getSubstitutedString", "(", "String", "[", "]", "args", ",", "boolean", "stripAmpersand", ")", "{", "String", "stringId", "=", "args", "[", "0", "]", ";", "String", "rawString", "=", "getString", "(", "stringId", ",", "stripAmpersand", ")", ";", "logger", ".", "finer", "(", "String", ".", "format", "(", "\"String \\\"%s\\\" fetched as \\\"%s\\\"\"", ",", "stringId", ",", "rawString", ")", ")", ";", "StringBuffer", "buf", "=", "new", "StringBuffer", "(", ")", ";", "int", "curArg", "=", "0", ";", "int", "formattersCount", "=", "0", ";", "boolean", "orderedMode", ";", "// Matches %1, %2, ...", "String", "orderedFormatterRegexp", "=", "\"%(\\\\d+)\"", ";", "Pattern", "pattern", "=", "Pattern", ".", "compile", "(", "SUBSTITUTED_STRING_REGEXP", ")", ";", "Matcher", "matcher", "=", "pattern", ".", "matcher", "(", "rawString", ")", ";", "// Check if there is at least one \"standard\" formatter", "if", "(", "matcher", ".", "find", "(", ")", ")", "{", "// There is, assume there are no ordered formatters in the string", "logger", ".", "finer", "(", "\"Parsing with standard formatters\"", ")", ";", "// Reset the search since we'll also need to substitute the first occurrence later on.", "matcher", ".", "reset", "(", ")", ";", "orderedMode", "=", "false", ";", "}", "else", "{", "// There is none, assume there are only ordered formatters in the string", "logger", ".", "finer", "(", "\"Parsing with ordered formatters\"", ")", ";", "pattern", "=", "Pattern", ".", "compile", "(", "orderedFormatterRegexp", ")", ";", "matcher", "=", "pattern", ".", "matcher", "(", "rawString", ")", ";", "orderedMode", "=", "true", ";", "}", "// For each formatter occurrence found in string...", "while", "(", "matcher", ".", "find", "(", ")", ")", "{", "formattersCount", "++", ";", "String", "replaceStr", "=", "matcher", ".", "group", "(", ")", ";", "String", "substitution", "=", "\"\"", ";", "if", "(", "replaceStr", ".", "equals", "(", "\"%%\"", ")", ")", "{", "substitution", "=", "\"%\"", ";", "}", "else", "{", "if", "(", "orderedMode", ")", "{", "// Choose the argument basing on the ordered argument number, i.e. %3 will fetch the third", "// element from args", "curArg", "=", "Integer", ".", "parseInt", "(", "replaceStr", ".", "substring", "(", "1", ")", ")", ";", "}", "else", "{", "// Just go one by one", "curArg", "++", ";", "}", "if", "(", "curArg", "<", "args", ".", "length", ")", "{", "// If args is long enough to contain the argument we want, substitute it", "substitution", "=", "args", "[", "curArg", "]", ";", "if", "(", "substitution", ".", "isEmpty", "(", ")", ")", "{", "substitution", "=", "WatirUtils", ".", "ANY_MATCHER", ";", "}", "}", "else", "{", "// If args is too short, leave the formatter intact", "substitution", "=", "replaceStr", ";", "}", "}", "matcher", ".", "appendReplacement", "(", "buf", ",", "substitution", ")", ";", "}", "matcher", ".", "appendTail", "(", "buf", ")", ";", "if", "(", "formattersCount", "!=", "(", "args", ".", "length", "-", "1", ")", ")", "{", "logger", ".", "warning", "(", "String", ".", "format", "(", "\"Argument count incorrect for %s, got %d, expected %d\"", ",", "stringId", ",", "(", "args", ".", "length", "-", "1", ")", ",", "formattersCount", ")", ")", ";", "}", "String", "result", "=", "buf", ".", "toString", "(", ")", ";", "logger", ".", "finer", "(", "\"Final string: '\"", "+", "result", "+", "\"'\"", ")", ";", "return", "result", ";", "}" ]
Fetches a translated string fetched basing on a string id and substitutes the printf formatters in it. Each substitution argument needs to be a string. The printf formatter types are ignored, and the given string argument is substituted. The method distinguishes between ordered substitution (i.e. %1, %2) and a standard substitution (i.e. %s, %d). In case the given argument list is too long or too short for the number of arguments in the fetched translated string, this method triggers a warning. In case the given argument list is too short, the method substitutes as many formatters as possible and leaves the rest of them intact. "%%" is substituted to "%". If a given argument is empty, i.e. "", it will be substituted to ANY_MATCHER, allowing later searching for the text without specific formatter values, i.e. matching "Show _ANY_ more..." to any string like "Show 1 more...", "Show 2 more...". @param args an array containing the printf substitution arguments, all of string type, and the string id as the first element @param stripAmpersand whether to strip the "&" character from the fetched string @return the final substituted string
[ "Fetches", "a", "translated", "string", "fetched", "basing", "on", "a", "string", "id", "and", "substitutes", "the", "printf", "formatters", "in", "it", ".", "Each", "substitution", "argument", "needs", "to", "be", "a", "string", ".", "The", "printf", "formatter", "types", "are", "ignored", "and", "the", "given", "string", "argument", "is", "substituted", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/scope/stp/services/desktop/ScopeDesktopUtils.java#L100-L174
3,093
operasoftware/operaprestodriver
src/com/opera/core/systems/internal/StackHashMap.java
StackHashMap.putIfAbsent
public V putIfAbsent(K k, V v) { synchronized (map) { if (!containsKey(k)) { list.addFirst(k); return map.put(k, v); } else { list.remove(k); } list.addFirst(k); return null; } }
java
public V putIfAbsent(K k, V v) { synchronized (map) { if (!containsKey(k)) { list.addFirst(k); return map.put(k, v); } else { list.remove(k); } list.addFirst(k); return null; } }
[ "public", "V", "putIfAbsent", "(", "K", "k", ",", "V", "v", ")", "{", "synchronized", "(", "map", ")", "{", "if", "(", "!", "containsKey", "(", "k", ")", ")", "{", "list", ".", "addFirst", "(", "k", ")", ";", "return", "map", ".", "put", "(", "k", ",", "v", ")", ";", "}", "else", "{", "list", ".", "remove", "(", "k", ")", ";", "}", "list", ".", "addFirst", "(", "k", ")", ";", "return", "null", ";", "}", "}" ]
Puts a key to top of the map if absent if the key is present in stack it is removed @return the value if it is not contained, null otherwise
[ "Puts", "a", "key", "to", "top", "of", "the", "map", "if", "absent", "if", "the", "key", "is", "present", "in", "stack", "it", "is", "removed" ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/internal/StackHashMap.java#L168-L179
3,094
rythmengine/rythmengine
src/main/java/org/rythmengine/exception/CompileException.java
CompileException.compilerException
public static CompilerException compilerException(String className, int line, String message) { CompilerException e = new CompilerException(); e.javaLineNumber = line; e.message = ExpressionParser.reversePositionPlaceHolder(message); e.className = className; return e; }
java
public static CompilerException compilerException(String className, int line, String message) { CompilerException e = new CompilerException(); e.javaLineNumber = line; e.message = ExpressionParser.reversePositionPlaceHolder(message); e.className = className; return e; }
[ "public", "static", "CompilerException", "compilerException", "(", "String", "className", ",", "int", "line", ",", "String", "message", ")", "{", "CompilerException", "e", "=", "new", "CompilerException", "(", ")", ";", "e", ".", "javaLineNumber", "=", "line", ";", "e", ".", "message", "=", "ExpressionParser", ".", "reversePositionPlaceHolder", "(", "message", ")", ";", "e", ".", "className", "=", "className", ";", "return", "e", ";", "}" ]
create a compiler exception for the given className, line number and message @param className @param line @param message @return the CompilerException
[ "create", "a", "compiler", "exception", "for", "the", "given", "className", "line", "number", "and", "message" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/exception/CompileException.java#L43-L49
3,095
rythmengine/rythmengine
src/main/java/org/rythmengine/Sandbox.java
Sandbox.turnOffSandbox
public static void turnOffSandbox(String code) { if (!sandboxLive) return; rsm().forbiddenIfCodeNotMatch(code); sandboxLive = false; System.setSecurityManager(null); }
java
public static void turnOffSandbox(String code) { if (!sandboxLive) return; rsm().forbiddenIfCodeNotMatch(code); sandboxLive = false; System.setSecurityManager(null); }
[ "public", "static", "void", "turnOffSandbox", "(", "String", "code", ")", "{", "if", "(", "!", "sandboxLive", ")", "return", ";", "rsm", "(", ")", ".", "forbiddenIfCodeNotMatch", "(", "code", ")", ";", "sandboxLive", "=", "false", ";", "System", ".", "setSecurityManager", "(", "null", ")", ";", "}" ]
Turn off sandbox mode. Used by Rythm unit testing program @param code
[ "Turn", "off", "sandbox", "mode", ".", "Used", "by", "Rythm", "unit", "testing", "program" ]
064b565f08d9da07378bf77a9dd856ea5831cc92
https://github.com/rythmengine/rythmengine/blob/064b565f08d9da07378bf77a9dd856ea5831cc92/src/main/java/org/rythmengine/Sandbox.java#L40-L45
3,096
operasoftware/operaprestodriver
src/com/opera/core/systems/arguments/OperaArgument.java
OperaArgument.sanitize
private static String sanitize(String key) { for (OperaArgumentSign sign : OperaArgumentSign.values()) { if (hasSwitch(key, sign.sign)) { return key.substring(sign.sign.length()); } } return key; }
java
private static String sanitize(String key) { for (OperaArgumentSign sign : OperaArgumentSign.values()) { if (hasSwitch(key, sign.sign)) { return key.substring(sign.sign.length()); } } return key; }
[ "private", "static", "String", "sanitize", "(", "String", "key", ")", "{", "for", "(", "OperaArgumentSign", "sign", ":", "OperaArgumentSign", ".", "values", "(", ")", ")", "{", "if", "(", "hasSwitch", "(", "key", ",", "sign", ".", "sign", ")", ")", "{", "return", "key", ".", "substring", "(", "sign", ".", "sign", ".", "length", "(", ")", ")", ";", "}", "}", "return", "key", ";", "}" ]
Sanitizes an argument that contains a sign. By default we sanitize all added arguments, meaning "-foo" will be sanitized to "foo". @param key the argument key to sanitize @return a sanitized argument key
[ "Sanitizes", "an", "argument", "that", "contains", "a", "sign", ".", "By", "default", "we", "sanitize", "all", "added", "arguments", "meaning", "-", "foo", "will", "be", "sanitized", "to", "foo", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/arguments/OperaArgument.java#L119-L127
3,097
operasoftware/operaprestodriver
src/com/opera/core/systems/arguments/OperaArgument.java
OperaArgument.hasSwitch
private static Boolean hasSwitch(String key, String sign) { return (key.length() > sign.length()) && key.substring(0, sign.length()).equals(sign); }
java
private static Boolean hasSwitch(String key, String sign) { return (key.length() > sign.length()) && key.substring(0, sign.length()).equals(sign); }
[ "private", "static", "Boolean", "hasSwitch", "(", "String", "key", ",", "String", "sign", ")", "{", "return", "(", "key", ".", "length", "(", ")", ">", "sign", ".", "length", "(", ")", ")", "&&", "key", ".", "substring", "(", "0", ",", "sign", ".", "length", "(", ")", ")", ".", "equals", "(", "sign", ")", ";", "}" ]
Determines whether given argument key contains given argument sign. @param key the argument key to check @param sign the sign to check for @return true if key contains sign as first characters, false otherwise @see OperaArgumentSign
[ "Determines", "whether", "given", "argument", "key", "contains", "given", "argument", "sign", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/arguments/OperaArgument.java#L137-L139
3,098
operasoftware/operaprestodriver
src/com/opera/core/systems/scope/stp/services/ScopeExec.java
ScopeExec.executeScreenWatcher
private ScreenWatcherResult executeScreenWatcher(ScreenWatcher.Builder builder, long timeout) { if (timeout <= 0) { timeout = 1; } // TODO(andreastt): Unsafe long to int cast builder.setTimeOut((int) timeout); builder.setWindowID(services.getWindowManager().getActiveWindowId()); Response response = executeMessage(ExecMessage.SETUP_SCREEN_WATCHER, builder, OperaIntervals.RESPONSE_TIMEOUT.getMs() + timeout); ScreenWatcherResult.Builder watcherBuilder = ScreenWatcherResult.newBuilder(); buildPayload(response, watcherBuilder); return watcherBuilder.build(); }
java
private ScreenWatcherResult executeScreenWatcher(ScreenWatcher.Builder builder, long timeout) { if (timeout <= 0) { timeout = 1; } // TODO(andreastt): Unsafe long to int cast builder.setTimeOut((int) timeout); builder.setWindowID(services.getWindowManager().getActiveWindowId()); Response response = executeMessage(ExecMessage.SETUP_SCREEN_WATCHER, builder, OperaIntervals.RESPONSE_TIMEOUT.getMs() + timeout); ScreenWatcherResult.Builder watcherBuilder = ScreenWatcherResult.newBuilder(); buildPayload(response, watcherBuilder); return watcherBuilder.build(); }
[ "private", "ScreenWatcherResult", "executeScreenWatcher", "(", "ScreenWatcher", ".", "Builder", "builder", ",", "long", "timeout", ")", "{", "if", "(", "timeout", "<=", "0", ")", "{", "timeout", "=", "1", ";", "}", "// TODO(andreastt): Unsafe long to int cast", "builder", ".", "setTimeOut", "(", "(", "int", ")", "timeout", ")", ";", "builder", ".", "setWindowID", "(", "services", ".", "getWindowManager", "(", ")", ".", "getActiveWindowId", "(", ")", ")", ";", "Response", "response", "=", "executeMessage", "(", "ExecMessage", ".", "SETUP_SCREEN_WATCHER", ",", "builder", ",", "OperaIntervals", ".", "RESPONSE_TIMEOUT", ".", "getMs", "(", ")", "+", "timeout", ")", ";", "ScreenWatcherResult", ".", "Builder", "watcherBuilder", "=", "ScreenWatcherResult", ".", "newBuilder", "(", ")", ";", "buildPayload", "(", "response", ",", "watcherBuilder", ")", ";", "return", "watcherBuilder", ".", "build", "(", ")", ";", "}" ]
Executes a screenwatcher with the given timeout and returns the result.
[ "Executes", "a", "screenwatcher", "with", "the", "given", "timeout", "and", "returns", "the", "result", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/scope/stp/services/ScopeExec.java#L242-L260
3,099
operasoftware/operaprestodriver
src/com/opera/core/systems/scope/AbstractEcmascriptService.java
AbstractEcmascriptService.buildEvalString
protected String buildEvalString(List<WebElement> elements, String script, Object... params) { String toSend; if (params != null && params.length > 0) { StringBuilder builder = new StringBuilder(); for (Object object : params) { if (builder.toString().length() > 0) { builder.append(','); } if (object instanceof Collection<?>) { builder.append('['); Collection<?> collection = (Collection<?>) object; for (Object argument : collection) { processArgument(argument, builder, elements); builder.append(','); } int lastCharIndex = builder.length() - 1; if (builder.charAt(lastCharIndex) != '[') { builder.deleteCharAt(lastCharIndex); } builder.append(']'); } else { processArgument(object, builder, elements); } } String arguments = builder.toString(); toSend = String.format("(function(){%s})(%s)", script, arguments); } else { toSend = script; } return toSend; }
java
protected String buildEvalString(List<WebElement> elements, String script, Object... params) { String toSend; if (params != null && params.length > 0) { StringBuilder builder = new StringBuilder(); for (Object object : params) { if (builder.toString().length() > 0) { builder.append(','); } if (object instanceof Collection<?>) { builder.append('['); Collection<?> collection = (Collection<?>) object; for (Object argument : collection) { processArgument(argument, builder, elements); builder.append(','); } int lastCharIndex = builder.length() - 1; if (builder.charAt(lastCharIndex) != '[') { builder.deleteCharAt(lastCharIndex); } builder.append(']'); } else { processArgument(object, builder, elements); } } String arguments = builder.toString(); toSend = String.format("(function(){%s})(%s)", script, arguments); } else { toSend = script; } return toSend; }
[ "protected", "String", "buildEvalString", "(", "List", "<", "WebElement", ">", "elements", ",", "String", "script", ",", "Object", "...", "params", ")", "{", "String", "toSend", ";", "if", "(", "params", "!=", "null", "&&", "params", ".", "length", ">", "0", ")", "{", "StringBuilder", "builder", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "Object", "object", ":", "params", ")", "{", "if", "(", "builder", ".", "toString", "(", ")", ".", "length", "(", ")", ">", "0", ")", "{", "builder", ".", "append", "(", "'", "'", ")", ";", "}", "if", "(", "object", "instanceof", "Collection", "<", "?", ">", ")", "{", "builder", ".", "append", "(", "'", "'", ")", ";", "Collection", "<", "?", ">", "collection", "=", "(", "Collection", "<", "?", ">", ")", "object", ";", "for", "(", "Object", "argument", ":", "collection", ")", "{", "processArgument", "(", "argument", ",", "builder", ",", "elements", ")", ";", "builder", ".", "append", "(", "'", "'", ")", ";", "}", "int", "lastCharIndex", "=", "builder", ".", "length", "(", ")", "-", "1", ";", "if", "(", "builder", ".", "charAt", "(", "lastCharIndex", ")", "!=", "'", "'", ")", "{", "builder", ".", "deleteCharAt", "(", "lastCharIndex", ")", ";", "}", "builder", ".", "append", "(", "'", "'", ")", ";", "}", "else", "{", "processArgument", "(", "object", ",", "builder", ",", "elements", ")", ";", "}", "}", "String", "arguments", "=", "builder", ".", "toString", "(", ")", ";", "toSend", "=", "String", ".", "format", "(", "\"(function(){%s})(%s)\"", ",", "script", ",", "arguments", ")", ";", "}", "else", "{", "toSend", "=", "script", ";", "}", "return", "toSend", ";", "}" ]
Build the script to send with arguments. @param elements the web elements to send with the script as argument @param script the script to execute, can have references to argument(s) @param params params to send with the script, will be parsed in to arguments @return the script to be sent to Eval command for execution
[ "Build", "the", "script", "to", "send", "with", "arguments", "." ]
1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01
https://github.com/operasoftware/operaprestodriver/blob/1ccceda80f1c1a0489171d17dcaa6e7b18fb4c01/src/com/opera/core/systems/scope/AbstractEcmascriptService.java#L105-L143