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
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.fixedCheckbox
public String fixedCheckbox (String name, boolean value) { StringBuilder buf = new StringBuilder(); buf.append("<input type=\"checkbox\""); buf.append(" name=\"").append(name).append("\""); if (value) { buf.append(_useXHTML ? " checked=\"checked\"" : " checked"); } buf.append(getCloseBrace()); return buf.toString(); }
java
public String fixedCheckbox (String name, boolean value) { StringBuilder buf = new StringBuilder(); buf.append("<input type=\"checkbox\""); buf.append(" name=\"").append(name).append("\""); if (value) { buf.append(_useXHTML ? " checked=\"checked\"" : " checked"); } buf.append(getCloseBrace()); return buf.toString(); }
[ "public", "String", "fixedCheckbox", "(", "String", "name", ",", "boolean", "value", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "\"<input type=\\\"checkbox\\\"\"", ")", ";", "buf", ".", "append", ...
Constructs a checkbox input field with the specified name and value.
[ "Constructs", "a", "checkbox", "input", "field", "with", "the", "specified", "name", "and", "value", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L275-L285
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.option
public String option ( String name, String value, String item, Object defaultValue) { String selectedValue = getValue(name, defaultValue); return fixedOption(name, value, item, selectedValue); }
java
public String option ( String name, String value, String item, Object defaultValue) { String selectedValue = getValue(name, defaultValue); return fixedOption(name, value, item, selectedValue); }
[ "public", "String", "option", "(", "String", "name", ",", "String", "value", ",", "String", "item", ",", "Object", "defaultValue", ")", "{", "String", "selectedValue", "=", "getValue", "(", "name", ",", "defaultValue", ")", ";", "return", "fixedOption", "(",...
Constructs an option entry for a select menu with the specified name, value, item, and default selected value.
[ "Constructs", "an", "option", "entry", "for", "a", "select", "menu", "with", "the", "specified", "name", "value", "item", "and", "default", "selected", "value", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L291-L296
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.fixedOption
public String fixedOption ( String name, String value, String item, Object selectedValue) { StringBuilder buf = new StringBuilder(); buf.append("<option value=\"").append(value).append("\""); if (selectedValue.equals(value)) { buf.append(" selected"); } buf.append(">").append(item).append("</option>"); return buf.toString(); }
java
public String fixedOption ( String name, String value, String item, Object selectedValue) { StringBuilder buf = new StringBuilder(); buf.append("<option value=\"").append(value).append("\""); if (selectedValue.equals(value)) { buf.append(" selected"); } buf.append(">").append(item).append("</option>"); return buf.toString(); }
[ "public", "String", "fixedOption", "(", "String", "name", ",", "String", "value", ",", "String", "item", ",", "Object", "selectedValue", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "\"<option value...
Constructs an option entry for a select menu with the specified name, value, item, and selected value.
[ "Constructs", "an", "option", "entry", "for", "a", "select", "menu", "with", "the", "specified", "name", "value", "item", "and", "selected", "value", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L302-L312
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.textarea
public String textarea (String name, String extra, Object defaultValue) { return fixedTextarea(name, extra, getValue(name, defaultValue)); }
java
public String textarea (String name, String extra, Object defaultValue) { return fixedTextarea(name, extra, getValue(name, defaultValue)); }
[ "public", "String", "textarea", "(", "String", "name", ",", "String", "extra", ",", "Object", "defaultValue", ")", "{", "return", "fixedTextarea", "(", "name", ",", "extra", ",", "getValue", "(", "name", ",", "defaultValue", ")", ")", ";", "}" ]
Constructs a text area with the specified name, optional extra parameters, and default text.
[ "Constructs", "a", "text", "area", "with", "the", "specified", "name", "optional", "extra", "parameters", "and", "default", "text", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L343-L346
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.fixedTextarea
public String fixedTextarea (String name, String extra, Object value) { StringBuilder buf = new StringBuilder(); buf.append("<textarea name=\"").append(name).append("\""); if (!StringUtil.isBlank(extra)) { buf.append(" ").append(extra); } buf.append(">"); if (value != null) { buf.append(value); } buf.append("</textarea>"); return buf.toString(); }
java
public String fixedTextarea (String name, String extra, Object value) { StringBuilder buf = new StringBuilder(); buf.append("<textarea name=\"").append(name).append("\""); if (!StringUtil.isBlank(extra)) { buf.append(" ").append(extra); } buf.append(">"); if (value != null) { buf.append(value); } buf.append("</textarea>"); return buf.toString(); }
[ "public", "String", "fixedTextarea", "(", "String", "name", ",", "String", "extra", ",", "Object", "value", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "\"<textarea name=\\\"\"", ")", ".", "append"...
Construct a text area with the specified name, optional extra parameters and the specified text.
[ "Construct", "a", "text", "area", "with", "the", "specified", "name", "optional", "extra", "parameters", "and", "the", "specified", "text", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L352-L365
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.input
protected String input (String type, String name, String extra, Object defaultValue) { return fixedInput(type, name, getValue(name, defaultValue), extra); }
java
protected String input (String type, String name, String extra, Object defaultValue) { return fixedInput(type, name, getValue(name, defaultValue), extra); }
[ "protected", "String", "input", "(", "String", "type", ",", "String", "name", ",", "String", "extra", ",", "Object", "defaultValue", ")", "{", "return", "fixedInput", "(", "type", ",", "name", ",", "getValue", "(", "name", ",", "defaultValue", ")", ",", ...
Generates an input form field with the specified type, name, defaultValue and extra attributes.
[ "Generates", "an", "input", "form", "field", "with", "the", "specified", "type", "name", "defaultValue", "and", "extra", "attributes", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L371-L375
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.fixedInput
protected String fixedInput ( String type, String name, Object value, String extra) { StringBuilder buf = new StringBuilder(); buf.append("<input type=\"").append(type).append("\""); buf.append(" name=\"").append(name).append("\""); buf.append(" value=\"").append(value).append("\""); if (!StringUtil.isBlank(extra)) { buf.append(" ").append(extra); } buf.append(getCloseBrace()); return buf.toString(); }
java
protected String fixedInput ( String type, String name, Object value, String extra) { StringBuilder buf = new StringBuilder(); buf.append("<input type=\"").append(type).append("\""); buf.append(" name=\"").append(name).append("\""); buf.append(" value=\"").append(value).append("\""); if (!StringUtil.isBlank(extra)) { buf.append(" ").append(extra); } buf.append(getCloseBrace()); return buf.toString(); }
[ "protected", "String", "fixedInput", "(", "String", "type", ",", "String", "name", ",", "Object", "value", ",", "String", "extra", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "\"<input type=\\\"\""...
Generates an input form field with the specified type, name, value and extra attributes. The value is not fetched from the request parameters but is always the value supplied.
[ "Generates", "an", "input", "form", "field", "with", "the", "specified", "type", "name", "value", "and", "extra", "attributes", ".", "The", "value", "is", "not", "fetched", "from", "the", "request", "parameters", "but", "is", "always", "the", "value", "suppl...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L382-L394
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/FormTool.java
FormTool.getValue
protected String getValue (String name, Object defaultValue) { String value = getParameter(name); if (StringUtil.isBlank(value)) { if (defaultValue == null) { value = ""; } else { value = String.valueOf(defaultValue); } } return HTMLUtil.entify(value); }
java
protected String getValue (String name, Object defaultValue) { String value = getParameter(name); if (StringUtil.isBlank(value)) { if (defaultValue == null) { value = ""; } else { value = String.valueOf(defaultValue); } } return HTMLUtil.entify(value); }
[ "protected", "String", "getValue", "(", "String", "name", ",", "Object", "defaultValue", ")", "{", "String", "value", "=", "getParameter", "(", "name", ")", ";", "if", "(", "StringUtil", ".", "isBlank", "(", "value", ")", ")", "{", "if", "(", "defaultVal...
Fetches the requested value from the servlet request and entifies it appropriately.
[ "Fetches", "the", "requested", "value", "from", "the", "servlet", "request", "and", "entifies", "it", "appropriately", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/FormTool.java#L400-L411
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java
JDBCTableSiteIdentifier.insertNewSite
public Site insertNewSite (String siteString) throws PersistenceException { if (_sitesByString.containsKey(siteString)) { return null; } // add it to the db Site site = new Site(); site.siteString = siteString; _repo.insertNewSite(site); // add it to our two mapping tables, taking care to avoid causing enumerateSites() to choke @SuppressWarnings("unchecked") HashMap<String,Site> newStrings = (HashMap<String,Site>)_sitesByString.clone(); HashIntMap<Site> newIds = _sitesById.clone(); newIds.put(site.siteId, site); newStrings.put(site.siteString, site); _sitesByString = newStrings; _sitesById = newIds; return site; }
java
public Site insertNewSite (String siteString) throws PersistenceException { if (_sitesByString.containsKey(siteString)) { return null; } // add it to the db Site site = new Site(); site.siteString = siteString; _repo.insertNewSite(site); // add it to our two mapping tables, taking care to avoid causing enumerateSites() to choke @SuppressWarnings("unchecked") HashMap<String,Site> newStrings = (HashMap<String,Site>)_sitesByString.clone(); HashIntMap<Site> newIds = _sitesById.clone(); newIds.put(site.siteId, site); newStrings.put(site.siteString, site); _sitesByString = newStrings; _sitesById = newIds; return site; }
[ "public", "Site", "insertNewSite", "(", "String", "siteString", ")", "throws", "PersistenceException", "{", "if", "(", "_sitesByString", ".", "containsKey", "(", "siteString", ")", ")", "{", "return", "null", ";", "}", "// add it to the db", "Site", "site", "=",...
Insert a new site into the site table and into this mapping.
[ "Insert", "a", "new", "site", "into", "the", "site", "table", "and", "into", "this", "mapping", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java#L129-L151
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java
JDBCTableSiteIdentifier.checkReloadSites
protected void checkReloadSites () { long now = System.currentTimeMillis(); boolean reload = false; synchronized (this) { reload = (now - _lastReload > RELOAD_INTERVAL); if (reload) { _lastReload = now; } } if (reload) { try { _repo.refreshSiteData(); } catch (PersistenceException pe) { log.warning("Error refreshing site data.", pe); } } }
java
protected void checkReloadSites () { long now = System.currentTimeMillis(); boolean reload = false; synchronized (this) { reload = (now - _lastReload > RELOAD_INTERVAL); if (reload) { _lastReload = now; } } if (reload) { try { _repo.refreshSiteData(); } catch (PersistenceException pe) { log.warning("Error refreshing site data.", pe); } } }
[ "protected", "void", "checkReloadSites", "(", ")", "{", "long", "now", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "boolean", "reload", "=", "false", ";", "synchronized", "(", "this", ")", "{", "reload", "=", "(", "now", "-", "_lastReload", "...
Checks to see if we should reload our sites information from the sites table.
[ "Checks", "to", "see", "if", "we", "should", "reload", "our", "sites", "information", "from", "the", "sites", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/JDBCTableSiteIdentifier.java#L156-L173
train
samskivert/samskivert
src/main/java/com/samskivert/util/MapEntry.java
MapEntry.setValue
public V setValue (V value) { V oldValue = _value; _value = value; return oldValue; }
java
public V setValue (V value) { V oldValue = _value; _value = value; return oldValue; }
[ "public", "V", "setValue", "(", "V", "value", ")", "{", "V", "oldValue", "=", "_value", ";", "_value", "=", "value", ";", "return", "oldValue", ";", "}" ]
from interface Map.Entry
[ "from", "interface", "Map", ".", "Entry" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/MapEntry.java#L41-L46
train
samskivert/samskivert
src/main/java/com/samskivert/util/Comparators.java
Comparators.comparable
@ReplacedBy("com.google.common.collect.Ordering.natural().nullsLast()") public static final <T extends Comparable<?>> Comparator<T> comparable () { @SuppressWarnings("unchecked") Comparator<T> comp = (Comparator<T>)COMPARABLE; return comp; }
java
@ReplacedBy("com.google.common.collect.Ordering.natural().nullsLast()") public static final <T extends Comparable<?>> Comparator<T> comparable () { @SuppressWarnings("unchecked") Comparator<T> comp = (Comparator<T>)COMPARABLE; return comp; }
[ "@", "ReplacedBy", "(", "\"com.google.common.collect.Ordering.natural().nullsLast()\"", ")", "public", "static", "final", "<", "T", "extends", "Comparable", "<", "?", ">", ">", "Comparator", "<", "T", ">", "comparable", "(", ")", "{", "@", "SuppressWarnings", "(",...
code to freak out; I don't entirely understand why
[ "code", "to", "freak", "out", ";", "I", "don", "t", "entirely", "understand", "why" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Comparators.java#L65-L70
train
samskivert/samskivert
src/main/java/com/samskivert/util/ObserverList.java
ObserverList.checkedApply
protected boolean checkedApply (ObserverOp<T> obop, T obs) { try { return obop.apply(obs); } catch (Throwable thrown) { log.warning("ObserverOp choked during notification", "op", obop, "obs", observerForLog(obs), thrown); // if they booched it, definitely don't remove them return true; } }
java
protected boolean checkedApply (ObserverOp<T> obop, T obs) { try { return obop.apply(obs); } catch (Throwable thrown) { log.warning("ObserverOp choked during notification", "op", obop, "obs", observerForLog(obs), thrown); // if they booched it, definitely don't remove them return true; } }
[ "protected", "boolean", "checkedApply", "(", "ObserverOp", "<", "T", ">", "obop", ",", "T", "obs", ")", "{", "try", "{", "return", "obop", ".", "apply", "(", "obs", ")", ";", "}", "catch", "(", "Throwable", "thrown", ")", "{", "log", ".", "warning", ...
Applies the operation to the observer, catching and logging any exceptions thrown in the process.
[ "Applies", "the", "operation", "to", "the", "observer", "catching", "and", "logging", "any", "exceptions", "thrown", "in", "the", "process", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ObserverList.java#L198-L208
train
samskivert/samskivert
src/main/java/com/samskivert/util/CheapIntMap.java
CheapIntMap.get
public Object get (int key) { int size = _keys.length, start = key % size; for (int ii = 0; ii < size; ii++) { int idx = (ii + start) % size; if (_keys[idx] == key) { return _values[idx]; } } return null; }
java
public Object get (int key) { int size = _keys.length, start = key % size; for (int ii = 0; ii < size; ii++) { int idx = (ii + start) % size; if (_keys[idx] == key) { return _values[idx]; } } return null; }
[ "public", "Object", "get", "(", "int", "key", ")", "{", "int", "size", "=", "_keys", ".", "length", ",", "start", "=", "key", "%", "size", ";", "for", "(", "int", "ii", "=", "0", ";", "ii", "<", "size", ";", "ii", "++", ")", "{", "int", "idx"...
Returns the object with the specified key, null if no object exists in the table with that key.
[ "Returns", "the", "object", "with", "the", "specified", "key", "null", "if", "no", "object", "exists", "in", "the", "table", "with", "that", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/CheapIntMap.java#L60-L70
train
samskivert/samskivert
src/main/java/com/samskivert/util/CheapIntMap.java
CheapIntMap.remove
public Object remove (int key) { int size = _keys.length, start = key % size; for (int ii = 0; ii < size; ii++) { int idx = (ii + start) % size; if (_keys[idx] == key) { Object value = _values[idx]; _keys[idx] = -1; _values[idx] = null; return value; } } return null; }
java
public Object remove (int key) { int size = _keys.length, start = key % size; for (int ii = 0; ii < size; ii++) { int idx = (ii + start) % size; if (_keys[idx] == key) { Object value = _values[idx]; _keys[idx] = -1; _values[idx] = null; return value; } } return null; }
[ "public", "Object", "remove", "(", "int", "key", ")", "{", "int", "size", "=", "_keys", ".", "length", ",", "start", "=", "key", "%", "size", ";", "for", "(", "int", "ii", "=", "0", ";", "ii", "<", "size", ";", "ii", "++", ")", "{", "int", "i...
Removes the mapping associated with the specified key. The previous value of the mapping will be returned.
[ "Removes", "the", "mapping", "associated", "with", "the", "specified", "key", ".", "The", "previous", "value", "of", "the", "mapping", "will", "be", "returned", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/CheapIntMap.java#L76-L89
train
samskivert/samskivert
src/main/java/com/samskivert/util/CheapIntMap.java
CheapIntMap.size
public int size () { int size = 0; for (int ii = 0, ll = _keys.length; ii < ll; ii++) { if (_keys[ii] != -1) { size++; } } return size; }
java
public int size () { int size = 0; for (int ii = 0, ll = _keys.length; ii < ll; ii++) { if (_keys[ii] != -1) { size++; } } return size; }
[ "public", "int", "size", "(", ")", "{", "int", "size", "=", "0", ";", "for", "(", "int", "ii", "=", "0", ",", "ll", "=", "_keys", ".", "length", ";", "ii", "<", "ll", ";", "ii", "++", ")", "{", "if", "(", "_keys", "[", "ii", "]", "!=", "-...
Returns the number of mappings in this table.
[ "Returns", "the", "number", "of", "mappings", "in", "this", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/CheapIntMap.java#L103-L112
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.getParameterNames
public static Iterable<String> getParameterNames (HttpServletRequest req) { List<String> params = new ArrayList<String>(); Enumeration<?> iter = req.getParameterNames(); while (iter.hasMoreElements()) { params.add((String)iter.nextElement()); } return params; }
java
public static Iterable<String> getParameterNames (HttpServletRequest req) { List<String> params = new ArrayList<String>(); Enumeration<?> iter = req.getParameterNames(); while (iter.hasMoreElements()) { params.add((String)iter.nextElement()); } return params; }
[ "public", "static", "Iterable", "<", "String", ">", "getParameterNames", "(", "HttpServletRequest", "req", ")", "{", "List", "<", "String", ">", "params", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "Enumeration", "<", "?", ">", "iter", "...
Returns the names of the parameters of the supplied request in a civilized format.
[ "Returns", "the", "names", "of", "the", "parameters", "of", "the", "supplied", "request", "in", "a", "civilized", "format", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L44-L52
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.requireFloatParameter
public static float requireFloatParameter ( HttpServletRequest req, String name, String invalidDataMessage) throws DataValidationException { return parseFloatParameter(getParameter(req, name, false), invalidDataMessage); }
java
public static float requireFloatParameter ( HttpServletRequest req, String name, String invalidDataMessage) throws DataValidationException { return parseFloatParameter(getParameter(req, name, false), invalidDataMessage); }
[ "public", "static", "float", "requireFloatParameter", "(", "HttpServletRequest", "req", ",", "String", "name", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "return", "parseFloatParameter", "(", "getParameter", "(", "req", ",", "n...
Fetches the supplied parameter from the request and converts it to a float. If the parameter does not exist or is not a well-formed float, a data validation exception is thrown with the supplied message.
[ "Fetches", "the", "supplied", "parameter", "from", "the", "request", "and", "converts", "it", "to", "a", "float", ".", "If", "the", "parameter", "does", "not", "exist", "or", "is", "not", "a", "well", "-", "formed", "float", "a", "data", "validation", "e...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L74-L79
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.getIntParameters
public static IntSet getIntParameters ( HttpServletRequest req, String name, String invalidDataMessage) throws DataValidationException { IntSet ints = new ArrayIntSet(); String[] values = req.getParameterValues(name); if (values != null) { for (int ii = 0; ii < values.length; ii++) { if (!StringUtil.isBlank(values[ii])) { ints.add(parseIntParameter(values[ii], invalidDataMessage)); } } } return ints; }
java
public static IntSet getIntParameters ( HttpServletRequest req, String name, String invalidDataMessage) throws DataValidationException { IntSet ints = new ArrayIntSet(); String[] values = req.getParameterValues(name); if (values != null) { for (int ii = 0; ii < values.length; ii++) { if (!StringUtil.isBlank(values[ii])) { ints.add(parseIntParameter(values[ii], invalidDataMessage)); } } } return ints; }
[ "public", "static", "IntSet", "getIntParameters", "(", "HttpServletRequest", "req", ",", "String", "name", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "IntSet", "ints", "=", "new", "ArrayIntSet", "(", ")", ";", "String", "["...
Fetches all the values from the request with the specified name and converts them to an IntSet. If the parameter does not exist or is not a well-formed integer, a data validation exception is thrown with the supplied message.
[ "Fetches", "all", "the", "values", "from", "the", "request", "with", "the", "specified", "name", "and", "converts", "them", "to", "an", "IntSet", ".", "If", "the", "parameter", "does", "not", "exist", "or", "is", "not", "a", "well", "-", "formed", "integ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L125-L139
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.getParameters
public static Set<String> getParameters (HttpServletRequest req, String name) { Set<String> set = new HashSet<String>(); String[] values = req.getParameterValues(name); if (values != null) { for (int ii = 0; ii < values.length; ii++) { if (!StringUtil.isBlank(values[ii])) { set.add(values[ii]); } } } return set; }
java
public static Set<String> getParameters (HttpServletRequest req, String name) { Set<String> set = new HashSet<String>(); String[] values = req.getParameterValues(name); if (values != null) { for (int ii = 0; ii < values.length; ii++) { if (!StringUtil.isBlank(values[ii])) { set.add(values[ii]); } } } return set; }
[ "public", "static", "Set", "<", "String", ">", "getParameters", "(", "HttpServletRequest", "req", ",", "String", "name", ")", "{", "Set", "<", "String", ">", "set", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "String", "[", "]", "values",...
Fetches all the values from the request with the specified name and converts them to a Set.
[ "Fetches", "all", "the", "values", "from", "the", "request", "with", "the", "specified", "name", "and", "converts", "them", "to", "a", "Set", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L144-L156
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.requireParameter
public static String requireParameter ( HttpServletRequest req, String name, String missingDataMessage) throws DataValidationException { String value = getParameter(req, name, true); if (StringUtil.isBlank(value)) { throw new DataValidationException(missingDataMessage); } return value; }
java
public static String requireParameter ( HttpServletRequest req, String name, String missingDataMessage) throws DataValidationException { String value = getParameter(req, name, true); if (StringUtil.isBlank(value)) { throw new DataValidationException(missingDataMessage); } return value; }
[ "public", "static", "String", "requireParameter", "(", "HttpServletRequest", "req", ",", "String", "name", ",", "String", "missingDataMessage", ")", "throws", "DataValidationException", "{", "String", "value", "=", "getParameter", "(", "req", ",", "name", ",", "tr...
Fetches the supplied parameter from the request. If the parameter does not exist, a data validation exception is thrown with the supplied message.
[ "Fetches", "the", "supplied", "parameter", "from", "the", "request", ".", "If", "the", "parameter", "does", "not", "exist", "a", "data", "validation", "exception", "is", "thrown", "with", "the", "supplied", "message", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L204-L213
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.requireParameter
public static String requireParameter ( HttpServletRequest req, String name, String missingDataMessage, int maxLength) throws DataValidationException { return StringUtil.truncate( requireParameter(req, name, missingDataMessage), maxLength); }
java
public static String requireParameter ( HttpServletRequest req, String name, String missingDataMessage, int maxLength) throws DataValidationException { return StringUtil.truncate( requireParameter(req, name, missingDataMessage), maxLength); }
[ "public", "static", "String", "requireParameter", "(", "HttpServletRequest", "req", ",", "String", "name", ",", "String", "missingDataMessage", ",", "int", "maxLength", ")", "throws", "DataValidationException", "{", "return", "StringUtil", ".", "truncate", "(", "req...
Fetches the supplied parameter from the request and ensures that it is no longer than maxLength. Note that use of this method could be dangerous. If the specified HttpServletRequest is used to pre-fill in values on a form, it will not know to use the truncated version. A user may enter a version that is too long, your code will see a truncated version, but then the user will see on the page again the full-length reproduction of what they typed in. Be careful.
[ "Fetches", "the", "supplied", "parameter", "from", "the", "request", "and", "ensures", "that", "it", "is", "no", "longer", "than", "maxLength", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L224-L230
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.parameterEquals
public static boolean parameterEquals (HttpServletRequest req, String name, String value) { return value.equals(getParameter(req, name, false)); }
java
public static boolean parameterEquals (HttpServletRequest req, String name, String value) { return value.equals(getParameter(req, name, false)); }
[ "public", "static", "boolean", "parameterEquals", "(", "HttpServletRequest", "req", ",", "String", "name", ",", "String", "value", ")", "{", "return", "value", ".", "equals", "(", "getParameter", "(", "req", ",", "name", ",", "false", ")", ")", ";", "}" ]
Returns true if the specified parameter is equal to the supplied value. If the parameter is not set in the request, false is returned. @param name The parameter whose value should be compared with the supplied value. @param value The value to which the parameter may be equal. This should not be null. @return true if the specified parameter is equal to the supplied parameter, false otherwise.
[ "Returns", "true", "if", "the", "specified", "parameter", "is", "equal", "to", "the", "supplied", "value", ".", "If", "the", "parameter", "is", "not", "set", "in", "the", "request", "false", "is", "returned", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L315-L318
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.parseIntParameter
protected static int parseIntParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Integer.parseInt(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
java
protected static int parseIntParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Integer.parseInt(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
[ "protected", "static", "int", "parseIntParameter", "(", "String", "value", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "try", "{", "return", "Integer", ".", "parseInt", "(", "value", ")", ";", "}", "catch", "(", "NumberFor...
Internal method to parse integer values.
[ "Internal", "method", "to", "parse", "integer", "values", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L323-L331
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.parseLongParameter
protected static long parseLongParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Long.parseLong(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
java
protected static long parseLongParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Long.parseLong(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
[ "protected", "static", "long", "parseLongParameter", "(", "String", "value", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "try", "{", "return", "Long", ".", "parseLong", "(", "value", ")", ";", "}", "catch", "(", "NumberFor...
Internal method to parse long values.
[ "Internal", "method", "to", "parse", "long", "values", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L336-L344
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.parseFloatParameter
protected static float parseFloatParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Float.parseFloat(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
java
protected static float parseFloatParameter (String value, String invalidDataMessage) throws DataValidationException { try { return Float.parseFloat(value); } catch (NumberFormatException nfe) { throw new DataValidationException(invalidDataMessage); } }
[ "protected", "static", "float", "parseFloatParameter", "(", "String", "value", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "try", "{", "return", "Float", ".", "parseFloat", "(", "value", ")", ";", "}", "catch", "(", "Numbe...
Internal method to parse a float value.
[ "Internal", "method", "to", "parse", "a", "float", "value", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L349-L357
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ParameterUtil.java
ParameterUtil.parseDateParameter
protected static Date parseDateParameter (String value, String invalidDataMessage) throws DataValidationException { try { synchronized (_dparser) { return _dparser.parse(value); } } catch (ParseException pe) { throw new DataValidationException(invalidDataMessage); } }
java
protected static Date parseDateParameter (String value, String invalidDataMessage) throws DataValidationException { try { synchronized (_dparser) { return _dparser.parse(value); } } catch (ParseException pe) { throw new DataValidationException(invalidDataMessage); } }
[ "protected", "static", "Date", "parseDateParameter", "(", "String", "value", ",", "String", "invalidDataMessage", ")", "throws", "DataValidationException", "{", "try", "{", "synchronized", "(", "_dparser", ")", "{", "return", "_dparser", ".", "parse", "(", "value"...
Internal method to parse a date.
[ "Internal", "method", "to", "parse", "a", "date", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ParameterUtil.java#L362-L372
train
samskivert/samskivert
src/main/java/com/samskivert/util/RandomUtil.java
RandomUtil.pickRandom
public static <T> T pickRandom (T[] values) { return (values == null || values.length == 0) ? null : values[getInt(values.length)]; }
java
public static <T> T pickRandom (T[] values) { return (values == null || values.length == 0) ? null : values[getInt(values.length)]; }
[ "public", "static", "<", "T", ">", "T", "pickRandom", "(", "T", "[", "]", "values", ")", "{", "return", "(", "values", "==", "null", "||", "values", ".", "length", "==", "0", ")", "?", "null", ":", "values", "[", "getInt", "(", "values", ".", "le...
Picks a random object from the supplied array of values. Even weight is given to all elements of the array. @return a randomly selected item or null if the array is null or of length zero.
[ "Picks", "a", "random", "object", "from", "the", "supplied", "array", "of", "values", ".", "Even", "weight", "is", "given", "to", "all", "elements", "of", "the", "array", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/RandomUtil.java#L283-L286
train
samskivert/samskivert
src/main/java/com/samskivert/util/RandomUtil.java
RandomUtil.pickRandom
public static <T> T pickRandom (List<T> values) { int size = values.size(); if (size == 0) { throw new IllegalArgumentException( "Must have at least one element [size=" + size + "]"); } return values.get(getInt(size)); }
java
public static <T> T pickRandom (List<T> values) { int size = values.size(); if (size == 0) { throw new IllegalArgumentException( "Must have at least one element [size=" + size + "]"); } return values.get(getInt(size)); }
[ "public", "static", "<", "T", ">", "T", "pickRandom", "(", "List", "<", "T", ">", "values", ")", "{", "int", "size", "=", "values", ".", "size", "(", ")", ";", "if", "(", "size", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(",...
Picks a random object from the supplied List @return a randomly selected item.
[ "Picks", "a", "random", "object", "from", "the", "supplied", "List" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/RandomUtil.java#L334-L342
train
samskivert/samskivert
src/main/java/com/samskivert/util/ResultListenerList.java
ResultListenerList.requestCompleted
public void requestCompleted (final T result) { apply(new ObserverOp<ResultListener<T>>() { public boolean apply (ResultListener<T> observer) { observer.requestCompleted(result); return true; } }); }
java
public void requestCompleted (final T result) { apply(new ObserverOp<ResultListener<T>>() { public boolean apply (ResultListener<T> observer) { observer.requestCompleted(result); return true; } }); }
[ "public", "void", "requestCompleted", "(", "final", "T", "result", ")", "{", "apply", "(", "new", "ObserverOp", "<", "ResultListener", "<", "T", ">", ">", "(", ")", "{", "public", "boolean", "apply", "(", "ResultListener", "<", "T", ">", "observer", ")",...
Multiplex a requestCompleted response to all the ResultListeners in this list.
[ "Multiplex", "a", "requestCompleted", "response", "to", "all", "the", "ResultListeners", "in", "this", "list", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ResultListenerList.java#L34-L42
train
samskivert/samskivert
src/main/java/com/samskivert/util/ResultListenerList.java
ResultListenerList.requestFailed
public void requestFailed (final Exception cause) { apply(new ObserverOp<ResultListener<T>>() { public boolean apply (ResultListener<T> observer) { observer.requestFailed(cause); return true; } }); }
java
public void requestFailed (final Exception cause) { apply(new ObserverOp<ResultListener<T>>() { public boolean apply (ResultListener<T> observer) { observer.requestFailed(cause); return true; } }); }
[ "public", "void", "requestFailed", "(", "final", "Exception", "cause", ")", "{", "apply", "(", "new", "ObserverOp", "<", "ResultListener", "<", "T", ">", ">", "(", ")", "{", "public", "boolean", "apply", "(", "ResultListener", "<", "T", ">", "observer", ...
Multiplex a requestFailed response to all the ResultListeners in this list.
[ "Multiplex", "a", "requestFailed", "response", "to", "all", "the", "ResultListeners", "in", "this", "list", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ResultListenerList.java#L48-L56
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.filterColors
public static String filterColors (String txt) { if (txt == null) return null; return COLOR_PATTERN.matcher(txt).replaceAll(""); }
java
public static String filterColors (String txt) { if (txt == null) return null; return COLOR_PATTERN.matcher(txt).replaceAll(""); }
[ "public", "static", "String", "filterColors", "(", "String", "txt", ")", "{", "if", "(", "txt", "==", "null", ")", "return", "null", ";", "return", "COLOR_PATTERN", ".", "matcher", "(", "txt", ")", ".", "replaceAll", "(", "\"\"", ")", ";", "}" ]
Filter out any color tags from the specified text.
[ "Filter", "out", "any", "color", "tags", "from", "the", "specified", "text", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L57-L61
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.escapeColors
public static String escapeColors (String txt) { if (txt == null) return null; return COLOR_PATTERN.matcher(txt).replaceAll("#''$1"); }
java
public static String escapeColors (String txt) { if (txt == null) return null; return COLOR_PATTERN.matcher(txt).replaceAll("#''$1"); }
[ "public", "static", "String", "escapeColors", "(", "String", "txt", ")", "{", "if", "(", "txt", "==", "null", ")", "return", "null", ";", "return", "COLOR_PATTERN", ".", "matcher", "(", "txt", ")", ".", "replaceAll", "(", "\"#''$1\"", ")", ";", "}" ]
Escape any special tags so that they won't be interpreted by the label.
[ "Escape", "any", "special", "tags", "so", "that", "they", "won", "t", "be", "interpreted", "by", "the", "label", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L66-L70
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.unescapeColors
private static String unescapeColors (String txt, boolean restore) { if (txt == null) return null; String prefix = restore ? "#" : "%"; return ESCAPED_PATTERN.matcher(txt).replaceAll(prefix + "$1"); }
java
private static String unescapeColors (String txt, boolean restore) { if (txt == null) return null; String prefix = restore ? "#" : "%"; return ESCAPED_PATTERN.matcher(txt).replaceAll(prefix + "$1"); }
[ "private", "static", "String", "unescapeColors", "(", "String", "txt", ",", "boolean", "restore", ")", "{", "if", "(", "txt", "==", "null", ")", "return", "null", ";", "String", "prefix", "=", "restore", "?", "\"#\"", ":", "\"%\"", ";", "return", "ESCAPE...
Un-escape escaped tags so that they look as the users intended.
[ "Un", "-", "escape", "escaped", "tags", "so", "that", "they", "look", "as", "the", "users", "intended", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L84-L89
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.setText
public boolean setText (String text) { // the Java text stuff freaks out in a variety of ways if it is asked to deal with the // empty string, so we fake blank labels by just using a space if (StringUtil.isBlank(text)) { text = " "; } // if there is no change then avoid doing anything if (text.equals((_rawText == null) ? _text : _rawText)) { return false; } // _text should contain the text without any tags _text = filterColors(text); // _rawText will be null if there are no tags _rawText = text.equals(_text) ? null : text; // if what we were passed contains escaped color tags, unescape them _text = unescapeColors(_text, true); if (_rawText != null) { _rawText = unescapeColors(_rawText, false); } invalidate("setText"); return true; }
java
public boolean setText (String text) { // the Java text stuff freaks out in a variety of ways if it is asked to deal with the // empty string, so we fake blank labels by just using a space if (StringUtil.isBlank(text)) { text = " "; } // if there is no change then avoid doing anything if (text.equals((_rawText == null) ? _text : _rawText)) { return false; } // _text should contain the text without any tags _text = filterColors(text); // _rawText will be null if there are no tags _rawText = text.equals(_text) ? null : text; // if what we were passed contains escaped color tags, unescape them _text = unescapeColors(_text, true); if (_rawText != null) { _rawText = unescapeColors(_rawText, false); } invalidate("setText"); return true; }
[ "public", "boolean", "setText", "(", "String", "text", ")", "{", "// the Java text stuff freaks out in a variety of ways if it is asked to deal with the", "// empty string, so we fake blank labels by just using a space", "if", "(", "StringUtil", ".", "isBlank", "(", "text", ")", ...
Sets the text to be displayed by this label. <p> This should be followed by a call to {@link #layout} before a call is made to {@link #render} as this method invalidates the layout information. @return true if the text changed as a result of being set, false if the label was already displaying the requested text.
[ "Sets", "the", "text", "to", "be", "displayed", "by", "this", "label", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L144-L170
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.setTargetWidth
public void setTargetWidth (int targetWidth) { if (targetWidth <= 0) { throw new IllegalArgumentException( "Invalid target width '" + targetWidth + "'"); } _constraints.width = targetWidth; _constraints.height = 0; invalidate("setTargetWidth"); }
java
public void setTargetWidth (int targetWidth) { if (targetWidth <= 0) { throw new IllegalArgumentException( "Invalid target width '" + targetWidth + "'"); } _constraints.width = targetWidth; _constraints.height = 0; invalidate("setTargetWidth"); }
[ "public", "void", "setTargetWidth", "(", "int", "targetWidth", ")", "{", "if", "(", "targetWidth", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid target width '\"", "+", "targetWidth", "+", "\"'\"", ")", ";", "}", "_constraints"...
Sets the target width for this label. Text will be wrapped to fit into this width, forcibly breaking words on character boundaries if a single word is too long to fit into the target width. Calling this method will annul any previously established target height as we must have one degree of freedom in which to maneuver. <p> This should be followed by a call to {@link #layout} before a call is made to {@link #render} as this method invalidates the layout information.
[ "Sets", "the", "target", "width", "for", "this", "label", ".", "Text", "will", "be", "wrapped", "to", "fit", "into", "this", "width", "forcibly", "breaking", "words", "on", "character", "boundaries", "if", "a", "single", "word", "is", "too", "long", "to", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L279-L288
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.setTargetHeight
public void setTargetHeight (int targetHeight) { if (targetHeight <= 0) { throw new IllegalArgumentException( "Invalid target height '" + targetHeight + "'"); } _constraints.width = 0; _constraints.height = targetHeight; invalidate("setTargetHeight"); }
java
public void setTargetHeight (int targetHeight) { if (targetHeight <= 0) { throw new IllegalArgumentException( "Invalid target height '" + targetHeight + "'"); } _constraints.width = 0; _constraints.height = targetHeight; invalidate("setTargetHeight"); }
[ "public", "void", "setTargetHeight", "(", "int", "targetHeight", ")", "{", "if", "(", "targetHeight", "<=", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Invalid target height '\"", "+", "targetHeight", "+", "\"'\"", ")", ";", "}", "_constra...
Sets the target height for this label. A simple algorithm will be used to balance the width of the text in order that there are only as many lines of text as fit into the target height. If rendering the label as a single line of text causes it to be taller than the target height, we simply render ourselves anyway. Calling this method will annul any previously established target width as we must have one degree of freedom in which to maneuver. <p> This should be followed by a call to {@link #layout} before a call is made to {@link #render} as this method invalidates the layout information.
[ "Sets", "the", "target", "height", "for", "this", "label", ".", "A", "simple", "algorithm", "will", "be", "used", "to", "balance", "the", "width", "of", "the", "text", "in", "order", "that", "there", "are", "only", "as", "many", "lines", "of", "text", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L301-L310
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.textIterator
protected AttributedCharacterIterator textIterator (Graphics2D gfx) { // first set up any attributes that apply to the entire text Font font = (_font == null) ? gfx.getFont() : _font; HashMap<TextAttribute,Object> map = new HashMap<TextAttribute,Object>(); map.put(TextAttribute.FONT, font); if ((_style & UNDERLINE) != 0) { map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL); } AttributedString text = new AttributedString(_text, map); addAttributes(text); return text.getIterator(); }
java
protected AttributedCharacterIterator textIterator (Graphics2D gfx) { // first set up any attributes that apply to the entire text Font font = (_font == null) ? gfx.getFont() : _font; HashMap<TextAttribute,Object> map = new HashMap<TextAttribute,Object>(); map.put(TextAttribute.FONT, font); if ((_style & UNDERLINE) != 0) { map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL); } AttributedString text = new AttributedString(_text, map); addAttributes(text); return text.getIterator(); }
[ "protected", "AttributedCharacterIterator", "textIterator", "(", "Graphics2D", "gfx", ")", "{", "// first set up any attributes that apply to the entire text", "Font", "font", "=", "(", "_font", "==", "null", ")", "?", "gfx", ".", "getFont", "(", ")", ":", "_font", ...
Constructs an attributed character iterator with our text and the appropriate font.
[ "Constructs", "an", "attributed", "character", "iterator", "with", "our", "text", "and", "the", "appropriate", "font", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L611-L624
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.addAttributes
protected void addAttributes (AttributedString text) { // add any color attributes for specific segments if (_rawText != null) { Matcher m = COLOR_PATTERN.matcher(_rawText); int startSeg = 0, endSeg = 0; Color lastColor = null; while (m.find()) { // color the segment just passed endSeg += m.start(); if (lastColor != null) { text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, endSeg); } // parse the tag: start or end a color String group = m.group(1); if ("x".equalsIgnoreCase(group)) { lastColor = null; } else { lastColor = new Color(Integer.parseInt(group, 16)); } // prepare for the next segment startSeg = endSeg; // Subtract the end of the segment from endSeg so that when we add the start of the // next match we have actually added the length of the characters in between. endSeg -= m.end(); } // apply any final color to the tail segment if (lastColor != null) { text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, _text.length()); } } }
java
protected void addAttributes (AttributedString text) { // add any color attributes for specific segments if (_rawText != null) { Matcher m = COLOR_PATTERN.matcher(_rawText); int startSeg = 0, endSeg = 0; Color lastColor = null; while (m.find()) { // color the segment just passed endSeg += m.start(); if (lastColor != null) { text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, endSeg); } // parse the tag: start or end a color String group = m.group(1); if ("x".equalsIgnoreCase(group)) { lastColor = null; } else { lastColor = new Color(Integer.parseInt(group, 16)); } // prepare for the next segment startSeg = endSeg; // Subtract the end of the segment from endSeg so that when we add the start of the // next match we have actually added the length of the characters in between. endSeg -= m.end(); } // apply any final color to the tail segment if (lastColor != null) { text.addAttribute(TextAttribute.FOREGROUND, lastColor, startSeg, _text.length()); } } }
[ "protected", "void", "addAttributes", "(", "AttributedString", "text", ")", "{", "// add any color attributes for specific segments", "if", "(", "_rawText", "!=", "null", ")", "{", "Matcher", "m", "=", "COLOR_PATTERN", ".", "matcher", "(", "_rawText", ")", ";", "i...
Add any attributes to the text.
[ "Add", "any", "attributes", "to", "the", "text", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L629-L662
train
samskivert/samskivert
src/main/java/com/samskivert/swing/Label.java
Label.getBounds
protected Rectangle2D getBounds (TextLayout layout) { if (RunAnywhere.isMacOS()) { return layout.getOutline(null).getBounds(); } else { return layout.getBounds(); } }
java
protected Rectangle2D getBounds (TextLayout layout) { if (RunAnywhere.isMacOS()) { return layout.getOutline(null).getBounds(); } else { return layout.getBounds(); } }
[ "protected", "Rectangle2D", "getBounds", "(", "TextLayout", "layout", ")", "{", "if", "(", "RunAnywhere", ".", "isMacOS", "(", ")", ")", "{", "return", "layout", ".", "getOutline", "(", "null", ")", ".", "getBounds", "(", ")", ";", "}", "else", "{", "r...
Gets the bounds of the supplied text layout in a way that works around the various befuckeries that currently happen on the Mac.
[ "Gets", "the", "bounds", "of", "the", "supplied", "text", "layout", "in", "a", "way", "that", "works", "around", "the", "various", "befuckeries", "that", "currently", "happen", "on", "the", "Mac", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/Label.java#L685-L692
train
nextreports/nextreports-engine
src/ro/nextreports/engine/queryexec/util/QueryResultPrinter.java
QueryResultPrinter.overwrite
static void overwrite(StringBuffer sb, int pos, String s) { int len = s.length(); for (int i = 0; i < len; i++) { sb.setCharAt(pos + i, s.charAt(i)); } }
java
static void overwrite(StringBuffer sb, int pos, String s) { int len = s.length(); for (int i = 0; i < len; i++) { sb.setCharAt(pos + i, s.charAt(i)); } }
[ "static", "void", "overwrite", "(", "StringBuffer", "sb", ",", "int", "pos", ",", "String", "s", ")", "{", "int", "len", "=", "s", ".", "length", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{",...
This utility method is used when printing the table of results.
[ "This", "utility", "method", "is", "used", "when", "printing", "the", "table", "of", "results", "." ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/queryexec/util/QueryResultPrinter.java#L154-L159
train
samskivert/samskivert
src/main/java/com/samskivert/xml/XMLUtil.java
XMLUtil.parse
public static void parse (DefaultHandler handler, InputStream in) throws IOException, ParserConfigurationException, SAXException { XMLReader xr = _pfactory.newSAXParser().getXMLReader(); xr.setContentHandler(handler); xr.setErrorHandler(handler); xr.parse(new InputSource(in)); }
java
public static void parse (DefaultHandler handler, InputStream in) throws IOException, ParserConfigurationException, SAXException { XMLReader xr = _pfactory.newSAXParser().getXMLReader(); xr.setContentHandler(handler); xr.setErrorHandler(handler); xr.parse(new InputSource(in)); }
[ "public", "static", "void", "parse", "(", "DefaultHandler", "handler", ",", "InputStream", "in", ")", "throws", "IOException", ",", "ParserConfigurationException", ",", "SAXException", "{", "XMLReader", "xr", "=", "_pfactory", ".", "newSAXParser", "(", ")", ".", ...
Parse the XML data in the given input stream, using the specified handler object as both the content and error handler. @param handler the SAX event handler @param in the input stream containing the XML to be parsed
[ "Parse", "the", "XML", "data", "in", "the", "given", "input", "stream", "using", "the", "specified", "handler", "object", "as", "both", "the", "content", "and", "error", "handler", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/xml/XMLUtil.java#L31-L40
train
samskivert/samskivert
src/main/java/com/samskivert/util/LogBuilder.java
LogBuilder.append
public LogBuilder append (Object... args) { if (args != null && args.length > 1) { for (int ii = 0, nn = args.length - (args.length % 2); ii < nn; ii += 2) { if (_hasArgs) { _log.append(", "); } else { if (_log.length() > 0) { // only need a space if we have a message _log.append(' '); } _log.append('['); _hasArgs = true; } _log.append(args[ii]).append('='); try { _log.append(StringUtil.toString(args[ii + 1])); } catch (Throwable t) { _log.append("<toString() failure: ").append(t).append('>'); } } } return this; }
java
public LogBuilder append (Object... args) { if (args != null && args.length > 1) { for (int ii = 0, nn = args.length - (args.length % 2); ii < nn; ii += 2) { if (_hasArgs) { _log.append(", "); } else { if (_log.length() > 0) { // only need a space if we have a message _log.append(' '); } _log.append('['); _hasArgs = true; } _log.append(args[ii]).append('='); try { _log.append(StringUtil.toString(args[ii + 1])); } catch (Throwable t) { _log.append("<toString() failure: ").append(t).append('>'); } } } return this; }
[ "public", "LogBuilder", "append", "(", "Object", "...", "args", ")", "{", "if", "(", "args", "!=", "null", "&&", "args", ".", "length", ">", "1", ")", "{", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "args", ".", "length", "-", "(", "arg...
Adds the given key value pairs to the log.
[ "Adds", "the", "given", "key", "value", "pairs", "to", "the", "log", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/LogBuilder.java#L35-L58
train
samskivert/samskivert
src/main/java/com/samskivert/util/AuditLogger.java
AuditLogger.openLog
protected void openLog (boolean freakout) { try { // create our file writer to which we'll log FileOutputStream fout = new FileOutputStream(_logPath, true); OutputStreamWriter writer = new OutputStreamWriter(fout, "UTF8"); _logWriter = new PrintWriter(new BufferedWriter(writer), true); // log a standard message log("log_opened " + _logPath); } catch (IOException ioe) { String errmsg = "Unable to open audit log '" + _logPath + "'"; if (freakout) { throw new RuntimeException(errmsg, ioe); } else { log.warning(errmsg, "ioe", ioe); } } }
java
protected void openLog (boolean freakout) { try { // create our file writer to which we'll log FileOutputStream fout = new FileOutputStream(_logPath, true); OutputStreamWriter writer = new OutputStreamWriter(fout, "UTF8"); _logWriter = new PrintWriter(new BufferedWriter(writer), true); // log a standard message log("log_opened " + _logPath); } catch (IOException ioe) { String errmsg = "Unable to open audit log '" + _logPath + "'"; if (freakout) { throw new RuntimeException(errmsg, ioe); } else { log.warning(errmsg, "ioe", ioe); } } }
[ "protected", "void", "openLog", "(", "boolean", "freakout", ")", "{", "try", "{", "// create our file writer to which we'll log", "FileOutputStream", "fout", "=", "new", "FileOutputStream", "(", "_logPath", ",", "true", ")", ";", "OutputStreamWriter", "writer", "=", ...
Opens our log file, sets up our print writer and writes a message to it indicating that it was opened.
[ "Opens", "our", "log", "file", "sets", "up", "our", "print", "writer", "and", "writes", "a", "message", "to", "it", "indicating", "that", "it", "was", "opened", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/AuditLogger.java#L102-L121
train
samskivert/samskivert
src/main/java/com/samskivert/util/AuditLogger.java
AuditLogger.checkRollOver
protected synchronized void checkRollOver () { // check to see if we should roll over the log String newDayStamp = _dayFormat.format(new Date()); // hey! we need to roll it over! if (!newDayStamp.equals(_dayStamp)) { log("log_closed"); _logWriter.close(); _logWriter = null; // rename the old file String npath = _logPath.getPath() + "." + _dayStamp; if (!_logPath.renameTo(new File(npath))) { log.warning("Failed to rename audit log file", "path", _logPath, "npath", npath); } // open our new log file openLog(false); // and set the next day stamp _dayStamp = newDayStamp; } scheduleNextRolloverCheck(); }
java
protected synchronized void checkRollOver () { // check to see if we should roll over the log String newDayStamp = _dayFormat.format(new Date()); // hey! we need to roll it over! if (!newDayStamp.equals(_dayStamp)) { log("log_closed"); _logWriter.close(); _logWriter = null; // rename the old file String npath = _logPath.getPath() + "." + _dayStamp; if (!_logPath.renameTo(new File(npath))) { log.warning("Failed to rename audit log file", "path", _logPath, "npath", npath); } // open our new log file openLog(false); // and set the next day stamp _dayStamp = newDayStamp; } scheduleNextRolloverCheck(); }
[ "protected", "synchronized", "void", "checkRollOver", "(", ")", "{", "// check to see if we should roll over the log", "String", "newDayStamp", "=", "_dayFormat", ".", "format", "(", "new", "Date", "(", ")", ")", ";", "// hey! we need to roll it over!", "if", "(", "!"...
Check to see if it's time to roll over the log file.
[ "Check", "to", "see", "if", "it", "s", "time", "to", "roll", "over", "the", "log", "file", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/AuditLogger.java#L126-L151
train
samskivert/samskivert
src/main/java/com/samskivert/util/AuditLogger.java
AuditLogger.scheduleNextRolloverCheck
protected void scheduleNextRolloverCheck () { Calendar cal = Calendar.getInstance(); // schedule the next check for the next hour mark long nextCheck = (1000L - cal.get(Calendar.MILLISECOND)) + (59L - cal.get(Calendar.SECOND)) * 1000L + (59L - cal.get(Calendar.MINUTE)) * (1000L * 60L); _rollover.schedule(nextCheck); }
java
protected void scheduleNextRolloverCheck () { Calendar cal = Calendar.getInstance(); // schedule the next check for the next hour mark long nextCheck = (1000L - cal.get(Calendar.MILLISECOND)) + (59L - cal.get(Calendar.SECOND)) * 1000L + (59L - cal.get(Calendar.MINUTE)) * (1000L * 60L); _rollover.schedule(nextCheck); }
[ "protected", "void", "scheduleNextRolloverCheck", "(", ")", "{", "Calendar", "cal", "=", "Calendar", ".", "getInstance", "(", ")", ";", "// schedule the next check for the next hour mark", "long", "nextCheck", "=", "(", "1000L", "-", "cal", ".", "get", "(", "Calen...
Schedule the next check to see if we should roll the logs over.
[ "Schedule", "the", "next", "check", "to", "see", "if", "we", "should", "roll", "the", "logs", "over", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/AuditLogger.java#L156-L166
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/ServletContextResourceLoader.java
ServletContextResourceLoader.init
@Override public void init (ExtendedProperties config) { // the web framework was kind enough to slip this into the runtime when it started up _sctx = (ServletContext)rsvc.getApplicationAttribute("ServletContext"); if (_sctx == null) { rsvc.getLog().warn("ServletContextResourceLoader: servlet context was not supplied " + "as application context. A user of the servlet context resource " + "loader must call Velocity.setApplicationAttribute(" + "\"ServletContext\", getServletContext())."); } }
java
@Override public void init (ExtendedProperties config) { // the web framework was kind enough to slip this into the runtime when it started up _sctx = (ServletContext)rsvc.getApplicationAttribute("ServletContext"); if (_sctx == null) { rsvc.getLog().warn("ServletContextResourceLoader: servlet context was not supplied " + "as application context. A user of the servlet context resource " + "loader must call Velocity.setApplicationAttribute(" + "\"ServletContext\", getServletContext())."); } }
[ "@", "Override", "public", "void", "init", "(", "ExtendedProperties", "config", ")", "{", "// the web framework was kind enough to slip this into the runtime when it started up", "_sctx", "=", "(", "ServletContext", ")", "rsvc", ".", "getApplicationAttribute", "(", "\"Servlet...
Called by Velocity to initialize this resource loader.
[ "Called", "by", "Velocity", "to", "initialize", "this", "resource", "loader", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/ServletContextResourceLoader.java#L44-L55
train
samskivert/samskivert
src/main/java/com/samskivert/util/FailureListener.java
FailureListener.retype
public <V> FailureListener<V> retype (Class<V> klass) { @SuppressWarnings("unchecked") FailureListener<V> casted = (FailureListener<V>)this; return casted; }
java
public <V> FailureListener<V> retype (Class<V> klass) { @SuppressWarnings("unchecked") FailureListener<V> casted = (FailureListener<V>)this; return casted; }
[ "public", "<", "V", ">", "FailureListener", "<", "V", ">", "retype", "(", "Class", "<", "V", ">", "klass", ")", "{", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "FailureListener", "<", "V", ">", "casted", "=", "(", "FailureListener", "<", "V", ...
Recasts us to look like we're of a different type. We can safely do this because we know that requestCompleted never actually looks at the value passed in.
[ "Recasts", "us", "to", "look", "like", "we", "re", "of", "a", "different", "type", ".", "We", "can", "safely", "do", "this", "because", "we", "know", "that", "requestCompleted", "never", "actually", "looks", "at", "the", "value", "passed", "in", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/FailureListener.java#L25-L29
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/TransitionRepository.java
TransitionRepository.transition
public void transition (Class<?> clazz, String name, Transition trans) throws PersistenceException { if (!isTransitionApplied(clazz, name) && noteTransition(clazz, name)) { try { trans.run(); } catch (PersistenceException e) { try { clearTransition(clazz, name); } catch (PersistenceException pe) { log.warning("Failed to clear failed transition", "class", clazz, "name", name, pe); } throw e; } catch (RuntimeException rte) { try { clearTransition(clazz, name); } catch (PersistenceException pe) { log.warning("Failed to clear failed transition", "class", clazz, "name", name, pe); } throw rte; } } }
java
public void transition (Class<?> clazz, String name, Transition trans) throws PersistenceException { if (!isTransitionApplied(clazz, name) && noteTransition(clazz, name)) { try { trans.run(); } catch (PersistenceException e) { try { clearTransition(clazz, name); } catch (PersistenceException pe) { log.warning("Failed to clear failed transition", "class", clazz, "name", name, pe); } throw e; } catch (RuntimeException rte) { try { clearTransition(clazz, name); } catch (PersistenceException pe) { log.warning("Failed to clear failed transition", "class", clazz, "name", name, pe); } throw rte; } } }
[ "public", "void", "transition", "(", "Class", "<", "?", ">", "clazz", ",", "String", "name", ",", "Transition", "trans", ")", "throws", "PersistenceException", "{", "if", "(", "!", "isTransitionApplied", "(", "clazz", ",", "name", ")", "&&", "noteTransition"...
Perform a transition if it has not already been applied, and record that it was applied.
[ "Perform", "a", "transition", "if", "it", "has", "not", "already", "been", "applied", "and", "record", "that", "it", "was", "applied", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/TransitionRepository.java#L53-L79
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/TransitionRepository.java
TransitionRepository.isTransitionApplied
public boolean isTransitionApplied (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); return execute(new Operation<Boolean>() { public Boolean invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( " select " + liaison.columnSQL("NAME") + " from " + liaison.tableSQL("TRANSITIONS") + " where " + liaison.columnSQL("CLASS") + "=?" + " and " + liaison.columnSQL("NAME") + "=?"); stmt.setString(1, cname); stmt.setString(2, name); ResultSet rs = stmt.executeQuery(); if (rs.next()) { return true; } } finally { JDBCUtil.close(stmt); } return false; } }); }
java
public boolean isTransitionApplied (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); return execute(new Operation<Boolean>() { public Boolean invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( " select " + liaison.columnSQL("NAME") + " from " + liaison.tableSQL("TRANSITIONS") + " where " + liaison.columnSQL("CLASS") + "=?" + " and " + liaison.columnSQL("NAME") + "=?"); stmt.setString(1, cname); stmt.setString(2, name); ResultSet rs = stmt.executeQuery(); if (rs.next()) { return true; } } finally { JDBCUtil.close(stmt); } return false; } }); }
[ "public", "boolean", "isTransitionApplied", "(", "Class", "<", "?", ">", "clazz", ",", "final", "String", "name", ")", "throws", "PersistenceException", "{", "final", "String", "cname", "=", "clazz", ".", "getName", "(", ")", ";", "return", "execute", "(", ...
Returns whether the specified name transition been applied.
[ "Returns", "whether", "the", "specified", "name", "transition", "been", "applied", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/TransitionRepository.java#L84-L112
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/TransitionRepository.java
TransitionRepository.noteTransition
public boolean noteTransition (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); return executeUpdate(new Operation<Boolean>() { public Boolean invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( "insert into " + liaison.tableSQL("TRANSITIONS") + " (" + liaison.columnSQL("CLASS") + ", " + liaison.columnSQL("NAME") + ", " + liaison.columnSQL("APPLIED") + ") values (?, ?, ?)"); stmt.setString(1, cname); stmt.setString(2, name); stmt.setTimestamp(3, new Timestamp(System.currentTimeMillis())); JDBCUtil.checkedUpdate(stmt, 1); return true; } catch (SQLException sqe) { if (liaison.isDuplicateRowException(sqe)) { return false; } else { throw sqe; } } finally { JDBCUtil.close(stmt); } } }); }
java
public boolean noteTransition (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); return executeUpdate(new Operation<Boolean>() { public Boolean invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( "insert into " + liaison.tableSQL("TRANSITIONS") + " (" + liaison.columnSQL("CLASS") + ", " + liaison.columnSQL("NAME") + ", " + liaison.columnSQL("APPLIED") + ") values (?, ?, ?)"); stmt.setString(1, cname); stmt.setString(2, name); stmt.setTimestamp(3, new Timestamp(System.currentTimeMillis())); JDBCUtil.checkedUpdate(stmt, 1); return true; } catch (SQLException sqe) { if (liaison.isDuplicateRowException(sqe)) { return false; } else { throw sqe; } } finally { JDBCUtil.close(stmt); } } }); }
[ "public", "boolean", "noteTransition", "(", "Class", "<", "?", ">", "clazz", ",", "final", "String", "name", ")", "throws", "PersistenceException", "{", "final", "String", "cname", "=", "clazz", ".", "getName", "(", ")", ";", "return", "executeUpdate", "(", ...
Note in the database that a particular transition has been applied. @return true if the transition was noted, false if it could not be noted because another process noted it first.
[ "Note", "in", "the", "database", "that", "a", "particular", "transition", "has", "been", "applied", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/TransitionRepository.java#L120-L153
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/TransitionRepository.java
TransitionRepository.clearTransition
public void clearTransition (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); executeUpdate(new Operation<Void>() { public Void invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( " delete from " + liaison.tableSQL("TRANSITIONS") + " where " + liaison.columnSQL("CLASS") + "=? " + " and " + liaison.columnSQL("NAME") + "=?"); stmt.setString(1, cname); stmt.setString(2, name); stmt.executeUpdate(); // we don't care if it worked or not } finally { JDBCUtil.close(stmt); } return null; } }); }
java
public void clearTransition (Class<?> clazz, final String name) throws PersistenceException { final String cname = clazz.getName(); executeUpdate(new Operation<Void>() { public Void invoke (Connection conn, DatabaseLiaison liaison) throws SQLException, PersistenceException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement( " delete from " + liaison.tableSQL("TRANSITIONS") + " where " + liaison.columnSQL("CLASS") + "=? " + " and " + liaison.columnSQL("NAME") + "=?"); stmt.setString(1, cname); stmt.setString(2, name); stmt.executeUpdate(); // we don't care if it worked or not } finally { JDBCUtil.close(stmt); } return null; } }); }
[ "public", "void", "clearTransition", "(", "Class", "<", "?", ">", "clazz", ",", "final", "String", "name", ")", "throws", "PersistenceException", "{", "final", "String", "cname", "=", "clazz", ".", "getName", "(", ")", ";", "executeUpdate", "(", "new", "Op...
Clear the transition.
[ "Clear", "the", "transition", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/TransitionRepository.java#L158-L182
train
nextreports/nextreports-engine
src/ro/nextreports/engine/querybuilder/sql/dialect/AbstractDialect.java
AbstractDialect.registerColumnType
protected void registerColumnType(String columnType, int jdbcType) { columnTypeMatchers.add(new ColumnTypeMatcher(columnType)); jdbcTypes.put(columnType, jdbcType); }
java
protected void registerColumnType(String columnType, int jdbcType) { columnTypeMatchers.add(new ColumnTypeMatcher(columnType)); jdbcTypes.put(columnType, jdbcType); }
[ "protected", "void", "registerColumnType", "(", "String", "columnType", ",", "int", "jdbcType", ")", "{", "columnTypeMatchers", ".", "add", "(", "new", "ColumnTypeMatcher", "(", "columnType", ")", ")", ";", "jdbcTypes", ".", "put", "(", "columnType", ",", "jdb...
Subclasses register a typename for the given type code. @param columnType the database column type @param jdbcType <tt>java.sql.Types</tt> typecode
[ "Subclasses", "register", "a", "typename", "for", "the", "given", "type", "code", "." ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/querybuilder/sql/dialect/AbstractDialect.java#L116-L119
train
samskivert/samskivert
src/main/java/com/samskivert/swing/SimpleSlider.java
SimpleSlider.setLabel
public void setLabel (String label) { _label.setText(label); _label.setVisible(!StringUtil.isBlank(label)); }
java
public void setLabel (String label) { _label.setText(label); _label.setVisible(!StringUtil.isBlank(label)); }
[ "public", "void", "setLabel", "(", "String", "label", ")", "{", "_label", ".", "setText", "(", "label", ")", ";", "_label", ".", "setVisible", "(", "!", "StringUtil", ".", "isBlank", "(", "label", ")", ")", ";", "}" ]
Updates the label displayed to the left of the slider.
[ "Updates", "the", "label", "displayed", "to", "the", "left", "of", "the", "slider", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/SimpleSlider.java#L79-L83
train
samskivert/samskivert
src/main/java/com/samskivert/swing/SimpleSlider.java
SimpleSlider.setValue
public void setValue (int value) { _slider.setValue(value); _value.setText(Integer.toString(value)); }
java
public void setValue (int value) { _slider.setValue(value); _value.setText(Integer.toString(value)); }
[ "public", "void", "setValue", "(", "int", "value", ")", "{", "_slider", ".", "setValue", "(", "value", ")", ";", "_value", ".", "setText", "(", "Integer", ".", "toString", "(", "value", ")", ")", ";", "}" ]
Sets the slider's current value.
[ "Sets", "the", "slider", "s", "current", "value", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/SimpleSlider.java#L96-L100
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/CurrencyTool.java
CurrencyTool.penniesToDollars
public String penniesToDollars (int pennies) { float decimal = pennies / 100f; // if the pennies is a whole number of dollars, then we return just the string number if (pennies % 100 == 0) { return String.format("%.0f", decimal); } // otherwise we always return two decimal places return String.format("%#.2f", decimal); }
java
public String penniesToDollars (int pennies) { float decimal = pennies / 100f; // if the pennies is a whole number of dollars, then we return just the string number if (pennies % 100 == 0) { return String.format("%.0f", decimal); } // otherwise we always return two decimal places return String.format("%#.2f", decimal); }
[ "public", "String", "penniesToDollars", "(", "int", "pennies", ")", "{", "float", "decimal", "=", "pennies", "/", "100f", ";", "// if the pennies is a whole number of dollars, then we return just the string number", "if", "(", "pennies", "%", "100", "==", "0", ")", "{...
Velocity currently doesn't support floats, so we have to provide our own support to convert pennies to a dollar amount.
[ "Velocity", "currently", "doesn", "t", "support", "floats", "so", "we", "have", "to", "provide", "our", "own", "support", "to", "convert", "pennies", "to", "a", "dollar", "amount", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/CurrencyTool.java#L64-L73
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.quote
public String quote (Date date) { return (date == null) ? null : escape(String.valueOf(date)); }
java
public String quote (Date date) { return (date == null) ? null : escape(String.valueOf(date)); }
[ "public", "String", "quote", "(", "Date", "date", ")", "{", "return", "(", "date", "==", "null", ")", "?", "null", ":", "escape", "(", "String", ".", "valueOf", "(", "date", ")", ")", ";", "}" ]
Converts the date to a string and surrounds it in single-quotes via the escape method. If the date is null, returns null.
[ "Converts", "the", "date", "to", "a", "string", "and", "surrounds", "it", "in", "single", "-", "quotes", "via", "the", "escape", "method", ".", "If", "the", "date", "is", "null", "returns", "null", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L208-L211
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.jigger
public static String jigger (String text) { if (text == null) { return null; } try { return new String(text.getBytes("UTF8"), "8859_1"); } catch (UnsupportedEncodingException uee) { log.warning("Jigger failed", uee); return text; } }
java
public static String jigger (String text) { if (text == null) { return null; } try { return new String(text.getBytes("UTF8"), "8859_1"); } catch (UnsupportedEncodingException uee) { log.warning("Jigger failed", uee); return text; } }
[ "public", "static", "String", "jigger", "(", "String", "text", ")", "{", "if", "(", "text", "==", "null", ")", "{", "return", "null", ";", "}", "try", "{", "return", "new", "String", "(", "text", ".", "getBytes", "(", "\"UTF8\"", ")", ",", "\"8859_1\...
Many databases simply fail to handle Unicode text properly and this routine provides a common workaround which is to represent a UTF-8 string as an ISO-8859-1 string. If you don't need to use the database's collation routines, this allows you to do pretty much exactly what you want at the expense of having to jigger and dejigger every goddamned string that might contain multibyte characters every time you access the database. Three cheers for progress!
[ "Many", "databases", "simply", "fail", "to", "handle", "Unicode", "text", "properly", "and", "this", "routine", "provides", "a", "common", "workaround", "which", "is", "to", "represent", "a", "UTF", "-", "8", "string", "as", "an", "ISO", "-", "8859", "-", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L247-L258
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.createTableIfMissing
public static boolean createTableIfMissing ( Connection conn, String table, String[] definition, String postamble) throws SQLException { if (tableExists(conn, table)) { return false; } Statement stmt = conn.createStatement(); try { stmt.executeUpdate("create table " + table + "(" + StringUtil.join(definition, ", ") + ") " + postamble); } finally { close(stmt); } log.info("Database table '" + table + "' created."); return true; }
java
public static boolean createTableIfMissing ( Connection conn, String table, String[] definition, String postamble) throws SQLException { if (tableExists(conn, table)) { return false; } Statement stmt = conn.createStatement(); try { stmt.executeUpdate("create table " + table + "(" + StringUtil.join(definition, ", ") + ") " + postamble); } finally { close(stmt); } log.info("Database table '" + table + "' created."); return true; }
[ "public", "static", "boolean", "createTableIfMissing", "(", "Connection", "conn", ",", "String", "table", ",", "String", "[", "]", "definition", ",", "String", "postamble", ")", "throws", "SQLException", "{", "if", "(", "tableExists", "(", "conn", ",", "table"...
Used to programatically create a database table. Does nothing if the table already exists. @return true if the table was created, false if it already existed.
[ "Used", "to", "programatically", "create", "a", "database", "table", ".", "Does", "nothing", "if", "the", "table", "already", "exists", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L290-L308
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.getIndexName
public static String getIndexName (Connection conn, String table, String column) throws SQLException { ResultSet rs = conn.getMetaData().getIndexInfo("", "", table, false, true); while (rs.next()) { String tname = rs.getString("TABLE_NAME"); String cname = rs.getString("COLUMN_NAME"); String iname = rs.getString("INDEX_NAME"); if (tname.equals(table) && cname.equals(column)) { return iname; } } return null; }
java
public static String getIndexName (Connection conn, String table, String column) throws SQLException { ResultSet rs = conn.getMetaData().getIndexInfo("", "", table, false, true); while (rs.next()) { String tname = rs.getString("TABLE_NAME"); String cname = rs.getString("COLUMN_NAME"); String iname = rs.getString("INDEX_NAME"); if (tname.equals(table) && cname.equals(column)) { return iname; } } return null; }
[ "public", "static", "String", "getIndexName", "(", "Connection", "conn", ",", "String", "table", ",", "String", "column", ")", "throws", "SQLException", "{", "ResultSet", "rs", "=", "conn", ".", "getMetaData", "(", ")", ".", "getIndexInfo", "(", "\"\"", ",",...
Returns the name of the index for the specified column in the specified table.
[ "Returns", "the", "name", "of", "the", "index", "for", "the", "specified", "column", "in", "the", "specified", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L396-L410
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.isColumnNullable
public static boolean isColumnNullable (Connection conn, String table, String column) throws SQLException { ResultSet rs = getColumnMetaData(conn, table, column); try { return rs.getString("IS_NULLABLE").equals("YES"); } finally { rs.close(); } }
java
public static boolean isColumnNullable (Connection conn, String table, String column) throws SQLException { ResultSet rs = getColumnMetaData(conn, table, column); try { return rs.getString("IS_NULLABLE").equals("YES"); } finally { rs.close(); } }
[ "public", "static", "boolean", "isColumnNullable", "(", "Connection", "conn", ",", "String", "table", ",", "String", "column", ")", "throws", "SQLException", "{", "ResultSet", "rs", "=", "getColumnMetaData", "(", "conn", ",", "table", ",", "column", ")", ";", ...
Determines whether or not the specified column accepts null values. @return true if the column accepts null values, false if it does not (or its nullability is unknown)
[ "Determines", "whether", "or", "not", "the", "specified", "column", "accepts", "null", "values", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L434-L444
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.getColumnDefaultValue
public static String getColumnDefaultValue (Connection conn, String table, String column) throws SQLException { ResultSet rs = getColumnMetaData(conn, table, column); try { return rs.getString("COLUMN_DEF"); } finally { rs.close(); } }
java
public static String getColumnDefaultValue (Connection conn, String table, String column) throws SQLException { ResultSet rs = getColumnMetaData(conn, table, column); try { return rs.getString("COLUMN_DEF"); } finally { rs.close(); } }
[ "public", "static", "String", "getColumnDefaultValue", "(", "Connection", "conn", ",", "String", "table", ",", "String", "column", ")", "throws", "SQLException", "{", "ResultSet", "rs", "=", "getColumnMetaData", "(", "conn", ",", "table", ",", "column", ")", "...
Returns a string representation of the default value for the specified column in the specified table. This may be null.
[ "Returns", "a", "string", "representation", "of", "the", "default", "value", "for", "the", "specified", "column", "in", "the", "specified", "table", ".", "This", "may", "be", "null", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L466-L475
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.dropIndex
public static boolean dropIndex (Connection conn, String table, String cname, String iname) throws SQLException { if (!tableContainsIndex(conn, table, cname, iname)) { return false; } String update = "ALTER TABLE " + table + " DROP INDEX " + iname; PreparedStatement stmt = null; try { stmt = conn.prepareStatement(update); if (stmt.executeUpdate() == 1) { log.info("Database index '" + iname + "' removed from table '" + table + "'."); } } finally { close(stmt); } return true; }
java
public static boolean dropIndex (Connection conn, String table, String cname, String iname) throws SQLException { if (!tableContainsIndex(conn, table, cname, iname)) { return false; } String update = "ALTER TABLE " + table + " DROP INDEX " + iname; PreparedStatement stmt = null; try { stmt = conn.prepareStatement(update); if (stmt.executeUpdate() == 1) { log.info("Database index '" + iname + "' removed from table '" + table + "'."); } } finally { close(stmt); } return true; }
[ "public", "static", "boolean", "dropIndex", "(", "Connection", "conn", ",", "String", "table", ",", "String", "cname", ",", "String", "iname", ")", "throws", "SQLException", "{", "if", "(", "!", "tableContainsIndex", "(", "conn", ",", "table", ",", "cname", ...
Removes a named index from the specified table. @return true if the index was dropped, false if it did not exist in the first place.
[ "Removes", "a", "named", "index", "from", "the", "specified", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L560-L578
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/JDBCUtil.java
JDBCUtil.dropPrimaryKey
public static void dropPrimaryKey (Connection conn, String table) throws SQLException { String update = "ALTER TABLE " + table + " DROP PRIMARY KEY"; PreparedStatement stmt = null; try { stmt = conn.prepareStatement(update); if (stmt.executeUpdate() == 1) { log.info("Database primary key removed from '" + table + "'."); } } finally { close(stmt); } }
java
public static void dropPrimaryKey (Connection conn, String table) throws SQLException { String update = "ALTER TABLE " + table + " DROP PRIMARY KEY"; PreparedStatement stmt = null; try { stmt = conn.prepareStatement(update); if (stmt.executeUpdate() == 1) { log.info("Database primary key removed from '" + table + "'."); } } finally { close(stmt); } }
[ "public", "static", "void", "dropPrimaryKey", "(", "Connection", "conn", ",", "String", "table", ")", "throws", "SQLException", "{", "String", "update", "=", "\"ALTER TABLE \"", "+", "table", "+", "\" DROP PRIMARY KEY\"", ";", "PreparedStatement", "stmt", "=", "nu...
Removes the primary key from the specified table.
[ "Removes", "the", "primary", "key", "from", "the", "specified", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/JDBCUtil.java#L583-L596
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/user/UserUtil.java
UserUtil.genAuthCode
public static String genAuthCode (User user) { // concatenate a bunch of secret stuff together StringBuilder buf = new StringBuilder(); buf.append(user.password); buf.append(System.currentTimeMillis()); buf.append(Math.random()); // and MD5 hash it return StringUtil.md5hex(buf.toString()); }
java
public static String genAuthCode (User user) { // concatenate a bunch of secret stuff together StringBuilder buf = new StringBuilder(); buf.append(user.password); buf.append(System.currentTimeMillis()); buf.append(Math.random()); // and MD5 hash it return StringUtil.md5hex(buf.toString()); }
[ "public", "static", "String", "genAuthCode", "(", "User", "user", ")", "{", "// concatenate a bunch of secret stuff together", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "user", ".", "password", ")", ";", "buf"...
Generates a new random session identifier for the supplied user.
[ "Generates", "a", "new", "random", "session", "identifier", "for", "the", "supplied", "user", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/user/UserUtil.java#L19-L29
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/user/UserUtil.java
UserUtil.legacyEncrypt
public static String legacyEncrypt (String username, String password, boolean ignoreUserCase) { if (ignoreUserCase) { username = username.toLowerCase(); } return Crypt.crypt(StringUtil.truncate(username, 2), password); }
java
public static String legacyEncrypt (String username, String password, boolean ignoreUserCase) { if (ignoreUserCase) { username = username.toLowerCase(); } return Crypt.crypt(StringUtil.truncate(username, 2), password); }
[ "public", "static", "String", "legacyEncrypt", "(", "String", "username", ",", "String", "password", ",", "boolean", "ignoreUserCase", ")", "{", "if", "(", "ignoreUserCase", ")", "{", "username", "=", "username", ".", "toLowerCase", "(", ")", ";", "}", "retu...
Encrypts passwords the way we used to.
[ "Encrypts", "passwords", "the", "way", "we", "used", "to", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/user/UserUtil.java#L44-L51
train
samskivert/samskivert
src/main/java/com/samskivert/util/Triple.java
Triple.newTriple
public static <A, B, C> Triple<A, B, C> newTriple (A a, B b, C c) { return new Triple<A, B, C>(a, b, c); }
java
public static <A, B, C> Triple<A, B, C> newTriple (A a, B b, C c) { return new Triple<A, B, C>(a, b, c); }
[ "public", "static", "<", "A", ",", "B", ",", "C", ">", "Triple", "<", "A", ",", "B", ",", "C", ">", "newTriple", "(", "A", "a", ",", "B", "b", ",", "C", "c", ")", "{", "return", "new", "Triple", "<", "A", ",", "B", ",", "C", ">", "(", "...
Creates a triple with the specified values.
[ "Creates", "a", "triple", "with", "the", "specified", "values", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Triple.java#L27-L30
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ScrollBox.java
ScrollBox.paintBackground
protected void paintBackground (Graphics g) { // simply fill our background color g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); }
java
protected void paintBackground (Graphics g) { // simply fill our background color g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); }
[ "protected", "void", "paintBackground", "(", "Graphics", "g", ")", "{", "// simply fill our background color", "g", ".", "setColor", "(", "getBackground", "(", ")", ")", ";", "g", ".", "fillRect", "(", "0", ",", "0", ",", "getWidth", "(", ")", ",", "getHei...
Paint the background.
[ "Paint", "the", "background", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ScrollBox.java#L89-L94
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ScrollBox.java
ScrollBox.paintBox
protected void paintBox (Graphics g, Rectangle box) { // just draw the box in our foreground color g.setColor(getForeground()); g.drawRect(box.x, box.y, box.width, box.height); }
java
protected void paintBox (Graphics g, Rectangle box) { // just draw the box in our foreground color g.setColor(getForeground()); g.drawRect(box.x, box.y, box.width, box.height); }
[ "protected", "void", "paintBox", "(", "Graphics", "g", ",", "Rectangle", "box", ")", "{", "// just draw the box in our foreground color", "g", ".", "setColor", "(", "getForeground", "(", ")", ")", ";", "g", ".", "drawRect", "(", "box", ".", "x", ",", "box", ...
Paint the box that represents the visible area of the two-dimensional scrolling area.
[ "Paint", "the", "box", "that", "represents", "the", "visible", "area", "of", "the", "two", "-", "dimensional", "scrolling", "area", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ScrollBox.java#L100-L105
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ScrollBox.java
ScrollBox.updateBox
protected void updateBox () { int hmin = _horz.getMinimum(); int vmin = _vert.getMinimum(); _hFactor = (_active.width) / (float) (_horz.getMaximum() - hmin); _vFactor = (_active.height) / (float) (_vert.getMaximum() - vmin); _box.x = _active.x + Math.round((_horz.getValue() - hmin) * _hFactor); _box.width = Math.round(_horz.getExtent() * _hFactor); _box.y = _active.y + Math.round((_vert.getValue() - vmin) * _vFactor); _box.height = Math.round(_vert.getExtent() * _vFactor); }
java
protected void updateBox () { int hmin = _horz.getMinimum(); int vmin = _vert.getMinimum(); _hFactor = (_active.width) / (float) (_horz.getMaximum() - hmin); _vFactor = (_active.height) / (float) (_vert.getMaximum() - vmin); _box.x = _active.x + Math.round((_horz.getValue() - hmin) * _hFactor); _box.width = Math.round(_horz.getExtent() * _hFactor); _box.y = _active.y + Math.round((_vert.getValue() - vmin) * _vFactor); _box.height = Math.round(_vert.getExtent() * _vFactor); }
[ "protected", "void", "updateBox", "(", ")", "{", "int", "hmin", "=", "_horz", ".", "getMinimum", "(", ")", ";", "int", "vmin", "=", "_vert", ".", "getMinimum", "(", ")", ";", "_hFactor", "=", "(", "_active", ".", "width", ")", "/", "(", "float", ")...
Recalculate the size of the box. You shouldn't need to override this to provide custom functionality. Use the above three methods instead.
[ "Recalculate", "the", "size", "of", "the", "box", ".", "You", "shouldn", "t", "need", "to", "override", "this", "to", "provide", "custom", "functionality", ".", "Use", "the", "above", "three", "methods", "instead", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ScrollBox.java#L122-L133
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayIntSet.java
ArrayIntSet.toIntArray
public int[] toIntArray (int[] target, int offset) { System.arraycopy(_values, 0, target, offset, _size); return target; }
java
public int[] toIntArray (int[] target, int offset) { System.arraycopy(_values, 0, target, offset, _size); return target; }
[ "public", "int", "[", "]", "toIntArray", "(", "int", "[", "]", "target", ",", "int", "offset", ")", "{", "System", ".", "arraycopy", "(", "_values", ",", "0", ",", "target", ",", "offset", ",", "_size", ")", ";", "return", "target", ";", "}" ]
Serializes this int set into an array at the specified offset. The array must be large enough to hold all the integers in our set at the offset specified. @return the array passed in.
[ "Serializes", "this", "int", "set", "into", "an", "array", "at", "the", "specified", "offset", ".", "The", "array", "must", "be", "large", "enough", "to", "hold", "all", "the", "integers", "in", "our", "set", "at", "the", "offset", "specified", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayIntSet.java#L95-L99
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayIntSet.java
ArrayIntSet.toShortArray
public short[] toShortArray () { short[] values = new short[_size]; for (int ii = 0; ii < _size; ii++) { values[ii] = (short)_values[ii]; } return values; }
java
public short[] toShortArray () { short[] values = new short[_size]; for (int ii = 0; ii < _size; ii++) { values[ii] = (short)_values[ii]; } return values; }
[ "public", "short", "[", "]", "toShortArray", "(", ")", "{", "short", "[", "]", "values", "=", "new", "short", "[", "_size", "]", ";", "for", "(", "int", "ii", "=", "0", ";", "ii", "<", "_size", ";", "ii", "++", ")", "{", "values", "[", "ii", ...
Creates an array of shorts from the contents of this set. Any values outside the range of a short will be truncated by way of a cast.
[ "Creates", "an", "array", "of", "shorts", "from", "the", "contents", "of", "this", "set", ".", "Any", "values", "outside", "the", "range", "of", "a", "short", "will", "be", "truncated", "by", "way", "of", "a", "cast", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayIntSet.java#L105-L112
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayIntSet.java
ArrayIntSet.interator
public Interator interator () { return new AbstractInterator() { public boolean hasNext () { return (_pos < _size); } public int nextInt () { if (_pos >= _size) { throw new NoSuchElementException(); } _canRemove = true; return _values[_pos++]; } @Override public void remove () { if (!_canRemove) { throw new IllegalStateException(); } System.arraycopy(_values, _pos, _values, _pos - 1, _size - _pos); _pos--; _size--; //_values[--_size] = 0; _canRemove = false; } protected int _pos; protected boolean _canRemove; }; }
java
public Interator interator () { return new AbstractInterator() { public boolean hasNext () { return (_pos < _size); } public int nextInt () { if (_pos >= _size) { throw new NoSuchElementException(); } _canRemove = true; return _values[_pos++]; } @Override public void remove () { if (!_canRemove) { throw new IllegalStateException(); } System.arraycopy(_values, _pos, _values, _pos - 1, _size - _pos); _pos--; _size--; //_values[--_size] = 0; _canRemove = false; } protected int _pos; protected boolean _canRemove; }; }
[ "public", "Interator", "interator", "(", ")", "{", "return", "new", "AbstractInterator", "(", ")", "{", "public", "boolean", "hasNext", "(", ")", "{", "return", "(", "_pos", "<", "_size", ")", ";", "}", "public", "int", "nextInt", "(", ")", "{", "if", ...
from interface IntSet
[ "from", "interface", "IntSet" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayIntSet.java#L182-L210
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayIntSet.java
ArrayIntSet.removeDuplicates
protected void removeDuplicates () { if (_size > 1) { int last = _values[0]; for (int ii = 1; ii < _size; ) { if (_values[ii] == last) { // shift everything down 1 _size--; System.arraycopy(_values, ii + 1, _values, ii, _size - ii); } else { last = _values[ii++]; } } } }
java
protected void removeDuplicates () { if (_size > 1) { int last = _values[0]; for (int ii = 1; ii < _size; ) { if (_values[ii] == last) { // shift everything down 1 _size--; System.arraycopy(_values, ii + 1, _values, ii, _size - ii); } else { last = _values[ii++]; } } } }
[ "protected", "void", "removeDuplicates", "(", ")", "{", "if", "(", "_size", ">", "1", ")", "{", "int", "last", "=", "_values", "[", "0", "]", ";", "for", "(", "int", "ii", "=", "1", ";", "ii", "<", "_size", ";", ")", "{", "if", "(", "_values", ...
Removes duplicates from our internal array. Only used by our constructors when initializing from a potentially duplicate-containing source array or collection.
[ "Removes", "duplicates", "from", "our", "internal", "array", ".", "Only", "used", "by", "our", "constructors", "when", "initializing", "from", "a", "potentially", "duplicate", "-", "containing", "source", "array", "or", "collection", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayIntSet.java#L338-L351
train
samskivert/samskivert
src/main/java/com/samskivert/util/RecentList.java
RecentList.add
public void add (Object value) { _list[_lastPos++ % _list.length] = value; // keep last pos cycling from keepCount to 2*keepCount-1 if (_lastPos == 2*_list.length) { _lastPos = _list.length; } }
java
public void add (Object value) { _list[_lastPos++ % _list.length] = value; // keep last pos cycling from keepCount to 2*keepCount-1 if (_lastPos == 2*_list.length) { _lastPos = _list.length; } }
[ "public", "void", "add", "(", "Object", "value", ")", "{", "_list", "[", "_lastPos", "++", "%", "_list", ".", "length", "]", "=", "value", ";", "// keep last pos cycling from keepCount to 2*keepCount-1", "if", "(", "_lastPos", "==", "2", "*", "_list", ".", "...
Adds the specified value to the list.
[ "Adds", "the", "specified", "value", "to", "the", "list", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/RecentList.java#L45-L52
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/ExceptionMap.java
ExceptionMap.getMessage
public static String getMessage (Throwable ex) { String msg = DEFAULT_ERROR_MSG; for (int i = 0; i < _keys.size(); i++) { Class<?> cl = _keys.get(i); if (cl.isInstance(ex)) { msg = _values.get(i); break; } } return msg.replace(MESSAGE_MARKER, ex.getMessage()); }
java
public static String getMessage (Throwable ex) { String msg = DEFAULT_ERROR_MSG; for (int i = 0; i < _keys.size(); i++) { Class<?> cl = _keys.get(i); if (cl.isInstance(ex)) { msg = _values.get(i); break; } } return msg.replace(MESSAGE_MARKER, ex.getMessage()); }
[ "public", "static", "String", "getMessage", "(", "Throwable", "ex", ")", "{", "String", "msg", "=", "DEFAULT_ERROR_MSG", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "_keys", ".", "size", "(", ")", ";", "i", "++", ")", "{", "Class", "<", ...
Looks up the supplied exception in the map and returns the most specific error message available for exceptions of that class. @param ex The exception to resolve into an error message. @return The error message to which this exception maps (properly populated with the message associated with this exception instance).
[ "Looks", "up", "the", "supplied", "exception", "in", "the", "map", "and", "returns", "the", "most", "specific", "error", "message", "available", "for", "exceptions", "of", "that", "class", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/ExceptionMap.java#L127-L138
train
samskivert/samskivert
src/main/java/com/samskivert/io/StreamUtil.java
StreamUtil.close
public static void close (Reader in) { if (in != null) { try { in.close(); } catch (IOException ioe) { log.warning("Error closing reader", "reader", in, "cause", ioe); } } }
java
public static void close (Reader in) { if (in != null) { try { in.close(); } catch (IOException ioe) { log.warning("Error closing reader", "reader", in, "cause", ioe); } } }
[ "public", "static", "void", "close", "(", "Reader", "in", ")", "{", "if", "(", "in", "!=", "null", ")", "{", "try", "{", "in", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "log", ".", "warning", "(", "\"Error cl...
Convenient close for a Reader. Use in a finally clause and love life.
[ "Convenient", "close", "for", "a", "Reader", ".", "Use", "in", "a", "finally", "clause", "and", "love", "life", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/io/StreamUtil.java#L54-L63
train
samskivert/samskivert
src/main/java/com/samskivert/io/StreamUtil.java
StreamUtil.close
public static void close (Writer out) { if (out != null) { try { out.close(); } catch (IOException ioe) { log.warning("Error closing writer", "writer", out, "cause", ioe); } } }
java
public static void close (Writer out) { if (out != null) { try { out.close(); } catch (IOException ioe) { log.warning("Error closing writer", "writer", out, "cause", ioe); } } }
[ "public", "static", "void", "close", "(", "Writer", "out", ")", "{", "if", "(", "out", "!=", "null", ")", "{", "try", "{", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "ioe", ")", "{", "log", ".", "warning", "(", "\"Error...
Convenient close for a Writer. Use in a finally clause and love life.
[ "Convenient", "close", "for", "a", "Writer", ".", "Use", "in", "a", "finally", "clause", "and", "love", "life", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/io/StreamUtil.java#L68-L77
train
nextreports/nextreports-engine
src/ro/nextreports/engine/exporter/HtmlExporter.java
HtmlExporter.newPage
protected void newPage() { if (!bean.isSubreport()) { try { stream.print("</table>\n"); stream.println("<p style=\"page-break-before: always\"></p>\n"); if (bean.getReportLayout().isUseSize()) { stream.print("<table>"); } else { stream.print("<table style='width:100%'>"); } if (bean.getReportLayout().isHeaderOnEveryPage()) { printHeaderBand(); } } catch (Exception e) { e.printStackTrace(); } } }
java
protected void newPage() { if (!bean.isSubreport()) { try { stream.print("</table>\n"); stream.println("<p style=\"page-break-before: always\"></p>\n"); if (bean.getReportLayout().isUseSize()) { stream.print("<table>"); } else { stream.print("<table style='width:100%'>"); } if (bean.getReportLayout().isHeaderOnEveryPage()) { printHeaderBand(); } } catch (Exception e) { e.printStackTrace(); } } }
[ "protected", "void", "newPage", "(", ")", "{", "if", "(", "!", "bean", ".", "isSubreport", "(", ")", ")", "{", "try", "{", "stream", ".", "print", "(", "\"</table>\\n\"", ")", ";", "stream", ".", "println", "(", "\"<p style=\\\"page-break-before: always\\\">...
tables need to be broken in order to force a page break.
[ "tables", "need", "to", "be", "broken", "in", "order", "to", "force", "a", "page", "break", "." ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/exporter/HtmlExporter.java#L345-L362
train
samskivert/samskivert
src/main/java/com/samskivert/util/RepeatCallTracker.java
RepeatCallTracker.checkCall
public boolean checkCall (String warning) { if (_firstCall == null) { _firstCall = new Exception( "---- First call (at " + _format.format(new Date()) + ") ----"); return false; } log.warning(warning, new Exception()); log.warning("First call:", _firstCall); return true; }
java
public boolean checkCall (String warning) { if (_firstCall == null) { _firstCall = new Exception( "---- First call (at " + _format.format(new Date()) + ") ----"); return false; } log.warning(warning, new Exception()); log.warning("First call:", _firstCall); return true; }
[ "public", "boolean", "checkCall", "(", "String", "warning", ")", "{", "if", "(", "_firstCall", "==", "null", ")", "{", "_firstCall", "=", "new", "Exception", "(", "\"---- First call (at \"", "+", "_format", ".", "format", "(", "new", "Date", "(", ")", ")",...
This method should be called when the code passes through the code path that should be called only once. The first time through this path, the method will return false and record the stack trace. Subsquent calls will log an error and report the current and first-time-through stack traces. @param warning the warning message to issue prior to logging the two stack traces.
[ "This", "method", "should", "be", "called", "when", "the", "code", "passes", "through", "the", "code", "path", "that", "should", "be", "called", "only", "once", ".", "The", "first", "time", "through", "this", "path", "the", "method", "will", "return", "fal...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/RepeatCallTracker.java#L33-L44
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.loadConfiguration
protected Properties loadConfiguration (ServletConfig config) throws IOException { Properties props = loadVelocityProps(config); // if we failed to create our application for whatever reason; bail if (_app == null) { return props; } // let the application set up velocity properties _app.configureVelocity(config, props); // if no file resource loader path has been set and a site-specific jar file path was // provided, wire up our site resource manager configureResourceManager(config, props); // wire up our #import directive props.setProperty("userdirective", ImportDirective.class.getName()); // configure the servlet context logger props.put(RuntimeSingleton.RUNTIME_LOG_LOGSYSTEM_CLASS, ServletContextLogger.class.getName()); // now return our augmented properties return props; }
java
protected Properties loadConfiguration (ServletConfig config) throws IOException { Properties props = loadVelocityProps(config); // if we failed to create our application for whatever reason; bail if (_app == null) { return props; } // let the application set up velocity properties _app.configureVelocity(config, props); // if no file resource loader path has been set and a site-specific jar file path was // provided, wire up our site resource manager configureResourceManager(config, props); // wire up our #import directive props.setProperty("userdirective", ImportDirective.class.getName()); // configure the servlet context logger props.put(RuntimeSingleton.RUNTIME_LOG_LOGSYSTEM_CLASS, ServletContextLogger.class.getName()); // now return our augmented properties return props; }
[ "protected", "Properties", "loadConfiguration", "(", "ServletConfig", "config", ")", "throws", "IOException", "{", "Properties", "props", "=", "loadVelocityProps", "(", "config", ")", ";", "// if we failed to create our application for whatever reason; bail", "if", "(", "_a...
We load our velocity properties from the classpath rather than from a file.
[ "We", "load", "our", "velocity", "properties", "from", "the", "classpath", "rather", "than", "from", "a", "file", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L216-L242
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.methodException
@SuppressWarnings("rawtypes") // our super class declares a bare Class public Object methodException (Class clazz, String method, Exception e) throws Exception { log.warning("Exception", "class", clazz.getName(), "method", method, e); return ""; }
java
@SuppressWarnings("rawtypes") // our super class declares a bare Class public Object methodException (Class clazz, String method, Exception e) throws Exception { log.warning("Exception", "class", clazz.getName(), "method", method, e); return ""; }
[ "@", "SuppressWarnings", "(", "\"rawtypes\"", ")", "// our super class declares a bare Class", "public", "Object", "methodException", "(", "Class", "clazz", ",", "String", "method", ",", "Exception", "e", ")", "throws", "Exception", "{", "log", ".", "warning", "(", ...
Called when a method throws an exception during template evaluation.
[ "Called", "when", "a", "method", "throws", "an", "exception", "during", "template", "evaluation", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L417-L423
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.selectTemplate
protected Template selectTemplate (int siteId, InvocationContext ctx) throws ResourceNotFoundException, ParseErrorException, Exception { String path = ctx.getRequest().getServletPath(); if (_usingSiteLoading) { // if we're using site resource loading, we need to prefix the path with the site // identifier path = siteId + ":" + path; } // log.info("Loading template", "path", path); return RuntimeSingleton.getTemplate(path); }
java
protected Template selectTemplate (int siteId, InvocationContext ctx) throws ResourceNotFoundException, ParseErrorException, Exception { String path = ctx.getRequest().getServletPath(); if (_usingSiteLoading) { // if we're using site resource loading, we need to prefix the path with the site // identifier path = siteId + ":" + path; } // log.info("Loading template", "path", path); return RuntimeSingleton.getTemplate(path); }
[ "protected", "Template", "selectTemplate", "(", "int", "siteId", ",", "InvocationContext", "ctx", ")", "throws", "ResourceNotFoundException", ",", "ParseErrorException", ",", "Exception", "{", "String", "path", "=", "ctx", ".", "getRequest", "(", ")", ".", "getSer...
This method is called to select the appropriate template for this request. The default implementation simply loads the template using Velocity's default template loading services based on the URI provided in the request. @param ctx The context of this request. @return The template to be used in generating the response.
[ "This", "method", "is", "called", "to", "select", "the", "appropriate", "template", "for", "this", "request", ".", "The", "default", "implementation", "simply", "loads", "the", "template", "using", "Velocity", "s", "default", "template", "loading", "services", "...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L504-L515
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.mergeTemplate
protected void mergeTemplate (Template template, InvocationContext context) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, UnsupportedEncodingException, IOException, Exception { HttpServletResponse response = context.getResponse(); ServletOutputStream output = response.getOutputStream(); // ASSUMPTION: response.setContentType() has been called. String encoding = response.getCharacterEncoding(); VelocityWriter vw = null; try { vw = (VelocityWriter)_writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding), 4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); } catch (IOException ioe) { // the client probably crashed or aborted the connection ungracefully, so use log.info log.info("Failed to write response", "uri", context.getRequest().getRequestURI(), "error", ioe); } finally { if (vw != null) { try { // flush and put back into the pool don't close to allow us to play nicely with // others. vw.flush(); } catch (IOException e) { // do nothing } // Clear the VelocityWriter's reference to its internal OutputStreamWriter to allow // the latter to be GC'd while vw is pooled. vw.recycle(null); _writerPool.put(vw); } } }
java
protected void mergeTemplate (Template template, InvocationContext context) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, UnsupportedEncodingException, IOException, Exception { HttpServletResponse response = context.getResponse(); ServletOutputStream output = response.getOutputStream(); // ASSUMPTION: response.setContentType() has been called. String encoding = response.getCharacterEncoding(); VelocityWriter vw = null; try { vw = (VelocityWriter)_writerPool.get(); if (vw == null) { vw = new VelocityWriter(new OutputStreamWriter(output, encoding), 4 * 1024, true); } else { vw.recycle(new OutputStreamWriter(output, encoding)); } template.merge(context, vw); } catch (IOException ioe) { // the client probably crashed or aborted the connection ungracefully, so use log.info log.info("Failed to write response", "uri", context.getRequest().getRequestURI(), "error", ioe); } finally { if (vw != null) { try { // flush and put back into the pool don't close to allow us to play nicely with // others. vw.flush(); } catch (IOException e) { // do nothing } // Clear the VelocityWriter's reference to its internal OutputStreamWriter to allow // the latter to be GC'd while vw is pooled. vw.recycle(null); _writerPool.put(vw); } } }
[ "protected", "void", "mergeTemplate", "(", "Template", "template", ",", "InvocationContext", "context", ")", "throws", "ResourceNotFoundException", ",", "ParseErrorException", ",", "MethodInvocationException", ",", "UnsupportedEncodingException", ",", "IOException", ",", "E...
Merges the template with the context. @param template template object returned by the {@link #handleRequest} method. @param context the context for this request.
[ "Merges", "the", "template", "with", "the", "context", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L523-L563
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.resolveLogic
protected Logic resolveLogic (String path) { // look for a cached logic instance String lclass = _app.generateClass(path); Logic logic = _logic.get(lclass); if (logic == null) { logic = instantiateLogic(path, lclass); // if something failed, use a dummy in it's place so that we don't sit around all day // freaking out about our inability to instantiate the proper logic class if (logic == null) { logic = new DummyLogic(); } // cache the resolved logic instance _logic.put(lclass, logic); } return logic; }
java
protected Logic resolveLogic (String path) { // look for a cached logic instance String lclass = _app.generateClass(path); Logic logic = _logic.get(lclass); if (logic == null) { logic = instantiateLogic(path, lclass); // if something failed, use a dummy in it's place so that we don't sit around all day // freaking out about our inability to instantiate the proper logic class if (logic == null) { logic = new DummyLogic(); } // cache the resolved logic instance _logic.put(lclass, logic); } return logic; }
[ "protected", "Logic", "resolveLogic", "(", "String", "path", ")", "{", "// look for a cached logic instance", "String", "lclass", "=", "_app", ".", "generateClass", "(", "path", ")", ";", "Logic", "logic", "=", "_logic", ".", "get", "(", "lclass", ")", ";", ...
This method is called to select the appropriate logic for this request URI. @return The logic to be used in generating the response or null if no logic could be matched.
[ "This", "method", "is", "called", "to", "select", "the", "appropriate", "logic", "for", "this", "request", "URI", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L571-L591
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DispatcherServlet.java
DispatcherServlet.instantiateLogic
protected Logic instantiateLogic (String path, String lclass) { try { Class<?> pcl = Class.forName(lclass); return (Logic)pcl.newInstance(); } catch (ClassNotFoundException cnfe) { // nothing interesting to report } catch (Throwable t) { log.warning("Unable to instantiate logic for application", "path", path, "lclass", lclass, t); } return null; }
java
protected Logic instantiateLogic (String path, String lclass) { try { Class<?> pcl = Class.forName(lclass); return (Logic)pcl.newInstance(); } catch (ClassNotFoundException cnfe) { // nothing interesting to report } catch (Throwable t) { log.warning("Unable to instantiate logic for application", "path", path, "lclass", lclass, t); } return null; }
[ "protected", "Logic", "instantiateLogic", "(", "String", "path", ",", "String", "lclass", ")", "{", "try", "{", "Class", "<", "?", ">", "pcl", "=", "Class", ".", "forName", "(", "lclass", ")", ";", "return", "(", "Logic", ")", "pcl", ".", "newInstance"...
Instantiates a logic instance with the supplied class name. May return null if no such class exists.
[ "Instantiates", "a", "logic", "instance", "with", "the", "supplied", "class", "name", ".", "May", "return", "null", "if", "no", "such", "class", "exists", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DispatcherServlet.java#L597-L608
train
samskivert/samskivert
src/main/java/com/samskivert/util/SerialExecutor.java
SerialExecutor.addTask
public void addTask (ExecutorTask task) { for (int ii=0, nn=_queue.size(); ii < nn; ii++) { ExecutorTask taskOnQueue = _queue.get(ii); if (taskOnQueue.merge(task)) { return; } } // otherwise, add it on _queue.add(task); // and perhaps start it going now if (!_executingNow) { checkNext(); } }
java
public void addTask (ExecutorTask task) { for (int ii=0, nn=_queue.size(); ii < nn; ii++) { ExecutorTask taskOnQueue = _queue.get(ii); if (taskOnQueue.merge(task)) { return; } } // otherwise, add it on _queue.add(task); // and perhaps start it going now if (!_executingNow) { checkNext(); } }
[ "public", "void", "addTask", "(", "ExecutorTask", "task", ")", "{", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "_queue", ".", "size", "(", ")", ";", "ii", "<", "nn", ";", "ii", "++", ")", "{", "ExecutorTask", "taskOnQueue", "=", "_queue", ...
Add a task to the executor, it is expected that this method is called on the ResultReceiver thread.
[ "Add", "a", "task", "to", "the", "executor", "it", "is", "expected", "that", "this", "method", "is", "called", "on", "the", "ResultReceiver", "thread", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/SerialExecutor.java#L99-L115
train
samskivert/samskivert
src/main/java/com/samskivert/util/SerialExecutor.java
SerialExecutor.checkNext
protected void checkNext () { _executingNow = !_queue.isEmpty(); if (_executingNow) { // start up a thread to execute the task in question ExecutorTask task = _queue.remove(0); final ExecutorThread thread = new ExecutorThread(task); thread.start(); // start up a timer that will abort this thread after the specified timeout new Interval(Interval.RUN_DIRECT) { @Override public void expired () { // this will NOOP if the task has already completed thread.abort(); } }.schedule(task.getTimeout()); } }
java
protected void checkNext () { _executingNow = !_queue.isEmpty(); if (_executingNow) { // start up a thread to execute the task in question ExecutorTask task = _queue.remove(0); final ExecutorThread thread = new ExecutorThread(task); thread.start(); // start up a timer that will abort this thread after the specified timeout new Interval(Interval.RUN_DIRECT) { @Override public void expired () { // this will NOOP if the task has already completed thread.abort(); } }.schedule(task.getTimeout()); } }
[ "protected", "void", "checkNext", "(", ")", "{", "_executingNow", "=", "!", "_queue", ".", "isEmpty", "(", ")", ";", "if", "(", "_executingNow", ")", "{", "// start up a thread to execute the task in question", "ExecutorTask", "task", "=", "_queue", ".", "remove",...
Execute the next task, if applicable.
[ "Execute", "the", "next", "task", "if", "applicable", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/SerialExecutor.java#L129-L146
train
samskivert/samskivert
src/main/java/com/samskivert/net/MACUtil.java
MACUtil.getMACAddresses
public static String[] getMACAddresses () { String [] cmds; if (RunAnywhere.isWindows()) { cmds = WINDOWS_CMDS; } else { cmds = UNIX_CMDS; } return parseMACs(tryCommands(cmds)); }
java
public static String[] getMACAddresses () { String [] cmds; if (RunAnywhere.isWindows()) { cmds = WINDOWS_CMDS; } else { cmds = UNIX_CMDS; } return parseMACs(tryCommands(cmds)); }
[ "public", "static", "String", "[", "]", "getMACAddresses", "(", ")", "{", "String", "[", "]", "cmds", ";", "if", "(", "RunAnywhere", ".", "isWindows", "(", ")", ")", "{", "cmds", "=", "WINDOWS_CMDS", ";", "}", "else", "{", "cmds", "=", "UNIX_CMDS", "...
Get all the MAC addresses of the hardware we are running on that we can find.
[ "Get", "all", "the", "MAC", "addresses", "of", "the", "hardware", "we", "are", "running", "on", "that", "we", "can", "find", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MACUtil.java#L39-L49
train
samskivert/samskivert
src/main/java/com/samskivert/net/MACUtil.java
MACUtil.parseMACs
protected static String[] parseMACs (String text) { if (text == null) { return new String[0]; } Matcher m = MACRegex.matcher(text); ArrayList<String> list = new ArrayList<String>(); while (m.find()) { String mac = m.group(1).toUpperCase(); mac = mac.replace(':', '-'); // "Didn't you get that memo?" Apparently some people are not // up on MAC addresses actually being unique, so we will ignore those. // // 44-45-53-XX-XX-XX - PPP Adaptor // 00-53-45-XX-XX-XX - PPP Adaptor // 00-E0-06-09-55-66 - Some bogus run of ASUS motherboards // 00-04-4B-80-80-03 - Some nvidia built-in lan issues // 00-03-8A-XX-XX-XX - MiniWAN or AOL software // 02-03-8A-00-00-11 - Westell Dual (USB/Ethernet) modem // FF-FF-FF-FF-FF-FF - Tunnel adapter Teredo // 02-00-4C-4F-4F-50 - MSFT thinger, loopback of some sort // 00-00-00-00-00-00(-00-E0) - IP6 tunnel if (mac.startsWith("44-45-53")) { continue; } else if (mac.startsWith("00-53-45-00")) { continue; } else if (mac.startsWith("00-E0-06-09-55-66")) { continue; } else if (mac.startsWith("00-04-4B-80-80-03")) { continue; } else if (mac.startsWith("00-03-8A")) { continue; } else if (mac.startsWith("02-03-8A-00-00-11")) { continue; } else if (mac.startsWith("FF-FF-FF-FF-FF-FF")) { continue; } else if (mac.startsWith("02-00-4C-4F-4F-50")) { continue; } else if (mac.startsWith("00-00-00-00-00-00")) { continue; } list.add(mac); } return list.toArray(new String[0]); }
java
protected static String[] parseMACs (String text) { if (text == null) { return new String[0]; } Matcher m = MACRegex.matcher(text); ArrayList<String> list = new ArrayList<String>(); while (m.find()) { String mac = m.group(1).toUpperCase(); mac = mac.replace(':', '-'); // "Didn't you get that memo?" Apparently some people are not // up on MAC addresses actually being unique, so we will ignore those. // // 44-45-53-XX-XX-XX - PPP Adaptor // 00-53-45-XX-XX-XX - PPP Adaptor // 00-E0-06-09-55-66 - Some bogus run of ASUS motherboards // 00-04-4B-80-80-03 - Some nvidia built-in lan issues // 00-03-8A-XX-XX-XX - MiniWAN or AOL software // 02-03-8A-00-00-11 - Westell Dual (USB/Ethernet) modem // FF-FF-FF-FF-FF-FF - Tunnel adapter Teredo // 02-00-4C-4F-4F-50 - MSFT thinger, loopback of some sort // 00-00-00-00-00-00(-00-E0) - IP6 tunnel if (mac.startsWith("44-45-53")) { continue; } else if (mac.startsWith("00-53-45-00")) { continue; } else if (mac.startsWith("00-E0-06-09-55-66")) { continue; } else if (mac.startsWith("00-04-4B-80-80-03")) { continue; } else if (mac.startsWith("00-03-8A")) { continue; } else if (mac.startsWith("02-03-8A-00-00-11")) { continue; } else if (mac.startsWith("FF-FF-FF-FF-FF-FF")) { continue; } else if (mac.startsWith("02-00-4C-4F-4F-50")) { continue; } else if (mac.startsWith("00-00-00-00-00-00")) { continue; } list.add(mac); } return list.toArray(new String[0]); }
[ "protected", "static", "String", "[", "]", "parseMACs", "(", "String", "text", ")", "{", "if", "(", "text", "==", "null", ")", "{", "return", "new", "String", "[", "0", "]", ";", "}", "Matcher", "m", "=", "MACRegex", ".", "matcher", "(", "text", ")...
Look through the text for all the MAC addresses we can find.
[ "Look", "through", "the", "text", "for", "all", "the", "MAC", "addresses", "we", "can", "find", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MACUtil.java#L54-L103
train
samskivert/samskivert
src/main/java/com/samskivert/net/MACUtil.java
MACUtil.tryCommands
protected static String tryCommands (String[] cmds) { if (cmds == null) { return null; } String output; for (int ii = 0; ii < cmds.length; ii++) { output = runCommand(cmds[ii]); if (output != null) { return output; } } return null; }
java
protected static String tryCommands (String[] cmds) { if (cmds == null) { return null; } String output; for (int ii = 0; ii < cmds.length; ii++) { output = runCommand(cmds[ii]); if (output != null) { return output; } } return null; }
[ "protected", "static", "String", "tryCommands", "(", "String", "[", "]", "cmds", ")", "{", "if", "(", "cmds", "==", "null", ")", "{", "return", "null", ";", "}", "String", "output", ";", "for", "(", "int", "ii", "=", "0", ";", "ii", "<", "cmds", ...
Takes a lists of commands and tries to run each one till one works. The idea being to be able to 'gracefully' cope with not knowing where a command is installed on different installations.
[ "Takes", "a", "lists", "of", "commands", "and", "tries", "to", "run", "each", "one", "till", "one", "works", ".", "The", "idea", "being", "to", "be", "able", "to", "gracefully", "cope", "with", "not", "knowing", "where", "a", "command", "is", "installed"...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MACUtil.java#L110-L126
train
samskivert/samskivert
src/main/java/com/samskivert/net/MACUtil.java
MACUtil.runCommand
protected static String runCommand (String cmd) { try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader cin = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder buffer= new StringBuilder(); String line = ""; while (line != null) { buffer.append(line); line = cin.readLine(); } cin.close(); return buffer.toString(); } catch (IOException e) { // don't want to log anything for the client to know what we are doing. // This will almost always be thrown/caught when the cmd isn't there. return null; } }
java
protected static String runCommand (String cmd) { try { Process p = Runtime.getRuntime().exec(cmd); BufferedReader cin = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder buffer= new StringBuilder(); String line = ""; while (line != null) { buffer.append(line); line = cin.readLine(); } cin.close(); return buffer.toString(); } catch (IOException e) { // don't want to log anything for the client to know what we are doing. // This will almost always be thrown/caught when the cmd isn't there. return null; } }
[ "protected", "static", "String", "runCommand", "(", "String", "cmd", ")", "{", "try", "{", "Process", "p", "=", "Runtime", ".", "getRuntime", "(", ")", ".", "exec", "(", "cmd", ")", ";", "BufferedReader", "cin", "=", "new", "BufferedReader", "(", "new", ...
Run the specified command and return the output as a string.
[ "Run", "the", "specified", "command", "and", "return", "the", "output", "as", "a", "string", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MACUtil.java#L131-L152
train
nextreports/nextreports-engine
src/ro/nextreports/engine/exporter/util/XlsxUtil.java
XlsxUtil.copyRow
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, XSSFRow srcRow, XSSFRow destRow, Map<Integer, CellStyle> styleMap) { // manage a list of merged zone in order to not insert two times a // merged zone Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>(); destRow.setHeight(srcRow.getHeight()); // pour chaque row for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) { XSSFCell oldCell = srcRow.getCell(j); // ancienne cell if (oldCell != null) { XSSFCell newCell = destRow.createCell(parentSheetColumn + j); copyCell(oldCell, newCell, styleMap); CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex()); if (mergedRegion != null) { CellRangeAddress newMergedRegion = new CellRangeAddress(parentSheetRow + mergedRegion.getFirstRow(), parentSheetRow + mergedRegion.getLastRow(), parentSheetColumn + mergedRegion.getFirstColumn(), parentSheetColumn + mergedRegion.getLastColumn()); CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion); if (isNewMergedRegion(wrapper, mergedRegions)) { mergedRegions.add(wrapper); destSheet.addMergedRegion(wrapper.range); } } } } }
java
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, int parentSheetRow, int parentSheetColumn, XSSFRow srcRow, XSSFRow destRow, Map<Integer, CellStyle> styleMap) { // manage a list of merged zone in order to not insert two times a // merged zone Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>(); destRow.setHeight(srcRow.getHeight()); // pour chaque row for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) { XSSFCell oldCell = srcRow.getCell(j); // ancienne cell if (oldCell != null) { XSSFCell newCell = destRow.createCell(parentSheetColumn + j); copyCell(oldCell, newCell, styleMap); CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex()); if (mergedRegion != null) { CellRangeAddress newMergedRegion = new CellRangeAddress(parentSheetRow + mergedRegion.getFirstRow(), parentSheetRow + mergedRegion.getLastRow(), parentSheetColumn + mergedRegion.getFirstColumn(), parentSheetColumn + mergedRegion.getLastColumn()); CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion); if (isNewMergedRegion(wrapper, mergedRegions)) { mergedRegions.add(wrapper); destSheet.addMergedRegion(wrapper.range); } } } } }
[ "public", "static", "void", "copyRow", "(", "XSSFSheet", "srcSheet", ",", "XSSFSheet", "destSheet", ",", "int", "parentSheetRow", ",", "int", "parentSheetColumn", ",", "XSSFRow", "srcRow", ",", "XSSFRow", "destRow", ",", "Map", "<", "Integer", ",", "CellStyle", ...
Copy a row from a sheet to another sheet @param srcSheet the sheet to copy @param destSheet the sheet to copy into @param parentSheetRow the row inside destSheet where we start to copy @param parentSheetColumn the column inside destSheet where we start to copy @param srcRow the row to copy @param destRow the row to create @param styleMap style map
[ "Copy", "a", "row", "from", "a", "sheet", "to", "another", "sheet" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/exporter/util/XlsxUtil.java#L83-L114
train
nextreports/nextreports-engine
src/ro/nextreports/engine/exporter/util/XlsxUtil.java
XlsxUtil.copyCell
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, CellStyle> styleMap) { if (styleMap != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); } else { int stHashCode = oldCell.getCellStyle().hashCode(); CellStyle newCellStyle = styleMap.get(stHashCode); if (newCellStyle == null) { newCellStyle = newCell.getSheet().getWorkbook().createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); styleMap.put(stHashCode, newCellStyle); } newCell.setCellStyle(newCellStyle); } } switch (oldCell.getCellType()) { case XSSFCell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; case XSSFCell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_BLANK: newCell.setCellType(XSSFCell.CELL_TYPE_BLANK); break; case XSSFCell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case XSSFCell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case XSSFCell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; default: break; } }
java
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, CellStyle> styleMap) { if (styleMap != null) { if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) { newCell.setCellStyle(oldCell.getCellStyle()); } else { int stHashCode = oldCell.getCellStyle().hashCode(); CellStyle newCellStyle = styleMap.get(stHashCode); if (newCellStyle == null) { newCellStyle = newCell.getSheet().getWorkbook().createCellStyle(); newCellStyle.cloneStyleFrom(oldCell.getCellStyle()); styleMap.put(stHashCode, newCellStyle); } newCell.setCellStyle(newCellStyle); } } switch (oldCell.getCellType()) { case XSSFCell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getStringCellValue()); break; case XSSFCell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_BLANK: newCell.setCellType(XSSFCell.CELL_TYPE_BLANK); break; case XSSFCell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case XSSFCell.CELL_TYPE_ERROR: newCell.setCellErrorValue(oldCell.getErrorCellValue()); break; case XSSFCell.CELL_TYPE_FORMULA: newCell.setCellFormula(oldCell.getCellFormula()); break; default: break; } }
[ "public", "static", "void", "copyCell", "(", "XSSFCell", "oldCell", ",", "XSSFCell", "newCell", ",", "Map", "<", "Integer", ",", "CellStyle", ">", "styleMap", ")", "{", "if", "(", "styleMap", "!=", "null", ")", "{", "if", "(", "oldCell", ".", "getSheet",...
Copy a cell to another cell @param oldCell cell to be copied @param newCell cell to be created @param styleMap style map
[ "Copy", "a", "cell", "to", "another", "cell" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/exporter/util/XlsxUtil.java#L123-L161
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.connect
public String connect (String hostname, int port) throws IOException, CDDBException { return connect(hostname, port, CLIENT_NAME, CLIENT_VERSION); }
java
public String connect (String hostname, int port) throws IOException, CDDBException { return connect(hostname, port, CLIENT_NAME, CLIENT_VERSION); }
[ "public", "String", "connect", "(", "String", "hostname", ",", "int", "port", ")", "throws", "IOException", ",", "CDDBException", "{", "return", "connect", "(", "hostname", ",", "port", ",", "CLIENT_NAME", ",", "CLIENT_VERSION", ")", ";", "}" ]
Connects this CDDB instance to the CDDB server running on the supplied host using the specified port and default client name and version. <p> <b>Note well:</b> you must close a CDDB connection once you are done with it, otherwise the socket connection will remain open and pointlessly consume machine resources. @param hostname The host to which to connect. @param port The port number on which to connect to the host. @exception IOException Thrown if a network error occurs attempting to connect to the host. @exception CDDBException Thrown if an error occurs after identifying ourselves to the host. @return The message supplied with the succesful connection response. @see #close
[ "Connects", "this", "CDDB", "instance", "to", "the", "CDDB", "server", "running", "on", "the", "supplied", "host", "using", "the", "specified", "port", "and", "default", "client", "name", "and", "version", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L112-L116
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.connect
public String connect (String hostname, int port, String clientName, String clientVersion) throws IOException, CDDBException { // obtain the necessary information we'll need to identify // ourselves to the CDDB server String localhost = InetAddress.getLocalHost().getHostName(); String username = System.getProperty("user.name"); if (username == null) { username = "anonymous"; } // establish our socket connection and IO streams InetAddress addr = InetAddress.getByName(hostname); _sock = new Socket(addr, port); _in = new BufferedReader(new InputStreamReader(_sock.getInputStream(), ISO8859)); _out = new PrintStream(new BufferedOutputStream(_sock.getOutputStream()), false, ISO8859); // first read (and discard) the banner string _in.readLine(); // try and change to the latest protocol version Response rsp = request("proto 6"); if (rsp.code == 201 || rsp.code == 501) { // Protocol 6 uses UTF-8 _in = new BufferedReader(new InputStreamReader(_sock.getInputStream(), UTF8)); _out = new PrintStream(new BufferedOutputStream(_sock.getOutputStream()), false, UTF8); } // send a hello request StringBuilder req = new StringBuilder("cddb hello "); req.append(username).append(" "); req.append(localhost).append(" "); req.append(clientName).append(" "); req.append(clientVersion); rsp = request(req.toString()); // confirm that the response was a successful one if (CDDBProtocol.codeFamily(rsp.code) != CDDBProtocol.OK && rsp.code != 402 /* already shook hands */) { throw new CDDBException(rsp.code, rsp.message); } return rsp.message; }
java
public String connect (String hostname, int port, String clientName, String clientVersion) throws IOException, CDDBException { // obtain the necessary information we'll need to identify // ourselves to the CDDB server String localhost = InetAddress.getLocalHost().getHostName(); String username = System.getProperty("user.name"); if (username == null) { username = "anonymous"; } // establish our socket connection and IO streams InetAddress addr = InetAddress.getByName(hostname); _sock = new Socket(addr, port); _in = new BufferedReader(new InputStreamReader(_sock.getInputStream(), ISO8859)); _out = new PrintStream(new BufferedOutputStream(_sock.getOutputStream()), false, ISO8859); // first read (and discard) the banner string _in.readLine(); // try and change to the latest protocol version Response rsp = request("proto 6"); if (rsp.code == 201 || rsp.code == 501) { // Protocol 6 uses UTF-8 _in = new BufferedReader(new InputStreamReader(_sock.getInputStream(), UTF8)); _out = new PrintStream(new BufferedOutputStream(_sock.getOutputStream()), false, UTF8); } // send a hello request StringBuilder req = new StringBuilder("cddb hello "); req.append(username).append(" "); req.append(localhost).append(" "); req.append(clientName).append(" "); req.append(clientVersion); rsp = request(req.toString()); // confirm that the response was a successful one if (CDDBProtocol.codeFamily(rsp.code) != CDDBProtocol.OK && rsp.code != 402 /* already shook hands */) { throw new CDDBException(rsp.code, rsp.message); } return rsp.message; }
[ "public", "String", "connect", "(", "String", "hostname", ",", "int", "port", ",", "String", "clientName", ",", "String", "clientVersion", ")", "throws", "IOException", ",", "CDDBException", "{", "// obtain the necessary information we'll need to identify", "// ourselves ...
Connects this CDDB instance to the CDDB server running on the supplied host using the specified port. <p> <b>Note well:</b> you must close a CDDB connection once you are done with it, otherwise the socket connection will remain open and pointlessly consume machine resources. @param hostname The host to which to connect. @param port The port number on which to connect to the host. @param clientName The name of the application establishing this connection. @param clientVersion The version of the application establishing this connection. @exception IOException Thrown if a network error occurs attempting to connect to the host. @exception CDDBException Thrown if an error occurs after identifying ourselves to the host. @return The message supplied with the succesful connection response. @see #close
[ "Connects", "this", "CDDB", "instance", "to", "the", "CDDB", "server", "running", "on", "the", "supplied", "host", "using", "the", "specified", "port", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L137-L181
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.lscat
public String[] lscat() throws IOException, CDDBException { // sanity check if (_sock == null) { throw new CDDBException(500, "Not connected"); } // make the request Response rsp = request("cddb lscat"); // anything other than an OK response earns an exception if (rsp.code != 210) { throw new CDDBException(rsp.code, rsp.message); } ArrayList<String> list = new ArrayList<String>(); String input; while (!(input = _in.readLine()).equals(CDDBProtocol.TERMINATOR)) { list.add(input); } String[] categories = new String[list.size()]; list.toArray(categories); return categories; }
java
public String[] lscat() throws IOException, CDDBException { // sanity check if (_sock == null) { throw new CDDBException(500, "Not connected"); } // make the request Response rsp = request("cddb lscat"); // anything other than an OK response earns an exception if (rsp.code != 210) { throw new CDDBException(rsp.code, rsp.message); } ArrayList<String> list = new ArrayList<String>(); String input; while (!(input = _in.readLine()).equals(CDDBProtocol.TERMINATOR)) { list.add(input); } String[] categories = new String[list.size()]; list.toArray(categories); return categories; }
[ "public", "String", "[", "]", "lscat", "(", ")", "throws", "IOException", ",", "CDDBException", "{", "// sanity check", "if", "(", "_sock", "==", "null", ")", "{", "throw", "new", "CDDBException", "(", "500", ",", "\"Not connected\"", ")", ";", "}", "// ma...
Fetches and returns the list of categories supported by the server. @throws IOException if a problem occurs chatting to the server. @throws CDDBException if the server responds with an error.
[ "Fetches", "and", "returns", "the", "list", "of", "categories", "supported", "by", "the", "server", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L227-L252
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.query
public Entry[] query (String discid, int[] frameOffsets, int length) throws IOException, CDDBException { // sanity check if (_sock == null) { throw new CDDBException(500, "Not connected"); } // construct the query parameter StringBuilder req = new StringBuilder("cddb query "); req.append(discid).append(" "); req.append(frameOffsets.length).append(" "); for (int frameOffset : frameOffsets) { req.append(frameOffset).append(" "); } req.append(length); // make the request Response rsp = request(req.toString()); Entry[] entries = null; // if this is an exact match, parse the entry and return it if (rsp.code == 200 /* exact match */) { entries = new Entry[1]; entries[0] = new Entry(); entries[0].parse(rsp.message); } else if (rsp.code == 211 /* inexact matches */) { // read the matches from the server ArrayList<Entry> list = new ArrayList<Entry>(); String input = _in.readLine(); while (input != null && !input.equals(CDDBProtocol.TERMINATOR)) { System.out.println("...: " + input); Entry e = new Entry(); e.parse(input); list.add(e); input = _in.readLine(); } entries = new Entry[list.size()]; list.toArray(entries); } else if (CDDBProtocol.codeFamily(rsp.code) != CDDBProtocol.OK) { throw new CDDBException(rsp.code, rsp.message); } return entries; }
java
public Entry[] query (String discid, int[] frameOffsets, int length) throws IOException, CDDBException { // sanity check if (_sock == null) { throw new CDDBException(500, "Not connected"); } // construct the query parameter StringBuilder req = new StringBuilder("cddb query "); req.append(discid).append(" "); req.append(frameOffsets.length).append(" "); for (int frameOffset : frameOffsets) { req.append(frameOffset).append(" "); } req.append(length); // make the request Response rsp = request(req.toString()); Entry[] entries = null; // if this is an exact match, parse the entry and return it if (rsp.code == 200 /* exact match */) { entries = new Entry[1]; entries[0] = new Entry(); entries[0].parse(rsp.message); } else if (rsp.code == 211 /* inexact matches */) { // read the matches from the server ArrayList<Entry> list = new ArrayList<Entry>(); String input = _in.readLine(); while (input != null && !input.equals(CDDBProtocol.TERMINATOR)) { System.out.println("...: " + input); Entry e = new Entry(); e.parse(input); list.add(e); input = _in.readLine(); } entries = new Entry[list.size()]; list.toArray(entries); } else if (CDDBProtocol.codeFamily(rsp.code) != CDDBProtocol.OK) { throw new CDDBException(rsp.code, rsp.message); } return entries; }
[ "public", "Entry", "[", "]", "query", "(", "String", "discid", ",", "int", "[", "]", "frameOffsets", ",", "int", "length", ")", "throws", "IOException", ",", "CDDBException", "{", "// sanity check", "if", "(", "_sock", "==", "null", ")", "{", "throw", "n...
Issues a query to the CDDB server using the supplied CD identifying information. @param discid The disc identifier (information on how to compute the disc ID is available <a href="http://www.freedb.org/sections.php?op=viewarticle&artid=6"> here</a>. @param frameOffsets The frame offset of each track. The length of this array is assumed to be the number of tracks on the CD and is used in the query. @param length The length (in seconds) of the CD. @return If no entry matches the query, null is returned. Otherwise one or more entries is returned that matched the query parameters.
[ "Issues", "a", "query", "to", "the", "CDDB", "server", "using", "the", "supplied", "CD", "identifying", "information", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L266-L312
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.append
protected final void append ( ArrayList<String> list, int index, String value) { // expand the list as necessary while (list.size() <= index) { list.add(""); } list.set(index, list.get(index) + value); }
java
protected final void append ( ArrayList<String> list, int index, String value) { // expand the list as necessary while (list.size() <= index) { list.add(""); } list.set(index, list.get(index) + value); }
[ "protected", "final", "void", "append", "(", "ArrayList", "<", "String", ">", "list", ",", "int", "index", ",", "String", "value", ")", "{", "// expand the list as necessary", "while", "(", "list", ".", "size", "(", ")", "<=", "index", ")", "{", "list", ...
Appends the supplied string to the contents of the list at the supplied index. If the list has no contents at the supplied index, the supplied value becomes the contents at that index.
[ "Appends", "the", "supplied", "string", "to", "the", "contents", "of", "the", "list", "at", "the", "supplied", "index", ".", "If", "the", "list", "has", "no", "contents", "at", "the", "supplied", "index", "the", "supplied", "value", "becomes", "the", "cont...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L479-L487
train
samskivert/samskivert
src/main/java/com/samskivert/net/cddb/CDDB.java
CDDB.request
protected Response request (String req) throws IOException { System.err.println("REQ:" + req); // send the request to the server _out.println(req); _out.flush(); // now read the response String rspstr = _in.readLine(); // if they closed the connection on us, we should deal if (rspstr == null) { throw new EOFException(); } System.err.println("RSP:" + rspstr); // parse the response Response rsp = new Response(); String codestr = rspstr; // assume the response is just a code unless we see a space int sidx = rspstr.indexOf(" "); if (sidx != -1) { codestr = rspstr.substring(0, sidx); rsp.message = rspstr.substring(sidx+1); } try { rsp.code = Integer.parseInt(codestr); } catch (NumberFormatException nfe) { rsp.code = 599; rsp.message = "Unparseable response"; } return rsp; }
java
protected Response request (String req) throws IOException { System.err.println("REQ:" + req); // send the request to the server _out.println(req); _out.flush(); // now read the response String rspstr = _in.readLine(); // if they closed the connection on us, we should deal if (rspstr == null) { throw new EOFException(); } System.err.println("RSP:" + rspstr); // parse the response Response rsp = new Response(); String codestr = rspstr; // assume the response is just a code unless we see a space int sidx = rspstr.indexOf(" "); if (sidx != -1) { codestr = rspstr.substring(0, sidx); rsp.message = rspstr.substring(sidx+1); } try { rsp.code = Integer.parseInt(codestr); } catch (NumberFormatException nfe) { rsp.code = 599; rsp.message = "Unparseable response"; } return rsp; }
[ "protected", "Response", "request", "(", "String", "req", ")", "throws", "IOException", "{", "System", ".", "err", ".", "println", "(", "\"REQ:\"", "+", "req", ")", ";", "// send the request to the server", "_out", ".", "println", "(", "req", ")", ";", "_out...
Issues a request to the CDDB server and parses the response.
[ "Issues", "a", "request", "to", "the", "CDDB", "server", "and", "parses", "the", "response", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/cddb/CDDB.java#L492-L528
train