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/swing/ComboButtonBox.java
ComboButtonBox.fireActionPerformed
protected void fireActionPerformed () { // guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // process the listeners last to first, notifying those that are // interested in this event for (int i = listeners.length-2; i >= 0; i -= 2) { if (listeners[i] == ActionListener.class) { // lazily create the event: if (_actionEvent == null) { _actionEvent = new ActionEvent( this, ActionEvent.ACTION_PERFORMED, _actionCommand); } ((ActionListener)listeners[i+1]).actionPerformed(_actionEvent); } } }
java
protected void fireActionPerformed () { // guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // process the listeners last to first, notifying those that are // interested in this event for (int i = listeners.length-2; i >= 0; i -= 2) { if (listeners[i] == ActionListener.class) { // lazily create the event: if (_actionEvent == null) { _actionEvent = new ActionEvent( this, ActionEvent.ACTION_PERFORMED, _actionCommand); } ((ActionListener)listeners[i+1]).actionPerformed(_actionEvent); } } }
[ "protected", "void", "fireActionPerformed", "(", ")", "{", "// guaranteed to return a non-null array", "Object", "[", "]", "listeners", "=", "listenerList", ".", "getListenerList", "(", ")", ";", "// process the listeners last to first, notifying those that are", "// interested...
Notifies our listeners when the selection changed.
[ "Notifies", "our", "listeners", "when", "the", "selection", "changed", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ComboButtonBox.java#L165-L181
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ComboButtonBox.java
ComboButtonBox.addButtons
protected void addButtons (int start, int count) { Object selobj = _model.getSelectedItem(); for (int i = start; i < count; i++) { Object elem = _model.getElementAt(i); if (selobj == elem) { _selectedIndex = i; } JLabel ibut = null; if (elem instanceof Image) { ibut = new JLabel(new ImageIcon((Image)elem)); } else { ibut = new JLabel(elem.toString()); } ibut.putClientProperty("element", elem); ibut.addMouseListener(this); ibut.setBorder((_selectedIndex == i) ? SELECTED_BORDER : DESELECTED_BORDER); add(ibut, i); } SwingUtil.refresh(this); }
java
protected void addButtons (int start, int count) { Object selobj = _model.getSelectedItem(); for (int i = start; i < count; i++) { Object elem = _model.getElementAt(i); if (selobj == elem) { _selectedIndex = i; } JLabel ibut = null; if (elem instanceof Image) { ibut = new JLabel(new ImageIcon((Image)elem)); } else { ibut = new JLabel(elem.toString()); } ibut.putClientProperty("element", elem); ibut.addMouseListener(this); ibut.setBorder((_selectedIndex == i) ? SELECTED_BORDER : DESELECTED_BORDER); add(ibut, i); } SwingUtil.refresh(this); }
[ "protected", "void", "addButtons", "(", "int", "start", ",", "int", "count", ")", "{", "Object", "selobj", "=", "_model", ".", "getSelectedItem", "(", ")", ";", "for", "(", "int", "i", "=", "start", ";", "i", "<", "count", ";", "i", "++", ")", "{",...
Adds buttons for the specified range of model elements.
[ "Adds", "buttons", "for", "the", "specified", "range", "of", "model", "elements", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ComboButtonBox.java#L295-L317
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ComboButtonBox.java
ComboButtonBox.removeButtons
protected void removeButtons (int start, int count) { while (count-- > 0) { remove(start); } // adjust the selected index if (_selectedIndex >= start) { if (start + count > _selectedIndex) { _selectedIndex = -1; } else { _selectedIndex -= count; } } }
java
protected void removeButtons (int start, int count) { while (count-- > 0) { remove(start); } // adjust the selected index if (_selectedIndex >= start) { if (start + count > _selectedIndex) { _selectedIndex = -1; } else { _selectedIndex -= count; } } }
[ "protected", "void", "removeButtons", "(", "int", "start", ",", "int", "count", ")", "{", "while", "(", "count", "--", ">", "0", ")", "{", "remove", "(", "start", ")", ";", "}", "// adjust the selected index", "if", "(", "_selectedIndex", ">=", "start", ...
Removes the buttons in the specified interval.
[ "Removes", "the", "buttons", "in", "the", "specified", "interval", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ComboButtonBox.java#L322-L336
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ComboButtonBox.java
ComboButtonBox.updateSelection
protected void updateSelection (int selidx) { // do nothing if this element is already selected if (selidx == _selectedIndex) { return; } // unhighlight the old component if (_selectedIndex != -1) { JLabel but = (JLabel)getComponent(_selectedIndex); but.setBorder(DESELECTED_BORDER); } // save the new selection _selectedIndex = selidx; // if the selection is valid, highlight the new component if (_selectedIndex != -1) { JLabel but = (JLabel)getComponent(_selectedIndex); but.setBorder(SELECTED_BORDER); } // fire an action performed to let listeners know about our // changed selection fireActionPerformed(); repaint(); }
java
protected void updateSelection (int selidx) { // do nothing if this element is already selected if (selidx == _selectedIndex) { return; } // unhighlight the old component if (_selectedIndex != -1) { JLabel but = (JLabel)getComponent(_selectedIndex); but.setBorder(DESELECTED_BORDER); } // save the new selection _selectedIndex = selidx; // if the selection is valid, highlight the new component if (_selectedIndex != -1) { JLabel but = (JLabel)getComponent(_selectedIndex); but.setBorder(SELECTED_BORDER); } // fire an action performed to let listeners know about our // changed selection fireActionPerformed(); repaint(); }
[ "protected", "void", "updateSelection", "(", "int", "selidx", ")", "{", "// do nothing if this element is already selected", "if", "(", "selidx", "==", "_selectedIndex", ")", "{", "return", ";", "}", "// unhighlight the old component", "if", "(", "_selectedIndex", "!=",...
Sets the selection to the specified index and updates the buttons to reflect the change. This does not update the model.
[ "Sets", "the", "selection", "to", "the", "specified", "index", "and", "updates", "the", "buttons", "to", "reflect", "the", "change", ".", "This", "does", "not", "update", "the", "model", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ComboButtonBox.java#L342-L369
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.layout
protected void layout (Graphics2D gfx, int iconPadding, int extraPadding) { // if we have an icon, let that dictate our size; otherwise just lay out our label all on // one line int sqwid, sqhei; if (_icon == null) { sqwid = sqhei = 0; } else { sqwid = _icon.getIconWidth(); sqhei = _icon.getIconHeight(); _label.setTargetHeight(sqhei); } // lay out our label _label.layout(gfx); Dimension lsize = _label.getSize(); // if we have no icon, make sure that the label has enough room if (_icon == null) { sqhei = lsize.height + extraPadding * 2; sqwid = extraPadding * 2; } // compute the diameter of the circle that perfectly encompasses our icon int hhei = sqhei / 2; int hwid = sqwid / 2; _dia = (int) (Math.sqrt(hwid * hwid + hhei * hhei) * 2); // compute the x and y offsets at which we'll start rendering _xoff = (_dia - sqwid) / 2; _yoff = (_dia - sqhei) / 2; // and for the label _lxoff = _dia - _xoff; _lyoff = (_dia - lsize.height) / 2; // now compute our closed and open sizes _size.height = _dia; // width is the diameter of the circle that contains the icon plus space for the label when // we're open _size.width = _dia + lsize.width + _xoff; // and if we are actually rendering the icon, we need to account for the space between it // and the label. if (_icon != null) { // and add the padding needed for the icon _size.width += _xoff + (iconPadding * 2); _xoff += iconPadding; _lxoff += iconPadding * 2; } }
java
protected void layout (Graphics2D gfx, int iconPadding, int extraPadding) { // if we have an icon, let that dictate our size; otherwise just lay out our label all on // one line int sqwid, sqhei; if (_icon == null) { sqwid = sqhei = 0; } else { sqwid = _icon.getIconWidth(); sqhei = _icon.getIconHeight(); _label.setTargetHeight(sqhei); } // lay out our label _label.layout(gfx); Dimension lsize = _label.getSize(); // if we have no icon, make sure that the label has enough room if (_icon == null) { sqhei = lsize.height + extraPadding * 2; sqwid = extraPadding * 2; } // compute the diameter of the circle that perfectly encompasses our icon int hhei = sqhei / 2; int hwid = sqwid / 2; _dia = (int) (Math.sqrt(hwid * hwid + hhei * hhei) * 2); // compute the x and y offsets at which we'll start rendering _xoff = (_dia - sqwid) / 2; _yoff = (_dia - sqhei) / 2; // and for the label _lxoff = _dia - _xoff; _lyoff = (_dia - lsize.height) / 2; // now compute our closed and open sizes _size.height = _dia; // width is the diameter of the circle that contains the icon plus space for the label when // we're open _size.width = _dia + lsize.width + _xoff; // and if we are actually rendering the icon, we need to account for the space between it // and the label. if (_icon != null) { // and add the padding needed for the icon _size.width += _xoff + (iconPadding * 2); _xoff += iconPadding; _lxoff += iconPadding * 2; } }
[ "protected", "void", "layout", "(", "Graphics2D", "gfx", ",", "int", "iconPadding", ",", "int", "extraPadding", ")", "{", "// if we have an icon, let that dictate our size; otherwise just lay out our label all on", "// one line", "int", "sqwid", ",", "sqhei", ";", "if", "...
Lays out the label sausage. It is assumed that the desired label font is already set in the label. @param iconPadding the number of pixels in the x direction to pad around the icon.
[ "Lays", "out", "the", "label", "sausage", ".", "It", "is", "assumed", "that", "the", "desired", "label", "font", "is", "already", "set", "in", "the", "label", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L46-L98
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.paint
protected void paint (Graphics2D gfx, int x, int y, Color background, Object cliData) { // turn on anti-aliasing (for our sausage lines) Object oalias = SwingUtil.activateAntiAliasing(gfx); // draw the base sausage gfx.setColor(background); drawBase(gfx, x, y); // render our icon if we've got one drawIcon(gfx, x, y, cliData); drawLabel(gfx, x, y); drawBorder(gfx, x, y); drawExtras(gfx, x, y, cliData); // restore original hints SwingUtil.restoreAntiAliasing(gfx, oalias); }
java
protected void paint (Graphics2D gfx, int x, int y, Color background, Object cliData) { // turn on anti-aliasing (for our sausage lines) Object oalias = SwingUtil.activateAntiAliasing(gfx); // draw the base sausage gfx.setColor(background); drawBase(gfx, x, y); // render our icon if we've got one drawIcon(gfx, x, y, cliData); drawLabel(gfx, x, y); drawBorder(gfx, x, y); drawExtras(gfx, x, y, cliData); // restore original hints SwingUtil.restoreAntiAliasing(gfx, oalias); }
[ "protected", "void", "paint", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ",", "Color", "background", ",", "Object", "cliData", ")", "{", "// turn on anti-aliasing (for our sausage lines)", "Object", "oalias", "=", "SwingUtil", ".", "activateAntiAl...
Paints the label sausage.
[ "Paints", "the", "label", "sausage", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L103-L122
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.drawBase
protected void drawBase (Graphics2D gfx, int x, int y) { gfx.fillRoundRect( x, y, _size.width - 1, _size.height - 1, _dia, _dia); }
java
protected void drawBase (Graphics2D gfx, int x, int y) { gfx.fillRoundRect( x, y, _size.width - 1, _size.height - 1, _dia, _dia); }
[ "protected", "void", "drawBase", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ")", "{", "gfx", ".", "fillRoundRect", "(", "x", ",", "y", ",", "_size", ".", "width", "-", "1", ",", "_size", ".", "height", "-", "1", ",", "_dia", ",",...
Draws the base sausage within which all the other decorations are added.
[ "Draws", "the", "base", "sausage", "within", "which", "all", "the", "other", "decorations", "are", "added", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L127-L131
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.drawIcon
protected void drawIcon (Graphics2D gfx, int x, int y, Object cliData) { if (_icon != null) { _icon.paintIcon(null, gfx, x + _xoff, y + _yoff); } }
java
protected void drawIcon (Graphics2D gfx, int x, int y, Object cliData) { if (_icon != null) { _icon.paintIcon(null, gfx, x + _xoff, y + _yoff); } }
[ "protected", "void", "drawIcon", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ",", "Object", "cliData", ")", "{", "if", "(", "_icon", "!=", "null", ")", "{", "_icon", ".", "paintIcon", "(", "null", ",", "gfx", ",", "x", "+", "_xoff",...
Draws the icon, if applicable.
[ "Draws", "the", "icon", "if", "applicable", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L136-L141
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.drawLabel
protected void drawLabel (Graphics2D gfx, int x, int y) { _label.render(gfx, x + _lxoff, y + _lyoff); }
java
protected void drawLabel (Graphics2D gfx, int x, int y) { _label.render(gfx, x + _lxoff, y + _lyoff); }
[ "protected", "void", "drawLabel", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ")", "{", "_label", ".", "render", "(", "gfx", ",", "x", "+", "_lxoff", ",", "y", "+", "_lyoff", ")", ";", "}" ]
Draws the label.
[ "Draws", "the", "label", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L146-L149
train
samskivert/samskivert
src/main/java/com/samskivert/swing/LabelSausage.java
LabelSausage.drawBorder
protected void drawBorder (Graphics2D gfx, int x, int y) { // draw the black outer border gfx.setColor(Color.black); gfx.drawRoundRect(x, y, _size.width - 1, _size.height - 1, _dia, _dia); }
java
protected void drawBorder (Graphics2D gfx, int x, int y) { // draw the black outer border gfx.setColor(Color.black); gfx.drawRoundRect(x, y, _size.width - 1, _size.height - 1, _dia, _dia); }
[ "protected", "void", "drawBorder", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ")", "{", "// draw the black outer border", "gfx", ".", "setColor", "(", "Color", ".", "black", ")", ";", "gfx", ".", "drawRoundRect", "(", "x", ",", "y", ",",...
Draws the black outer border.
[ "Draws", "the", "black", "outer", "border", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/LabelSausage.java#L154-L159
train
nextreports/nextreports-engine
src/ro/nextreports/engine/util/DialectUtil.java
DialectUtil.getFullColumnClassName
public static String getFullColumnClassName(String className) { if (className.startsWith("java.")) { return className; } if ("String".equals(className)) { return "java.lang.String"; } else if ("Int".equals(className)) { return "java.lang.Integer"; } else if ("Double".equals(className)) { return "java.lang.Double"; } else if ("Date".equals(className)) { return "java.util.Date"; } else if ("Long".equals(className)) { return "java.lang.Long"; } else if ("Float".equals(className)) { return "java.lang.Float"; } else if ("Boolean".equals(className)) { return "java.lang.Boolean"; } else { return "java.lang.Object"; } }
java
public static String getFullColumnClassName(String className) { if (className.startsWith("java.")) { return className; } if ("String".equals(className)) { return "java.lang.String"; } else if ("Int".equals(className)) { return "java.lang.Integer"; } else if ("Double".equals(className)) { return "java.lang.Double"; } else if ("Date".equals(className)) { return "java.util.Date"; } else if ("Long".equals(className)) { return "java.lang.Long"; } else if ("Float".equals(className)) { return "java.lang.Float"; } else if ("Boolean".equals(className)) { return "java.lang.Boolean"; } else { return "java.lang.Object"; } }
[ "public", "static", "String", "getFullColumnClassName", "(", "String", "className", ")", "{", "if", "(", "className", ".", "startsWith", "(", "\"java.\"", ")", ")", "{", "return", "className", ";", "}", "if", "(", "\"String\"", ".", "equals", "(", "className...
CsvJdbc driver className is not a full java class name
[ "CsvJdbc", "driver", "className", "is", "not", "a", "full", "java", "class", "name" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/util/DialectUtil.java#L49-L70
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.centerWindow
public static void centerWindow (Window window) { Rectangle bounds; try { bounds = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } catch (Throwable t) { Toolkit tk = window.getToolkit(); Dimension ss = tk.getScreenSize(); bounds = new Rectangle(ss); } int width = window.getWidth(), height = window.getHeight(); window.setBounds(bounds.x + (bounds.width-width)/2, bounds.y + (bounds.height-height)/2, width, height); }
java
public static void centerWindow (Window window) { Rectangle bounds; try { bounds = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration().getBounds(); } catch (Throwable t) { Toolkit tk = window.getToolkit(); Dimension ss = tk.getScreenSize(); bounds = new Rectangle(ss); } int width = window.getWidth(), height = window.getHeight(); window.setBounds(bounds.x + (bounds.width-width)/2, bounds.y + (bounds.height-height)/2, width, height); }
[ "public", "static", "void", "centerWindow", "(", "Window", "window", ")", "{", "Rectangle", "bounds", ";", "try", "{", "bounds", "=", "GraphicsEnvironment", ".", "getLocalGraphicsEnvironment", "(", ")", ".", "getDefaultScreenDevice", "(", ")", ".", "getDefaultConf...
Center the given window within the screen boundaries. @param window the window to be centered.
[ "Center", "the", "given", "window", "within", "the", "screen", "boundaries", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L95-L110
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.drawStringCentered
public static void drawStringCentered ( Graphics g, String str, int x, int y, int width, int height) { FontMetrics fm = g.getFontMetrics(g.getFont()); int xpos = x + ((width - fm.stringWidth(str)) / 2); int ypos = y + ((height + fm.getAscent()) / 2); g.drawString(str, xpos, ypos); }
java
public static void drawStringCentered ( Graphics g, String str, int x, int y, int width, int height) { FontMetrics fm = g.getFontMetrics(g.getFont()); int xpos = x + ((width - fm.stringWidth(str)) / 2); int ypos = y + ((height + fm.getAscent()) / 2); g.drawString(str, xpos, ypos); }
[ "public", "static", "void", "drawStringCentered", "(", "Graphics", "g", ",", "String", "str", ",", "int", "x", ",", "int", "y", ",", "int", "width", ",", "int", "height", ")", "{", "FontMetrics", "fm", "=", "g", ".", "getFontMetrics", "(", "g", ".", ...
Draw a string centered within a rectangle. The string is drawn using the graphics context's current font and color. @param g the graphics context. @param str the string. @param x the bounding x position. @param y the bounding y position. @param width the bounding width. @param height the bounding height.
[ "Draw", "a", "string", "centered", "within", "a", "rectangle", ".", "The", "string", "is", "drawn", "using", "the", "graphics", "context", "s", "current", "font", "and", "color", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L132-L139
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.fitRectInRect
public static Point fitRectInRect (Rectangle rect, Rectangle bounds) { // Guarantee that the right and bottom edges will be contained and do our best for the top // and left edges. return new Point(Math.min(bounds.x + bounds.width - rect.width, Math.max(rect.x, bounds.x)), Math.min(bounds.y + bounds.height - rect.height, Math.max(rect.y, bounds.y))); }
java
public static Point fitRectInRect (Rectangle rect, Rectangle bounds) { // Guarantee that the right and bottom edges will be contained and do our best for the top // and left edges. return new Point(Math.min(bounds.x + bounds.width - rect.width, Math.max(rect.x, bounds.x)), Math.min(bounds.y + bounds.height - rect.height, Math.max(rect.y, bounds.y))); }
[ "public", "static", "Point", "fitRectInRect", "(", "Rectangle", "rect", ",", "Rectangle", "bounds", ")", "{", "// Guarantee that the right and bottom edges will be contained and do our best for the top", "// and left edges.", "return", "new", "Point", "(", "Math", ".", "min",...
Returns the most reasonable position for the specified rectangle to be placed at so as to maximize its containment by the specified bounding rectangle while still placing it as near its original coordinates as possible. @param rect the rectangle to be positioned. @param bounds the containing rectangle.
[ "Returns", "the", "most", "reasonable", "position", "for", "the", "specified", "rectangle", "to", "be", "placed", "at", "so", "as", "to", "maximize", "its", "containment", "by", "the", "specified", "bounding", "rectangle", "while", "still", "placing", "it", "a...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L149-L157
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.positionRect
public static boolean positionRect ( Rectangle r, Rectangle bounds, Collection<? extends Shape> avoidShapes) { Point origPos = r.getLocation(); Comparator<Point> comp = createPointComparator(origPos); SortableArrayList<Point> possibles = new SortableArrayList<Point>(); // start things off with the passed-in point (adjusted to be inside the bounds, if needed) possibles.add(fitRectInRect(r, bounds)); // keep track of area that doesn't generate new possibles Area dead = new Area(); CHECKPOSSIBLES: while (!possibles.isEmpty()) { r.setLocation(possibles.remove(0)); // make sure the rectangle is in the view and not over a dead area if ((!bounds.contains(r)) || dead.intersects(r)) { continue; } // see if it hits any shapes we're trying to avoid for (Iterator<? extends Shape> iter = avoidShapes.iterator(); iter.hasNext(); ) { Shape shape = iter.next(); if (shape.intersects(r)) { // remove that shape from our avoid list iter.remove(); // but add it to our dead area dead.add(new Area(shape)); // add 4 new possible points, each pushed in one direction Rectangle pusher = shape.getBounds(); possibles.add(new Point(pusher.x - r.width, r.y)); possibles.add(new Point(r.x, pusher.y - r.height)); possibles.add(new Point(pusher.x + pusher.width, r.y)); possibles.add(new Point(r.x, pusher.y + pusher.height)); // re-sort the list possibles.sort(comp); continue CHECKPOSSIBLES; } } // hey! if we got here, then it worked! return true; } // we never found a match, move the rectangle back r.setLocation(origPos); return false; }
java
public static boolean positionRect ( Rectangle r, Rectangle bounds, Collection<? extends Shape> avoidShapes) { Point origPos = r.getLocation(); Comparator<Point> comp = createPointComparator(origPos); SortableArrayList<Point> possibles = new SortableArrayList<Point>(); // start things off with the passed-in point (adjusted to be inside the bounds, if needed) possibles.add(fitRectInRect(r, bounds)); // keep track of area that doesn't generate new possibles Area dead = new Area(); CHECKPOSSIBLES: while (!possibles.isEmpty()) { r.setLocation(possibles.remove(0)); // make sure the rectangle is in the view and not over a dead area if ((!bounds.contains(r)) || dead.intersects(r)) { continue; } // see if it hits any shapes we're trying to avoid for (Iterator<? extends Shape> iter = avoidShapes.iterator(); iter.hasNext(); ) { Shape shape = iter.next(); if (shape.intersects(r)) { // remove that shape from our avoid list iter.remove(); // but add it to our dead area dead.add(new Area(shape)); // add 4 new possible points, each pushed in one direction Rectangle pusher = shape.getBounds(); possibles.add(new Point(pusher.x - r.width, r.y)); possibles.add(new Point(r.x, pusher.y - r.height)); possibles.add(new Point(pusher.x + pusher.width, r.y)); possibles.add(new Point(r.x, pusher.y + pusher.height)); // re-sort the list possibles.sort(comp); continue CHECKPOSSIBLES; } } // hey! if we got here, then it worked! return true; } // we never found a match, move the rectangle back r.setLocation(origPos); return false; }
[ "public", "static", "boolean", "positionRect", "(", "Rectangle", "r", ",", "Rectangle", "bounds", ",", "Collection", "<", "?", "extends", "Shape", ">", "avoidShapes", ")", "{", "Point", "origPos", "=", "r", ".", "getLocation", "(", ")", ";", "Comparator", ...
Position the specified rectangle as closely as possible to its current position, but make sure it is within the specified bounds and that it does not overlap any of the Shapes contained in the avoid list. @param r the rectangle to attempt to position. @param bounds the bounding box within which the rectangle must be positioned. @param avoidShapes a collection of Shapes that must not be overlapped. The collection will be destructively modified. @return true if the rectangle was successfully placed, given the constraints, or false if the positioning failed (the rectangle will be left at it's original location.
[ "Position", "the", "specified", "rectangle", "as", "closely", "as", "possible", "to", "its", "current", "position", "but", "make", "sure", "it", "is", "within", "the", "specified", "bounds", "and", "that", "it", "does", "not", "overlap", "any", "of", "the", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L172-L222
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.createPointComparator
public static <P extends Point2D> Comparator<P> createPointComparator (final P origin) { return new Comparator<P>() { public int compare (P p1, P p2) { double dist1 = origin.distance(p1); double dist2 = origin.distance(p2); return (dist1 > dist2) ? 1 : ((dist1 < dist2) ? -1 : 0); } }; }
java
public static <P extends Point2D> Comparator<P> createPointComparator (final P origin) { return new Comparator<P>() { public int compare (P p1, P p2) { double dist1 = origin.distance(p1); double dist2 = origin.distance(p2); return (dist1 > dist2) ? 1 : ((dist1 < dist2) ? -1 : 0); } }; }
[ "public", "static", "<", "P", "extends", "Point2D", ">", "Comparator", "<", "P", ">", "createPointComparator", "(", "final", "P", "origin", ")", "{", "return", "new", "Comparator", "<", "P", ">", "(", ")", "{", "public", "int", "compare", "(", "P", "p1...
Create a comparator that compares against the distance from the specified point. Note: The comparator will continue to sort by distance from the origin point, even if the origin point's coordinates are modified after the comparator is created. Used by positionRect().
[ "Create", "a", "comparator", "that", "compares", "against", "the", "distance", "from", "the", "specified", "point", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L232-L242
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.applyToHierarchy
public static void applyToHierarchy (Component comp, ComponentOp op) { applyToHierarchy(comp, Integer.MAX_VALUE, op); }
java
public static void applyToHierarchy (Component comp, ComponentOp op) { applyToHierarchy(comp, Integer.MAX_VALUE, op); }
[ "public", "static", "void", "applyToHierarchy", "(", "Component", "comp", ",", "ComponentOp", "op", ")", "{", "applyToHierarchy", "(", "comp", ",", "Integer", ".", "MAX_VALUE", ",", "op", ")", ";", "}" ]
Apply the specified ComponentOp to the supplied component and then all its descendants.
[ "Apply", "the", "specified", "ComponentOp", "to", "the", "supplied", "component", "and", "then", "all", "its", "descendants", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L276-L279
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.applyToHierarchy
public static void applyToHierarchy (Component comp, int depth, ComponentOp op) { if (comp == null) { return; } op.apply(comp); if (comp instanceof Container && --depth >= 0) { Container c = (Container) comp; int ccount = c.getComponentCount(); for (int ii = 0; ii < ccount; ii++) { applyToHierarchy(c.getComponent(ii), depth, op); } } }
java
public static void applyToHierarchy (Component comp, int depth, ComponentOp op) { if (comp == null) { return; } op.apply(comp); if (comp instanceof Container && --depth >= 0) { Container c = (Container) comp; int ccount = c.getComponentCount(); for (int ii = 0; ii < ccount; ii++) { applyToHierarchy(c.getComponent(ii), depth, op); } } }
[ "public", "static", "void", "applyToHierarchy", "(", "Component", "comp", ",", "int", "depth", ",", "ComponentOp", "op", ")", "{", "if", "(", "comp", "==", "null", ")", "{", "return", ";", "}", "op", ".", "apply", "(", "comp", ")", ";", "if", "(", ...
Apply the specified ComponentOp to the supplied component and then all its descendants, up to the specified maximum depth.
[ "Apply", "the", "specified", "ComponentOp", "to", "the", "supplied", "component", "and", "then", "all", "its", "descendants", "up", "to", "the", "specified", "maximum", "depth", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L285-L299
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.activateAntiAliasing
public static Object activateAntiAliasing (Graphics2D gfx) { RenderingHints ohints = gfx.getRenderingHints(), nhints = new RenderingHints(null); nhints.add(ohints); nhints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); nhints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); gfx.setRenderingHints(nhints); return ohints; }
java
public static Object activateAntiAliasing (Graphics2D gfx) { RenderingHints ohints = gfx.getRenderingHints(), nhints = new RenderingHints(null); nhints.add(ohints); nhints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); nhints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); gfx.setRenderingHints(nhints); return ohints; }
[ "public", "static", "Object", "activateAntiAliasing", "(", "Graphics2D", "gfx", ")", "{", "RenderingHints", "ohints", "=", "gfx", ".", "getRenderingHints", "(", ")", ",", "nhints", "=", "new", "RenderingHints", "(", "null", ")", ";", "nhints", ".", "add", "(...
Activates anti-aliasing in the supplied graphics context on both text and 2D drawing primitives. @return an object that should be passed to {@link #restoreAntiAliasing} to restore the graphics context to its original settings.
[ "Activates", "anti", "-", "aliasing", "in", "the", "supplied", "graphics", "context", "on", "both", "text", "and", "2D", "drawing", "primitives", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L412-L420
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.restoreAntiAliasing
public static void restoreAntiAliasing (Graphics2D gfx, Object rock) { if (rock != null) { gfx.setRenderingHints((RenderingHints)rock); } }
java
public static void restoreAntiAliasing (Graphics2D gfx, Object rock) { if (rock != null) { gfx.setRenderingHints((RenderingHints)rock); } }
[ "public", "static", "void", "restoreAntiAliasing", "(", "Graphics2D", "gfx", ",", "Object", "rock", ")", "{", "if", "(", "rock", "!=", "null", ")", "{", "gfx", ".", "setRenderingHints", "(", "(", "RenderingHints", ")", "rock", ")", ";", "}", "}" ]
Restores anti-aliasing in the supplied graphics context to its original setting. @param rock the results of a previous call to {@link #activateAntiAliasing} or null, in which case this method will NOOP. This alleviates every caller having to conditionally avoid calling restore if they chose not to activate earlier.
[ "Restores", "anti", "-", "aliasing", "in", "the", "supplied", "graphics", "context", "to", "its", "original", "setting", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L429-L434
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.sizeToContents
public static void sizeToContents (JTable table) { TableModel model = table.getModel(); TableColumn column = null; Component comp = null; int ccount = table.getColumnModel().getColumnCount(), rcount = model.getRowCount(), cellHeight = 0; for (int cc = 0; cc < ccount; cc++) { int headerWidth = 0, cellWidth = 0; column = table.getColumnModel().getColumn(cc); try { comp = column.getHeaderRenderer().getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; } catch (NullPointerException e) { // getHeaderRenderer() this doesn't work in 1.3 } for (int rr = 0; rr < rcount; rr++) { Object cellValue = model.getValueAt(rr, cc); comp = table.getDefaultRenderer(model.getColumnClass(cc)). getTableCellRendererComponent(table, cellValue, false, false, 0, cc); Dimension psize = comp.getPreferredSize(); cellWidth = Math.max(psize.width, cellWidth); cellHeight = Math.max(psize.height, cellHeight); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } if (cellHeight > 0) { table.setRowHeight(cellHeight); } }
java
public static void sizeToContents (JTable table) { TableModel model = table.getModel(); TableColumn column = null; Component comp = null; int ccount = table.getColumnModel().getColumnCount(), rcount = model.getRowCount(), cellHeight = 0; for (int cc = 0; cc < ccount; cc++) { int headerWidth = 0, cellWidth = 0; column = table.getColumnModel().getColumn(cc); try { comp = column.getHeaderRenderer().getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; } catch (NullPointerException e) { // getHeaderRenderer() this doesn't work in 1.3 } for (int rr = 0; rr < rcount; rr++) { Object cellValue = model.getValueAt(rr, cc); comp = table.getDefaultRenderer(model.getColumnClass(cc)). getTableCellRendererComponent(table, cellValue, false, false, 0, cc); Dimension psize = comp.getPreferredSize(); cellWidth = Math.max(psize.width, cellWidth); cellHeight = Math.max(psize.height, cellHeight); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } if (cellHeight > 0) { table.setRowHeight(cellHeight); } }
[ "public", "static", "void", "sizeToContents", "(", "JTable", "table", ")", "{", "TableModel", "model", "=", "table", ".", "getModel", "(", ")", ";", "TableColumn", "column", "=", "null", ";", "Component", "comp", "=", "null", ";", "int", "ccount", "=", "...
Adjusts the widths and heights of the cells of the supplied table to fit their contents.
[ "Adjusts", "the", "widths", "and", "heights", "of", "the", "cells", "of", "the", "supplied", "table", "to", "fit", "their", "contents", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L449-L482
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.createImageCursor
public static Cursor createImageCursor (Image img, Point hotspot) { Toolkit tk = Toolkit.getDefaultToolkit(); // for now, just report the cursor restrictions, then blindly create int w = img.getWidth(null); int h = img.getHeight(null); Dimension d = tk.getBestCursorSize(w, h); // int colors = tk.getMaximumCursorColors(); // Log.debug("Creating custom cursor [desiredSize=" + w + "x" + h + // ", bestSize=" + d.width + "x" + d.height + // ", maxcolors=" + colors + "]."); // if the passed-in image is smaller, pad it with transparent pixels and use it anyway. if (((w < d.width) && (h <= d.height)) || ((w <= d.width) && (h < d.height))) { Image padder = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(). createCompatibleImage(d.width, d.height, Transparency.BITMASK); Graphics g = padder.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); // and reassign the image to the padded image img = padder; // and adjust the 'best' to cheat the hotspot checking code d.width = w; d.height = h; } // make sure the hotspot is valid if (hotspot == null) { hotspot = new Point(d.width / 2, d.height / 2); } else { hotspot.x = Math.min(d.width - 1, Math.max(0, hotspot.x)); hotspot.y = Math.min(d.height - 1, Math.max(0, hotspot.y)); } // and create the cursor return tk.createCustomCursor(img, hotspot, "samskivertDnDCursor"); }
java
public static Cursor createImageCursor (Image img, Point hotspot) { Toolkit tk = Toolkit.getDefaultToolkit(); // for now, just report the cursor restrictions, then blindly create int w = img.getWidth(null); int h = img.getHeight(null); Dimension d = tk.getBestCursorSize(w, h); // int colors = tk.getMaximumCursorColors(); // Log.debug("Creating custom cursor [desiredSize=" + w + "x" + h + // ", bestSize=" + d.width + "x" + d.height + // ", maxcolors=" + colors + "]."); // if the passed-in image is smaller, pad it with transparent pixels and use it anyway. if (((w < d.width) && (h <= d.height)) || ((w <= d.width) && (h < d.height))) { Image padder = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(). createCompatibleImage(d.width, d.height, Transparency.BITMASK); Graphics g = padder.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); // and reassign the image to the padded image img = padder; // and adjust the 'best' to cheat the hotspot checking code d.width = w; d.height = h; } // make sure the hotspot is valid if (hotspot == null) { hotspot = new Point(d.width / 2, d.height / 2); } else { hotspot.x = Math.min(d.width - 1, Math.max(0, hotspot.x)); hotspot.y = Math.min(d.height - 1, Math.max(0, hotspot.y)); } // and create the cursor return tk.createCustomCursor(img, hotspot, "samskivertDnDCursor"); }
[ "public", "static", "Cursor", "createImageCursor", "(", "Image", "img", ",", "Point", "hotspot", ")", "{", "Toolkit", "tk", "=", "Toolkit", ".", "getDefaultToolkit", "(", ")", ";", "// for now, just report the cursor restrictions, then blindly create", "int", "w", "="...
Create a custom cursor out of the specified image, with the specified hotspot.
[ "Create", "a", "custom", "cursor", "out", "of", "the", "specified", "image", "with", "the", "specified", "hotspot", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L508-L549
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.addDebugBorders
public static void addDebugBorders (JPanel panel) { Color bcolor = new Color(_rando.nextInt(256), _rando.nextInt(256), _rando.nextInt(256)); panel.setBorder(BorderFactory.createLineBorder(bcolor)); for (int ii = 0; ii < panel.getComponentCount(); ii++) { Object child = panel.getComponent(ii); if (child instanceof JPanel) { addDebugBorders((JPanel)child); } } }
java
public static void addDebugBorders (JPanel panel) { Color bcolor = new Color(_rando.nextInt(256), _rando.nextInt(256), _rando.nextInt(256)); panel.setBorder(BorderFactory.createLineBorder(bcolor)); for (int ii = 0; ii < panel.getComponentCount(); ii++) { Object child = panel.getComponent(ii); if (child instanceof JPanel) { addDebugBorders((JPanel)child); } } }
[ "public", "static", "void", "addDebugBorders", "(", "JPanel", "panel", ")", "{", "Color", "bcolor", "=", "new", "Color", "(", "_rando", ".", "nextInt", "(", "256", ")", ",", "_rando", ".", "nextInt", "(", "256", ")", ",", "_rando", ".", "nextInt", "(",...
Adds a one pixel border of random color to this and all panels contained in this panel's child hierarchy.
[ "Adds", "a", "one", "pixel", "border", "of", "random", "color", "to", "this", "and", "all", "panels", "contained", "in", "this", "panel", "s", "child", "hierarchy", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L555-L566
train
samskivert/samskivert
src/main/java/com/samskivert/swing/util/SwingUtil.java
SwingUtil.setFrameIcons
public static void setFrameIcons (Frame frame, List<? extends Image> icons) { try { Method m = frame.getClass().getMethod("setIconImages", List.class); m.invoke(frame, icons); return; } catch (SecurityException e) { // Fine, fine, no reflection for us } catch (NoSuchMethodException e) { // This is fine, we must be on a pre-1.6 JVM } catch (Exception e) { // Something else went awry? Log it log.warning("Error setting frame icons", "frame", frame, "icons", icons, "e", e); } // We couldn't find it, couldn't reflect, or something. // Just use whichever's at the top of the list frame.setIconImage(icons.get(0)); }
java
public static void setFrameIcons (Frame frame, List<? extends Image> icons) { try { Method m = frame.getClass().getMethod("setIconImages", List.class); m.invoke(frame, icons); return; } catch (SecurityException e) { // Fine, fine, no reflection for us } catch (NoSuchMethodException e) { // This is fine, we must be on a pre-1.6 JVM } catch (Exception e) { // Something else went awry? Log it log.warning("Error setting frame icons", "frame", frame, "icons", icons, "e", e); } // We couldn't find it, couldn't reflect, or something. // Just use whichever's at the top of the list frame.setIconImage(icons.get(0)); }
[ "public", "static", "void", "setFrameIcons", "(", "Frame", "frame", ",", "List", "<", "?", "extends", "Image", ">", "icons", ")", "{", "try", "{", "Method", "m", "=", "frame", ".", "getClass", "(", ")", ".", "getMethod", "(", "\"setIconImages\"", ",", ...
Sets the frame's icons. Unfortunately, the ability to pass multiple icons so the OS can choose the most size-appropriate one was added in 1.6; before that, you can only set one icon. This method attempts to find and use setIconImages, but if it can't, sets the frame's icon to the first image in the list passed in.
[ "Sets", "the", "frame", "s", "icons", ".", "Unfortunately", "the", "ability", "to", "pass", "multiple", "icons", "so", "the", "OS", "can", "choose", "the", "most", "size", "-", "appropriate", "one", "was", "added", "in", "1", ".", "6", ";", "before", "...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/util/SwingUtil.java#L576-L594
train
samskivert/samskivert
src/main/java/com/samskivert/swing/RuntimeAdjust.java
RuntimeAdjust.createAdjustEditor
public static JComponent createAdjustEditor () { VGroupLayout layout = new VGroupLayout( VGroupLayout.NONE, VGroupLayout.STRETCH, 3, VGroupLayout.TOP); layout.setOffAxisJustification(VGroupLayout.LEFT); JTabbedPane editor = new EditorPane(); Font font = editor.getFont(); Font smaller = font.deriveFont(font.getSize()-1f); String library = null; JPanel lpanel = null; String pkgname = null; CollapsiblePanel pkgpanel = null; int acount = _adjusts.size(); for (int ii = 0; ii < acount; ii++) { Adjust adjust = _adjusts.get(ii); // create a new library label if necessary if (!adjust.getLibrary().equals(library)) { library = adjust.getLibrary(); pkgname = null; lpanel = new JPanel(layout); lpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); editor.addTab(library, lpanel); } // create a new package panel if necessary if (!adjust.getPackage().equals(pkgname)) { pkgname = adjust.getPackage(); pkgpanel = new CollapsiblePanel(); JCheckBox pkgcheck = new JCheckBox(pkgname); pkgcheck.setSelected(true); pkgpanel.setTrigger(pkgcheck, null, null); pkgpanel.setTriggerContainer(pkgcheck); pkgpanel.getContent().setLayout(layout); pkgpanel.setCollapsed(false); lpanel.add(pkgpanel); } // add an entry for this adjustment pkgpanel.getContent().add(new JSeparator()); JPanel aeditor = adjust.getEditor(); aeditor.setFont(smaller); pkgpanel.getContent().add(aeditor); } return editor; }
java
public static JComponent createAdjustEditor () { VGroupLayout layout = new VGroupLayout( VGroupLayout.NONE, VGroupLayout.STRETCH, 3, VGroupLayout.TOP); layout.setOffAxisJustification(VGroupLayout.LEFT); JTabbedPane editor = new EditorPane(); Font font = editor.getFont(); Font smaller = font.deriveFont(font.getSize()-1f); String library = null; JPanel lpanel = null; String pkgname = null; CollapsiblePanel pkgpanel = null; int acount = _adjusts.size(); for (int ii = 0; ii < acount; ii++) { Adjust adjust = _adjusts.get(ii); // create a new library label if necessary if (!adjust.getLibrary().equals(library)) { library = adjust.getLibrary(); pkgname = null; lpanel = new JPanel(layout); lpanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); editor.addTab(library, lpanel); } // create a new package panel if necessary if (!adjust.getPackage().equals(pkgname)) { pkgname = adjust.getPackage(); pkgpanel = new CollapsiblePanel(); JCheckBox pkgcheck = new JCheckBox(pkgname); pkgcheck.setSelected(true); pkgpanel.setTrigger(pkgcheck, null, null); pkgpanel.setTriggerContainer(pkgcheck); pkgpanel.getContent().setLayout(layout); pkgpanel.setCollapsed(false); lpanel.add(pkgpanel); } // add an entry for this adjustment pkgpanel.getContent().add(new JSeparator()); JPanel aeditor = adjust.getEditor(); aeditor.setFont(smaller); pkgpanel.getContent().add(aeditor); } return editor; }
[ "public", "static", "JComponent", "createAdjustEditor", "(", ")", "{", "VGroupLayout", "layout", "=", "new", "VGroupLayout", "(", "VGroupLayout", ".", "NONE", ",", "VGroupLayout", ".", "STRETCH", ",", "3", ",", "VGroupLayout", ".", "TOP", ")", ";", "layout", ...
Creates a Swing user interface that can be used to adjust all registered runtime adjustments.
[ "Creates", "a", "Swing", "user", "interface", "that", "can", "be", "used", "to", "adjust", "all", "registered", "runtime", "adjustments", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/RuntimeAdjust.java#L66-L116
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/DataTool.java
DataTool.get
public Object get (Object array, int index) { return (array == null) ? null : Array.get(array, index); }
java
public Object get (Object array, int index) { return (array == null) ? null : Array.get(array, index); }
[ "public", "Object", "get", "(", "Object", "array", ",", "int", "index", ")", "{", "return", "(", "array", "==", "null", ")", "?", "null", ":", "Array", ".", "get", "(", "array", ",", "index", ")", ";", "}" ]
Returns the object in the array at index. Wrapped as an object if it is a primitive.
[ "Returns", "the", "object", "in", "the", "array", "at", "index", ".", "Wrapped", "as", "an", "object", "if", "it", "is", "a", "primitive", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/DataTool.java#L37-L40
train
samskivert/samskivert
src/main/java/com/samskivert/net/HttpPostUtil.java
HttpPostUtil.httpPost
public static String httpPost ( final URL url, final String submission, int timeout, final Map<String, String> requestProps) throws IOException, ServiceWaiter.TimeoutException { final ServiceWaiter<String> waiter = new ServiceWaiter<String>( (timeout < 0) ? ServiceWaiter.NO_TIMEOUT : timeout); Thread tt = new Thread() { @Override public void run () { try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); for (Map.Entry<String, String> entry : requestProps.entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(submission); out.flush(); out.close(); BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); StringBuilder buf = new StringBuilder(); for (String s; null != (s = reader.readLine()); ) { buf.append(s); } reader.close(); waiter.postSuccess(buf.toString()); // yay } catch (IOException e) { waiter.postFailure(e); // boo } } }; tt.start(); if (waiter.waitForResponse()) { return waiter.getArgument(); } else { throw (IOException) waiter.getError(); } }
java
public static String httpPost ( final URL url, final String submission, int timeout, final Map<String, String> requestProps) throws IOException, ServiceWaiter.TimeoutException { final ServiceWaiter<String> waiter = new ServiceWaiter<String>( (timeout < 0) ? ServiceWaiter.NO_TIMEOUT : timeout); Thread tt = new Thread() { @Override public void run () { try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); for (Map.Entry<String, String> entry : requestProps.entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(submission); out.flush(); out.close(); BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); StringBuilder buf = new StringBuilder(); for (String s; null != (s = reader.readLine()); ) { buf.append(s); } reader.close(); waiter.postSuccess(buf.toString()); // yay } catch (IOException e) { waiter.postFailure(e); // boo } } }; tt.start(); if (waiter.waitForResponse()) { return waiter.getArgument(); } else { throw (IOException) waiter.getError(); } }
[ "public", "static", "String", "httpPost", "(", "final", "URL", "url", ",", "final", "String", "submission", ",", "int", "timeout", ",", "final", "Map", "<", "String", ",", "String", ">", "requestProps", ")", "throws", "IOException", ",", "ServiceWaiter", "."...
Return the results of a form post. Note that the http request takes place on another thread, but this thread blocks until the results are returned or it times out. @param url from which to make the request. @param submission the entire submission eg {@code foo=bar&baz=boo&futz=foo}. @param timeout time to wait for the response, in seconds, or -1 for forever. @param requestProps additional request properties.
[ "Return", "the", "results", "of", "a", "form", "post", ".", "Note", "that", "the", "http", "request", "takes", "place", "on", "another", "thread", "but", "this", "thread", "blocks", "until", "the", "results", "are", "returned", "or", "it", "times", "out", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/HttpPostUtil.java#L52-L98
train
samskivert/samskivert
src/main/java/com/samskivert/util/JDK14Logger.java
JDK14Logger.inferCaller
protected String[] inferCaller () { String self = getClass().getName(); // locate ourselves in the call stack StackTraceElement[] stack = (new Throwable()).getStackTrace(); int ii = 0; for (; ii < stack.length; ii++) { if (self.equals(stack[ii].getClassName())) { break; } } System.err.println("Found self at " + ii); // now locate the first thing that's not us, that's the caller for (; ii < stack.length; ii++) { String cname = stack[ii].getClassName(); if (!cname.equals(self)) { System.err.println("Found non-self at " + ii + " " + cname); return new String[] { cname, stack[ii].getMethodName() }; } } System.err.println("Failed to find non-self."); return new String[] { null, null }; }
java
protected String[] inferCaller () { String self = getClass().getName(); // locate ourselves in the call stack StackTraceElement[] stack = (new Throwable()).getStackTrace(); int ii = 0; for (; ii < stack.length; ii++) { if (self.equals(stack[ii].getClassName())) { break; } } System.err.println("Found self at " + ii); // now locate the first thing that's not us, that's the caller for (; ii < stack.length; ii++) { String cname = stack[ii].getClassName(); if (!cname.equals(self)) { System.err.println("Found non-self at " + ii + " " + cname); return new String[] { cname, stack[ii].getMethodName() }; } } System.err.println("Failed to find non-self."); return new String[] { null, null }; }
[ "protected", "String", "[", "]", "inferCaller", "(", ")", "{", "String", "self", "=", "getClass", "(", ")", ".", "getName", "(", ")", ";", "// locate ourselves in the call stack", "StackTraceElement", "[", "]", "stack", "=", "(", "new", "Throwable", "(", ")"...
Infers the caller of a Logger method from the current stack trace. This can be used by wrappers to provide the correct calling class and method information to their underlying log implementation. @return a two element array containing { class name, method name } or { null, null } if the caller could not be inferred.
[ "Infers", "the", "caller", "of", "a", "Logger", "method", "from", "the", "current", "stack", "trace", ".", "This", "can", "be", "used", "by", "wrappers", "to", "provide", "the", "correct", "calling", "class", "and", "method", "information", "to", "their", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/JDK14Logger.java#L65-L88
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/SiteJarResourceLoader.java
SiteJarResourceLoader.isSourceModified
@Override public boolean isSourceModified (Resource resource) { SiteKey skey = new SiteKey(resource.getName()); // if the resource is for the default site, it is never considered to // be modified if (skey.siteId == SiteIdentifier.DEFAULT_SITE_ID) { return false; } else { // otherwise compare the last modified time of the loaded resource // with that of the associated site-specific jar file try { return (resource.getLastModified() < _loader.getLastModified(skey.siteId)); } catch (IOException ioe) { Log.log.warning("Failure obtaining last modified time of site-specific jar file", "siteId", skey.siteId, "error", ioe); return false; } } }
java
@Override public boolean isSourceModified (Resource resource) { SiteKey skey = new SiteKey(resource.getName()); // if the resource is for the default site, it is never considered to // be modified if (skey.siteId == SiteIdentifier.DEFAULT_SITE_ID) { return false; } else { // otherwise compare the last modified time of the loaded resource // with that of the associated site-specific jar file try { return (resource.getLastModified() < _loader.getLastModified(skey.siteId)); } catch (IOException ioe) { Log.log.warning("Failure obtaining last modified time of site-specific jar file", "siteId", skey.siteId, "error", ioe); return false; } } }
[ "@", "Override", "public", "boolean", "isSourceModified", "(", "Resource", "resource", ")", "{", "SiteKey", "skey", "=", "new", "SiteKey", "(", "resource", ".", "getName", "(", ")", ")", ";", "// if the resource is for the default site, it is never considered to", "//...
Things won't ever be modified when loaded from the servlet context because they came from the webapp .war file and if that is reloaded, everything will be thrown away and started afresh.
[ "Things", "won", "t", "ever", "be", "modified", "when", "loaded", "from", "the", "servlet", "context", "because", "they", "came", "from", "the", "webapp", ".", "war", "file", "and", "if", "that", "is", "reloaded", "everything", "will", "be", "thrown", "awa...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/SiteJarResourceLoader.java#L86-L108
train
geckoboard-java-api/highchart-java-api
src/main/java/nl/pvanassen/highchart/api/Series.java
Series.setType
public Series setType(SeriesType type) { if(type != null) { this.type = type.name().toLowerCase(); } else { this.type = null; } return this; }
java
public Series setType(SeriesType type) { if(type != null) { this.type = type.name().toLowerCase(); } else { this.type = null; } return this; }
[ "public", "Series", "setType", "(", "SeriesType", "type", ")", "{", "if", "(", "type", "!=", "null", ")", "{", "this", ".", "type", "=", "type", ".", "name", "(", ")", ".", "toLowerCase", "(", ")", ";", "}", "else", "{", "this", ".", "type", "=",...
The type of series @param type the type to set @return
[ "The", "type", "of", "series" ]
66776cbd3c85380bb3dd21a942e0c5a2be6135a7
https://github.com/geckoboard-java-api/highchart-java-api/blob/66776cbd3c85380bb3dd21a942e0c5a2be6135a7/src/main/java/nl/pvanassen/highchart/api/Series.java#L126-L133
train
nextreports/nextreports-engine
src/ro/nextreports/integration/RuntimeParametersPanel.java
RuntimeParametersPanel.populateDependentParameters
private void populateDependentParameters(Report nextReport, QueryParameter parameter) { Map<String, QueryParameter> childParams = ParameterUtil.getChildDependentParameters(nextReport, parameter); // update model parameter values for every child parameter for (QueryParameter childParam : childParams.values()) { if (!parameters.contains(childParam)) { continue; } int index = parameters.indexOf(childParam); JComponent childComponent = getParameterComponent(index); List<IdName> values = new ArrayList<IdName>(); // a parameter may depend on more than one parameter (has more parents) // we must see if all the parents have selected values (this is not done in this example) Map<String, QueryParameter> allParentParams = ParameterUtil.getParentDependentParameters(nextReport, childParam); if ((childParam.getSource() != null) && (childParam.getSource().trim().length() > 0)) { try { Map<String, Serializable> allParameterValues = new HashMap<String, Serializable>(); for (String name : allParentParams.keySet()) { QueryParameter parent = allParentParams.get(name); index = parameters.indexOf(parent); JComponent parentComponent = getParameterComponent(index); allParameterValues.put(name, (Serializable)getParameterValue( parentComponent, parent)); } values = ParameterUtil.getParameterValues(connection, childParam, ParameterUtil.toMap(parameters), allParameterValues); setValues(childComponent,values); } catch (Exception e) { e.printStackTrace(); } } } }
java
private void populateDependentParameters(Report nextReport, QueryParameter parameter) { Map<String, QueryParameter> childParams = ParameterUtil.getChildDependentParameters(nextReport, parameter); // update model parameter values for every child parameter for (QueryParameter childParam : childParams.values()) { if (!parameters.contains(childParam)) { continue; } int index = parameters.indexOf(childParam); JComponent childComponent = getParameterComponent(index); List<IdName> values = new ArrayList<IdName>(); // a parameter may depend on more than one parameter (has more parents) // we must see if all the parents have selected values (this is not done in this example) Map<String, QueryParameter> allParentParams = ParameterUtil.getParentDependentParameters(nextReport, childParam); if ((childParam.getSource() != null) && (childParam.getSource().trim().length() > 0)) { try { Map<String, Serializable> allParameterValues = new HashMap<String, Serializable>(); for (String name : allParentParams.keySet()) { QueryParameter parent = allParentParams.get(name); index = parameters.indexOf(parent); JComponent parentComponent = getParameterComponent(index); allParameterValues.put(name, (Serializable)getParameterValue( parentComponent, parent)); } values = ParameterUtil.getParameterValues(connection, childParam, ParameterUtil.toMap(parameters), allParameterValues); setValues(childComponent,values); } catch (Exception e) { e.printStackTrace(); } } } }
[ "private", "void", "populateDependentParameters", "(", "Report", "nextReport", ",", "QueryParameter", "parameter", ")", "{", "Map", "<", "String", ",", "QueryParameter", ">", "childParams", "=", "ParameterUtil", ".", "getChildDependentParameters", "(", "nextReport", "...
and set their values too
[ "and", "set", "their", "values", "too" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/integration/RuntimeParametersPanel.java#L295-L333
train
nextreports/nextreports-engine
src/ro/nextreports/engine/util/StringUtil.java
StringUtil.equalsText
public static boolean equalsText(String s1, String s2) { if (s1 == null) { if (s2 != null) { return false; } } else { if (s2 == null) { return false; } } if ((s1 != null) && (s2 != null)) { s1 = s1.replaceAll("\\s", "").toLowerCase(); s2 = s2.replaceAll("\\s", "").toLowerCase(); if (!s1.equals(s2)) { return false; } } return true; }
java
public static boolean equalsText(String s1, String s2) { if (s1 == null) { if (s2 != null) { return false; } } else { if (s2 == null) { return false; } } if ((s1 != null) && (s2 != null)) { s1 = s1.replaceAll("\\s", "").toLowerCase(); s2 = s2.replaceAll("\\s", "").toLowerCase(); if (!s1.equals(s2)) { return false; } } return true; }
[ "public", "static", "boolean", "equalsText", "(", "String", "s1", ",", "String", "s2", ")", "{", "if", "(", "s1", "==", "null", ")", "{", "if", "(", "s2", "!=", "null", ")", "{", "return", "false", ";", "}", "}", "else", "{", "if", "(", "s2", "...
functional compare for two strings as ignore-case text
[ "functional", "compare", "for", "two", "strings", "as", "ignore", "-", "case", "text" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/util/StringUtil.java#L345-L363
train
nextreports/nextreports-engine
src/ro/nextreports/engine/util/StringUtil.java
StringUtil.isImage
private static boolean isImage(String hexString) { boolean isImage = false; //png if (hexString.startsWith("89504e470d0a1a0a")) { isImage = true; //gif } else if (hexString.startsWith("474946383761") || hexString.startsWith("474946383961")) { isImage = true; // jpeg } else if (hexString.startsWith("ffd8ffe0")) { isImage = true; } return isImage; }
java
private static boolean isImage(String hexString) { boolean isImage = false; //png if (hexString.startsWith("89504e470d0a1a0a")) { isImage = true; //gif } else if (hexString.startsWith("474946383761") || hexString.startsWith("474946383961")) { isImage = true; // jpeg } else if (hexString.startsWith("ffd8ffe0")) { isImage = true; } return isImage; }
[ "private", "static", "boolean", "isImage", "(", "String", "hexString", ")", "{", "boolean", "isImage", "=", "false", ";", "//png", "if", "(", "hexString", ".", "startsWith", "(", "\"89504e470d0a1a0a\"", ")", ")", "{", "isImage", "=", "true", ";", "//gif\t", ...
JPEGs start with FF D8 FF E0 xx xx 4A 46 49 46 00
[ "JPEGs", "start", "with", "FF", "D8", "FF", "E0", "xx", "xx", "4A", "46", "49", "46", "00" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/util/StringUtil.java#L407-L420
train
samskivert/samskivert
src/main/java/com/samskivert/swing/RadialLabelSausage.java
RadialLabelSausage.layout
public void layout (Graphics2D gfx, Font font) { _label.setFont(font); layout(gfx, BORDER_THICKNESS); openBounds.width = _size.width; openBounds.height = _size.height; // and closed up, we're just a circle closedBounds.height = closedBounds.width = _size.height; }
java
public void layout (Graphics2D gfx, Font font) { _label.setFont(font); layout(gfx, BORDER_THICKNESS); openBounds.width = _size.width; openBounds.height = _size.height; // and closed up, we're just a circle closedBounds.height = closedBounds.width = _size.height; }
[ "public", "void", "layout", "(", "Graphics2D", "gfx", ",", "Font", "font", ")", "{", "_label", ".", "setFont", "(", "font", ")", ";", "layout", "(", "gfx", ",", "BORDER_THICKNESS", ")", ";", "openBounds", ".", "width", "=", "_size", ".", "width", ";", ...
Computes the dimensions of this label based on the specified font and in the specified graphics context.
[ "Computes", "the", "dimensions", "of", "this", "label", "based", "on", "the", "specified", "font", "and", "in", "the", "specified", "graphics", "context", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/RadialLabelSausage.java#L89-L99
train
samskivert/samskivert
src/main/java/com/samskivert/swing/RadialLabelSausage.java
RadialLabelSausage.drawBase
@Override protected void drawBase (Graphics2D gfx, int x, int y) { if (_active) { // render the sausage super.drawBase(gfx, x, y); } else { // render the circle gfx.fillOval(x, y, closedBounds.width - 1, closedBounds.height - 1); } }
java
@Override protected void drawBase (Graphics2D gfx, int x, int y) { if (_active) { // render the sausage super.drawBase(gfx, x, y); } else { // render the circle gfx.fillOval(x, y, closedBounds.width - 1, closedBounds.height - 1); } }
[ "@", "Override", "protected", "void", "drawBase", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ")", "{", "if", "(", "_active", ")", "{", "// render the sausage", "super", ".", "drawBase", "(", "gfx", ",", "x", ",", "y", ")", ";", "}", ...
Draw the base circle or sausage within which all the other decorations are added.
[ "Draw", "the", "base", "circle", "or", "sausage", "within", "which", "all", "the", "other", "decorations", "are", "added", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/RadialLabelSausage.java#L162-L173
train
samskivert/samskivert
src/main/java/com/samskivert/swing/RadialLabelSausage.java
RadialLabelSausage.paint
protected void paint (Graphics2D gfx, int x, int y, RadialMenu menu) { paint(gfx, x, y, UIManager.getColor("RadialLabelSausage.background"), menu); }
java
protected void paint (Graphics2D gfx, int x, int y, RadialMenu menu) { paint(gfx, x, y, UIManager.getColor("RadialLabelSausage.background"), menu); }
[ "protected", "void", "paint", "(", "Graphics2D", "gfx", ",", "int", "x", ",", "int", "y", ",", "RadialMenu", "menu", ")", "{", "paint", "(", "gfx", ",", "x", ",", "y", ",", "UIManager", ".", "getColor", "(", "\"RadialLabelSausage.background\"", ")", ",",...
Paints the radial label sausage.
[ "Paints", "the", "radial", "label", "sausage", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/RadialLabelSausage.java#L178-L181
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.nextPowerOfTwo
public static int nextPowerOfTwo (int value) { return (int)Math.pow(2, Math.ceil(Math.log(value) / Math.log(2))); }
java
public static int nextPowerOfTwo (int value) { return (int)Math.pow(2, Math.ceil(Math.log(value) / Math.log(2))); }
[ "public", "static", "int", "nextPowerOfTwo", "(", "int", "value", ")", "{", "return", "(", "int", ")", "Math", ".", "pow", "(", "2", ",", "Math", ".", "ceil", "(", "Math", ".", "log", "(", "value", ")", "/", "Math", ".", "log", "(", "2", ")", "...
Rounds the specified value up to the next nearest power of two.
[ "Rounds", "the", "specified", "value", "up", "to", "the", "next", "nearest", "power", "of", "two", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L55-L58
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.add
public static Object[] add (Object[] list, int startIdx, Object element) { requireNotNull(element); // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; } // search for a spot to insert yon element; assuming we'll insert // it at the end of the list if we don't find one int llength = list.length; int index = llength; for (int i = startIdx; i < llength; i++) { if (list[i] == null) { index = i; break; } } // expand the list if necessary if (index >= llength) { list = accomodate(list, index); } // stick the element on in list[index] = element; return list; }
java
public static Object[] add (Object[] list, int startIdx, Object element) { requireNotNull(element); // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; } // search for a spot to insert yon element; assuming we'll insert // it at the end of the list if we don't find one int llength = list.length; int index = llength; for (int i = startIdx; i < llength; i++) { if (list[i] == null) { index = i; break; } } // expand the list if necessary if (index >= llength) { list = accomodate(list, index); } // stick the element on in list[index] = element; return list; }
[ "public", "static", "Object", "[", "]", "add", "(", "Object", "[", "]", "list", ",", "int", "startIdx", ",", "Object", "element", ")", "{", "requireNotNull", "(", "element", ")", ";", "// make sure we've got a list to work with", "if", "(", "list", "==", "nu...
Adds the specified element to the next empty slot in the specified list. Begins searching for empty slots at the specified index. This can be used to quickly add elements to a list that preserves consecutivity by calling it with the size of the list as the first index to check. @param list the list to which to add the element. Can be null. @param startIdx the index at which to start looking for a spot. @param element the element to add. @return a reference to the list with element added (might not be the list you passed in due to expansion, or allocation).
[ "Adds", "the", "specified", "element", "to", "the", "next", "empty", "slot", "in", "the", "specified", "list", ".", "Begins", "searching", "for", "empty", "slots", "at", "the", "specified", "index", ".", "This", "can", "be", "used", "to", "quickly", "add",...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L89-L118
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.insert
public static Object[] insert (Object[] list, int index, Object element) { requireNotNull(element); // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; } // make a note of the size of the array int size = list.length; // expand the list if necessary (the last element contains a // value) if (list[size-1] != null) { list = accomodate(list, size); } else { // otherwise, pretend the list is one element shorter and // we'll overwrite the last null size--; } // shift everything down System.arraycopy(list, index, list, index+1, size-index); // stick the element on in list[index] = element; return list; }
java
public static Object[] insert (Object[] list, int index, Object element) { requireNotNull(element); // make sure we've got a list to work with if (list == null) { list = new Object[DEFAULT_LIST_SIZE]; } // make a note of the size of the array int size = list.length; // expand the list if necessary (the last element contains a // value) if (list[size-1] != null) { list = accomodate(list, size); } else { // otherwise, pretend the list is one element shorter and // we'll overwrite the last null size--; } // shift everything down System.arraycopy(list, index, list, index+1, size-index); // stick the element on in list[index] = element; return list; }
[ "public", "static", "Object", "[", "]", "insert", "(", "Object", "[", "]", "list", ",", "int", "index", ",", "Object", "element", ")", "{", "requireNotNull", "(", "element", ")", ";", "// make sure we've got a list to work with", "if", "(", "list", "==", "nu...
Inserts the supplied element at the specified position in the array, shifting the remaining elements down. The array will be expanded if necessary. @param list the list in which to insert the element. Can be null. @param index the index at which to insert the element. @param element the element to insert. @return a reference to the list with element inserted (might not be the list you passed in due to expansion, or allocation).
[ "Inserts", "the", "supplied", "element", "at", "the", "specified", "position", "in", "the", "array", "shifting", "the", "remaining", "elements", "down", ".", "The", "array", "will", "be", "expanded", "if", "necessary", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L132-L161
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.indexOfNull
public static int indexOfNull (Object[] list) { if (list != null) { for (int ii=0, nn = list.length; ii < nn; ii++) { if (list[ii] == null) { return ii; } } } return -1; }
java
public static int indexOfNull (Object[] list) { if (list != null) { for (int ii=0, nn = list.length; ii < nn; ii++) { if (list[ii] == null) { return ii; } } } return -1; }
[ "public", "static", "int", "indexOfNull", "(", "Object", "[", "]", "list", ")", "{", "if", "(", "list", "!=", "null", ")", "{", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "list", ".", "length", ";", "ii", "<", "nn", ";", "ii", "++", "...
Returns the lowest index in the array that contains null, or -1 if there is no room to add elements without expanding the array.
[ "Returns", "the", "lowest", "index", "in", "the", "array", "that", "contains", "null", "or", "-", "1", "if", "there", "is", "no", "room", "to", "add", "elements", "without", "expanding", "the", "array", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L271-L281
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.remove
public static Object remove (Object[] list, int index) { if (list == null) { return null; } int llength = list.length; if (llength <= index || index < 0) { return null; } Object elem = list[index]; System.arraycopy(list, index+1, list, index, llength-(index+1)); list[llength-1] = null; return elem; }
java
public static Object remove (Object[] list, int index) { if (list == null) { return null; } int llength = list.length; if (llength <= index || index < 0) { return null; } Object elem = list[index]; System.arraycopy(list, index+1, list, index, llength-(index+1)); list[llength-1] = null; return elem; }
[ "public", "static", "Object", "remove", "(", "Object", "[", "]", "list", ",", "int", "index", ")", "{", "if", "(", "list", "==", "null", ")", "{", "return", "null", ";", "}", "int", "llength", "=", "list", ".", "length", ";", "if", "(", "llength", ...
Removes the element at the specified index. The elements after the removed element will be slid down the array one spot to fill the place of the removed element. If a null array is supplied or one that is not large enough to accomodate this index, null is returned. @return the object that was removed from the array or null if no object existed at that location.
[ "Removes", "the", "element", "at", "the", "specified", "index", ".", "The", "elements", "after", "the", "removed", "element", "will", "be", "slid", "down", "the", "array", "one", "spot", "to", "fill", "the", "place", "of", "the", "removed", "element", ".",...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L404-L419
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.size
@Deprecated public static int size (Object[] list) { if (list == null) { return 0; } int llength = list.length; for (int ii = 0; ii < llength; ii++) { if (list[ii] == null) { return ii; } } return llength; }
java
@Deprecated public static int size (Object[] list) { if (list == null) { return 0; } int llength = list.length; for (int ii = 0; ii < llength; ii++) { if (list[ii] == null) { return ii; } } return llength; }
[ "@", "Deprecated", "public", "static", "int", "size", "(", "Object", "[", "]", "list", ")", "{", "if", "(", "list", "==", "null", ")", "{", "return", "0", ";", "}", "int", "llength", "=", "list", ".", "length", ";", "for", "(", "int", "ii", "=", ...
Returns the number of elements prior to the first null in the supplied list. @deprecated This is incompatible with things like clearRef(), which leave a null space.
[ "Returns", "the", "number", "of", "elements", "prior", "to", "the", "first", "null", "in", "the", "supplied", "list", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L425-L437
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.getSize
public static int getSize (Object[] list) { int size = 0; for (int ii = 0, nn = (list == null) ? 0 : list.length; ii < nn; ii++) { if (list[ii] != null) { size++; } } return size; }
java
public static int getSize (Object[] list) { int size = 0; for (int ii = 0, nn = (list == null) ? 0 : list.length; ii < nn; ii++) { if (list[ii] != null) { size++; } } return size; }
[ "public", "static", "int", "getSize", "(", "Object", "[", "]", "list", ")", "{", "int", "size", "=", "0", ";", "for", "(", "int", "ii", "=", "0", ",", "nn", "=", "(", "list", "==", "null", ")", "?", "0", ":", "list", ".", "length", ";", "ii",...
Returns the number of non-null elements in the supplied list.
[ "Returns", "the", "number", "of", "non", "-", "null", "elements", "in", "the", "supplied", "list", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L442-L451
train
samskivert/samskivert
src/main/java/com/samskivert/util/ListUtil.java
ListUtil.main
public static void main (String[] args) { Object[] list = null; String foo = "foo"; String bar = "bar"; list = ListUtil.add(list, foo); System.out.println("add(foo): " + StringUtil.toString(list)); list = ListUtil.add(list, bar); System.out.println("add(bar): " + StringUtil.toString(list)); ListUtil.clearRef(list, foo); System.out.println("clear(foo): " + StringUtil.toString(list)); String newBar = new String("bar"); // prevent java from cleverly // referencing the same string // from the constant pool System.out.println("containsRef(newBar): " + ListUtil.containsRef(list, newBar)); System.out.println("contains(newBar): " + ListUtil.contains(list, newBar)); ListUtil.clear(list, newBar); System.out.println("clear(newBar): " + StringUtil.toString(list)); list = ListUtil.add(list, 0, foo); list = ListUtil.add(list, 1, bar); System.out.println("Added foo+bar: " + StringUtil.toString(list)); ListUtil.removeRef(list, foo); System.out.println("removeRef(foo): " + StringUtil.toString(list)); list = ListUtil.add(list, 0, foo); list = ListUtil.add(list, 1, bar); System.out.println("Added foo+bar: " + StringUtil.toString(list)); ListUtil.remove(list, 0); System.out.println("remove(0): " + StringUtil.toString(list)); ListUtil.remove(list, 0); System.out.println("remove(0): " + StringUtil.toString(list)); Object[] tl = ListUtil.testAndAddRef(list, bar); if (tl == null) { System.out.println("testAndAddRef(bar): failed: " + StringUtil.toString(list)); } else { list = tl; System.out.println("testAndAddRef(bar): added: " + StringUtil.toString(list)); } String biz = "biz"; tl = ListUtil.testAndAddRef(list, biz); if (tl == null) { System.out.println("testAndAddRef(biz): failed: " + StringUtil.toString(list)); } else { list = tl; System.out.println("testAndAddRef(biz): added: " + StringUtil.toString(list)); } }
java
public static void main (String[] args) { Object[] list = null; String foo = "foo"; String bar = "bar"; list = ListUtil.add(list, foo); System.out.println("add(foo): " + StringUtil.toString(list)); list = ListUtil.add(list, bar); System.out.println("add(bar): " + StringUtil.toString(list)); ListUtil.clearRef(list, foo); System.out.println("clear(foo): " + StringUtil.toString(list)); String newBar = new String("bar"); // prevent java from cleverly // referencing the same string // from the constant pool System.out.println("containsRef(newBar): " + ListUtil.containsRef(list, newBar)); System.out.println("contains(newBar): " + ListUtil.contains(list, newBar)); ListUtil.clear(list, newBar); System.out.println("clear(newBar): " + StringUtil.toString(list)); list = ListUtil.add(list, 0, foo); list = ListUtil.add(list, 1, bar); System.out.println("Added foo+bar: " + StringUtil.toString(list)); ListUtil.removeRef(list, foo); System.out.println("removeRef(foo): " + StringUtil.toString(list)); list = ListUtil.add(list, 0, foo); list = ListUtil.add(list, 1, bar); System.out.println("Added foo+bar: " + StringUtil.toString(list)); ListUtil.remove(list, 0); System.out.println("remove(0): " + StringUtil.toString(list)); ListUtil.remove(list, 0); System.out.println("remove(0): " + StringUtil.toString(list)); Object[] tl = ListUtil.testAndAddRef(list, bar); if (tl == null) { System.out.println("testAndAddRef(bar): failed: " + StringUtil.toString(list)); } else { list = tl; System.out.println("testAndAddRef(bar): added: " + StringUtil.toString(list)); } String biz = "biz"; tl = ListUtil.testAndAddRef(list, biz); if (tl == null) { System.out.println("testAndAddRef(biz): failed: " + StringUtil.toString(list)); } else { list = tl; System.out.println("testAndAddRef(biz): added: " + StringUtil.toString(list)); } }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "Object", "[", "]", "list", "=", "null", ";", "String", "foo", "=", "\"foo\"", ";", "String", "bar", "=", "\"bar\"", ";", "list", "=", "ListUtil", ".", "add", "(", "list...
Run some tests.
[ "Run", "some", "tests", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ListUtil.java#L484-L547
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.getOrElse
public int getOrElse (int key, int defval) { Record rec = locateRecord(key); return (rec == null) ? defval : rec.value; }
java
public int getOrElse (int key, int defval) { Record rec = locateRecord(key); return (rec == null) ? defval : rec.value; }
[ "public", "int", "getOrElse", "(", "int", "key", ",", "int", "defval", ")", "{", "Record", "rec", "=", "locateRecord", "(", "key", ")", ";", "return", "(", "rec", "==", "null", ")", "?", "defval", ":", "rec", ".", "value", ";", "}" ]
Returns the value mapped to the specified key or the supplied default value if there is no mapping.
[ "Returns", "the", "value", "mapped", "to", "the", "specified", "key", "or", "the", "supplied", "default", "value", "if", "there", "is", "no", "mapping", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L120-L124
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.removeOrElse
public int removeOrElse (int key, int defval) { _modCount++; int removed = removeImpl(key, defval); checkShrink(); return removed; }
java
public int removeOrElse (int key, int defval) { _modCount++; int removed = removeImpl(key, defval); checkShrink(); return removed; }
[ "public", "int", "removeOrElse", "(", "int", "key", ",", "int", "defval", ")", "{", "_modCount", "++", ";", "int", "removed", "=", "removeImpl", "(", "key", ",", "defval", ")", ";", "checkShrink", "(", ")", ";", "return", "removed", ";", "}" ]
Removes the value mapped for the specified key. @return the value to which the key was mapped or the supplied default value if there was no mapping for that key.
[ "Removes", "the", "value", "mapped", "for", "the", "specified", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L179-L185
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.clear
public void clear () { _modCount++; // abandon all of our hash chains (the joy of garbage collection) for (int i = 0; i < _buckets.length; i++) { _buckets[i] = null; } // zero out our size _size = 0; }
java
public void clear () { _modCount++; // abandon all of our hash chains (the joy of garbage collection) for (int i = 0; i < _buckets.length; i++) { _buckets[i] = null; } // zero out our size _size = 0; }
[ "public", "void", "clear", "(", ")", "{", "_modCount", "++", ";", "// abandon all of our hash chains (the joy of garbage collection)", "for", "(", "int", "i", "=", "0", ";", "i", "<", "_buckets", ".", "length", ";", "i", "++", ")", "{", "_buckets", "[", "i",...
Clears all mappings.
[ "Clears", "all", "mappings", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L190-L200
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.ensureCapacity
public void ensureCapacity (int minCapacity) { int size = _buckets.length; while (minCapacity > (int) (size * _loadFactor)) { size *= 2; } if (size != _buckets.length) { resizeBuckets(size); } }
java
public void ensureCapacity (int minCapacity) { int size = _buckets.length; while (minCapacity > (int) (size * _loadFactor)) { size *= 2; } if (size != _buckets.length) { resizeBuckets(size); } }
[ "public", "void", "ensureCapacity", "(", "int", "minCapacity", ")", "{", "int", "size", "=", "_buckets", ".", "length", ";", "while", "(", "minCapacity", ">", "(", "int", ")", "(", "size", "*", "_loadFactor", ")", ")", "{", "size", "*=", "2", ";", "}...
Ensure that the hash can comfortably hold the specified number of elements. Calling this method is not necessary, but can improve performance if done prior to adding many elements.
[ "Ensure", "that", "the", "hash", "can", "comfortably", "hold", "the", "specified", "number", "of", "elements", ".", "Calling", "this", "method", "is", "not", "necessary", "but", "can", "improve", "performance", "if", "done", "prior", "to", "adding", "many", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L206-L215
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.locateRecord
protected Record locateRecord (int key) { int index = Math.abs(key)%_buckets.length; for (Record rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { return rec; } } return null; }
java
protected Record locateRecord (int key) { int index = Math.abs(key)%_buckets.length; for (Record rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { return rec; } } return null; }
[ "protected", "Record", "locateRecord", "(", "int", "key", ")", "{", "int", "index", "=", "Math", ".", "abs", "(", "key", ")", "%", "_buckets", ".", "length", ";", "for", "(", "Record", "rec", "=", "_buckets", "[", "index", "]", ";", "rec", "!=", "n...
Internal method to locate the record for the specified key.
[ "Internal", "method", "to", "locate", "the", "record", "for", "the", "specified", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L220-L229
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.removeImpl
protected int removeImpl (int key, int defval) { int index = Math.abs(key)%_buckets.length; Record prev = null; // go through the chain looking for a match for (Record rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { if (prev == null) { _buckets[index] = rec.next; } else { prev.next = rec.next; } _size--; return rec.value; } prev = rec; } return defval; // not found }
java
protected int removeImpl (int key, int defval) { int index = Math.abs(key)%_buckets.length; Record prev = null; // go through the chain looking for a match for (Record rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { if (prev == null) { _buckets[index] = rec.next; } else { prev.next = rec.next; } _size--; return rec.value; } prev = rec; } return defval; // not found }
[ "protected", "int", "removeImpl", "(", "int", "key", ",", "int", "defval", ")", "{", "int", "index", "=", "Math", ".", "abs", "(", "key", ")", "%", "_buckets", ".", "length", ";", "Record", "prev", "=", "null", ";", "// go through the chain looking for a m...
Internal method for removing a mapping.
[ "Internal", "method", "for", "removing", "a", "mapping", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L234-L254
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.checkShrink
protected void checkShrink () { if ((_buckets.length > DEFAULT_BUCKETS) && (_size < (int) (_buckets.length * _loadFactor * .125))) { resizeBuckets(Math.max(DEFAULT_BUCKETS, _buckets.length >> 1)); } }
java
protected void checkShrink () { if ((_buckets.length > DEFAULT_BUCKETS) && (_size < (int) (_buckets.length * _loadFactor * .125))) { resizeBuckets(Math.max(DEFAULT_BUCKETS, _buckets.length >> 1)); } }
[ "protected", "void", "checkShrink", "(", ")", "{", "if", "(", "(", "_buckets", ".", "length", ">", "DEFAULT_BUCKETS", ")", "&&", "(", "_size", "<", "(", "int", ")", "(", "_buckets", ".", "length", "*", "_loadFactor", "*", ".125", ")", ")", ")", "{", ...
Check to see if we want to shrink the table.
[ "Check", "to", "see", "if", "we", "want", "to", "shrink", "the", "table", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L259-L265
train
samskivert/samskivert
src/main/java/com/samskivert/util/IntIntMap.java
IntIntMap.entrySet
public Set<IntIntEntry> entrySet () { return new AbstractSet<IntIntEntry>() { @Override public int size () { return _size; } @Override public Iterator<IntIntEntry> iterator() { return new IntEntryIterator(); } }; }
java
public Set<IntIntEntry> entrySet () { return new AbstractSet<IntIntEntry>() { @Override public int size () { return _size; } @Override public Iterator<IntIntEntry> iterator() { return new IntEntryIterator(); } }; }
[ "public", "Set", "<", "IntIntEntry", ">", "entrySet", "(", ")", "{", "return", "new", "AbstractSet", "<", "IntIntEntry", ">", "(", ")", "{", "@", "Override", "public", "int", "size", "(", ")", "{", "return", "_size", ";", "}", "@", "Override", "public"...
Get a set of all the entries in this map.
[ "Get", "a", "set", "of", "all", "the", "entries", "in", "this", "map", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/IntIntMap.java#L378-L389
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.addComponent
public void addComponent (BaseComponent comp) { if (comp instanceof InitComponent) { if (_initers == null) { throw new IllegalStateException("Too late to register InitComponent."); } _initers.add((InitComponent)comp); } if (comp instanceof ShutdownComponent) { if (_downers == null) { throw new IllegalStateException("Too late to register ShutdownComponent."); } _downers.add((ShutdownComponent)comp); } }
java
public void addComponent (BaseComponent comp) { if (comp instanceof InitComponent) { if (_initers == null) { throw new IllegalStateException("Too late to register InitComponent."); } _initers.add((InitComponent)comp); } if (comp instanceof ShutdownComponent) { if (_downers == null) { throw new IllegalStateException("Too late to register ShutdownComponent."); } _downers.add((ShutdownComponent)comp); } }
[ "public", "void", "addComponent", "(", "BaseComponent", "comp", ")", "{", "if", "(", "comp", "instanceof", "InitComponent", ")", "{", "if", "(", "_initers", "==", "null", ")", "{", "throw", "new", "IllegalStateException", "(", "\"Too late to register InitComponent...
Registers a component with the lifecycle. This should be done during dependency resolution by injecting the Lifecycle into your constructor and calling this method there.
[ "Registers", "a", "component", "with", "the", "lifecycle", ".", "This", "should", "be", "done", "during", "dependency", "resolution", "by", "injecting", "the", "Lifecycle", "into", "your", "constructor", "and", "calling", "this", "method", "there", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L46-L60
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.removeComponent
public void removeComponent (BaseComponent comp) { if (_initers != null && comp instanceof InitComponent) { _initers.remove((InitComponent)comp); } if (_downers != null && comp instanceof ShutdownComponent) { _downers.remove((ShutdownComponent)comp); } }
java
public void removeComponent (BaseComponent comp) { if (_initers != null && comp instanceof InitComponent) { _initers.remove((InitComponent)comp); } if (_downers != null && comp instanceof ShutdownComponent) { _downers.remove((ShutdownComponent)comp); } }
[ "public", "void", "removeComponent", "(", "BaseComponent", "comp", ")", "{", "if", "(", "_initers", "!=", "null", "&&", "comp", "instanceof", "InitComponent", ")", "{", "_initers", ".", "remove", "(", "(", "InitComponent", ")", "comp", ")", ";", "}", "if",...
Removes a component from the lifecycle. This is generally not used.
[ "Removes", "a", "component", "from", "the", "lifecycle", ".", "This", "is", "generally", "not", "used", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L65-L73
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.addInitConstraint
public void addInitConstraint (InitComponent lhs, Constraint constraint, InitComponent rhs) { if (lhs == null || rhs == null) { throw new IllegalArgumentException("Cannot add constraint about null component."); } InitComponent before = (constraint == Constraint.RUNS_BEFORE) ? lhs : rhs; InitComponent after = (constraint == Constraint.RUNS_BEFORE) ? rhs : lhs; _initers.addDependency(after, before); }
java
public void addInitConstraint (InitComponent lhs, Constraint constraint, InitComponent rhs) { if (lhs == null || rhs == null) { throw new IllegalArgumentException("Cannot add constraint about null component."); } InitComponent before = (constraint == Constraint.RUNS_BEFORE) ? lhs : rhs; InitComponent after = (constraint == Constraint.RUNS_BEFORE) ? rhs : lhs; _initers.addDependency(after, before); }
[ "public", "void", "addInitConstraint", "(", "InitComponent", "lhs", ",", "Constraint", "constraint", ",", "InitComponent", "rhs", ")", "{", "if", "(", "lhs", "==", "null", "||", "rhs", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", ...
Adds a constraint that a certain component must be initialized before another.
[ "Adds", "a", "constraint", "that", "a", "certain", "component", "must", "be", "initialized", "before", "another", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L78-L86
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.addShutdownConstraint
public void addShutdownConstraint (ShutdownComponent lhs, Constraint constraint, ShutdownComponent rhs) { if (lhs == null || rhs == null) { throw new IllegalArgumentException("Cannot add constraint about null component."); } ShutdownComponent before = (constraint == Constraint.RUNS_BEFORE) ? lhs : rhs; ShutdownComponent after = (constraint == Constraint.RUNS_BEFORE) ? rhs : lhs; _downers.addDependency(after, before); }
java
public void addShutdownConstraint (ShutdownComponent lhs, Constraint constraint, ShutdownComponent rhs) { if (lhs == null || rhs == null) { throw new IllegalArgumentException("Cannot add constraint about null component."); } ShutdownComponent before = (constraint == Constraint.RUNS_BEFORE) ? lhs : rhs; ShutdownComponent after = (constraint == Constraint.RUNS_BEFORE) ? rhs : lhs; _downers.addDependency(after, before); }
[ "public", "void", "addShutdownConstraint", "(", "ShutdownComponent", "lhs", ",", "Constraint", "constraint", ",", "ShutdownComponent", "rhs", ")", "{", "if", "(", "lhs", "==", "null", "||", "rhs", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException...
Adds a constraint that a certain component must be shutdown before another.
[ "Adds", "a", "constraint", "that", "a", "certain", "component", "must", "be", "shutdown", "before", "another", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L91-L100
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.init
public void init () { if (_initers == null) { log.warning("Refusing repeat init() request."); return; } ObserverList<InitComponent> list = _initers.toObserverList(); _initers = null; list.apply(new ObserverList.ObserverOp<InitComponent>() { public boolean apply (InitComponent comp) { log.debug("Initializing component", "comp", comp); comp.init(); return true; } }); }
java
public void init () { if (_initers == null) { log.warning("Refusing repeat init() request."); return; } ObserverList<InitComponent> list = _initers.toObserverList(); _initers = null; list.apply(new ObserverList.ObserverOp<InitComponent>() { public boolean apply (InitComponent comp) { log.debug("Initializing component", "comp", comp); comp.init(); return true; } }); }
[ "public", "void", "init", "(", ")", "{", "if", "(", "_initers", "==", "null", ")", "{", "log", ".", "warning", "(", "\"Refusing repeat init() request.\"", ")", ";", "return", ";", "}", "ObserverList", "<", "InitComponent", ">", "list", "=", "_initers", "."...
Initializes all components immediately on the caller's thread.
[ "Initializes", "all", "components", "immediately", "on", "the", "caller", "s", "thread", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L113-L129
train
samskivert/samskivert
src/main/java/com/samskivert/util/Lifecycle.java
Lifecycle.shutdown
public void shutdown () { if (_downers == null) { log.warning("Refusing repeat shutdown() request."); return; } ObserverList<ShutdownComponent> list = _downers.toObserverList(); _downers = null; list.apply(new ObserverList.ObserverOp<ShutdownComponent>() { public boolean apply (ShutdownComponent comp) { log.debug("Shutting down component", "comp", comp); comp.shutdown(); return true; } }); }
java
public void shutdown () { if (_downers == null) { log.warning("Refusing repeat shutdown() request."); return; } ObserverList<ShutdownComponent> list = _downers.toObserverList(); _downers = null; list.apply(new ObserverList.ObserverOp<ShutdownComponent>() { public boolean apply (ShutdownComponent comp) { log.debug("Shutting down component", "comp", comp); comp.shutdown(); return true; } }); }
[ "public", "void", "shutdown", "(", ")", "{", "if", "(", "_downers", "==", "null", ")", "{", "log", ".", "warning", "(", "\"Refusing repeat shutdown() request.\"", ")", ";", "return", ";", "}", "ObserverList", "<", "ShutdownComponent", ">", "list", "=", "_dow...
Shuts down all components immediately on the caller's thread.
[ "Shuts", "down", "all", "components", "immediately", "on", "the", "caller", "s", "thread", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Lifecycle.java#L134-L150
train
samskivert/samskivert
src/main/java/com/samskivert/util/HashIntMap.java
HashIntMap.getImpl
protected Record<V> getImpl (int key) { for (Record<V> rec = _buckets[keyToIndex(key)]; rec != null; rec = rec.next) { if (rec.key == key) { return rec; } } return null; }
java
protected Record<V> getImpl (int key) { for (Record<V> rec = _buckets[keyToIndex(key)]; rec != null; rec = rec.next) { if (rec.key == key) { return rec; } } return null; }
[ "protected", "Record", "<", "V", ">", "getImpl", "(", "int", "key", ")", "{", "for", "(", "Record", "<", "V", ">", "rec", "=", "_buckets", "[", "keyToIndex", "(", "key", ")", "]", ";", "rec", "!=", "null", ";", "rec", "=", "rec", ".", "next", "...
Locate the record with the specified key.
[ "Locate", "the", "record", "with", "the", "specified", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/HashIntMap.java#L168-L176
train
samskivert/samskivert
src/main/java/com/samskivert/util/HashIntMap.java
HashIntMap.removeImpl
protected Record<V> removeImpl (int key, boolean checkShrink) { int index = keyToIndex(key); // go through the chain looking for a match for (Record<V> prev = null, rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { if (prev == null) { _buckets[index] = rec.next; } else { prev.next = rec.next; } _size--; if (checkShrink) { checkShrink(); } return rec; } prev = rec; } return null; }
java
protected Record<V> removeImpl (int key, boolean checkShrink) { int index = keyToIndex(key); // go through the chain looking for a match for (Record<V> prev = null, rec = _buckets[index]; rec != null; rec = rec.next) { if (rec.key == key) { if (prev == null) { _buckets[index] = rec.next; } else { prev.next = rec.next; } _size--; if (checkShrink) { checkShrink(); } return rec; } prev = rec; } return null; }
[ "protected", "Record", "<", "V", ">", "removeImpl", "(", "int", "key", ",", "boolean", "checkShrink", ")", "{", "int", "index", "=", "keyToIndex", "(", "key", ")", ";", "// go through the chain looking for a match", "for", "(", "Record", "<", "V", ">", "prev...
Remove an element with optional checking to see if we should shrink. When this is called from our iterator, checkShrink==false to avoid booching the buckets.
[ "Remove", "an", "element", "with", "optional", "checking", "to", "see", "if", "we", "should", "shrink", ".", "When", "this", "is", "called", "from", "our", "iterator", "checkShrink", "==", "false", "to", "avoid", "booching", "the", "buckets", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/HashIntMap.java#L182-L204
train
samskivert/samskivert
src/main/java/com/samskivert/util/HashIntMap.java
HashIntMap.keyToIndex
protected final int keyToIndex (int key) { // we lift the hash-fixing function from HashMap because Sun // wasn't kind enough to make it public key += ~(key << 9); key ^= (key >>> 14); key += (key << 4); key ^= (key >>> 10); return key & (_buckets.length - 1); }
java
protected final int keyToIndex (int key) { // we lift the hash-fixing function from HashMap because Sun // wasn't kind enough to make it public key += ~(key << 9); key ^= (key >>> 14); key += (key << 4); key ^= (key >>> 10); return key & (_buckets.length - 1); }
[ "protected", "final", "int", "keyToIndex", "(", "int", "key", ")", "{", "// we lift the hash-fixing function from HashMap because Sun", "// wasn't kind enough to make it public", "key", "+=", "~", "(", "key", "<<", "9", ")", ";", "key", "^=", "(", "key", ">>>", "14"...
Turn the specified key into an index.
[ "Turn", "the", "specified", "key", "into", "an", "index", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/HashIntMap.java#L243-L252
train
samskivert/samskivert
src/main/java/com/samskivert/util/HashIntMap.java
HashIntMap.intKeySet
public IntSet intKeySet () { // damn Sun bastards made the 'keySet' variable with default access, so we can't share it if (_keySet == null) { _keySet = new AbstractIntSet() { public Interator interator () { return new AbstractInterator () { public boolean hasNext () { return i.hasNext(); } public int nextInt () { return i.next().getIntKey(); } @Override public void remove () { i.remove(); } private Iterator<IntEntry<V>> i = intEntrySet().iterator(); }; } @Override public int size () { return HashIntMap.this.size(); } @Override public boolean contains (int t) { return HashIntMap.this.containsKey(t); } @Override public boolean remove (int value) { Record<V> removed = removeImpl(value, true); return (removed != null); } }; } return _keySet; }
java
public IntSet intKeySet () { // damn Sun bastards made the 'keySet' variable with default access, so we can't share it if (_keySet == null) { _keySet = new AbstractIntSet() { public Interator interator () { return new AbstractInterator () { public boolean hasNext () { return i.hasNext(); } public int nextInt () { return i.next().getIntKey(); } @Override public void remove () { i.remove(); } private Iterator<IntEntry<V>> i = intEntrySet().iterator(); }; } @Override public int size () { return HashIntMap.this.size(); } @Override public boolean contains (int t) { return HashIntMap.this.containsKey(t); } @Override public boolean remove (int value) { Record<V> removed = removeImpl(value, true); return (removed != null); } }; } return _keySet; }
[ "public", "IntSet", "intKeySet", "(", ")", "{", "// damn Sun bastards made the 'keySet' variable with default access, so we can't share it", "if", "(", "_keySet", "==", "null", ")", "{", "_keySet", "=", "new", "AbstractIntSet", "(", ")", "{", "public", "Interator", "int...
documentation inherited from interface IntMap
[ "documentation", "inherited", "from", "interface", "IntMap" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/HashIntMap.java#L384-L419
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/RequestUtils.java
RequestUtils.rehostLocation
public static String rehostLocation ( HttpServletRequest req, String servername) { StringBuffer buf = req.getRequestURL(); String csname = req.getServerName(); int csidx = buf.indexOf(csname); if (csidx != -1) { buf.delete(csidx, csidx + csname.length()); buf.insert(csidx, servername); } String query = req.getQueryString(); if (!StringUtil.isBlank(query)) { buf.append("?").append(query); } return buf.toString(); }
java
public static String rehostLocation ( HttpServletRequest req, String servername) { StringBuffer buf = req.getRequestURL(); String csname = req.getServerName(); int csidx = buf.indexOf(csname); if (csidx != -1) { buf.delete(csidx, csidx + csname.length()); buf.insert(csidx, servername); } String query = req.getQueryString(); if (!StringUtil.isBlank(query)) { buf.append("?").append(query); } return buf.toString(); }
[ "public", "static", "String", "rehostLocation", "(", "HttpServletRequest", "req", ",", "String", "servername", ")", "{", "StringBuffer", "buf", "=", "req", ".", "getRequestURL", "(", ")", ";", "String", "csname", "=", "req", ".", "getServerName", "(", ")", "...
Recreates the URL used to make the supplied request, replacing the server part of the URL with the supplied server name.
[ "Recreates", "the", "URL", "used", "to", "make", "the", "supplied", "request", "replacing", "the", "server", "part", "of", "the", "URL", "with", "the", "supplied", "server", "name", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/RequestUtils.java#L54-L69
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/util/RequestUtils.java
RequestUtils.getServletURL
public static String getServletURL (HttpServletRequest req, String path) { StringBuffer buf = req.getRequestURL(); String sname = req.getServletPath(); buf.delete(buf.length() - sname.length(), buf.length()); if (!path.startsWith("/")) { buf.append("/"); } buf.append(path); return buf.toString(); }
java
public static String getServletURL (HttpServletRequest req, String path) { StringBuffer buf = req.getRequestURL(); String sname = req.getServletPath(); buf.delete(buf.length() - sname.length(), buf.length()); if (!path.startsWith("/")) { buf.append("/"); } buf.append(path); return buf.toString(); }
[ "public", "static", "String", "getServletURL", "(", "HttpServletRequest", "req", ",", "String", "path", ")", "{", "StringBuffer", "buf", "=", "req", ".", "getRequestURL", "(", ")", ";", "String", "sname", "=", "req", ".", "getServletPath", "(", ")", ";", "...
Prepends the server, port and servlet context path to the supplied path, resulting in a fully-formed URL for requesting a servlet.
[ "Prepends", "the", "server", "port", "and", "servlet", "context", "path", "to", "the", "supplied", "path", "resulting", "in", "a", "fully", "-", "formed", "URL", "for", "requesting", "a", "servlet", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/util/RequestUtils.java#L75-L85
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ObjectEditorTable.java
ObjectEditorTable.insertDatum
public void insertDatum (Object element, int row) { _data.add(row, element); _model.fireTableRowsInserted(row, row); }
java
public void insertDatum (Object element, int row) { _data.add(row, element); _model.fireTableRowsInserted(row, row); }
[ "public", "void", "insertDatum", "(", "Object", "element", ",", "int", "row", ")", "{", "_data", ".", "add", "(", "row", ",", "element", ")", ";", "_model", ".", "fireTableRowsInserted", "(", "row", ",", "row", ")", ";", "}" ]
Insert the specified element at the specified row.
[ "Insert", "the", "specified", "element", "at", "the", "specified", "row", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ObjectEditorTable.java#L217-L221
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ObjectEditorTable.java
ObjectEditorTable.updateDatum
public void updateDatum (Object element, int row) { _data.set(row, element); _model.fireTableRowsUpdated(row, row); }
java
public void updateDatum (Object element, int row) { _data.set(row, element); _model.fireTableRowsUpdated(row, row); }
[ "public", "void", "updateDatum", "(", "Object", "element", ",", "int", "row", ")", "{", "_data", ".", "set", "(", "row", ",", "element", ")", ";", "_model", ".", "fireTableRowsUpdated", "(", "row", ",", "row", ")", ";", "}" ]
Change the value of the specified row.
[ "Change", "the", "value", "of", "the", "specified", "row", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ObjectEditorTable.java#L226-L230
train
samskivert/samskivert
src/main/java/com/samskivert/swing/ObjectEditorTable.java
ObjectEditorTable.removeDatum
public void removeDatum (Object element) { int dex = _data.indexOf(element); if (dex != -1) { removeDatum(dex); } }
java
public void removeDatum (Object element) { int dex = _data.indexOf(element); if (dex != -1) { removeDatum(dex); } }
[ "public", "void", "removeDatum", "(", "Object", "element", ")", "{", "int", "dex", "=", "_data", ".", "indexOf", "(", "element", ")", ";", "if", "(", "dex", "!=", "-", "1", ")", "{", "removeDatum", "(", "dex", ")", ";", "}", "}" ]
Remove the specified element from the set of data.
[ "Remove", "the", "specified", "element", "from", "the", "set", "of", "data", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/swing/ObjectEditorTable.java#L235-L241
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/HttpErrorException.java
HttpErrorException.getErrorMessage
public String getErrorMessage () { String msg = getMessage(); return String.valueOf(_errorCode).equals(msg) ? null : msg; }
java
public String getErrorMessage () { String msg = getMessage(); return String.valueOf(_errorCode).equals(msg) ? null : msg; }
[ "public", "String", "getErrorMessage", "(", ")", "{", "String", "msg", "=", "getMessage", "(", ")", ";", "return", "String", ".", "valueOf", "(", "_errorCode", ")", ".", "equals", "(", "msg", ")", "?", "null", ":", "msg", ";", "}" ]
Returns the textual error message supplied with this exception or null if only an error code was supplied.
[ "Returns", "the", "textual", "error", "message", "supplied", "with", "this", "exception", "or", "null", "if", "only", "an", "error", "code", "was", "supplied", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/HttpErrorException.java#L44-L48
train
samskivert/samskivert
src/main/java/com/samskivert/net/PathUtil.java
PathUtil.getCanonicalPathElements
public static String[] getCanonicalPathElements (File file) throws IOException { file = file.getCanonicalFile(); // If we were a file, get its parent if (!file.isDirectory()) { file = file.getParentFile(); } return file.getPath().split(File.separator); }
java
public static String[] getCanonicalPathElements (File file) throws IOException { file = file.getCanonicalFile(); // If we were a file, get its parent if (!file.isDirectory()) { file = file.getParentFile(); } return file.getPath().split(File.separator); }
[ "public", "static", "String", "[", "]", "getCanonicalPathElements", "(", "File", "file", ")", "throws", "IOException", "{", "file", "=", "file", ".", "getCanonicalFile", "(", ")", ";", "// If we were a file, get its parent", "if", "(", "!", "file", ".", "isDirec...
Gets the individual path elements building up the canonical path to the given file.
[ "Gets", "the", "individual", "path", "elements", "building", "up", "the", "canonical", "path", "to", "the", "given", "file", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/PathUtil.java#L63-L74
train
samskivert/samskivert
src/main/java/com/samskivert/net/PathUtil.java
PathUtil.computeRelativePath
public static String computeRelativePath (File file, File relativeTo) throws IOException { String[] realDirs = getCanonicalPathElements(file); String[] relativeToDirs = getCanonicalPathElements(relativeTo); // Eliminate the common root int common = 0; for (; common < realDirs.length && common < relativeToDirs.length; common++) { if (!realDirs[common].equals(relativeToDirs[common])) { break; } } String relativePath = ""; // For each remaining level in the file path, add a .. for (int ii = 0; ii < (realDirs.length - common); ii++) { relativePath += ".." + File.separator; } // For each level in the resource path, add the path for (; common < relativeToDirs.length; common++) { relativePath += relativeToDirs[common] + File.separator; } return relativePath; }
java
public static String computeRelativePath (File file, File relativeTo) throws IOException { String[] realDirs = getCanonicalPathElements(file); String[] relativeToDirs = getCanonicalPathElements(relativeTo); // Eliminate the common root int common = 0; for (; common < realDirs.length && common < relativeToDirs.length; common++) { if (!realDirs[common].equals(relativeToDirs[common])) { break; } } String relativePath = ""; // For each remaining level in the file path, add a .. for (int ii = 0; ii < (realDirs.length - common); ii++) { relativePath += ".." + File.separator; } // For each level in the resource path, add the path for (; common < relativeToDirs.length; common++) { relativePath += relativeToDirs[common] + File.separator; } return relativePath; }
[ "public", "static", "String", "computeRelativePath", "(", "File", "file", ",", "File", "relativeTo", ")", "throws", "IOException", "{", "String", "[", "]", "realDirs", "=", "getCanonicalPathElements", "(", "file", ")", ";", "String", "[", "]", "relativeToDirs", ...
Computes a relative path between to Files @param file the file we're referencing @param relativeTo the path from which we want to refer to the file
[ "Computes", "a", "relative", "path", "between", "to", "Files" ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/PathUtil.java#L82-L109
train
nextreports/nextreports-engine
src/ro/nextreports/engine/EngineProperties.java
EngineProperties.getRunPriority
public static int getRunPriority() { String s = System.getProperty(RUN_PRIORITY_PROPERTY); int priority = Thread.NORM_PRIORITY; if (s != null) { try { priority = Integer.parseInt(s); } catch (NumberFormatException ex) { // priority remains Thread.NORM_PRIORITY } } return priority; }
java
public static int getRunPriority() { String s = System.getProperty(RUN_PRIORITY_PROPERTY); int priority = Thread.NORM_PRIORITY; if (s != null) { try { priority = Integer.parseInt(s); } catch (NumberFormatException ex) { // priority remains Thread.NORM_PRIORITY } } return priority; }
[ "public", "static", "int", "getRunPriority", "(", ")", "{", "String", "s", "=", "System", ".", "getProperty", "(", "RUN_PRIORITY_PROPERTY", ")", ";", "int", "priority", "=", "Thread", ".", "NORM_PRIORITY", ";", "if", "(", "s", "!=", "null", ")", "{", "tr...
Get priority for running next reports queries and exporters @return priority for running next reports queries and exporters
[ "Get", "priority", "for", "running", "next", "reports", "queries", "and", "exporters" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/EngineProperties.java#L44-L55
train
nextreports/nextreports-engine
src/ro/nextreports/engine/EngineProperties.java
EngineProperties.getRecordsYield
public static int getRecordsYield() { String s = System.getProperty(RECORDS_YIELD_PROPERTY); int records = Integer.MAX_VALUE; if (s != null) { try { records = Integer.parseInt(s); } catch (NumberFormatException ex) { // records remains Integer.MAX_VALUE } } return records; }
java
public static int getRecordsYield() { String s = System.getProperty(RECORDS_YIELD_PROPERTY); int records = Integer.MAX_VALUE; if (s != null) { try { records = Integer.parseInt(s); } catch (NumberFormatException ex) { // records remains Integer.MAX_VALUE } } return records; }
[ "public", "static", "int", "getRecordsYield", "(", ")", "{", "String", "s", "=", "System", ".", "getProperty", "(", "RECORDS_YIELD_PROPERTY", ")", ";", "int", "records", "=", "Integer", ".", "MAX_VALUE", ";", "if", "(", "s", "!=", "null", ")", "{", "try"...
Get number of query records after the exporter waits a little to degrevate the processor @return number of query records after the exporter waits a little to degrevate the processor
[ "Get", "number", "of", "query", "records", "after", "the", "exporter", "waits", "a", "little", "to", "degrevate", "the", "processor" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/EngineProperties.java#L61-L72
train
nextreports/nextreports-engine
src/ro/nextreports/engine/EngineProperties.java
EngineProperties.getMillisYield
public static int getMillisYield() { String s = System.getProperty(MILLIS_YIELD_PROPERTY); int millis = DEFAULT_MILLIS_YIELD; if (s != null) { try { millis = Integer.parseInt(s); } catch (NumberFormatException ex) { // records remains DEFAULT_MILLIS_YIELD } } return millis; }
java
public static int getMillisYield() { String s = System.getProperty(MILLIS_YIELD_PROPERTY); int millis = DEFAULT_MILLIS_YIELD; if (s != null) { try { millis = Integer.parseInt(s); } catch (NumberFormatException ex) { // records remains DEFAULT_MILLIS_YIELD } } return millis; }
[ "public", "static", "int", "getMillisYield", "(", ")", "{", "String", "s", "=", "System", ".", "getProperty", "(", "MILLIS_YIELD_PROPERTY", ")", ";", "int", "millis", "=", "DEFAULT_MILLIS_YIELD", ";", "if", "(", "s", "!=", "null", ")", "{", "try", "{", "...
Get number of milliseconds the exporter will wait after RECORDS_YIELD are exported @return number of milliseconds the exporter will wait after RECORDS_YIELD are exported
[ "Get", "number", "of", "milliseconds", "the", "exporter", "will", "wait", "after", "RECORDS_YIELD", "are", "exported" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/EngineProperties.java#L78-L89
train
nextreports/nextreports-engine
src/ro/nextreports/engine/exporter/XlsExporter.java
XlsExporter.createSummaryInformation
public static void createSummaryInformation(String filePath, String title) { if (filePath == null) { return; } try { File poiFilesystem = new File(filePath); InputStream is = new FileInputStream(poiFilesystem); POIFSFileSystem poifs = new POIFSFileSystem(is); is.close(); DirectoryEntry dir = poifs.getRoot(); SummaryInformation si = PropertySetFactory.newSummaryInformation(); si.setTitle(title); si.setAuthor(ReleaseInfoAdapter.getCompany()); si.setApplicationName("NextReports " + ReleaseInfoAdapter.getVersionNumber()); si.setSubject("Created by NextReports Designer" + ReleaseInfoAdapter.getVersionNumber()); si.setCreateDateTime(new Date()); si.setKeywords(ReleaseInfoAdapter.getHome()); si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME); OutputStream out = new FileOutputStream(poiFilesystem); poifs.writeFilesystem(out); out.close(); } catch (Exception ex) { ex.printStackTrace(); } }
java
public static void createSummaryInformation(String filePath, String title) { if (filePath == null) { return; } try { File poiFilesystem = new File(filePath); InputStream is = new FileInputStream(poiFilesystem); POIFSFileSystem poifs = new POIFSFileSystem(is); is.close(); DirectoryEntry dir = poifs.getRoot(); SummaryInformation si = PropertySetFactory.newSummaryInformation(); si.setTitle(title); si.setAuthor(ReleaseInfoAdapter.getCompany()); si.setApplicationName("NextReports " + ReleaseInfoAdapter.getVersionNumber()); si.setSubject("Created by NextReports Designer" + ReleaseInfoAdapter.getVersionNumber()); si.setCreateDateTime(new Date()); si.setKeywords(ReleaseInfoAdapter.getHome()); si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME); OutputStream out = new FileOutputStream(poiFilesystem); poifs.writeFilesystem(out); out.close(); } catch (Exception ex) { ex.printStackTrace(); } }
[ "public", "static", "void", "createSummaryInformation", "(", "String", "filePath", ",", "String", "title", ")", "{", "if", "(", "filePath", "==", "null", ")", "{", "return", ";", "}", "try", "{", "File", "poiFilesystem", "=", "new", "File", "(", "filePath"...
is called also on the server
[ "is", "called", "also", "on", "the", "server" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/exporter/XlsExporter.java#L165-L194
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/SiteResourceLoader.java
SiteResourceLoader.getSiteClassLoader
public ClassLoader getSiteClassLoader (int siteId) throws IOException { // synchronize on the lock to ensure that only one thread per site // is concurrently executing synchronized (getLock(siteId)) { // see if we've already got one ClassLoader loader = _loaders.get(siteId); // create one if we've not if (loader == null) { final SiteResourceBundle bundle = getBundle(siteId); if (bundle == null) { // no bundle... no classloader. return null; } loader = AccessController.doPrivileged(new PrivilegedAction<SiteClassLoader>() { public SiteClassLoader run () { return new SiteClassLoader(bundle); } }); _loaders.put(siteId, loader); } return loader; } }
java
public ClassLoader getSiteClassLoader (int siteId) throws IOException { // synchronize on the lock to ensure that only one thread per site // is concurrently executing synchronized (getLock(siteId)) { // see if we've already got one ClassLoader loader = _loaders.get(siteId); // create one if we've not if (loader == null) { final SiteResourceBundle bundle = getBundle(siteId); if (bundle == null) { // no bundle... no classloader. return null; } loader = AccessController.doPrivileged(new PrivilegedAction<SiteClassLoader>() { public SiteClassLoader run () { return new SiteClassLoader(bundle); } }); _loaders.put(siteId, loader); } return loader; } }
[ "public", "ClassLoader", "getSiteClassLoader", "(", "int", "siteId", ")", "throws", "IOException", "{", "// synchronize on the lock to ensure that only one thread per site", "// is concurrently executing", "synchronized", "(", "getLock", "(", "siteId", ")", ")", "{", "// see ...
Returns a class loader that loads resources from the site-specific jar file for the specified site. If no site-specific jar file exists for the specified site, null will be returned.
[ "Returns", "a", "class", "loader", "that", "loads", "resources", "from", "the", "site", "-", "specific", "jar", "file", "for", "the", "specified", "site", ".", "If", "no", "site", "-", "specific", "jar", "file", "exists", "for", "the", "specified", "site",...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/SiteResourceLoader.java#L139-L166
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/SiteResourceLoader.java
SiteResourceLoader.getLock
protected Object getLock (int siteId) { Object lock = null; synchronized (_locks) { lock = _locks.get(siteId); // create a lock object if we haven't one already if (lock == null) { _locks.put(siteId, lock = new Object()); } } return lock; }
java
protected Object getLock (int siteId) { Object lock = null; synchronized (_locks) { lock = _locks.get(siteId); // create a lock object if we haven't one already if (lock == null) { _locks.put(siteId, lock = new Object()); } } return lock; }
[ "protected", "Object", "getLock", "(", "int", "siteId", ")", "{", "Object", "lock", "=", "null", ";", "synchronized", "(", "_locks", ")", "{", "lock", "=", "_locks", ".", "get", "(", "siteId", ")", ";", "// create a lock object if we haven't one already", "if"...
We synchronize on a per-site basis, but we use a separate lock object for each site so that the process of loading a bundle for the first time does not require blocking access to resources from other sites.
[ "We", "synchronize", "on", "a", "per", "-", "site", "basis", "but", "we", "use", "a", "separate", "lock", "object", "for", "each", "site", "so", "that", "the", "process", "of", "loading", "a", "bundle", "for", "the", "first", "time", "does", "not", "re...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/SiteResourceLoader.java#L180-L194
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/SiteResourceLoader.java
SiteResourceLoader.getBundle
protected SiteResourceBundle getBundle (int siteId) throws IOException { // look up the site resource bundle for this site SiteResourceBundle bundle = _bundles.get(siteId); // if we haven't got one, create one if (bundle == null) { // obtain the string identifier for this site String ident = _siteIdent.getSiteString(siteId); // compose that with the jar file directory to obtain the // path to the site-specific jar file File file = new File(_jarPath, ident + JAR_EXTENSION); // create a handle for this site-specific jar file bundle = new SiteResourceBundle(file); // cache our new bundle _bundles.put(siteId, bundle); } return bundle; }
java
protected SiteResourceBundle getBundle (int siteId) throws IOException { // look up the site resource bundle for this site SiteResourceBundle bundle = _bundles.get(siteId); // if we haven't got one, create one if (bundle == null) { // obtain the string identifier for this site String ident = _siteIdent.getSiteString(siteId); // compose that with the jar file directory to obtain the // path to the site-specific jar file File file = new File(_jarPath, ident + JAR_EXTENSION); // create a handle for this site-specific jar file bundle = new SiteResourceBundle(file); // cache our new bundle _bundles.put(siteId, bundle); } return bundle; }
[ "protected", "SiteResourceBundle", "getBundle", "(", "int", "siteId", ")", "throws", "IOException", "{", "// look up the site resource bundle for this site", "SiteResourceBundle", "bundle", "=", "_bundles", ".", "get", "(", "siteId", ")", ";", "// if we haven't got one, cre...
Obtains the site-specific jar file for the specified site. This should only be called when the lock for this site is held.
[ "Obtains", "the", "site", "-", "specific", "jar", "file", "for", "the", "specified", "site", ".", "This", "should", "only", "be", "called", "when", "the", "lock", "for", "this", "site", "is", "held", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/SiteResourceLoader.java#L200-L220
train
samskivert/samskivert
src/main/java/com/samskivert/util/Interval.java
Interval.create
public static Interval create (RunQueue runQueue, final Runnable onExpired) { // we could probably avoid all the wacky machinations internal to Interval that do the // runbuddy reposting and whatever and just create a non-runqueue interval that posts the // supplied runnable to the runqueue when it expires, but we'll just punt on that for now return new Interval(runQueue) { @Override public void expired () { onExpired.run(); } @Override public String toString () { return onExpired.toString(); } }; }
java
public static Interval create (RunQueue runQueue, final Runnable onExpired) { // we could probably avoid all the wacky machinations internal to Interval that do the // runbuddy reposting and whatever and just create a non-runqueue interval that posts the // supplied runnable to the runqueue when it expires, but we'll just punt on that for now return new Interval(runQueue) { @Override public void expired () { onExpired.run(); } @Override public String toString () { return onExpired.toString(); } }; }
[ "public", "static", "Interval", "create", "(", "RunQueue", "runQueue", ",", "final", "Runnable", "onExpired", ")", "{", "// we could probably avoid all the wacky machinations internal to Interval that do the", "// runbuddy reposting and whatever and just create a non-runqueue interval th...
Creates an interval that executes the supplied runnable on the specified RunQueue when it expires.
[ "Creates", "an", "interval", "that", "executes", "the", "supplied", "runnable", "on", "the", "specified", "RunQueue", "when", "it", "expires", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Interval.java#L80-L93
train
samskivert/samskivert
src/main/java/com/samskivert/util/Interval.java
Interval.cancel
public final void cancel () { IntervalTask task = _task; if (task != null) { _task = null; task.cancel(); } }
java
public final void cancel () { IntervalTask task = _task; if (task != null) { _task = null; task.cancel(); } }
[ "public", "final", "void", "cancel", "(", ")", "{", "IntervalTask", "task", "=", "_task", ";", "if", "(", "task", "!=", "null", ")", "{", "_task", "=", "null", ";", "task", ".", "cancel", "(", ")", ";", "}", "}" ]
Cancel the current schedule, and ensure that any expirations that are queued up but have not yet run do not run.
[ "Cancel", "the", "current", "schedule", "and", "ensure", "that", "any", "expirations", "that", "are", "queued", "up", "but", "have", "not", "yet", "run", "do", "not", "run", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/Interval.java#L214-L221
train
samskivert/samskivert
src/main/java/com/samskivert/net/MailUtil.java
MailUtil.deliverMail
public static void deliverMail (String recipient, String sender, String subject, String body) throws IOException { deliverMail(new String[] { recipient }, sender, subject, body); }
java
public static void deliverMail (String recipient, String sender, String subject, String body) throws IOException { deliverMail(new String[] { recipient }, sender, subject, body); }
[ "public", "static", "void", "deliverMail", "(", "String", "recipient", ",", "String", "sender", ",", "String", "subject", ",", "String", "body", ")", "throws", "IOException", "{", "deliverMail", "(", "new", "String", "[", "]", "{", "recipient", "}", ",", "...
Delivers the supplied mail message using the machine's local mail SMTP server which must be listening on port 25. @exception IOException thrown if an error occurs delivering the email. See {@link Transport#send} for exceptions that can be thrown due to response from the SMTP server.
[ "Delivers", "the", "supplied", "mail", "message", "using", "the", "machine", "s", "local", "mail", "SMTP", "server", "which", "must", "be", "listening", "on", "port", "25", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MailUtil.java#L64-L69
train
samskivert/samskivert
src/main/java/com/samskivert/net/MailUtil.java
MailUtil.deliverMail
public static void deliverMail (String[] recipients, String sender, String subject, String body, String[] headers, String[] values) throws IOException { if (recipients == null || recipients.length < 1) { throw new IOException("Must specify one or more recipients."); } try { MimeMessage message = createEmptyMessage(); int hcount = (headers == null) ? 0 : headers.length; for (int ii = 0; ii < hcount; ii++) { message.addHeader(headers[ii], values[ii]); } message.setText(body); deliverMail(recipients, sender, subject, message); } catch (Exception e) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil.toString(recipients) + ", subject=" + subject + "]"; IOException ioe = new IOException(errmsg); ioe.initCause(e); throw ioe; } }
java
public static void deliverMail (String[] recipients, String sender, String subject, String body, String[] headers, String[] values) throws IOException { if (recipients == null || recipients.length < 1) { throw new IOException("Must specify one or more recipients."); } try { MimeMessage message = createEmptyMessage(); int hcount = (headers == null) ? 0 : headers.length; for (int ii = 0; ii < hcount; ii++) { message.addHeader(headers[ii], values[ii]); } message.setText(body); deliverMail(recipients, sender, subject, message); } catch (Exception e) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil.toString(recipients) + ", subject=" + subject + "]"; IOException ioe = new IOException(errmsg); ioe.initCause(e); throw ioe; } }
[ "public", "static", "void", "deliverMail", "(", "String", "[", "]", "recipients", ",", "String", "sender", ",", "String", "subject", ",", "String", "body", ",", "String", "[", "]", "headers", ",", "String", "[", "]", "values", ")", "throws", "IOException",...
Delivers the supplied mail, with the specified additional headers.
[ "Delivers", "the", "supplied", "mail", "with", "the", "specified", "additional", "headers", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MailUtil.java#L91-L117
train
samskivert/samskivert
src/main/java/com/samskivert/net/MailUtil.java
MailUtil.deliverMail
public static void deliverMail (String[] recipients, String sender, String subject, MimeMessage message) throws IOException { checkCreateSession(); try { message.setFrom(new InternetAddress(sender)); for (String recipient : recipients) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); } if (subject != null) { message.setSubject(subject); } message.saveChanges(); Address[] recips = message.getAllRecipients(); if (recips == null || recips.length == 0) { log.info("Not sending mail to zero recipients", "subject", subject, "message", message); return; } Transport t = _defaultSession.getTransport(recips[0]); try { t.addTransportListener(_listener); t.connect(); t.sendMessage(message, recips); } finally { t.close(); } } catch (Exception e) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil.toString(recipients) + ", subject=" + subject + "]"; IOException ioe = new IOException(errmsg); ioe.initCause(e); throw ioe; } }
java
public static void deliverMail (String[] recipients, String sender, String subject, MimeMessage message) throws IOException { checkCreateSession(); try { message.setFrom(new InternetAddress(sender)); for (String recipient : recipients) { message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); } if (subject != null) { message.setSubject(subject); } message.saveChanges(); Address[] recips = message.getAllRecipients(); if (recips == null || recips.length == 0) { log.info("Not sending mail to zero recipients", "subject", subject, "message", message); return; } Transport t = _defaultSession.getTransport(recips[0]); try { t.addTransportListener(_listener); t.connect(); t.sendMessage(message, recips); } finally { t.close(); } } catch (Exception e) { String errmsg = "Failure sending mail [from=" + sender + ", to=" + StringUtil.toString(recipients) + ", subject=" + subject + "]"; IOException ioe = new IOException(errmsg); ioe.initCause(e); throw ioe; } }
[ "public", "static", "void", "deliverMail", "(", "String", "[", "]", "recipients", ",", "String", "sender", ",", "String", "subject", ",", "MimeMessage", "message", ")", "throws", "IOException", "{", "checkCreateSession", "(", ")", ";", "try", "{", "message", ...
Delivers an already-formed message to the specified recipients. This message can be any mime type including multipart.
[ "Delivers", "an", "already", "-", "formed", "message", "to", "the", "specified", "recipients", ".", "This", "message", "can", "be", "any", "mime", "type", "including", "multipart", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MailUtil.java#L123-L161
train
samskivert/samskivert
src/main/java/com/samskivert/net/MailUtil.java
MailUtil.checkCreateSession
protected static void checkCreateSession () { if (_defaultSession == null) { // no need to sync Properties props = System.getProperties(); if (props.getProperty("mail.smtp.host") == null) { props.put("mail.smtp.host", "localhost"); } _defaultSession = Session.getDefaultInstance(props, null); } }
java
protected static void checkCreateSession () { if (_defaultSession == null) { // no need to sync Properties props = System.getProperties(); if (props.getProperty("mail.smtp.host") == null) { props.put("mail.smtp.host", "localhost"); } _defaultSession = Session.getDefaultInstance(props, null); } }
[ "protected", "static", "void", "checkCreateSession", "(", ")", "{", "if", "(", "_defaultSession", "==", "null", ")", "{", "// no need to sync", "Properties", "props", "=", "System", ".", "getProperties", "(", ")", ";", "if", "(", "props", ".", "getProperty", ...
Create our default session if not already created.
[ "Create", "our", "default", "session", "if", "not", "already", "created", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/net/MailUtil.java#L175-L184
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/InvocationContext.java
InvocationContext.getTemplate
public Template getTemplate (String path, String encoding) throws Exception { Object siteId = get("__siteid__"); if (siteId != null) { path = siteId + ":" + path; } if (encoding == null) { return RuntimeSingleton.getRuntimeServices().getTemplate(path); } else { return RuntimeSingleton.getRuntimeServices().getTemplate(path, encoding); } }
java
public Template getTemplate (String path, String encoding) throws Exception { Object siteId = get("__siteid__"); if (siteId != null) { path = siteId + ":" + path; } if (encoding == null) { return RuntimeSingleton.getRuntimeServices().getTemplate(path); } else { return RuntimeSingleton.getRuntimeServices().getTemplate(path, encoding); } }
[ "public", "Template", "getTemplate", "(", "String", "path", ",", "String", "encoding", ")", "throws", "Exception", "{", "Object", "siteId", "=", "get", "(", "\"__siteid__\"", ")", ";", "if", "(", "siteId", "!=", "null", ")", "{", "path", "=", "siteId", "...
Fetches a Velocity template that can be used for later formatting. The template is read with the specified encoding or the default encoding if encoding is null. @exception Exception thrown if an error occurs loading or parsing the template.
[ "Fetches", "a", "Velocity", "template", "that", "can", "be", "used", "for", "later", "formatting", ".", "The", "template", "is", "read", "with", "the", "specified", "encoding", "or", "the", "default", "encoding", "if", "encoding", "is", "null", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/InvocationContext.java#L57-L69
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/InvocationContext.java
InvocationContext.putAllParameters
@Deprecated public void putAllParameters () { Enumeration<?> e = _req.getParameterNames(); while (e.hasMoreElements()) { String param = (String)e.nextElement(); put(param, _req.getParameter(param)); } }
java
@Deprecated public void putAllParameters () { Enumeration<?> e = _req.getParameterNames(); while (e.hasMoreElements()) { String param = (String)e.nextElement(); put(param, _req.getParameter(param)); } }
[ "@", "Deprecated", "public", "void", "putAllParameters", "(", ")", "{", "Enumeration", "<", "?", ">", "e", "=", "_req", ".", "getParameterNames", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements", "(", ")", ")", "{", "String", "param", "=", "(",...
Don't use this method. It is terribly unsafe and was written by a lazy engineer.
[ "Don", "t", "use", "this", "method", ".", "It", "is", "terribly", "unsafe", "and", "was", "written", "by", "a", "lazy", "engineer", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/InvocationContext.java#L101-L109
train
samskivert/samskivert
src/main/java/com/samskivert/velocity/InvocationContext.java
InvocationContext.encodeAllParameters
public String encodeAllParameters () { StringBuilder buf = new StringBuilder(); Enumeration<?> e = _req.getParameterNames(); while (e.hasMoreElements()) { if (buf.length() > 0) { buf.append('&'); } String param = (String) e.nextElement(); buf.append(StringUtil.encode(param)); buf.append('='); buf.append(StringUtil.encode(_req.getParameter(param))); } return buf.toString(); }
java
public String encodeAllParameters () { StringBuilder buf = new StringBuilder(); Enumeration<?> e = _req.getParameterNames(); while (e.hasMoreElements()) { if (buf.length() > 0) { buf.append('&'); } String param = (String) e.nextElement(); buf.append(StringUtil.encode(param)); buf.append('='); buf.append(StringUtil.encode(_req.getParameter(param))); } return buf.toString(); }
[ "public", "String", "encodeAllParameters", "(", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "Enumeration", "<", "?", ">", "e", "=", "_req", ".", "getParameterNames", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements"...
Encodes all the request params so they can be slapped onto a different URL which is useful when doing redirects.
[ "Encodes", "all", "the", "request", "params", "so", "they", "can", "be", "slapped", "onto", "a", "different", "URL", "which", "is", "useful", "when", "doing", "redirects", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/velocity/InvocationContext.java#L115-L130
train
samskivert/samskivert
src/main/java/com/samskivert/jdbc/LiaisonRegistry.java
LiaisonRegistry.getLiaison
public static DatabaseLiaison getLiaison (String url) { if (url == null) throw new NullPointerException("URL must not be null"); // see if we already have a liaison mapped for this connection DatabaseLiaison liaison = _mappings.get(url); if (liaison == null) { // scan the list looking for a matching liaison for (DatabaseLiaison candidate : _liaisons) { if (candidate.matchesURL(url)) { liaison = candidate; break; } } // if we didn't find a matching liaison, use the default if (liaison == null) { log.warning("Unable to match liaison for database. Using default.", "url", url); liaison = new DefaultLiaison(); } // map this URL to this liaison _mappings.put(url, liaison); } return liaison; }
java
public static DatabaseLiaison getLiaison (String url) { if (url == null) throw new NullPointerException("URL must not be null"); // see if we already have a liaison mapped for this connection DatabaseLiaison liaison = _mappings.get(url); if (liaison == null) { // scan the list looking for a matching liaison for (DatabaseLiaison candidate : _liaisons) { if (candidate.matchesURL(url)) { liaison = candidate; break; } } // if we didn't find a matching liaison, use the default if (liaison == null) { log.warning("Unable to match liaison for database. Using default.", "url", url); liaison = new DefaultLiaison(); } // map this URL to this liaison _mappings.put(url, liaison); } return liaison; }
[ "public", "static", "DatabaseLiaison", "getLiaison", "(", "String", "url", ")", "{", "if", "(", "url", "==", "null", ")", "throw", "new", "NullPointerException", "(", "\"URL must not be null\"", ")", ";", "// see if we already have a liaison mapped for this connection", ...
Fetch the appropriate database liaison for the supplied URL, which should be the same string that would be used to configure a connection to the database.
[ "Fetch", "the", "appropriate", "database", "liaison", "for", "the", "supplied", "URL", "which", "should", "be", "the", "same", "string", "that", "would", "be", "used", "to", "configure", "a", "connection", "to", "the", "database", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/jdbc/LiaisonRegistry.java#L26-L51
train
nextreports/nextreports-engine
src/ro/nextreports/engine/exporter/XlsxExporter.java
XlsxExporter.updateSubreportBandElementStyle
private XSSFCellStyle updateSubreportBandElementStyle(XSSFCellStyle cellStyle, BandElement bandElement, Object value, int gridRow, int gridColumn, int colSpan) { if (subreportCellStyle == null) { return cellStyle; } if (gridColumn == 0) { cellStyle.setBorderLeft(subreportCellStyle.getBorderLeft()); cellStyle.setLeftBorderColor(subreportCellStyle.getLeftBorderColor()); } else if (gridColumn+colSpan-1 == bean.getReportLayout().getColumnCount()-1) { cellStyle.setBorderRight(subreportCellStyle.getBorderRight()); cellStyle.setRightBorderColor(subreportCellStyle.getRightBorderColor()); } if (pageRow == 0) { cellStyle.setBorderTop(subreportCellStyle.getBorderTop()); cellStyle.setTopBorderColor(subreportCellStyle.getTopBorderColor()); } else if ( (pageRow+1) == getRowsCount()) { cellStyle.setBorderBottom(subreportCellStyle.getBorderBottom()); cellStyle.setBottomBorderColor(subreportCellStyle.getBottomBorderColor()); } return cellStyle; }
java
private XSSFCellStyle updateSubreportBandElementStyle(XSSFCellStyle cellStyle, BandElement bandElement, Object value, int gridRow, int gridColumn, int colSpan) { if (subreportCellStyle == null) { return cellStyle; } if (gridColumn == 0) { cellStyle.setBorderLeft(subreportCellStyle.getBorderLeft()); cellStyle.setLeftBorderColor(subreportCellStyle.getLeftBorderColor()); } else if (gridColumn+colSpan-1 == bean.getReportLayout().getColumnCount()-1) { cellStyle.setBorderRight(subreportCellStyle.getBorderRight()); cellStyle.setRightBorderColor(subreportCellStyle.getRightBorderColor()); } if (pageRow == 0) { cellStyle.setBorderTop(subreportCellStyle.getBorderTop()); cellStyle.setTopBorderColor(subreportCellStyle.getTopBorderColor()); } else if ( (pageRow+1) == getRowsCount()) { cellStyle.setBorderBottom(subreportCellStyle.getBorderBottom()); cellStyle.setBottomBorderColor(subreportCellStyle.getBottomBorderColor()); } return cellStyle; }
[ "private", "XSSFCellStyle", "updateSubreportBandElementStyle", "(", "XSSFCellStyle", "cellStyle", ",", "BandElement", "bandElement", ",", "Object", "value", ",", "int", "gridRow", ",", "int", "gridColumn", ",", "int", "colSpan", ")", "{", "if", "(", "subreportCellSt...
If a border style is set on a ReportBandElement we must apply it to all subreport cells
[ "If", "a", "border", "style", "is", "set", "on", "a", "ReportBandElement", "we", "must", "apply", "it", "to", "all", "subreport", "cells" ]
a847575a9298b5fce63b88961190c5b83ddccc44
https://github.com/nextreports/nextreports-engine/blob/a847575a9298b5fce63b88961190c5b83ddccc44/src/ro/nextreports/engine/exporter/XlsxExporter.java#L470-L492
train
samskivert/samskivert
src/main/java/com/samskivert/util/SoftCache.java
SoftCache.get
public V get (K key) { V value = null; SoftReference<V> ref = _map.get(key); if (ref != null) { value = ref.get(); if (value == null) { _map.remove(key); } } return value; }
java
public V get (K key) { V value = null; SoftReference<V> ref = _map.get(key); if (ref != null) { value = ref.get(); if (value == null) { _map.remove(key); } } return value; }
[ "public", "V", "get", "(", "K", "key", ")", "{", "V", "value", "=", "null", ";", "SoftReference", "<", "V", ">", "ref", "=", "_map", ".", "get", "(", "key", ")", ";", "if", "(", "ref", "!=", "null", ")", "{", "value", "=", "ref", ".", "get", ...
Looks up and returns the value associated with the supplied key.
[ "Looks", "up", "and", "returns", "the", "value", "associated", "with", "the", "supplied", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/SoftCache.java#L51-L62
train
samskivert/samskivert
src/main/java/com/samskivert/util/SoftCache.java
SoftCache.remove
public V remove (K key) { SoftReference<V> ref = _map.remove(key); return (ref == null) ? null : ref.get(); }
java
public V remove (K key) { SoftReference<V> ref = _map.remove(key); return (ref == null) ? null : ref.get(); }
[ "public", "V", "remove", "(", "K", "key", ")", "{", "SoftReference", "<", "V", ">", "ref", "=", "_map", ".", "remove", "(", "key", ")", ";", "return", "(", "ref", "==", "null", ")", "?", "null", ":", "ref", ".", "get", "(", ")", ";", "}" ]
Removes the specified key from the map. Returns the value to which the key was previously mapped or null.
[ "Removes", "the", "specified", "key", "from", "the", "map", ".", "Returns", "the", "value", "to", "which", "the", "key", "was", "previously", "mapped", "or", "null", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/SoftCache.java#L77-L81
train
samskivert/samskivert
src/main/java/com/samskivert/servlet/SiteIdentifiers.java
SiteIdentifiers.single
public static SiteIdentifier single (final int siteId, final String siteString) { return new SiteIdentifier() { public int identifySite (HttpServletRequest req) { return siteId; } public String getSiteString (int siteId) { return siteString; } public int getSiteId (String siteString) { return siteId; } public Iterator<Site> enumerateSites () { return Collections.singletonList(new Site(siteId, siteString)).iterator(); } }; }
java
public static SiteIdentifier single (final int siteId, final String siteString) { return new SiteIdentifier() { public int identifySite (HttpServletRequest req) { return siteId; } public String getSiteString (int siteId) { return siteString; } public int getSiteId (String siteString) { return siteId; } public Iterator<Site> enumerateSites () { return Collections.singletonList(new Site(siteId, siteString)).iterator(); } }; }
[ "public", "static", "SiteIdentifier", "single", "(", "final", "int", "siteId", ",", "final", "String", "siteString", ")", "{", "return", "new", "SiteIdentifier", "(", ")", "{", "public", "int", "identifySite", "(", "HttpServletRequest", "req", ")", "{", "retur...
Returns a site identifier that returns the specified site always.
[ "Returns", "a", "site", "identifier", "that", "returns", "the", "specified", "site", "always", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/servlet/SiteIdentifiers.java#L23-L38
train
samskivert/samskivert
src/main/java/com/samskivert/util/KeyUtil.java
KeyUtil.generateRandomKey
public static String generateRandomKey (Random rand, int length) { int numKeyChars = KEY_CHARS.length(); StringBuilder buf = new StringBuilder(); for (int ii = 0; ii < length; ii++) { buf.append(KEY_CHARS.charAt(rand.nextInt(numKeyChars))); } return buf.toString(); }
java
public static String generateRandomKey (Random rand, int length) { int numKeyChars = KEY_CHARS.length(); StringBuilder buf = new StringBuilder(); for (int ii = 0; ii < length; ii++) { buf.append(KEY_CHARS.charAt(rand.nextInt(numKeyChars))); } return buf.toString(); }
[ "public", "static", "String", "generateRandomKey", "(", "Random", "rand", ",", "int", "length", ")", "{", "int", "numKeyChars", "=", "KEY_CHARS", ".", "length", "(", ")", ";", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", ...
Return a key of the given length that contains random numbers.
[ "Return", "a", "key", "of", "the", "given", "length", "that", "contains", "random", "numbers", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/KeyUtil.java#L29-L37
train
samskivert/samskivert
src/main/java/com/samskivert/util/KeyUtil.java
KeyUtil.verifyLuhn
public static boolean verifyLuhn (String key) { // If there is a non digit, or it is all zeros. if (StringUtil.isBlank(key) || key.matches(".*\\D.*") || key.matches("^[0]+$")) { return false; } return (getLuhnRemainder(key) == 0); }
java
public static boolean verifyLuhn (String key) { // If there is a non digit, or it is all zeros. if (StringUtil.isBlank(key) || key.matches(".*\\D.*") || key.matches("^[0]+$")) { return false; } return (getLuhnRemainder(key) == 0); }
[ "public", "static", "boolean", "verifyLuhn", "(", "String", "key", ")", "{", "// If there is a non digit, or it is all zeros.", "if", "(", "StringUtil", ".", "isBlank", "(", "key", ")", "||", "key", ".", "matches", "(", "\".*\\\\D.*\"", ")", "||", "key", ".", ...
Verify the key with the Luhn check. If the key is all zeros, then the luhn check is true, but that is almost never what you want so explicitly check for zero and return false if it is.
[ "Verify", "the", "key", "with", "the", "Luhn", "check", ".", "If", "the", "key", "is", "all", "zeros", "then", "the", "luhn", "check", "is", "true", "but", "that", "is", "almost", "never", "what", "you", "want", "so", "explicitly", "check", "for", "zer...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/KeyUtil.java#L44-L53
train
samskivert/samskivert
src/main/java/com/samskivert/util/KeyUtil.java
KeyUtil.getLuhnRemainder
public static int getLuhnRemainder (String key) { int len = key.length(); int sum = 0; for (int multSeq = len % 2, ii=0; ii < len; ii++) { int c = key.charAt(ii) - '0'; if (ii % 2 == multSeq) { c *= 2; } sum += (c / 10) + (c % 10); } return sum % 10; }
java
public static int getLuhnRemainder (String key) { int len = key.length(); int sum = 0; for (int multSeq = len % 2, ii=0; ii < len; ii++) { int c = key.charAt(ii) - '0'; if (ii % 2 == multSeq) { c *= 2; } sum += (c / 10) + (c % 10); } return sum % 10; }
[ "public", "static", "int", "getLuhnRemainder", "(", "String", "key", ")", "{", "int", "len", "=", "key", ".", "length", "(", ")", ";", "int", "sum", "=", "0", ";", "for", "(", "int", "multSeq", "=", "len", "%", "2", ",", "ii", "=", "0", ";", "i...
Return the luhn remainder for the given key. @see <a href="http://www.beachnet.com/~hstiles/cardtype.html"> Instructions for computing the Lunh remainder</a> @see <a href="http://www.google.com/search?q=luhn%20credit%20card"> Find more information with Google</a>
[ "Return", "the", "luhn", "remainder", "for", "the", "given", "key", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/KeyUtil.java#L76-L89
train
samskivert/samskivert
src/main/java/com/samskivert/util/FormatterUtil.java
FormatterUtil.configureDefaultHandler
public static void configureDefaultHandler (Formatter formatter) { Logger logger = LogManager.getLogManager().getLogger(""); for (Handler handler : logger.getHandlers()) { handler.setFormatter(formatter); } }
java
public static void configureDefaultHandler (Formatter formatter) { Logger logger = LogManager.getLogManager().getLogger(""); for (Handler handler : logger.getHandlers()) { handler.setFormatter(formatter); } }
[ "public", "static", "void", "configureDefaultHandler", "(", "Formatter", "formatter", ")", "{", "Logger", "logger", "=", "LogManager", ".", "getLogManager", "(", ")", ".", "getLogger", "(", "\"\"", ")", ";", "for", "(", "Handler", "handler", ":", "logger", "...
Configures the default logging handler to use an instance of the specified formatter when formatting messages.
[ "Configures", "the", "default", "logging", "handler", "to", "use", "an", "instance", "of", "the", "specified", "formatter", "when", "formatting", "messages", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/FormatterUtil.java#L31-L37
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayUtil.java
ArrayUtil.reverse
public static void reverse (byte[] values, int offset, int length) { int aidx = offset; int bidx = offset + length - 1; while (bidx > aidx) { byte value = values[aidx]; values[aidx] = values[bidx]; values[bidx] = value; aidx++; bidx--; } }
java
public static void reverse (byte[] values, int offset, int length) { int aidx = offset; int bidx = offset + length - 1; while (bidx > aidx) { byte value = values[aidx]; values[aidx] = values[bidx]; values[bidx] = value; aidx++; bidx--; } }
[ "public", "static", "void", "reverse", "(", "byte", "[", "]", "values", ",", "int", "offset", ",", "int", "length", ")", "{", "int", "aidx", "=", "offset", ";", "int", "bidx", "=", "offset", "+", "length", "-", "1", ";", "while", "(", "bidx", ">", ...
Reverses a subset of elements within the specified array. @param values the array containing elements to reverse. @param offset the index at which to start reversing elements. @param length the number of elements to reverse.
[ "Reverses", "a", "subset", "of", "elements", "within", "the", "specified", "array", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayUtil.java#L125-L136
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayUtil.java
ArrayUtil.shuffle
public static void shuffle (Object[] values, Random rnd) { shuffle(values, 0, values.length, rnd); }
java
public static void shuffle (Object[] values, Random rnd) { shuffle(values, 0, values.length, rnd); }
[ "public", "static", "void", "shuffle", "(", "Object", "[", "]", "values", ",", "Random", "rnd", ")", "{", "shuffle", "(", "values", ",", "0", ",", "values", ".", "length", ",", "rnd", ")", ";", "}" ]
Shuffles the elements in the given array into a random sequence. @param values the array to shuffle. @param rnd the source from which random values for shuffling the array are obtained.
[ "Shuffles", "the", "elements", "in", "the", "given", "array", "into", "a", "random", "sequence", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayUtil.java#L323-L326
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayUtil.java
ArrayUtil.insert
public static byte[] insert (byte[] values, byte value, int index) { byte[] nvalues = new byte[values.length+1]; if (index > 0) { System.arraycopy(values, 0, nvalues, 0, index); } nvalues[index] = value; if (index < values.length) { System.arraycopy(values, index, nvalues, index+1, values.length-index); } return nvalues; }
java
public static byte[] insert (byte[] values, byte value, int index) { byte[] nvalues = new byte[values.length+1]; if (index > 0) { System.arraycopy(values, 0, nvalues, 0, index); } nvalues[index] = value; if (index < values.length) { System.arraycopy(values, index, nvalues, index+1, values.length-index); } return nvalues; }
[ "public", "static", "byte", "[", "]", "insert", "(", "byte", "[", "]", "values", ",", "byte", "value", ",", "int", "index", ")", "{", "byte", "[", "]", "nvalues", "=", "new", "byte", "[", "values", ".", "length", "+", "1", "]", ";", "if", "(", ...
Creates a new array one larger than the supplied array and with the specified value inserted into the specified slot.
[ "Creates", "a", "new", "array", "one", "larger", "than", "the", "supplied", "array", "and", "with", "the", "specified", "value", "inserted", "into", "the", "specified", "slot", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayUtil.java#L722-L733
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayUtil.java
ArrayUtil.insert
public static <T extends Object> T[] insert (T[] values, T value, int index) { @SuppressWarnings("unchecked") T[] nvalues = (T[])Array.newInstance(values.getClass().getComponentType(), values.length+1); if (index > 0) { System.arraycopy(values, 0, nvalues, 0, index); } nvalues[index] = value; if (index < values.length) { System.arraycopy(values, index, nvalues, index+1, values.length-index); } return nvalues; }
java
public static <T extends Object> T[] insert (T[] values, T value, int index) { @SuppressWarnings("unchecked") T[] nvalues = (T[])Array.newInstance(values.getClass().getComponentType(), values.length+1); if (index > 0) { System.arraycopy(values, 0, nvalues, 0, index); } nvalues[index] = value; if (index < values.length) { System.arraycopy(values, index, nvalues, index+1, values.length-index); } return nvalues; }
[ "public", "static", "<", "T", "extends", "Object", ">", "T", "[", "]", "insert", "(", "T", "[", "]", "values", ",", "T", "value", ",", "int", "index", ")", "{", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "T", "[", "]", "nvalues", "=", "(",...
Creates a new array one larger than the supplied array and with the specified value inserted into the specified slot. The type of the values array will be preserved.
[ "Creates", "a", "new", "array", "one", "larger", "than", "the", "supplied", "array", "and", "with", "the", "specified", "value", "inserted", "into", "the", "specified", "slot", ".", "The", "type", "of", "the", "values", "array", "will", "be", "preserved", ...
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayUtil.java#L792-L804
train
samskivert/samskivert
src/main/java/com/samskivert/util/ArrayUtil.java
ArrayUtil.append
public static <T extends Object> T[] append (T[] values, T value) { return insert(values, value, values.length); }
java
public static <T extends Object> T[] append (T[] values, T value) { return insert(values, value, values.length); }
[ "public", "static", "<", "T", "extends", "Object", ">", "T", "[", "]", "append", "(", "T", "[", "]", "values", ",", "T", "value", ")", "{", "return", "insert", "(", "values", ",", "value", ",", "values", ".", "length", ")", ";", "}" ]
Creates a new array one larger than the supplied array and with the specified value inserted into the last slot. The type of the values array will be preserved.
[ "Creates", "a", "new", "array", "one", "larger", "than", "the", "supplied", "array", "and", "with", "the", "specified", "value", "inserted", "into", "the", "last", "slot", ".", "The", "type", "of", "the", "values", "array", "will", "be", "preserved", "." ]
a64d9ef42b69819bdb2c66bddac6a64caef928b6
https://github.com/samskivert/samskivert/blob/a64d9ef42b69819bdb2c66bddac6a64caef928b6/src/main/java/com/samskivert/util/ArrayUtil.java#L847-L850
train