repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
groovy/groovy-core
subprojects/groovy-console/src/main/groovy/groovy/ui/text/FindReplaceUtility.java
FindReplaceUtility.findNext
private static int findNext(boolean reverse, int pos) { boolean backwards = IS_BACKWARDS_CHECKBOX.isSelected(); backwards = backwards ? !reverse : reverse; String pattern = (String) FIND_FIELD.getSelectedItem(); if (pattern != null && pattern.length() > 0) { try { Document doc = textComponent.getDocument(); doc.getText(0, doc.getLength(), SEGMENT); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } pos += textComponent.getSelectedText() == null ? (backwards ? -1 : 1) : 0; char first = backwards ? pattern.charAt(pattern.length() - 1) : pattern.charAt(0); char oppFirst = Character.isUpperCase(first) ? Character.toLowerCase(first) : Character.toUpperCase(first); int start = pos; boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected(); int end = backwards ? 0 : SEGMENT.getEndIndex(); pos += backwards ? -1 : 1; int length = textComponent.getDocument().getLength(); if (pos > length) { pos = wrapped ? 0 : length; } boolean found = false; while (!found && (backwards ? pos > end : pos < end)) { found = !MATCH_CASE_CHECKBOX.isSelected() && SEGMENT.array[pos] == oppFirst; found = found ? found : SEGMENT.array[pos] == first; if (found) { pos += backwards ? -(pattern.length() - 1) : 0; for (int i = 0; found && i < pattern.length(); i++) { char c = pattern.charAt(i); found = SEGMENT.array[pos + i] == c; if (!MATCH_CASE_CHECKBOX.isSelected() && !found) { c = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c); found = SEGMENT.array[pos + i] == c; } } } if (!found) { pos += backwards ? -1 : 1; if (pos == end && wrapped) { pos = backwards ? SEGMENT.getEndIndex() : 0; end = start; wrapped = false; } } } pos = found ? pos : -1; } return pos; }
java
private static int findNext(boolean reverse, int pos) { boolean backwards = IS_BACKWARDS_CHECKBOX.isSelected(); backwards = backwards ? !reverse : reverse; String pattern = (String) FIND_FIELD.getSelectedItem(); if (pattern != null && pattern.length() > 0) { try { Document doc = textComponent.getDocument(); doc.getText(0, doc.getLength(), SEGMENT); } catch (Exception e) { // should NEVER reach here e.printStackTrace(); } pos += textComponent.getSelectedText() == null ? (backwards ? -1 : 1) : 0; char first = backwards ? pattern.charAt(pattern.length() - 1) : pattern.charAt(0); char oppFirst = Character.isUpperCase(first) ? Character.toLowerCase(first) : Character.toUpperCase(first); int start = pos; boolean wrapped = WRAP_SEARCH_CHECKBOX.isSelected(); int end = backwards ? 0 : SEGMENT.getEndIndex(); pos += backwards ? -1 : 1; int length = textComponent.getDocument().getLength(); if (pos > length) { pos = wrapped ? 0 : length; } boolean found = false; while (!found && (backwards ? pos > end : pos < end)) { found = !MATCH_CASE_CHECKBOX.isSelected() && SEGMENT.array[pos] == oppFirst; found = found ? found : SEGMENT.array[pos] == first; if (found) { pos += backwards ? -(pattern.length() - 1) : 0; for (int i = 0; found && i < pattern.length(); i++) { char c = pattern.charAt(i); found = SEGMENT.array[pos + i] == c; if (!MATCH_CASE_CHECKBOX.isSelected() && !found) { c = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c); found = SEGMENT.array[pos + i] == c; } } } if (!found) { pos += backwards ? -1 : 1; if (pos == end && wrapped) { pos = backwards ? SEGMENT.getEndIndex() : 0; end = start; wrapped = false; } } } pos = found ? pos : -1; } return pos; }
[ "private", "static", "int", "findNext", "(", "boolean", "reverse", ",", "int", "pos", ")", "{", "boolean", "backwards", "=", "IS_BACKWARDS_CHECKBOX", ".", "isSelected", "(", ")", ";", "backwards", "=", "backwards", "?", "!", "reverse", ":", "reverse", ";", ...
Find and select the next searchable matching text. @param reverse look forwards or backwards @param pos the starting index to start finding from @return the location of the next selected, or -1 if not found
[ "Find", "and", "select", "the", "next", "searchable", "matching", "text", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-console/src/main/groovy/groovy/ui/text/FindReplaceUtility.java#L261-L326
train
groovy/groovy-core
src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
IndyInterface.invalidateSwitchPoints
protected static void invalidateSwitchPoints() { if (LOG_ENABLED) { LOG.info("invalidating switch point"); } SwitchPoint old = switchPoint; switchPoint = new SwitchPoint(); synchronized(IndyInterface.class) { SwitchPoint.invalidateAll(new SwitchPoint[]{old}); } }
java
protected static void invalidateSwitchPoints() { if (LOG_ENABLED) { LOG.info("invalidating switch point"); } SwitchPoint old = switchPoint; switchPoint = new SwitchPoint(); synchronized(IndyInterface.class) { SwitchPoint.invalidateAll(new SwitchPoint[]{old}); } }
[ "protected", "static", "void", "invalidateSwitchPoints", "(", ")", "{", "if", "(", "LOG_ENABLED", ")", "{", "LOG", ".", "info", "(", "\"invalidating switch point\"", ")", ";", "}", "SwitchPoint", "old", "=", "switchPoint", ";", "switchPoint", "=", "new", "Swit...
Callback for constant meta class update change
[ "Callback", "for", "constant", "meta", "class", "update", "change" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java#L108-L115
train
groovy/groovy-core
src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
IndyInterface.bootstrapCurrent
public static CallSite bootstrapCurrent(Lookup caller, String name, MethodType type) { return realBootstrap(caller, name, CALL_TYPES.METHOD.ordinal(), type, false, true, false); }
java
public static CallSite bootstrapCurrent(Lookup caller, String name, MethodType type) { return realBootstrap(caller, name, CALL_TYPES.METHOD.ordinal(), type, false, true, false); }
[ "public", "static", "CallSite", "bootstrapCurrent", "(", "Lookup", "caller", ",", "String", "name", ",", "MethodType", "type", ")", "{", "return", "realBootstrap", "(", "caller", ",", "name", ",", "CALL_TYPES", ".", "METHOD", ".", "ordinal", "(", ")", ",", ...
bootstrap method for method calls with "this" as receiver @deprecated since Groovy 2.1.0
[ "bootstrap", "method", "for", "method", "calls", "with", "this", "as", "receiver" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java#L157-L159
train
groovy/groovy-core
src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
IndyInterface.realBootstrap
private static CallSite realBootstrap(Lookup caller, String name, int callID, MethodType type, boolean safe, boolean thisCall, boolean spreadCall) { // since indy does not give us the runtime types // we produce first a dummy call site, which then changes the target to one, // that does the method selection including the the direct call to the // real method. MutableCallSite mc = new MutableCallSite(type); MethodHandle mh = makeFallBack(mc,caller.lookupClass(),name,callID,type,safe,thisCall,spreadCall); mc.setTarget(mh); return mc; }
java
private static CallSite realBootstrap(Lookup caller, String name, int callID, MethodType type, boolean safe, boolean thisCall, boolean spreadCall) { // since indy does not give us the runtime types // we produce first a dummy call site, which then changes the target to one, // that does the method selection including the the direct call to the // real method. MutableCallSite mc = new MutableCallSite(type); MethodHandle mh = makeFallBack(mc,caller.lookupClass(),name,callID,type,safe,thisCall,spreadCall); mc.setTarget(mh); return mc; }
[ "private", "static", "CallSite", "realBootstrap", "(", "Lookup", "caller", ",", "String", "name", ",", "int", "callID", ",", "MethodType", "type", ",", "boolean", "safe", ",", "boolean", "thisCall", ",", "boolean", "spreadCall", ")", "{", "// since indy does not...
backing bootstrap method with all parameters
[ "backing", "bootstrap", "method", "with", "all", "parameters" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/vmplugin/v7/IndyInterface.java#L188-L197
train
groovy/groovy-core
subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/TableLayout.java
TableLayout.addCell
public void addCell(TableLayoutCell cell) { GridBagConstraints constraints = cell.getConstraints(); constraints.insets = new Insets(cellpadding, cellpadding, cellpadding, cellpadding); add(cell.getComponent(), constraints); }
java
public void addCell(TableLayoutCell cell) { GridBagConstraints constraints = cell.getConstraints(); constraints.insets = new Insets(cellpadding, cellpadding, cellpadding, cellpadding); add(cell.getComponent(), constraints); }
[ "public", "void", "addCell", "(", "TableLayoutCell", "cell", ")", "{", "GridBagConstraints", "constraints", "=", "cell", ".", "getConstraints", "(", ")", ";", "constraints", ".", "insets", "=", "new", "Insets", "(", "cellpadding", ",", "cellpadding", ",", "cel...
Adds a new cell to the current grid @param cell the td component
[ "Adds", "a", "new", "cell", "to", "the", "current", "grid" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-swing/src/main/groovy/groovy/swing/impl/TableLayout.java#L54-L58
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/CompileUnit.java
CompileUnit.addClass
public void addClass(ClassNode node) { node = node.redirect(); String name = node.getName(); ClassNode stored = classes.get(name); if (stored != null && stored != node) { // we have a duplicate class! // One possibility for this is, that we declared a script and a // class in the same file and named the class like the file SourceUnit nodeSource = node.getModule().getContext(); SourceUnit storedSource = stored.getModule().getContext(); String txt = "Invalid duplicate class definition of class " + node.getName() + " : "; if (nodeSource == storedSource) { // same class in same source txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n"; if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + " the script body based on the file name. Solutions are to change the file name or to change the class name.\n"; } } else { txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " each contain a class with the name " + node.getName() + ".\n"; } nodeSource.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), nodeSource) ); } classes.put(name, node); if (classesToCompile.containsKey(name)) { ClassNode cn = classesToCompile.get(name); cn.setRedirect(node); classesToCompile.remove(name); } }
java
public void addClass(ClassNode node) { node = node.redirect(); String name = node.getName(); ClassNode stored = classes.get(name); if (stored != null && stored != node) { // we have a duplicate class! // One possibility for this is, that we declared a script and a // class in the same file and named the class like the file SourceUnit nodeSource = node.getModule().getContext(); SourceUnit storedSource = stored.getModule().getContext(); String txt = "Invalid duplicate class definition of class " + node.getName() + " : "; if (nodeSource == storedSource) { // same class in same source txt += "The source " + nodeSource.getName() + " contains at least two definitions of the class " + node.getName() + ".\n"; if (node.isScriptBody() || stored.isScriptBody()) { txt += "One of the classes is an explicit generated class using the class statement, the other is a class generated from" + " the script body based on the file name. Solutions are to change the file name or to change the class name.\n"; } } else { txt += "The sources " + nodeSource.getName() + " and " + storedSource.getName() + " each contain a class with the name " + node.getName() + ".\n"; } nodeSource.getErrorCollector().addErrorAndContinue( new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), nodeSource) ); } classes.put(name, node); if (classesToCompile.containsKey(name)) { ClassNode cn = classesToCompile.get(name); cn.setRedirect(node); classesToCompile.remove(name); } }
[ "public", "void", "addClass", "(", "ClassNode", "node", ")", "{", "node", "=", "node", ".", "redirect", "(", ")", ";", "String", "name", "=", "node", ".", "getName", "(", ")", ";", "ClassNode", "stored", "=", "classes", ".", "get", "(", "name", ")", ...
Adds a class to the unit.
[ "Adds", "a", "class", "to", "the", "unit", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/CompileUnit.java#L127-L159
train
groovy/groovy-core
src/main/org/codehaus/groovy/tools/LoaderConfiguration.java
LoaderConfiguration.getSlashyPath
private String getSlashyPath(final String path) { String changedPath = path; if (File.separatorChar != '/') changedPath = changedPath.replace(File.separatorChar, '/'); return changedPath; }
java
private String getSlashyPath(final String path) { String changedPath = path; if (File.separatorChar != '/') changedPath = changedPath.replace(File.separatorChar, '/'); return changedPath; }
[ "private", "String", "getSlashyPath", "(", "final", "String", "path", ")", "{", "String", "changedPath", "=", "path", ";", "if", "(", "File", ".", "separatorChar", "!=", "'", "'", ")", "changedPath", "=", "changedPath", ".", "replace", "(", "File", ".", ...
This solution is based on an absolute path
[ "This", "solution", "is", "based", "on", "an", "absolute", "path" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/tools/LoaderConfiguration.java#L259-L265
train
groovy/groovy-core
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.write
public static void write(Path self, String text, String charset) throws IOException { Writer writer = null; try { writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.forName(charset)); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
java
public static void write(Path self, String text, String charset) throws IOException { Writer writer = null; try { writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.forName(charset)); writer.write(text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
[ "public", "static", "void", "write", "(", "Path", "self", ",", "String", "text", ",", "String", "charset", ")", "throws", "IOException", "{", "Writer", "writer", "=", "null", ";", "try", "{", "writer", "=", "new", "OutputStreamWriter", "(", "Files", ".", ...
Write the text to the Path, using the specified encoding. @param self a Path @param text the text to write to the Path @param charset the charset used @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Write", "the", "text", "to", "the", "Path", "using", "the", "specified", "encoding", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L558-L571
train
groovy/groovy-core
subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
NioGroovyMethods.append
public static void append(Path self, Object text) throws IOException { Writer writer = null; try { writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.defaultCharset()); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
java
public static void append(Path self, Object text) throws IOException { Writer writer = null; try { writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.defaultCharset()); InvokerHelper.write(writer, text); writer.flush(); Writer temp = writer; writer = null; temp.close(); } finally { closeWithWarning(writer); } }
[ "public", "static", "void", "append", "(", "Path", "self", ",", "Object", "text", ")", "throws", "IOException", "{", "Writer", "writer", "=", "null", ";", "try", "{", "writer", "=", "new", "OutputStreamWriter", "(", "Files", ".", "newOutputStream", "(", "s...
Append the text at the end of the Path. @param self a Path @param text the text to append at the end of the Path @throws java.io.IOException if an IOException occurs. @since 2.3.0
[ "Append", "the", "text", "at", "the", "end", "of", "the", "Path", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java#L581-L594
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.count
public static int count(CharSequence self, CharSequence text) { int answer = 0; for (int idx = 0; true; idx++) { idx = self.toString().indexOf(text.toString(), idx); // break once idx goes to -1 or for case of empty string once // we get to the end to avoid JDK library bug (see GROOVY-5858) if (idx < answer) break; ++answer; } return answer; }
java
public static int count(CharSequence self, CharSequence text) { int answer = 0; for (int idx = 0; true; idx++) { idx = self.toString().indexOf(text.toString(), idx); // break once idx goes to -1 or for case of empty string once // we get to the end to avoid JDK library bug (see GROOVY-5858) if (idx < answer) break; ++answer; } return answer; }
[ "public", "static", "int", "count", "(", "CharSequence", "self", ",", "CharSequence", "text", ")", "{", "int", "answer", "=", "0", ";", "for", "(", "int", "idx", "=", "0", ";", "true", ";", "idx", "++", ")", "{", "idx", "=", "self", ".", "toString"...
Count the number of occurrences of a sub CharSequence. @param self a CharSequence @param text a sub CharSequence @return the number of occurrences of the given CharSequence inside this CharSequence @see #count(String, String) @since 1.8.2
[ "Count", "the", "number", "of", "occurrences", "of", "a", "sub", "CharSequence", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L387-L397
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.eachMatch
public static <T extends CharSequence> T eachMatch(T self, CharSequence regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) { eachMatch(self.toString(), regex.toString(), closure); return self; }
java
public static <T extends CharSequence> T eachMatch(T self, CharSequence regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) { eachMatch(self.toString(), regex.toString(), closure); return self; }
[ "public", "static", "<", "T", "extends", "CharSequence", ">", "T", "eachMatch", "(", "T", "self", ",", "CharSequence", "regex", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "{", "\"List<String>\"", ",", "\"...
Process each regex group matched substring of the given CharSequence. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group. @param self the source CharSequence @param regex a Regex CharSequence @param closure a closure with one parameter or as much parameters as groups @return the source CharSequence @see #eachMatch(String, String, groovy.lang.Closure) @since 1.8.2
[ "Process", "each", "regex", "group", "matched", "substring", "of", "the", "given", "CharSequence", ".", "If", "the", "closure", "parameter", "takes", "one", "argument", "an", "array", "with", "all", "match", "groups", "is", "passed", "to", "it", ".", "If", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L692-L695
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.eachMatch
public static String eachMatch(String self, String regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) { return eachMatch(self, Pattern.compile(regex), closure); }
java
public static String eachMatch(String self, String regex, @ClosureParams(value=FromString.class, options={"List<String>","String[]"}) Closure closure) { return eachMatch(self, Pattern.compile(regex), closure); }
[ "public", "static", "String", "eachMatch", "(", "String", "self", ",", "String", "regex", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "{", "\"List<String>\"", ",", "\"String[]\"", "}", ")", "Closure", "closu...
Process each regex group matched substring of the given string. If the closure parameter takes one argument, an array with all match groups is passed to it. If the closure takes as many arguments as there are match groups, then each parameter will be one match group. @param self the source string @param regex a Regex string @param closure a closure with one parameter or as much parameters as groups @return the source string @since 1.6.0
[ "Process", "each", "regex", "group", "matched", "substring", "of", "the", "given", "string", ".", "If", "the", "closure", "parameter", "takes", "one", "argument", "an", "array", "with", "all", "match", "groups", "is", "passed", "to", "it", ".", "If", "the"...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L745-L747
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.expandLine
public static String expandLine(CharSequence self, int tabStop) { String s = self.toString(); int index; while ((index = s.indexOf('\t')) != -1) { StringBuilder builder = new StringBuilder(s); int count = tabStop - index % tabStop; builder.deleteCharAt(index); for (int i = 0; i < count; i++) builder.insert(index, " "); s = builder.toString(); } return s; }
java
public static String expandLine(CharSequence self, int tabStop) { String s = self.toString(); int index; while ((index = s.indexOf('\t')) != -1) { StringBuilder builder = new StringBuilder(s); int count = tabStop - index % tabStop; builder.deleteCharAt(index); for (int i = 0; i < count; i++) builder.insert(index, " "); s = builder.toString(); } return s; }
[ "public", "static", "String", "expandLine", "(", "CharSequence", "self", ",", "int", "tabStop", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "int", "index", ";", "while", "(", "(", "index", "=", "s", ".", "indexOf", "(", "'",...
Expands all tabs into spaces. Assumes the CharSequence represents a single line of text. @param self A line to expand @param tabStop The number of spaces a tab represents @return The expanded toString() of this CharSequence @see #expandLine(String, int) @since 1.8.2
[ "Expands", "all", "tabs", "into", "spaces", ".", "Assumes", "the", "CharSequence", "represents", "a", "single", "line", "of", "text", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L819-L830
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.find
public static String find(CharSequence self, CharSequence regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure closure) { return find(self.toString(), Pattern.compile(regex.toString()), closure); }
java
public static String find(CharSequence self, CharSequence regex, @ClosureParams(value=SimpleType.class, options="java.lang.String[]") Closure closure) { return find(self.toString(), Pattern.compile(regex.toString()), closure); }
[ "public", "static", "String", "find", "(", "CharSequence", "self", ",", "CharSequence", "regex", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"java.lang.String[]\"", ")", "Closure", "closure", ")", "{", "retu...
Returns the result of calling a closure with the first occurrence of a regular expression found within a CharSequence. If the regex doesn't match, the closure will not be called and find will return null. @param self a CharSequence @param regex the capturing regex CharSequence @param closure the closure that will be passed the full match, plus each of the capturing groups (if any) @return a String containing the result of calling the closure (calling toString() if needed), or null if the regex pattern doesn't match @see #find(String, java.util.regex.Pattern, groovy.lang.Closure) @since 1.8.2
[ "Returns", "the", "result", "of", "calling", "a", "closure", "with", "the", "first", "occurrence", "of", "a", "regular", "expression", "found", "within", "a", "CharSequence", ".", "If", "the", "regex", "doesn", "t", "match", "the", "closure", "will", "not", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L881-L883
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(CharSequence self, Collection indices) { StringBuilder answer = new StringBuilder(); for (Object value : indices) { if (value instanceof Range) { answer.append(getAt(self, (Range) value)); } else if (value instanceof Collection) { answer.append(getAt(self, (Collection) value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); answer.append(getAt(self, idx)); } } return answer.toString(); }
java
public static String getAt(CharSequence self, Collection indices) { StringBuilder answer = new StringBuilder(); for (Object value : indices) { if (value instanceof Range) { answer.append(getAt(self, (Range) value)); } else if (value instanceof Collection) { answer.append(getAt(self, (Collection) value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); answer.append(getAt(self, idx)); } } return answer.toString(); }
[ "public", "static", "String", "getAt", "(", "CharSequence", "self", ",", "Collection", "indices", ")", "{", "StringBuilder", "answer", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "Object", "value", ":", "indices", ")", "{", "if", "(", "value", ...
Select a List of characters from a CharSequence using a Collection to identify the indices to be selected. @param self a CharSequence @param indices a Collection of indices @return a String consisting of the characters at the given indices @since 1.0
[ "Select", "a", "List", "of", "characters", "from", "a", "CharSequence", "using", "a", "Collection", "to", "identify", "the", "indices", "to", "be", "selected", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1205-L1218
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static CharSequence getAt(CharSequence text, int index) { index = normaliseIndex(index, text.length()); return text.subSequence(index, index + 1); }
java
public static CharSequence getAt(CharSequence text, int index) { index = normaliseIndex(index, text.length()); return text.subSequence(index, index + 1); }
[ "public", "static", "CharSequence", "getAt", "(", "CharSequence", "text", ",", "int", "index", ")", "{", "index", "=", "normaliseIndex", "(", "index", ",", "text", ".", "length", "(", ")", ")", ";", "return", "text", ".", "subSequence", "(", "index", ","...
Support the subscript operator for CharSequence. @param text a CharSequence @param index the index of the Character to get @return the Character at the given index @since 1.0
[ "Support", "the", "subscript", "operator", "for", "CharSequence", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1240-L1243
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(GString text, int index) { return (String) getAt(text.toString(), index); }
java
public static String getAt(GString text, int index) { return (String) getAt(text.toString(), index); }
[ "public", "static", "String", "getAt", "(", "GString", "text", ",", "int", "index", ")", "{", "return", "(", "String", ")", "getAt", "(", "text", ".", "toString", "(", ")", ",", "index", ")", ";", "}" ]
Support the subscript operator for GString. @param text a GString @param index the index of the Character to get @return the Character at the given index @since 2.3.7
[ "Support", "the", "subscript", "operator", "for", "GString", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1253-L1255
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static CharSequence getAt(CharSequence text, IntRange range) { return getAt(text, (Range) range); }
java
public static CharSequence getAt(CharSequence text, IntRange range) { return getAt(text, (Range) range); }
[ "public", "static", "CharSequence", "getAt", "(", "CharSequence", "text", ",", "IntRange", "range", ")", "{", "return", "getAt", "(", "text", ",", "(", "Range", ")", "range", ")", ";", "}" ]
Support the range subscript operator for CharSequence with IntRange @param text a CharSequence @param range an IntRange @return the subsequence CharSequence @since 1.0
[ "Support", "the", "range", "subscript", "operator", "for", "CharSequence", "with", "IntRange" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1265-L1267
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static CharSequence getAt(CharSequence text, Range range) { RangeInfo info = subListBorders(text.length(), range); CharSequence sequence = text.subSequence(info.from, info.to); return info.reverse ? reverse(sequence) : sequence; }
java
public static CharSequence getAt(CharSequence text, Range range) { RangeInfo info = subListBorders(text.length(), range); CharSequence sequence = text.subSequence(info.from, info.to); return info.reverse ? reverse(sequence) : sequence; }
[ "public", "static", "CharSequence", "getAt", "(", "CharSequence", "text", ",", "Range", "range", ")", "{", "RangeInfo", "info", "=", "subListBorders", "(", "text", ".", "length", "(", ")", ",", "range", ")", ";", "CharSequence", "sequence", "=", "text", "....
Support the range subscript operator for CharSequence @param text a CharSequence @param range a Range @return the subsequence CharSequence @since 1.0
[ "Support", "the", "range", "subscript", "operator", "for", "CharSequence" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1289-L1293
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(GString text, Range range) { return getAt(text.toString(), range); }
java
public static String getAt(GString text, Range range) { return getAt(text.toString(), range); }
[ "public", "static", "String", "getAt", "(", "GString", "text", ",", "Range", "range", ")", "{", "return", "getAt", "(", "text", ".", "toString", "(", ")", ",", "range", ")", ";", "}" ]
Support the range subscript operator for GString @param text a GString @param range a Range @return the String of characters corresponding to the provided range @since 2.3.7
[ "Support", "the", "range", "subscript", "operator", "for", "GString" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1303-L1305
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static List getAt(Matcher self, Collection indices) { List result = new ArrayList(); for (Object value : indices) { if (value instanceof Range) { result.addAll(getAt(self, (Range) value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); result.add(getAt(self, idx)); } } return result; }
java
public static List getAt(Matcher self, Collection indices) { List result = new ArrayList(); for (Object value : indices) { if (value instanceof Range) { result.addAll(getAt(self, (Range) value)); } else { int idx = DefaultTypeTransformation.intUnbox(value); result.add(getAt(self, idx)); } } return result; }
[ "public", "static", "List", "getAt", "(", "Matcher", "self", ",", "Collection", "indices", ")", "{", "List", "result", "=", "new", "ArrayList", "(", ")", ";", "for", "(", "Object", "value", ":", "indices", ")", "{", "if", "(", "value", "instanceof", "R...
Select a List of values from a Matcher using a Collection to identify the indices to be selected. @param self a Matcher @param indices a Collection of indices @return a String of the values at the given indices @since 1.6.0
[ "Select", "a", "List", "of", "values", "from", "a", "Matcher", "using", "a", "Collection", "to", "identify", "the", "indices", "to", "be", "selected", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1316-L1327
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(String text, int index) { index = normaliseIndex(index, text.length()); return text.substring(index, index + 1); }
java
public static String getAt(String text, int index) { index = normaliseIndex(index, text.length()); return text.substring(index, index + 1); }
[ "public", "static", "String", "getAt", "(", "String", "text", ",", "int", "index", ")", "{", "index", "=", "normaliseIndex", "(", "index", ",", "text", ".", "length", "(", ")", ")", ";", "return", "text", ".", "substring", "(", "index", ",", "index", ...
Support the subscript operator for String. @param text a String @param index the index of the Character to get @return the Character at the given index @since 1.0
[ "Support", "the", "subscript", "operator", "for", "String", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1449-L1452
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(String text, IntRange range) { return getAt(text, (Range) range); }
java
public static String getAt(String text, IntRange range) { return getAt(text, (Range) range); }
[ "public", "static", "String", "getAt", "(", "String", "text", ",", "IntRange", "range", ")", "{", "return", "getAt", "(", "text", ",", "(", "Range", ")", "range", ")", ";", "}" ]
Support the range subscript operator for String with IntRange @param text a String @param range an IntRange @return the resulting String @since 1.0
[ "Support", "the", "range", "subscript", "operator", "for", "String", "with", "IntRange" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1462-L1464
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getAt
public static String getAt(String text, Range range) { RangeInfo info = subListBorders(text.length(), range); String answer = text.substring(info.from, info.to); if (info.reverse) { answer = reverse(answer); } return answer; }
java
public static String getAt(String text, Range range) { RangeInfo info = subListBorders(text.length(), range); String answer = text.substring(info.from, info.to); if (info.reverse) { answer = reverse(answer); } return answer; }
[ "public", "static", "String", "getAt", "(", "String", "text", ",", "Range", "range", ")", "{", "RangeInfo", "info", "=", "subListBorders", "(", "text", ".", "length", "(", ")", ",", "range", ")", ";", "String", "answer", "=", "text", ".", "substring", ...
Support the range subscript operator for String @param text a String @param range a Range @return a substring corresponding to the Range @since 1.0
[ "Support", "the", "range", "subscript", "operator", "for", "String" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1474-L1481
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.getCount
public static int getCount(Matcher matcher) { int counter = 0; matcher.reset(); while (matcher.find()) { counter++; } return counter; }
java
public static int getCount(Matcher matcher) { int counter = 0; matcher.reset(); while (matcher.find()) { counter++; } return counter; }
[ "public", "static", "int", "getCount", "(", "Matcher", "matcher", ")", "{", "int", "counter", "=", "0", ";", "matcher", ".", "reset", "(", ")", ";", "while", "(", "matcher", ".", "find", "(", ")", ")", "{", "counter", "++", ";", "}", "return", "cou...
Find the number of Strings matched to the given Matcher. @param matcher a Matcher @return int the number of Strings matched to the given matcher. @since 1.0
[ "Find", "the", "number", "of", "Strings", "matched", "to", "the", "given", "Matcher", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1511-L1518
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isAllWhitespace
public static boolean isAllWhitespace(CharSequence self) { String s = self.toString(); for (int i = 0; i < s.length(); i++) { if (!Character.isWhitespace(s.charAt(i))) return false; } return true; }
java
public static boolean isAllWhitespace(CharSequence self) { String s = self.toString(); for (int i = 0; i < s.length(); i++) { if (!Character.isWhitespace(s.charAt(i))) return false; } return true; }
[ "public", "static", "boolean", "isAllWhitespace", "(", "CharSequence", "self", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "s", ".", "length", "(", ")", ";", "i", "++", ")...
True if a CharSequence only contains whitespace characters. @param self The CharSequence to check the characters in @return true If all characters are whitespace characters @see #isAllWhitespace(String) @since 1.8.2
[ "True", "if", "a", "CharSequence", "only", "contains", "whitespace", "characters", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1578-L1585
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isBigDecimal
public static boolean isBigDecimal(CharSequence self) { try { new BigDecimal(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isBigDecimal(CharSequence self) { try { new BigDecimal(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isBigDecimal", "(", "CharSequence", "self", ")", "{", "try", "{", "new", "BigDecimal", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatExcepti...
Determine if a CharSequence can be parsed as a BigDecimal. @param self a CharSequence @return true if the CharSequence can be parsed @see #isBigDecimal(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "a", "BigDecimal", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1604-L1611
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isBigInteger
public static boolean isBigInteger(CharSequence self) { try { new BigInteger(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isBigInteger(CharSequence self) { try { new BigInteger(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isBigInteger", "(", "CharSequence", "self", ")", "{", "try", "{", "new", "BigInteger", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatExcepti...
Determine if a CharSequence can be parsed as a BigInteger. @param self a CharSequence @return true if the CharSequence can be parsed @see #isBigInteger(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "a", "BigInteger", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1630-L1637
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isDouble
public static boolean isDouble(CharSequence self) { try { Double.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isDouble(CharSequence self) { try { Double.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isDouble", "(", "CharSequence", "self", ")", "{", "try", "{", "Double", ".", "valueOf", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatExce...
Determine if a CharSequence can be parsed as a Double. @param self a CharSequence @return true if the CharSequence can be parsed @see #isDouble(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "a", "Double", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1730-L1737
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isFloat
public static boolean isFloat(CharSequence self) { try { Float.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isFloat(CharSequence self) { try { Float.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isFloat", "(", "CharSequence", "self", ")", "{", "try", "{", "Float", ".", "valueOf", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatExcept...
Determine if a CharSequence can be parsed as a Float. @param self a CharSequence @return true if the CharSequence can be parsed @see #isFloat(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "a", "Float", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1756-L1763
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isInteger
public static boolean isInteger(CharSequence self) { try { Integer.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isInteger(CharSequence self) { try { Integer.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isInteger", "(", "CharSequence", "self", ")", "{", "try", "{", "Integer", ".", "valueOf", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatEx...
Determine if a CharSequence can be parsed as an Integer. @param self a CharSequence @return true if the CharSequence can be parsed @see #isInteger(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "an", "Integer", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1782-L1789
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.isLong
public static boolean isLong(CharSequence self) { try { Long.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
java
public static boolean isLong(CharSequence self) { try { Long.valueOf(self.toString().trim()); return true; } catch (NumberFormatException nfe) { return false; } }
[ "public", "static", "boolean", "isLong", "(", "CharSequence", "self", ")", "{", "try", "{", "Long", ".", "valueOf", "(", "self", ".", "toString", "(", ")", ".", "trim", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "NumberFormatExceptio...
Determine if a CharSequence can be parsed as a Long. @param self a CharSequence @return true if the CharSequence can be parsed @see #isLong(String) @since 1.8.2
[ "Determine", "if", "a", "CharSequence", "can", "be", "parsed", "as", "a", "Long", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1808-L1815
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.leftShift
public static StringBuffer leftShift(String self, Object value) { return new StringBuffer(self).append(value); }
java
public static StringBuffer leftShift(String self, Object value) { return new StringBuffer(self).append(value); }
[ "public", "static", "StringBuffer", "leftShift", "(", "String", "self", ",", "Object", "value", ")", "{", "return", "new", "StringBuffer", "(", "self", ")", ".", "append", "(", "value", ")", ";", "}" ]
Overloads the left shift operator to provide an easy way to append multiple objects as string representations to a String. @param self a String @param value an Object @return a StringBuffer built from this string @since 1.0
[ "Overloads", "the", "left", "shift", "operator", "to", "provide", "an", "easy", "way", "to", "append", "multiple", "objects", "as", "string", "representations", "to", "a", "String", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1926-L1928
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.leftShift
public static StringBuilder leftShift(StringBuilder self, Object value) { self.append(value); return self; }
java
public static StringBuilder leftShift(StringBuilder self, Object value) { self.append(value); return self; }
[ "public", "static", "StringBuilder", "leftShift", "(", "StringBuilder", "self", ",", "Object", "value", ")", "{", "self", ".", "append", "(", "value", ")", ";", "return", "self", ";", "}" ]
Overloads the left shift operator to provide syntactic sugar for appending to a StringBuilder. @param self a StringBuilder @param value an Object @return the original StringBuilder @since 1.8.2
[ "Overloads", "the", "left", "shift", "operator", "to", "provide", "syntactic", "sugar", "for", "appending", "to", "a", "StringBuilder", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1952-L1955
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.minus
public static String minus(CharSequence self, Object target) { String s = self.toString(); String text = DefaultGroovyMethods.toString(target); int index = s.indexOf(text); if (index == -1) return s; int end = index + text.length(); if (s.length() > end) { return s.substring(0, index) + s.substring(end); } return s.substring(0, index); }
java
public static String minus(CharSequence self, Object target) { String s = self.toString(); String text = DefaultGroovyMethods.toString(target); int index = s.indexOf(text); if (index == -1) return s; int end = index + text.length(); if (s.length() > end) { return s.substring(0, index) + s.substring(end); } return s.substring(0, index); }
[ "public", "static", "String", "minus", "(", "CharSequence", "self", ",", "Object", "target", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "String", "text", "=", "DefaultGroovyMethods", ".", "toString", "(", "target", ")", ";", "i...
Remove a part of a CharSequence by replacing the first occurrence of target within self with '' and returns the result. @param self a CharSequence @param target an object representing the part to remove @return a String containing the original minus the part to be removed @see #minus(String, Object) @since 1.8.2
[ "Remove", "a", "part", "of", "a", "CharSequence", "by", "replacing", "the", "first", "occurrence", "of", "target", "within", "self", "with", "and", "returns", "the", "result", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L1990-L2000
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.minus
public static String minus(CharSequence self, Pattern pattern) { return pattern.matcher(self).replaceFirst(""); }
java
public static String minus(CharSequence self, Pattern pattern) { return pattern.matcher(self).replaceFirst(""); }
[ "public", "static", "String", "minus", "(", "CharSequence", "self", ",", "Pattern", "pattern", ")", "{", "return", "pattern", ".", "matcher", "(", "self", ")", ".", "replaceFirst", "(", "\"\"", ")", ";", "}" ]
Remove a part of a CharSequence. This replaces the first occurrence of the pattern within self with '' and returns the result. @param self a String @param pattern a Pattern representing the part to remove @return a String minus the part to be removed @since 2.2.0
[ "Remove", "a", "part", "of", "a", "CharSequence", ".", "This", "replaces", "the", "first", "occurrence", "of", "the", "pattern", "within", "self", "with", "and", "returns", "the", "result", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2011-L2013
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.multiply
public static String multiply(CharSequence self, Number factor) { String s = self.toString(); int size = factor.intValue(); if (size == 0) return ""; else if (size < 0) { throw new IllegalArgumentException("multiply() should be called with a number of 0 or greater not: " + size); } StringBuilder answer = new StringBuilder(s); for (int i = 1; i < size; i++) { answer.append(s); } return answer.toString(); }
java
public static String multiply(CharSequence self, Number factor) { String s = self.toString(); int size = factor.intValue(); if (size == 0) return ""; else if (size < 0) { throw new IllegalArgumentException("multiply() should be called with a number of 0 or greater not: " + size); } StringBuilder answer = new StringBuilder(s); for (int i = 1; i < size; i++) { answer.append(s); } return answer.toString(); }
[ "public", "static", "String", "multiply", "(", "CharSequence", "self", ",", "Number", "factor", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "int", "size", "=", "factor", ".", "intValue", "(", ")", ";", "if", "(", "size", "==...
Repeat a CharSequence a certain number of times. @param self a CharSequence to be repeated @param factor the number of times the CharSequence should be repeated @return a String composed of a repetition @throws IllegalArgumentException if the number of repetitions is &lt; 0 @since 1.8.2
[ "Repeat", "a", "CharSequence", "a", "certain", "number", "of", "times", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2042-L2055
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.next
public static String next(CharSequence self) { StringBuilder buffer = new StringBuilder(self); if (buffer.length() == 0) { buffer.append(Character.MIN_VALUE); } else { char last = buffer.charAt(buffer.length() - 1); if (last == Character.MAX_VALUE) { buffer.append(Character.MIN_VALUE); } else { char next = last; next++; buffer.setCharAt(buffer.length() - 1, next); } } return buffer.toString(); }
java
public static String next(CharSequence self) { StringBuilder buffer = new StringBuilder(self); if (buffer.length() == 0) { buffer.append(Character.MIN_VALUE); } else { char last = buffer.charAt(buffer.length() - 1); if (last == Character.MAX_VALUE) { buffer.append(Character.MIN_VALUE); } else { char next = last; next++; buffer.setCharAt(buffer.length() - 1, next); } } return buffer.toString(); }
[ "public", "static", "String", "next", "(", "CharSequence", "self", ")", "{", "StringBuilder", "buffer", "=", "new", "StringBuilder", "(", "self", ")", ";", "if", "(", "buffer", ".", "length", "(", ")", "==", "0", ")", "{", "buffer", ".", "append", "(",...
This method is called by the ++ operator for the class CharSequence. It increments the last character in the given CharSequence. If the last character in the CharSequence is Character.MAX_VALUE a Character.MIN_VALUE will be appended. The empty CharSequence is incremented to a string consisting of the character Character.MIN_VALUE. @param self a CharSequence @return a value obtained by incrementing the toString() of the CharSequence @since 1.8.2
[ "This", "method", "is", "called", "by", "the", "++", "operator", "for", "the", "class", "CharSequence", ".", "It", "increments", "the", "last", "character", "in", "the", "given", "CharSequence", ".", "If", "the", "last", "character", "in", "the", "CharSequen...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2077-L2092
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.normalize
public static String normalize(final CharSequence self) { final String s = self.toString(); int nx = s.indexOf('\r'); if (nx < 0) { return s; } final int len = s.length(); final StringBuilder sb = new StringBuilder(len); int i = 0; do { sb.append(s, i, nx); sb.append('\n'); if ((i = nx + 1) >= len) break; if (s.charAt(i) == '\n') { // skip the LF in CR LF if (++i >= len) break; } nx = s.indexOf('\r', i); } while (nx > 0); sb.append(s, i, len); return sb.toString(); }
java
public static String normalize(final CharSequence self) { final String s = self.toString(); int nx = s.indexOf('\r'); if (nx < 0) { return s; } final int len = s.length(); final StringBuilder sb = new StringBuilder(len); int i = 0; do { sb.append(s, i, nx); sb.append('\n'); if ((i = nx + 1) >= len) break; if (s.charAt(i) == '\n') { // skip the LF in CR LF if (++i >= len) break; } nx = s.indexOf('\r', i); } while (nx > 0); sb.append(s, i, len); return sb.toString(); }
[ "public", "static", "String", "normalize", "(", "final", "CharSequence", "self", ")", "{", "final", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "int", "nx", "=", "s", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "nx", "<", ...
Return a String with linefeeds and carriage returns normalized to linefeeds. @param self a CharSequence object @return the normalized toString() for the CharSequence @see #normalize(String) @since 1.8.2
[ "Return", "a", "String", "with", "linefeeds", "and", "carriage", "returns", "normalized", "to", "linefeeds", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2111-L2141
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.plus
public static String plus(CharSequence left, Object value) { return left + DefaultGroovyMethods.toString(value); }
java
public static String plus(CharSequence left, Object value) { return left + DefaultGroovyMethods.toString(value); }
[ "public", "static", "String", "plus", "(", "CharSequence", "left", ",", "Object", "value", ")", "{", "return", "left", "+", "DefaultGroovyMethods", ".", "toString", "(", "value", ")", ";", "}" ]
Appends the String representation of the given operand to this CharSequence. @param left a CharSequence @param value any Object @return the original toString() of the CharSequence with the object appended @since 1.8.2
[ "Appends", "the", "String", "representation", "of", "the", "given", "operand", "to", "this", "CharSequence", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2325-L2327
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.plus
public static String plus(Number value, String right) { return DefaultGroovyMethods.toString(value) + right; }
java
public static String plus(Number value, String right) { return DefaultGroovyMethods.toString(value) + right; }
[ "public", "static", "String", "plus", "(", "Number", "value", ",", "String", "right", ")", "{", "return", "DefaultGroovyMethods", ".", "toString", "(", "value", ")", "+", "right", ";", "}" ]
Appends a String to the string representation of this number. @param value a Number @param right a String @return a String @since 1.0
[ "Appends", "a", "String", "to", "the", "string", "representation", "of", "this", "number", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2337-L2339
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.readLines
public static List<String> readLines(CharSequence self) throws IOException { return IOGroovyMethods.readLines(new StringReader(self.toString())); }
java
public static List<String> readLines(CharSequence self) throws IOException { return IOGroovyMethods.readLines(new StringReader(self.toString())); }
[ "public", "static", "List", "<", "String", ">", "readLines", "(", "CharSequence", "self", ")", "throws", "IOException", "{", "return", "IOGroovyMethods", ".", "readLines", "(", "new", "StringReader", "(", "self", ".", "toString", "(", ")", ")", ")", ";", "...
Return the lines of a CharSequence as a List of String. @param self a CharSequence object @return a list of lines @throws java.io.IOException if an error occurs @since 1.8.2
[ "Return", "the", "lines", "of", "a", "CharSequence", "as", "a", "List", "of", "String", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2443-L2445
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.replaceAll
public static String replaceAll(final CharSequence self, final CharSequence regex, final CharSequence replacement) { return self.toString().replaceAll(regex.toString(), replacement.toString()); }
java
public static String replaceAll(final CharSequence self, final CharSequence regex, final CharSequence replacement) { return self.toString().replaceAll(regex.toString(), replacement.toString()); }
[ "public", "static", "String", "replaceAll", "(", "final", "CharSequence", "self", ",", "final", "CharSequence", "regex", ",", "final", "CharSequence", "replacement", ")", "{", "return", "self", ".", "toString", "(", ")", ".", "replaceAll", "(", "regex", ".", ...
Replaces each substring of this CharSequence that matches the given regular expression with the given replacement. @param self a CharSequence @param regex the capturing regex @param replacement the string to be substituted for each match @return the toString() of the CharSequence with content replaced @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid @see String#replaceAll(String, String) @since 1.8.2
[ "Replaces", "each", "substring", "of", "this", "CharSequence", "that", "matches", "the", "given", "regular", "expression", "with", "the", "given", "replacement", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2468-L2470
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.replaceFirst
public static String replaceFirst(final CharSequence self, final CharSequence regex, final CharSequence replacement) { return self.toString().replaceFirst(regex.toString(), replacement.toString()); }
java
public static String replaceFirst(final CharSequence self, final CharSequence regex, final CharSequence replacement) { return self.toString().replaceFirst(regex.toString(), replacement.toString()); }
[ "public", "static", "String", "replaceFirst", "(", "final", "CharSequence", "self", ",", "final", "CharSequence", "regex", ",", "final", "CharSequence", "replacement", ")", "{", "return", "self", ".", "toString", "(", ")", ".", "replaceFirst", "(", "regex", "....
Replaces the first substring of this CharSequence that matches the given regular expression with the given replacement. @param self a CharSequence @param regex the capturing regex @param replacement the CharSequence to be substituted for each match @return a CharSequence with replaced content @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid @see String#replaceFirst(String, String) @since 1.8.2
[ "Replaces", "the", "first", "substring", "of", "this", "CharSequence", "that", "matches", "the", "given", "regular", "expression", "with", "the", "given", "replacement", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2629-L2631
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.setIndex
public static void setIndex(Matcher matcher, int idx) { int count = getCount(matcher); if (idx < -count || idx >= count) { throw new IndexOutOfBoundsException("index is out of range " + (-count) + ".." + (count - 1) + " (index = " + idx + ")"); } if (idx == 0) { matcher.reset(); } else if (idx > 0) { matcher.reset(); for (int i = 0; i < idx; i++) { matcher.find(); } } else if (idx < 0) { matcher.reset(); idx += getCount(matcher); for (int i = 0; i < idx; i++) { matcher.find(); } } }
java
public static void setIndex(Matcher matcher, int idx) { int count = getCount(matcher); if (idx < -count || idx >= count) { throw new IndexOutOfBoundsException("index is out of range " + (-count) + ".." + (count - 1) + " (index = " + idx + ")"); } if (idx == 0) { matcher.reset(); } else if (idx > 0) { matcher.reset(); for (int i = 0; i < idx; i++) { matcher.find(); } } else if (idx < 0) { matcher.reset(); idx += getCount(matcher); for (int i = 0; i < idx; i++) { matcher.find(); } } }
[ "public", "static", "void", "setIndex", "(", "Matcher", "matcher", ",", "int", "idx", ")", "{", "int", "count", "=", "getCount", "(", "matcher", ")", ";", "if", "(", "idx", "<", "-", "count", "||", "idx", ">=", "count", ")", "{", "throw", "new", "I...
Set the position of the given Matcher to the given index. @param matcher a Matcher @param idx the index number @since 1.0
[ "Set", "the", "position", "of", "the", "given", "Matcher", "to", "the", "given", "index", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2770-L2789
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.splitEachLine
public static <T> T splitEachLine(CharSequence self, CharSequence regex, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { return splitEachLine(self, Pattern.compile(regex.toString()), closure); }
java
public static <T> T splitEachLine(CharSequence self, CharSequence regex, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { return splitEachLine(self, Pattern.compile(regex.toString()), closure); }
[ "public", "static", "<", "T", ">", "T", "splitEachLine", "(", "CharSequence", "self", ",", "CharSequence", "regex", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "\"List<String>\"", ")", "Closure", "<", "T", ...
Iterates through the given CharSequence line by line, splitting each line using the given regex delimiter. The list of tokens for each line is then passed to the given closure. @param self a CharSequence @param regex the delimiting regular expression @param closure a closure @return the last value returned by the closure @throws java.io.IOException if an error occurs @throws java.util.regex.PatternSyntaxException if the regular expression's syntax is invalid @see #splitEachLine(CharSequence, java.util.regex.Pattern, groovy.lang.Closure) @since 1.8.2
[ "Iterates", "through", "the", "given", "CharSequence", "line", "by", "line", "splitting", "each", "line", "using", "the", "given", "regex", "delimiter", ".", "The", "list", "of", "tokens", "for", "each", "line", "is", "then", "passed", "to", "the", "given", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2885-L2887
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.splitEachLine
public static <T> T splitEachLine(CharSequence self, Pattern pattern, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { final List<String> list = readLines(self); T result = null; for (String line : list) { List vals = Arrays.asList(pattern.split(line)); result = closure.call(vals); } return result; }
java
public static <T> T splitEachLine(CharSequence self, Pattern pattern, @ClosureParams(value=FromString.class,options="List<String>") Closure<T> closure) throws IOException { final List<String> list = readLines(self); T result = null; for (String line : list) { List vals = Arrays.asList(pattern.split(line)); result = closure.call(vals); } return result; }
[ "public", "static", "<", "T", ">", "T", "splitEachLine", "(", "CharSequence", "self", ",", "Pattern", "pattern", ",", "@", "ClosureParams", "(", "value", "=", "FromString", ".", "class", ",", "options", "=", "\"List<String>\"", ")", "Closure", "<", "T", ">...
Iterates through the given CharSequence line by line, splitting each line using the given separator Pattern. The list of tokens for each line is then passed to the given closure. @param self a CharSequence @param pattern the regular expression Pattern for the delimiter @param closure a closure @return the last value returned by the closure @throws java.io.IOException if an error occurs @since 1.8.2
[ "Iterates", "through", "the", "given", "CharSequence", "line", "by", "line", "splitting", "each", "line", "using", "the", "given", "separator", "Pattern", ".", "The", "list", "of", "tokens", "for", "each", "line", "is", "then", "passed", "to", "the", "given"...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L2901-L2909
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.takeWhile
public static String takeWhile(GString self, @ClosureParams(value=SimpleType.class, options="char") Closure condition) { return (String) takeWhile(self.toString(), condition); }
java
public static String takeWhile(GString self, @ClosureParams(value=SimpleType.class, options="char") Closure condition) { return (String) takeWhile(self.toString(), condition); }
[ "public", "static", "String", "takeWhile", "(", "GString", "self", ",", "@", "ClosureParams", "(", "value", "=", "SimpleType", ".", "class", ",", "options", "=", "\"char\"", ")", "Closure", "condition", ")", "{", "return", "(", "String", ")", "takeWhile", ...
A GString variant of the equivalent GString method. @param self the original GString @param condition the closure that must evaluate to true to continue taking elements @return a prefix of elements in the GString where each element passed to the given closure evaluates to true @since 2.3.7
[ "A", "GString", "variant", "of", "the", "equivalent", "GString", "method", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L3206-L3208
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.toList
public static List<String> toList(CharSequence self) { String s = self.toString(); int size = s.length(); List<String> answer = new ArrayList<String>(size); for (int i = 0; i < size; i++) { answer.add(s.substring(i, i + 1)); } return answer; }
java
public static List<String> toList(CharSequence self) { String s = self.toString(); int size = s.length(); List<String> answer = new ArrayList<String>(size); for (int i = 0; i < size; i++) { answer.add(s.substring(i, i + 1)); } return answer; }
[ "public", "static", "List", "<", "String", ">", "toList", "(", "CharSequence", "self", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "int", "size", "=", "s", ".", "length", "(", ")", ";", "List", "<", "String", ">", "answer"...
Converts the given CharSequence into a List of Strings of one character. @param self a CharSequence @return a List of characters (a 1-character String) @see #toSet(String) @since 1.8.2
[ "Converts", "the", "given", "CharSequence", "into", "a", "List", "of", "Strings", "of", "one", "character", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L3425-L3433
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.unexpand
public static String unexpand(CharSequence self, int tabStop) { String s = self.toString(); if (s.length() == 0) return s; try { StringBuilder builder = new StringBuilder(); for (String line : readLines((CharSequence) s)) { builder.append(unexpandLine(line, tabStop)); builder.append("\n"); } // remove the normalized ending line ending if it was not present if (!s.endsWith("\n")) { builder.deleteCharAt(builder.length() - 1); } return builder.toString(); } catch (IOException e) { /* ignore */ } return s; }
java
public static String unexpand(CharSequence self, int tabStop) { String s = self.toString(); if (s.length() == 0) return s; try { StringBuilder builder = new StringBuilder(); for (String line : readLines((CharSequence) s)) { builder.append(unexpandLine(line, tabStop)); builder.append("\n"); } // remove the normalized ending line ending if it was not present if (!s.endsWith("\n")) { builder.deleteCharAt(builder.length() - 1); } return builder.toString(); } catch (IOException e) { /* ignore */ } return s; }
[ "public", "static", "String", "unexpand", "(", "CharSequence", "self", ",", "int", "tabStop", ")", "{", "String", "s", "=", "self", ".", "toString", "(", ")", ";", "if", "(", "s", ".", "length", "(", ")", "==", "0", ")", "return", "s", ";", "try", ...
Replaces sequences of whitespaces with tabs. @param self A CharSequence to unexpand @param tabStop The number of spaces a tab represents @return an unexpanded String @since 1.8.2
[ "Replaces", "sequences", "of", "whitespaces", "with", "tabs", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L3580-L3598
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
StringGroovyMethods.unexpandLine
public static String unexpandLine(CharSequence self, int tabStop) { StringBuilder builder = new StringBuilder(self.toString()); int index = 0; while (index + tabStop < builder.length()) { // cut original string in tabstop-length pieces String piece = builder.substring(index, index + tabStop); // count trailing whitespace characters int count = 0; while ((count < tabStop) && (Character.isWhitespace(piece.charAt(tabStop - (count + 1))))) count++; // replace if whitespace was found if (count > 0) { piece = piece.substring(0, tabStop - count) + '\t'; builder.replace(index, index + tabStop, piece); index = index + tabStop - (count - 1); } else index = index + tabStop; } return builder.toString(); }
java
public static String unexpandLine(CharSequence self, int tabStop) { StringBuilder builder = new StringBuilder(self.toString()); int index = 0; while (index + tabStop < builder.length()) { // cut original string in tabstop-length pieces String piece = builder.substring(index, index + tabStop); // count trailing whitespace characters int count = 0; while ((count < tabStop) && (Character.isWhitespace(piece.charAt(tabStop - (count + 1))))) count++; // replace if whitespace was found if (count > 0) { piece = piece.substring(0, tabStop - count) + '\t'; builder.replace(index, index + tabStop, piece); index = index + tabStop - (count - 1); } else index = index + tabStop; } return builder.toString(); }
[ "public", "static", "String", "unexpandLine", "(", "CharSequence", "self", ",", "int", "tabStop", ")", "{", "StringBuilder", "builder", "=", "new", "StringBuilder", "(", "self", ".", "toString", "(", ")", ")", ";", "int", "index", "=", "0", ";", "while", ...
Replaces sequences of whitespaces with tabs within a line. @param self A line to unexpand @param tabStop The number of spaces a tab represents @return an unexpanded String @since 1.8.2
[ "Replaces", "sequences", "of", "whitespaces", "with", "tabs", "within", "a", "line", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java#L3626-L3645
train
groovy/groovy-core
src/main/org/codehaus/groovy/ast/ClassNode.java
ClassNode.hasPossibleMethod
public boolean hasPossibleMethod(String name, Expression arguments) { int count = 0; if (arguments instanceof TupleExpression) { TupleExpression tuple = (TupleExpression) arguments; // TODO this won't strictly be true when using list expansion in argument calls count = tuple.getExpressions().size(); } ClassNode node = this; do { for (MethodNode method : getMethods(name)) { if (method.getParameters().length == count && !method.isStatic()) { return true; } } node = node.getSuperClass(); } while (node != null); return false; }
java
public boolean hasPossibleMethod(String name, Expression arguments) { int count = 0; if (arguments instanceof TupleExpression) { TupleExpression tuple = (TupleExpression) arguments; // TODO this won't strictly be true when using list expansion in argument calls count = tuple.getExpressions().size(); } ClassNode node = this; do { for (MethodNode method : getMethods(name)) { if (method.getParameters().length == count && !method.isStatic()) { return true; } } node = node.getSuperClass(); } while (node != null); return false; }
[ "public", "boolean", "hasPossibleMethod", "(", "String", "name", ",", "Expression", "arguments", ")", "{", "int", "count", "=", "0", ";", "if", "(", "arguments", "instanceof", "TupleExpression", ")", "{", "TupleExpression", "tuple", "=", "(", "TupleExpression", ...
Returns true if the given method has a possibly matching instance method with the given name and arguments. @param name the name of the method of interest @param arguments the arguments to match against @return true if a matching method was found
[ "Returns", "true", "if", "the", "given", "method", "has", "a", "possibly", "matching", "instance", "method", "with", "the", "given", "name", "and", "arguments", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/ast/ClassNode.java#L1221-L1240
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
StaticTypeCheckingVisitor.checkOrMarkPrivateAccess
private void checkOrMarkPrivateAccess(Expression source, FieldNode fn) { if (fn!=null && Modifier.isPrivate(fn.getModifiers()) && (fn.getDeclaringClass() != typeCheckingContext.getEnclosingClassNode() || typeCheckingContext.getEnclosingClosure()!=null) && fn.getDeclaringClass().getModule() == typeCheckingContext.getEnclosingClassNode().getModule()) { addPrivateFieldOrMethodAccess(source, fn.getDeclaringClass(), StaticTypesMarker.PV_FIELDS_ACCESS, fn); } }
java
private void checkOrMarkPrivateAccess(Expression source, FieldNode fn) { if (fn!=null && Modifier.isPrivate(fn.getModifiers()) && (fn.getDeclaringClass() != typeCheckingContext.getEnclosingClassNode() || typeCheckingContext.getEnclosingClosure()!=null) && fn.getDeclaringClass().getModule() == typeCheckingContext.getEnclosingClassNode().getModule()) { addPrivateFieldOrMethodAccess(source, fn.getDeclaringClass(), StaticTypesMarker.PV_FIELDS_ACCESS, fn); } }
[ "private", "void", "checkOrMarkPrivateAccess", "(", "Expression", "source", ",", "FieldNode", "fn", ")", "{", "if", "(", "fn", "!=", "null", "&&", "Modifier", ".", "isPrivate", "(", "fn", ".", "getModifiers", "(", ")", ")", "&&", "(", "fn", ".", "getDecl...
Given a field node, checks if we are calling a private field from an inner class.
[ "Given", "a", "field", "node", "checks", "if", "we", "are", "calling", "a", "private", "field", "from", "an", "inner", "class", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L347-L353
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
StaticTypeCheckingVisitor.checkOrMarkPrivateAccess
private void checkOrMarkPrivateAccess(Expression source, MethodNode mn) { if (mn==null) { return; } ClassNode declaringClass = mn.getDeclaringClass(); ClassNode enclosingClassNode = typeCheckingContext.getEnclosingClassNode(); if (declaringClass != enclosingClassNode || typeCheckingContext.getEnclosingClosure() != null) { int mods = mn.getModifiers(); boolean sameModule = declaringClass.getModule() == enclosingClassNode.getModule(); String packageName = declaringClass.getPackageName(); if (packageName==null) { packageName = ""; } if ((Modifier.isPrivate(mods) && sameModule) || (Modifier.isProtected(mods) && !packageName.equals(enclosingClassNode.getPackageName()))) { addPrivateFieldOrMethodAccess(source, sameModule? declaringClass : enclosingClassNode, StaticTypesMarker.PV_METHODS_ACCESS, mn); } } }
java
private void checkOrMarkPrivateAccess(Expression source, MethodNode mn) { if (mn==null) { return; } ClassNode declaringClass = mn.getDeclaringClass(); ClassNode enclosingClassNode = typeCheckingContext.getEnclosingClassNode(); if (declaringClass != enclosingClassNode || typeCheckingContext.getEnclosingClosure() != null) { int mods = mn.getModifiers(); boolean sameModule = declaringClass.getModule() == enclosingClassNode.getModule(); String packageName = declaringClass.getPackageName(); if (packageName==null) { packageName = ""; } if ((Modifier.isPrivate(mods) && sameModule) || (Modifier.isProtected(mods) && !packageName.equals(enclosingClassNode.getPackageName()))) { addPrivateFieldOrMethodAccess(source, sameModule? declaringClass : enclosingClassNode, StaticTypesMarker.PV_METHODS_ACCESS, mn); } } }
[ "private", "void", "checkOrMarkPrivateAccess", "(", "Expression", "source", ",", "MethodNode", "mn", ")", "{", "if", "(", "mn", "==", "null", ")", "{", "return", ";", "}", "ClassNode", "declaringClass", "=", "mn", ".", "getDeclaringClass", "(", ")", ";", "...
Given a method node, checks if we are calling a private method from an inner class.
[ "Given", "a", "method", "node", "checks", "if", "we", "are", "calling", "a", "private", "method", "from", "an", "inner", "class", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L358-L376
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
StaticTypeCheckingVisitor.ensureValidSetter
private boolean ensureValidSetter(final Expression expression, final Expression leftExpression, final Expression rightExpression, final SetterInfo setterInfo) { // for expressions like foo = { ... } // we know that the RHS type is a closure // but we must check if the binary expression is an assignment // because we need to check if a setter uses @DelegatesTo VariableExpression ve = new VariableExpression("%", setterInfo.receiverType); MethodCallExpression call = new MethodCallExpression( ve, setterInfo.name, rightExpression ); call.setImplicitThis(false); visitMethodCallExpression(call); MethodNode directSetterCandidate = call.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (directSetterCandidate==null) { // this may happen if there's a setter of type boolean/String/Class, and that we are using the property // notation AND that the RHS is not a boolean/String/Class for (MethodNode setter : setterInfo.setters) { ClassNode type = getWrapper(setter.getParameters()[0].getOriginType()); if (Boolean_TYPE.equals(type) || STRING_TYPE.equals(type) || CLASS_Type.equals(type)) { call = new MethodCallExpression( ve, setterInfo.name, new CastExpression(type,rightExpression) ); call.setImplicitThis(false); visitMethodCallExpression(call); directSetterCandidate = call.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (directSetterCandidate!=null) { break; } } } } if (directSetterCandidate != null) { for (MethodNode setter : setterInfo.setters) { if (setter == directSetterCandidate) { leftExpression.putNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, directSetterCandidate); storeType(leftExpression, getType(rightExpression)); break; } } } else { ClassNode firstSetterType = setterInfo.setters.iterator().next().getParameters()[0].getOriginType(); addAssignmentError(firstSetterType, getType(rightExpression), expression); return true; } return false; }
java
private boolean ensureValidSetter(final Expression expression, final Expression leftExpression, final Expression rightExpression, final SetterInfo setterInfo) { // for expressions like foo = { ... } // we know that the RHS type is a closure // but we must check if the binary expression is an assignment // because we need to check if a setter uses @DelegatesTo VariableExpression ve = new VariableExpression("%", setterInfo.receiverType); MethodCallExpression call = new MethodCallExpression( ve, setterInfo.name, rightExpression ); call.setImplicitThis(false); visitMethodCallExpression(call); MethodNode directSetterCandidate = call.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (directSetterCandidate==null) { // this may happen if there's a setter of type boolean/String/Class, and that we are using the property // notation AND that the RHS is not a boolean/String/Class for (MethodNode setter : setterInfo.setters) { ClassNode type = getWrapper(setter.getParameters()[0].getOriginType()); if (Boolean_TYPE.equals(type) || STRING_TYPE.equals(type) || CLASS_Type.equals(type)) { call = new MethodCallExpression( ve, setterInfo.name, new CastExpression(type,rightExpression) ); call.setImplicitThis(false); visitMethodCallExpression(call); directSetterCandidate = call.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (directSetterCandidate!=null) { break; } } } } if (directSetterCandidate != null) { for (MethodNode setter : setterInfo.setters) { if (setter == directSetterCandidate) { leftExpression.putNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, directSetterCandidate); storeType(leftExpression, getType(rightExpression)); break; } } } else { ClassNode firstSetterType = setterInfo.setters.iterator().next().getParameters()[0].getOriginType(); addAssignmentError(firstSetterType, getType(rightExpression), expression); return true; } return false; }
[ "private", "boolean", "ensureValidSetter", "(", "final", "Expression", "expression", ",", "final", "Expression", "leftExpression", ",", "final", "Expression", "rightExpression", ",", "final", "SetterInfo", "setterInfo", ")", "{", "// for expressions like foo = { ... }", "...
Given a binary expression corresponding to an assignment, will check that the type of the RHS matches one of the possible setters and if not, throw a type checking error. @param expression the assignment expression @param leftExpression left expression of the assignment @param rightExpression right expression of the assignment @param setterInfo possible setters @return true if type checking passed
[ "Given", "a", "binary", "expression", "corresponding", "to", "an", "assignment", "will", "check", "that", "the", "type", "of", "the", "RHS", "matches", "one", "of", "the", "possible", "setters", "and", "if", "not", "throw", "a", "type", "checking", "error", ...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L704-L752
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
StaticTypeCheckingVisitor.addArrayMethods
private void addArrayMethods(List<MethodNode> methods, ClassNode receiver, String name, ClassNode[] args) { if (args.length!=1) return; if (!receiver.isArray()) return; if (!isIntCategory(getUnwrapper(args[0]))) return; if ("getAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, receiver.getComponentType(), new Parameter[]{new Parameter(args[0],"arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } else if ("setAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, VOID_TYPE, new Parameter[]{new Parameter(args[0],"arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } }
java
private void addArrayMethods(List<MethodNode> methods, ClassNode receiver, String name, ClassNode[] args) { if (args.length!=1) return; if (!receiver.isArray()) return; if (!isIntCategory(getUnwrapper(args[0]))) return; if ("getAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, receiver.getComponentType(), new Parameter[]{new Parameter(args[0],"arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } else if ("setAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, VOID_TYPE, new Parameter[]{new Parameter(args[0],"arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } }
[ "private", "void", "addArrayMethods", "(", "List", "<", "MethodNode", ">", "methods", ",", "ClassNode", "receiver", ",", "String", "name", ",", "ClassNode", "[", "]", "args", ")", "{", "if", "(", "args", ".", "length", "!=", "1", ")", "return", ";", "i...
add various getAt and setAt methods for primitive arrays @param receiver the receiver class @param name the name of the method @param args the argument classes
[ "add", "various", "getAt", "and", "setAt", "methods", "for", "primitive", "arrays" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L3011-L3024
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
StaticTypeCheckingVisitor.getGenericsResolvedTypeOfFieldOrProperty
private ClassNode getGenericsResolvedTypeOfFieldOrProperty(AnnotatedNode an, ClassNode type) { if (!type.isUsingGenerics()) return type; Map<String, GenericsType> connections = new HashMap(); //TODO: inner classes mean a different this-type. This is ignored here! extractGenericsConnections(connections, typeCheckingContext.getEnclosingClassNode(), an.getDeclaringClass()); type= applyGenericsContext(connections, type); return type; }
java
private ClassNode getGenericsResolvedTypeOfFieldOrProperty(AnnotatedNode an, ClassNode type) { if (!type.isUsingGenerics()) return type; Map<String, GenericsType> connections = new HashMap(); //TODO: inner classes mean a different this-type. This is ignored here! extractGenericsConnections(connections, typeCheckingContext.getEnclosingClassNode(), an.getDeclaringClass()); type= applyGenericsContext(connections, type); return type; }
[ "private", "ClassNode", "getGenericsResolvedTypeOfFieldOrProperty", "(", "AnnotatedNode", "an", ",", "ClassNode", "type", ")", "{", "if", "(", "!", "type", ".", "isUsingGenerics", "(", ")", ")", "return", "type", ";", "Map", "<", "String", ",", "GenericsType", ...
resolves a Field or Property node generics by using the current class and the declaring class to extract the right meaning of the generics symbols @param an a FieldNode or PropertyNode @param type the origin type @return the new ClassNode with corrected generics
[ "resolves", "a", "Field", "or", "Property", "node", "generics", "by", "using", "the", "current", "class", "and", "the", "declaring", "class", "to", "extract", "the", "right", "meaning", "of", "the", "generics", "symbols" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L4000-L4007
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
EncodingGroovyMethods.decodeBase64
public static byte[] decodeBase64(String value) { int byteShift = 4; int tmp = 0; boolean done = false; final StringBuilder buffer = new StringBuilder(); for (int i = 0; i != value.length(); i++) { final char c = value.charAt(i); final int sixBit = (c < 123) ? EncodingGroovyMethodsSupport.TRANSLATE_TABLE[c] : 66; if (sixBit < 64) { if (done) throw new RuntimeException("= character not at end of base64 value"); // TODO: change this exception type tmp = (tmp << 6) | sixBit; if (byteShift-- != 4) { buffer.append((char) ((tmp >> (byteShift * 2)) & 0XFF)); } } else if (sixBit == 64) { byteShift--; done = true; } else if (sixBit == 66) { // RFC 2045 says that I'm allowed to take the presence of // these characters as evidence of data corruption // So I will throw new RuntimeException("bad character in base64 value"); // TODO: change this exception type } if (byteShift == 0) byteShift = 4; } try { return buffer.toString().getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Base 64 decode produced byte values > 255"); // TODO: change this exception type } }
java
public static byte[] decodeBase64(String value) { int byteShift = 4; int tmp = 0; boolean done = false; final StringBuilder buffer = new StringBuilder(); for (int i = 0; i != value.length(); i++) { final char c = value.charAt(i); final int sixBit = (c < 123) ? EncodingGroovyMethodsSupport.TRANSLATE_TABLE[c] : 66; if (sixBit < 64) { if (done) throw new RuntimeException("= character not at end of base64 value"); // TODO: change this exception type tmp = (tmp << 6) | sixBit; if (byteShift-- != 4) { buffer.append((char) ((tmp >> (byteShift * 2)) & 0XFF)); } } else if (sixBit == 64) { byteShift--; done = true; } else if (sixBit == 66) { // RFC 2045 says that I'm allowed to take the presence of // these characters as evidence of data corruption // So I will throw new RuntimeException("bad character in base64 value"); // TODO: change this exception type } if (byteShift == 0) byteShift = 4; } try { return buffer.toString().getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Base 64 decode produced byte values > 255"); // TODO: change this exception type } }
[ "public", "static", "byte", "[", "]", "decodeBase64", "(", "String", "value", ")", "{", "int", "byteShift", "=", "4", ";", "int", "tmp", "=", "0", ";", "boolean", "done", "=", "false", ";", "final", "StringBuilder", "buffer", "=", "new", "StringBuilder",...
Decode the String from Base64 into a byte array. @param value the string to be decoded @return the decoded bytes as an array @since 1.0
[ "Decode", "the", "String", "from", "Base64", "into", "a", "byte", "array", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/EncodingGroovyMethods.java#L151-L191
train
groovy/groovy-core
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
Groovy.runStatements
protected void runStatements(Reader reader, PrintStream out) throws IOException { log.debug("runStatements()"); StringBuilder txt = new StringBuilder(); String line = ""; BufferedReader in = new BufferedReader(reader); while ((line = in.readLine()) != null) { line = getProject().replaceProperties(line); if (line.indexOf("--") >= 0) { txt.append("\n"); } } // Catch any statements not followed by ; if (!txt.toString().equals("")) { execGroovy(txt.toString(), out); } }
java
protected void runStatements(Reader reader, PrintStream out) throws IOException { log.debug("runStatements()"); StringBuilder txt = new StringBuilder(); String line = ""; BufferedReader in = new BufferedReader(reader); while ((line = in.readLine()) != null) { line = getProject().replaceProperties(line); if (line.indexOf("--") >= 0) { txt.append("\n"); } } // Catch any statements not followed by ; if (!txt.toString().equals("")) { execGroovy(txt.toString(), out); } }
[ "protected", "void", "runStatements", "(", "Reader", "reader", ",", "PrintStream", "out", ")", "throws", "IOException", "{", "log", ".", "debug", "(", "\"runStatements()\"", ")", ";", "StringBuilder", "txt", "=", "new", "StringBuilder", "(", ")", ";", "String"...
Read in lines and execute them. @param reader the reader from which to get the groovy source to exec @param out the outputstream to use @throws java.io.IOException if something goes wrong
[ "Read", "in", "lines", "and", "execute", "them", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java#L354-L371
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java
JsonOutput.toJson
public static String toJson(Date date) { if (date == null) { return NULL_VALUE; } CharBuf buffer = CharBuf.create(26); writeDate(date, buffer); return buffer.toString(); }
java
public static String toJson(Date date) { if (date == null) { return NULL_VALUE; } CharBuf buffer = CharBuf.create(26); writeDate(date, buffer); return buffer.toString(); }
[ "public", "static", "String", "toJson", "(", "Date", "date", ")", "{", "if", "(", "date", "==", "null", ")", "{", "return", "NULL_VALUE", ";", "}", "CharBuf", "buffer", "=", "CharBuf", ".", "create", "(", "26", ")", ";", "writeDate", "(", "date", ","...
Format a date that is parseable from JavaScript, according to ISO-8601. @param date the date to format to a JSON string @return a formatted date in the form of a string
[ "Format", "a", "date", "that", "is", "parseable", "from", "JavaScript", "according", "to", "ISO", "-", "8601", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L105-L114
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java
JsonOutput.toJson
public static String toJson(Calendar cal) { if (cal == null) { return NULL_VALUE; } CharBuf buffer = CharBuf.create(26); writeDate(cal.getTime(), buffer); return buffer.toString(); }
java
public static String toJson(Calendar cal) { if (cal == null) { return NULL_VALUE; } CharBuf buffer = CharBuf.create(26); writeDate(cal.getTime(), buffer); return buffer.toString(); }
[ "public", "static", "String", "toJson", "(", "Calendar", "cal", ")", "{", "if", "(", "cal", "==", "null", ")", "{", "return", "NULL_VALUE", ";", "}", "CharBuf", "buffer", "=", "CharBuf", ".", "create", "(", "26", ")", ";", "writeDate", "(", "cal", "....
Format a calendar instance that is parseable from JavaScript, according to ISO-8601. @param cal the calendar to format to a JSON string @return a formatted date in the form of a string
[ "Format", "a", "calendar", "instance", "that", "is", "parseable", "from", "JavaScript", "according", "to", "ISO", "-", "8601", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L122-L131
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java
JsonOutput.writeNumber
private static void writeNumber(Class<?> numberClass, Number value, CharBuf buffer) { if (numberClass == Integer.class) { buffer.addInt((Integer) value); } else if (numberClass == Long.class) { buffer.addLong((Long) value); } else if (numberClass == BigInteger.class) { buffer.addBigInteger((BigInteger) value); } else if (numberClass == BigDecimal.class) { buffer.addBigDecimal((BigDecimal) value); } else if (numberClass == Double.class) { Double doubleValue = (Double) value; if (doubleValue.isInfinite()) { throw new JsonException("Number " + value + " can't be serialized as JSON: infinite are not allowed in JSON."); } if (doubleValue.isNaN()) { throw new JsonException("Number " + value + " can't be serialized as JSON: NaN are not allowed in JSON."); } buffer.addDouble(doubleValue); } else if (numberClass == Float.class) { Float floatValue = (Float) value; if (floatValue.isInfinite()) { throw new JsonException("Number " + value + " can't be serialized as JSON: infinite are not allowed in JSON."); } if (floatValue.isNaN()) { throw new JsonException("Number " + value + " can't be serialized as JSON: NaN are not allowed in JSON."); } buffer.addFloat(floatValue); } else if (numberClass == Byte.class) { buffer.addByte((Byte) value); } else if (numberClass == Short.class) { buffer.addShort((Short) value); } else { // Handle other Number implementations buffer.addString(value.toString()); } }
java
private static void writeNumber(Class<?> numberClass, Number value, CharBuf buffer) { if (numberClass == Integer.class) { buffer.addInt((Integer) value); } else if (numberClass == Long.class) { buffer.addLong((Long) value); } else if (numberClass == BigInteger.class) { buffer.addBigInteger((BigInteger) value); } else if (numberClass == BigDecimal.class) { buffer.addBigDecimal((BigDecimal) value); } else if (numberClass == Double.class) { Double doubleValue = (Double) value; if (doubleValue.isInfinite()) { throw new JsonException("Number " + value + " can't be serialized as JSON: infinite are not allowed in JSON."); } if (doubleValue.isNaN()) { throw new JsonException("Number " + value + " can't be serialized as JSON: NaN are not allowed in JSON."); } buffer.addDouble(doubleValue); } else if (numberClass == Float.class) { Float floatValue = (Float) value; if (floatValue.isInfinite()) { throw new JsonException("Number " + value + " can't be serialized as JSON: infinite are not allowed in JSON."); } if (floatValue.isNaN()) { throw new JsonException("Number " + value + " can't be serialized as JSON: NaN are not allowed in JSON."); } buffer.addFloat(floatValue); } else if (numberClass == Byte.class) { buffer.addByte((Byte) value); } else if (numberClass == Short.class) { buffer.addShort((Short) value); } else { // Handle other Number implementations buffer.addString(value.toString()); } }
[ "private", "static", "void", "writeNumber", "(", "Class", "<", "?", ">", "numberClass", ",", "Number", "value", ",", "CharBuf", "buffer", ")", "{", "if", "(", "numberClass", "==", "Integer", ".", "class", ")", "{", "buffer", ".", "addInt", "(", "(", "I...
Serializes Number value and writes it into specified buffer.
[ "Serializes", "Number", "value", "and", "writes", "it", "into", "specified", "buffer", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L209-L245
train
groovy/groovy-core
subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java
JsonOutput.writeCharSequence
private static void writeCharSequence(CharSequence seq, CharBuf buffer) { if (seq.length() > 0) { buffer.addJsonEscapedString(seq.toString()); } else { buffer.addChars(EMPTY_STRING_CHARS); } }
java
private static void writeCharSequence(CharSequence seq, CharBuf buffer) { if (seq.length() > 0) { buffer.addJsonEscapedString(seq.toString()); } else { buffer.addChars(EMPTY_STRING_CHARS); } }
[ "private", "static", "void", "writeCharSequence", "(", "CharSequence", "seq", ",", "CharBuf", "buffer", ")", "{", "if", "(", "seq", ".", "length", "(", ")", ">", "0", ")", "{", "buffer", ".", "addJsonEscapedString", "(", "seq", ".", "toString", "(", ")",...
Serializes any char sequence and writes it into specified buffer.
[ "Serializes", "any", "char", "sequence", "and", "writes", "it", "into", "specified", "buffer", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-json/src/main/java/groovy/json/JsonOutput.java#L304-L310
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java
ShortTypeHandling.castToEnum
public static Enum castToEnum(Object object, Class<? extends Enum> type) { if (object==null) return null; if (type.isInstance(object)) return (Enum) object; if (object instanceof String || object instanceof GString) { return Enum.valueOf(type, object.toString()); } throw new GroovyCastException(object, type); }
java
public static Enum castToEnum(Object object, Class<? extends Enum> type) { if (object==null) return null; if (type.isInstance(object)) return (Enum) object; if (object instanceof String || object instanceof GString) { return Enum.valueOf(type, object.toString()); } throw new GroovyCastException(object, type); }
[ "public", "static", "Enum", "castToEnum", "(", "Object", "object", ",", "Class", "<", "?", "extends", "Enum", ">", "type", ")", "{", "if", "(", "object", "==", "null", ")", "return", "null", ";", "if", "(", "type", ".", "isInstance", "(", "object", "...
this class requires that the supplied enum is not fitting a Collection case for casting
[ "this", "class", "requires", "that", "the", "supplied", "enum", "is", "not", "fitting", "a", "Collection", "case", "for", "casting" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/typehandling/ShortTypeHandling.java#L52-L59
train
groovy/groovy-core
subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
Groovyc.setTargetBytecode
public void setTargetBytecode(String version) { if (CompilerConfiguration.PRE_JDK5.equals(version) || CompilerConfiguration.POST_JDK5.equals(version)) { this.targetBytecode = version; } }
java
public void setTargetBytecode(String version) { if (CompilerConfiguration.PRE_JDK5.equals(version) || CompilerConfiguration.POST_JDK5.equals(version)) { this.targetBytecode = version; } }
[ "public", "void", "setTargetBytecode", "(", "String", "version", ")", "{", "if", "(", "CompilerConfiguration", ".", "PRE_JDK5", ".", "equals", "(", "version", ")", "||", "CompilerConfiguration", ".", "POST_JDK5", ".", "equals", "(", "version", ")", ")", "{", ...
Sets the bytecode compatibility mode @param version the bytecode compatibility mode
[ "Sets", "the", "bytecode", "compatibility", "mode" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java#L292-L296
train
groovy/groovy-core
src/main/groovy/util/Node.java
Node.depthFirst
public List depthFirst() { List answer = new NodeList(); answer.add(this); answer.addAll(depthFirstRest()); return answer; }
java
public List depthFirst() { List answer = new NodeList(); answer.add(this); answer.addAll(depthFirstRest()); return answer; }
[ "public", "List", "depthFirst", "(", ")", "{", "List", "answer", "=", "new", "NodeList", "(", ")", ";", "answer", ".", "add", "(", "this", ")", ";", "answer", ".", "addAll", "(", "depthFirstRest", "(", ")", ")", ";", "return", "answer", ";", "}" ]
Provides a collection of all the nodes in the tree using a depth first traversal. @return the list of (depth-first) ordered nodes
[ "Provides", "a", "collection", "of", "all", "the", "nodes", "in", "the", "tree", "using", "a", "depth", "first", "traversal", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/util/Node.java#L544-L549
train
groovy/groovy-core
src/main/groovy/lang/MetaProperty.java
MetaProperty.getGetterName
public static String getGetterName(String propertyName, Class type) { String prefix = type == boolean.class || type == Boolean.class ? "is" : "get"; return prefix + MetaClassHelper.capitalize(propertyName); }
java
public static String getGetterName(String propertyName, Class type) { String prefix = type == boolean.class || type == Boolean.class ? "is" : "get"; return prefix + MetaClassHelper.capitalize(propertyName); }
[ "public", "static", "String", "getGetterName", "(", "String", "propertyName", ",", "Class", "type", ")", "{", "String", "prefix", "=", "type", "==", "boolean", ".", "class", "||", "type", "==", "Boolean", ".", "class", "?", "\"is\"", ":", "\"get\"", ";", ...
Gets the name for the getter for this property @return The name of the property. The name is "get"+ the capitalized propertyName or, in the case of boolean values, "is" + the capitalized propertyName
[ "Gets", "the", "name", "for", "the", "getter", "for", "this", "property" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/MetaProperty.java#L90-L93
train
groovy/groovy-core
src/main/groovy/lang/ProxyMetaClass.java
ProxyMetaClass.getInstance
public static ProxyMetaClass getInstance(Class theClass) throws IntrospectionException { MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry(); MetaClass meta = metaRegistry.getMetaClass(theClass); return new ProxyMetaClass(metaRegistry, theClass, meta); }
java
public static ProxyMetaClass getInstance(Class theClass) throws IntrospectionException { MetaClassRegistry metaRegistry = GroovySystem.getMetaClassRegistry(); MetaClass meta = metaRegistry.getMetaClass(theClass); return new ProxyMetaClass(metaRegistry, theClass, meta); }
[ "public", "static", "ProxyMetaClass", "getInstance", "(", "Class", "theClass", ")", "throws", "IntrospectionException", "{", "MetaClassRegistry", "metaRegistry", "=", "GroovySystem", ".", "getMetaClassRegistry", "(", ")", ";", "MetaClass", "meta", "=", "metaRegistry", ...
convenience factory method for the most usual case.
[ "convenience", "factory", "method", "for", "the", "most", "usual", "case", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/lang/ProxyMetaClass.java#L47-L51
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/ResolveVisitor.java
ResolveVisitor.correctClassClassChain
private Expression correctClassClassChain(PropertyExpression pe) { LinkedList<Expression> stack = new LinkedList<Expression>(); ClassExpression found = null; for (Expression it = pe; it != null; it = ((PropertyExpression) it).getObjectExpression()) { if (it instanceof ClassExpression) { found = (ClassExpression) it; break; } else if (!(it.getClass() == PropertyExpression.class)) { return pe; } stack.addFirst(it); } if (found == null) return pe; if (stack.isEmpty()) return pe; Object stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpression = (PropertyExpression) stackElement; String propertyNamePart = classPropertyExpression.getPropertyAsString(); if (propertyNamePart == null || !propertyNamePart.equals("class")) return pe; found.setSourcePosition(classPropertyExpression); if (stack.isEmpty()) return found; stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpressionContainer = (PropertyExpression) stackElement; classPropertyExpressionContainer.setObjectExpression(found); return pe; }
java
private Expression correctClassClassChain(PropertyExpression pe) { LinkedList<Expression> stack = new LinkedList<Expression>(); ClassExpression found = null; for (Expression it = pe; it != null; it = ((PropertyExpression) it).getObjectExpression()) { if (it instanceof ClassExpression) { found = (ClassExpression) it; break; } else if (!(it.getClass() == PropertyExpression.class)) { return pe; } stack.addFirst(it); } if (found == null) return pe; if (stack.isEmpty()) return pe; Object stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpression = (PropertyExpression) stackElement; String propertyNamePart = classPropertyExpression.getPropertyAsString(); if (propertyNamePart == null || !propertyNamePart.equals("class")) return pe; found.setSourcePosition(classPropertyExpression); if (stack.isEmpty()) return found; stackElement = stack.removeFirst(); if (!(stackElement.getClass() == PropertyExpression.class)) return pe; PropertyExpression classPropertyExpressionContainer = (PropertyExpression) stackElement; classPropertyExpressionContainer.setObjectExpression(found); return pe; }
[ "private", "Expression", "correctClassClassChain", "(", "PropertyExpression", "pe", ")", "{", "LinkedList", "<", "Expression", ">", "stack", "=", "new", "LinkedList", "<", "Expression", ">", "(", ")", ";", "ClassExpression", "found", "=", "null", ";", "for", "...
and class as property
[ "and", "class", "as", "property" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/ResolveVisitor.java#L781-L810
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java
DefaultGroovyMethodsSupport.closeWithWarning
public static void closeWithWarning(Closeable c) { if (c != null) { try { c.close(); } catch (IOException e) { LOG.warning("Caught exception during close(): " + e); } } }
java
public static void closeWithWarning(Closeable c) { if (c != null) { try { c.close(); } catch (IOException e) { LOG.warning("Caught exception during close(): " + e); } } }
[ "public", "static", "void", "closeWithWarning", "(", "Closeable", "c", ")", "{", "if", "(", "c", "!=", "null", ")", "{", "try", "{", "c", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "LOG", ".", "warning", "(", "\...
Close the Closeable. Logging a warning if any problems occur. @param c the thing to close
[ "Close", "the", "Closeable", ".", "Logging", "a", "warning", "if", "any", "problems", "occur", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethodsSupport.java#L88-L96
train
groovy/groovy-core
src/main/org/codehaus/groovy/util/ManagedConcurrentValueMap.java
ManagedConcurrentValueMap.get
public V get(K key) { ManagedReference<V> ref = internalMap.get(key); if (ref!=null) return ref.get(); return null; }
java
public V get(K key) { ManagedReference<V> ref = internalMap.get(key); if (ref!=null) return ref.get(); return null; }
[ "public", "V", "get", "(", "K", "key", ")", "{", "ManagedReference", "<", "V", ">", "ref", "=", "internalMap", ".", "get", "(", "key", ")", ";", "if", "(", "ref", "!=", "null", ")", "return", "ref", ".", "get", "(", ")", ";", "return", "null", ...
Returns the value stored for the given key at the point of call. @param key a non null key @return the value stored in the map for the given key
[ "Returns", "the", "value", "stored", "for", "the", "given", "key", "at", "the", "point", "of", "call", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedConcurrentValueMap.java#L55-L59
train
groovy/groovy-core
src/main/org/codehaus/groovy/util/ManagedConcurrentValueMap.java
ManagedConcurrentValueMap.put
public void put(final K key, V value) { ManagedReference<V> ref = new ManagedReference<V>(bundle, value) { @Override public void finalizeReference() { super.finalizeReference(); internalMap.remove(key, get()); } }; internalMap.put(key, ref); }
java
public void put(final K key, V value) { ManagedReference<V> ref = new ManagedReference<V>(bundle, value) { @Override public void finalizeReference() { super.finalizeReference(); internalMap.remove(key, get()); } }; internalMap.put(key, ref); }
[ "public", "void", "put", "(", "final", "K", "key", ",", "V", "value", ")", "{", "ManagedReference", "<", "V", ">", "ref", "=", "new", "ManagedReference", "<", "V", ">", "(", "bundle", ",", "value", ")", "{", "@", "Override", "public", "void", "finali...
Sets a new value for a given key. an older value is overwritten. @param key a non null key @param value the new value
[ "Sets", "a", "new", "value", "for", "a", "given", "key", ".", "an", "older", "value", "is", "overwritten", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/util/ManagedConcurrentValueMap.java#L66-L75
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/SourceUnit.java
SourceUnit.getSample
public String getSample(int line, int column, Janitor janitor) { String sample = null; String text = source.getLine(line, janitor); if (text != null) { if (column > 0) { String marker = Utilities.repeatString(" ", column - 1) + "^"; if (column > 40) { int start = column - 30 - 1; int end = (column + 10 > text.length() ? text.length() : column + 10 - 1); sample = " " + text.substring(start, end) + Utilities.eol() + " " + marker.substring(start, marker.length()); } else { sample = " " + text + Utilities.eol() + " " + marker; } } else { sample = text; } } return sample; }
java
public String getSample(int line, int column, Janitor janitor) { String sample = null; String text = source.getLine(line, janitor); if (text != null) { if (column > 0) { String marker = Utilities.repeatString(" ", column - 1) + "^"; if (column > 40) { int start = column - 30 - 1; int end = (column + 10 > text.length() ? text.length() : column + 10 - 1); sample = " " + text.substring(start, end) + Utilities.eol() + " " + marker.substring(start, marker.length()); } else { sample = " " + text + Utilities.eol() + " " + marker; } } else { sample = text; } } return sample; }
[ "public", "String", "getSample", "(", "int", "line", ",", "int", "column", ",", "Janitor", "janitor", ")", "{", "String", "sample", "=", "null", ";", "String", "text", "=", "source", ".", "getLine", "(", "line", ",", "janitor", ")", ";", "if", "(", "...
Returns a sampling of the source at the specified line and column, of null if it is unavailable.
[ "Returns", "a", "sampling", "of", "the", "source", "at", "the", "specified", "line", "and", "column", "of", "null", "if", "it", "is", "unavailable", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/SourceUnit.java#L313-L335
train
groovy/groovy-core
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
Sql.withInstance
public static void withInstance(String url, Closure c) throws SQLException { Sql sql = null; try { sql = newInstance(url); c.call(sql); } finally { if (sql != null) sql.close(); } }
java
public static void withInstance(String url, Closure c) throws SQLException { Sql sql = null; try { sql = newInstance(url); c.call(sql); } finally { if (sql != null) sql.close(); } }
[ "public", "static", "void", "withInstance", "(", "String", "url", ",", "Closure", "c", ")", "throws", "SQLException", "{", "Sql", "sql", "=", "null", ";", "try", "{", "sql", "=", "newInstance", "(", "url", ")", ";", "c", ".", "call", "(", "sql", ")",...
Invokes a closure passing it a new Sql instance created from the given JDBC connection URL. The created connection will be closed if required. @param url a database url of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code> @param c the Closure to call @see #newInstance(String) @throws SQLException if a database access error occurs
[ "Invokes", "a", "closure", "passing", "it", "a", "new", "Sql", "instance", "created", "from", "the", "given", "JDBC", "connection", "URL", ".", "The", "created", "connection", "will", "be", "closed", "if", "required", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L293-L301
train
groovy/groovy-core
subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java
Sql.withTransaction
public synchronized void withTransaction(Closure closure) throws SQLException { boolean savedCacheConnection = cacheConnection; cacheConnection = true; Connection connection = null; boolean savedAutoCommit = true; try { connection = createConnection(); savedAutoCommit = connection.getAutoCommit(); connection.setAutoCommit(false); callClosurePossiblyWithConnection(closure, connection); connection.commit(); } catch (SQLException e) { handleError(connection, e); throw e; } catch (RuntimeException e) { handleError(connection, e); throw e; } catch (Error e) { handleError(connection, e); throw e; } catch (Exception e) { handleError(connection, e); throw new SQLException("Unexpected exception during transaction", e); } finally { if (connection != null) { try { connection.setAutoCommit(savedAutoCommit); } catch (SQLException e) { LOG.finest("Caught exception resetting auto commit: " + e.getMessage() + " - continuing"); } } cacheConnection = false; closeResources(connection, null); cacheConnection = savedCacheConnection; if (dataSource != null && !cacheConnection) { useConnection = null; } } }
java
public synchronized void withTransaction(Closure closure) throws SQLException { boolean savedCacheConnection = cacheConnection; cacheConnection = true; Connection connection = null; boolean savedAutoCommit = true; try { connection = createConnection(); savedAutoCommit = connection.getAutoCommit(); connection.setAutoCommit(false); callClosurePossiblyWithConnection(closure, connection); connection.commit(); } catch (SQLException e) { handleError(connection, e); throw e; } catch (RuntimeException e) { handleError(connection, e); throw e; } catch (Error e) { handleError(connection, e); throw e; } catch (Exception e) { handleError(connection, e); throw new SQLException("Unexpected exception during transaction", e); } finally { if (connection != null) { try { connection.setAutoCommit(savedAutoCommit); } catch (SQLException e) { LOG.finest("Caught exception resetting auto commit: " + e.getMessage() + " - continuing"); } } cacheConnection = false; closeResources(connection, null); cacheConnection = savedCacheConnection; if (dataSource != null && !cacheConnection) { useConnection = null; } } }
[ "public", "synchronized", "void", "withTransaction", "(", "Closure", "closure", ")", "throws", "SQLException", "{", "boolean", "savedCacheConnection", "=", "cacheConnection", ";", "cacheConnection", "=", "true", ";", "Connection", "connection", "=", "null", ";", "bo...
Performs the closure within a transaction using a cached connection. If the closure takes a single argument, it will be called with the connection, otherwise it will be called with no arguments. @param closure the given closure @throws SQLException if a database error occurs
[ "Performs", "the", "closure", "within", "a", "transaction", "using", "a", "cached", "connection", ".", "If", "the", "closure", "takes", "a", "single", "argument", "it", "will", "be", "called", "with", "the", "connection", "otherwise", "it", "will", "be", "ca...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java#L3515-L3554
train
groovy/groovy-core
src/main/org/codehaus/groovy/runtime/ReflectionMethodInvoker.java
ReflectionMethodInvoker.invoke
public static Object invoke(Object object, String methodName, Object[] parameters) { try { Class[] classTypes = new Class[parameters.length]; for (int i = 0; i < classTypes.length; i++) { classTypes[i] = parameters[i].getClass(); } Method method = object.getClass().getMethod(methodName, classTypes); return method.invoke(object, parameters); } catch (Throwable t) { return InvokerHelper.invokeMethod(object, methodName, parameters); } }
java
public static Object invoke(Object object, String methodName, Object[] parameters) { try { Class[] classTypes = new Class[parameters.length]; for (int i = 0; i < classTypes.length; i++) { classTypes[i] = parameters[i].getClass(); } Method method = object.getClass().getMethod(methodName, classTypes); return method.invoke(object, parameters); } catch (Throwable t) { return InvokerHelper.invokeMethod(object, methodName, parameters); } }
[ "public", "static", "Object", "invoke", "(", "Object", "object", ",", "String", "methodName", ",", "Object", "[", "]", "parameters", ")", "{", "try", "{", "Class", "[", "]", "classTypes", "=", "new", "Class", "[", "parameters", ".", "length", "]", ";", ...
Invoke a method through reflection. Falls through to using the Invoker to call the method in case the reflection call fails.. @param object the object on which to invoke a method @param methodName the name of the method to invoke @param parameters the parameters of the method call @return the result of the method call
[ "Invoke", "a", "method", "through", "reflection", ".", "Falls", "through", "to", "using", "the", "Invoker", "to", "call", "the", "method", "in", "case", "the", "reflection", "call", "fails", ".." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/runtime/ReflectionMethodInvoker.java#L43-L54
train
groovy/groovy-core
src/main/org/codehaus/groovy/tools/StringHelper.java
StringHelper.tokenizeUnquoted
public static String[] tokenizeUnquoted(String s) { List tokens = new LinkedList(); int first = 0; while (first < s.length()) { first = skipWhitespace(s, first); int last = scanToken(s, first); if (first < last) { tokens.add(s.substring(first, last)); } first = last; } return (String[])tokens.toArray(new String[tokens.size()]); }
java
public static String[] tokenizeUnquoted(String s) { List tokens = new LinkedList(); int first = 0; while (first < s.length()) { first = skipWhitespace(s, first); int last = scanToken(s, first); if (first < last) { tokens.add(s.substring(first, last)); } first = last; } return (String[])tokens.toArray(new String[tokens.size()]); }
[ "public", "static", "String", "[", "]", "tokenizeUnquoted", "(", "String", "s", ")", "{", "List", "tokens", "=", "new", "LinkedList", "(", ")", ";", "int", "first", "=", "0", ";", "while", "(", "first", "<", "s", ".", "length", "(", ")", ")", "{", ...
This method tokenizes a string by space characters, but ignores spaces in quoted parts,that are parts in '' or "". The method does allows the usage of "" in '' and '' in "". The space character between tokens is not returned. @param s the string to tokenize @return the tokens
[ "This", "method", "tokenizes", "a", "string", "by", "space", "characters", "but", "ignores", "spaces", "in", "quoted", "parts", "that", "are", "parts", "in", "or", ".", "The", "method", "does", "allows", "the", "usage", "of", "in", "and", "in", ".", "The...
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/tools/StringHelper.java#L38-L50
train
groovy/groovy-core
src/main/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java
StaticCompilationVisitor.addPrivateFieldsAccessors
@SuppressWarnings("unchecked") private void addPrivateFieldsAccessors(ClassNode node) { Set<ASTNode> accessedFields = (Set<ASTNode>) node.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS); if (accessedFields==null) return; Map<String, MethodNode> privateConstantAccessors = (Map<String, MethodNode>) node.getNodeMetaData(PRIVATE_FIELDS_ACCESSORS); if (privateConstantAccessors!=null) { // already added return; } int acc = -1; privateConstantAccessors = new HashMap<String, MethodNode>(); final int access = Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; for (FieldNode fieldNode : node.getFields()) { if (accessedFields.contains(fieldNode)) { acc++; Parameter param = new Parameter(node.getPlainNodeReference(), "$that"); Expression receiver = fieldNode.isStatic()?new ClassExpression(node):new VariableExpression(param); Statement stmt = new ExpressionStatement(new PropertyExpression( receiver, fieldNode.getName() )); MethodNode accessor = node.addMethod("pfaccess$"+acc, access, fieldNode.getOriginType(), new Parameter[]{param}, ClassNode.EMPTY_ARRAY, stmt); privateConstantAccessors.put(fieldNode.getName(), accessor); } } node.setNodeMetaData(PRIVATE_FIELDS_ACCESSORS, privateConstantAccessors); }
java
@SuppressWarnings("unchecked") private void addPrivateFieldsAccessors(ClassNode node) { Set<ASTNode> accessedFields = (Set<ASTNode>) node.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS); if (accessedFields==null) return; Map<String, MethodNode> privateConstantAccessors = (Map<String, MethodNode>) node.getNodeMetaData(PRIVATE_FIELDS_ACCESSORS); if (privateConstantAccessors!=null) { // already added return; } int acc = -1; privateConstantAccessors = new HashMap<String, MethodNode>(); final int access = Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; for (FieldNode fieldNode : node.getFields()) { if (accessedFields.contains(fieldNode)) { acc++; Parameter param = new Parameter(node.getPlainNodeReference(), "$that"); Expression receiver = fieldNode.isStatic()?new ClassExpression(node):new VariableExpression(param); Statement stmt = new ExpressionStatement(new PropertyExpression( receiver, fieldNode.getName() )); MethodNode accessor = node.addMethod("pfaccess$"+acc, access, fieldNode.getOriginType(), new Parameter[]{param}, ClassNode.EMPTY_ARRAY, stmt); privateConstantAccessors.put(fieldNode.getName(), accessor); } } node.setNodeMetaData(PRIVATE_FIELDS_ACCESSORS, privateConstantAccessors); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "void", "addPrivateFieldsAccessors", "(", "ClassNode", "node", ")", "{", "Set", "<", "ASTNode", ">", "accessedFields", "=", "(", "Set", "<", "ASTNode", ">", ")", "node", ".", "getNodeMetaData", "("...
Adds special accessors for private constants so that inner classes can retrieve them.
[ "Adds", "special", "accessors", "for", "private", "constants", "so", "that", "inner", "classes", "can", "retrieve", "them", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java#L170-L197
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.isPostJDK5
public static boolean isPostJDK5(String bytecodeVersion) { return JDK5.equals(bytecodeVersion) || JDK6.equals(bytecodeVersion) || JDK7.equals(bytecodeVersion) || JDK8.equals(bytecodeVersion); }
java
public static boolean isPostJDK5(String bytecodeVersion) { return JDK5.equals(bytecodeVersion) || JDK6.equals(bytecodeVersion) || JDK7.equals(bytecodeVersion) || JDK8.equals(bytecodeVersion); }
[ "public", "static", "boolean", "isPostJDK5", "(", "String", "bytecodeVersion", ")", "{", "return", "JDK5", ".", "equals", "(", "bytecodeVersion", ")", "||", "JDK6", ".", "equals", "(", "bytecodeVersion", ")", "||", "JDK7", ".", "equals", "(", "bytecodeVersion"...
Checks if the specified bytecode version string represents a JDK 1.5+ compatible bytecode version. @param bytecodeVersion the bytecode version string (1.4, 1.5, 1.6, 1.7 or 1.8) @return true if the bytecode version is JDK 1.5+
[ "Checks", "if", "the", "specified", "bytecode", "version", "string", "represents", "a", "JDK", "1", ".", "5", "+", "compatible", "bytecode", "version", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/CompilerConfiguration.java#L363-L368
train
groovy/groovy-core
src/main/org/codehaus/groovy/control/CompilerConfiguration.java
CompilerConfiguration.setTargetDirectory
public void setTargetDirectory(String directory) { if (directory != null && directory.length() > 0) { this.targetDirectory = new File(directory); } else { this.targetDirectory = null; } }
java
public void setTargetDirectory(String directory) { if (directory != null && directory.length() > 0) { this.targetDirectory = new File(directory); } else { this.targetDirectory = null; } }
[ "public", "void", "setTargetDirectory", "(", "String", "directory", ")", "{", "if", "(", "directory", "!=", "null", "&&", "directory", ".", "length", "(", ")", ">", "0", ")", "{", "this", ".", "targetDirectory", "=", "new", "File", "(", "directory", ")",...
Sets the target directory.
[ "Sets", "the", "target", "directory", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/control/CompilerConfiguration.java#L566-L572
train
groovy/groovy-core
src/main/org/codehaus/groovy/tools/RootLoader.java
RootLoader.loadClass
protected synchronized Class loadClass(final String name, boolean resolve) throws ClassNotFoundException { Class c = this.findLoadedClass(name); if (c != null) return c; c = (Class) customClasses.get(name); if (c != null) return c; try { c = oldFindClass(name); } catch (ClassNotFoundException cnfe) { // IGNORE } if (c == null) c = super.loadClass(name, resolve); if (resolve) resolveClass(c); return c; }
java
protected synchronized Class loadClass(final String name, boolean resolve) throws ClassNotFoundException { Class c = this.findLoadedClass(name); if (c != null) return c; c = (Class) customClasses.get(name); if (c != null) return c; try { c = oldFindClass(name); } catch (ClassNotFoundException cnfe) { // IGNORE } if (c == null) c = super.loadClass(name, resolve); if (resolve) resolveClass(c); return c; }
[ "protected", "synchronized", "Class", "loadClass", "(", "final", "String", "name", ",", "boolean", "resolve", ")", "throws", "ClassNotFoundException", "{", "Class", "c", "=", "this", ".", "findLoadedClass", "(", "name", ")", ";", "if", "(", "c", "!=", "null"...
loads a class using the name of the class
[ "loads", "a", "class", "using", "the", "name", "of", "the", "class" ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/org/codehaus/groovy/tools/RootLoader.java#L140-L156
train
groovy/groovy-core
src/main/groovy/util/NodeList.java
NodeList.getAt
public NodeList getAt(String name) { NodeList answer = new NodeList(); for (Object child : this) { if (child instanceof Node) { Node childNode = (Node) child; Object temp = childNode.get(name); if (temp instanceof Collection) { answer.addAll((Collection) temp); } else { answer.add(temp); } } } return answer; }
java
public NodeList getAt(String name) { NodeList answer = new NodeList(); for (Object child : this) { if (child instanceof Node) { Node childNode = (Node) child; Object temp = childNode.get(name); if (temp instanceof Collection) { answer.addAll((Collection) temp); } else { answer.add(temp); } } } return answer; }
[ "public", "NodeList", "getAt", "(", "String", "name", ")", "{", "NodeList", "answer", "=", "new", "NodeList", "(", ")", ";", "for", "(", "Object", "child", ":", "this", ")", "{", "if", "(", "child", "instanceof", "Node", ")", "{", "Node", "childNode", ...
Provides lookup of elements by non-namespaced name. @param name the name or shortcut key for nodes of interest @return the nodes of interest which match name
[ "Provides", "lookup", "of", "elements", "by", "non", "-", "namespaced", "name", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/util/NodeList.java#L118-L132
train
groovy/groovy-core
src/main/groovy/util/NodeList.java
NodeList.text
public String text() { String previousText = null; StringBuilder buffer = null; for (Object child : this) { String text = null; if (child instanceof String) { text = (String) child; } else if (child instanceof Node) { text = ((Node) child).text(); } if (text != null) { if (previousText == null) { previousText = text; } else { if (buffer == null) { buffer = new StringBuilder(); buffer.append(previousText); } buffer.append(text); } } } if (buffer != null) { return buffer.toString(); } if (previousText != null) { return previousText; } return ""; }
java
public String text() { String previousText = null; StringBuilder buffer = null; for (Object child : this) { String text = null; if (child instanceof String) { text = (String) child; } else if (child instanceof Node) { text = ((Node) child).text(); } if (text != null) { if (previousText == null) { previousText = text; } else { if (buffer == null) { buffer = new StringBuilder(); buffer.append(previousText); } buffer.append(text); } } } if (buffer != null) { return buffer.toString(); } if (previousText != null) { return previousText; } return ""; }
[ "public", "String", "text", "(", ")", "{", "String", "previousText", "=", "null", ";", "StringBuilder", "buffer", "=", "null", ";", "for", "(", "Object", "child", ":", "this", ")", "{", "String", "text", "=", "null", ";", "if", "(", "child", "instanceo...
Returns the text value of all of the elements in the collection. @return the text value of all the elements in the collection or null
[ "Returns", "the", "text", "value", "of", "all", "of", "the", "elements", "in", "the", "collection", "." ]
01309f9d4be34ddf93c4a9943b5a97843bff6181
https://github.com/groovy/groovy-core/blob/01309f9d4be34ddf93c4a9943b5a97843bff6181/src/main/groovy/util/NodeList.java#L157-L186
train
joestelmach/natty
src/main/java/com/joestelmach/natty/Parser.java
Parser.isAllNumeric
private boolean isAllNumeric(TokenStream stream) { List<Token> tokens = ((NattyTokenSource) stream.getTokenSource()).getTokens(); for(Token token:tokens) { try { Integer.parseInt(token.getText()); } catch(NumberFormatException e) { return false; } } return true; }
java
private boolean isAllNumeric(TokenStream stream) { List<Token> tokens = ((NattyTokenSource) stream.getTokenSource()).getTokens(); for(Token token:tokens) { try { Integer.parseInt(token.getText()); } catch(NumberFormatException e) { return false; } } return true; }
[ "private", "boolean", "isAllNumeric", "(", "TokenStream", "stream", ")", "{", "List", "<", "Token", ">", "tokens", "=", "(", "(", "NattyTokenSource", ")", "stream", ".", "getTokenSource", "(", ")", ")", ".", "getTokens", "(", ")", ";", "for", "(", "Token...
Determines if a token stream contains only numeric tokens @param stream @return true if all tokens in the given stream can be parsed as an integer
[ "Determines", "if", "a", "token", "stream", "contains", "only", "numeric", "tokens" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/Parser.java#L166-L176
train
joestelmach/natty
src/main/java/com/joestelmach/natty/Parser.java
Parser.collectTokenStreams
private List<TokenStream> collectTokenStreams(TokenStream stream) { // walk through the token stream and build a collection // of sub token streams that represent possible date locations List<Token> currentGroup = null; List<List<Token>> groups = new ArrayList<List<Token>>(); Token currentToken; int currentTokenType; StringBuilder tokenString = new StringBuilder(); while((currentToken = stream.getTokenSource().nextToken()).getType() != DateLexer.EOF) { currentTokenType = currentToken.getType(); tokenString.append(DateParser.tokenNames[currentTokenType]).append(" "); // we're currently NOT collecting for a possible date group if(currentGroup == null) { // skip over white space and known tokens that cannot be the start of a date if(currentTokenType != DateLexer.WHITE_SPACE && DateParser.FOLLOW_empty_in_parse186.member(currentTokenType)) { currentGroup = new ArrayList<Token>(); currentGroup.add(currentToken); } } // we're currently collecting else { // preserve white space if(currentTokenType == DateLexer.WHITE_SPACE) { currentGroup.add(currentToken); } else { // if this is an unknown token, we'll close out the current group if(currentTokenType == DateLexer.UNKNOWN) { addGroup(currentGroup, groups); currentGroup = null; } // otherwise, the token is known and we're currently collecting for // a group, so we'll add it to the current group else { currentGroup.add(currentToken); } } } } if(currentGroup != null) { addGroup(currentGroup, groups); } _logger.info("STREAM: " + tokenString.toString()); List<TokenStream> streams = new ArrayList<TokenStream>(); for(List<Token> group:groups) { if(!group.isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append("GROUP: "); for (Token token : group) { builder.append(DateParser.tokenNames[token.getType()]).append(" "); } _logger.info(builder.toString()); streams.add(new CommonTokenStream(new NattyTokenSource(group))); } } return streams; }
java
private List<TokenStream> collectTokenStreams(TokenStream stream) { // walk through the token stream and build a collection // of sub token streams that represent possible date locations List<Token> currentGroup = null; List<List<Token>> groups = new ArrayList<List<Token>>(); Token currentToken; int currentTokenType; StringBuilder tokenString = new StringBuilder(); while((currentToken = stream.getTokenSource().nextToken()).getType() != DateLexer.EOF) { currentTokenType = currentToken.getType(); tokenString.append(DateParser.tokenNames[currentTokenType]).append(" "); // we're currently NOT collecting for a possible date group if(currentGroup == null) { // skip over white space and known tokens that cannot be the start of a date if(currentTokenType != DateLexer.WHITE_SPACE && DateParser.FOLLOW_empty_in_parse186.member(currentTokenType)) { currentGroup = new ArrayList<Token>(); currentGroup.add(currentToken); } } // we're currently collecting else { // preserve white space if(currentTokenType == DateLexer.WHITE_SPACE) { currentGroup.add(currentToken); } else { // if this is an unknown token, we'll close out the current group if(currentTokenType == DateLexer.UNKNOWN) { addGroup(currentGroup, groups); currentGroup = null; } // otherwise, the token is known and we're currently collecting for // a group, so we'll add it to the current group else { currentGroup.add(currentToken); } } } } if(currentGroup != null) { addGroup(currentGroup, groups); } _logger.info("STREAM: " + tokenString.toString()); List<TokenStream> streams = new ArrayList<TokenStream>(); for(List<Token> group:groups) { if(!group.isEmpty()) { StringBuilder builder = new StringBuilder(); builder.append("GROUP: "); for (Token token : group) { builder.append(DateParser.tokenNames[token.getType()]).append(" "); } _logger.info(builder.toString()); streams.add(new CommonTokenStream(new NattyTokenSource(group))); } } return streams; }
[ "private", "List", "<", "TokenStream", ">", "collectTokenStreams", "(", "TokenStream", "stream", ")", "{", "// walk through the token stream and build a collection ", "// of sub token streams that represent possible date locations", "List", "<", "Token", ">", "currentGroup", "=",...
Scans the given token global token stream for a list of sub-token streams representing those portions of the global stream that may contain date time information @param stream @return
[ "Scans", "the", "given", "token", "global", "token", "stream", "for", "a", "list", "of", "sub", "-", "token", "streams", "representing", "those", "portions", "of", "the", "global", "stream", "that", "may", "contain", "date", "time", "information" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/Parser.java#L260-L326
train
joestelmach/natty
src/main/java/com/joestelmach/natty/Parser.java
Parser.addGroup
private void addGroup(List<Token> group, List<List<Token>> groups) { if(group.isEmpty()) return; // remove trailing tokens that should be ignored while(!group.isEmpty() && IGNORED_TRAILING_TOKENS.contains( group.get(group.size() - 1).getType())) { group.remove(group.size() - 1); } // if the group still has some tokens left, we'll add it to our list of groups if(!group.isEmpty()) { groups.add(group); } }
java
private void addGroup(List<Token> group, List<List<Token>> groups) { if(group.isEmpty()) return; // remove trailing tokens that should be ignored while(!group.isEmpty() && IGNORED_TRAILING_TOKENS.contains( group.get(group.size() - 1).getType())) { group.remove(group.size() - 1); } // if the group still has some tokens left, we'll add it to our list of groups if(!group.isEmpty()) { groups.add(group); } }
[ "private", "void", "addGroup", "(", "List", "<", "Token", ">", "group", ",", "List", "<", "List", "<", "Token", ">", ">", "groups", ")", "{", "if", "(", "group", ".", "isEmpty", "(", ")", ")", "return", ";", "// remove trailing tokens that should be ignore...
Cleans up the given group and adds it to the list of groups if still valid @param group @param groups
[ "Cleans", "up", "the", "given", "group", "and", "adds", "it", "to", "the", "list", "of", "groups", "if", "still", "valid" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/Parser.java#L333-L347
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToDayOfWeek
public void seekToDayOfWeek(String direction, String seekType, String seekAmount, String dayOfWeek) { int dayOfWeekInt = Integer.parseInt(dayOfWeek); int seekAmountInt = Integer.parseInt(seekAmount); assert(direction.equals(DIR_LEFT) || direction.equals(DIR_RIGHT)); assert(seekType.equals(SEEK_BY_DAY) || seekType.equals(SEEK_BY_WEEK)); assert(dayOfWeekInt >= 1 && dayOfWeekInt <= 7); markDateInvocation(); int sign = direction.equals(DIR_RIGHT) ? 1 : -1; if(seekType.equals(SEEK_BY_WEEK)) { // set our calendar to this weeks requested day of the week, // then add or subtract the week(s) _calendar.set(Calendar.DAY_OF_WEEK, dayOfWeekInt); _calendar.add(Calendar.DAY_OF_YEAR, seekAmountInt * 7 * sign); } else if(seekType.equals(SEEK_BY_DAY)) { // find the closest day do { _calendar.add(Calendar.DAY_OF_YEAR, sign); } while(_calendar.get(Calendar.DAY_OF_WEEK) != dayOfWeekInt); // now add/subtract any additional days if(seekAmountInt > 0) { _calendar.add(Calendar.WEEK_OF_YEAR, (seekAmountInt - 1) * sign); } } }
java
public void seekToDayOfWeek(String direction, String seekType, String seekAmount, String dayOfWeek) { int dayOfWeekInt = Integer.parseInt(dayOfWeek); int seekAmountInt = Integer.parseInt(seekAmount); assert(direction.equals(DIR_LEFT) || direction.equals(DIR_RIGHT)); assert(seekType.equals(SEEK_BY_DAY) || seekType.equals(SEEK_BY_WEEK)); assert(dayOfWeekInt >= 1 && dayOfWeekInt <= 7); markDateInvocation(); int sign = direction.equals(DIR_RIGHT) ? 1 : -1; if(seekType.equals(SEEK_BY_WEEK)) { // set our calendar to this weeks requested day of the week, // then add or subtract the week(s) _calendar.set(Calendar.DAY_OF_WEEK, dayOfWeekInt); _calendar.add(Calendar.DAY_OF_YEAR, seekAmountInt * 7 * sign); } else if(seekType.equals(SEEK_BY_DAY)) { // find the closest day do { _calendar.add(Calendar.DAY_OF_YEAR, sign); } while(_calendar.get(Calendar.DAY_OF_WEEK) != dayOfWeekInt); // now add/subtract any additional days if(seekAmountInt > 0) { _calendar.add(Calendar.WEEK_OF_YEAR, (seekAmountInt - 1) * sign); } } }
[ "public", "void", "seekToDayOfWeek", "(", "String", "direction", ",", "String", "seekType", ",", "String", "seekAmount", ",", "String", "dayOfWeek", ")", "{", "int", "dayOfWeekInt", "=", "Integer", ".", "parseInt", "(", "dayOfWeek", ")", ";", "int", "seekAmoun...
seeks to a specified day of the week in the past or future. @param direction the direction to seek: two possibilities '<' go backward '>' go forward @param seekType the type of seek to perform (by_day or by_week) by_day means we seek to the very next occurrence of the given day by_week means we seek to the first occurrence of the given day week in the next (or previous,) week (or multiple of next or previous week depending on the seek amount.) @param seekAmount the amount to seek. Must be guaranteed to parse as an integer @param dayOfWeek the day of the week to seek to, represented as an integer from 1 to 7 (1 being Sunday, 7 being Saturday.) Must be guaranteed to parse as an Integer
[ "seeks", "to", "a", "specified", "day", "of", "the", "week", "in", "the", "past", "or", "future", "." ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L80-L108
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToDayOfMonth
public void seekToDayOfMonth(String dayOfMonth) { int dayOfMonthInt = Integer.parseInt(dayOfMonth); assert(dayOfMonthInt >= 1 && dayOfMonthInt <= 31); markDateInvocation(); dayOfMonthInt = Math.min(dayOfMonthInt, _calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); _calendar.set(Calendar.DAY_OF_MONTH, dayOfMonthInt); }
java
public void seekToDayOfMonth(String dayOfMonth) { int dayOfMonthInt = Integer.parseInt(dayOfMonth); assert(dayOfMonthInt >= 1 && dayOfMonthInt <= 31); markDateInvocation(); dayOfMonthInt = Math.min(dayOfMonthInt, _calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); _calendar.set(Calendar.DAY_OF_MONTH, dayOfMonthInt); }
[ "public", "void", "seekToDayOfMonth", "(", "String", "dayOfMonth", ")", "{", "int", "dayOfMonthInt", "=", "Integer", ".", "parseInt", "(", "dayOfMonth", ")", ";", "assert", "(", "dayOfMonthInt", ">=", "1", "&&", "dayOfMonthInt", "<=", "31", ")", ";", "markDa...
Seeks to the given day within the current month @param dayOfMonth the day of the month to seek to, represented as an integer from 1 to 31. Must be guaranteed to parse as an Integer. If this day is beyond the last day of the current month, the actual last day of the month will be used.
[ "Seeks", "to", "the", "given", "day", "within", "the", "current", "month" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L117-L125
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToDayOfYear
public void seekToDayOfYear(String dayOfYear) { int dayOfYearInt = Integer.parseInt(dayOfYear); assert(dayOfYearInt >= 1 && dayOfYearInt <= 366); markDateInvocation(); dayOfYearInt = Math.min(dayOfYearInt, _calendar.getActualMaximum(Calendar.DAY_OF_YEAR)); _calendar.set(Calendar.DAY_OF_YEAR, dayOfYearInt); }
java
public void seekToDayOfYear(String dayOfYear) { int dayOfYearInt = Integer.parseInt(dayOfYear); assert(dayOfYearInt >= 1 && dayOfYearInt <= 366); markDateInvocation(); dayOfYearInt = Math.min(dayOfYearInt, _calendar.getActualMaximum(Calendar.DAY_OF_YEAR)); _calendar.set(Calendar.DAY_OF_YEAR, dayOfYearInt); }
[ "public", "void", "seekToDayOfYear", "(", "String", "dayOfYear", ")", "{", "int", "dayOfYearInt", "=", "Integer", ".", "parseInt", "(", "dayOfYear", ")", ";", "assert", "(", "dayOfYearInt", ">=", "1", "&&", "dayOfYearInt", "<=", "366", ")", ";", "markDateInv...
Seeks to the given day within the current year @param dayOfYear the day of the year to seek to, represented as an integer from 1 to 366. Must be guaranteed to parse as an Integer. If this day is beyond the last day of the current year, the actual last day of the year will be used.
[ "Seeks", "to", "the", "given", "day", "within", "the", "current", "year" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L134-L142
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToMonth
public void seekToMonth(String direction, String seekAmount, String month) { int seekAmountInt = Integer.parseInt(seekAmount); int monthInt = Integer.parseInt(month); assert(direction.equals(DIR_LEFT) || direction.equals(DIR_RIGHT)); assert(monthInt >= 1 && monthInt <= 12); markDateInvocation(); // set the day to the first of month. This step is necessary because if we seek to the // current day of a month whose number of days is less than the current day, we will // pushed into the next month. _calendar.set(Calendar.DAY_OF_MONTH, 1); // seek to the appropriate year if(seekAmountInt > 0) { int currentMonth = _calendar.get(Calendar.MONTH) + 1; int sign = direction.equals(DIR_RIGHT) ? 1 : -1; int numYearsToShift = seekAmountInt + (currentMonth == monthInt ? 0 : (currentMonth < monthInt ? sign > 0 ? -1 : 0 : sign > 0 ? 0 : -1)); _calendar.add(Calendar.YEAR, (numYearsToShift * sign)); } // now set the month _calendar.set(Calendar.MONTH, monthInt - 1); }
java
public void seekToMonth(String direction, String seekAmount, String month) { int seekAmountInt = Integer.parseInt(seekAmount); int monthInt = Integer.parseInt(month); assert(direction.equals(DIR_LEFT) || direction.equals(DIR_RIGHT)); assert(monthInt >= 1 && monthInt <= 12); markDateInvocation(); // set the day to the first of month. This step is necessary because if we seek to the // current day of a month whose number of days is less than the current day, we will // pushed into the next month. _calendar.set(Calendar.DAY_OF_MONTH, 1); // seek to the appropriate year if(seekAmountInt > 0) { int currentMonth = _calendar.get(Calendar.MONTH) + 1; int sign = direction.equals(DIR_RIGHT) ? 1 : -1; int numYearsToShift = seekAmountInt + (currentMonth == monthInt ? 0 : (currentMonth < monthInt ? sign > 0 ? -1 : 0 : sign > 0 ? 0 : -1)); _calendar.add(Calendar.YEAR, (numYearsToShift * sign)); } // now set the month _calendar.set(Calendar.MONTH, monthInt - 1); }
[ "public", "void", "seekToMonth", "(", "String", "direction", ",", "String", "seekAmount", ",", "String", "month", ")", "{", "int", "seekAmountInt", "=", "Integer", ".", "parseInt", "(", "seekAmount", ")", ";", "int", "monthInt", "=", "Integer", ".", "parseIn...
seeks to a particular month @param direction the direction to seek: two possibilities '<' go backward '>' go forward @param seekAmount the amount to seek. Must be guaranteed to parse as an integer @param month the month to seek to. Must be guaranteed to parse as an integer between 1 and 12
[ "seeks", "to", "a", "particular", "month" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L169-L194
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.setExplicitTime
public void setExplicitTime(String hours, String minutes, String seconds, String amPm, String zoneString) { int hoursInt = Integer.parseInt(hours); int minutesInt = minutes != null ? Integer.parseInt(minutes) : 0; assert(amPm == null || amPm.equals(AM) || amPm.equals(PM)); assert(hoursInt >= 0); assert(minutesInt >= 0 && minutesInt < 60); markTimeInvocation(amPm); // reset milliseconds to 0 _calendar.set(Calendar.MILLISECOND, 0); // if no explicit zone is given, we use our own TimeZone zone = null; if(zoneString != null) { if(zoneString.startsWith(PLUS) || zoneString.startsWith(MINUS)) { zoneString = GMT + zoneString; } zone = TimeZone.getTimeZone(zoneString); } _calendar.setTimeZone(zone != null ? zone : _defaultTimeZone); _calendar.set(Calendar.HOUR_OF_DAY, hoursInt); // hours greater than 12 are in 24-hour time if(hoursInt <= 12) { int amPmInt = amPm == null ? (hoursInt >= 12 ? Calendar.PM : Calendar.AM) : amPm.equals(PM) ? Calendar.PM : Calendar.AM; _calendar.set(Calendar.AM_PM, amPmInt); // calendar is whacky at 12 o'clock (must use 0) if(hoursInt == 12) hoursInt = 0; _calendar.set(Calendar.HOUR, hoursInt); } if(seconds != null) { int secondsInt = Integer.parseInt(seconds); assert(secondsInt >= 0 && secondsInt < 60); _calendar.set(Calendar.SECOND, secondsInt); } else { _calendar.set(Calendar.SECOND, 0); } _calendar.set(Calendar.MINUTE, minutesInt); }
java
public void setExplicitTime(String hours, String minutes, String seconds, String amPm, String zoneString) { int hoursInt = Integer.parseInt(hours); int minutesInt = minutes != null ? Integer.parseInt(minutes) : 0; assert(amPm == null || amPm.equals(AM) || amPm.equals(PM)); assert(hoursInt >= 0); assert(minutesInt >= 0 && minutesInt < 60); markTimeInvocation(amPm); // reset milliseconds to 0 _calendar.set(Calendar.MILLISECOND, 0); // if no explicit zone is given, we use our own TimeZone zone = null; if(zoneString != null) { if(zoneString.startsWith(PLUS) || zoneString.startsWith(MINUS)) { zoneString = GMT + zoneString; } zone = TimeZone.getTimeZone(zoneString); } _calendar.setTimeZone(zone != null ? zone : _defaultTimeZone); _calendar.set(Calendar.HOUR_OF_DAY, hoursInt); // hours greater than 12 are in 24-hour time if(hoursInt <= 12) { int amPmInt = amPm == null ? (hoursInt >= 12 ? Calendar.PM : Calendar.AM) : amPm.equals(PM) ? Calendar.PM : Calendar.AM; _calendar.set(Calendar.AM_PM, amPmInt); // calendar is whacky at 12 o'clock (must use 0) if(hoursInt == 12) hoursInt = 0; _calendar.set(Calendar.HOUR, hoursInt); } if(seconds != null) { int secondsInt = Integer.parseInt(seconds); assert(secondsInt >= 0 && secondsInt < 60); _calendar.set(Calendar.SECOND, secondsInt); } else { _calendar.set(Calendar.SECOND, 0); } _calendar.set(Calendar.MINUTE, minutesInt); }
[ "public", "void", "setExplicitTime", "(", "String", "hours", ",", "String", "minutes", ",", "String", "seconds", ",", "String", "amPm", ",", "String", "zoneString", ")", "{", "int", "hoursInt", "=", "Integer", ".", "parseInt", "(", "hours", ")", ";", "int"...
Sets the the time of day @param hours the hours to set. Must be guaranteed to parse as an integer between 0 and 23 @param minutes the minutes to set. Must be guaranteed to parse as an integer between 0 and 59 @param seconds the optional seconds to set. Must be guaranteed to parse as an integer between 0 and 59 @param amPm the meridian indicator to use. Must be either 'am' or 'pm' @param zoneString the time zone to use in one of two formats: - zoneinfo format (America/New_York, America/Los_Angeles, etc) - GMT offset (+05:00, -0500, +5, etc)
[ "Sets", "the", "the", "time", "of", "day" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L334-L380
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToHoliday
public void seekToHoliday(String holidayString, String direction, String seekAmount) { Holiday holiday = Holiday.valueOf(holidayString); assert(holiday != null); seekToIcsEvent(HOLIDAY_ICS_FILE, holiday.getSummary(), direction, seekAmount); }
java
public void seekToHoliday(String holidayString, String direction, String seekAmount) { Holiday holiday = Holiday.valueOf(holidayString); assert(holiday != null); seekToIcsEvent(HOLIDAY_ICS_FILE, holiday.getSummary(), direction, seekAmount); }
[ "public", "void", "seekToHoliday", "(", "String", "holidayString", ",", "String", "direction", ",", "String", "seekAmount", ")", "{", "Holiday", "holiday", "=", "Holiday", ".", "valueOf", "(", "holidayString", ")", ";", "assert", "(", "holiday", "!=", "null", ...
Seeks forward or backwards to a particular holiday based on the current date @param holidayString The holiday to seek to @param direction The direction to seek @param seekAmount The number of years to seek
[ "Seeks", "forward", "or", "backwards", "to", "a", "particular", "holiday", "based", "on", "the", "current", "date" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L389-L394
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToHolidayYear
public void seekToHolidayYear(String holidayString, String yearString) { Holiday holiday = Holiday.valueOf(holidayString); assert(holiday != null); seekToIcsEventYear(HOLIDAY_ICS_FILE, yearString, holiday.getSummary()); }
java
public void seekToHolidayYear(String holidayString, String yearString) { Holiday holiday = Holiday.valueOf(holidayString); assert(holiday != null); seekToIcsEventYear(HOLIDAY_ICS_FILE, yearString, holiday.getSummary()); }
[ "public", "void", "seekToHolidayYear", "(", "String", "holidayString", ",", "String", "yearString", ")", "{", "Holiday", "holiday", "=", "Holiday", ".", "valueOf", "(", "holidayString", ")", ";", "assert", "(", "holiday", "!=", "null", ")", ";", "seekToIcsEven...
Seeks to the given holiday within the given year @param holidayString @param yearString
[ "Seeks", "to", "the", "given", "holiday", "within", "the", "given", "year" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L402-L407
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToSeason
public void seekToSeason(String seasonString, String direction, String seekAmount) { Season season = Season.valueOf(seasonString); assert(season!= null); seekToIcsEvent(SEASON_ICS_FILE, season.getSummary(), direction, seekAmount); }
java
public void seekToSeason(String seasonString, String direction, String seekAmount) { Season season = Season.valueOf(seasonString); assert(season!= null); seekToIcsEvent(SEASON_ICS_FILE, season.getSummary(), direction, seekAmount); }
[ "public", "void", "seekToSeason", "(", "String", "seasonString", ",", "String", "direction", ",", "String", "seekAmount", ")", "{", "Season", "season", "=", "Season", ".", "valueOf", "(", "seasonString", ")", ";", "assert", "(", "season", "!=", "null", ")", ...
Seeks forward or backwards to a particular season based on the current date @param seasonString The season to seek to @param direction The direction to seek @param seekAmount The number of years to seek
[ "Seeks", "forward", "or", "backwards", "to", "a", "particular", "season", "based", "on", "the", "current", "date" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L416-L421
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seekToSeasonYear
public void seekToSeasonYear(String seasonString, String yearString) { Season season = Season.valueOf(seasonString); assert(season != null); seekToIcsEventYear(SEASON_ICS_FILE, yearString, season.getSummary()); }
java
public void seekToSeasonYear(String seasonString, String yearString) { Season season = Season.valueOf(seasonString); assert(season != null); seekToIcsEventYear(SEASON_ICS_FILE, yearString, season.getSummary()); }
[ "public", "void", "seekToSeasonYear", "(", "String", "seasonString", ",", "String", "yearString", ")", "{", "Season", "season", "=", "Season", ".", "valueOf", "(", "seasonString", ")", ";", "assert", "(", "season", "!=", "null", ")", ";", "seekToIcsEventYear",...
Seeks to the given season within the given year @param seasonString @param yearString
[ "Seeks", "to", "the", "given", "season", "within", "the", "given", "year" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L429-L434
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.resetCalendar
private void resetCalendar() { _calendar = getCalendar(); if (_defaultTimeZone != null) { _calendar.setTimeZone(_defaultTimeZone); } _currentYear = _calendar.get(Calendar.YEAR); }
java
private void resetCalendar() { _calendar = getCalendar(); if (_defaultTimeZone != null) { _calendar.setTimeZone(_defaultTimeZone); } _currentYear = _calendar.get(Calendar.YEAR); }
[ "private", "void", "resetCalendar", "(", ")", "{", "_calendar", "=", "getCalendar", "(", ")", ";", "if", "(", "_defaultTimeZone", "!=", "null", ")", "{", "_calendar", ".", "setTimeZone", "(", "_defaultTimeZone", ")", ";", "}", "_currentYear", "=", "_calendar...
Resets the calendar
[ "Resets", "the", "calendar" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L543-L549
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.seasonalDateFromIcs
private Date seasonalDateFromIcs(String icsFileName, String eventSummary, int year) { Map<Integer, Date> dates = getDatesFromIcs(icsFileName, eventSummary, year, year); return dates.get(year - (eventSummary.equals(Holiday.NEW_YEARS_EVE.getSummary()) ? 1 : 0)); }
java
private Date seasonalDateFromIcs(String icsFileName, String eventSummary, int year) { Map<Integer, Date> dates = getDatesFromIcs(icsFileName, eventSummary, year, year); return dates.get(year - (eventSummary.equals(Holiday.NEW_YEARS_EVE.getSummary()) ? 1 : 0)); }
[ "private", "Date", "seasonalDateFromIcs", "(", "String", "icsFileName", ",", "String", "eventSummary", ",", "int", "year", ")", "{", "Map", "<", "Integer", ",", "Date", ">", "dates", "=", "getDatesFromIcs", "(", "icsFileName", ",", "eventSummary", ",", "year",...
Finds and returns the date for the given event summary and year within the given ics file, or null if not present.
[ "Finds", "and", "returns", "the", "date", "for", "the", "given", "event", "summary", "and", "year", "within", "the", "given", "ics", "file", "or", "null", "if", "not", "present", "." ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L619-L622
train
joestelmach/natty
src/main/java/com/joestelmach/natty/WalkerState.java
WalkerState.markDateInvocation
private void markDateInvocation() { _updatePreviousDates = !_dateGivenInGroup; _dateGivenInGroup = true; _dateGroup.setDateInferred(false); if(_firstDateInvocationInGroup) { // if a time has been given within the current date group, // we capture the current time before resetting the calendar if(_timeGivenInGroup) { int hours = _calendar.get(Calendar.HOUR_OF_DAY); int minutes = _calendar.get(Calendar.MINUTE); int seconds = _calendar.get(Calendar.SECOND); resetCalendar(); _calendar.set(Calendar.HOUR_OF_DAY, hours); _calendar.set(Calendar.MINUTE, minutes); _calendar.set(Calendar.SECOND, seconds); } else { resetCalendar(); } _firstDateInvocationInGroup = false; } }
java
private void markDateInvocation() { _updatePreviousDates = !_dateGivenInGroup; _dateGivenInGroup = true; _dateGroup.setDateInferred(false); if(_firstDateInvocationInGroup) { // if a time has been given within the current date group, // we capture the current time before resetting the calendar if(_timeGivenInGroup) { int hours = _calendar.get(Calendar.HOUR_OF_DAY); int minutes = _calendar.get(Calendar.MINUTE); int seconds = _calendar.get(Calendar.SECOND); resetCalendar(); _calendar.set(Calendar.HOUR_OF_DAY, hours); _calendar.set(Calendar.MINUTE, minutes); _calendar.set(Calendar.SECOND, seconds); } else { resetCalendar(); } _firstDateInvocationInGroup = false; } }
[ "private", "void", "markDateInvocation", "(", ")", "{", "_updatePreviousDates", "=", "!", "_dateGivenInGroup", ";", "_dateGivenInGroup", "=", "true", ";", "_dateGroup", ".", "setDateInferred", "(", "false", ")", ";", "if", "(", "_firstDateInvocationInGroup", ")", ...
ensures that the first invocation of a date seeking rule is captured
[ "ensures", "that", "the", "first", "invocation", "of", "a", "date", "seeking", "rule", "is", "captured" ]
74389feb4c9372e51cd51eb0800a0177fec3e5a0
https://github.com/joestelmach/natty/blob/74389feb4c9372e51cd51eb0800a0177fec3e5a0/src/main/java/com/joestelmach/natty/WalkerState.java#L628-L651
train
sstrickx/yahoofinance-api
src/main/java/yahoofinance/histquotes/HistQuotesRequest.java
HistQuotesRequest.cleanHistCalendar
private Calendar cleanHistCalendar(Calendar cal) { cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); return cal; }
java
private Calendar cleanHistCalendar(Calendar cal) { cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); return cal; }
[ "private", "Calendar", "cleanHistCalendar", "(", "Calendar", "cal", ")", "{", "cal", ".", "set", "(", "Calendar", ".", "MILLISECOND", ",", "0", ")", ";", "cal", ".", "set", "(", "Calendar", ".", "SECOND", ",", "0", ")", ";", "cal", ".", "set", "(", ...
Put everything smaller than days at 0 @param cal calendar to be cleaned
[ "Put", "everything", "smaller", "than", "days", "at", "0" ]
2766ba52fc5cccf9b4da5c06423d68059cf0a6e6
https://github.com/sstrickx/yahoofinance-api/blob/2766ba52fc5cccf9b4da5c06423d68059cf0a6e6/src/main/java/yahoofinance/histquotes/HistQuotesRequest.java#L79-L85
train
sstrickx/yahoofinance-api
src/main/java/yahoofinance/Utils.java
Utils.parseDividendDate
public static Calendar parseDividendDate(String date) { if (!Utils.isParseable(date)) { return null; } date = date.trim(); SimpleDateFormat format = new SimpleDateFormat(Utils.getDividendDateFormat(date), Locale.US); format.setTimeZone(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); try { Calendar today = Calendar.getInstance(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); Calendar parsedDate = Calendar.getInstance(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); parsedDate.setTime(format.parse(date)); if (parsedDate.get(Calendar.YEAR) == 1970) { // Not really clear which year the dividend date is... making a reasonable guess. int monthDiff = parsedDate.get(Calendar.MONTH) - today.get(Calendar.MONTH); int year = today.get(Calendar.YEAR); if (monthDiff > 6) { year -= 1; } else if (monthDiff < -6) { year += 1; } parsedDate.set(Calendar.YEAR, year); } return parsedDate; } catch (ParseException ex) { log.warn("Failed to parse dividend date: " + date); log.debug("Failed to parse dividend date: " + date, ex); return null; } }
java
public static Calendar parseDividendDate(String date) { if (!Utils.isParseable(date)) { return null; } date = date.trim(); SimpleDateFormat format = new SimpleDateFormat(Utils.getDividendDateFormat(date), Locale.US); format.setTimeZone(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); try { Calendar today = Calendar.getInstance(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); Calendar parsedDate = Calendar.getInstance(TimeZone.getTimeZone(YahooFinance.TIMEZONE)); parsedDate.setTime(format.parse(date)); if (parsedDate.get(Calendar.YEAR) == 1970) { // Not really clear which year the dividend date is... making a reasonable guess. int monthDiff = parsedDate.get(Calendar.MONTH) - today.get(Calendar.MONTH); int year = today.get(Calendar.YEAR); if (monthDiff > 6) { year -= 1; } else if (monthDiff < -6) { year += 1; } parsedDate.set(Calendar.YEAR, year); } return parsedDate; } catch (ParseException ex) { log.warn("Failed to parse dividend date: " + date); log.debug("Failed to parse dividend date: " + date, ex); return null; } }
[ "public", "static", "Calendar", "parseDividendDate", "(", "String", "date", ")", "{", "if", "(", "!", "Utils", ".", "isParseable", "(", "date", ")", ")", "{", "return", "null", ";", "}", "date", "=", "date", ".", "trim", "(", ")", ";", "SimpleDateForma...
Used to parse the dividend dates. Returns null if the date cannot be parsed. @param date String received that represents the date @return Calendar object representing the parsed date
[ "Used", "to", "parse", "the", "dividend", "dates", ".", "Returns", "null", "if", "the", "date", "cannot", "be", "parsed", "." ]
2766ba52fc5cccf9b4da5c06423d68059cf0a6e6
https://github.com/sstrickx/yahoofinance-api/blob/2766ba52fc5cccf9b4da5c06423d68059cf0a6e6/src/main/java/yahoofinance/Utils.java#L194-L224
train