id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,800 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java | UIPasswordField.updateText | protected void updateText()
{
this.text.setLength(0);
this.text.append(password.toString().replaceAll("(?s).", String.valueOf(passwordChar)));
guiText.setText(text.toString());
} | java | protected void updateText()
{
this.text.setLength(0);
this.text.append(password.toString().replaceAll("(?s).", String.valueOf(passwordChar)));
guiText.setText(text.toString());
} | [
"protected",
"void",
"updateText",
"(",
")",
"{",
"this",
".",
"text",
".",
"setLength",
"(",
"0",
")",
";",
"this",
".",
"text",
".",
"append",
"(",
"password",
".",
"toString",
"(",
")",
".",
"replaceAll",
"(",
"\"(?s).\"",
",",
"String",
".",
"valueOf",
"(",
"passwordChar",
")",
")",
")",
";",
"guiText",
".",
"setText",
"(",
"text",
".",
"toString",
"(",
")",
")",
";",
"}"
] | Updates the text from the password value | [
"Updates",
"the",
"text",
"from",
"the",
"password",
"value"
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java#L72-L77 |
2,801 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java | UIPasswordField.addText | @Override
public void addText(String text)
{
if (selectingText)
deleteSelectedText();
final StringBuilder oldText = this.password;
final String oldValue = oldText.toString();
String newValue = oldText.insert(this.cursor.index, text).toString();
if (this.filterFunction != null)
newValue = this.filterFunction.apply(newValue);
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.password = new StringBuilder(newValue);
this.updateText();
this.cursor.jumpBy(text.length());
} | java | @Override
public void addText(String text)
{
if (selectingText)
deleteSelectedText();
final StringBuilder oldText = this.password;
final String oldValue = oldText.toString();
String newValue = oldText.insert(this.cursor.index, text).toString();
if (this.filterFunction != null)
newValue = this.filterFunction.apply(newValue);
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.password = new StringBuilder(newValue);
this.updateText();
this.cursor.jumpBy(text.length());
} | [
"@",
"Override",
"public",
"void",
"addText",
"(",
"String",
"text",
")",
"{",
"if",
"(",
"selectingText",
")",
"deleteSelectedText",
"(",
")",
";",
"final",
"StringBuilder",
"oldText",
"=",
"this",
".",
"password",
";",
"final",
"String",
"oldValue",
"=",
"oldText",
".",
"toString",
"(",
")",
";",
"String",
"newValue",
"=",
"oldText",
".",
"insert",
"(",
"this",
".",
"cursor",
".",
"index",
",",
"text",
")",
".",
"toString",
"(",
")",
";",
"if",
"(",
"this",
".",
"filterFunction",
"!=",
"null",
")",
"newValue",
"=",
"this",
".",
"filterFunction",
".",
"apply",
"(",
"newValue",
")",
";",
"if",
"(",
"!",
"fireEvent",
"(",
"new",
"ComponentEvent",
".",
"ValueChange",
"<>",
"(",
"this",
",",
"oldValue",
",",
"newValue",
")",
")",
")",
"return",
";",
"this",
".",
"password",
"=",
"new",
"StringBuilder",
"(",
"newValue",
")",
";",
"this",
".",
"updateText",
"(",
")",
";",
"this",
".",
"cursor",
".",
"jumpBy",
"(",
"text",
".",
"length",
"(",
")",
")",
";",
"}"
] | Adds the text.
@param text the text | [
"Adds",
"the",
"text",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java#L84-L103 |
2,802 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java | UIPasswordField.deleteSelectedText | @Override
public void deleteSelectedText()
{
if (!selectingText)
return;
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
password.delete(start, end);
updateText();
selectingText = false;
cursor.jumpTo(start);
} | java | @Override
public void deleteSelectedText()
{
if (!selectingText)
return;
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
password.delete(start, end);
updateText();
selectingText = false;
cursor.jumpTo(start);
} | [
"@",
"Override",
"public",
"void",
"deleteSelectedText",
"(",
")",
"{",
"if",
"(",
"!",
"selectingText",
")",
"return",
";",
"int",
"start",
"=",
"Math",
".",
"min",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"int",
"end",
"=",
"Math",
".",
"max",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"password",
".",
"delete",
"(",
"start",
",",
"end",
")",
";",
"updateText",
"(",
")",
";",
"selectingText",
"=",
"false",
";",
"cursor",
".",
"jumpTo",
"(",
"start",
")",
";",
"}"
] | Delete selected text. | [
"Delete",
"selected",
"text",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java#L137-L150 |
2,803 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java | UIPasswordField.handleCtrlKeyDown | @Override
protected boolean handleCtrlKeyDown(int keyCode)
{
return GuiScreen.isCtrlKeyDown() && !(keyCode == Keyboard.KEY_C || keyCode == Keyboard.KEY_X) && super.handleCtrlKeyDown(keyCode);
} | java | @Override
protected boolean handleCtrlKeyDown(int keyCode)
{
return GuiScreen.isCtrlKeyDown() && !(keyCode == Keyboard.KEY_C || keyCode == Keyboard.KEY_X) && super.handleCtrlKeyDown(keyCode);
} | [
"@",
"Override",
"protected",
"boolean",
"handleCtrlKeyDown",
"(",
"int",
"keyCode",
")",
"{",
"return",
"GuiScreen",
".",
"isCtrlKeyDown",
"(",
")",
"&&",
"!",
"(",
"keyCode",
"==",
"Keyboard",
".",
"KEY_C",
"||",
"keyCode",
"==",
"Keyboard",
".",
"KEY_X",
")",
"&&",
"super",
".",
"handleCtrlKeyDown",
"(",
"keyCode",
")",
";",
"}"
] | Handle ctrl key down.
@param keyCode the key code
@return true, if successful | [
"Handle",
"ctrl",
"key",
"down",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UIPasswordField.java#L158-L162 |
2,804 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/renderer/icon/Icon.java | Icon.setUVs | public void setUVs(float u, float v, float U, float V)
{
minU = u;
minV = v;
maxU = U;
maxV = V;
} | java | public void setUVs(float u, float v, float U, float V)
{
minU = u;
minV = v;
maxU = U;
maxV = V;
} | [
"public",
"void",
"setUVs",
"(",
"float",
"u",
",",
"float",
"v",
",",
"float",
"U",
",",
"float",
"V",
")",
"{",
"minU",
"=",
"u",
";",
"minV",
"=",
"v",
";",
"maxU",
"=",
"U",
";",
"maxV",
"=",
"V",
";",
"}"
] | Sets the u vs.
@param u the u
@param v the v
@param U the u
@param V the v | [
"Sets",
"the",
"u",
"vs",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/renderer/icon/Icon.java#L173-L179 |
2,805 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.getSelectedText | public String getSelectedText()
{
if (!selectingText)
return "";
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
return this.text.substring(start, end);
} | java | public String getSelectedText()
{
if (!selectingText)
return "";
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
return this.text.substring(start, end);
} | [
"public",
"String",
"getSelectedText",
"(",
")",
"{",
"if",
"(",
"!",
"selectingText",
")",
"return",
"\"\"",
";",
"int",
"start",
"=",
"Math",
".",
"min",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"int",
"end",
"=",
"Math",
".",
"max",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"return",
"this",
".",
"text",
".",
"substring",
"(",
"start",
",",
"end",
")",
";",
"}"
] | Gets the currently selected text.
@return the text selected. | [
"Gets",
"the",
"currently",
"selected",
"text",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L209-L218 |
2,806 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.setColors | public UITextField setColors(int bgColor, int cursorColor, int selectColor)
{
setColor(bgColor);
this.cursorColor = cursorColor;
this.selectColor = selectColor;
return this;
} | java | public UITextField setColors(int bgColor, int cursorColor, int selectColor)
{
setColor(bgColor);
this.cursorColor = cursorColor;
this.selectColor = selectColor;
return this;
} | [
"public",
"UITextField",
"setColors",
"(",
"int",
"bgColor",
",",
"int",
"cursorColor",
",",
"int",
"selectColor",
")",
"{",
"setColor",
"(",
"bgColor",
")",
";",
"this",
".",
"cursorColor",
"=",
"cursorColor",
";",
"this",
".",
"selectColor",
"=",
"selectColor",
";",
"return",
"this",
";",
"}"
] | Sets the options.
@param bgColor the bg color
@param cursorColor the cursor color
@param selectColor the select color
@return the UI text field | [
"Sets",
"the",
"options",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L283-L290 |
2,807 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.setFocused | @Override
public void setFocused(boolean focused)
{
if (!isEnabled() || !isVisible())
return;
if (!this.focused)
selectAllOnRelease = true;
super.setFocused(focused);
} | java | @Override
public void setFocused(boolean focused)
{
if (!isEnabled() || !isVisible())
return;
if (!this.focused)
selectAllOnRelease = true;
super.setFocused(focused);
} | [
"@",
"Override",
"public",
"void",
"setFocused",
"(",
"boolean",
"focused",
")",
"{",
"if",
"(",
"!",
"isEnabled",
"(",
")",
"||",
"!",
"isVisible",
"(",
")",
")",
"return",
";",
"if",
"(",
"!",
"this",
".",
"focused",
")",
"selectAllOnRelease",
"=",
"true",
";",
"super",
".",
"setFocused",
"(",
"focused",
")",
";",
"}"
] | Sets the focused.
@param focused the new focused | [
"Sets",
"the",
"focused",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L308-L318 |
2,808 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.setFilter | public void setFilter(Function<String, String> filterFunction)
{
this.filterFunction = filterFunction;
this.text = new StringBuilder(this.filterFunction.apply(this.text.toString()));
} | java | public void setFilter(Function<String, String> filterFunction)
{
this.filterFunction = filterFunction;
this.text = new StringBuilder(this.filterFunction.apply(this.text.toString()));
} | [
"public",
"void",
"setFilter",
"(",
"Function",
"<",
"String",
",",
"String",
">",
"filterFunction",
")",
"{",
"this",
".",
"filterFunction",
"=",
"filterFunction",
";",
"this",
".",
"text",
"=",
"new",
"StringBuilder",
"(",
"this",
".",
"filterFunction",
".",
"apply",
"(",
"this",
".",
"text",
".",
"toString",
"(",
")",
")",
")",
";",
"}"
] | Sets the function that applies to all incoming text. Immediately applies filter to current text.
@param filterFunction the function | [
"Sets",
"the",
"function",
"that",
"applies",
"to",
"all",
"incoming",
"text",
".",
"Immediately",
"applies",
"filter",
"to",
"current",
"text",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L379-L383 |
2,809 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.addText | public void addText(String str)
{
if (selectingText)
deleteSelectedText();
final StringBuilder oldText = this.text;
final String oldValue = this.text.toString();
String newValue = oldText.insert(this.cursor.index, str).toString();
if (this.filterFunction != null)
newValue = this.filterFunction.apply(newValue);
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.text = new StringBuilder(newValue);
guiText.setText(newValue);
cursor.jumpBy(str.length());
} | java | public void addText(String str)
{
if (selectingText)
deleteSelectedText();
final StringBuilder oldText = this.text;
final String oldValue = this.text.toString();
String newValue = oldText.insert(this.cursor.index, str).toString();
if (this.filterFunction != null)
newValue = this.filterFunction.apply(newValue);
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.text = new StringBuilder(newValue);
guiText.setText(newValue);
cursor.jumpBy(str.length());
} | [
"public",
"void",
"addText",
"(",
"String",
"str",
")",
"{",
"if",
"(",
"selectingText",
")",
"deleteSelectedText",
"(",
")",
";",
"final",
"StringBuilder",
"oldText",
"=",
"this",
".",
"text",
";",
"final",
"String",
"oldValue",
"=",
"this",
".",
"text",
".",
"toString",
"(",
")",
";",
"String",
"newValue",
"=",
"oldText",
".",
"insert",
"(",
"this",
".",
"cursor",
".",
"index",
",",
"str",
")",
".",
"toString",
"(",
")",
";",
"if",
"(",
"this",
".",
"filterFunction",
"!=",
"null",
")",
"newValue",
"=",
"this",
".",
"filterFunction",
".",
"apply",
"(",
"newValue",
")",
";",
"if",
"(",
"!",
"fireEvent",
"(",
"new",
"ComponentEvent",
".",
"ValueChange",
"<>",
"(",
"this",
",",
"oldValue",
",",
"newValue",
")",
")",
")",
"return",
";",
"this",
".",
"text",
"=",
"new",
"StringBuilder",
"(",
"newValue",
")",
";",
"guiText",
".",
"setText",
"(",
"newValue",
")",
";",
"cursor",
".",
"jumpBy",
"(",
"str",
".",
"length",
"(",
")",
")",
";",
"}"
] | Adds text at current cursor position. If some text is selected, it's deleted first.
@param str the text | [
"Adds",
"text",
"at",
"current",
"cursor",
"position",
".",
"If",
"some",
"text",
"is",
"selected",
"it",
"s",
"deleted",
"first",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L413-L432 |
2,810 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.deleteSelectedText | public void deleteSelectedText()
{
if (!selectingText)
return;
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
String oldValue = this.text.toString();
String newValue = new StringBuilder(oldValue).delete(start, end).toString();
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.text = new StringBuilder(newValue);
guiText.setText(newValue);
selectingText = false;
cursor.jumpTo(start);
} | java | public void deleteSelectedText()
{
if (!selectingText)
return;
int start = Math.min(selectionCursor.index, cursor.index);
int end = Math.max(selectionCursor.index, cursor.index);
String oldValue = this.text.toString();
String newValue = new StringBuilder(oldValue).delete(start, end).toString();
if (!fireEvent(new ComponentEvent.ValueChange<>(this, oldValue, newValue)))
return;
this.text = new StringBuilder(newValue);
guiText.setText(newValue);
selectingText = false;
cursor.jumpTo(start);
} | [
"public",
"void",
"deleteSelectedText",
"(",
")",
"{",
"if",
"(",
"!",
"selectingText",
")",
"return",
";",
"int",
"start",
"=",
"Math",
".",
"min",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"int",
"end",
"=",
"Math",
".",
"max",
"(",
"selectionCursor",
".",
"index",
",",
"cursor",
".",
"index",
")",
";",
"String",
"oldValue",
"=",
"this",
".",
"text",
".",
"toString",
"(",
")",
";",
"String",
"newValue",
"=",
"new",
"StringBuilder",
"(",
"oldValue",
")",
".",
"delete",
"(",
"start",
",",
"end",
")",
".",
"toString",
"(",
")",
";",
"if",
"(",
"!",
"fireEvent",
"(",
"new",
"ComponentEvent",
".",
"ValueChange",
"<>",
"(",
"this",
",",
"oldValue",
",",
"newValue",
")",
")",
")",
"return",
";",
"this",
".",
"text",
"=",
"new",
"StringBuilder",
"(",
"newValue",
")",
";",
"guiText",
".",
"setText",
"(",
"newValue",
")",
";",
"selectingText",
"=",
"false",
";",
"cursor",
".",
"jumpTo",
"(",
"start",
")",
";",
"}"
] | Deletes the text currently selected. | [
"Deletes",
"the",
"text",
"currently",
"selected",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L437-L455 |
2,811 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.deleteWord | public void deleteWord(boolean backwards)
{
if (!selectingText)
{
selectingText = true;
selectionCursor.from(cursor);
cursor.jumpToNextSpace(backwards);
}
deleteSelectedText();
} | java | public void deleteWord(boolean backwards)
{
if (!selectingText)
{
selectingText = true;
selectionCursor.from(cursor);
cursor.jumpToNextSpace(backwards);
}
deleteSelectedText();
} | [
"public",
"void",
"deleteWord",
"(",
"boolean",
"backwards",
")",
"{",
"if",
"(",
"!",
"selectingText",
")",
"{",
"selectingText",
"=",
"true",
";",
"selectionCursor",
".",
"from",
"(",
"cursor",
")",
";",
"cursor",
".",
"jumpToNextSpace",
"(",
"backwards",
")",
";",
"}",
"deleteSelectedText",
"(",
")",
";",
"}"
] | Deletes the text from current cursor position to the next space.
@param backwards whether to look left for the next space | [
"Deletes",
"the",
"text",
"from",
"current",
"cursor",
"position",
"to",
"the",
"next",
"space",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L479-L488 |
2,812 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java | UITextField.selectWord | public void selectWord(int position)
{
if (text.length() == 0)
return;
selectingText = true;
selectionCursor.jumpTo(position);
selectionCursor.jumpToNextSpace(true);
if (Character.isWhitespace(text.charAt(selectionCursor.index)))
selectionCursor.shiftRight();
cursor.jumpTo(position);
cursor.jumpToNextSpace(false);
} | java | public void selectWord(int position)
{
if (text.length() == 0)
return;
selectingText = true;
selectionCursor.jumpTo(position);
selectionCursor.jumpToNextSpace(true);
if (Character.isWhitespace(text.charAt(selectionCursor.index)))
selectionCursor.shiftRight();
cursor.jumpTo(position);
cursor.jumpToNextSpace(false);
} | [
"public",
"void",
"selectWord",
"(",
"int",
"position",
")",
"{",
"if",
"(",
"text",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
";",
"selectingText",
"=",
"true",
";",
"selectionCursor",
".",
"jumpTo",
"(",
"position",
")",
";",
"selectionCursor",
".",
"jumpToNextSpace",
"(",
"true",
")",
";",
"if",
"(",
"Character",
".",
"isWhitespace",
"(",
"text",
".",
"charAt",
"(",
"selectionCursor",
".",
"index",
")",
")",
")",
"selectionCursor",
".",
"shiftRight",
"(",
")",
";",
"cursor",
".",
"jumpTo",
"(",
"position",
")",
";",
"cursor",
".",
"jumpToNextSpace",
"(",
"false",
")",
";",
"}"
] | Select word.
@param position the position | [
"Select",
"word",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITextField.java#L503-L517 |
2,813 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UISelect.java | UISelect.selected | public T selected()
{
return selectedIndex < 0 || selectedIndex >= options().size() ? null : options().get(selectedIndex);
} | java | public T selected()
{
return selectedIndex < 0 || selectedIndex >= options().size() ? null : options().get(selectedIndex);
} | [
"public",
"T",
"selected",
"(",
")",
"{",
"return",
"selectedIndex",
"<",
"0",
"||",
"selectedIndex",
">=",
"options",
"(",
")",
".",
"size",
"(",
")",
"?",
"null",
":",
"options",
"(",
")",
".",
"get",
"(",
"selectedIndex",
")",
";",
"}"
] | Gets the currently selected option.
@return the selected option | [
"Gets",
"the",
"currently",
"selected",
"option",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UISelect.java#L196-L199 |
2,814 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UISelect.java | UISelect.select | public T select(T option)
{
int index = options().indexOf(option);
if (index == -1 || index == selectedIndex)
return selected();
if (fireEvent(new SelectEvent<>(this, option)))
setSelected(option);
return selected();
} | java | public T select(T option)
{
int index = options().indexOf(option);
if (index == -1 || index == selectedIndex)
return selected();
if (fireEvent(new SelectEvent<>(this, option)))
setSelected(option);
return selected();
} | [
"public",
"T",
"select",
"(",
"T",
"option",
")",
"{",
"int",
"index",
"=",
"options",
"(",
")",
".",
"indexOf",
"(",
"option",
")",
";",
"if",
"(",
"index",
"==",
"-",
"1",
"||",
"index",
"==",
"selectedIndex",
")",
"return",
"selected",
"(",
")",
";",
"if",
"(",
"fireEvent",
"(",
"new",
"SelectEvent",
"<>",
"(",
"this",
",",
"option",
")",
")",
")",
"setSelected",
"(",
"option",
")",
";",
"return",
"selected",
"(",
")",
";",
"}"
] | Selects the option.
@param option the option
@return the option value | [
"Selects",
"the",
"option",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UISelect.java#L207-L217 |
2,815 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.leftOf | public static IntSupplier leftOf(ISized owner, IPositioned other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().x() - owner.size().width() - spacing;
};
} | java | public static IntSupplier leftOf(ISized owner, IPositioned other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().x() - owner.size().width() - spacing;
};
} | [
"public",
"static",
"IntSupplier",
"leftOf",
"(",
"ISized",
"owner",
",",
"IPositioned",
"other",
",",
"int",
"spacing",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"x",
"(",
")",
"-",
"owner",
".",
"size",
"(",
")",
".",
"width",
"(",
")",
"-",
"spacing",
";",
"}",
";",
"}"
] | Positions the owner to the left of the other.
@param other the other
@param spacing the spacing
@return the int supplier | [
"Positions",
"the",
"owner",
"to",
"the",
"left",
"of",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L161-L167 |
2,816 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.rightOf | public static <T extends IPositioned & ISized> IntSupplier rightOf(T other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().x() + other.size().width() + spacing;
};
} | java | public static <T extends IPositioned & ISized> IntSupplier rightOf(T other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().x() + other.size().width() + spacing;
};
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IntSupplier",
"rightOf",
"(",
"T",
"other",
",",
"int",
"spacing",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"x",
"(",
")",
"+",
"other",
".",
"size",
"(",
")",
".",
"width",
"(",
")",
"+",
"spacing",
";",
"}",
";",
"}"
] | Positions the owner to the right of the other.
@param <T> the generic type
@param other the other
@param spacing the spacing
@return the int supplier | [
"Positions",
"the",
"owner",
"to",
"the",
"right",
"of",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L177-L183 |
2,817 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.above | public static IntSupplier above(ISized owner, IPositioned other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().y() - owner.size().height() - spacing;
};
} | java | public static IntSupplier above(ISized owner, IPositioned other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().y() - owner.size().height() - spacing;
};
} | [
"public",
"static",
"IntSupplier",
"above",
"(",
"ISized",
"owner",
",",
"IPositioned",
"other",
",",
"int",
"spacing",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"y",
"(",
")",
"-",
"owner",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
"-",
"spacing",
";",
"}",
";",
"}"
] | Positions the owner above the other.
@param other the other
@param spacing the spacing
@return the int supplier | [
"Positions",
"the",
"owner",
"above",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L192-L198 |
2,818 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.below | public static <T extends IPositioned & ISized> IntSupplier below(T other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().y() + other.size().height() + spacing;
};
} | java | public static <T extends IPositioned & ISized> IntSupplier below(T other, int spacing)
{
checkNotNull(other);
return () -> {
return other.position().y() + other.size().height() + spacing;
};
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IntSupplier",
"below",
"(",
"T",
"other",
",",
"int",
"spacing",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"y",
"(",
")",
"+",
"other",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
"+",
"spacing",
";",
"}",
";",
"}"
] | Positions the owner below the other.
@param <T> the generic type
@param other the other
@param spacing the spacing
@return the int supplier | [
"Positions",
"the",
"owner",
"below",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L208-L215 |
2,819 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.leftAlignedTo | public static IntSupplier leftAlignedTo(IPositioned other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().x() + offset;
};
} | java | public static IntSupplier leftAlignedTo(IPositioned other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().x() + offset;
};
} | [
"public",
"static",
"IntSupplier",
"leftAlignedTo",
"(",
"IPositioned",
"other",
",",
"int",
"offset",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"x",
"(",
")",
"+",
"offset",
";",
"}",
";",
"}"
] | Left aligns the owner to the other.
@param other the other
@param offset the offset
@return the int supplier | [
"Left",
"aligns",
"the",
"owner",
"to",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L225-L231 |
2,820 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.centeredTo | public static <T extends IPositioned & ISized> IntSupplier centeredTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().x() + (other.size().width() - owner.size().width()) / 2 + offset;
};
} | java | public static <T extends IPositioned & ISized> IntSupplier centeredTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().x() + (other.size().width() - owner.size().width()) / 2 + offset;
};
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IntSupplier",
"centeredTo",
"(",
"ISized",
"owner",
",",
"T",
"other",
",",
"int",
"offset",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"x",
"(",
")",
"+",
"(",
"other",
".",
"size",
"(",
")",
".",
"width",
"(",
")",
"-",
"owner",
".",
"size",
"(",
")",
".",
"width",
"(",
")",
")",
"/",
"2",
"+",
"offset",
";",
"}",
";",
"}"
] | Centers the owner to the other.
@param <T> the generic type
@param other the other
@param offset the offset
@return the int supplier | [
"Centers",
"the",
"owner",
"to",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L257-L263 |
2,821 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.topAlignedTo | public static IntSupplier topAlignedTo(IPositioned other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().y() + offset;
};
} | java | public static IntSupplier topAlignedTo(IPositioned other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().y() + offset;
};
} | [
"public",
"static",
"IntSupplier",
"topAlignedTo",
"(",
"IPositioned",
"other",
",",
"int",
"offset",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"y",
"(",
")",
"+",
"offset",
";",
"}",
";",
"}"
] | Top aligns the owner to the other.
@param other the other
@param offset the offset
@return the int supplier | [
"Top",
"aligns",
"the",
"owner",
"to",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L272-L279 |
2,822 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.bottomAlignedTo | public static <T extends IPositioned & ISized> IntSupplier bottomAlignedTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().y() + other.size().height() - owner.size().height() + offset;
};
} | java | public static <T extends IPositioned & ISized> IntSupplier bottomAlignedTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return other.position().y() + other.size().height() - owner.size().height() + offset;
};
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IntSupplier",
"bottomAlignedTo",
"(",
"ISized",
"owner",
",",
"T",
"other",
",",
"int",
"offset",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"other",
".",
"position",
"(",
")",
".",
"y",
"(",
")",
"+",
"other",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
"-",
"owner",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
"+",
"offset",
";",
"}",
";",
"}"
] | Bottom aligns the owner to the other.
@param <T> the generic type
@param other the other
@param offset the offset
@return the int supplier | [
"Bottom",
"aligns",
"the",
"owner",
"to",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L289-L297 |
2,823 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Positions.java | Positions.middleAlignedTo | public static <T extends IPositioned & ISized> IntSupplier middleAlignedTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return (int) (other.position().y() + Math.ceil(((float) other.size().height() - owner.size().height()) / 2) + offset);
};
} | java | public static <T extends IPositioned & ISized> IntSupplier middleAlignedTo(ISized owner, T other, int offset)
{
checkNotNull(other);
return () -> {
return (int) (other.position().y() + Math.ceil(((float) other.size().height() - owner.size().height()) / 2) + offset);
};
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IntSupplier",
"middleAlignedTo",
"(",
"ISized",
"owner",
",",
"T",
"other",
",",
"int",
"offset",
")",
"{",
"checkNotNull",
"(",
"other",
")",
";",
"return",
"(",
")",
"->",
"{",
"return",
"(",
"int",
")",
"(",
"other",
".",
"position",
"(",
")",
".",
"y",
"(",
")",
"+",
"Math",
".",
"ceil",
"(",
"(",
"(",
"float",
")",
"other",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
"-",
"owner",
".",
"size",
"(",
")",
".",
"height",
"(",
")",
")",
"/",
"2",
")",
"+",
"offset",
")",
";",
"}",
";",
"}"
] | Middle aligns the owner to the other.
@param <T> the generic type
@param other the other
@param offset the offset
@return the int supplier | [
"Middle",
"aligns",
"the",
"owner",
"to",
"the",
"other",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Positions.java#L307-L313 |
2,824 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/util/EnumFacingUtils.java | EnumFacingUtils.getRotationCount | public static int getRotationCount(EnumFacing facing)
{
if (facing == null)
return 0;
switch (facing)
{
case EAST:
return 1;
case NORTH:
return 2;
case WEST:
return 3;
case SOUTH:
default:
return 0;
}
} | java | public static int getRotationCount(EnumFacing facing)
{
if (facing == null)
return 0;
switch (facing)
{
case EAST:
return 1;
case NORTH:
return 2;
case WEST:
return 3;
case SOUTH:
default:
return 0;
}
} | [
"public",
"static",
"int",
"getRotationCount",
"(",
"EnumFacing",
"facing",
")",
"{",
"if",
"(",
"facing",
"==",
"null",
")",
"return",
"0",
";",
"switch",
"(",
"facing",
")",
"{",
"case",
"EAST",
":",
"return",
"1",
";",
"case",
"NORTH",
":",
"return",
"2",
";",
"case",
"WEST",
":",
"return",
"3",
";",
"case",
"SOUTH",
":",
"default",
":",
"return",
"0",
";",
"}",
"}"
] | Gets the rotation count for the facing.
@param facing the facing
@return the rotation count | [
"Gets",
"the",
"rotation",
"count",
"for",
"the",
"facing",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/util/EnumFacingUtils.java#L44-L61 |
2,825 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/util/EnumFacingUtils.java | EnumFacingUtils.getRealSide | public static EnumFacing getRealSide(IBlockState state, EnumFacing side)
{
if (state == null || side == null)
return side;
EnumFacing direction = DirectionalComponent.getDirection(state);
if (direction == EnumFacing.SOUTH)
return side;
if (direction == EnumFacing.DOWN)
return side.rotateAround(Axis.X);
else if (direction == EnumFacing.UP)
switch (side)
{
case UP:
return EnumFacing.SOUTH;
case DOWN:
return EnumFacing.NORTH;
case NORTH:
return EnumFacing.UP;
case SOUTH:
return EnumFacing.DOWN;
default:
return side;
}
int count = EnumFacingUtils.getRotationCount(direction);
side = EnumFacingUtils.rotateFacing(side, count);
return side;
} | java | public static EnumFacing getRealSide(IBlockState state, EnumFacing side)
{
if (state == null || side == null)
return side;
EnumFacing direction = DirectionalComponent.getDirection(state);
if (direction == EnumFacing.SOUTH)
return side;
if (direction == EnumFacing.DOWN)
return side.rotateAround(Axis.X);
else if (direction == EnumFacing.UP)
switch (side)
{
case UP:
return EnumFacing.SOUTH;
case DOWN:
return EnumFacing.NORTH;
case NORTH:
return EnumFacing.UP;
case SOUTH:
return EnumFacing.DOWN;
default:
return side;
}
int count = EnumFacingUtils.getRotationCount(direction);
side = EnumFacingUtils.rotateFacing(side, count);
return side;
} | [
"public",
"static",
"EnumFacing",
"getRealSide",
"(",
"IBlockState",
"state",
",",
"EnumFacing",
"side",
")",
"{",
"if",
"(",
"state",
"==",
"null",
"||",
"side",
"==",
"null",
")",
"return",
"side",
";",
"EnumFacing",
"direction",
"=",
"DirectionalComponent",
".",
"getDirection",
"(",
"state",
")",
";",
"if",
"(",
"direction",
"==",
"EnumFacing",
".",
"SOUTH",
")",
"return",
"side",
";",
"if",
"(",
"direction",
"==",
"EnumFacing",
".",
"DOWN",
")",
"return",
"side",
".",
"rotateAround",
"(",
"Axis",
".",
"X",
")",
";",
"else",
"if",
"(",
"direction",
"==",
"EnumFacing",
".",
"UP",
")",
"switch",
"(",
"side",
")",
"{",
"case",
"UP",
":",
"return",
"EnumFacing",
".",
"SOUTH",
";",
"case",
"DOWN",
":",
"return",
"EnumFacing",
".",
"NORTH",
";",
"case",
"NORTH",
":",
"return",
"EnumFacing",
".",
"UP",
";",
"case",
"SOUTH",
":",
"return",
"EnumFacing",
".",
"DOWN",
";",
"default",
":",
"return",
"side",
";",
"}",
"int",
"count",
"=",
"EnumFacingUtils",
".",
"getRotationCount",
"(",
"direction",
")",
";",
"side",
"=",
"EnumFacingUtils",
".",
"rotateFacing",
"(",
"side",
",",
"count",
")",
";",
"return",
"side",
";",
"}"
] | Gets the real side of a rotated block.
@param state the state
@param side the side
@return the real side | [
"Gets",
"the",
"real",
"side",
"of",
"a",
"rotated",
"block",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/util/EnumFacingUtils.java#L99-L129 |
2,826 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/network/MalisisNetwork.java | MalisisNetwork.registerMessage | public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side)
{
super.registerMessage(messageHandler, requestMessageType, discriminator++, side);
MalisisCore.log.info("Registering " + messageHandler.getSimpleName() + " for " + requestMessageType.getSimpleName()
+ " with discriminator " + discriminator + " in channel " + name);
} | java | public <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> messageHandler, Class<REQ> requestMessageType, Side side)
{
super.registerMessage(messageHandler, requestMessageType, discriminator++, side);
MalisisCore.log.info("Registering " + messageHandler.getSimpleName() + " for " + requestMessageType.getSimpleName()
+ " with discriminator " + discriminator + " in channel " + name);
} | [
"public",
"<",
"REQ",
"extends",
"IMessage",
",",
"REPLY",
"extends",
"IMessage",
">",
"void",
"registerMessage",
"(",
"Class",
"<",
"?",
"extends",
"IMessageHandler",
"<",
"REQ",
",",
"REPLY",
">",
">",
"messageHandler",
",",
"Class",
"<",
"REQ",
">",
"requestMessageType",
",",
"Side",
"side",
")",
"{",
"super",
".",
"registerMessage",
"(",
"messageHandler",
",",
"requestMessageType",
",",
"discriminator",
"++",
",",
"side",
")",
";",
"MalisisCore",
".",
"log",
".",
"info",
"(",
"\"Registering \"",
"+",
"messageHandler",
".",
"getSimpleName",
"(",
")",
"+",
"\" for \"",
"+",
"requestMessageType",
".",
"getSimpleName",
"(",
")",
"+",
"\" with discriminator \"",
"+",
"discriminator",
"+",
"\" in channel \"",
"+",
"name",
")",
";",
"}"
] | Register a message with the next discriminator available.
@param <REQ> the generic type
@param <REPLY> the generic type
@param messageHandler the message handler
@param requestMessageType the request message type
@param side the side | [
"Register",
"a",
"message",
"with",
"the",
"next",
"discriminator",
"available",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/network/MalisisNetwork.java#L98-L103 |
2,827 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/renderer/element/Bezier.java | Bezier.buildVertexes | private void buildVertexes()
{
vertexes.clear();
if (controlPoints.size() == 0)
return;
double step = 1D / (precision + 1);
double t = 0;
vertexes.add(controlPoints.get(0));
for (int i = 1; i <= precision; i++)
{
t = i * step;
vertexes.add(i, interpolateAll(controlPoints, controlPoints.size() - 1, 0, t));
}
vertexes.add(controlPoints.get(controlPoints.size() - 1));
dirty = false;
} | java | private void buildVertexes()
{
vertexes.clear();
if (controlPoints.size() == 0)
return;
double step = 1D / (precision + 1);
double t = 0;
vertexes.add(controlPoints.get(0));
for (int i = 1; i <= precision; i++)
{
t = i * step;
vertexes.add(i, interpolateAll(controlPoints, controlPoints.size() - 1, 0, t));
}
vertexes.add(controlPoints.get(controlPoints.size() - 1));
dirty = false;
} | [
"private",
"void",
"buildVertexes",
"(",
")",
"{",
"vertexes",
".",
"clear",
"(",
")",
";",
"if",
"(",
"controlPoints",
".",
"size",
"(",
")",
"==",
"0",
")",
"return",
";",
"double",
"step",
"=",
"1D",
"/",
"(",
"precision",
"+",
"1",
")",
";",
"double",
"t",
"=",
"0",
";",
"vertexes",
".",
"add",
"(",
"controlPoints",
".",
"get",
"(",
"0",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<=",
"precision",
";",
"i",
"++",
")",
"{",
"t",
"=",
"i",
"*",
"step",
";",
"vertexes",
".",
"add",
"(",
"i",
",",
"interpolateAll",
"(",
"controlPoints",
",",
"controlPoints",
".",
"size",
"(",
")",
"-",
"1",
",",
"0",
",",
"t",
")",
")",
";",
"}",
"vertexes",
".",
"add",
"(",
"controlPoints",
".",
"get",
"(",
"controlPoints",
".",
"size",
"(",
")",
"-",
"1",
")",
")",
";",
"dirty",
"=",
"false",
";",
"}"
] | Builds the vertexes. | [
"Builds",
"the",
"vertexes",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/renderer/element/Bezier.java#L148-L165 |
2,828 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/renderer/element/Bezier.java | Bezier.interpolateAll | public Vertex interpolateAll(List<Vertex> vertexes, int r, int index, double t)
{
if (vertexes.size() == 1)
return vertexes.get(0);
if (r == 0)
return vertexes.get(index);
Vertex v1 = interpolateAll(vertexes, r - 1, index, t);
Vertex v2 = interpolateAll(vertexes, r - 1, index + 1, t);
return interpolate(v1, v2, t);
} | java | public Vertex interpolateAll(List<Vertex> vertexes, int r, int index, double t)
{
if (vertexes.size() == 1)
return vertexes.get(0);
if (r == 0)
return vertexes.get(index);
Vertex v1 = interpolateAll(vertexes, r - 1, index, t);
Vertex v2 = interpolateAll(vertexes, r - 1, index + 1, t);
return interpolate(v1, v2, t);
} | [
"public",
"Vertex",
"interpolateAll",
"(",
"List",
"<",
"Vertex",
">",
"vertexes",
",",
"int",
"r",
",",
"int",
"index",
",",
"double",
"t",
")",
"{",
"if",
"(",
"vertexes",
".",
"size",
"(",
")",
"==",
"1",
")",
"return",
"vertexes",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"r",
"==",
"0",
")",
"return",
"vertexes",
".",
"get",
"(",
"index",
")",
";",
"Vertex",
"v1",
"=",
"interpolateAll",
"(",
"vertexes",
",",
"r",
"-",
"1",
",",
"index",
",",
"t",
")",
";",
"Vertex",
"v2",
"=",
"interpolateAll",
"(",
"vertexes",
",",
"r",
"-",
"1",
",",
"index",
"+",
"1",
",",
"t",
")",
";",
"return",
"interpolate",
"(",
"v1",
",",
"v2",
",",
"t",
")",
";",
"}"
] | Interpolate the vertexes places.
@param vertexes the vertexes
@param r the degree
@param index the index of the vertex
@param t the completion among the path
@return the vertex | [
"Interpolate",
"the",
"vertexes",
"places",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/renderer/element/Bezier.java#L176-L187 |
2,829 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/inventory/MalisisSlot.java | MalisisSlot.setItemStackSize | public int setItemStackSize(int stackSize)
{
if (itemStack.isEmpty())
return 0;
int start = itemStack.getCount();
itemStack.setCount(Math.min(stackSize, Math.min(itemStack.getMaxStackSize(), getSlotStackLimit())));
return itemStack.getCount() - start;
} | java | public int setItemStackSize(int stackSize)
{
if (itemStack.isEmpty())
return 0;
int start = itemStack.getCount();
itemStack.setCount(Math.min(stackSize, Math.min(itemStack.getMaxStackSize(), getSlotStackLimit())));
return itemStack.getCount() - start;
} | [
"public",
"int",
"setItemStackSize",
"(",
"int",
"stackSize",
")",
"{",
"if",
"(",
"itemStack",
".",
"isEmpty",
"(",
")",
")",
"return",
"0",
";",
"int",
"start",
"=",
"itemStack",
".",
"getCount",
"(",
")",
";",
"itemStack",
".",
"setCount",
"(",
"Math",
".",
"min",
"(",
"stackSize",
",",
"Math",
".",
"min",
"(",
"itemStack",
".",
"getMaxStackSize",
"(",
")",
",",
"getSlotStackLimit",
"(",
")",
")",
")",
")",
";",
"return",
"itemStack",
".",
"getCount",
"(",
")",
"-",
"start",
";",
"}"
] | Sets the item stack size.
@param stackSize the stack size
@return the amount of items that were added to the slot. | [
"Sets",
"the",
"item",
"stack",
"size",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/inventory/MalisisSlot.java#L274-L282 |
2,830 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/component/interaction/UITab.java | UITab.setActive | public UITab setActive(boolean active)
{
if (container == null)
{
this.active = active;
return this;
}
// if (this.active != active)
// {
// switch (getTabPosition())
// {
// case TOP:
// case BOTTOM:
// this.y += active ? -1 : 1;
// this.height += active ? 2 : -2;
// break;
// case LEFT:
// case RIGHT:
// this.x += active ? -1 : 1;
// this.width += active ? 2 : -2;
// break;
// }
// }
this.active = active;
this.container.setVisible(active);
this.container.setEnabled(active);
this.zIndex = container.getZIndex() + (active ? 1 : 0);
//applies current color to attached container
setColor(this.color);
fireEvent(new ActiveStateChange<>(this, active));
return this;
} | java | public UITab setActive(boolean active)
{
if (container == null)
{
this.active = active;
return this;
}
// if (this.active != active)
// {
// switch (getTabPosition())
// {
// case TOP:
// case BOTTOM:
// this.y += active ? -1 : 1;
// this.height += active ? 2 : -2;
// break;
// case LEFT:
// case RIGHT:
// this.x += active ? -1 : 1;
// this.width += active ? 2 : -2;
// break;
// }
// }
this.active = active;
this.container.setVisible(active);
this.container.setEnabled(active);
this.zIndex = container.getZIndex() + (active ? 1 : 0);
//applies current color to attached container
setColor(this.color);
fireEvent(new ActiveStateChange<>(this, active));
return this;
} | [
"public",
"UITab",
"setActive",
"(",
"boolean",
"active",
")",
"{",
"if",
"(",
"container",
"==",
"null",
")",
"{",
"this",
".",
"active",
"=",
"active",
";",
"return",
"this",
";",
"}",
"//\t\tif (this.active != active)",
"//\t\t{",
"//\t\t\tswitch (getTabPosition())",
"//\t\t\t{",
"//\t\t\t\tcase TOP:",
"//\t\t\t\tcase BOTTOM:",
"//\t\t\t\t\tthis.y += active ? -1 : 1;",
"//\t\t\t\t\tthis.height += active ? 2 : -2;",
"//\t\t\t\t\tbreak;",
"//\t\t\t\tcase LEFT:",
"//\t\t\t\tcase RIGHT:",
"//\t\t\t\t\tthis.x += active ? -1 : 1;",
"//\t\t\t\t\tthis.width += active ? 2 : -2;",
"//\t\t\t\t\tbreak;",
"//\t\t\t}",
"//\t\t}",
"this",
".",
"active",
"=",
"active",
";",
"this",
".",
"container",
".",
"setVisible",
"(",
"active",
")",
";",
"this",
".",
"container",
".",
"setEnabled",
"(",
"active",
")",
";",
"this",
".",
"zIndex",
"=",
"container",
".",
"getZIndex",
"(",
")",
"+",
"(",
"active",
"?",
"1",
":",
"0",
")",
";",
"//applies current color to attached container",
"setColor",
"(",
"this",
".",
"color",
")",
";",
"fireEvent",
"(",
"new",
"ActiveStateChange",
"<>",
"(",
"this",
",",
"active",
")",
")",
";",
"return",
"this",
";",
"}"
] | Sets this tab to be active. Enables and sets visibility for its container.
@param active true if active | [
"Sets",
"this",
"tab",
"to",
"be",
"active",
".",
"Enables",
"and",
"sets",
"visibility",
"for",
"its",
"container",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/component/interaction/UITab.java#L231-L266 |
2,831 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/renderer/animation/transformation/ParallelTransformation.java | ParallelTransformation.doTransform | @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doTransform(ITransformable transformable, float comp)
{
if (listTransformations.size() == 0)
return;
for (Transformation transformation : listTransformations)
transformation.transform(transformable, elapsedTimeCurrentLoop);
} | java | @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void doTransform(ITransformable transformable, float comp)
{
if (listTransformations.size() == 0)
return;
for (Transformation transformation : listTransformations)
transformation.transform(transformable, elapsedTimeCurrentLoop);
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
",",
"\"rawtypes\"",
"}",
")",
"@",
"Override",
"protected",
"void",
"doTransform",
"(",
"ITransformable",
"transformable",
",",
"float",
"comp",
")",
"{",
"if",
"(",
"listTransformations",
".",
"size",
"(",
")",
"==",
"0",
")",
"return",
";",
"for",
"(",
"Transformation",
"transformation",
":",
"listTransformations",
")",
"transformation",
".",
"transform",
"(",
"transformable",
",",
"elapsedTimeCurrentLoop",
")",
";",
"}"
] | Calculates the tranformation.
@param transformable the transformable
@param comp the comp | [
"Calculates",
"the",
"tranformation",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/renderer/animation/transformation/ParallelTransformation.java#L82-L91 |
2,832 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/renderer/animation/transformation/ParallelTransformation.java | ParallelTransformation.reversed | @Override
public ParallelTransformation reversed(boolean reversed)
{
if (!reversed)
return this;
for (Transformation<?, ?> transformation : listTransformations)
transformation.reversed(true);
return this;
} | java | @Override
public ParallelTransformation reversed(boolean reversed)
{
if (!reversed)
return this;
for (Transformation<?, ?> transformation : listTransformations)
transformation.reversed(true);
return this;
} | [
"@",
"Override",
"public",
"ParallelTransformation",
"reversed",
"(",
"boolean",
"reversed",
")",
"{",
"if",
"(",
"!",
"reversed",
")",
"return",
"this",
";",
"for",
"(",
"Transformation",
"<",
"?",
",",
"?",
">",
"transformation",
":",
"listTransformations",
")",
"transformation",
".",
"reversed",
"(",
"true",
")",
";",
"return",
"this",
";",
"}"
] | Sets this trasformation in reverse.
@param reversed the reversed
@return the parallel transformation | [
"Sets",
"this",
"trasformation",
"in",
"reverse",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/renderer/animation/transformation/ParallelTransformation.java#L99-L109 |
2,833 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/MalisisCore.java | MalisisCore.preInit | @EventHandler
public void preInit(FMLPreInitializationEvent event)
{
asmDataTable = event.getAsmData();
autoLoadClasses();
//register this to the EVENT_BUS for onGuiClose()
MinecraftForge.EVENT_BUS.register(this);
settings = new MalisisCoreSettings(event.getSuggestedConfigurationFile());
Registries.processFMLStateEvent(event);
} | java | @EventHandler
public void preInit(FMLPreInitializationEvent event)
{
asmDataTable = event.getAsmData();
autoLoadClasses();
//register this to the EVENT_BUS for onGuiClose()
MinecraftForge.EVENT_BUS.register(this);
settings = new MalisisCoreSettings(event.getSuggestedConfigurationFile());
Registries.processFMLStateEvent(event);
} | [
"@",
"EventHandler",
"public",
"void",
"preInit",
"(",
"FMLPreInitializationEvent",
"event",
")",
"{",
"asmDataTable",
"=",
"event",
".",
"getAsmData",
"(",
")",
";",
"autoLoadClasses",
"(",
")",
";",
"//register this to the EVENT_BUS for onGuiClose()",
"MinecraftForge",
".",
"EVENT_BUS",
".",
"register",
"(",
"this",
")",
";",
"settings",
"=",
"new",
"MalisisCoreSettings",
"(",
"event",
".",
"getSuggestedConfigurationFile",
"(",
")",
")",
";",
"Registries",
".",
"processFMLStateEvent",
"(",
"event",
")",
";",
"}"
] | Pre-initialization event
@param event the event | [
"Pre",
"-",
"initialization",
"event"
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/MalisisCore.java#L234-L246 |
2,834 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/util/Ray.java | Ray.intersectX | public double intersectX(double x)
{
if (direction.x == 0)
return Double.NaN;
return (x - origin.x) / direction.x;
} | java | public double intersectX(double x)
{
if (direction.x == 0)
return Double.NaN;
return (x - origin.x) / direction.x;
} | [
"public",
"double",
"intersectX",
"(",
"double",
"x",
")",
"{",
"if",
"(",
"direction",
".",
"x",
"==",
"0",
")",
"return",
"Double",
".",
"NaN",
";",
"return",
"(",
"x",
"-",
"origin",
".",
"x",
")",
"/",
"direction",
".",
"x",
";",
"}"
] | Gets the distance to the plane at x.
@param x the x plane
@return the distance | [
"Gets",
"the",
"distance",
"to",
"the",
"plane",
"at",
"x",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/util/Ray.java#L102-L107 |
2,835 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/util/Ray.java | Ray.intersectY | public double intersectY(double y)
{
if (direction.y == 0)
return Double.NaN;
return (y - origin.y) / direction.y;
} | java | public double intersectY(double y)
{
if (direction.y == 0)
return Double.NaN;
return (y - origin.y) / direction.y;
} | [
"public",
"double",
"intersectY",
"(",
"double",
"y",
")",
"{",
"if",
"(",
"direction",
".",
"y",
"==",
"0",
")",
"return",
"Double",
".",
"NaN",
";",
"return",
"(",
"y",
"-",
"origin",
".",
"y",
")",
"/",
"direction",
".",
"y",
";",
"}"
] | Gets the distance to the plane at y.
@param y the y plane
@return the distance | [
"Gets",
"the",
"distance",
"to",
"the",
"plane",
"at",
"y",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/util/Ray.java#L115-L120 |
2,836 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/util/Ray.java | Ray.intersectZ | public double intersectZ(double z)
{
if (direction.z == 0)
return Double.NaN;
return (z - origin.z) / direction.z;
} | java | public double intersectZ(double z)
{
if (direction.z == 0)
return Double.NaN;
return (z - origin.z) / direction.z;
} | [
"public",
"double",
"intersectZ",
"(",
"double",
"z",
")",
"{",
"if",
"(",
"direction",
".",
"z",
"==",
"0",
")",
"return",
"Double",
".",
"NaN",
";",
"return",
"(",
"z",
"-",
"origin",
".",
"z",
")",
"/",
"direction",
".",
"z",
";",
"}"
] | Gets the distance to the plane at z.
@param z the z plane
@return the distance | [
"Gets",
"the",
"distance",
"to",
"the",
"plane",
"at",
"z",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/util/Ray.java#L128-L133 |
2,837 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Position.java | Position.inParent | public static IPosition inParent(IChild<?> owner, int x, int y)
{
return new DynamicPosition(0, 0, leftAligned(owner, x), topAligned(owner, y));
} | java | public static IPosition inParent(IChild<?> owner, int x, int y)
{
return new DynamicPosition(0, 0, leftAligned(owner, x), topAligned(owner, y));
} | [
"public",
"static",
"IPosition",
"inParent",
"(",
"IChild",
"<",
"?",
">",
"owner",
",",
"int",
"x",
",",
"int",
"y",
")",
"{",
"return",
"new",
"DynamicPosition",
"(",
"0",
",",
"0",
",",
"leftAligned",
"(",
"owner",
",",
"x",
")",
",",
"topAligned",
"(",
"owner",
",",
"y",
")",
")",
";",
"}"
] | position relative to parent | [
"position",
"relative",
"to",
"parent"
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Position.java#L243-L246 |
2,838 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/element/position/Position.java | Position.leftOf | public static <T extends IPositioned & ISized, U extends IPositioned & ISized> IPosition leftOf(ISized owner, U other, int spacing)
{
return of(Positions.leftOf(owner, other, spacing), middleAlignedTo(owner, other, 0));
} | java | public static <T extends IPositioned & ISized, U extends IPositioned & ISized> IPosition leftOf(ISized owner, U other, int spacing)
{
return of(Positions.leftOf(owner, other, spacing), middleAlignedTo(owner, other, 0));
} | [
"public",
"static",
"<",
"T",
"extends",
"IPositioned",
"&",
"ISized",
",",
"U",
"extends",
"IPositioned",
"&",
"ISized",
">",
"IPosition",
"leftOf",
"(",
"ISized",
"owner",
",",
"U",
"other",
",",
"int",
"spacing",
")",
"{",
"return",
"of",
"(",
"Positions",
".",
"leftOf",
"(",
"owner",
",",
"other",
",",
"spacing",
")",
",",
"middleAlignedTo",
"(",
"owner",
",",
"other",
",",
"0",
")",
")",
";",
"}"
] | position relative to other | [
"position",
"relative",
"to",
"other"
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/element/position/Position.java#L301-L304 |
2,839 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/MalisisGui.java | MalisisGui.handleMouseInput | @Override
public void handleMouseInput()
{
try
{
MOUSE_POSITION.udpate(this);
UIComponent component = getComponentAt(MOUSE_POSITION.x(), MOUSE_POSITION.y());
int button = Mouse.getEventButton();
if (Mouse.getEventButtonState())
{
if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
return;
this.eventButton = button;
this.lastMouseEvent = Minecraft.getSystemTime();
this.mousePressed(component, this.eventButton);
}
else if (button != -1)
{
if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
return;
this.eventButton = -1;
this.mouseReleased(component, button);
this.draggedComponent = null;
}
else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
{
this.mouseDragged(this.eventButton);
}
if (MOUSE_POSITION.hasChanged())
{
if (component != null)
{
tooltip = component.getTooltip();
if (component.isEnabled())
{
component.onMouseMove();
component.setHovered(true);
}
}
else
{
setHoveredComponent(null, false);
tooltip = null;
}
}
int delta = Mouse.getEventDWheel();
if (delta == 0)
return;
else if (delta > 1)
delta = 1;
else if (delta < -1)
delta = -1;
if (component != null && component.isEnabled())
{
component.onScrollWheel(delta);
}
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | java | @Override
public void handleMouseInput()
{
try
{
MOUSE_POSITION.udpate(this);
UIComponent component = getComponentAt(MOUSE_POSITION.x(), MOUSE_POSITION.y());
int button = Mouse.getEventButton();
if (Mouse.getEventButtonState())
{
if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
return;
this.eventButton = button;
this.lastMouseEvent = Minecraft.getSystemTime();
this.mousePressed(component, this.eventButton);
}
else if (button != -1)
{
if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
return;
this.eventButton = -1;
this.mouseReleased(component, button);
this.draggedComponent = null;
}
else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
{
this.mouseDragged(this.eventButton);
}
if (MOUSE_POSITION.hasChanged())
{
if (component != null)
{
tooltip = component.getTooltip();
if (component.isEnabled())
{
component.onMouseMove();
component.setHovered(true);
}
}
else
{
setHoveredComponent(null, false);
tooltip = null;
}
}
int delta = Mouse.getEventDWheel();
if (delta == 0)
return;
else if (delta > 1)
delta = 1;
else if (delta < -1)
delta = -1;
if (component != null && component.isEnabled())
{
component.onScrollWheel(delta);
}
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | [
"@",
"Override",
"public",
"void",
"handleMouseInput",
"(",
")",
"{",
"try",
"{",
"MOUSE_POSITION",
".",
"udpate",
"(",
"this",
")",
";",
"UIComponent",
"component",
"=",
"getComponentAt",
"(",
"MOUSE_POSITION",
".",
"x",
"(",
")",
",",
"MOUSE_POSITION",
".",
"y",
"(",
")",
")",
";",
"int",
"button",
"=",
"Mouse",
".",
"getEventButton",
"(",
")",
";",
"if",
"(",
"Mouse",
".",
"getEventButtonState",
"(",
")",
")",
"{",
"if",
"(",
"this",
".",
"mc",
".",
"gameSettings",
".",
"touchscreen",
"&&",
"this",
".",
"touchValue",
"++",
">",
"0",
")",
"return",
";",
"this",
".",
"eventButton",
"=",
"button",
";",
"this",
".",
"lastMouseEvent",
"=",
"Minecraft",
".",
"getSystemTime",
"(",
")",
";",
"this",
".",
"mousePressed",
"(",
"component",
",",
"this",
".",
"eventButton",
")",
";",
"}",
"else",
"if",
"(",
"button",
"!=",
"-",
"1",
")",
"{",
"if",
"(",
"this",
".",
"mc",
".",
"gameSettings",
".",
"touchscreen",
"&&",
"--",
"this",
".",
"touchValue",
">",
"0",
")",
"return",
";",
"this",
".",
"eventButton",
"=",
"-",
"1",
";",
"this",
".",
"mouseReleased",
"(",
"component",
",",
"button",
")",
";",
"this",
".",
"draggedComponent",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"this",
".",
"eventButton",
"!=",
"-",
"1",
"&&",
"this",
".",
"lastMouseEvent",
">",
"0L",
")",
"{",
"this",
".",
"mouseDragged",
"(",
"this",
".",
"eventButton",
")",
";",
"}",
"if",
"(",
"MOUSE_POSITION",
".",
"hasChanged",
"(",
")",
")",
"{",
"if",
"(",
"component",
"!=",
"null",
")",
"{",
"tooltip",
"=",
"component",
".",
"getTooltip",
"(",
")",
";",
"if",
"(",
"component",
".",
"isEnabled",
"(",
")",
")",
"{",
"component",
".",
"onMouseMove",
"(",
")",
";",
"component",
".",
"setHovered",
"(",
"true",
")",
";",
"}",
"}",
"else",
"{",
"setHoveredComponent",
"(",
"null",
",",
"false",
")",
";",
"tooltip",
"=",
"null",
";",
"}",
"}",
"int",
"delta",
"=",
"Mouse",
".",
"getEventDWheel",
"(",
")",
";",
"if",
"(",
"delta",
"==",
"0",
")",
"return",
";",
"else",
"if",
"(",
"delta",
">",
"1",
")",
"delta",
"=",
"1",
";",
"else",
"if",
"(",
"delta",
"<",
"-",
"1",
")",
"delta",
"=",
"-",
"1",
";",
"if",
"(",
"component",
"!=",
"null",
"&&",
"component",
".",
"isEnabled",
"(",
")",
")",
"{",
"component",
".",
"onScrollWheel",
"(",
"delta",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"MalisisCore",
".",
"message",
"(",
"\"A problem occured : \"",
"+",
"e",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\": \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"e",
".",
"printStackTrace",
"(",
"new",
"PrintStream",
"(",
"new",
"FileOutputStream",
"(",
"FileDescriptor",
".",
"out",
")",
")",
")",
";",
"}",
"}"
] | Called every frame to handle mouse input. | [
"Called",
"every",
"frame",
"to",
"handle",
"mouse",
"input",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/MalisisGui.java#L331-L399 |
2,840 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/MalisisGui.java | MalisisGui.mousePressed | protected void mousePressed(UIComponent component, int button)
{
try
{
long time = System.currentTimeMillis();
if (component != null && component.isEnabled())
{
boolean regularClick = true;
//double click
if (button == lastClickButton && time - lastClickTime < 250 && component == focusedComponent)
{
regularClick = !component.onDoubleClick(MouseButton.getButton(button));
lastClickTime = 0;
}
//do not trigger onButtonPress when double clicked (fixed shift-double click issue in inventory)
if (regularClick)
{
component.onButtonPress(MouseButton.getButton(button));
if (draggedComponent == null)
draggedComponent = component;
}
component.setFocused(true);
}
else
{
setFocusedComponent(null, true);
if (inventoryContainer != null && !inventoryContainer.getPickedItemStack().isEmpty())
{
ActionType action = button == 1 ? ActionType.DROP_ONE : ActionType.DROP_STACK;
MalisisGui.sendAction(action, null, button);
}
}
lastClickTime = time;
lastClickButton = button;
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | java | protected void mousePressed(UIComponent component, int button)
{
try
{
long time = System.currentTimeMillis();
if (component != null && component.isEnabled())
{
boolean regularClick = true;
//double click
if (button == lastClickButton && time - lastClickTime < 250 && component == focusedComponent)
{
regularClick = !component.onDoubleClick(MouseButton.getButton(button));
lastClickTime = 0;
}
//do not trigger onButtonPress when double clicked (fixed shift-double click issue in inventory)
if (regularClick)
{
component.onButtonPress(MouseButton.getButton(button));
if (draggedComponent == null)
draggedComponent = component;
}
component.setFocused(true);
}
else
{
setFocusedComponent(null, true);
if (inventoryContainer != null && !inventoryContainer.getPickedItemStack().isEmpty())
{
ActionType action = button == 1 ? ActionType.DROP_ONE : ActionType.DROP_STACK;
MalisisGui.sendAction(action, null, button);
}
}
lastClickTime = time;
lastClickButton = button;
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | [
"protected",
"void",
"mousePressed",
"(",
"UIComponent",
"component",
",",
"int",
"button",
")",
"{",
"try",
"{",
"long",
"time",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"if",
"(",
"component",
"!=",
"null",
"&&",
"component",
".",
"isEnabled",
"(",
")",
")",
"{",
"boolean",
"regularClick",
"=",
"true",
";",
"//double click",
"if",
"(",
"button",
"==",
"lastClickButton",
"&&",
"time",
"-",
"lastClickTime",
"<",
"250",
"&&",
"component",
"==",
"focusedComponent",
")",
"{",
"regularClick",
"=",
"!",
"component",
".",
"onDoubleClick",
"(",
"MouseButton",
".",
"getButton",
"(",
"button",
")",
")",
";",
"lastClickTime",
"=",
"0",
";",
"}",
"//do not trigger onButtonPress when double clicked (fixed shift-double click issue in inventory)",
"if",
"(",
"regularClick",
")",
"{",
"component",
".",
"onButtonPress",
"(",
"MouseButton",
".",
"getButton",
"(",
"button",
")",
")",
";",
"if",
"(",
"draggedComponent",
"==",
"null",
")",
"draggedComponent",
"=",
"component",
";",
"}",
"component",
".",
"setFocused",
"(",
"true",
")",
";",
"}",
"else",
"{",
"setFocusedComponent",
"(",
"null",
",",
"true",
")",
";",
"if",
"(",
"inventoryContainer",
"!=",
"null",
"&&",
"!",
"inventoryContainer",
".",
"getPickedItemStack",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"ActionType",
"action",
"=",
"button",
"==",
"1",
"?",
"ActionType",
".",
"DROP_ONE",
":",
"ActionType",
".",
"DROP_STACK",
";",
"MalisisGui",
".",
"sendAction",
"(",
"action",
",",
"null",
",",
"button",
")",
";",
"}",
"}",
"lastClickTime",
"=",
"time",
";",
"lastClickButton",
"=",
"button",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"MalisisCore",
".",
"message",
"(",
"\"A problem occured : \"",
"+",
"e",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\": \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"e",
".",
"printStackTrace",
"(",
"new",
"PrintStream",
"(",
"new",
"FileOutputStream",
"(",
"FileDescriptor",
".",
"out",
")",
")",
")",
";",
"}",
"}"
] | Called when a mouse button is pressed down. | [
"Called",
"when",
"a",
"mouse",
"button",
"is",
"pressed",
"down",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/MalisisGui.java#L404-L447 |
2,841 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/MalisisGui.java | MalisisGui.mouseDragged | protected void mouseDragged(int button)
{
try
{
if (draggedComponent != null)
draggedComponent.onDrag(MouseButton.getButton(button));
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | java | protected void mouseDragged(int button)
{
try
{
if (draggedComponent != null)
draggedComponent.onDrag(MouseButton.getButton(button));
}
catch (Exception e)
{
MalisisCore.message("A problem occured : " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | [
"protected",
"void",
"mouseDragged",
"(",
"int",
"button",
")",
"{",
"try",
"{",
"if",
"(",
"draggedComponent",
"!=",
"null",
")",
"draggedComponent",
".",
"onDrag",
"(",
"MouseButton",
".",
"getButton",
"(",
"button",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"MalisisCore",
".",
"message",
"(",
"\"A problem occured : \"",
"+",
"e",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\": \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"e",
".",
"printStackTrace",
"(",
"new",
"PrintStream",
"(",
"new",
"FileOutputStream",
"(",
"FileDescriptor",
".",
"out",
")",
")",
")",
";",
"}",
"}"
] | Called when the mouse is moved while a button is pressed. | [
"Called",
"when",
"the",
"mouse",
"is",
"moved",
"while",
"a",
"button",
"is",
"pressed",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/MalisisGui.java#L452-L465 |
2,842 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/MalisisGui.java | MalisisGui.keyTyped | @Override
protected void keyTyped(char keyChar, int keyCode)
{
try
{
boolean ret = false;
for (IKeyListener listener : keyListeners)
ret |= listener.onKeyTyped(keyChar, keyCode);
if (ret)
return;
if (focusedComponent != null && !keyListeners.contains(focusedComponent) && focusedComponent.onKeyTyped(keyChar, keyCode))
return;
if (hoveredComponent != null && !keyListeners.contains(hoveredComponent) && hoveredComponent.onKeyTyped(keyChar, keyCode))
return;
if (isGuiCloseKey(keyCode) && mc.currentScreen == this)
close();
if (!MalisisCore.isObfEnv && isCtrlKeyDown() && (current() != null || isOverlay))
{
if (keyCode == Keyboard.KEY_R)
{
clearScreen();
setResolution();
setHoveredComponent(null, true);
setFocusedComponent(null, true);
constructed = false;
doConstruct();
}
if (keyCode == Keyboard.KEY_D)
{
debug = !debug;
debugComponent.setEnabled(debug);
}
if (keyCode == Keyboard.KEY_P)
{
Position.CACHED = !Position.CACHED;
}
if (keyCode == Keyboard.KEY_S)
{
Size.CACHED = !Size.CACHED;
}
}
}
catch (Exception e)
{
MalisisCore.message("A problem occured while handling key typed for " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | java | @Override
protected void keyTyped(char keyChar, int keyCode)
{
try
{
boolean ret = false;
for (IKeyListener listener : keyListeners)
ret |= listener.onKeyTyped(keyChar, keyCode);
if (ret)
return;
if (focusedComponent != null && !keyListeners.contains(focusedComponent) && focusedComponent.onKeyTyped(keyChar, keyCode))
return;
if (hoveredComponent != null && !keyListeners.contains(hoveredComponent) && hoveredComponent.onKeyTyped(keyChar, keyCode))
return;
if (isGuiCloseKey(keyCode) && mc.currentScreen == this)
close();
if (!MalisisCore.isObfEnv && isCtrlKeyDown() && (current() != null || isOverlay))
{
if (keyCode == Keyboard.KEY_R)
{
clearScreen();
setResolution();
setHoveredComponent(null, true);
setFocusedComponent(null, true);
constructed = false;
doConstruct();
}
if (keyCode == Keyboard.KEY_D)
{
debug = !debug;
debugComponent.setEnabled(debug);
}
if (keyCode == Keyboard.KEY_P)
{
Position.CACHED = !Position.CACHED;
}
if (keyCode == Keyboard.KEY_S)
{
Size.CACHED = !Size.CACHED;
}
}
}
catch (Exception e)
{
MalisisCore.message("A problem occured while handling key typed for " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
} | [
"@",
"Override",
"protected",
"void",
"keyTyped",
"(",
"char",
"keyChar",
",",
"int",
"keyCode",
")",
"{",
"try",
"{",
"boolean",
"ret",
"=",
"false",
";",
"for",
"(",
"IKeyListener",
"listener",
":",
"keyListeners",
")",
"ret",
"|=",
"listener",
".",
"onKeyTyped",
"(",
"keyChar",
",",
"keyCode",
")",
";",
"if",
"(",
"ret",
")",
"return",
";",
"if",
"(",
"focusedComponent",
"!=",
"null",
"&&",
"!",
"keyListeners",
".",
"contains",
"(",
"focusedComponent",
")",
"&&",
"focusedComponent",
".",
"onKeyTyped",
"(",
"keyChar",
",",
"keyCode",
")",
")",
"return",
";",
"if",
"(",
"hoveredComponent",
"!=",
"null",
"&&",
"!",
"keyListeners",
".",
"contains",
"(",
"hoveredComponent",
")",
"&&",
"hoveredComponent",
".",
"onKeyTyped",
"(",
"keyChar",
",",
"keyCode",
")",
")",
"return",
";",
"if",
"(",
"isGuiCloseKey",
"(",
"keyCode",
")",
"&&",
"mc",
".",
"currentScreen",
"==",
"this",
")",
"close",
"(",
")",
";",
"if",
"(",
"!",
"MalisisCore",
".",
"isObfEnv",
"&&",
"isCtrlKeyDown",
"(",
")",
"&&",
"(",
"current",
"(",
")",
"!=",
"null",
"||",
"isOverlay",
")",
")",
"{",
"if",
"(",
"keyCode",
"==",
"Keyboard",
".",
"KEY_R",
")",
"{",
"clearScreen",
"(",
")",
";",
"setResolution",
"(",
")",
";",
"setHoveredComponent",
"(",
"null",
",",
"true",
")",
";",
"setFocusedComponent",
"(",
"null",
",",
"true",
")",
";",
"constructed",
"=",
"false",
";",
"doConstruct",
"(",
")",
";",
"}",
"if",
"(",
"keyCode",
"==",
"Keyboard",
".",
"KEY_D",
")",
"{",
"debug",
"=",
"!",
"debug",
";",
"debugComponent",
".",
"setEnabled",
"(",
"debug",
")",
";",
"}",
"if",
"(",
"keyCode",
"==",
"Keyboard",
".",
"KEY_P",
")",
"{",
"Position",
".",
"CACHED",
"=",
"!",
"Position",
".",
"CACHED",
";",
"}",
"if",
"(",
"keyCode",
"==",
"Keyboard",
".",
"KEY_S",
")",
"{",
"Size",
".",
"CACHED",
"=",
"!",
"Size",
".",
"CACHED",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"MalisisCore",
".",
"message",
"(",
"\"A problem occured while handling key typed for \"",
"+",
"e",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
"+",
"\": \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"e",
".",
"printStackTrace",
"(",
"new",
"PrintStream",
"(",
"new",
"FileOutputStream",
"(",
"FileDescriptor",
".",
"out",
")",
")",
")",
";",
"}",
"}"
] | Called when a key is pressed on the keyboard. | [
"Called",
"when",
"a",
"key",
"is",
"pressed",
"on",
"the",
"keyboard",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/MalisisGui.java#L513-L566 |
2,843 | Ordinastie/MalisisCore | src/main/java/net/malisis/core/client/gui/MalisisGui.java | MalisisGui.sendAction | public static void sendAction(ActionType action, MalisisSlot slot, int code)
{
if (action == null || current() == null || current().inventoryContainer == null)
return;
int inventoryId = slot != null ? slot.getInventoryId() : 0;
int slotNumber = slot != null ? slot.getSlotIndex() : 0;
current().inventoryContainer.handleAction(action, inventoryId, slotNumber, code);
InventoryActionMessage.sendAction(action, inventoryId, slotNumber, code);
} | java | public static void sendAction(ActionType action, MalisisSlot slot, int code)
{
if (action == null || current() == null || current().inventoryContainer == null)
return;
int inventoryId = slot != null ? slot.getInventoryId() : 0;
int slotNumber = slot != null ? slot.getSlotIndex() : 0;
current().inventoryContainer.handleAction(action, inventoryId, slotNumber, code);
InventoryActionMessage.sendAction(action, inventoryId, slotNumber, code);
} | [
"public",
"static",
"void",
"sendAction",
"(",
"ActionType",
"action",
",",
"MalisisSlot",
"slot",
",",
"int",
"code",
")",
"{",
"if",
"(",
"action",
"==",
"null",
"||",
"current",
"(",
")",
"==",
"null",
"||",
"current",
"(",
")",
".",
"inventoryContainer",
"==",
"null",
")",
"return",
";",
"int",
"inventoryId",
"=",
"slot",
"!=",
"null",
"?",
"slot",
".",
"getInventoryId",
"(",
")",
":",
"0",
";",
"int",
"slotNumber",
"=",
"slot",
"!=",
"null",
"?",
"slot",
".",
"getSlotIndex",
"(",
")",
":",
"0",
";",
"current",
"(",
")",
".",
"inventoryContainer",
".",
"handleAction",
"(",
"action",
",",
"inventoryId",
",",
"slotNumber",
",",
"code",
")",
";",
"InventoryActionMessage",
".",
"sendAction",
"(",
"action",
",",
"inventoryId",
",",
"slotNumber",
",",
"code",
")",
";",
"}"
] | Sends a GUI action to the server.
@param action the action
@param slot the slot
@param code the keyboard code | [
"Sends",
"a",
"GUI",
"action",
"to",
"the",
"server",
"."
] | 4f8e1fa462d5c372fc23414482ba9f429881cc54 | https://github.com/Ordinastie/MalisisCore/blob/4f8e1fa462d5c372fc23414482ba9f429881cc54/src/main/java/net/malisis/core/client/gui/MalisisGui.java#L773-L783 |
2,844 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/MultigetSliceIterator.java | MultigetSliceIterator.runQuery | private void runQuery() {
if(this.rowKeysList != null && this.rowKeysList.size() > 0) { // Check if there are rowkeys to query Cassandra
if (threadCount > 1) { // When thread count greater than 1 enables parallelism, use threads to query Cassandra
// multiple times
ExecutorService executor = Executors
.newFixedThreadPool(threadCount);
List<Future<?>> futures = new LinkedList<Future<?>>();
for (final List<K> param : this.rowKeysList) {
Future<?> future = executor.submit(new Runnable() {
public void run() {
// Query Cassandra with the input keys provided
runMultigetSliceQuery(param);
}
});
futures.add(future);
}
for (Future<?> f : futures) {// iterate through thread results
try {
f.get(); // wait for thread to complete
} catch (InterruptedException e) {
throw new HectorException("Failed to retrieve rows from Cassandra.",e);
}
catch (ExecutionException e) {
throw new HectorException("Failed to retrieve rows from Cassandra.",e);
}
}
// Safe to shutdown the threadpool and release the resources
executor.shutdown();
// set the rowKeysIndex to size of input keys so as no further calls
// will be made to Cassandra.
// This ensures iterator.hasNext() returns false when all keys are
// queried
rowKeysIndex = this.rowKeysList.size();
}
else {// When thread count less than or equal to 1 (0 or negative) disables
// parallelism, set of(maxRowCountPerQuery) keys queries
// Cassandra at a time
runMultigetSliceQuery(this.rowKeysList.get(rowKeysIndex));
// Increment the rowKeyIndex instead of setting it to this.rowKeysList.size();
rowKeysIndex++;
}
}
ArrayList<Row<K, N, V>> resultList = new ArrayList<Row<K, N, V>>(queryResult.size());
synchronized (queryResult) {
// Ensure that runMultigetSliceQuery() method call updates global
// variable queryResult with query result (if exists)
if (queryResult != null && queryResult.size() > 0) {
for (Rows<K, N, V> rows : queryResult) {
if (rows != null && rows.getCount() > 0) {
for (Row<K, N, V> row : rows) {
// prepare List<Row<K, N, V>> to return
// the iterator of <Row<K,N,V>> to the caller
resultList.add(row);
}
}
}
}
}
// assign global iterator with the result of multigetSliceQuery
iterator = resultList.iterator();
} | java | private void runQuery() {
if(this.rowKeysList != null && this.rowKeysList.size() > 0) { // Check if there are rowkeys to query Cassandra
if (threadCount > 1) { // When thread count greater than 1 enables parallelism, use threads to query Cassandra
// multiple times
ExecutorService executor = Executors
.newFixedThreadPool(threadCount);
List<Future<?>> futures = new LinkedList<Future<?>>();
for (final List<K> param : this.rowKeysList) {
Future<?> future = executor.submit(new Runnable() {
public void run() {
// Query Cassandra with the input keys provided
runMultigetSliceQuery(param);
}
});
futures.add(future);
}
for (Future<?> f : futures) {// iterate through thread results
try {
f.get(); // wait for thread to complete
} catch (InterruptedException e) {
throw new HectorException("Failed to retrieve rows from Cassandra.",e);
}
catch (ExecutionException e) {
throw new HectorException("Failed to retrieve rows from Cassandra.",e);
}
}
// Safe to shutdown the threadpool and release the resources
executor.shutdown();
// set the rowKeysIndex to size of input keys so as no further calls
// will be made to Cassandra.
// This ensures iterator.hasNext() returns false when all keys are
// queried
rowKeysIndex = this.rowKeysList.size();
}
else {// When thread count less than or equal to 1 (0 or negative) disables
// parallelism, set of(maxRowCountPerQuery) keys queries
// Cassandra at a time
runMultigetSliceQuery(this.rowKeysList.get(rowKeysIndex));
// Increment the rowKeyIndex instead of setting it to this.rowKeysList.size();
rowKeysIndex++;
}
}
ArrayList<Row<K, N, V>> resultList = new ArrayList<Row<K, N, V>>(queryResult.size());
synchronized (queryResult) {
// Ensure that runMultigetSliceQuery() method call updates global
// variable queryResult with query result (if exists)
if (queryResult != null && queryResult.size() > 0) {
for (Rows<K, N, V> rows : queryResult) {
if (rows != null && rows.getCount() > 0) {
for (Row<K, N, V> row : rows) {
// prepare List<Row<K, N, V>> to return
// the iterator of <Row<K,N,V>> to the caller
resultList.add(row);
}
}
}
}
}
// assign global iterator with the result of multigetSliceQuery
iterator = resultList.iterator();
} | [
"private",
"void",
"runQuery",
"(",
")",
"{",
"if",
"(",
"this",
".",
"rowKeysList",
"!=",
"null",
"&&",
"this",
".",
"rowKeysList",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"// Check if there are rowkeys to query Cassandra",
"if",
"(",
"threadCount",
">",
"1",
")",
"{",
"// When thread count greater than 1 enables parallelism, use threads to query Cassandra",
"// multiple times",
"ExecutorService",
"executor",
"=",
"Executors",
".",
"newFixedThreadPool",
"(",
"threadCount",
")",
";",
"List",
"<",
"Future",
"<",
"?",
">",
">",
"futures",
"=",
"new",
"LinkedList",
"<",
"Future",
"<",
"?",
">",
">",
"(",
")",
";",
"for",
"(",
"final",
"List",
"<",
"K",
">",
"param",
":",
"this",
".",
"rowKeysList",
")",
"{",
"Future",
"<",
"?",
">",
"future",
"=",
"executor",
".",
"submit",
"(",
"new",
"Runnable",
"(",
")",
"{",
"public",
"void",
"run",
"(",
")",
"{",
"// Query Cassandra with the input keys provided",
"runMultigetSliceQuery",
"(",
"param",
")",
";",
"}",
"}",
")",
";",
"futures",
".",
"add",
"(",
"future",
")",
";",
"}",
"for",
"(",
"Future",
"<",
"?",
">",
"f",
":",
"futures",
")",
"{",
"// iterate through thread results",
"try",
"{",
"f",
".",
"get",
"(",
")",
";",
"// wait for thread to complete",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"throw",
"new",
"HectorException",
"(",
"\"Failed to retrieve rows from Cassandra.\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"ExecutionException",
"e",
")",
"{",
"throw",
"new",
"HectorException",
"(",
"\"Failed to retrieve rows from Cassandra.\"",
",",
"e",
")",
";",
"}",
"}",
"// Safe to shutdown the threadpool and release the resources",
"executor",
".",
"shutdown",
"(",
")",
";",
"// set the rowKeysIndex to size of input keys so as no further calls",
"// will be made to Cassandra.",
"// This ensures iterator.hasNext() returns false when all keys are",
"// queried",
"rowKeysIndex",
"=",
"this",
".",
"rowKeysList",
".",
"size",
"(",
")",
";",
"}",
"else",
"{",
"// When thread count less than or equal to 1 (0 or negative) disables",
"// parallelism, set of(maxRowCountPerQuery) keys queries",
"// Cassandra at a time",
"runMultigetSliceQuery",
"(",
"this",
".",
"rowKeysList",
".",
"get",
"(",
"rowKeysIndex",
")",
")",
";",
"// Increment the rowKeyIndex instead of setting it to this.rowKeysList.size(); ",
"rowKeysIndex",
"++",
";",
"}",
"}",
"ArrayList",
"<",
"Row",
"<",
"K",
",",
"N",
",",
"V",
">",
">",
"resultList",
"=",
"new",
"ArrayList",
"<",
"Row",
"<",
"K",
",",
"N",
",",
"V",
">",
">",
"(",
"queryResult",
".",
"size",
"(",
")",
")",
";",
"synchronized",
"(",
"queryResult",
")",
"{",
"// Ensure that runMultigetSliceQuery() method call updates global",
"// variable queryResult with query result (if exists)",
"if",
"(",
"queryResult",
"!=",
"null",
"&&",
"queryResult",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"for",
"(",
"Rows",
"<",
"K",
",",
"N",
",",
"V",
">",
"rows",
":",
"queryResult",
")",
"{",
"if",
"(",
"rows",
"!=",
"null",
"&&",
"rows",
".",
"getCount",
"(",
")",
">",
"0",
")",
"{",
"for",
"(",
"Row",
"<",
"K",
",",
"N",
",",
"V",
">",
"row",
":",
"rows",
")",
"{",
"// prepare List<Row<K, N, V>> to return",
"// the iterator of <Row<K,N,V>> to the caller",
"resultList",
".",
"add",
"(",
"row",
")",
";",
"}",
"}",
"}",
"}",
"}",
"// assign global iterator with the result of multigetSliceQuery",
"iterator",
"=",
"resultList",
".",
"iterator",
"(",
")",
";",
"}"
] | This method prepares keys for execution, determines whether to use
parallelism or not to query Cassandra, executes the query and collects the result | [
"This",
"method",
"prepares",
"keys",
"for",
"execution",
"determines",
"whether",
"to",
"use",
"parallelism",
"or",
"not",
"to",
"query",
"Cassandra",
"executes",
"the",
"query",
"and",
"collects",
"the",
"result"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/MultigetSliceIterator.java#L333-L409 |
2,845 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/MultigetSliceIterator.java | MultigetSliceIterator.prepareKeysForParallelism | private List<List<K>> prepareKeysForParallelism() {
// Calculate the number of row keys to be queried at a time.
// Consider whether parallelism is enabled or not.
// When numThreads is calculated, the int truncation
// causes one fewer thread to be used if numKeys isn't evenly divided
// into maxRowCountPerQuery. Thus,
// the keys are divided among threads/ calls evenly with each thread
// getting up to maxRowCountPerQuery
List<List<K>> returnKeys = new LinkedList<List<K>>();
int numKeys = rowKeys.size();
// Calculate how many thread are required based on input # keys and each
// time rowkeys limit of maxRowCountPerQuery
int numThreads = 1;
if(maxRowCountPerQuery>0){
numThreads=(int) Math.ceil((numKeys / (double) maxRowCountPerQuery));
numThreads= Math.max(numThreads, 1);
}
// if number of threads required is more than the maximum limit of
// allowable threads then cap the number of threads
threadCount=Math.min(numThreads, maxThreads);
// We get the ceiling of numKeys/numThreads in order to spread out the
// row keys evenly.
// e.g. if numKeys=101 and maxRowCountPerQuery=50, it makes set of 34
// keys to be queried at a time. numThreads= Ceil(101/50)=>3
numKeysPerThread = (int) Math
.ceil(numKeys / (double) numThreads);
// Default it to 1, so that all keys will be passed once, instead of breaking it
numKeysPerThread=Math.max(numKeysPerThread, 1);
//Check if there are any rowkeys
if(this.rowKeys!=null && this.rowKeys.size()>0) {
// split keys into subsets based on the above calculation
returnKeys = Lists.partition(rowKeys, numKeysPerThread);
}
return returnKeys;
} | java | private List<List<K>> prepareKeysForParallelism() {
// Calculate the number of row keys to be queried at a time.
// Consider whether parallelism is enabled or not.
// When numThreads is calculated, the int truncation
// causes one fewer thread to be used if numKeys isn't evenly divided
// into maxRowCountPerQuery. Thus,
// the keys are divided among threads/ calls evenly with each thread
// getting up to maxRowCountPerQuery
List<List<K>> returnKeys = new LinkedList<List<K>>();
int numKeys = rowKeys.size();
// Calculate how many thread are required based on input # keys and each
// time rowkeys limit of maxRowCountPerQuery
int numThreads = 1;
if(maxRowCountPerQuery>0){
numThreads=(int) Math.ceil((numKeys / (double) maxRowCountPerQuery));
numThreads= Math.max(numThreads, 1);
}
// if number of threads required is more than the maximum limit of
// allowable threads then cap the number of threads
threadCount=Math.min(numThreads, maxThreads);
// We get the ceiling of numKeys/numThreads in order to spread out the
// row keys evenly.
// e.g. if numKeys=101 and maxRowCountPerQuery=50, it makes set of 34
// keys to be queried at a time. numThreads= Ceil(101/50)=>3
numKeysPerThread = (int) Math
.ceil(numKeys / (double) numThreads);
// Default it to 1, so that all keys will be passed once, instead of breaking it
numKeysPerThread=Math.max(numKeysPerThread, 1);
//Check if there are any rowkeys
if(this.rowKeys!=null && this.rowKeys.size()>0) {
// split keys into subsets based on the above calculation
returnKeys = Lists.partition(rowKeys, numKeysPerThread);
}
return returnKeys;
} | [
"private",
"List",
"<",
"List",
"<",
"K",
">",
">",
"prepareKeysForParallelism",
"(",
")",
"{",
"// Calculate the number of row keys to be queried at a time.",
"// Consider whether parallelism is enabled or not.",
"// When numThreads is calculated, the int truncation",
"// causes one fewer thread to be used if numKeys isn't evenly divided",
"// into maxRowCountPerQuery. Thus,",
"// the keys are divided among threads/ calls evenly with each thread",
"// getting up to maxRowCountPerQuery",
"List",
"<",
"List",
"<",
"K",
">>",
"returnKeys",
"=",
"new",
"LinkedList",
"<",
"List",
"<",
"K",
">",
">",
"(",
")",
";",
"int",
"numKeys",
"=",
"rowKeys",
".",
"size",
"(",
")",
";",
"// Calculate how many thread are required based on input # keys and each",
"// time rowkeys limit of maxRowCountPerQuery",
"int",
"numThreads",
"=",
"1",
";",
"if",
"(",
"maxRowCountPerQuery",
">",
"0",
")",
"{",
"numThreads",
"=",
"(",
"int",
")",
"Math",
".",
"ceil",
"(",
"(",
"numKeys",
"/",
"(",
"double",
")",
"maxRowCountPerQuery",
")",
")",
";",
"numThreads",
"=",
"Math",
".",
"max",
"(",
"numThreads",
",",
"1",
")",
";",
"}",
"// if number of threads required is more than the maximum limit of",
"// allowable threads then cap the number of threads",
"threadCount",
"=",
"Math",
".",
"min",
"(",
"numThreads",
",",
"maxThreads",
")",
";",
"// We get the ceiling of numKeys/numThreads in order to spread out the",
"// row keys evenly.",
"// e.g. if numKeys=101 and maxRowCountPerQuery=50, it makes set of 34",
"// keys to be queried at a time. numThreads= Ceil(101/50)=>3",
"numKeysPerThread",
"=",
"(",
"int",
")",
"Math",
".",
"ceil",
"(",
"numKeys",
"/",
"(",
"double",
")",
"numThreads",
")",
";",
"// Default it to 1, so that all keys will be passed once, instead of breaking it",
"numKeysPerThread",
"=",
"Math",
".",
"max",
"(",
"numKeysPerThread",
",",
"1",
")",
";",
"//Check if there are any rowkeys ",
"if",
"(",
"this",
".",
"rowKeys",
"!=",
"null",
"&&",
"this",
".",
"rowKeys",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"// split keys into subsets based on the above calculation",
"returnKeys",
"=",
"Lists",
".",
"partition",
"(",
"rowKeys",
",",
"numKeysPerThread",
")",
";",
"}",
"return",
"returnKeys",
";",
"}"
] | prepare row Keys For Parallelism by considering maxRowCountPerQuery,
m_maxThreads and numKeys
@param m_maxThreads
@return | [
"prepare",
"row",
"Keys",
"For",
"Parallelism",
"by",
"considering",
"maxRowCountPerQuery",
"m_maxThreads",
"and",
"numKeys"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/MultigetSliceIterator.java#L537-L583 |
2,846 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/utils/ByteBufferOutputStream.java | ByteBufferOutputStream.write | public void write(ByteBuffer buffer) {
if (buffer.remaining() < 8196) {
write(buffer.array(), buffer.arrayOffset() + buffer.position(),
buffer.remaining());
} else { // append w/o copying bytes
ByteBuffer dup = buffer.duplicate();
dup.position(buffer.limit()); // ready for flip
buffers.add(dup);
}
} | java | public void write(ByteBuffer buffer) {
if (buffer.remaining() < 8196) {
write(buffer.array(), buffer.arrayOffset() + buffer.position(),
buffer.remaining());
} else { // append w/o copying bytes
ByteBuffer dup = buffer.duplicate();
dup.position(buffer.limit()); // ready for flip
buffers.add(dup);
}
} | [
"public",
"void",
"write",
"(",
"ByteBuffer",
"buffer",
")",
"{",
"if",
"(",
"buffer",
".",
"remaining",
"(",
")",
"<",
"8196",
")",
"{",
"write",
"(",
"buffer",
".",
"array",
"(",
")",
",",
"buffer",
".",
"arrayOffset",
"(",
")",
"+",
"buffer",
".",
"position",
"(",
")",
",",
"buffer",
".",
"remaining",
"(",
")",
")",
";",
"}",
"else",
"{",
"// append w/o copying bytes",
"ByteBuffer",
"dup",
"=",
"buffer",
".",
"duplicate",
"(",
")",
";",
"dup",
".",
"position",
"(",
"buffer",
".",
"limit",
"(",
")",
")",
";",
"// ready for flip",
"buffers",
".",
"add",
"(",
"dup",
")",
";",
"}",
"}"
] | Add a buffer to the output without copying, if possible. | [
"Add",
"a",
"buffer",
"to",
"the",
"output",
"without",
"copying",
"if",
"possible",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/utils/ByteBufferOutputStream.java#L166-L175 |
2,847 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfUpdater.java | SuperCfUpdater.updateInternal | void updateInternal() {
// HSuperColumnImpl needs a refactor, this construction is lame.
// the value serializer is not used in HSuperColumnImpl, so this is safe for name
if ( !subColumns.isEmpty() ) {
log.debug("Adding column {} for key {} and cols {}", new Object[]{getCurrentSuperColumn(), getCurrentKey(), subColumns});
HSuperColumnImpl<SN, N, ?> column = new HSuperColumnImpl(getCurrentSuperColumn(), subColumns,
0, template.getTopSerializer(), template.getSubSerializer(), TypeInferringSerializer.get());
mutator.addInsertion(getCurrentKey(), template.getColumnFamily(), column);
}
} | java | void updateInternal() {
// HSuperColumnImpl needs a refactor, this construction is lame.
// the value serializer is not used in HSuperColumnImpl, so this is safe for name
if ( !subColumns.isEmpty() ) {
log.debug("Adding column {} for key {} and cols {}", new Object[]{getCurrentSuperColumn(), getCurrentKey(), subColumns});
HSuperColumnImpl<SN, N, ?> column = new HSuperColumnImpl(getCurrentSuperColumn(), subColumns,
0, template.getTopSerializer(), template.getSubSerializer(), TypeInferringSerializer.get());
mutator.addInsertion(getCurrentKey(), template.getColumnFamily(), column);
}
} | [
"void",
"updateInternal",
"(",
")",
"{",
"// HSuperColumnImpl needs a refactor, this construction is lame.",
"// the value serializer is not used in HSuperColumnImpl, so this is safe for name",
"if",
"(",
"!",
"subColumns",
".",
"isEmpty",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Adding column {} for key {} and cols {}\"",
",",
"new",
"Object",
"[",
"]",
"{",
"getCurrentSuperColumn",
"(",
")",
",",
"getCurrentKey",
"(",
")",
",",
"subColumns",
"}",
")",
";",
"HSuperColumnImpl",
"<",
"SN",
",",
"N",
",",
"?",
">",
"column",
"=",
"new",
"HSuperColumnImpl",
"(",
"getCurrentSuperColumn",
"(",
")",
",",
"subColumns",
",",
"0",
",",
"template",
".",
"getTopSerializer",
"(",
")",
",",
"template",
".",
"getSubSerializer",
"(",
")",
",",
"TypeInferringSerializer",
".",
"get",
"(",
")",
")",
";",
"mutator",
".",
"addInsertion",
"(",
"getCurrentKey",
"(",
")",
",",
"template",
".",
"getColumnFamily",
"(",
")",
",",
"column",
")",
";",
"}",
"}"
] | collapse the state of the active HSuperColumn | [
"collapse",
"the",
"state",
"of",
"the",
"active",
"HSuperColumn"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfUpdater.java#L105-L115 |
2,848 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/HectorObjectMapper.java | HectorObjectMapper.getObject | public <T, I> T getObject(Keyspace keyspace, String colFamName, I pkObj) {
if (null == pkObj) {
throw new IllegalArgumentException("object ID cannot be null or empty");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(colFamName, true);
byte[] colFamKey = generateColumnFamilyKeyFromPkObj(cfMapDef, pkObj);
SliceQuery<byte[], String, byte[]> q = HFactory.createSliceQuery(keyspace,
BytesArraySerializer.get(), StringSerializer.get(), BytesArraySerializer.get());
q.setColumnFamily(colFamName);
q.setKey(colFamKey);
// if no anonymous handler then use specific columns
if (cfMapDef.isColumnSliceRequired()) {
q.setColumnNames(cfMapDef.getSliceColumnNameArr());
} else {
q.setRange("", "", false, maxNumColumns);
}
QueryResult<ColumnSlice<String, byte[]>> result = q.execute();
if (null == result || null == result.get()) {
return null;
}
T obj = createObject(cfMapDef, pkObj, result.get());
return obj;
} | java | public <T, I> T getObject(Keyspace keyspace, String colFamName, I pkObj) {
if (null == pkObj) {
throw new IllegalArgumentException("object ID cannot be null or empty");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(colFamName, true);
byte[] colFamKey = generateColumnFamilyKeyFromPkObj(cfMapDef, pkObj);
SliceQuery<byte[], String, byte[]> q = HFactory.createSliceQuery(keyspace,
BytesArraySerializer.get(), StringSerializer.get(), BytesArraySerializer.get());
q.setColumnFamily(colFamName);
q.setKey(colFamKey);
// if no anonymous handler then use specific columns
if (cfMapDef.isColumnSliceRequired()) {
q.setColumnNames(cfMapDef.getSliceColumnNameArr());
} else {
q.setRange("", "", false, maxNumColumns);
}
QueryResult<ColumnSlice<String, byte[]>> result = q.execute();
if (null == result || null == result.get()) {
return null;
}
T obj = createObject(cfMapDef, pkObj, result.get());
return obj;
} | [
"public",
"<",
"T",
",",
"I",
">",
"T",
"getObject",
"(",
"Keyspace",
"keyspace",
",",
"String",
"colFamName",
",",
"I",
"pkObj",
")",
"{",
"if",
"(",
"null",
"==",
"pkObj",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"object ID cannot be null or empty\"",
")",
";",
"}",
"CFMappingDef",
"<",
"T",
">",
"cfMapDef",
"=",
"cacheMgr",
".",
"getCfMapDef",
"(",
"colFamName",
",",
"true",
")",
";",
"byte",
"[",
"]",
"colFamKey",
"=",
"generateColumnFamilyKeyFromPkObj",
"(",
"cfMapDef",
",",
"pkObj",
")",
";",
"SliceQuery",
"<",
"byte",
"[",
"]",
",",
"String",
",",
"byte",
"[",
"]",
">",
"q",
"=",
"HFactory",
".",
"createSliceQuery",
"(",
"keyspace",
",",
"BytesArraySerializer",
".",
"get",
"(",
")",
",",
"StringSerializer",
".",
"get",
"(",
")",
",",
"BytesArraySerializer",
".",
"get",
"(",
")",
")",
";",
"q",
".",
"setColumnFamily",
"(",
"colFamName",
")",
";",
"q",
".",
"setKey",
"(",
"colFamKey",
")",
";",
"// if no anonymous handler then use specific columns",
"if",
"(",
"cfMapDef",
".",
"isColumnSliceRequired",
"(",
")",
")",
"{",
"q",
".",
"setColumnNames",
"(",
"cfMapDef",
".",
"getSliceColumnNameArr",
"(",
")",
")",
";",
"}",
"else",
"{",
"q",
".",
"setRange",
"(",
"\"\"",
",",
"\"\"",
",",
"false",
",",
"maxNumColumns",
")",
";",
"}",
"QueryResult",
"<",
"ColumnSlice",
"<",
"String",
",",
"byte",
"[",
"]",
">",
">",
"result",
"=",
"q",
".",
"execute",
"(",
")",
";",
"if",
"(",
"null",
"==",
"result",
"||",
"null",
"==",
"result",
".",
"get",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"T",
"obj",
"=",
"createObject",
"(",
"cfMapDef",
",",
"pkObj",
",",
"result",
".",
"get",
"(",
")",
")",
";",
"return",
"obj",
";",
"}"
] | Retrieve columns from cassandra keyspace and column family, instantiate a
new object of required type, and then map them to the object's properties.
@param <T>
@param keyspace
@param colFamName
@param pkObj
@return | [
"Retrieve",
"columns",
"from",
"cassandra",
"keyspace",
"and",
"column",
"family",
"instantiate",
"a",
"new",
"object",
"of",
"required",
"type",
"and",
"then",
"map",
"them",
"to",
"the",
"object",
"s",
"properties",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/HectorObjectMapper.java#L79-L107 |
2,849 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/security/KerberosHelper.java | KerberosHelper.loginService | public static Subject loginService(String serviceName) throws LoginException {
LoginContext loginCtx = new LoginContext(serviceName, new CallbackHandler() {
// as we use .keytab file there is no need to specify any options in callback
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
}
});
loginCtx.login();
return loginCtx.getSubject();
} | java | public static Subject loginService(String serviceName) throws LoginException {
LoginContext loginCtx = new LoginContext(serviceName, new CallbackHandler() {
// as we use .keytab file there is no need to specify any options in callback
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
}
});
loginCtx.login();
return loginCtx.getSubject();
} | [
"public",
"static",
"Subject",
"loginService",
"(",
"String",
"serviceName",
")",
"throws",
"LoginException",
"{",
"LoginContext",
"loginCtx",
"=",
"new",
"LoginContext",
"(",
"serviceName",
",",
"new",
"CallbackHandler",
"(",
")",
"{",
"// as we use .keytab file there is no need to specify any options in callback",
"public",
"void",
"handle",
"(",
"Callback",
"[",
"]",
"callbacks",
")",
"throws",
"IOException",
",",
"UnsupportedCallbackException",
"{",
"}",
"}",
")",
";",
"loginCtx",
".",
"login",
"(",
")",
";",
"return",
"loginCtx",
".",
"getSubject",
"(",
")",
";",
"}"
] | Log in using the service name for jaas.conf file and .keytab instead of specifying username and password
@param serviceName service name defined in jass.conf file
@return the authenticated Subject or <code>null</code> is the authentication failed
@throws LoginException if there is any error during the login | [
"Log",
"in",
"using",
"the",
"service",
"name",
"for",
"jaas",
".",
"conf",
"file",
"and",
".",
"keytab",
"instead",
"of",
"specifying",
"username",
"and",
"password"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/security/KerberosHelper.java#L34-L44 |
2,850 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/security/KerberosHelper.java | KerberosHelper.authenticateClient | public static GSSContext authenticateClient(final Socket socket, Subject subject, final String servicePrincipalName) {
return Subject.doAs(subject, new PrivilegedAction<GSSContext>() {
public GSSContext run() {
try {
GSSManager manager = GSSManager.getInstance();
GSSName peerName = manager.createName(servicePrincipalName, GSSName.NT_HOSTBASED_SERVICE);
GSSContext context = manager.createContext(peerName, null, null, GSSContext.DEFAULT_LIFETIME);
// Loop while the context is still not established
while (!context.isEstablished()) {
context.initSecContext(socket.getInputStream(), socket.getOutputStream());
}
return context;
} catch (Exception e) {
log.error("Unable to authenticate client against Kerberos", e);
return null;
}
}
});
} | java | public static GSSContext authenticateClient(final Socket socket, Subject subject, final String servicePrincipalName) {
return Subject.doAs(subject, new PrivilegedAction<GSSContext>() {
public GSSContext run() {
try {
GSSManager manager = GSSManager.getInstance();
GSSName peerName = manager.createName(servicePrincipalName, GSSName.NT_HOSTBASED_SERVICE);
GSSContext context = manager.createContext(peerName, null, null, GSSContext.DEFAULT_LIFETIME);
// Loop while the context is still not established
while (!context.isEstablished()) {
context.initSecContext(socket.getInputStream(), socket.getOutputStream());
}
return context;
} catch (Exception e) {
log.error("Unable to authenticate client against Kerberos", e);
return null;
}
}
});
} | [
"public",
"static",
"GSSContext",
"authenticateClient",
"(",
"final",
"Socket",
"socket",
",",
"Subject",
"subject",
",",
"final",
"String",
"servicePrincipalName",
")",
"{",
"return",
"Subject",
".",
"doAs",
"(",
"subject",
",",
"new",
"PrivilegedAction",
"<",
"GSSContext",
">",
"(",
")",
"{",
"public",
"GSSContext",
"run",
"(",
")",
"{",
"try",
"{",
"GSSManager",
"manager",
"=",
"GSSManager",
".",
"getInstance",
"(",
")",
";",
"GSSName",
"peerName",
"=",
"manager",
".",
"createName",
"(",
"servicePrincipalName",
",",
"GSSName",
".",
"NT_HOSTBASED_SERVICE",
")",
";",
"GSSContext",
"context",
"=",
"manager",
".",
"createContext",
"(",
"peerName",
",",
"null",
",",
"null",
",",
"GSSContext",
".",
"DEFAULT_LIFETIME",
")",
";",
"// Loop while the context is still not established",
"while",
"(",
"!",
"context",
".",
"isEstablished",
"(",
")",
")",
"{",
"context",
".",
"initSecContext",
"(",
"socket",
".",
"getInputStream",
"(",
")",
",",
"socket",
".",
"getOutputStream",
"(",
")",
")",
";",
"}",
"return",
"context",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Unable to authenticate client against Kerberos\"",
",",
"e",
")",
";",
"return",
"null",
";",
"}",
"}",
"}",
")",
";",
"}"
] | Authenticate client to use this service and return secure context
@param socket
The socket used for communication
@param subject
The Kerberos service subject
@param servicePrincipalName
Service principal name
@return context if authorized or null | [
"Authenticate",
"client",
"to",
"use",
"this",
"service",
"and",
"return",
"secure",
"context"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/security/KerberosHelper.java#L72-L92 |
2,851 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/BatchMutation.java | BatchMutation.addDeletion | public BatchMutation<K> addDeletion(K key, List<String> columnFamilies, Deletion deletion) {
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
addMutation(key, columnFamilies, mutation);
return this;
} | java | public BatchMutation<K> addDeletion(K key, List<String> columnFamilies, Deletion deletion) {
Mutation mutation = new Mutation();
mutation.setDeletion(deletion);
addMutation(key, columnFamilies, mutation);
return this;
} | [
"public",
"BatchMutation",
"<",
"K",
">",
"addDeletion",
"(",
"K",
"key",
",",
"List",
"<",
"String",
">",
"columnFamilies",
",",
"Deletion",
"deletion",
")",
"{",
"Mutation",
"mutation",
"=",
"new",
"Mutation",
"(",
")",
";",
"mutation",
".",
"setDeletion",
"(",
"deletion",
")",
";",
"addMutation",
"(",
"key",
",",
"columnFamilies",
",",
"mutation",
")",
";",
"return",
"this",
";",
"}"
] | Add a deletion request to the batch mutation. | [
"Add",
"a",
"deletion",
"request",
"to",
"the",
"batch",
"mutation",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/BatchMutation.java#L105-L110 |
2,852 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java | SuperCfTemplate.countColumns | public int countColumns(K key, SN start, SN end, int max) {
SuperCountQuery<K, SN> query = HFactory.createSuperCountQuery(keyspace,
keySerializer, topSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setRange(start, end, max);
return query.execute().get();
} | java | public int countColumns(K key, SN start, SN end, int max) {
SuperCountQuery<K, SN> query = HFactory.createSuperCountQuery(keyspace,
keySerializer, topSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setRange(start, end, max);
return query.execute().get();
} | [
"public",
"int",
"countColumns",
"(",
"K",
"key",
",",
"SN",
"start",
",",
"SN",
"end",
",",
"int",
"max",
")",
"{",
"SuperCountQuery",
"<",
"K",
",",
"SN",
">",
"query",
"=",
"HFactory",
".",
"createSuperCountQuery",
"(",
"keyspace",
",",
"keySerializer",
",",
"topSerializer",
")",
";",
"query",
".",
"setKey",
"(",
"key",
")",
";",
"query",
".",
"setColumnFamily",
"(",
"columnFamily",
")",
";",
"query",
".",
"setRange",
"(",
"start",
",",
"end",
",",
"max",
")",
";",
"return",
"query",
".",
"execute",
"(",
")",
".",
"get",
"(",
")",
";",
"}"
] | Counts columns in the specified range of a super column family
@param key
@param start
@param end
@param max
@return | [
"Counts",
"columns",
"in",
"the",
"specified",
"range",
"of",
"a",
"super",
"column",
"family"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java#L86-L93 |
2,853 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java | SuperCfTemplate.countSubColumns | public int countSubColumns(K key, SN superColumnName, N start,
N end, int max) {
SubCountQuery<K, SN, N> query = HFactory.createSubCountQuery(
keyspace, keySerializer, topSerializer, subSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setSuperColumn(superColumnName);
query.setRange(start, end, max);
return query.execute().get();
} | java | public int countSubColumns(K key, SN superColumnName, N start,
N end, int max) {
SubCountQuery<K, SN, N> query = HFactory.createSubCountQuery(
keyspace, keySerializer, topSerializer, subSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setSuperColumn(superColumnName);
query.setRange(start, end, max);
return query.execute().get();
} | [
"public",
"int",
"countSubColumns",
"(",
"K",
"key",
",",
"SN",
"superColumnName",
",",
"N",
"start",
",",
"N",
"end",
",",
"int",
"max",
")",
"{",
"SubCountQuery",
"<",
"K",
",",
"SN",
",",
"N",
">",
"query",
"=",
"HFactory",
".",
"createSubCountQuery",
"(",
"keyspace",
",",
"keySerializer",
",",
"topSerializer",
",",
"subSerializer",
")",
";",
"query",
".",
"setKey",
"(",
"key",
")",
";",
"query",
".",
"setColumnFamily",
"(",
"columnFamily",
")",
";",
"query",
".",
"setSuperColumn",
"(",
"superColumnName",
")",
";",
"query",
".",
"setRange",
"(",
"start",
",",
"end",
",",
"max",
")",
";",
"return",
"query",
".",
"execute",
"(",
")",
".",
"get",
"(",
")",
";",
"}"
] | Counts child columns in the specified range of a children in a specified
super column
@param key
@param superColumnName
@param start
@param end
@param max
@return | [
"Counts",
"child",
"columns",
"in",
"the",
"specified",
"range",
"of",
"a",
"children",
"in",
"a",
"specified",
"super",
"column"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java#L106-L115 |
2,854 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java | SuperCfTemplate.querySuperColumns | public SuperCfResult<K, SN, N> querySuperColumns(K key, HSlicePredicate<SN> predicate) {
return doExecuteSlice(key,null,predicate);
} | java | public SuperCfResult<K, SN, N> querySuperColumns(K key, HSlicePredicate<SN> predicate) {
return doExecuteSlice(key,null,predicate);
} | [
"public",
"SuperCfResult",
"<",
"K",
",",
"SN",
",",
"N",
">",
"querySuperColumns",
"(",
"K",
"key",
",",
"HSlicePredicate",
"<",
"SN",
">",
"predicate",
")",
"{",
"return",
"doExecuteSlice",
"(",
"key",
",",
"null",
",",
"predicate",
")",
";",
"}"
] | Query super columns using the provided predicate instead of the internal one
@param key
@param predicate
@return | [
"Query",
"super",
"columns",
"using",
"the",
"provided",
"predicate",
"instead",
"of",
"the",
"internal",
"one"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java#L146-L148 |
2,855 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java | SuperCfTemplate.deleteColumn | @Override
public void deleteColumn(K key, SN sColumnName) {
createMutator().superDelete(key, getColumnFamily(), sColumnName, topSerializer);
} | java | @Override
public void deleteColumn(K key, SN sColumnName) {
createMutator().superDelete(key, getColumnFamily(), sColumnName, topSerializer);
} | [
"@",
"Override",
"public",
"void",
"deleteColumn",
"(",
"K",
"key",
",",
"SN",
"sColumnName",
")",
"{",
"createMutator",
"(",
")",
".",
"superDelete",
"(",
"key",
",",
"getColumnFamily",
"(",
")",
",",
"sColumnName",
",",
"topSerializer",
")",
";",
"}"
] | Immediately delete the key and superColumn combination | [
"Immediately",
"delete",
"the",
"key",
"and",
"superColumn",
"combination"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java#L209-L212 |
2,856 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java | SuperCfTemplate.deleteRow | @Override
public void deleteRow(K key) {
createMutator().delete(key, getColumnFamily(), null, null);
} | java | @Override
public void deleteRow(K key) {
createMutator().delete(key, getColumnFamily(), null, null);
} | [
"@",
"Override",
"public",
"void",
"deleteRow",
"(",
"K",
"key",
")",
"{",
"createMutator",
"(",
")",
".",
"delete",
"(",
"key",
",",
"getColumnFamily",
"(",
")",
",",
"null",
",",
"null",
")",
";",
"}"
] | Immediately delete the row | [
"Immediately",
"delete",
"the",
"row"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/SuperCfTemplate.java#L217-L220 |
2,857 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java | ClassCacheMgr.getCfMapDef | public <T> CFMappingDef<T> getCfMapDef(String colFamName, boolean throwException) {
@SuppressWarnings("unchecked")
CFMappingDef<T> cfMapDef = (CFMappingDef<T>) cfMapByColFamName.get(colFamName);
if (null == cfMapDef && throwException) {
throw new HectorObjectMapperException(
"could not find property definitions for column family, "
+ colFamName
+ ", in class cache. This indicates the EntityManager was not initialized properly. If not using EntityManager the cache must be explicity initialized");
}
return cfMapDef;
} | java | public <T> CFMappingDef<T> getCfMapDef(String colFamName, boolean throwException) {
@SuppressWarnings("unchecked")
CFMappingDef<T> cfMapDef = (CFMappingDef<T>) cfMapByColFamName.get(colFamName);
if (null == cfMapDef && throwException) {
throw new HectorObjectMapperException(
"could not find property definitions for column family, "
+ colFamName
+ ", in class cache. This indicates the EntityManager was not initialized properly. If not using EntityManager the cache must be explicity initialized");
}
return cfMapDef;
} | [
"public",
"<",
"T",
">",
"CFMappingDef",
"<",
"T",
">",
"getCfMapDef",
"(",
"String",
"colFamName",
",",
"boolean",
"throwException",
")",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"CFMappingDef",
"<",
"T",
">",
"cfMapDef",
"=",
"(",
"CFMappingDef",
"<",
"T",
">",
")",
"cfMapByColFamName",
".",
"get",
"(",
"colFamName",
")",
";",
"if",
"(",
"null",
"==",
"cfMapDef",
"&&",
"throwException",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"\"could not find property definitions for column family, \"",
"+",
"colFamName",
"+",
"\", in class cache. This indicates the EntityManager was not initialized properly. If not using EntityManager the cache must be explicity initialized\"",
")",
";",
"}",
"return",
"cfMapDef",
";",
"}"
] | Retrieve class mapping meta-data by ColumnFamily name.
@param <T>
@param colFamName
@param throwException
@return CFMappingDef if found, exception if throwException = true, and null
otherwise | [
"Retrieve",
"class",
"mapping",
"meta",
"-",
"data",
"by",
"ColumnFamily",
"name",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java#L100-L111 |
2,858 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java | ClassCacheMgr.initializeCacheForClass | public <T> CFMappingDef<T> initializeCacheForClass(Class<T> clazz) {
CFMappingDef<T> cfMapDef = initializeColumnFamilyMapDef(clazz);
try {
initializePropertiesMapDef(cfMapDef);
} catch (IntrospectionException e) {
throw new HectorObjectMapperException(e);
} catch (InstantiationException e) {
throw new HectorObjectMapperException(e);
} catch (IllegalAccessException e) {
throw new HectorObjectMapperException(e);
}
// by the time we get here, all super classes and their annotations have
// been processed and validated, and all annotations for this class have
// been processed. what's left to do is validate this class, set super
// classes, and and set any defaults
checkMappingAndSetDefaults(cfMapDef);
// if this class is not a derived class, then map the ColumnFamily name
if (!cfMapDef.isDerivedEntity()) {
cfMapByColFamName.put(cfMapDef.getEffectiveColFamName(), cfMapDef);
}
// always map the parsed class to its ColumnFamily map definition
cfMapByClazz.put(cfMapDef.getRealClass(), cfMapDef);
return cfMapDef;
} | java | public <T> CFMappingDef<T> initializeCacheForClass(Class<T> clazz) {
CFMappingDef<T> cfMapDef = initializeColumnFamilyMapDef(clazz);
try {
initializePropertiesMapDef(cfMapDef);
} catch (IntrospectionException e) {
throw new HectorObjectMapperException(e);
} catch (InstantiationException e) {
throw new HectorObjectMapperException(e);
} catch (IllegalAccessException e) {
throw new HectorObjectMapperException(e);
}
// by the time we get here, all super classes and their annotations have
// been processed and validated, and all annotations for this class have
// been processed. what's left to do is validate this class, set super
// classes, and and set any defaults
checkMappingAndSetDefaults(cfMapDef);
// if this class is not a derived class, then map the ColumnFamily name
if (!cfMapDef.isDerivedEntity()) {
cfMapByColFamName.put(cfMapDef.getEffectiveColFamName(), cfMapDef);
}
// always map the parsed class to its ColumnFamily map definition
cfMapByClazz.put(cfMapDef.getRealClass(), cfMapDef);
return cfMapDef;
} | [
"public",
"<",
"T",
">",
"CFMappingDef",
"<",
"T",
">",
"initializeCacheForClass",
"(",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"CFMappingDef",
"<",
"T",
">",
"cfMapDef",
"=",
"initializeColumnFamilyMapDef",
"(",
"clazz",
")",
";",
"try",
"{",
"initializePropertiesMapDef",
"(",
"cfMapDef",
")",
";",
"}",
"catch",
"(",
"IntrospectionException",
"e",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"InstantiationException",
"e",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"e",
")",
";",
"}",
"// by the time we get here, all super classes and their annotations have",
"// been processed and validated, and all annotations for this class have",
"// been processed. what's left to do is validate this class, set super",
"// classes, and and set any defaults",
"checkMappingAndSetDefaults",
"(",
"cfMapDef",
")",
";",
"// if this class is not a derived class, then map the ColumnFamily name",
"if",
"(",
"!",
"cfMapDef",
".",
"isDerivedEntity",
"(",
")",
")",
"{",
"cfMapByColFamName",
".",
"put",
"(",
"cfMapDef",
".",
"getEffectiveColFamName",
"(",
")",
",",
"cfMapDef",
")",
";",
"}",
"// always map the parsed class to its ColumnFamily map definition",
"cfMapByClazz",
".",
"put",
"(",
"cfMapDef",
".",
"getRealClass",
"(",
")",
",",
"cfMapDef",
")",
";",
"return",
"cfMapDef",
";",
"}"
] | For each class that should be managed, this method must be called to parse
its annotations and derive its meta-data.
@param <T>
@param clazz
@return CFMapping describing the initialized class. | [
"For",
"each",
"class",
"that",
"should",
"be",
"managed",
"this",
"method",
"must",
"be",
"called",
"to",
"parse",
"its",
"annotations",
"and",
"derive",
"its",
"meta",
"-",
"data",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java#L122-L149 |
2,859 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java | ClassCacheMgr.findAnnotatedMethod | public Method findAnnotatedMethod(Class<?> clazz, Class<? extends Annotation> anno) {
for (Method meth : clazz.getMethods()) {
if (meth.isAnnotationPresent(anno)) {
return meth;
}
}
return null;
} | java | public Method findAnnotatedMethod(Class<?> clazz, Class<? extends Annotation> anno) {
for (Method meth : clazz.getMethods()) {
if (meth.isAnnotationPresent(anno)) {
return meth;
}
}
return null;
} | [
"public",
"Method",
"findAnnotatedMethod",
"(",
"Class",
"<",
"?",
">",
"clazz",
",",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"anno",
")",
"{",
"for",
"(",
"Method",
"meth",
":",
"clazz",
".",
"getMethods",
"(",
")",
")",
"{",
"if",
"(",
"meth",
".",
"isAnnotationPresent",
"(",
"anno",
")",
")",
"{",
"return",
"meth",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find method annotated with the given annotation.
@param clazz
@param anno
@return returns Method if found, null otherwise | [
"Find",
"method",
"annotated",
"with",
"the",
"given",
"annotation",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/ClassCacheMgr.java#L373-L380 |
2,860 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/ClearCounterRow.java | ClearCounterRow.clear | public void clear() {
Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval));
SliceCounterQuery<K, N> query = HFactory.createCounterSliceQuery(this.keyspace, this.keySerializer, this.nameSerializer).
setColumnFamily(this.cf).
setKey(this.rowKey);
SliceCounterIterator<K, N> iterator =
new SliceCounterIterator<K, N>(query, null, (N) null, false, this.count);
while(iterator.hasNext()) {
HCounterColumn<N> column = iterator.next();
mutator.incrementCounter(this.rowKey, this.cf, column.getName(), column.getValue() * -1);
}
mutator.execute();
} | java | public void clear() {
Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval));
SliceCounterQuery<K, N> query = HFactory.createCounterSliceQuery(this.keyspace, this.keySerializer, this.nameSerializer).
setColumnFamily(this.cf).
setKey(this.rowKey);
SliceCounterIterator<K, N> iterator =
new SliceCounterIterator<K, N>(query, null, (N) null, false, this.count);
while(iterator.hasNext()) {
HCounterColumn<N> column = iterator.next();
mutator.incrementCounter(this.rowKey, this.cf, column.getName(), column.getValue() * -1);
}
mutator.execute();
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"Mutator",
"<",
"K",
">",
"mutator",
"=",
"HFactory",
".",
"createMutator",
"(",
"this",
".",
"keyspace",
",",
"this",
".",
"keySerializer",
",",
"new",
"BatchSizeHint",
"(",
"1",
",",
"this",
".",
"mutateInterval",
")",
")",
";",
"SliceCounterQuery",
"<",
"K",
",",
"N",
">",
"query",
"=",
"HFactory",
".",
"createCounterSliceQuery",
"(",
"this",
".",
"keyspace",
",",
"this",
".",
"keySerializer",
",",
"this",
".",
"nameSerializer",
")",
".",
"setColumnFamily",
"(",
"this",
".",
"cf",
")",
".",
"setKey",
"(",
"this",
".",
"rowKey",
")",
";",
"SliceCounterIterator",
"<",
"K",
",",
"N",
">",
"iterator",
"=",
"new",
"SliceCounterIterator",
"<",
"K",
",",
"N",
">",
"(",
"query",
",",
"null",
",",
"(",
"N",
")",
"null",
",",
"false",
",",
"this",
".",
"count",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"HCounterColumn",
"<",
"N",
">",
"column",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"mutator",
".",
"incrementCounter",
"(",
"this",
".",
"rowKey",
",",
"this",
".",
"cf",
",",
"column",
".",
"getName",
"(",
")",
",",
"column",
".",
"getValue",
"(",
")",
"*",
"-",
"1",
")",
";",
"}",
"mutator",
".",
"execute",
"(",
")",
";",
"}"
] | Clear the counter columns. | [
"Clear",
"the",
"counter",
"columns",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/ClearCounterRow.java#L78-L94 |
2,861 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.createCluster | public static Cluster createCluster(String clusterName,
CassandraHostConfigurator cassandraHostConfigurator,
Map<String, String> credentials) {
synchronized (clusters) {
Cluster cluster = clusters.get(clusterName);
if ( cluster == null ) {
cluster = new ThriftCluster(clusterName,
cassandraHostConfigurator, credentials);
clusters.put(clusterName, cluster);
cluster.onStartup();
}
return cluster;
}
} | java | public static Cluster createCluster(String clusterName,
CassandraHostConfigurator cassandraHostConfigurator,
Map<String, String> credentials) {
synchronized (clusters) {
Cluster cluster = clusters.get(clusterName);
if ( cluster == null ) {
cluster = new ThriftCluster(clusterName,
cassandraHostConfigurator, credentials);
clusters.put(clusterName, cluster);
cluster.onStartup();
}
return cluster;
}
} | [
"public",
"static",
"Cluster",
"createCluster",
"(",
"String",
"clusterName",
",",
"CassandraHostConfigurator",
"cassandraHostConfigurator",
",",
"Map",
"<",
"String",
",",
"String",
">",
"credentials",
")",
"{",
"synchronized",
"(",
"clusters",
")",
"{",
"Cluster",
"cluster",
"=",
"clusters",
".",
"get",
"(",
"clusterName",
")",
";",
"if",
"(",
"cluster",
"==",
"null",
")",
"{",
"cluster",
"=",
"new",
"ThriftCluster",
"(",
"clusterName",
",",
"cassandraHostConfigurator",
",",
"credentials",
")",
";",
"clusters",
".",
"put",
"(",
"clusterName",
",",
"cluster",
")",
";",
"cluster",
".",
"onStartup",
"(",
")",
";",
"}",
"return",
"cluster",
";",
"}",
"}"
] | Method looks in the cache for the cluster by name. If none exists, a new
ThriftCluster instance is created and added to the map of known clusters
@param clusterName
The cluster name. This is an identifying string for the cluster,
e.g. "production" or "test" etc. Clusters will be created on
demand per each unique clusterName key.
@param cassandraHostConfigurator
@param credentials | [
"Method",
"looks",
"in",
"the",
"cache",
"for",
"the",
"cluster",
"by",
"name",
".",
"If",
"none",
"exists",
"a",
"new",
"ThriftCluster",
"instance",
"is",
"created",
"and",
"added",
"to",
"the",
"map",
"of",
"known",
"clusters"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L191-L204 |
2,862 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.shutdownCluster | public static void shutdownCluster(Cluster cluster) {
synchronized (clusters) {
String clusterName = cluster.getName();
if (clusters.get(clusterName) != null ) {
cluster.getConnectionManager().shutdown();
clusters.remove(clusterName);
}
}
} | java | public static void shutdownCluster(Cluster cluster) {
synchronized (clusters) {
String clusterName = cluster.getName();
if (clusters.get(clusterName) != null ) {
cluster.getConnectionManager().shutdown();
clusters.remove(clusterName);
}
}
} | [
"public",
"static",
"void",
"shutdownCluster",
"(",
"Cluster",
"cluster",
")",
"{",
"synchronized",
"(",
"clusters",
")",
"{",
"String",
"clusterName",
"=",
"cluster",
".",
"getName",
"(",
")",
";",
"if",
"(",
"clusters",
".",
"get",
"(",
"clusterName",
")",
"!=",
"null",
")",
"{",
"cluster",
".",
"getConnectionManager",
"(",
")",
".",
"shutdown",
"(",
")",
";",
"clusters",
".",
"remove",
"(",
"clusterName",
")",
";",
"}",
"}",
"}"
] | Shutdown this cluster, removing it from the Map. This operation is
extremely expensive and should not be done lightly.
@param cluster | [
"Shutdown",
"this",
"cluster",
"removing",
"it",
"from",
"the",
"Map",
".",
"This",
"operation",
"is",
"extremely",
"expensive",
"and",
"should",
"not",
"be",
"done",
"lightly",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L215-L223 |
2,863 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.createKeyspace | public static Keyspace createKeyspace(String keyspace, Cluster cluster) {
return createKeyspace(keyspace, cluster,
createDefaultConsistencyLevelPolicy(),
FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE);
} | java | public static Keyspace createKeyspace(String keyspace, Cluster cluster) {
return createKeyspace(keyspace, cluster,
createDefaultConsistencyLevelPolicy(),
FailoverPolicy.ON_FAIL_TRY_ALL_AVAILABLE);
} | [
"public",
"static",
"Keyspace",
"createKeyspace",
"(",
"String",
"keyspace",
",",
"Cluster",
"cluster",
")",
"{",
"return",
"createKeyspace",
"(",
"keyspace",
",",
"cluster",
",",
"createDefaultConsistencyLevelPolicy",
"(",
")",
",",
"FailoverPolicy",
".",
"ON_FAIL_TRY_ALL_AVAILABLE",
")",
";",
"}"
] | Creates a Keyspace with the default consistency level policy.
Example usage.
String clusterName = "Test Cluster";
String host = "localhost:9160";
Cluster cluster = HFactory.getOrCreateCluster(clusterName, host);
String keyspaceName = "testKeyspace";
Keyspace myKeyspace = HFactory.createKeyspace(keyspaceName, cluster);
@param keyspace
@param cluster
@return | [
"Creates",
"a",
"Keyspace",
"with",
"the",
"default",
"consistency",
"level",
"policy",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L240-L244 |
2,864 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.createMutator | public static <K, N, V> Mutator<K> createMutator(Keyspace keyspace,
Serializer<K> keySerializer) {
return new MutatorImpl<K>(keyspace, keySerializer);
} | java | public static <K, N, V> Mutator<K> createMutator(Keyspace keyspace,
Serializer<K> keySerializer) {
return new MutatorImpl<K>(keyspace, keySerializer);
} | [
"public",
"static",
"<",
"K",
",",
"N",
",",
"V",
">",
"Mutator",
"<",
"K",
">",
"createMutator",
"(",
"Keyspace",
"keyspace",
",",
"Serializer",
"<",
"K",
">",
"keySerializer",
")",
"{",
"return",
"new",
"MutatorImpl",
"<",
"K",
">",
"(",
"keyspace",
",",
"keySerializer",
")",
";",
"}"
] | Creates a mutator for updating records in a keyspace.
@param keyspace
@param keySerializer | [
"Creates",
"a",
"mutator",
"for",
"updating",
"records",
"in",
"a",
"keyspace",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L339-L342 |
2,865 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.createCounterColumn | public static <N> HCounterColumn<N> createCounterColumn(N name, long value, Serializer<N> nameSerializer) {
return new HCounterColumnImpl<N>(name, value, nameSerializer);
} | java | public static <N> HCounterColumn<N> createCounterColumn(N name, long value, Serializer<N> nameSerializer) {
return new HCounterColumnImpl<N>(name, value, nameSerializer);
} | [
"public",
"static",
"<",
"N",
">",
"HCounterColumn",
"<",
"N",
">",
"createCounterColumn",
"(",
"N",
"name",
",",
"long",
"value",
",",
"Serializer",
"<",
"N",
">",
"nameSerializer",
")",
"{",
"return",
"new",
"HCounterColumnImpl",
"<",
"N",
">",
"(",
"name",
",",
"value",
",",
"nameSerializer",
")",
";",
"}"
] | Create a counter column with a name and long value | [
"Create",
"a",
"counter",
"column",
"with",
"a",
"name",
"and",
"long",
"value"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L643-L645 |
2,866 | hector-client/hector | core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java | HFactory.createCounterColumn | public static HCounterColumn<String> createCounterColumn(String name, long value) {
StringSerializer se = StringSerializer.get();
return createCounterColumn(name, value, se);
} | java | public static HCounterColumn<String> createCounterColumn(String name, long value) {
StringSerializer se = StringSerializer.get();
return createCounterColumn(name, value, se);
} | [
"public",
"static",
"HCounterColumn",
"<",
"String",
">",
"createCounterColumn",
"(",
"String",
"name",
",",
"long",
"value",
")",
"{",
"StringSerializer",
"se",
"=",
"StringSerializer",
".",
"get",
"(",
")",
";",
"return",
"createCounterColumn",
"(",
"name",
",",
"value",
",",
"se",
")",
";",
"}"
] | Convenient method for creating a counter column with a String name and long value | [
"Convenient",
"method",
"for",
"creating",
"a",
"counter",
"column",
"with",
"a",
"String",
"name",
"and",
"long",
"value"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/hector/api/factory/HFactory.java#L650-L653 |
2,867 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/spring/HectorTemplateImpl.java | HectorTemplateImpl.createColumnPath | <N> ColumnPath createColumnPath(String columnFamilyName, N columnName,
Serializer<N> nameSerializer) {
return createColumnPath(columnFamilyName, nameSerializer.toByteBuffer(columnName));
} | java | <N> ColumnPath createColumnPath(String columnFamilyName, N columnName,
Serializer<N> nameSerializer) {
return createColumnPath(columnFamilyName, nameSerializer.toByteBuffer(columnName));
} | [
"<",
"N",
">",
"ColumnPath",
"createColumnPath",
"(",
"String",
"columnFamilyName",
",",
"N",
"columnName",
",",
"Serializer",
"<",
"N",
">",
"nameSerializer",
")",
"{",
"return",
"createColumnPath",
"(",
"columnFamilyName",
",",
"nameSerializer",
".",
"toByteBuffer",
"(",
"columnName",
")",
")",
";",
"}"
] | probably should be typed for thrift vs. avro | [
"probably",
"should",
"be",
"typed",
"for",
"thrift",
"vs",
".",
"avro"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/spring/HectorTemplateImpl.java#L235-L238 |
2,868 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java | EntityManagerImpl.find | @Override
public <T> T find(Class<T> clazz, Object id) {
if (null == clazz) {
throw new IllegalArgumentException("clazz cannot be null");
}
if (null == id) {
throw new IllegalArgumentException("id cannot be null");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(clazz, false);
if (null == cfMapDef) {
throw new HectorObjectMapperException("No class annotated with @"
+ Entity.class.getSimpleName() + " for type, " + clazz.getName());
}
return objMapper.getObject(keyspace, cfMapDef.getEffectiveColFamName(), id);
} | java | @Override
public <T> T find(Class<T> clazz, Object id) {
if (null == clazz) {
throw new IllegalArgumentException("clazz cannot be null");
}
if (null == id) {
throw new IllegalArgumentException("id cannot be null");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(clazz, false);
if (null == cfMapDef) {
throw new HectorObjectMapperException("No class annotated with @"
+ Entity.class.getSimpleName() + " for type, " + clazz.getName());
}
return objMapper.getObject(keyspace, cfMapDef.getEffectiveColFamName(), id);
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"find",
"(",
"Class",
"<",
"T",
">",
"clazz",
",",
"Object",
"id",
")",
"{",
"if",
"(",
"null",
"==",
"clazz",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"clazz cannot be null\"",
")",
";",
"}",
"if",
"(",
"null",
"==",
"id",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"id cannot be null\"",
")",
";",
"}",
"CFMappingDef",
"<",
"T",
">",
"cfMapDef",
"=",
"cacheMgr",
".",
"getCfMapDef",
"(",
"clazz",
",",
"false",
")",
";",
"if",
"(",
"null",
"==",
"cfMapDef",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"\"No class annotated with @\"",
"+",
"Entity",
".",
"class",
".",
"getSimpleName",
"(",
")",
"+",
"\" for type, \"",
"+",
"clazz",
".",
"getName",
"(",
")",
")",
";",
"}",
"return",
"objMapper",
".",
"getObject",
"(",
"keyspace",
",",
"cfMapDef",
".",
"getEffectiveColFamName",
"(",
")",
",",
"id",
")",
";",
"}"
] | Load an entity instance. If the ID does not map to a persisted entity, then
null is returned.
@param <T> The type of entity to load for compile time type checking
@param clazz The type of entity to load for runtime instance creation
@param id ID of the instance to load
@return instance of Entity or null if can't be found | [
"Load",
"an",
"entity",
"instance",
".",
"If",
"the",
"ID",
"does",
"not",
"map",
"to",
"a",
"persisted",
"entity",
"then",
"null",
"is",
"returned",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java#L147-L163 |
2,869 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java | EntityManagerImpl.find | public <T> T find(Class<T> clazz, Object id, ColumnSlice<String, byte[]> colSlice) {
if (null == clazz) {
throw new IllegalArgumentException("clazz cannot be null");
}
if (null == id) {
throw new IllegalArgumentException("id cannot be null");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(clazz, false);
if (null == cfMapDef) {
throw new HectorObjectMapperException("No class annotated with @"
+ Entity.class.getSimpleName() + " for type, " + clazz.getName());
}
T obj = objMapper.createObject(cfMapDef, id, colSlice);
return obj;
} | java | public <T> T find(Class<T> clazz, Object id, ColumnSlice<String, byte[]> colSlice) {
if (null == clazz) {
throw new IllegalArgumentException("clazz cannot be null");
}
if (null == id) {
throw new IllegalArgumentException("id cannot be null");
}
CFMappingDef<T> cfMapDef = cacheMgr.getCfMapDef(clazz, false);
if (null == cfMapDef) {
throw new HectorObjectMapperException("No class annotated with @"
+ Entity.class.getSimpleName() + " for type, " + clazz.getName());
}
T obj = objMapper.createObject(cfMapDef, id, colSlice);
return obj;
} | [
"public",
"<",
"T",
">",
"T",
"find",
"(",
"Class",
"<",
"T",
">",
"clazz",
",",
"Object",
"id",
",",
"ColumnSlice",
"<",
"String",
",",
"byte",
"[",
"]",
">",
"colSlice",
")",
"{",
"if",
"(",
"null",
"==",
"clazz",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"clazz cannot be null\"",
")",
";",
"}",
"if",
"(",
"null",
"==",
"id",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"id cannot be null\"",
")",
";",
"}",
"CFMappingDef",
"<",
"T",
">",
"cfMapDef",
"=",
"cacheMgr",
".",
"getCfMapDef",
"(",
"clazz",
",",
"false",
")",
";",
"if",
"(",
"null",
"==",
"cfMapDef",
")",
"{",
"throw",
"new",
"HectorObjectMapperException",
"(",
"\"No class annotated with @\"",
"+",
"Entity",
".",
"class",
".",
"getSimpleName",
"(",
")",
"+",
"\" for type, \"",
"+",
"clazz",
".",
"getName",
"(",
")",
")",
";",
"}",
"T",
"obj",
"=",
"objMapper",
".",
"createObject",
"(",
"cfMapDef",
",",
"id",
",",
"colSlice",
")",
";",
"return",
"obj",
";",
"}"
] | Load an entity instance given the raw column slice. This is a stop gap
solution for instanting objects using entity manager while iterating over
rows.
@param <T> The type of entity to load for compile time type checking
@param clazz The type of entity to load for runtime instance creation
@param id ID of the instance to load
@param colSlice Raw row slice as returned from Hector API, of the type
<code>ColumnSlice<String, byte[]></code>
@return Completely instantiated persisted object | [
"Load",
"an",
"entity",
"instance",
"given",
"the",
"raw",
"column",
"slice",
".",
"This",
"is",
"a",
"stop",
"gap",
"solution",
"for",
"instanting",
"objects",
"using",
"entity",
"manager",
"while",
"iterating",
"over",
"rows",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java#L177-L193 |
2,870 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java | EntityManagerImpl.persist | @Override
public void persist(Object obj) {
if (null == obj) {
throw new IllegalArgumentException("object to save cannot be null");
}
objMapper.saveObj(keyspace, obj);
} | java | @Override
public void persist(Object obj) {
if (null == obj) {
throw new IllegalArgumentException("object to save cannot be null");
}
objMapper.saveObj(keyspace, obj);
} | [
"@",
"Override",
"public",
"void",
"persist",
"(",
"Object",
"obj",
")",
"{",
"if",
"(",
"null",
"==",
"obj",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"object to save cannot be null\"",
")",
";",
"}",
"objMapper",
".",
"saveObj",
"(",
"keyspace",
",",
"obj",
")",
";",
"}"
] | Save the entity instance.
@param obj
@return | [
"Save",
"the",
"entity",
"instance",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/EntityManagerImpl.java#L231-L237 |
2,871 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java | HConnectionManager.addCassandraHost | public boolean addCassandraHost(CassandraHost cassandraHost) {
if ( !getHosts().contains(cassandraHost) ) {
HClientPool pool = null;
try {
cassandraHostConfigurator.applyConfig(cassandraHost);
pool = cassandraHostConfigurator.getLoadBalancingPolicy().createConnection(clientFactory, cassandraHost, monitor);
hostPools.putIfAbsent(cassandraHost, pool);
log.info("Added host {} to pool", cassandraHost.getName());
listenerHandler.fireOnAddHost(cassandraHost, true, null, null);
return true;
} catch (HectorTransportException hte) {
String errorMessage = "Transport exception host to HConnectionManager: " + cassandraHost;
log.error(errorMessage, hte);
listenerHandler.fireOnAddHost(cassandraHost, false, errorMessage, hte);
} catch (Exception ex) {
String errorMessage = "General exception host to HConnectionManager: " + cassandraHost;
log.error(errorMessage, ex);
listenerHandler.fireOnAddHost(cassandraHost, false, errorMessage, ex);
}
} else {
String message = "Host already existed for pool " + cassandraHost.getName();
log.info(message);
listenerHandler.fireOnAddHost(cassandraHost, false, message, null);
}
return false;
} | java | public boolean addCassandraHost(CassandraHost cassandraHost) {
if ( !getHosts().contains(cassandraHost) ) {
HClientPool pool = null;
try {
cassandraHostConfigurator.applyConfig(cassandraHost);
pool = cassandraHostConfigurator.getLoadBalancingPolicy().createConnection(clientFactory, cassandraHost, monitor);
hostPools.putIfAbsent(cassandraHost, pool);
log.info("Added host {} to pool", cassandraHost.getName());
listenerHandler.fireOnAddHost(cassandraHost, true, null, null);
return true;
} catch (HectorTransportException hte) {
String errorMessage = "Transport exception host to HConnectionManager: " + cassandraHost;
log.error(errorMessage, hte);
listenerHandler.fireOnAddHost(cassandraHost, false, errorMessage, hte);
} catch (Exception ex) {
String errorMessage = "General exception host to HConnectionManager: " + cassandraHost;
log.error(errorMessage, ex);
listenerHandler.fireOnAddHost(cassandraHost, false, errorMessage, ex);
}
} else {
String message = "Host already existed for pool " + cassandraHost.getName();
log.info(message);
listenerHandler.fireOnAddHost(cassandraHost, false, message, null);
}
return false;
} | [
"public",
"boolean",
"addCassandraHost",
"(",
"CassandraHost",
"cassandraHost",
")",
"{",
"if",
"(",
"!",
"getHosts",
"(",
")",
".",
"contains",
"(",
"cassandraHost",
")",
")",
"{",
"HClientPool",
"pool",
"=",
"null",
";",
"try",
"{",
"cassandraHostConfigurator",
".",
"applyConfig",
"(",
"cassandraHost",
")",
";",
"pool",
"=",
"cassandraHostConfigurator",
".",
"getLoadBalancingPolicy",
"(",
")",
".",
"createConnection",
"(",
"clientFactory",
",",
"cassandraHost",
",",
"monitor",
")",
";",
"hostPools",
".",
"putIfAbsent",
"(",
"cassandraHost",
",",
"pool",
")",
";",
"log",
".",
"info",
"(",
"\"Added host {} to pool\"",
",",
"cassandraHost",
".",
"getName",
"(",
")",
")",
";",
"listenerHandler",
".",
"fireOnAddHost",
"(",
"cassandraHost",
",",
"true",
",",
"null",
",",
"null",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"HectorTransportException",
"hte",
")",
"{",
"String",
"errorMessage",
"=",
"\"Transport exception host to HConnectionManager: \"",
"+",
"cassandraHost",
";",
"log",
".",
"error",
"(",
"errorMessage",
",",
"hte",
")",
";",
"listenerHandler",
".",
"fireOnAddHost",
"(",
"cassandraHost",
",",
"false",
",",
"errorMessage",
",",
"hte",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"String",
"errorMessage",
"=",
"\"General exception host to HConnectionManager: \"",
"+",
"cassandraHost",
";",
"log",
".",
"error",
"(",
"errorMessage",
",",
"ex",
")",
";",
"listenerHandler",
".",
"fireOnAddHost",
"(",
"cassandraHost",
",",
"false",
",",
"errorMessage",
",",
"ex",
")",
";",
"}",
"}",
"else",
"{",
"String",
"message",
"=",
"\"Host already existed for pool \"",
"+",
"cassandraHost",
".",
"getName",
"(",
")",
";",
"log",
".",
"info",
"(",
"message",
")",
";",
"listenerHandler",
".",
"fireOnAddHost",
"(",
"cassandraHost",
",",
"false",
",",
"message",
",",
"null",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the host was successfully added. In any sort of failure exceptions are
caught and logged, returning false.
@param cassandraHost
@return | [
"Returns",
"true",
"if",
"the",
"host",
"was",
"successfully",
"added",
".",
"In",
"any",
"sort",
"of",
"failure",
"exceptions",
"are",
"caught",
"and",
"logged",
"returning",
"false",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java#L90-L115 |
2,872 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java | HConnectionManager.unsuspendCassandraHost | public boolean unsuspendCassandraHost(CassandraHost cassandraHost) {
HClientPool pool = suspendedHostPools.remove(cassandraHost);
boolean readded = pool != null;
if ( readded ) {
boolean alreadyThere = hostPools.putIfAbsent(cassandraHost, pool) != null;
if ( alreadyThere ) {
log.error("Unsuspend called on a pool that was already active for CassandraHost {}", cassandraHost);
pool.shutdown();
}
}
listenerHandler.fireOnUnSuspendHost(cassandraHost, readded);
log.info("UN-Suspend operation status was {} for CassandraHost {}", readded, cassandraHost);
return readded;
} | java | public boolean unsuspendCassandraHost(CassandraHost cassandraHost) {
HClientPool pool = suspendedHostPools.remove(cassandraHost);
boolean readded = pool != null;
if ( readded ) {
boolean alreadyThere = hostPools.putIfAbsent(cassandraHost, pool) != null;
if ( alreadyThere ) {
log.error("Unsuspend called on a pool that was already active for CassandraHost {}", cassandraHost);
pool.shutdown();
}
}
listenerHandler.fireOnUnSuspendHost(cassandraHost, readded);
log.info("UN-Suspend operation status was {} for CassandraHost {}", readded, cassandraHost);
return readded;
} | [
"public",
"boolean",
"unsuspendCassandraHost",
"(",
"CassandraHost",
"cassandraHost",
")",
"{",
"HClientPool",
"pool",
"=",
"suspendedHostPools",
".",
"remove",
"(",
"cassandraHost",
")",
";",
"boolean",
"readded",
"=",
"pool",
"!=",
"null",
";",
"if",
"(",
"readded",
")",
"{",
"boolean",
"alreadyThere",
"=",
"hostPools",
".",
"putIfAbsent",
"(",
"cassandraHost",
",",
"pool",
")",
"!=",
"null",
";",
"if",
"(",
"alreadyThere",
")",
"{",
"log",
".",
"error",
"(",
"\"Unsuspend called on a pool that was already active for CassandraHost {}\"",
",",
"cassandraHost",
")",
";",
"pool",
".",
"shutdown",
"(",
")",
";",
"}",
"}",
"listenerHandler",
".",
"fireOnUnSuspendHost",
"(",
"cassandraHost",
",",
"readded",
")",
";",
"log",
".",
"info",
"(",
"\"UN-Suspend operation status was {} for CassandraHost {}\"",
",",
"readded",
",",
"cassandraHost",
")",
";",
"return",
"readded",
";",
"}"
] | The opposite of suspendCassandraHost, places the pool back into selection
@param cassandraHost
@return true if this operation was successful. A no-op returning false
if there was no such host in the underlying suspendedHostPool map. | [
"The",
"opposite",
"of",
"suspendCassandraHost",
"places",
"the",
"pool",
"back",
"into",
"selection"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java#L184-L197 |
2,873 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java | HConnectionManager.doTimeoutCheck | private void doTimeoutCheck(CassandraHost cassandraHost) {
if ( hostTimeoutTracker != null && hostPools.size() > 1) {
if (hostTimeoutTracker.checkTimeout(cassandraHost) ) {
suspendCassandraHost(cassandraHost);
}
}
} | java | private void doTimeoutCheck(CassandraHost cassandraHost) {
if ( hostTimeoutTracker != null && hostPools.size() > 1) {
if (hostTimeoutTracker.checkTimeout(cassandraHost) ) {
suspendCassandraHost(cassandraHost);
}
}
} | [
"private",
"void",
"doTimeoutCheck",
"(",
"CassandraHost",
"cassandraHost",
")",
"{",
"if",
"(",
"hostTimeoutTracker",
"!=",
"null",
"&&",
"hostPools",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"if",
"(",
"hostTimeoutTracker",
".",
"checkTimeout",
"(",
"cassandraHost",
")",
")",
"{",
"suspendCassandraHost",
"(",
"cassandraHost",
")",
";",
"}",
"}",
"}"
] | Use the HostTimeoutCheck and initiate a suspend if and only if
we are configured for such AND there is more than one operating host pool
@param cassandraHost | [
"Use",
"the",
"HostTimeoutCheck",
"and",
"initiate",
"a",
"suspend",
"if",
"and",
"only",
"if",
"we",
"are",
"configured",
"for",
"such",
"AND",
"there",
"is",
"more",
"than",
"one",
"operating",
"host",
"pool"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/HConnectionManager.java#L373-L379 |
2,874 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/DynamicLoadBalancingPolicy.java | DynamicLoadBalancingPolicy.updateScores | void updateScores() {
for (LatencyAwareHClientPool pool : allPools) {
scores.put(pool, pool.score());
pool.resetIntervel();
}
} | java | void updateScores() {
for (LatencyAwareHClientPool pool : allPools) {
scores.put(pool, pool.score());
pool.resetIntervel();
}
} | [
"void",
"updateScores",
"(",
")",
"{",
"for",
"(",
"LatencyAwareHClientPool",
"pool",
":",
"allPools",
")",
"{",
"scores",
".",
"put",
"(",
"pool",
",",
"pool",
".",
"score",
"(",
")",
")",
";",
"pool",
".",
"resetIntervel",
"(",
")",
";",
"}",
"}"
] | This will be a expensive call. | [
"This",
"will",
"be",
"a",
"expensive",
"call",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/DynamicLoadBalancingPolicy.java#L137-L142 |
2,875 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/dao/SimpleCassandraDao.java | SimpleCassandraDao.insertMulti | public void insertMulti(String columnName, Map<String, String> keyValues) {
Mutator<String> m = createMutator(keyspace, serializer);
for (Map.Entry<String, String> keyValue: keyValues.entrySet()) {
m.addInsertion(keyValue.getKey(), columnFamilyName,
createColumn(columnName, keyValue.getValue(), keyspace.createClock(), serializer, serializer));
}
m.execute();
} | java | public void insertMulti(String columnName, Map<String, String> keyValues) {
Mutator<String> m = createMutator(keyspace, serializer);
for (Map.Entry<String, String> keyValue: keyValues.entrySet()) {
m.addInsertion(keyValue.getKey(), columnFamilyName,
createColumn(columnName, keyValue.getValue(), keyspace.createClock(), serializer, serializer));
}
m.execute();
} | [
"public",
"void",
"insertMulti",
"(",
"String",
"columnName",
",",
"Map",
"<",
"String",
",",
"String",
">",
"keyValues",
")",
"{",
"Mutator",
"<",
"String",
">",
"m",
"=",
"createMutator",
"(",
"keyspace",
",",
"serializer",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"keyValue",
":",
"keyValues",
".",
"entrySet",
"(",
")",
")",
"{",
"m",
".",
"addInsertion",
"(",
"keyValue",
".",
"getKey",
"(",
")",
",",
"columnFamilyName",
",",
"createColumn",
"(",
"columnName",
",",
"keyValue",
".",
"getValue",
"(",
")",
",",
"keyspace",
".",
"createClock",
"(",
")",
",",
"serializer",
",",
"serializer",
")",
")",
";",
"}",
"m",
".",
"execute",
"(",
")",
";",
"}"
] | Insert multiple values for a given columnName | [
"Insert",
"multiple",
"values",
"for",
"a",
"given",
"columnName"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/dao/SimpleCassandraDao.java#L81-L88 |
2,876 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/JmxMonitor.java | JmxMonitor.getContextPath | private String getContextPath() {
ClassLoader loader = getClass().getClassLoader();
if(loader == null)
return null;
URL url = loader.getResource("/");
if (url != null) {
String[] elements = url.toString().split("/");
for (int i = elements.length - 1; i > 0; --i) {
// URLs look like this: file:/.../ImageServer/WEB-INF/classes/
// And we want that part that's just before WEB-INF
if ("WEB-INF".equals(elements[i])) {
return elements[i - 1];
}
}
}
return null;
} | java | private String getContextPath() {
ClassLoader loader = getClass().getClassLoader();
if(loader == null)
return null;
URL url = loader.getResource("/");
if (url != null) {
String[] elements = url.toString().split("/");
for (int i = elements.length - 1; i > 0; --i) {
// URLs look like this: file:/.../ImageServer/WEB-INF/classes/
// And we want that part that's just before WEB-INF
if ("WEB-INF".equals(elements[i])) {
return elements[i - 1];
}
}
}
return null;
} | [
"private",
"String",
"getContextPath",
"(",
")",
"{",
"ClassLoader",
"loader",
"=",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
";",
"if",
"(",
"loader",
"==",
"null",
")",
"return",
"null",
";",
"URL",
"url",
"=",
"loader",
".",
"getResource",
"(",
"\"/\"",
")",
";",
"if",
"(",
"url",
"!=",
"null",
")",
"{",
"String",
"[",
"]",
"elements",
"=",
"url",
".",
"toString",
"(",
")",
".",
"split",
"(",
"\"/\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"elements",
".",
"length",
"-",
"1",
";",
"i",
">",
"0",
";",
"--",
"i",
")",
"{",
"// URLs look like this: file:/.../ImageServer/WEB-INF/classes/",
"// And we want that part that's just before WEB-INF",
"if",
"(",
"\"WEB-INF\"",
".",
"equals",
"(",
"elements",
"[",
"i",
"]",
")",
")",
"{",
"return",
"elements",
"[",
"i",
"-",
"1",
"]",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Tries to guess a context path for the running application.
If this is a web application running under a tomcat server this will work.
If unsuccessful, returns null.
@return A string representing the current context path or null if it cannot be determined. | [
"Tries",
"to",
"guess",
"a",
"context",
"path",
"for",
"the",
"running",
"application",
".",
"If",
"this",
"is",
"a",
"web",
"application",
"running",
"under",
"a",
"tomcat",
"server",
"this",
"will",
"work",
".",
"If",
"unsuccessful",
"returns",
"null",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/JmxMonitor.java#L113-L129 |
2,877 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java | ColumnFamilyTemplate.countColumns | public int countColumns(K key, N start, N end, int max) {
CountQuery<K, N> query = HFactory.createCountQuery(keyspace, keySerializer,
topSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setRange(start, end, max);
return query.execute().get();
} | java | public int countColumns(K key, N start, N end, int max) {
CountQuery<K, N> query = HFactory.createCountQuery(keyspace, keySerializer,
topSerializer);
query.setKey(key);
query.setColumnFamily(columnFamily);
query.setRange(start, end, max);
return query.execute().get();
} | [
"public",
"int",
"countColumns",
"(",
"K",
"key",
",",
"N",
"start",
",",
"N",
"end",
",",
"int",
"max",
")",
"{",
"CountQuery",
"<",
"K",
",",
"N",
">",
"query",
"=",
"HFactory",
".",
"createCountQuery",
"(",
"keyspace",
",",
"keySerializer",
",",
"topSerializer",
")",
";",
"query",
".",
"setKey",
"(",
"key",
")",
";",
"query",
".",
"setColumnFamily",
"(",
"columnFamily",
")",
";",
"query",
".",
"setRange",
"(",
"start",
",",
"end",
",",
"max",
")",
";",
"return",
"query",
".",
"execute",
"(",
")",
".",
"get",
"(",
")",
";",
"}"
] | Counts columns in the specified range of a standard column family
@param key
@param start
@param end
@param max
@return | [
"Counts",
"columns",
"in",
"the",
"specified",
"range",
"of",
"a",
"standard",
"column",
"family"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java#L103-L110 |
2,878 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java | ColumnFamilyTemplate.queryColumns | public <T> T queryColumns(K key, HSlicePredicate<N> predicate,
ColumnFamilyRowMapper<K, N, T> mapper) {
return doExecuteSlice(key, predicate, mapper);
} | java | public <T> T queryColumns(K key, HSlicePredicate<N> predicate,
ColumnFamilyRowMapper<K, N, T> mapper) {
return doExecuteSlice(key, predicate, mapper);
} | [
"public",
"<",
"T",
">",
"T",
"queryColumns",
"(",
"K",
"key",
",",
"HSlicePredicate",
"<",
"N",
">",
"predicate",
",",
"ColumnFamilyRowMapper",
"<",
"K",
",",
"N",
",",
"T",
">",
"mapper",
")",
"{",
"return",
"doExecuteSlice",
"(",
"key",
",",
"predicate",
",",
"mapper",
")",
";",
"}"
] | Queries a range of columns at the given key and maps them to an object of
type OBJ using the given mapping object
@param <T>
@param key
@param predicate The {@link HSlicePredicate} which can hold specific column names
or a range of columns
@param mapper
@return | [
"Queries",
"a",
"range",
"of",
"columns",
"at",
"the",
"given",
"key",
"and",
"maps",
"them",
"to",
"an",
"object",
"of",
"type",
"OBJ",
"using",
"the",
"given",
"mapping",
"object"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java#L135-L138 |
2,879 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java | ColumnFamilyTemplate.queryColumns | public <T> T queryColumns(K key, List<N> columns,
ColumnFamilyRowMapper<K, N, T> mapper) {
HSlicePredicate<N> predicate = new HSlicePredicate<N>(topSerializer);
predicate.setColumnNames(columns);
return doExecuteSlice(key, predicate, mapper);
} | java | public <T> T queryColumns(K key, List<N> columns,
ColumnFamilyRowMapper<K, N, T> mapper) {
HSlicePredicate<N> predicate = new HSlicePredicate<N>(topSerializer);
predicate.setColumnNames(columns);
return doExecuteSlice(key, predicate, mapper);
} | [
"public",
"<",
"T",
">",
"T",
"queryColumns",
"(",
"K",
"key",
",",
"List",
"<",
"N",
">",
"columns",
",",
"ColumnFamilyRowMapper",
"<",
"K",
",",
"N",
",",
"T",
">",
"mapper",
")",
"{",
"HSlicePredicate",
"<",
"N",
">",
"predicate",
"=",
"new",
"HSlicePredicate",
"<",
"N",
">",
"(",
"topSerializer",
")",
";",
"predicate",
".",
"setColumnNames",
"(",
"columns",
")",
";",
"return",
"doExecuteSlice",
"(",
"key",
",",
"predicate",
",",
"mapper",
")",
";",
"}"
] | Queries all columns at a given key and maps them to an object of type OBJ
using the given mapping object
@param <T>
@param key
@param columns
@param mapper
@return | [
"Queries",
"all",
"columns",
"at",
"a",
"given",
"key",
"and",
"maps",
"them",
"to",
"an",
"object",
"of",
"type",
"OBJ",
"using",
"the",
"given",
"mapping",
"object"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/ColumnFamilyTemplate.java#L150-L155 |
2,880 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/NodeDiscovery.java | NodeDiscovery.doAddNodes | public void doAddNodes() {
if (log.isDebugEnabled()) {
log.debug("Node discovery running...");
}
Set<CassandraHost> foundHosts = discoverNodes();
if (foundHosts != null && foundHosts.size() > 0) {
log.info("Found {} new host(s) in Ring", foundHosts.size());
for (CassandraHost cassandraHost : foundHosts) {
log.info("Addding found host {} to pool", cassandraHost);
cassandraHostConfigurator.applyConfig(cassandraHost);
connectionManager.addCassandraHost(cassandraHost);
}
}
if (log.isDebugEnabled()) {
log.debug("Node discovery run complete.");
}
} | java | public void doAddNodes() {
if (log.isDebugEnabled()) {
log.debug("Node discovery running...");
}
Set<CassandraHost> foundHosts = discoverNodes();
if (foundHosts != null && foundHosts.size() > 0) {
log.info("Found {} new host(s) in Ring", foundHosts.size());
for (CassandraHost cassandraHost : foundHosts) {
log.info("Addding found host {} to pool", cassandraHost);
cassandraHostConfigurator.applyConfig(cassandraHost);
connectionManager.addCassandraHost(cassandraHost);
}
}
if (log.isDebugEnabled()) {
log.debug("Node discovery run complete.");
}
} | [
"public",
"void",
"doAddNodes",
"(",
")",
"{",
"if",
"(",
"log",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Node discovery running...\"",
")",
";",
"}",
"Set",
"<",
"CassandraHost",
">",
"foundHosts",
"=",
"discoverNodes",
"(",
")",
";",
"if",
"(",
"foundHosts",
"!=",
"null",
"&&",
"foundHosts",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"log",
".",
"info",
"(",
"\"Found {} new host(s) in Ring\"",
",",
"foundHosts",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"CassandraHost",
"cassandraHost",
":",
"foundHosts",
")",
"{",
"log",
".",
"info",
"(",
"\"Addding found host {} to pool\"",
",",
"cassandraHost",
")",
";",
"cassandraHostConfigurator",
".",
"applyConfig",
"(",
"cassandraHost",
")",
";",
"connectionManager",
".",
"addCassandraHost",
"(",
"cassandraHost",
")",
";",
"}",
"}",
"if",
"(",
"log",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Node discovery run complete.\"",
")",
";",
"}",
"}"
] | Find any nodes that are not already in the connection manager but are in
the cassandra ring and add them | [
"Find",
"any",
"nodes",
"that",
"are",
"not",
"already",
"in",
"the",
"connection",
"manager",
"but",
"are",
"in",
"the",
"cassandra",
"ring",
"and",
"add",
"them"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/NodeDiscovery.java#L39-L55 |
2,881 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/connection/NodeDiscovery.java | NodeDiscovery.discoverNodes | public Set<CassandraHost> discoverNodes() {
Cluster cluster = HFactory.getCluster(connectionManager.getClusterName());
if (cluster == null) {
return null;
}
Set<CassandraHost> existingHosts = connectionManager.getHosts();
Set<CassandraHost> foundHosts = new HashSet<CassandraHost>();
if (log.isDebugEnabled()) {
log.debug("using existing hosts {}", existingHosts);
}
try {
for (KeyspaceDefinition keyspaceDefinition : cluster.describeKeyspaces()) {
if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
for (TokenRange tokenRange : tokenRanges) {
for (EndpointDetails endPointDetail : tokenRange.getEndpoint_details()) {
// Check if we are allowed to include this Data
// Center.
if (dataCenterValidator == null
|| dataCenterValidator.validate(endPointDetail.getDatacenter())) {
// Maybe add this host if it's a new host.
CassandraHost foundHost = new CassandraHost(endPointDetail.getHost(),
cassandraHostConfigurator.getPort());
if (!existingHosts.contains(foundHost)) {
log.info("Found a node we don't know about {} for TokenRange {}", foundHost,
tokenRange);
foundHosts.add(foundHost);
}
}
}
}
break;
}
}
} catch (Exception e) {
log.error("Discovery Service failed attempt to connect CassandraHost", e);
}
return foundHosts;
} | java | public Set<CassandraHost> discoverNodes() {
Cluster cluster = HFactory.getCluster(connectionManager.getClusterName());
if (cluster == null) {
return null;
}
Set<CassandraHost> existingHosts = connectionManager.getHosts();
Set<CassandraHost> foundHosts = new HashSet<CassandraHost>();
if (log.isDebugEnabled()) {
log.debug("using existing hosts {}", existingHosts);
}
try {
for (KeyspaceDefinition keyspaceDefinition : cluster.describeKeyspaces()) {
if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
for (TokenRange tokenRange : tokenRanges) {
for (EndpointDetails endPointDetail : tokenRange.getEndpoint_details()) {
// Check if we are allowed to include this Data
// Center.
if (dataCenterValidator == null
|| dataCenterValidator.validate(endPointDetail.getDatacenter())) {
// Maybe add this host if it's a new host.
CassandraHost foundHost = new CassandraHost(endPointDetail.getHost(),
cassandraHostConfigurator.getPort());
if (!existingHosts.contains(foundHost)) {
log.info("Found a node we don't know about {} for TokenRange {}", foundHost,
tokenRange);
foundHosts.add(foundHost);
}
}
}
}
break;
}
}
} catch (Exception e) {
log.error("Discovery Service failed attempt to connect CassandraHost", e);
}
return foundHosts;
} | [
"public",
"Set",
"<",
"CassandraHost",
">",
"discoverNodes",
"(",
")",
"{",
"Cluster",
"cluster",
"=",
"HFactory",
".",
"getCluster",
"(",
"connectionManager",
".",
"getClusterName",
"(",
")",
")",
";",
"if",
"(",
"cluster",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"Set",
"<",
"CassandraHost",
">",
"existingHosts",
"=",
"connectionManager",
".",
"getHosts",
"(",
")",
";",
"Set",
"<",
"CassandraHost",
">",
"foundHosts",
"=",
"new",
"HashSet",
"<",
"CassandraHost",
">",
"(",
")",
";",
"if",
"(",
"log",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"using existing hosts {}\"",
",",
"existingHosts",
")",
";",
"}",
"try",
"{",
"for",
"(",
"KeyspaceDefinition",
"keyspaceDefinition",
":",
"cluster",
".",
"describeKeyspaces",
"(",
")",
")",
"{",
"if",
"(",
"!",
"keyspaceDefinition",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"Keyspace",
".",
"KEYSPACE_SYSTEM",
")",
")",
"{",
"List",
"<",
"TokenRange",
">",
"tokenRanges",
"=",
"cluster",
".",
"describeRing",
"(",
"keyspaceDefinition",
".",
"getName",
"(",
")",
")",
";",
"for",
"(",
"TokenRange",
"tokenRange",
":",
"tokenRanges",
")",
"{",
"for",
"(",
"EndpointDetails",
"endPointDetail",
":",
"tokenRange",
".",
"getEndpoint_details",
"(",
")",
")",
"{",
"// Check if we are allowed to include this Data",
"// Center.",
"if",
"(",
"dataCenterValidator",
"==",
"null",
"||",
"dataCenterValidator",
".",
"validate",
"(",
"endPointDetail",
".",
"getDatacenter",
"(",
")",
")",
")",
"{",
"// Maybe add this host if it's a new host.",
"CassandraHost",
"foundHost",
"=",
"new",
"CassandraHost",
"(",
"endPointDetail",
".",
"getHost",
"(",
")",
",",
"cassandraHostConfigurator",
".",
"getPort",
"(",
")",
")",
";",
"if",
"(",
"!",
"existingHosts",
".",
"contains",
"(",
"foundHost",
")",
")",
"{",
"log",
".",
"info",
"(",
"\"Found a node we don't know about {} for TokenRange {}\"",
",",
"foundHost",
",",
"tokenRange",
")",
";",
"foundHosts",
".",
"add",
"(",
"foundHost",
")",
";",
"}",
"}",
"}",
"}",
"break",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"Discovery Service failed attempt to connect CassandraHost\"",
",",
"e",
")",
";",
"}",
"return",
"foundHosts",
";",
"}"
] | Find any unknown nodes in the cassandra ring | [
"Find",
"any",
"unknown",
"nodes",
"in",
"the",
"cassandra",
"ring"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/connection/NodeDiscovery.java#L60-L105 |
2,882 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java | AbstractColumnFamilyTemplate.addColumn | public AbstractColumnFamilyTemplate<K,N> addColumn(N columnName, Serializer<?> valueSerializer) {
columnValueSerializers.put(columnName, valueSerializer);
activeSlicePredicate.addColumnName(columnName);
return this;
} | java | public AbstractColumnFamilyTemplate<K,N> addColumn(N columnName, Serializer<?> valueSerializer) {
columnValueSerializers.put(columnName, valueSerializer);
activeSlicePredicate.addColumnName(columnName);
return this;
} | [
"public",
"AbstractColumnFamilyTemplate",
"<",
"K",
",",
"N",
">",
"addColumn",
"(",
"N",
"columnName",
",",
"Serializer",
"<",
"?",
">",
"valueSerializer",
")",
"{",
"columnValueSerializers",
".",
"put",
"(",
"columnName",
",",
"valueSerializer",
")",
";",
"activeSlicePredicate",
".",
"addColumnName",
"(",
"columnName",
")",
";",
"return",
"this",
";",
"}"
] | Add a column to the static set of columns which will be used in constructing
the single-argument form of slicing operations
@param columnName
@param valueSerializer | [
"Add",
"a",
"column",
"to",
"the",
"static",
"set",
"of",
"columns",
"which",
"will",
"be",
"used",
"in",
"constructing",
"the",
"single",
"-",
"argument",
"form",
"of",
"slicing",
"operations"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java#L77-L81 |
2,883 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java | AbstractColumnFamilyTemplate.deleteRow | public void deleteRow(K key) {
createMutator().addDeletion(key, columnFamily, null, topSerializer).execute();
} | java | public void deleteRow(K key) {
createMutator().addDeletion(key, columnFamily, null, topSerializer).execute();
} | [
"public",
"void",
"deleteRow",
"(",
"K",
"key",
")",
"{",
"createMutator",
"(",
")",
".",
"addDeletion",
"(",
"key",
",",
"columnFamily",
",",
"null",
",",
"topSerializer",
")",
".",
"execute",
"(",
")",
";",
"}"
] | Immediately delete this row in a single mutation operation
@param key | [
"Immediately",
"delete",
"this",
"row",
"in",
"a",
"single",
"mutation",
"operation"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java#L172-L174 |
2,884 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java | AbstractColumnFamilyTemplate.deleteColumn | public void deleteColumn(K key, N columnName) {
createMutator().addDeletion(key, columnFamily, columnName, topSerializer).execute();
} | java | public void deleteColumn(K key, N columnName) {
createMutator().addDeletion(key, columnFamily, columnName, topSerializer).execute();
} | [
"public",
"void",
"deleteColumn",
"(",
"K",
"key",
",",
"N",
"columnName",
")",
"{",
"createMutator",
"(",
")",
".",
"addDeletion",
"(",
"key",
",",
"columnFamily",
",",
"columnName",
",",
"topSerializer",
")",
".",
"execute",
"(",
")",
";",
"}"
] | Immediately delete this column as a single mutation operation
@param key
@param columnName | [
"Immediately",
"delete",
"this",
"column",
"as",
"a",
"single",
"mutation",
"operation"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/template/AbstractColumnFamilyTemplate.java#L191-L193 |
2,885 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/jndi/CassandraClientJndiResourceFactory.java | CassandraClientJndiResourceFactory.getObjectInstance | public Object getObjectInstance(Object object, Name jndiName, Context context,
Hashtable<?, ?> environment) throws Exception {
Reference resourceRef = null;
if (object instanceof Reference) {
resourceRef = (Reference) object;
} else {
throw new Exception("Object provided is not a javax.naming.Reference type");
}
// config CassandraHostConfigurator
if ( cluster == null ) {
configure(resourceRef);
}
return keyspace;
} | java | public Object getObjectInstance(Object object, Name jndiName, Context context,
Hashtable<?, ?> environment) throws Exception {
Reference resourceRef = null;
if (object instanceof Reference) {
resourceRef = (Reference) object;
} else {
throw new Exception("Object provided is not a javax.naming.Reference type");
}
// config CassandraHostConfigurator
if ( cluster == null ) {
configure(resourceRef);
}
return keyspace;
} | [
"public",
"Object",
"getObjectInstance",
"(",
"Object",
"object",
",",
"Name",
"jndiName",
",",
"Context",
"context",
",",
"Hashtable",
"<",
"?",
",",
"?",
">",
"environment",
")",
"throws",
"Exception",
"{",
"Reference",
"resourceRef",
"=",
"null",
";",
"if",
"(",
"object",
"instanceof",
"Reference",
")",
"{",
"resourceRef",
"=",
"(",
"Reference",
")",
"object",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Object provided is not a javax.naming.Reference type\"",
")",
";",
"}",
"// config CassandraHostConfigurator \r",
"if",
"(",
"cluster",
"==",
"null",
")",
"{",
"configure",
"(",
"resourceRef",
")",
";",
"}",
"return",
"keyspace",
";",
"}"
] | Creates an object using the location or reference information specified.
@param object The possibly null object containing location or reference information that
can be used in creating an object.
@param jndiName The name of this object relative to nameCtx, or null if no name is
specified.
@param context The context relative to which the name parameter is specified, or null
if name is relative to the default initial context.
@param environment The possibly null environment that is used in creating the object.
@return Object - The object created; null if an object cannot be created.
@exception Exception - if this object factory encountered an exception while attempting
to create an object, and no other object factories are to be tried. | [
"Creates",
"an",
"object",
"using",
"the",
"location",
"or",
"reference",
"information",
"specified",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/jndi/CassandraClientJndiResourceFactory.java#L70-L86 |
2,886 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/ColumnFamilyRowCopy.java | ColumnFamilyRowCopy.copy | public void copy() throws HectorException {
if (this.cf == null) {
throw new HectorException("Unable to clone row with null column family");
}
if (this.rowKey == null) {
throw new HectorException("Unable to clone row with null row key");
}
if (this.destinationKey == null) {
throw new HectorException("Unable to clone row with null clone key");
}
ColumnFamilyTemplate<K, ByteBuffer> template = new ThriftColumnFamilyTemplate<K, ByteBuffer>(this.keyspace, this.cf, this.keySerializer, this.bs);
Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval));
ColumnFamilyUpdater<K, ByteBuffer> updater = template.createUpdater(this.destinationKey, mutator);
SliceQuery<K, ByteBuffer, ByteBuffer> query = HFactory.createSliceQuery(this.keyspace, this.keySerializer, this.bs, this.bs).
setColumnFamily(this.cf).
setKey(this.rowKey);
ColumnSliceIterator<K, ByteBuffer, ByteBuffer> iterator = new ColumnSliceIterator<K, ByteBuffer, ByteBuffer>(query, this.bs.fromBytes(new byte[0]), this.bs.fromBytes(new byte[0]), false);
while (iterator.hasNext()) {
HColumn<ByteBuffer, ByteBuffer> column = iterator.next();
updater.setValue(column.getName(), column.getValue(), this.bs);
}
template.update(updater);
} | java | public void copy() throws HectorException {
if (this.cf == null) {
throw new HectorException("Unable to clone row with null column family");
}
if (this.rowKey == null) {
throw new HectorException("Unable to clone row with null row key");
}
if (this.destinationKey == null) {
throw new HectorException("Unable to clone row with null clone key");
}
ColumnFamilyTemplate<K, ByteBuffer> template = new ThriftColumnFamilyTemplate<K, ByteBuffer>(this.keyspace, this.cf, this.keySerializer, this.bs);
Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval));
ColumnFamilyUpdater<K, ByteBuffer> updater = template.createUpdater(this.destinationKey, mutator);
SliceQuery<K, ByteBuffer, ByteBuffer> query = HFactory.createSliceQuery(this.keyspace, this.keySerializer, this.bs, this.bs).
setColumnFamily(this.cf).
setKey(this.rowKey);
ColumnSliceIterator<K, ByteBuffer, ByteBuffer> iterator = new ColumnSliceIterator<K, ByteBuffer, ByteBuffer>(query, this.bs.fromBytes(new byte[0]), this.bs.fromBytes(new byte[0]), false);
while (iterator.hasNext()) {
HColumn<ByteBuffer, ByteBuffer> column = iterator.next();
updater.setValue(column.getName(), column.getValue(), this.bs);
}
template.update(updater);
} | [
"public",
"void",
"copy",
"(",
")",
"throws",
"HectorException",
"{",
"if",
"(",
"this",
".",
"cf",
"==",
"null",
")",
"{",
"throw",
"new",
"HectorException",
"(",
"\"Unable to clone row with null column family\"",
")",
";",
"}",
"if",
"(",
"this",
".",
"rowKey",
"==",
"null",
")",
"{",
"throw",
"new",
"HectorException",
"(",
"\"Unable to clone row with null row key\"",
")",
";",
"}",
"if",
"(",
"this",
".",
"destinationKey",
"==",
"null",
")",
"{",
"throw",
"new",
"HectorException",
"(",
"\"Unable to clone row with null clone key\"",
")",
";",
"}",
"ColumnFamilyTemplate",
"<",
"K",
",",
"ByteBuffer",
">",
"template",
"=",
"new",
"ThriftColumnFamilyTemplate",
"<",
"K",
",",
"ByteBuffer",
">",
"(",
"this",
".",
"keyspace",
",",
"this",
".",
"cf",
",",
"this",
".",
"keySerializer",
",",
"this",
".",
"bs",
")",
";",
"Mutator",
"<",
"K",
">",
"mutator",
"=",
"HFactory",
".",
"createMutator",
"(",
"this",
".",
"keyspace",
",",
"this",
".",
"keySerializer",
",",
"new",
"BatchSizeHint",
"(",
"1",
",",
"this",
".",
"mutateInterval",
")",
")",
";",
"ColumnFamilyUpdater",
"<",
"K",
",",
"ByteBuffer",
">",
"updater",
"=",
"template",
".",
"createUpdater",
"(",
"this",
".",
"destinationKey",
",",
"mutator",
")",
";",
"SliceQuery",
"<",
"K",
",",
"ByteBuffer",
",",
"ByteBuffer",
">",
"query",
"=",
"HFactory",
".",
"createSliceQuery",
"(",
"this",
".",
"keyspace",
",",
"this",
".",
"keySerializer",
",",
"this",
".",
"bs",
",",
"this",
".",
"bs",
")",
".",
"setColumnFamily",
"(",
"this",
".",
"cf",
")",
".",
"setKey",
"(",
"this",
".",
"rowKey",
")",
";",
"ColumnSliceIterator",
"<",
"K",
",",
"ByteBuffer",
",",
"ByteBuffer",
">",
"iterator",
"=",
"new",
"ColumnSliceIterator",
"<",
"K",
",",
"ByteBuffer",
",",
"ByteBuffer",
">",
"(",
"query",
",",
"this",
".",
"bs",
".",
"fromBytes",
"(",
"new",
"byte",
"[",
"0",
"]",
")",
",",
"this",
".",
"bs",
".",
"fromBytes",
"(",
"new",
"byte",
"[",
"0",
"]",
")",
",",
"false",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"HColumn",
"<",
"ByteBuffer",
",",
"ByteBuffer",
">",
"column",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"updater",
".",
"setValue",
"(",
"column",
".",
"getName",
"(",
")",
",",
"column",
".",
"getValue",
"(",
")",
",",
"this",
".",
"bs",
")",
";",
"}",
"template",
".",
"update",
"(",
"updater",
")",
";",
"}"
] | Copy the source row to the destination row.
@throws HectorException if any required fields are not set | [
"Copy",
"the",
"source",
"row",
"to",
"the",
"destination",
"row",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/ColumnFamilyRowCopy.java#L85-L111 |
2,887 | hector-client/hector | object-mapper/src/main/java/me/prettyprint/hom/CFMappingDef.java | CFMappingDef.setDefaults | @SuppressWarnings("unchecked")
public void setDefaults(Class<T> realClass) {
this.realClass = realClass;
this.keyDef = new KeyDefinition();
// find the "effective" class - skipping up the hierarchy over inner classes
effectiveClass = realClass;
boolean entityFound;
while (!(entityFound = (null != effectiveClass.getAnnotation(Entity.class)))) {
// TODO:BTB this might should be isSynthetic
if (!effectiveClass.isAnonymousClass()) {
break;
} else {
effectiveClass = (Class<T>) effectiveClass.getSuperclass();
}
}
// if class is missing @Entity, then proceed no further
if (!entityFound) {
throw new HomMissingEntityAnnotationException("class, " + realClass.getName()
+ ", not annotated with @" + Entity.class.getSimpleName());
}
} | java | @SuppressWarnings("unchecked")
public void setDefaults(Class<T> realClass) {
this.realClass = realClass;
this.keyDef = new KeyDefinition();
// find the "effective" class - skipping up the hierarchy over inner classes
effectiveClass = realClass;
boolean entityFound;
while (!(entityFound = (null != effectiveClass.getAnnotation(Entity.class)))) {
// TODO:BTB this might should be isSynthetic
if (!effectiveClass.isAnonymousClass()) {
break;
} else {
effectiveClass = (Class<T>) effectiveClass.getSuperclass();
}
}
// if class is missing @Entity, then proceed no further
if (!entityFound) {
throw new HomMissingEntityAnnotationException("class, " + realClass.getName()
+ ", not annotated with @" + Entity.class.getSimpleName());
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"void",
"setDefaults",
"(",
"Class",
"<",
"T",
">",
"realClass",
")",
"{",
"this",
".",
"realClass",
"=",
"realClass",
";",
"this",
".",
"keyDef",
"=",
"new",
"KeyDefinition",
"(",
")",
";",
"// find the \"effective\" class - skipping up the hierarchy over inner classes",
"effectiveClass",
"=",
"realClass",
";",
"boolean",
"entityFound",
";",
"while",
"(",
"!",
"(",
"entityFound",
"=",
"(",
"null",
"!=",
"effectiveClass",
".",
"getAnnotation",
"(",
"Entity",
".",
"class",
")",
")",
")",
")",
"{",
"// TODO:BTB this might should be isSynthetic",
"if",
"(",
"!",
"effectiveClass",
".",
"isAnonymousClass",
"(",
")",
")",
"{",
"break",
";",
"}",
"else",
"{",
"effectiveClass",
"=",
"(",
"Class",
"<",
"T",
">",
")",
"effectiveClass",
".",
"getSuperclass",
"(",
")",
";",
"}",
"}",
"// if class is missing @Entity, then proceed no further",
"if",
"(",
"!",
"entityFound",
")",
"{",
"throw",
"new",
"HomMissingEntityAnnotationException",
"(",
"\"class, \"",
"+",
"realClass",
".",
"getName",
"(",
")",
"+",
"\", not annotated with @\"",
"+",
"Entity",
".",
"class",
".",
"getSimpleName",
"(",
")",
")",
";",
"}",
"}"
] | Setup mapping with defaults for the given class. Does not parse all
annotations.
@param realClass | [
"Setup",
"mapping",
"with",
"defaults",
"for",
"the",
"given",
"class",
".",
"Does",
"not",
"parse",
"all",
"annotations",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/object-mapper/src/main/java/me/prettyprint/hom/CFMappingDef.java#L67-L89 |
2,888 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/CassandraHost.java | CassandraHost.isPerformNameResolution | public boolean isPerformNameResolution() {
String sysprop = System.getProperty(
SystemProperties.HECTOR_PERFORM_NAME_RESOLUTION.toString());
return sysprop != null && Boolean.parseBoolean(sysprop);
} | java | public boolean isPerformNameResolution() {
String sysprop = System.getProperty(
SystemProperties.HECTOR_PERFORM_NAME_RESOLUTION.toString());
return sysprop != null && Boolean.parseBoolean(sysprop);
} | [
"public",
"boolean",
"isPerformNameResolution",
"(",
")",
"{",
"String",
"sysprop",
"=",
"System",
".",
"getProperty",
"(",
"SystemProperties",
".",
"HECTOR_PERFORM_NAME_RESOLUTION",
".",
"toString",
"(",
")",
")",
";",
"return",
"sysprop",
"!=",
"null",
"&&",
"Boolean",
".",
"parseBoolean",
"(",
"sysprop",
")",
";",
"}"
] | Checks whether name resolution should occur.
@return | [
"Checks",
"whether",
"name",
"resolution",
"should",
"occur",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/CassandraHost.java#L117-L122 |
2,889 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/CassandraHostConfigurator.java | CassandraHostConfigurator.setAutoDiscoveryDataCenter | public void setAutoDiscoveryDataCenter(String dataCenter) {
if (StringUtils.isNotBlank(dataCenter)) {
this.autoDiscoveryDataCenters = Arrays.asList(dataCenter);
}
} | java | public void setAutoDiscoveryDataCenter(String dataCenter) {
if (StringUtils.isNotBlank(dataCenter)) {
this.autoDiscoveryDataCenters = Arrays.asList(dataCenter);
}
} | [
"public",
"void",
"setAutoDiscoveryDataCenter",
"(",
"String",
"dataCenter",
")",
"{",
"if",
"(",
"StringUtils",
".",
"isNotBlank",
"(",
"dataCenter",
")",
")",
"{",
"this",
".",
"autoDiscoveryDataCenters",
"=",
"Arrays",
".",
"asList",
"(",
"dataCenter",
")",
";",
"}",
"}"
] | Sets the local datacenter for the DiscoveryService. Nodes out of this
datacenter will be discarded. For configuration simplicity, you can provide
an empty or null string with the effect being the same as if you had not set
this property.
@param dataCenter DataCenter name | [
"Sets",
"the",
"local",
"datacenter",
"for",
"the",
"DiscoveryService",
".",
"Nodes",
"out",
"of",
"this",
"datacenter",
"will",
"be",
"discarded",
".",
"For",
"configuration",
"simplicity",
"you",
"can",
"provide",
"an",
"empty",
"or",
"null",
"string",
"with",
"the",
"effect",
"being",
"the",
"same",
"as",
"if",
"you",
"had",
"not",
"set",
"this",
"property",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/CassandraHostConfigurator.java#L259-L263 |
2,890 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/model/HSlicePredicate.java | HSlicePredicate.setColumnNames | public HSlicePredicate<N> setColumnNames(Collection<N> columnNames) {
this.columnNames = columnNames;
predicateType = PredicateType.ColumnNames;
return this;
} | java | public HSlicePredicate<N> setColumnNames(Collection<N> columnNames) {
this.columnNames = columnNames;
predicateType = PredicateType.ColumnNames;
return this;
} | [
"public",
"HSlicePredicate",
"<",
"N",
">",
"setColumnNames",
"(",
"Collection",
"<",
"N",
">",
"columnNames",
")",
"{",
"this",
".",
"columnNames",
"=",
"columnNames",
";",
"predicateType",
"=",
"PredicateType",
".",
"ColumnNames",
";",
"return",
"this",
";",
"}"
] | Same as varargs signature, except we take a collection
@param columns
a list of column names | [
"Same",
"as",
"varargs",
"signature",
"except",
"we",
"take",
"a",
"collection"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/model/HSlicePredicate.java#L67-L71 |
2,891 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/model/HSlicePredicate.java | HSlicePredicate.toThrift | public SlicePredicate toThrift() {
SlicePredicate pred = new SlicePredicate();
switch (predicateType) {
case ColumnNames:
if (columnNames == null ) {
return null;
}
pred.setColumn_names(toThriftColumnNames(columnNames));
break;
case Range:
Assert.isTrue(countSet, "Count was not set, neither were column-names set, can't execute");
SliceRange range = new SliceRange(findBytes(start), findBytes(finish), reversed, count);
pred.setSlice_range(range);
break;
case Unknown:
default:
throw new HectorException(
"Neither column names nor range were set, this is an invalid slice predicate");
}
return pred;
} | java | public SlicePredicate toThrift() {
SlicePredicate pred = new SlicePredicate();
switch (predicateType) {
case ColumnNames:
if (columnNames == null ) {
return null;
}
pred.setColumn_names(toThriftColumnNames(columnNames));
break;
case Range:
Assert.isTrue(countSet, "Count was not set, neither were column-names set, can't execute");
SliceRange range = new SliceRange(findBytes(start), findBytes(finish), reversed, count);
pred.setSlice_range(range);
break;
case Unknown:
default:
throw new HectorException(
"Neither column names nor range were set, this is an invalid slice predicate");
}
return pred;
} | [
"public",
"SlicePredicate",
"toThrift",
"(",
")",
"{",
"SlicePredicate",
"pred",
"=",
"new",
"SlicePredicate",
"(",
")",
";",
"switch",
"(",
"predicateType",
")",
"{",
"case",
"ColumnNames",
":",
"if",
"(",
"columnNames",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"pred",
".",
"setColumn_names",
"(",
"toThriftColumnNames",
"(",
"columnNames",
")",
")",
";",
"break",
";",
"case",
"Range",
":",
"Assert",
".",
"isTrue",
"(",
"countSet",
",",
"\"Count was not set, neither were column-names set, can't execute\"",
")",
";",
"SliceRange",
"range",
"=",
"new",
"SliceRange",
"(",
"findBytes",
"(",
"start",
")",
",",
"findBytes",
"(",
"finish",
")",
",",
"reversed",
",",
"count",
")",
";",
"pred",
".",
"setSlice_range",
"(",
"range",
")",
";",
"break",
";",
"case",
"Unknown",
":",
"default",
":",
"throw",
"new",
"HectorException",
"(",
"\"Neither column names nor range were set, this is an invalid slice predicate\"",
")",
";",
"}",
"return",
"pred",
";",
"}"
] | Will throw a runtime exception if neither columnsNames nor count were set.
@return | [
"Will",
"throw",
"a",
"runtime",
"exception",
"if",
"neither",
"columnsNames",
"nor",
"count",
"were",
"set",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/model/HSlicePredicate.java#L159-L180 |
2,892 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/utils/StringUtils.java | StringUtils.bytes | public static byte[] bytes(String s) {
try {
return s.getBytes(ENCODING);
} catch (UnsupportedEncodingException e) {
log.error("UnsupportedEncodingException ", e);
throw new RuntimeException(e);
}
} | java | public static byte[] bytes(String s) {
try {
return s.getBytes(ENCODING);
} catch (UnsupportedEncodingException e) {
log.error("UnsupportedEncodingException ", e);
throw new RuntimeException(e);
}
} | [
"public",
"static",
"byte",
"[",
"]",
"bytes",
"(",
"String",
"s",
")",
"{",
"try",
"{",
"return",
"s",
".",
"getBytes",
"(",
"ENCODING",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"UnsupportedEncodingException \"",
",",
"e",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] | Gets UTF-8 bytes from the string.
@param s
@return | [
"Gets",
"UTF",
"-",
"8",
"bytes",
"from",
"the",
"string",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/utils/StringUtils.java#L26-L33 |
2,893 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/utils/StringUtils.java | StringUtils.string | public static String string(byte[] bytes) {
if (bytes == null) {
return null;
}
try {
return new String(bytes, ENCODING);
} catch (UnsupportedEncodingException e) {
log.error("UnsupportedEncodingException ", e);
throw new RuntimeException(e);
}
} | java | public static String string(byte[] bytes) {
if (bytes == null) {
return null;
}
try {
return new String(bytes, ENCODING);
} catch (UnsupportedEncodingException e) {
log.error("UnsupportedEncodingException ", e);
throw new RuntimeException(e);
}
} | [
"public",
"static",
"String",
"string",
"(",
"byte",
"[",
"]",
"bytes",
")",
"{",
"if",
"(",
"bytes",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"return",
"new",
"String",
"(",
"bytes",
",",
"ENCODING",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"log",
".",
"error",
"(",
"\"UnsupportedEncodingException \"",
",",
"e",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] | Utility for converting bytes to strings. UTF-8 is assumed.
@param bytes
@return | [
"Utility",
"for",
"converting",
"bytes",
"to",
"strings",
".",
"UTF",
"-",
"8",
"is",
"assumed",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/utils/StringUtils.java#L40-L50 |
2,894 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/examples/ExampleDaoV2.java | ExampleDaoV2.insertMulti | public <K> void insertMulti(Map<K, String> keyValues, Serializer<K> keySerializer) {
Mutator<K> m = createMutator(keyspace, keySerializer);
for (Map.Entry<K, String> keyValue: keyValues.entrySet()) {
m.addInsertion(keyValue.getKey(), CF_NAME,
createColumn(COLUMN_NAME, keyValue.getValue(), keyspace.createClock(), serializer, serializer));
}
m.execute();
} | java | public <K> void insertMulti(Map<K, String> keyValues, Serializer<K> keySerializer) {
Mutator<K> m = createMutator(keyspace, keySerializer);
for (Map.Entry<K, String> keyValue: keyValues.entrySet()) {
m.addInsertion(keyValue.getKey(), CF_NAME,
createColumn(COLUMN_NAME, keyValue.getValue(), keyspace.createClock(), serializer, serializer));
}
m.execute();
} | [
"public",
"<",
"K",
">",
"void",
"insertMulti",
"(",
"Map",
"<",
"K",
",",
"String",
">",
"keyValues",
",",
"Serializer",
"<",
"K",
">",
"keySerializer",
")",
"{",
"Mutator",
"<",
"K",
">",
"m",
"=",
"createMutator",
"(",
"keyspace",
",",
"keySerializer",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"K",
",",
"String",
">",
"keyValue",
":",
"keyValues",
".",
"entrySet",
"(",
")",
")",
"{",
"m",
".",
"addInsertion",
"(",
"keyValue",
".",
"getKey",
"(",
")",
",",
"CF_NAME",
",",
"createColumn",
"(",
"COLUMN_NAME",
",",
"keyValue",
".",
"getValue",
"(",
")",
",",
"keyspace",
".",
"createClock",
"(",
")",
",",
"serializer",
",",
"serializer",
")",
")",
";",
"}",
"m",
".",
"execute",
"(",
")",
";",
"}"
] | Insert multiple values | [
"Insert",
"multiple",
"values"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/examples/ExampleDaoV2.java#L105-L112 |
2,895 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/io/ChunkInputStream.java | ChunkInputStream.fetchChunk | private boolean fetchChunk() throws IOException {
try {
ColumnQuery<T, Long, byte[]> query = HFactory.createColumnQuery(keyspace, rowKeySerializer, LongSerializer.get(), BytesArraySerializer.get());
QueryResult<HColumn<Long, byte[]>> result = query.setColumnFamily(cf).setKey(key).setName(chunkPos).execute();
HColumn<Long, byte[]> column = result.get();
if (column != null) {
chunk = column.getValue();
chunkPos++;
pos = 0;
return true;
} else {
return false;
}
} catch (HectorException e) {
throw new IOException("Unable to read data", e);
}
} | java | private boolean fetchChunk() throws IOException {
try {
ColumnQuery<T, Long, byte[]> query = HFactory.createColumnQuery(keyspace, rowKeySerializer, LongSerializer.get(), BytesArraySerializer.get());
QueryResult<HColumn<Long, byte[]>> result = query.setColumnFamily(cf).setKey(key).setName(chunkPos).execute();
HColumn<Long, byte[]> column = result.get();
if (column != null) {
chunk = column.getValue();
chunkPos++;
pos = 0;
return true;
} else {
return false;
}
} catch (HectorException e) {
throw new IOException("Unable to read data", e);
}
} | [
"private",
"boolean",
"fetchChunk",
"(",
")",
"throws",
"IOException",
"{",
"try",
"{",
"ColumnQuery",
"<",
"T",
",",
"Long",
",",
"byte",
"[",
"]",
">",
"query",
"=",
"HFactory",
".",
"createColumnQuery",
"(",
"keyspace",
",",
"rowKeySerializer",
",",
"LongSerializer",
".",
"get",
"(",
")",
",",
"BytesArraySerializer",
".",
"get",
"(",
")",
")",
";",
"QueryResult",
"<",
"HColumn",
"<",
"Long",
",",
"byte",
"[",
"]",
">",
">",
"result",
"=",
"query",
".",
"setColumnFamily",
"(",
"cf",
")",
".",
"setKey",
"(",
"key",
")",
".",
"setName",
"(",
"chunkPos",
")",
".",
"execute",
"(",
")",
";",
"HColumn",
"<",
"Long",
",",
"byte",
"[",
"]",
">",
"column",
"=",
"result",
".",
"get",
"(",
")",
";",
"if",
"(",
"column",
"!=",
"null",
")",
"{",
"chunk",
"=",
"column",
".",
"getValue",
"(",
")",
";",
"chunkPos",
"++",
";",
"pos",
"=",
"0",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"HectorException",
"e",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Unable to read data\"",
",",
"e",
")",
";",
"}",
"}"
] | Fetch the next chunk.
@return exists if there was a chunk to fetch.
@throws IOException | [
"Fetch",
"the",
"next",
"chunk",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/io/ChunkInputStream.java#L61-L78 |
2,896 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/model/thrift/ThriftConverter.java | ThriftConverter.getColumnList | public static List<Column> getColumnList(List<ColumnOrSuperColumn> columns) {
ArrayList<Column> list = new ArrayList<Column>(columns.size());
for (ColumnOrSuperColumn col : columns) {
list.add(col.getColumn());
}
return list;
} | java | public static List<Column> getColumnList(List<ColumnOrSuperColumn> columns) {
ArrayList<Column> list = new ArrayList<Column>(columns.size());
for (ColumnOrSuperColumn col : columns) {
list.add(col.getColumn());
}
return list;
} | [
"public",
"static",
"List",
"<",
"Column",
">",
"getColumnList",
"(",
"List",
"<",
"ColumnOrSuperColumn",
">",
"columns",
")",
"{",
"ArrayList",
"<",
"Column",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"Column",
">",
"(",
"columns",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"ColumnOrSuperColumn",
"col",
":",
"columns",
")",
"{",
"list",
".",
"add",
"(",
"col",
".",
"getColumn",
"(",
")",
")",
";",
"}",
"return",
"list",
";",
"}"
] | Converts a list of ColumnOrSuperColumn to Column
@param columns
@return | [
"Converts",
"a",
"list",
"of",
"ColumnOrSuperColumn",
"to",
"Column"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/model/thrift/ThriftConverter.java#L48-L54 |
2,897 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/service/HColumnFamilyImpl.java | HColumnFamilyImpl.getValue | @Override
public <V> V getValue(N name, Serializer<V> valueSerializer) {
return extractColumnValue(name, valueSerializer);
} | java | @Override
public <V> V getValue(N name, Serializer<V> valueSerializer) {
return extractColumnValue(name, valueSerializer);
} | [
"@",
"Override",
"public",
"<",
"V",
">",
"V",
"getValue",
"(",
"N",
"name",
",",
"Serializer",
"<",
"V",
">",
"valueSerializer",
")",
"{",
"return",
"extractColumnValue",
"(",
"name",
",",
"valueSerializer",
")",
";",
"}"
] | Extract a value for the specified name and serializer | [
"Extract",
"a",
"value",
"for",
"the",
"specified",
"name",
"and",
"serializer"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/service/HColumnFamilyImpl.java#L219-L222 |
2,898 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/locking/HLockManagerImpl.java | HLockManagerImpl.setAcquired | private void setAcquired(HLock lock, Map<String, String> canBeEarlier) {
// start the heartbeat
Future<Void> heartbeat = scheduler.schedule(new Heartbeat(lock), lockTtl / 2, TimeUnit.MILLISECONDS);
((HLockImpl) lock).setHeartbeat(heartbeat);
((HLockImpl) lock).setAcquired(true);
if (logger.isDebugEnabled()) {
logLock(lock, canBeEarlier.keySet());
}
} | java | private void setAcquired(HLock lock, Map<String, String> canBeEarlier) {
// start the heartbeat
Future<Void> heartbeat = scheduler.schedule(new Heartbeat(lock), lockTtl / 2, TimeUnit.MILLISECONDS);
((HLockImpl) lock).setHeartbeat(heartbeat);
((HLockImpl) lock).setAcquired(true);
if (logger.isDebugEnabled()) {
logLock(lock, canBeEarlier.keySet());
}
} | [
"private",
"void",
"setAcquired",
"(",
"HLock",
"lock",
",",
"Map",
"<",
"String",
",",
"String",
">",
"canBeEarlier",
")",
"{",
"// start the heartbeat",
"Future",
"<",
"Void",
">",
"heartbeat",
"=",
"scheduler",
".",
"schedule",
"(",
"new",
"Heartbeat",
"(",
"lock",
")",
",",
"lockTtl",
"/",
"2",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"(",
"(",
"HLockImpl",
")",
"lock",
")",
".",
"setHeartbeat",
"(",
"heartbeat",
")",
";",
"(",
"(",
"HLockImpl",
")",
"lock",
")",
".",
"setAcquired",
"(",
"true",
")",
";",
"if",
"(",
"logger",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"logLock",
"(",
"lock",
",",
"canBeEarlier",
".",
"keySet",
"(",
")",
")",
";",
"}",
"}"
] | Start the heartbeat thread before we return
@param lock | [
"Start",
"the",
"heartbeat",
"thread",
"before",
"we",
"return"
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/locking/HLockManagerImpl.java#L156-L168 |
2,899 | hector-client/hector | core/src/main/java/me/prettyprint/cassandra/model/CqlQuery.java | CqlQuery.execute | @Override
public QueryResult<CqlRows<K, N, V>> execute() {
return new QueryResultImpl<CqlRows<K, N, V>>(
keyspace.doExecuteOperation(new Operation<CqlRows<K, N, V>>(OperationType.READ) {
@Override
public CqlRows<K, N, V> execute(Client cassandra) throws HectorException {
CqlRows<K, N, V> rows = null;
try {
if (cqlVersion != null) {
cassandra.set_cql_version(cqlVersion);
}
CqlResult result = null;
if (cql3) {
result = cassandra.execute_cql3_query(query,
useCompression ? Compression.GZIP : Compression.NONE, ThriftConverter.consistencyLevel(getConsistency()));
} else {
result = cassandra.execute_cql_query(query,
useCompression ? Compression.GZIP : Compression.NONE);
}
if ( log.isDebugEnabled() ) {
log.debug("Found CqlResult: {}", result);
}
switch (result.getType()) {
case VOID:
rows = new CqlRows<K, N, V>();
break;
default:
if ( result.getRowsSize() > 0 ) {
LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>(result.getRowsSize());
int keyColumnIndex = -1;
for (Iterator<CqlRow> rowsIter = result.getRowsIterator(); rowsIter.hasNext(); ) {
CqlRow row = rowsIter.next();
ByteBuffer kbb = ByteBuffer.wrap(row.getKey());
// if CQL3 is used row.getKey() always returns null, so we have
// to find the KEY in the columns.
if (cql3) {
List<Column> rowcolumns = row.getColumns();
// first time through we find the column and then use the
// column index to avoid needless work.
if (keyColumnIndex == -1) {
for (Column c: rowcolumns) {
keyColumnIndex++;
String name = StringSerializer.get().fromBytes(c.getName());
if (name.toUpperCase().equals("KEY")) {
kbb = ByteBuffer.wrap(c.getValue());
break;
}
}
} else {
kbb = ByteBuffer.wrap(row.getColumns().get(keyColumnIndex).getValue());
}
}
ret.put(kbb, filterKeyColumn(row));
}
Map<K, List<Column>> thriftRet = keySerializer.fromBytesMap(ret);
rows = new CqlRows<K, N, V>((LinkedHashMap<K, List<Column>>)thriftRet, columnNameSerializer, valueSerializer);
}
break;
}
} catch (Exception ex) {
throw keyspace.getExceptionsTranslator().translate(ex);
}
return rows;
}
}), this);
} | java | @Override
public QueryResult<CqlRows<K, N, V>> execute() {
return new QueryResultImpl<CqlRows<K, N, V>>(
keyspace.doExecuteOperation(new Operation<CqlRows<K, N, V>>(OperationType.READ) {
@Override
public CqlRows<K, N, V> execute(Client cassandra) throws HectorException {
CqlRows<K, N, V> rows = null;
try {
if (cqlVersion != null) {
cassandra.set_cql_version(cqlVersion);
}
CqlResult result = null;
if (cql3) {
result = cassandra.execute_cql3_query(query,
useCompression ? Compression.GZIP : Compression.NONE, ThriftConverter.consistencyLevel(getConsistency()));
} else {
result = cassandra.execute_cql_query(query,
useCompression ? Compression.GZIP : Compression.NONE);
}
if ( log.isDebugEnabled() ) {
log.debug("Found CqlResult: {}", result);
}
switch (result.getType()) {
case VOID:
rows = new CqlRows<K, N, V>();
break;
default:
if ( result.getRowsSize() > 0 ) {
LinkedHashMap<ByteBuffer, List<Column>> ret = new LinkedHashMap<ByteBuffer, List<Column>>(result.getRowsSize());
int keyColumnIndex = -1;
for (Iterator<CqlRow> rowsIter = result.getRowsIterator(); rowsIter.hasNext(); ) {
CqlRow row = rowsIter.next();
ByteBuffer kbb = ByteBuffer.wrap(row.getKey());
// if CQL3 is used row.getKey() always returns null, so we have
// to find the KEY in the columns.
if (cql3) {
List<Column> rowcolumns = row.getColumns();
// first time through we find the column and then use the
// column index to avoid needless work.
if (keyColumnIndex == -1) {
for (Column c: rowcolumns) {
keyColumnIndex++;
String name = StringSerializer.get().fromBytes(c.getName());
if (name.toUpperCase().equals("KEY")) {
kbb = ByteBuffer.wrap(c.getValue());
break;
}
}
} else {
kbb = ByteBuffer.wrap(row.getColumns().get(keyColumnIndex).getValue());
}
}
ret.put(kbb, filterKeyColumn(row));
}
Map<K, List<Column>> thriftRet = keySerializer.fromBytesMap(ret);
rows = new CqlRows<K, N, V>((LinkedHashMap<K, List<Column>>)thriftRet, columnNameSerializer, valueSerializer);
}
break;
}
} catch (Exception ex) {
throw keyspace.getExceptionsTranslator().translate(ex);
}
return rows;
}
}), this);
} | [
"@",
"Override",
"public",
"QueryResult",
"<",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
">",
"execute",
"(",
")",
"{",
"return",
"new",
"QueryResultImpl",
"<",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
">",
"(",
"keyspace",
".",
"doExecuteOperation",
"(",
"new",
"Operation",
"<",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
">",
"(",
"OperationType",
".",
"READ",
")",
"{",
"@",
"Override",
"public",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
"execute",
"(",
"Client",
"cassandra",
")",
"throws",
"HectorException",
"{",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
"rows",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"cqlVersion",
"!=",
"null",
")",
"{",
"cassandra",
".",
"set_cql_version",
"(",
"cqlVersion",
")",
";",
"}",
"CqlResult",
"result",
"=",
"null",
";",
"if",
"(",
"cql3",
")",
"{",
"result",
"=",
"cassandra",
".",
"execute_cql3_query",
"(",
"query",
",",
"useCompression",
"?",
"Compression",
".",
"GZIP",
":",
"Compression",
".",
"NONE",
",",
"ThriftConverter",
".",
"consistencyLevel",
"(",
"getConsistency",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"result",
"=",
"cassandra",
".",
"execute_cql_query",
"(",
"query",
",",
"useCompression",
"?",
"Compression",
".",
"GZIP",
":",
"Compression",
".",
"NONE",
")",
";",
"}",
"if",
"(",
"log",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"log",
".",
"debug",
"(",
"\"Found CqlResult: {}\"",
",",
"result",
")",
";",
"}",
"switch",
"(",
"result",
".",
"getType",
"(",
")",
")",
"{",
"case",
"VOID",
":",
"rows",
"=",
"new",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
"(",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"result",
".",
"getRowsSize",
"(",
")",
">",
"0",
")",
"{",
"LinkedHashMap",
"<",
"ByteBuffer",
",",
"List",
"<",
"Column",
">",
">",
"ret",
"=",
"new",
"LinkedHashMap",
"<",
"ByteBuffer",
",",
"List",
"<",
"Column",
">",
">",
"(",
"result",
".",
"getRowsSize",
"(",
")",
")",
";",
"int",
"keyColumnIndex",
"=",
"-",
"1",
";",
"for",
"(",
"Iterator",
"<",
"CqlRow",
">",
"rowsIter",
"=",
"result",
".",
"getRowsIterator",
"(",
")",
";",
"rowsIter",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"CqlRow",
"row",
"=",
"rowsIter",
".",
"next",
"(",
")",
";",
"ByteBuffer",
"kbb",
"=",
"ByteBuffer",
".",
"wrap",
"(",
"row",
".",
"getKey",
"(",
")",
")",
";",
"// if CQL3 is used row.getKey() always returns null, so we have",
"// to find the KEY in the columns.",
"if",
"(",
"cql3",
")",
"{",
"List",
"<",
"Column",
">",
"rowcolumns",
"=",
"row",
".",
"getColumns",
"(",
")",
";",
"// first time through we find the column and then use the",
"// column index to avoid needless work.",
"if",
"(",
"keyColumnIndex",
"==",
"-",
"1",
")",
"{",
"for",
"(",
"Column",
"c",
":",
"rowcolumns",
")",
"{",
"keyColumnIndex",
"++",
";",
"String",
"name",
"=",
"StringSerializer",
".",
"get",
"(",
")",
".",
"fromBytes",
"(",
"c",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"name",
".",
"toUpperCase",
"(",
")",
".",
"equals",
"(",
"\"KEY\"",
")",
")",
"{",
"kbb",
"=",
"ByteBuffer",
".",
"wrap",
"(",
"c",
".",
"getValue",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"kbb",
"=",
"ByteBuffer",
".",
"wrap",
"(",
"row",
".",
"getColumns",
"(",
")",
".",
"get",
"(",
"keyColumnIndex",
")",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"ret",
".",
"put",
"(",
"kbb",
",",
"filterKeyColumn",
"(",
"row",
")",
")",
";",
"}",
"Map",
"<",
"K",
",",
"List",
"<",
"Column",
">",
">",
"thriftRet",
"=",
"keySerializer",
".",
"fromBytesMap",
"(",
"ret",
")",
";",
"rows",
"=",
"new",
"CqlRows",
"<",
"K",
",",
"N",
",",
"V",
">",
"(",
"(",
"LinkedHashMap",
"<",
"K",
",",
"List",
"<",
"Column",
">",
">",
")",
"thriftRet",
",",
"columnNameSerializer",
",",
"valueSerializer",
")",
";",
"}",
"break",
";",
"}",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"keyspace",
".",
"getExceptionsTranslator",
"(",
")",
".",
"translate",
"(",
"ex",
")",
";",
"}",
"return",
"rows",
";",
"}",
"}",
")",
",",
"this",
")",
";",
"}"
] | For future releases, we should consider refactoring how execute
method converts the thrift CqlResult to Hector CqlRows. Starting
with CQL3 the KEY is no longer returned by default and is no
longer treated as a "special" thing. To get the KEY from the
resultset, we have to look at the columns. Using the KEY
in CqlRows is nice, and makes it easy to get results by the KEY.
The downside is that users have to explicitly include the KEY in
the statement. Changing how CqlRows work "might" break some
existing use cases. For now, the implementation finds the column
and expects the statement to have the KEY. | [
"For",
"future",
"releases",
"we",
"should",
"consider",
"refactoring",
"how",
"execute",
"method",
"converts",
"the",
"thrift",
"CqlResult",
"to",
"Hector",
"CqlRows",
".",
"Starting",
"with",
"CQL3",
"the",
"KEY",
"is",
"no",
"longer",
"returned",
"by",
"default",
"and",
"is",
"no",
"longer",
"treated",
"as",
"a",
"special",
"thing",
".",
"To",
"get",
"the",
"KEY",
"from",
"the",
"resultset",
"we",
"have",
"to",
"look",
"at",
"the",
"columns",
".",
"Using",
"the",
"KEY",
"in",
"CqlRows",
"is",
"nice",
"and",
"makes",
"it",
"easy",
"to",
"get",
"results",
"by",
"the",
"KEY",
".",
"The",
"downside",
"is",
"that",
"users",
"have",
"to",
"explicitly",
"include",
"the",
"KEY",
"in",
"the",
"statement",
".",
"Changing",
"how",
"CqlRows",
"work",
"might",
"break",
"some",
"existing",
"use",
"cases",
".",
"For",
"now",
"the",
"implementation",
"finds",
"the",
"column",
"and",
"expects",
"the",
"statement",
"to",
"have",
"the",
"KEY",
"."
] | a302e68ca8d91b45d332e8c9afd7d98030b54de1 | https://github.com/hector-client/hector/blob/a302e68ca8d91b45d332e8c9afd7d98030b54de1/core/src/main/java/me/prettyprint/cassandra/model/CqlQuery.java#L132-L201 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.