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
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
12,100
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java
|
VarTensor.prod
|
public void prod(VarTensor f) {
VarTensor newFactor = applyBinOp(this, f, new AlgebraLambda.Prod());
internalSet(newFactor);
}
|
java
|
public void prod(VarTensor f) {
VarTensor newFactor = applyBinOp(this, f, new AlgebraLambda.Prod());
internalSet(newFactor);
}
|
[
"public",
"void",
"prod",
"(",
"VarTensor",
"f",
")",
"{",
"VarTensor",
"newFactor",
"=",
"applyBinOp",
"(",
"this",
",",
"f",
",",
"new",
"AlgebraLambda",
".",
"Prod",
"(",
")",
")",
";",
"internalSet",
"(",
"newFactor",
")",
";",
"}"
] |
Multiplies a factor to this one.
From libDAI:
The product of two factors is defined as follows: if
\f$f : \prod_{l\in L} X_l \to [0,\infty)\f$ and \f$g : \prod_{m\in M} X_m \to [0,\infty)\f$, then
\f[fg : \prod_{l\in L\cup M} X_l \to [0,\infty) : x \mapsto f(x_L) g(x_M).\f]
|
[
"Multiplies",
"a",
"factor",
"to",
"this",
"one",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java#L133-L136
|
12,101
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java
|
VarTensor.internalSet
|
private void internalSet(VarTensor newFactor) {
this.vars = newFactor.vars;
this.dims = newFactor.dims;
this.strides = newFactor.strides;
this.values = newFactor.values;
}
|
java
|
private void internalSet(VarTensor newFactor) {
this.vars = newFactor.vars;
this.dims = newFactor.dims;
this.strides = newFactor.strides;
this.values = newFactor.values;
}
|
[
"private",
"void",
"internalSet",
"(",
"VarTensor",
"newFactor",
")",
"{",
"this",
".",
"vars",
"=",
"newFactor",
".",
"vars",
";",
"this",
".",
"dims",
"=",
"newFactor",
".",
"dims",
";",
"this",
".",
"strides",
"=",
"newFactor",
".",
"strides",
";",
"this",
".",
"values",
"=",
"newFactor",
".",
"values",
";",
"}"
] |
This set method is used to internally update ALL the fields.
|
[
"This",
"set",
"method",
"is",
"used",
"to",
"internally",
"update",
"ALL",
"the",
"fields",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java#L156-L161
|
12,102
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java
|
VarTensor.applyBinOp
|
private static VarTensor applyBinOp(final VarTensor f1, final VarTensor f2, final AlgebraLambda.LambdaBinOp op) {
checkSameAlgebra(f1, f2);
Algebra s = f1.s;
if (f1.vars.size() == 0) {
// Return a copy of f2.
return new VarTensor(f2);
} else if (f2.vars.size() == 0) {
// Don't use the copy constructor, just return f1.
return f1;
} else if (f1.vars == f2.vars || f1.vars.equals(f2.vars)) {
// Special case where the factors have identical variable sets.
assert (f1.values.length == f2.values.length);
for (int c = 0; c < f1.values.length; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[c]);
}
return f1;
} else if (f1.vars.isSuperset(f2.vars)) {
// Special case where f1 is a superset of f2.
IntIter iter2 = f2.vars.getConfigIter(f1.vars);
int n = f1.vars.calcNumConfigs();
for (int c = 0; c < n; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[iter2.next()]);
}
assert(!iter2.hasNext());
return f1;
} else {
// The union of the two variable sets must be created.
VarSet union = new VarSet(f1.vars, f2.vars);
VarTensor out = new VarTensor(s, union);
IntIter iter1 = f1.vars.getConfigIter(union);
IntIter iter2 = f2.vars.getConfigIter(union);
int n = out.vars.calcNumConfigs();
for (int c = 0; c < n; c++) {
out.values[c] = op.call(s, f1.values[iter1.next()], f2.values[iter2.next()]);
}
assert(!iter1.hasNext());
assert(!iter2.hasNext());
return out;
}
}
|
java
|
private static VarTensor applyBinOp(final VarTensor f1, final VarTensor f2, final AlgebraLambda.LambdaBinOp op) {
checkSameAlgebra(f1, f2);
Algebra s = f1.s;
if (f1.vars.size() == 0) {
// Return a copy of f2.
return new VarTensor(f2);
} else if (f2.vars.size() == 0) {
// Don't use the copy constructor, just return f1.
return f1;
} else if (f1.vars == f2.vars || f1.vars.equals(f2.vars)) {
// Special case where the factors have identical variable sets.
assert (f1.values.length == f2.values.length);
for (int c = 0; c < f1.values.length; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[c]);
}
return f1;
} else if (f1.vars.isSuperset(f2.vars)) {
// Special case where f1 is a superset of f2.
IntIter iter2 = f2.vars.getConfigIter(f1.vars);
int n = f1.vars.calcNumConfigs();
for (int c = 0; c < n; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[iter2.next()]);
}
assert(!iter2.hasNext());
return f1;
} else {
// The union of the two variable sets must be created.
VarSet union = new VarSet(f1.vars, f2.vars);
VarTensor out = new VarTensor(s, union);
IntIter iter1 = f1.vars.getConfigIter(union);
IntIter iter2 = f2.vars.getConfigIter(union);
int n = out.vars.calcNumConfigs();
for (int c = 0; c < n; c++) {
out.values[c] = op.call(s, f1.values[iter1.next()], f2.values[iter2.next()]);
}
assert(!iter1.hasNext());
assert(!iter2.hasNext());
return out;
}
}
|
[
"private",
"static",
"VarTensor",
"applyBinOp",
"(",
"final",
"VarTensor",
"f1",
",",
"final",
"VarTensor",
"f2",
",",
"final",
"AlgebraLambda",
".",
"LambdaBinOp",
"op",
")",
"{",
"checkSameAlgebra",
"(",
"f1",
",",
"f2",
")",
";",
"Algebra",
"s",
"=",
"f1",
".",
"s",
";",
"if",
"(",
"f1",
".",
"vars",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"// Return a copy of f2.",
"return",
"new",
"VarTensor",
"(",
"f2",
")",
";",
"}",
"else",
"if",
"(",
"f2",
".",
"vars",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"// Don't use the copy constructor, just return f1.",
"return",
"f1",
";",
"}",
"else",
"if",
"(",
"f1",
".",
"vars",
"==",
"f2",
".",
"vars",
"||",
"f1",
".",
"vars",
".",
"equals",
"(",
"f2",
".",
"vars",
")",
")",
"{",
"// Special case where the factors have identical variable sets.",
"assert",
"(",
"f1",
".",
"values",
".",
"length",
"==",
"f2",
".",
"values",
".",
"length",
")",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"f1",
".",
"values",
".",
"length",
";",
"c",
"++",
")",
"{",
"f1",
".",
"values",
"[",
"c",
"]",
"=",
"op",
".",
"call",
"(",
"s",
",",
"f1",
".",
"values",
"[",
"c",
"]",
",",
"f2",
".",
"values",
"[",
"c",
"]",
")",
";",
"}",
"return",
"f1",
";",
"}",
"else",
"if",
"(",
"f1",
".",
"vars",
".",
"isSuperset",
"(",
"f2",
".",
"vars",
")",
")",
"{",
"// Special case where f1 is a superset of f2.",
"IntIter",
"iter2",
"=",
"f2",
".",
"vars",
".",
"getConfigIter",
"(",
"f1",
".",
"vars",
")",
";",
"int",
"n",
"=",
"f1",
".",
"vars",
".",
"calcNumConfigs",
"(",
")",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"n",
";",
"c",
"++",
")",
"{",
"f1",
".",
"values",
"[",
"c",
"]",
"=",
"op",
".",
"call",
"(",
"s",
",",
"f1",
".",
"values",
"[",
"c",
"]",
",",
"f2",
".",
"values",
"[",
"iter2",
".",
"next",
"(",
")",
"]",
")",
";",
"}",
"assert",
"(",
"!",
"iter2",
".",
"hasNext",
"(",
")",
")",
";",
"return",
"f1",
";",
"}",
"else",
"{",
"// The union of the two variable sets must be created.",
"VarSet",
"union",
"=",
"new",
"VarSet",
"(",
"f1",
".",
"vars",
",",
"f2",
".",
"vars",
")",
";",
"VarTensor",
"out",
"=",
"new",
"VarTensor",
"(",
"s",
",",
"union",
")",
";",
"IntIter",
"iter1",
"=",
"f1",
".",
"vars",
".",
"getConfigIter",
"(",
"union",
")",
";",
"IntIter",
"iter2",
"=",
"f2",
".",
"vars",
".",
"getConfigIter",
"(",
"union",
")",
";",
"int",
"n",
"=",
"out",
".",
"vars",
".",
"calcNumConfigs",
"(",
")",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"n",
";",
"c",
"++",
")",
"{",
"out",
".",
"values",
"[",
"c",
"]",
"=",
"op",
".",
"call",
"(",
"s",
",",
"f1",
".",
"values",
"[",
"iter1",
".",
"next",
"(",
")",
"]",
",",
"f2",
".",
"values",
"[",
"iter2",
".",
"next",
"(",
")",
"]",
")",
";",
"}",
"assert",
"(",
"!",
"iter1",
".",
"hasNext",
"(",
")",
")",
";",
"assert",
"(",
"!",
"iter2",
".",
"hasNext",
"(",
")",
")",
";",
"return",
"out",
";",
"}",
"}"
] |
Applies the binary operator to factors f1 and f2.
This method will opt to be destructive on f1 (returning it instead of a
new factor) if time/space can be saved by doing so.
Note: destructive if necessary.
@param f1 The first factor. (returned if it will save time/space)
@param f2 The second factor.
@param op The binary operator.
@return The new factor.
|
[
"Applies",
"the",
"binary",
"operator",
"to",
"factors",
"f1",
"and",
"f2",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java#L176-L215
|
12,103
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java
|
VarTensor.elemApplyBinOp
|
private static void elemApplyBinOp(final VarTensor f1, final VarTensor f2, final AlgebraLambda.LambdaBinOp op) {
checkSameAlgebra(f1, f2);
Algebra s = f1.s;
if (f1.size() != f2.size()) {
throw new IllegalArgumentException("VarTensors are different sizes");
}
for (int c = 0; c < f1.values.length; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[c]);
}
}
|
java
|
private static void elemApplyBinOp(final VarTensor f1, final VarTensor f2, final AlgebraLambda.LambdaBinOp op) {
checkSameAlgebra(f1, f2);
Algebra s = f1.s;
if (f1.size() != f2.size()) {
throw new IllegalArgumentException("VarTensors are different sizes");
}
for (int c = 0; c < f1.values.length; c++) {
f1.values[c] = op.call(s, f1.values[c], f2.values[c]);
}
}
|
[
"private",
"static",
"void",
"elemApplyBinOp",
"(",
"final",
"VarTensor",
"f1",
",",
"final",
"VarTensor",
"f2",
",",
"final",
"AlgebraLambda",
".",
"LambdaBinOp",
"op",
")",
"{",
"checkSameAlgebra",
"(",
"f1",
",",
"f2",
")",
";",
"Algebra",
"s",
"=",
"f1",
".",
"s",
";",
"if",
"(",
"f1",
".",
"size",
"(",
")",
"!=",
"f2",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"VarTensors are different sizes\"",
")",
";",
"}",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"f1",
".",
"values",
".",
"length",
";",
"c",
"++",
")",
"{",
"f1",
".",
"values",
"[",
"c",
"]",
"=",
"op",
".",
"call",
"(",
"s",
",",
"f1",
".",
"values",
"[",
"c",
"]",
",",
"f2",
".",
"values",
"[",
"c",
"]",
")",
";",
"}",
"}"
] |
Applies the operation to each element of f1 and f2, which are assumed to be of the same size.
The result is stored in f1.
@param f1 Input factor 1 and the output factor.
@param f2 Input factor 2.
@param op The operation to apply.
|
[
"Applies",
"the",
"operation",
"to",
"each",
"element",
"of",
"f1",
"and",
"f2",
"which",
"are",
"assumed",
"to",
"be",
"of",
"the",
"same",
"size",
".",
"The",
"result",
"is",
"stored",
"in",
"f1",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarTensor.java#L225-L234
|
12,104
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/eval/AccuracyEvaluator.java
|
AccuracyEvaluator.evaluate
|
public double evaluate(List<VarConfig> goldConfigs, List<VarConfig> predictedConfigs) {
int numCorrect = 0;
int numTotal = 0;
assert (goldConfigs.size() == predictedConfigs.size());
for (int i=0; i<goldConfigs.size(); i++) {
VarConfig gold = goldConfigs.get(i);
VarConfig pred = predictedConfigs.get(i);
//assert (gold.getVars().equals(pred.getVars()));
for (Var v : gold.getVars()) {
if (v.getType() == VarType.PREDICTED) {
int goldState = gold.getState(v);
int predState = pred.getState(v);
if (goldState == predState) {
numCorrect++;
}
numTotal++;
}
}
}
return (double) numCorrect / numTotal;
}
|
java
|
public double evaluate(List<VarConfig> goldConfigs, List<VarConfig> predictedConfigs) {
int numCorrect = 0;
int numTotal = 0;
assert (goldConfigs.size() == predictedConfigs.size());
for (int i=0; i<goldConfigs.size(); i++) {
VarConfig gold = goldConfigs.get(i);
VarConfig pred = predictedConfigs.get(i);
//assert (gold.getVars().equals(pred.getVars()));
for (Var v : gold.getVars()) {
if (v.getType() == VarType.PREDICTED) {
int goldState = gold.getState(v);
int predState = pred.getState(v);
if (goldState == predState) {
numCorrect++;
}
numTotal++;
}
}
}
return (double) numCorrect / numTotal;
}
|
[
"public",
"double",
"evaluate",
"(",
"List",
"<",
"VarConfig",
">",
"goldConfigs",
",",
"List",
"<",
"VarConfig",
">",
"predictedConfigs",
")",
"{",
"int",
"numCorrect",
"=",
"0",
";",
"int",
"numTotal",
"=",
"0",
";",
"assert",
"(",
"goldConfigs",
".",
"size",
"(",
")",
"==",
"predictedConfigs",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"goldConfigs",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"VarConfig",
"gold",
"=",
"goldConfigs",
".",
"get",
"(",
"i",
")",
";",
"VarConfig",
"pred",
"=",
"predictedConfigs",
".",
"get",
"(",
"i",
")",
";",
"//assert (gold.getVars().equals(pred.getVars()));",
"for",
"(",
"Var",
"v",
":",
"gold",
".",
"getVars",
"(",
")",
")",
"{",
"if",
"(",
"v",
".",
"getType",
"(",
")",
"==",
"VarType",
".",
"PREDICTED",
")",
"{",
"int",
"goldState",
"=",
"gold",
".",
"getState",
"(",
"v",
")",
";",
"int",
"predState",
"=",
"pred",
".",
"getState",
"(",
"v",
")",
";",
"if",
"(",
"goldState",
"==",
"predState",
")",
"{",
"numCorrect",
"++",
";",
"}",
"numTotal",
"++",
";",
"}",
"}",
"}",
"return",
"(",
"double",
")",
"numCorrect",
"/",
"numTotal",
";",
"}"
] |
Computes the accuracy on the PREDICTED variables.
|
[
"Computes",
"the",
"accuracy",
"on",
"the",
"PREDICTED",
"variables",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/eval/AccuracyEvaluator.java#L12-L34
|
12,105
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/ExpFamFactor.java
|
ExpFamFactor.updateFromModel
|
public void updateFromModel(FgModel model) {
initialized = true;
int numConfigs = this.getVars().calcNumConfigs();
for (int c=0; c<numConfigs; c++) {
double dot = getDotProd(c, model);
assert !Double.isNaN(dot) && dot != Double.POSITIVE_INFINITY : "Invalid value for factor: " + dot;
this.setValue(c, dot);
}
}
|
java
|
public void updateFromModel(FgModel model) {
initialized = true;
int numConfigs = this.getVars().calcNumConfigs();
for (int c=0; c<numConfigs; c++) {
double dot = getDotProd(c, model);
assert !Double.isNaN(dot) && dot != Double.POSITIVE_INFINITY : "Invalid value for factor: " + dot;
this.setValue(c, dot);
}
}
|
[
"public",
"void",
"updateFromModel",
"(",
"FgModel",
"model",
")",
"{",
"initialized",
"=",
"true",
";",
"int",
"numConfigs",
"=",
"this",
".",
"getVars",
"(",
")",
".",
"calcNumConfigs",
"(",
")",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"numConfigs",
";",
"c",
"++",
")",
"{",
"double",
"dot",
"=",
"getDotProd",
"(",
"c",
",",
"model",
")",
";",
"assert",
"!",
"Double",
".",
"isNaN",
"(",
"dot",
")",
"&&",
"dot",
"!=",
"Double",
".",
"POSITIVE_INFINITY",
":",
"\"Invalid value for factor: \"",
"+",
"dot",
";",
"this",
".",
"setValue",
"(",
"c",
",",
"dot",
")",
";",
"}",
"}"
] |
If this factor depends on the model, this method will updates this
factor's internal representation accordingly.
@param model The model.
|
[
"If",
"this",
"factor",
"depends",
"on",
"the",
"model",
"this",
"method",
"will",
"updates",
"this",
"factor",
"s",
"internal",
"representation",
"accordingly",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/ExpFamFactor.java#L59-L67
|
12,106
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/TensorUtils.java
|
TensorUtils.getVectorFromReals
|
public static Tensor getVectorFromReals(Algebra s, double... values) {
Tensor t0 = getVectorFromValues(RealAlgebra.getInstance(), values);
return t0.copyAndConvertAlgebra(s);
}
|
java
|
public static Tensor getVectorFromReals(Algebra s, double... values) {
Tensor t0 = getVectorFromValues(RealAlgebra.getInstance(), values);
return t0.copyAndConvertAlgebra(s);
}
|
[
"public",
"static",
"Tensor",
"getVectorFromReals",
"(",
"Algebra",
"s",
",",
"double",
"...",
"values",
")",
"{",
"Tensor",
"t0",
"=",
"getVectorFromValues",
"(",
"RealAlgebra",
".",
"getInstance",
"(",
")",
",",
"values",
")",
";",
"return",
"t0",
".",
"copyAndConvertAlgebra",
"(",
"s",
")",
";",
"}"
] |
Gets a tensor in the s semiring, where the input values are assumed to be in the reals.
|
[
"Gets",
"a",
"tensor",
"in",
"the",
"s",
"semiring",
"where",
"the",
"input",
"values",
"are",
"assumed",
"to",
"be",
"in",
"the",
"reals",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/TensorUtils.java#L57-L60
|
12,107
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.getConfigIndexOfSubset
|
public int getConfigIndexOfSubset(VarSet vars) {
int configIndex = 0;
int numStatesProd = 1;
for (int v=vars.size()-1; v >= 0; v--) {
Var var = vars.get(v);
int state = config.get(var);
configIndex += state * numStatesProd;
numStatesProd *= var.getNumStates();
if (numStatesProd <= 0) {
throw new IllegalStateException("Integer overflow when computing config index -- this can occur if trying to compute the index of a high arity factor: " + numStatesProd);
}
}
return configIndex;
}
|
java
|
public int getConfigIndexOfSubset(VarSet vars) {
int configIndex = 0;
int numStatesProd = 1;
for (int v=vars.size()-1; v >= 0; v--) {
Var var = vars.get(v);
int state = config.get(var);
configIndex += state * numStatesProd;
numStatesProd *= var.getNumStates();
if (numStatesProd <= 0) {
throw new IllegalStateException("Integer overflow when computing config index -- this can occur if trying to compute the index of a high arity factor: " + numStatesProd);
}
}
return configIndex;
}
|
[
"public",
"int",
"getConfigIndexOfSubset",
"(",
"VarSet",
"vars",
")",
"{",
"int",
"configIndex",
"=",
"0",
";",
"int",
"numStatesProd",
"=",
"1",
";",
"for",
"(",
"int",
"v",
"=",
"vars",
".",
"size",
"(",
")",
"-",
"1",
";",
"v",
">=",
"0",
";",
"v",
"--",
")",
"{",
"Var",
"var",
"=",
"vars",
".",
"get",
"(",
"v",
")",
";",
"int",
"state",
"=",
"config",
".",
"get",
"(",
"var",
")",
";",
"configIndex",
"+=",
"state",
"*",
"numStatesProd",
";",
"numStatesProd",
"*=",
"var",
".",
"getNumStates",
"(",
")",
";",
"if",
"(",
"numStatesProd",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Integer overflow when computing config index -- this can occur if trying to compute the index of a high arity factor: \"",
"+",
"numStatesProd",
")",
";",
"}",
"}",
"return",
"configIndex",
";",
"}"
] |
Gets the index of this configuration for the given variable set.
This is used to provide a unique index for each setting of the the
variables in a VarSet.
|
[
"Gets",
"the",
"index",
"of",
"this",
"configuration",
"for",
"the",
"given",
"variable",
"set",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L60-L73
|
12,108
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.put
|
public void put(VarConfig other) {
this.config.putAll(other.config);
this.vars.addAll(other.vars);
}
|
java
|
public void put(VarConfig other) {
this.config.putAll(other.config);
this.vars.addAll(other.vars);
}
|
[
"public",
"void",
"put",
"(",
"VarConfig",
"other",
")",
"{",
"this",
".",
"config",
".",
"putAll",
"(",
"other",
".",
"config",
")",
";",
"this",
".",
"vars",
".",
"addAll",
"(",
"other",
".",
"vars",
")",
";",
"}"
] |
Sets all variable assignments in other.
|
[
"Sets",
"all",
"variable",
"assignments",
"in",
"other",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L76-L79
|
12,109
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.put
|
public void put(Var var, String stateName) {
int state = var.getState(stateName);
if (state == -1) {
throw new IllegalArgumentException("Unknown state name " + stateName + " for var " + var);
}
put(var, state);
}
|
java
|
public void put(Var var, String stateName) {
int state = var.getState(stateName);
if (state == -1) {
throw new IllegalArgumentException("Unknown state name " + stateName + " for var " + var);
}
put(var, state);
}
|
[
"public",
"void",
"put",
"(",
"Var",
"var",
",",
"String",
"stateName",
")",
"{",
"int",
"state",
"=",
"var",
".",
"getState",
"(",
"stateName",
")",
";",
"if",
"(",
"state",
"==",
"-",
"1",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unknown state name \"",
"+",
"stateName",
"+",
"\" for var \"",
"+",
"var",
")",
";",
"}",
"put",
"(",
"var",
",",
"state",
")",
";",
"}"
] |
Sets the state value to stateName for the given variable, adding it if necessary.
|
[
"Sets",
"the",
"state",
"value",
"to",
"stateName",
"for",
"the",
"given",
"variable",
"adding",
"it",
"if",
"necessary",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L82-L88
|
12,110
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.put
|
public void put(Var var, int state) {
if (state < 0 || state >= var.getNumStates()) {
throw new IllegalArgumentException("Invalid state idx " + state + " for var " + var);
}
config.put(var, state);
vars.add(var);
}
|
java
|
public void put(Var var, int state) {
if (state < 0 || state >= var.getNumStates()) {
throw new IllegalArgumentException("Invalid state idx " + state + " for var " + var);
}
config.put(var, state);
vars.add(var);
}
|
[
"public",
"void",
"put",
"(",
"Var",
"var",
",",
"int",
"state",
")",
"{",
"if",
"(",
"state",
"<",
"0",
"||",
"state",
">=",
"var",
".",
"getNumStates",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid state idx \"",
"+",
"state",
"+",
"\" for var \"",
"+",
"var",
")",
";",
"}",
"config",
".",
"put",
"(",
"var",
",",
"state",
")",
";",
"vars",
".",
"add",
"(",
"var",
")",
";",
"}"
] |
Sets the state value to state for the given variable, adding it if necessary.
|
[
"Sets",
"the",
"state",
"value",
"to",
"state",
"for",
"the",
"given",
"variable",
"adding",
"it",
"if",
"necessary",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L91-L97
|
12,111
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.getSubset
|
public VarConfig getSubset(VarSet subsetVars) {
if (!vars.isSuperset(subsetVars)) {
throw new IllegalStateException("This config does not contain all the given variables.");
}
return getIntersection(subsetVars);
}
|
java
|
public VarConfig getSubset(VarSet subsetVars) {
if (!vars.isSuperset(subsetVars)) {
throw new IllegalStateException("This config does not contain all the given variables.");
}
return getIntersection(subsetVars);
}
|
[
"public",
"VarConfig",
"getSubset",
"(",
"VarSet",
"subsetVars",
")",
"{",
"if",
"(",
"!",
"vars",
".",
"isSuperset",
"(",
"subsetVars",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"This config does not contain all the given variables.\"",
")",
";",
"}",
"return",
"getIntersection",
"(",
"subsetVars",
")",
";",
"}"
] |
Gets a new variable configuration that contains only a subset of the variables.
|
[
"Gets",
"a",
"new",
"variable",
"configuration",
"that",
"contains",
"only",
"a",
"subset",
"of",
"the",
"variables",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L138-L143
|
12,112
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java
|
VarConfig.getIntersection
|
public VarConfig getIntersection(Iterable<Var> otherVars) {
VarConfig subset = new VarConfig();
for (Var v : otherVars) {
Integer state = config.get(v);
if (state != null) {
subset.put(v, state);
}
}
return subset;
}
|
java
|
public VarConfig getIntersection(Iterable<Var> otherVars) {
VarConfig subset = new VarConfig();
for (Var v : otherVars) {
Integer state = config.get(v);
if (state != null) {
subset.put(v, state);
}
}
return subset;
}
|
[
"public",
"VarConfig",
"getIntersection",
"(",
"Iterable",
"<",
"Var",
">",
"otherVars",
")",
"{",
"VarConfig",
"subset",
"=",
"new",
"VarConfig",
"(",
")",
";",
"for",
"(",
"Var",
"v",
":",
"otherVars",
")",
"{",
"Integer",
"state",
"=",
"config",
".",
"get",
"(",
"v",
")",
";",
"if",
"(",
"state",
"!=",
"null",
")",
"{",
"subset",
".",
"put",
"(",
"v",
",",
"state",
")",
";",
"}",
"}",
"return",
"subset",
";",
"}"
] |
Gets a new variable configuration that keeps only variables in otherVars.
|
[
"Gets",
"a",
"new",
"variable",
"configuration",
"that",
"keeps",
"only",
"variables",
"in",
"otherVars",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/VarConfig.java#L146-L155
|
12,113
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/train/ModuleObjective.java
|
ModuleObjective.accum
|
@Override
public void accum(FgModel model, int i, Accumulator ac) {
try {
accumWithException(model, i, ac);
} catch(Throwable t) {
log.error("Skipping example " + i + " due to throwable: " + t.getMessage());
t.printStackTrace();
}
}
|
java
|
@Override
public void accum(FgModel model, int i, Accumulator ac) {
try {
accumWithException(model, i, ac);
} catch(Throwable t) {
log.error("Skipping example " + i + " due to throwable: " + t.getMessage());
t.printStackTrace();
}
}
|
[
"@",
"Override",
"public",
"void",
"accum",
"(",
"FgModel",
"model",
",",
"int",
"i",
",",
"Accumulator",
"ac",
")",
"{",
"try",
"{",
"accumWithException",
"(",
"model",
",",
"i",
",",
"ac",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"log",
".",
"error",
"(",
"\"Skipping example \"",
"+",
"i",
"+",
"\" due to throwable: \"",
"+",
"t",
".",
"getMessage",
"(",
")",
")",
";",
"t",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] |
Assumed by caller to be threadsafe.
|
[
"Assumed",
"by",
"caller",
"to",
"be",
"threadsafe",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/train/ModuleObjective.java#L38-L46
|
12,114
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/PropagateRequestImpl.java
|
PropagateRequestImpl.createResponseParams
|
private ISFSObject createResponseParams() {
return ResponseParamsBuilder.create()
.addition(addition)
.excludedVars(excludedVars)
.includedVars(includedVars)
.transformer(new ParamTransformer(context))
.data(data)
.build();
}
|
java
|
private ISFSObject createResponseParams() {
return ResponseParamsBuilder.create()
.addition(addition)
.excludedVars(excludedVars)
.includedVars(includedVars)
.transformer(new ParamTransformer(context))
.data(data)
.build();
}
|
[
"private",
"ISFSObject",
"createResponseParams",
"(",
")",
"{",
"return",
"ResponseParamsBuilder",
".",
"create",
"(",
")",
".",
"addition",
"(",
"addition",
")",
".",
"excludedVars",
"(",
"excludedVars",
")",
".",
"includedVars",
"(",
"includedVars",
")",
".",
"transformer",
"(",
"new",
"ParamTransformer",
"(",
"context",
")",
")",
".",
"data",
"(",
"data",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Create smartfox object to response to client
@return smartfox parameter object
|
[
"Create",
"smartfox",
"object",
"to",
"response",
"to",
"client"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/PropagateRequestImpl.java#L145-L153
|
12,115
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/data/FgExampleCache.java
|
FgExampleCache.get
|
public LFgExample get(int i) {
LFgExample ex;
synchronized (cache) {
ex = cache.get(i);
}
if (ex == null) {
ex = exampleFactory.get(i);
synchronized (cache) {
cache.put(i, ex);
}
}
return ex;
}
|
java
|
public LFgExample get(int i) {
LFgExample ex;
synchronized (cache) {
ex = cache.get(i);
}
if (ex == null) {
ex = exampleFactory.get(i);
synchronized (cache) {
cache.put(i, ex);
}
}
return ex;
}
|
[
"public",
"LFgExample",
"get",
"(",
"int",
"i",
")",
"{",
"LFgExample",
"ex",
";",
"synchronized",
"(",
"cache",
")",
"{",
"ex",
"=",
"cache",
".",
"get",
"(",
"i",
")",
";",
"}",
"if",
"(",
"ex",
"==",
"null",
")",
"{",
"ex",
"=",
"exampleFactory",
".",
"get",
"(",
"i",
")",
";",
"synchronized",
"(",
"cache",
")",
"{",
"cache",
".",
"put",
"(",
"i",
",",
"ex",
")",
";",
"}",
"}",
"return",
"ex",
";",
"}"
] |
Gets the i'th example.
|
[
"Gets",
"the",
"i",
"th",
"example",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/data/FgExampleCache.java#L55-L67
|
12,116
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/cky/intdata/IntBinaryTree.java
|
IntBinaryTree.updateStartEnd
|
public void updateStartEnd() {
ArrayList<IntBinaryTree> leaves = getLeaves();
for (int i=0; i<leaves.size(); i++) {
IntBinaryTree leaf = leaves.get(i);
leaf.start = i;
leaf.end = i+1;
}
postOrderTraversal(new UpdateStartEnd());
}
|
java
|
public void updateStartEnd() {
ArrayList<IntBinaryTree> leaves = getLeaves();
for (int i=0; i<leaves.size(); i++) {
IntBinaryTree leaf = leaves.get(i);
leaf.start = i;
leaf.end = i+1;
}
postOrderTraversal(new UpdateStartEnd());
}
|
[
"public",
"void",
"updateStartEnd",
"(",
")",
"{",
"ArrayList",
"<",
"IntBinaryTree",
">",
"leaves",
"=",
"getLeaves",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"leaves",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"IntBinaryTree",
"leaf",
"=",
"leaves",
".",
"get",
"(",
"i",
")",
";",
"leaf",
".",
"start",
"=",
"i",
";",
"leaf",
".",
"end",
"=",
"i",
"+",
"1",
";",
"}",
"postOrderTraversal",
"(",
"new",
"UpdateStartEnd",
"(",
")",
")",
";",
"}"
] |
Updates all the start end fields, treating the current node as the root.
|
[
"Updates",
"all",
"the",
"start",
"end",
"fields",
"treating",
"the",
"current",
"node",
"as",
"the",
"root",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/cky/intdata/IntBinaryTree.java#L199-L207
|
12,117
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/cky/intdata/IntBinaryTree.java
|
IntBinaryTree.getLeaves
|
public ArrayList<IntBinaryTree> getLeaves() {
LeafCollector leafCollector = new LeafCollector();
postOrderTraversal(leafCollector);
return leafCollector.leaves;
}
|
java
|
public ArrayList<IntBinaryTree> getLeaves() {
LeafCollector leafCollector = new LeafCollector();
postOrderTraversal(leafCollector);
return leafCollector.leaves;
}
|
[
"public",
"ArrayList",
"<",
"IntBinaryTree",
">",
"getLeaves",
"(",
")",
"{",
"LeafCollector",
"leafCollector",
"=",
"new",
"LeafCollector",
"(",
")",
";",
"postOrderTraversal",
"(",
"leafCollector",
")",
";",
"return",
"leafCollector",
".",
"leaves",
";",
"}"
] |
Gets the leaves of this tree.
|
[
"Gets",
"the",
"leaves",
"of",
"this",
"tree",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/cky/intdata/IntBinaryTree.java#L212-L216
|
12,118
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/collections/SmallSet.java
|
SmallSet.diff
|
public SmallSet<E> diff(SmallSet<E> other) {
SmallSet<E> tmp = new SmallSet<E>(this.size() - other.size());
Sort.diffSortedLists(this.list, other.list, tmp.list);
return tmp;
}
|
java
|
public SmallSet<E> diff(SmallSet<E> other) {
SmallSet<E> tmp = new SmallSet<E>(this.size() - other.size());
Sort.diffSortedLists(this.list, other.list, tmp.list);
return tmp;
}
|
[
"public",
"SmallSet",
"<",
"E",
">",
"diff",
"(",
"SmallSet",
"<",
"E",
">",
"other",
")",
"{",
"SmallSet",
"<",
"E",
">",
"tmp",
"=",
"new",
"SmallSet",
"<",
"E",
">",
"(",
"this",
".",
"size",
"(",
")",
"-",
"other",
".",
"size",
"(",
")",
")",
";",
"Sort",
".",
"diffSortedLists",
"(",
"this",
".",
"list",
",",
"other",
".",
"list",
",",
"tmp",
".",
"list",
")",
";",
"return",
"tmp",
";",
"}"
] |
Gets a new SmallSet containing the difference of this set with the other.
|
[
"Gets",
"a",
"new",
"SmallSet",
"containing",
"the",
"difference",
"of",
"this",
"set",
"with",
"the",
"other",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/collections/SmallSet.java#L164-L168
|
12,119
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/DefaultDict.java
|
DefaultDict.get
|
@Override
public V get(Object key) {
if (super.containsKey(key)) {
return super.get(key);
} else {
@SuppressWarnings("unchecked")
K k = (K) key;
V v = makeDefault.apply(k);
put(k, v);
return v;
}
}
|
java
|
@Override
public V get(Object key) {
if (super.containsKey(key)) {
return super.get(key);
} else {
@SuppressWarnings("unchecked")
K k = (K) key;
V v = makeDefault.apply(k);
put(k, v);
return v;
}
}
|
[
"@",
"Override",
"public",
"V",
"get",
"(",
"Object",
"key",
")",
"{",
"if",
"(",
"super",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"return",
"super",
".",
"get",
"(",
"key",
")",
";",
"}",
"else",
"{",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"K",
"k",
"=",
"(",
"K",
")",
"key",
";",
"V",
"v",
"=",
"makeDefault",
".",
"apply",
"(",
"k",
")",
";",
"put",
"(",
"k",
",",
"v",
")",
";",
"return",
"v",
";",
"}",
"}"
] |
If the key isn't in the dictionary, the makeDefault function will be called to create a new value
which will be added
|
[
"If",
"the",
"key",
"isn",
"t",
"in",
"the",
"dictionary",
"the",
"makeDefault",
"function",
"will",
"be",
"called",
"to",
"create",
"a",
"new",
"value",
"which",
"will",
"be",
"added"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/DefaultDict.java#L48-L59
|
12,120
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cache/GzipMap.java
|
GzipMap.deserialize
|
public static Object deserialize(byte[] bytes, boolean gzipOnSerialize) {
try {
InputStream is = new ByteArrayInputStream(bytes);
if (gzipOnSerialize) {
is = new GZIPInputStream(is);
}
ObjectInputStream in = new ObjectInputStream(is);
Object inObj = in.readObject();
in.close();
return inObj;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
java
|
public static Object deserialize(byte[] bytes, boolean gzipOnSerialize) {
try {
InputStream is = new ByteArrayInputStream(bytes);
if (gzipOnSerialize) {
is = new GZIPInputStream(is);
}
ObjectInputStream in = new ObjectInputStream(is);
Object inObj = in.readObject();
in.close();
return inObj;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"Object",
"deserialize",
"(",
"byte",
"[",
"]",
"bytes",
",",
"boolean",
"gzipOnSerialize",
")",
"{",
"try",
"{",
"InputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"bytes",
")",
";",
"if",
"(",
"gzipOnSerialize",
")",
"{",
"is",
"=",
"new",
"GZIPInputStream",
"(",
"is",
")",
";",
"}",
"ObjectInputStream",
"in",
"=",
"new",
"ObjectInputStream",
"(",
"is",
")",
";",
"Object",
"inObj",
"=",
"in",
".",
"readObject",
"(",
")",
";",
"in",
".",
"close",
"(",
")",
";",
"return",
"inObj",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Deserialize and ungzip an object.
|
[
"Deserialize",
"and",
"ungzip",
"an",
"object",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cache/GzipMap.java#L120-L135
|
12,121
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cache/GzipMap.java
|
GzipMap.serialize
|
public static byte[] serialize(Serializable obj, boolean gzipOnSerialize) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out;
if (gzipOnSerialize) {
out = new ObjectOutputStream(new GZIPOutputStream(baos));
} else {
out = new ObjectOutputStream(baos);
}
out.writeObject(obj);
out.flush();
out.close();
return baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
java
|
public static byte[] serialize(Serializable obj, boolean gzipOnSerialize) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out;
if (gzipOnSerialize) {
out = new ObjectOutputStream(new GZIPOutputStream(baos));
} else {
out = new ObjectOutputStream(baos);
}
out.writeObject(obj);
out.flush();
out.close();
return baos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
[
"public",
"static",
"byte",
"[",
"]",
"serialize",
"(",
"Serializable",
"obj",
",",
"boolean",
"gzipOnSerialize",
")",
"{",
"try",
"{",
"ByteArrayOutputStream",
"baos",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"ObjectOutputStream",
"out",
";",
"if",
"(",
"gzipOnSerialize",
")",
"{",
"out",
"=",
"new",
"ObjectOutputStream",
"(",
"new",
"GZIPOutputStream",
"(",
"baos",
")",
")",
";",
"}",
"else",
"{",
"out",
"=",
"new",
"ObjectOutputStream",
"(",
"baos",
")",
";",
"}",
"out",
".",
"writeObject",
"(",
"obj",
")",
";",
"out",
".",
"flush",
"(",
")",
";",
"out",
".",
"close",
"(",
")",
";",
"return",
"baos",
".",
"toByteArray",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Serializes and gzips an object.
|
[
"Serializes",
"and",
"gzips",
"an",
"object",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cache/GzipMap.java#L138-L154
|
12,122
|
JodaOrg/joda-collect
|
src/main/java/org/joda/collect/grid/AbstractCell.java
|
AbstractCell.comparator
|
@SuppressWarnings({ "unchecked", "rawtypes" })
static final <R> Comparator<Cell<R>> comparator() {
return (Comparator<Cell<R>>) (Comparator) COMPARATOR;
}
|
java
|
@SuppressWarnings({ "unchecked", "rawtypes" })
static final <R> Comparator<Cell<R>> comparator() {
return (Comparator<Cell<R>>) (Comparator) COMPARATOR;
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
",",
"\"rawtypes\"",
"}",
")",
"static",
"final",
"<",
"R",
">",
"Comparator",
"<",
"Cell",
"<",
"R",
">",
">",
"comparator",
"(",
")",
"{",
"return",
"(",
"Comparator",
"<",
"Cell",
"<",
"R",
">",
">",
")",
"(",
"Comparator",
")",
"COMPARATOR",
";",
"}"
] |
Compare by row then column.
@param <R> the type of the value
@return the comparator, not null
|
[
"Compare",
"by",
"row",
"then",
"column",
"."
] |
a4b05d5eebad5beb41715c0678cf11835cf0fa3f
|
https://github.com/JodaOrg/joda-collect/blob/a4b05d5eebad5beb41715c0678cf11835cf0fa3f/src/main/java/org/joda/collect/grid/AbstractCell.java#L38-L41
|
12,123
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/PingClientImpl.java
|
PingClientImpl.scheduleOneTime
|
private void scheduleOneTime(TaskScheduler scheduler) {
scheduledFuture = scheduler.schedule(runnable, (int)delayTime, TimeUnit.MILLISECONDS);
}
|
java
|
private void scheduleOneTime(TaskScheduler scheduler) {
scheduledFuture = scheduler.schedule(runnable, (int)delayTime, TimeUnit.MILLISECONDS);
}
|
[
"private",
"void",
"scheduleOneTime",
"(",
"TaskScheduler",
"scheduler",
")",
"{",
"scheduledFuture",
"=",
"scheduler",
".",
"schedule",
"(",
"runnable",
",",
"(",
"int",
")",
"delayTime",
",",
"TimeUnit",
".",
"MILLISECONDS",
")",
";",
"}"
] |
Schedule one short
@param scheduler TaskScheduler object
|
[
"Schedule",
"one",
"short"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/PingClientImpl.java#L150-L152
|
12,124
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.transform
|
public SFSDataWrapper transform(Object value) {
if(value == null)
return transformNullValue(value);
return transformNotNullValue(value);
}
|
java
|
public SFSDataWrapper transform(Object value) {
if(value == null)
return transformNullValue(value);
return transformNotNullValue(value);
}
|
[
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"return",
"transformNullValue",
"(",
"value",
")",
";",
"return",
"transformNotNullValue",
"(",
"value",
")",
";",
"}"
] |
Transform the value to SFSDataWrapper object
@param value the value
@return a SFSDataWrapper object
|
[
"Transform",
"the",
"value",
"to",
"SFSDataWrapper",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L75-L79
|
12,125
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.transformArrayObject
|
protected SFSDataWrapper transformArrayObject(Object value) {
int length = ArrayUtils.getLength(value);
if(length == 0)
return new SFSDataWrapper(SFSDataType.NULL, null);
ISFSArray sfsarray = new SFSArray();
for(Object obj : (Object[])value)
sfsarray.add(transform(obj));
return new SFSDataWrapper(SFSDataType.SFS_ARRAY, sfsarray);
}
|
java
|
protected SFSDataWrapper transformArrayObject(Object value) {
int length = ArrayUtils.getLength(value);
if(length == 0)
return new SFSDataWrapper(SFSDataType.NULL, null);
ISFSArray sfsarray = new SFSArray();
for(Object obj : (Object[])value)
sfsarray.add(transform(obj));
return new SFSDataWrapper(SFSDataType.SFS_ARRAY, sfsarray);
}
|
[
"protected",
"SFSDataWrapper",
"transformArrayObject",
"(",
"Object",
"value",
")",
"{",
"int",
"length",
"=",
"ArrayUtils",
".",
"getLength",
"(",
"value",
")",
";",
"if",
"(",
"length",
"==",
"0",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"NULL",
",",
"null",
")",
";",
"ISFSArray",
"sfsarray",
"=",
"new",
"SFSArray",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"(",
"Object",
"[",
"]",
")",
"value",
")",
"sfsarray",
".",
"(",
"transform",
"(",
"obj",
")",
")",
";",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SFS_ARRAY",
",",
"sfsarray",
")",
";",
"}"
] |
Transform a java pojo object array to sfsarray
@param value the pojo object array
@return a SFSDataWrapper object
|
[
"Transform",
"a",
"java",
"pojo",
"object",
"array",
"to",
"sfsarray"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L112-L120
|
12,126
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.transformObject
|
protected SFSDataWrapper transformObject(Object value) {
ResponseParamsClass struct = null;
if(context != null) struct = context.getResponseParamsClass(value.getClass());
if(struct == null) struct = new ResponseParamsClass(value.getClass());
ISFSObject sfsObject = new ResponseParamSerializer().object2params(struct, value);
return new SFSDataWrapper(SFSDataType.SFS_OBJECT, sfsObject);
}
|
java
|
protected SFSDataWrapper transformObject(Object value) {
ResponseParamsClass struct = null;
if(context != null) struct = context.getResponseParamsClass(value.getClass());
if(struct == null) struct = new ResponseParamsClass(value.getClass());
ISFSObject sfsObject = new ResponseParamSerializer().object2params(struct, value);
return new SFSDataWrapper(SFSDataType.SFS_OBJECT, sfsObject);
}
|
[
"protected",
"SFSDataWrapper",
"transformObject",
"(",
"Object",
"value",
")",
"{",
"ResponseParamsClass",
"struct",
"=",
"null",
";",
"if",
"(",
"context",
"!=",
"null",
")",
"struct",
"=",
"context",
".",
"getResponseParamsClass",
"(",
"value",
".",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"struct",
"==",
"null",
")",
"struct",
"=",
"new",
"ResponseParamsClass",
"(",
"value",
".",
"getClass",
"(",
")",
")",
";",
"ISFSObject",
"sfsObject",
"=",
"new",
"ResponseParamSerializer",
"(",
")",
".",
"object2params",
"(",
"struct",
",",
"value",
")",
";",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SFS_OBJECT",
",",
"sfsObject",
")",
";",
"}"
] |
Transform a java pojo object to sfsobject
@param value pojo java object
@return a SFSDataWrapper object
|
[
"Transform",
"a",
"java",
"pojo",
"object",
"to",
"sfsobject"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L128-L134
|
12,127
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.transformCollection
|
@SuppressWarnings("unchecked")
protected SFSDataWrapper transformCollection(Object value) {
Collection<?> collection = (Collection<?>)value;
if(collection.isEmpty())
return new SFSDataWrapper(SFSDataType.NULL, value);
Iterator<?> it = collection.iterator();
Object firstItem = it.next();
if(firstItem.getClass().isArray())
return transformArrayCollection(collection);
if(isObject(firstItem.getClass()))
return transformObjectCollection((Collection<?>)value);
if(firstItem instanceof Boolean)
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, value);
if(firstItem instanceof Byte)
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, collectionToPrimitiveByteArray((Collection<Byte>)value));
if(firstItem instanceof Character)
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charCollectionToPrimitiveByteArray((Collection<Character>)value));
if(firstItem instanceof Double)
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, value);
if(firstItem instanceof Float)
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, value);
if(firstItem instanceof Integer)
return new SFSDataWrapper(SFSDataType.INT_ARRAY, value);
if(firstItem instanceof Long)
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, value);
if(firstItem instanceof Short)
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, value);
if(firstItem instanceof String)
return new SFSDataWrapper(SFSDataType.UTF_STRING_ARRAY, value);
throw new IllegalArgumentException("Can not transform value of " + value.getClass());
}
|
java
|
@SuppressWarnings("unchecked")
protected SFSDataWrapper transformCollection(Object value) {
Collection<?> collection = (Collection<?>)value;
if(collection.isEmpty())
return new SFSDataWrapper(SFSDataType.NULL, value);
Iterator<?> it = collection.iterator();
Object firstItem = it.next();
if(firstItem.getClass().isArray())
return transformArrayCollection(collection);
if(isObject(firstItem.getClass()))
return transformObjectCollection((Collection<?>)value);
if(firstItem instanceof Boolean)
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, value);
if(firstItem instanceof Byte)
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, collectionToPrimitiveByteArray((Collection<Byte>)value));
if(firstItem instanceof Character)
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charCollectionToPrimitiveByteArray((Collection<Character>)value));
if(firstItem instanceof Double)
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, value);
if(firstItem instanceof Float)
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, value);
if(firstItem instanceof Integer)
return new SFSDataWrapper(SFSDataType.INT_ARRAY, value);
if(firstItem instanceof Long)
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, value);
if(firstItem instanceof Short)
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, value);
if(firstItem instanceof String)
return new SFSDataWrapper(SFSDataType.UTF_STRING_ARRAY, value);
throw new IllegalArgumentException("Can not transform value of " + value.getClass());
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"protected",
"SFSDataWrapper",
"transformCollection",
"(",
"Object",
"value",
")",
"{",
"Collection",
"<",
"?",
">",
"collection",
"=",
"(",
"Collection",
"<",
"?",
">",
")",
"value",
";",
"if",
"(",
"collection",
".",
"isEmpty",
"(",
")",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"NULL",
",",
"value",
")",
";",
"Iterator",
"<",
"?",
">",
"it",
"=",
"collection",
".",
"iterator",
"(",
")",
";",
"Object",
"firstItem",
"=",
"it",
".",
"next",
"(",
")",
";",
"if",
"(",
"firstItem",
".",
"getClass",
"(",
")",
".",
"isArray",
"(",
")",
")",
"return",
"transformArrayCollection",
"(",
"collection",
")",
";",
"if",
"(",
"isObject",
"(",
"firstItem",
".",
"getClass",
"(",
")",
")",
")",
"return",
"transformObjectCollection",
"(",
"(",
"Collection",
"<",
"?",
">",
")",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Boolean",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BOOL_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Byte",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"collectionToPrimitiveByteArray",
"(",
"(",
"Collection",
"<",
"Byte",
">",
")",
"value",
")",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Character",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"charCollectionToPrimitiveByteArray",
"(",
"(",
"Collection",
"<",
"Character",
">",
")",
"value",
")",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Double",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"DOUBLE_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Float",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"FLOAT_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Integer",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"INT_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Long",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"LONG_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"Short",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SHORT_ARRAY",
",",
"value",
")",
";",
"if",
"(",
"firstItem",
"instanceof",
"String",
")",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"UTF_STRING_ARRAY",
",",
"value",
")",
";",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Can not transform value of \"",
"+",
"value",
".",
"getClass",
"(",
")",
")",
";",
"}"
] |
Transform a collection of value to SFSDataWrapper object
@param value the collection of value
@return a SFSDataWrapper object
|
[
"Transform",
"a",
"collection",
"of",
"value",
"to",
"SFSDataWrapper",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L170-L201
|
12,128
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.findTransformer
|
protected Transformer findTransformer(Class<?> clazz) {
Transformer answer = transformers.get(clazz);
if(answer == null)
throw new IllegalArgumentException("Can not transform value of " + clazz);
return answer;
}
|
java
|
protected Transformer findTransformer(Class<?> clazz) {
Transformer answer = transformers.get(clazz);
if(answer == null)
throw new IllegalArgumentException("Can not transform value of " + clazz);
return answer;
}
|
[
"protected",
"Transformer",
"findTransformer",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"Transformer",
"answer",
"=",
"transformers",
".",
"get",
"(",
"clazz",
")",
";",
"if",
"(",
"answer",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Can not transform value of \"",
"+",
"clazz",
")",
";",
"return",
"answer",
";",
"}"
] |
Find transformer of a type
@param clazz the type
@return a transformer reference
|
[
"Find",
"transformer",
"of",
"a",
"type"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L219-L224
|
12,129
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.initWithWrapperType
|
protected void initWithWrapperType() {
// =========== wrapper type ==============
transformers.put(Boolean.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL, value);
}
});
transformers.put(Byte.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE, value);
}
});
transformers.put(Character.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE, (byte)((Character)value).charValue());
}
});
transformers.put(Double.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE, value);
}
});
transformers.put(Float.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT, value);
}
});
transformers.put(Integer.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT, value);
}
});
transformers.put(Long.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG, value);
}
});
transformers.put(Short.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT, value);
}
});
}
|
java
|
protected void initWithWrapperType() {
// =========== wrapper type ==============
transformers.put(Boolean.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL, value);
}
});
transformers.put(Byte.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE, value);
}
});
transformers.put(Character.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE, (byte)((Character)value).charValue());
}
});
transformers.put(Double.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE, value);
}
});
transformers.put(Float.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT, value);
}
});
transformers.put(Integer.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT, value);
}
});
transformers.put(Long.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG, value);
}
});
transformers.put(Short.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT, value);
}
});
}
|
[
"protected",
"void",
"initWithWrapperType",
"(",
")",
"{",
"// =========== wrapper type ==============",
"transformers",
".",
"put",
"(",
"Boolean",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BOOL",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Byte",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Character",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE",
",",
"(",
"byte",
")",
"(",
"(",
"Character",
")",
"value",
")",
".",
"charValue",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Double",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"DOUBLE",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Float",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"FLOAT",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Integer",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"INT",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Long",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"LONG",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Short",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SHORT",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Add transformers of wrapper type to the map
|
[
"Add",
"transformers",
"of",
"wrapper",
"type",
"to",
"the",
"map"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L246-L296
|
12,130
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.initWithPrimitiveTypeArray
|
protected void initWithPrimitiveTypeArray() {
// =========== primitve array type ==============
transformers.put(boolean[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, primitiveArrayToBoolCollection((boolean[])value));
}
});
transformers.put(byte[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, value);
}
});
transformers.put(char[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charArrayToByteArray((char[])value));
}
});
transformers.put(double[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, primitiveArrayToDoubleCollection((double[])value));
}
});
transformers.put(float[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, primitiveArrayToFloatCollection((float[])value));
}
});
transformers.put(int[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT_ARRAY, primitiveArrayToIntCollection((int[])value));
}
});
transformers.put(long[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, primitiveArrayToLongCollection((long[])value));
}
});
transformers.put(short[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, primitiveArrayToShortCollection((short[])value));
}
});
}
|
java
|
protected void initWithPrimitiveTypeArray() {
// =========== primitve array type ==============
transformers.put(boolean[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, primitiveArrayToBoolCollection((boolean[])value));
}
});
transformers.put(byte[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, value);
}
});
transformers.put(char[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charArrayToByteArray((char[])value));
}
});
transformers.put(double[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, primitiveArrayToDoubleCollection((double[])value));
}
});
transformers.put(float[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, primitiveArrayToFloatCollection((float[])value));
}
});
transformers.put(int[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT_ARRAY, primitiveArrayToIntCollection((int[])value));
}
});
transformers.put(long[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, primitiveArrayToLongCollection((long[])value));
}
});
transformers.put(short[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, primitiveArrayToShortCollection((short[])value));
}
});
}
|
[
"protected",
"void",
"initWithPrimitiveTypeArray",
"(",
")",
"{",
"// =========== primitve array type ==============",
"transformers",
".",
"put",
"(",
"boolean",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BOOL_ARRAY",
",",
"primitiveArrayToBoolCollection",
"(",
"(",
"boolean",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"byte",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"char",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"charArrayToByteArray",
"(",
"(",
"char",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"double",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"DOUBLE_ARRAY",
",",
"primitiveArrayToDoubleCollection",
"(",
"(",
"double",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"float",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"FLOAT_ARRAY",
",",
"primitiveArrayToFloatCollection",
"(",
"(",
"float",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"int",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"INT_ARRAY",
",",
"primitiveArrayToIntCollection",
"(",
"(",
"int",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"long",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"LONG_ARRAY",
",",
"primitiveArrayToLongCollection",
"(",
"(",
"long",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"short",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SHORT_ARRAY",
",",
"primitiveArrayToShortCollection",
"(",
"(",
"short",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Add transformers of array of primitive values to the map
|
[
"Add",
"transformers",
"of",
"array",
"of",
"primitive",
"values",
"to",
"the",
"map"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L301-L351
|
12,131
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.initWithWrapperTypArray
|
protected void initWithWrapperTypArray() {
// =========== wrapper array type ==============
transformers.put(Boolean[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, wrapperArrayToCollection((Boolean[])value));
}
});
transformers.put(Byte[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, toPrimitiveByteArray((Byte[])value));
}
});
transformers.put(Character[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charWrapperArrayToPrimitiveByteArray((Character[])value));
}
});
transformers.put(Double[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, wrapperArrayToCollection((Double[])value));
}
});
transformers.put(Float[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, wrapperArrayToCollection((Float[])value));
}
});
transformers.put(Integer[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT_ARRAY, wrapperArrayToCollection((Integer[])value));
}
});
transformers.put(Long[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, wrapperArrayToCollection((Long[])value));
}
});
transformers.put(Short[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, wrapperArrayToCollection((Short[])value));
}
});
}
|
java
|
protected void initWithWrapperTypArray() {
// =========== wrapper array type ==============
transformers.put(Boolean[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BOOL_ARRAY, wrapperArrayToCollection((Boolean[])value));
}
});
transformers.put(Byte[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, toPrimitiveByteArray((Byte[])value));
}
});
transformers.put(Character[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.BYTE_ARRAY, charWrapperArrayToPrimitiveByteArray((Character[])value));
}
});
transformers.put(Double[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.DOUBLE_ARRAY, wrapperArrayToCollection((Double[])value));
}
});
transformers.put(Float[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.FLOAT_ARRAY, wrapperArrayToCollection((Float[])value));
}
});
transformers.put(Integer[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.INT_ARRAY, wrapperArrayToCollection((Integer[])value));
}
});
transformers.put(Long[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.LONG_ARRAY, wrapperArrayToCollection((Long[])value));
}
});
transformers.put(Short[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.SHORT_ARRAY, wrapperArrayToCollection((Short[])value));
}
});
}
|
[
"protected",
"void",
"initWithWrapperTypArray",
"(",
")",
"{",
"// =========== wrapper array type ==============",
"transformers",
".",
"put",
"(",
"Boolean",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BOOL_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Boolean",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Byte",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"toPrimitiveByteArray",
"(",
"(",
"Byte",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Character",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"BYTE_ARRAY",
",",
"charWrapperArrayToPrimitiveByteArray",
"(",
"(",
"Character",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Double",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"DOUBLE_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Double",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Float",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"FLOAT_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Float",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Integer",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"INT_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Integer",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Long",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"LONG_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Long",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"Short",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"SHORT_ARRAY",
",",
"wrapperArrayToCollection",
"(",
"(",
"Short",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Add transformers of array of wrapper values to the map
|
[
"Add",
"transformers",
"of",
"array",
"of",
"wrapper",
"values",
"to",
"the",
"map"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L356-L406
|
12,132
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java
|
SimpleTransformer.initWithStringType
|
protected void initWithStringType() {
transformers.put(String.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.UTF_STRING, value);
}
});
transformers.put(String[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.UTF_STRING_ARRAY, stringArrayToCollection((String[])value));
}
});
}
|
java
|
protected void initWithStringType() {
transformers.put(String.class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.UTF_STRING, value);
}
});
transformers.put(String[].class, new Transformer() {
@Override
public SFSDataWrapper transform(Object value) {
return new SFSDataWrapper(SFSDataType.UTF_STRING_ARRAY, stringArrayToCollection((String[])value));
}
});
}
|
[
"protected",
"void",
"initWithStringType",
"(",
")",
"{",
"transformers",
".",
"put",
"(",
"String",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"UTF_STRING",
",",
"value",
")",
";",
"}",
"}",
")",
";",
"transformers",
".",
"put",
"(",
"String",
"[",
"]",
".",
"class",
",",
"new",
"Transformer",
"(",
")",
"{",
"@",
"Override",
"public",
"SFSDataWrapper",
"transform",
"(",
"Object",
"value",
")",
"{",
"return",
"new",
"SFSDataWrapper",
"(",
"SFSDataType",
".",
"UTF_STRING_ARRAY",
",",
"stringArrayToCollection",
"(",
"(",
"String",
"[",
"]",
")",
"value",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Add transformer of string and transformer of array of strings to the map
|
[
"Add",
"transformer",
"of",
"string",
"and",
"transformer",
"of",
"array",
"of",
"strings",
"to",
"the",
"map"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/data/impl/SimpleTransformer.java#L411-L425
|
12,133
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/SendObjectMessageImpl.java
|
SendObjectMessageImpl.getSfsRoom
|
private Room getSfsRoom() {
if(StringUtils.isEmpty(roomName))
return extension.getParentZone().getRoomById(roomId);
return CommandUtil.getSfsRoom(roomName, extension);
}
|
java
|
private Room getSfsRoom() {
if(StringUtils.isEmpty(roomName))
return extension.getParentZone().getRoomById(roomId);
return CommandUtil.getSfsRoom(roomName, extension);
}
|
[
"private",
"Room",
"getSfsRoom",
"(",
")",
"{",
"if",
"(",
"StringUtils",
".",
"isEmpty",
"(",
"roomName",
")",
")",
"return",
"extension",
".",
"getParentZone",
"(",
")",
".",
"getRoomById",
"(",
"roomId",
")",
";",
"return",
"CommandUtil",
".",
"getSfsRoom",
"(",
"roomName",
",",
"extension",
")",
";",
"}"
] |
Get smartfox room reference by name
@return smartfox room reference
|
[
"Get",
"smartfox",
"room",
"reference",
"by",
"name"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/SendObjectMessageImpl.java#L69-L73
|
12,134
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/SendObjectMessageImpl.java
|
SendObjectMessageImpl.getMessage
|
private ISFSObject getMessage() {
if(messageObject != null) {
MessageParamsClass clazz = context.getMessageParamsClass(messageObject.getClass());
if(clazz != null)
return new ResponseParamSerializer().object2params(clazz.getUnwrapper(), messageObject);
}
if(jsonMessage != null)
return SFSObject.newFromJsonData(jsonMessage);
if(messageString == null)
return new SFSObject();
ISFSObject answer = new SFSObject();
answer.putUtfString(APIKey.MESSAGE, messageString);
return answer;
}
|
java
|
private ISFSObject getMessage() {
if(messageObject != null) {
MessageParamsClass clazz = context.getMessageParamsClass(messageObject.getClass());
if(clazz != null)
return new ResponseParamSerializer().object2params(clazz.getUnwrapper(), messageObject);
}
if(jsonMessage != null)
return SFSObject.newFromJsonData(jsonMessage);
if(messageString == null)
return new SFSObject();
ISFSObject answer = new SFSObject();
answer.putUtfString(APIKey.MESSAGE, messageString);
return answer;
}
|
[
"private",
"ISFSObject",
"getMessage",
"(",
")",
"{",
"if",
"(",
"messageObject",
"!=",
"null",
")",
"{",
"MessageParamsClass",
"clazz",
"=",
"context",
".",
"getMessageParamsClass",
"(",
"messageObject",
".",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"clazz",
"!=",
"null",
")",
"return",
"new",
"ResponseParamSerializer",
"(",
")",
".",
"object2params",
"(",
"clazz",
".",
"getUnwrapper",
"(",
")",
",",
"messageObject",
")",
";",
"}",
"if",
"(",
"jsonMessage",
"!=",
"null",
")",
"return",
"SFSObject",
".",
"newFromJsonData",
"(",
"jsonMessage",
")",
";",
"if",
"(",
"messageString",
"==",
"null",
")",
"return",
"new",
"SFSObject",
"(",
")",
";",
"ISFSObject",
"answer",
"=",
"new",
"SFSObject",
"(",
")",
";",
"answer",
".",
"putUtfString",
"(",
"APIKey",
".",
"MESSAGE",
",",
"messageString",
")",
";",
"return",
"answer",
";",
"}"
] |
Create smartfox parameter object from a POJO object or json string or string
@return smartfox parameter object
|
[
"Create",
"smartfox",
"parameter",
"object",
"from",
"a",
"POJO",
"object",
"or",
"json",
"string",
"or",
"string"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/SendObjectMessageImpl.java#L80-L94
|
12,135
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/sch/util/ScheduleUtils.java
|
ScheduleUtils.cycle
|
public static <T> Iterator<T> cycle(Iterator<T> itr, int times) {
// if we repeat 0, then it is as if the itr were empty, so don't take the items
final List<T> items = (times != 0) ? Lists.newLinkedList(iterable(itr)) : Collections.emptyList();
return new Iterator<T>() {
private Iterator<T> currentItr = Collections.emptyIterator();
private int ncalls = 0;
private Iterator<T> getItr() {
// if this is the first call or we've gotten to the end of a round
if (!currentItr.hasNext() && ncalls < times) {
currentItr = items.iterator();
ncalls++;
}
return currentItr;
}
@Override
public boolean hasNext() {
return getItr().hasNext();
}
@Override
public T next() {
return getItr().next();
}
};
}
|
java
|
public static <T> Iterator<T> cycle(Iterator<T> itr, int times) {
// if we repeat 0, then it is as if the itr were empty, so don't take the items
final List<T> items = (times != 0) ? Lists.newLinkedList(iterable(itr)) : Collections.emptyList();
return new Iterator<T>() {
private Iterator<T> currentItr = Collections.emptyIterator();
private int ncalls = 0;
private Iterator<T> getItr() {
// if this is the first call or we've gotten to the end of a round
if (!currentItr.hasNext() && ncalls < times) {
currentItr = items.iterator();
ncalls++;
}
return currentItr;
}
@Override
public boolean hasNext() {
return getItr().hasNext();
}
@Override
public T next() {
return getItr().next();
}
};
}
|
[
"public",
"static",
"<",
"T",
">",
"Iterator",
"<",
"T",
">",
"cycle",
"(",
"Iterator",
"<",
"T",
">",
"itr",
",",
"int",
"times",
")",
"{",
"// if we repeat 0, then it is as if the itr were empty, so don't take the items",
"final",
"List",
"<",
"T",
">",
"items",
"=",
"(",
"times",
"!=",
"0",
")",
"?",
"Lists",
".",
"newLinkedList",
"(",
"iterable",
"(",
"itr",
")",
")",
":",
"Collections",
".",
"emptyList",
"(",
")",
";",
"return",
"new",
"Iterator",
"<",
"T",
">",
"(",
")",
"{",
"private",
"Iterator",
"<",
"T",
">",
"currentItr",
"=",
"Collections",
".",
"emptyIterator",
"(",
")",
";",
"private",
"int",
"ncalls",
"=",
"0",
";",
"private",
"Iterator",
"<",
"T",
">",
"getItr",
"(",
")",
"{",
"// if this is the first call or we've gotten to the end of a round",
"if",
"(",
"!",
"currentItr",
".",
"hasNext",
"(",
")",
"&&",
"ncalls",
"<",
"times",
")",
"{",
"currentItr",
"=",
"items",
".",
"iterator",
"(",
")",
";",
"ncalls",
"++",
";",
"}",
"return",
"currentItr",
";",
"}",
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"return",
"getItr",
"(",
")",
".",
"hasNext",
"(",
")",
";",
"}",
"@",
"Override",
"public",
"T",
"next",
"(",
")",
"{",
"return",
"getItr",
"(",
")",
".",
"next",
"(",
")",
";",
"}",
"}",
";",
"}"
] |
Returns an iterator cycles over the elements in items repeat times;
if repeat < 0, then this cycles indefinitely
if repeat == 0, then the iterator is an empty iterator
|
[
"Returns",
"an",
"iterator",
"cycles",
"over",
"the",
"elements",
"in",
"items",
"repeat",
"times",
";",
"if",
"repeat",
"<",
"0",
"then",
"this",
"cycles",
"indefinitely",
"if",
"repeat",
"==",
"0",
"then",
"the",
"iterator",
"is",
"an",
"empty",
"iterator"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/sch/util/ScheduleUtils.java#L69-L98
|
12,136
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.getSiblingsOf
|
public static ArrayList<Integer> getSiblingsOf(int[] parents, int idx) {
int parent = parents[idx];
ArrayList<Integer> siblings = new ArrayList<Integer>();
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
siblings.add(i);
}
}
return siblings;
}
|
java
|
public static ArrayList<Integer> getSiblingsOf(int[] parents, int idx) {
int parent = parents[idx];
ArrayList<Integer> siblings = new ArrayList<Integer>();
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
siblings.add(i);
}
}
return siblings;
}
|
[
"public",
"static",
"ArrayList",
"<",
"Integer",
">",
"getSiblingsOf",
"(",
"int",
"[",
"]",
"parents",
",",
"int",
"idx",
")",
"{",
"int",
"parent",
"=",
"parents",
"[",
"idx",
"]",
";",
"ArrayList",
"<",
"Integer",
">",
"siblings",
"=",
"new",
"ArrayList",
"<",
"Integer",
">",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"parents",
"[",
"i",
"]",
"==",
"parent",
")",
"{",
"siblings",
".",
"add",
"(",
"i",
")",
";",
"}",
"}",
"return",
"siblings",
";",
"}"
] |
Gets the siblings of the specified word.
@param parents The parents array.
@param idx The word for which to extract siblings.
@return The indices of the siblings.
|
[
"Gets",
"the",
"siblings",
"of",
"the",
"specified",
"word",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L102-L111
|
12,137
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.containsCycle
|
public static boolean containsCycle(int[] parents) {
for (int i=0; i<parents.length; i++) {
int numAncestors = 0;
int parent = parents[i];
while(parent != ParentsArray.WALL_POSITION) {
numAncestors += 1;
if (numAncestors > parents.length - 1) {
return true;
}
parent = parents[parent];
}
}
return false;
}
|
java
|
public static boolean containsCycle(int[] parents) {
for (int i=0; i<parents.length; i++) {
int numAncestors = 0;
int parent = parents[i];
while(parent != ParentsArray.WALL_POSITION) {
numAncestors += 1;
if (numAncestors > parents.length - 1) {
return true;
}
parent = parents[parent];
}
}
return false;
}
|
[
"public",
"static",
"boolean",
"containsCycle",
"(",
"int",
"[",
"]",
"parents",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"int",
"numAncestors",
"=",
"0",
";",
"int",
"parent",
"=",
"parents",
"[",
"i",
"]",
";",
"while",
"(",
"parent",
"!=",
"ParentsArray",
".",
"WALL_POSITION",
")",
"{",
"numAncestors",
"+=",
"1",
";",
"if",
"(",
"numAncestors",
">",
"parents",
".",
"length",
"-",
"1",
")",
"{",
"return",
"true",
";",
"}",
"parent",
"=",
"parents",
"[",
"parent",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if a dependency tree represented as a parents array contains a cycle.
@param parents
A parents array where parents[i] contains the index of the
parent of the word at position i, with parents[i] = -1
indicating that the parent of word i is the wall node.
@return True if the tree specified by the parents array contains a cycle,
False otherwise.
|
[
"Checks",
"if",
"a",
"dependency",
"tree",
"represented",
"as",
"a",
"parents",
"array",
"contains",
"a",
"cycle",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L123-L136
|
12,138
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.isProjective
|
public static boolean isProjective(int[] parents) {
for (int i=0; i<parents.length; i++) {
int pari = (parents[i] == ParentsArray.WALL_POSITION) ? parents.length : parents[i];
int minI = i < pari ? i : pari;
int maxI = i > pari ? i : pari;
for (int j=0; j<parents.length; j++) {
if (j == i) {
continue;
}
int parj = (parents[j] == ParentsArray.WALL_POSITION) ? parents.length : parents[j];
if (minI < j && j < maxI) {
if (!(minI <= parj && parj <= maxI)) {
return false;
}
} else {
if (!(parj <= minI || parj >= maxI)) {
return false;
}
}
}
}
return true;
}
|
java
|
public static boolean isProjective(int[] parents) {
for (int i=0; i<parents.length; i++) {
int pari = (parents[i] == ParentsArray.WALL_POSITION) ? parents.length : parents[i];
int minI = i < pari ? i : pari;
int maxI = i > pari ? i : pari;
for (int j=0; j<parents.length; j++) {
if (j == i) {
continue;
}
int parj = (parents[j] == ParentsArray.WALL_POSITION) ? parents.length : parents[j];
if (minI < j && j < maxI) {
if (!(minI <= parj && parj <= maxI)) {
return false;
}
} else {
if (!(parj <= minI || parj >= maxI)) {
return false;
}
}
}
}
return true;
}
|
[
"public",
"static",
"boolean",
"isProjective",
"(",
"int",
"[",
"]",
"parents",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"int",
"pari",
"=",
"(",
"parents",
"[",
"i",
"]",
"==",
"ParentsArray",
".",
"WALL_POSITION",
")",
"?",
"parents",
".",
"length",
":",
"parents",
"[",
"i",
"]",
";",
"int",
"minI",
"=",
"i",
"<",
"pari",
"?",
"i",
":",
"pari",
";",
"int",
"maxI",
"=",
"i",
">",
"pari",
"?",
"i",
":",
"pari",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"parents",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"j",
"==",
"i",
")",
"{",
"continue",
";",
"}",
"int",
"parj",
"=",
"(",
"parents",
"[",
"j",
"]",
"==",
"ParentsArray",
".",
"WALL_POSITION",
")",
"?",
"parents",
".",
"length",
":",
"parents",
"[",
"j",
"]",
";",
"if",
"(",
"minI",
"<",
"j",
"&&",
"j",
"<",
"maxI",
")",
"{",
"if",
"(",
"!",
"(",
"minI",
"<=",
"parj",
"&&",
"parj",
"<=",
"maxI",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"(",
"parj",
"<=",
"minI",
"||",
"parj",
">=",
"maxI",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Checks that a dependency tree represented as a parents array is projective.
@param parents
A parents array where parents[i] contains the index of the
parent of the word at position i, with parents[i] = -1
indicating that the parent of word i is the wall node.
@return True if the tree specified by the parents array is projective,
False otherwise.
|
[
"Checks",
"that",
"a",
"dependency",
"tree",
"represented",
"as",
"a",
"parents",
"array",
"is",
"projective",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L148-L170
|
12,139
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.countChildrenOf
|
public static int countChildrenOf(int[] parents, int parent) {
int count = 0;
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
count++;
}
}
return count;
}
|
java
|
public static int countChildrenOf(int[] parents, int parent) {
int count = 0;
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
count++;
}
}
return count;
}
|
[
"public",
"static",
"int",
"countChildrenOf",
"(",
"int",
"[",
"]",
"parents",
",",
"int",
"parent",
")",
"{",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"parents",
"[",
"i",
"]",
"==",
"parent",
")",
"{",
"count",
"++",
";",
"}",
"}",
"return",
"count",
";",
"}"
] |
Counts of the number of children in a dependency tree for the given
parent index.
@param parents
A parents array where parents[i] contains the index of the
parent of the word at position i, with parents[i] = -1
indicating that the parent of word i is the wall node.
@param parent The parent for which the children should be counted.
@return The number of entries in <code>parents</code> that equal
<code>parent</code>.
|
[
"Counts",
"of",
"the",
"number",
"of",
"children",
"in",
"a",
"dependency",
"tree",
"for",
"the",
"given",
"parent",
"index",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L184-L192
|
12,140
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.getChildrenOf
|
public static IntArrayList getChildrenOf(int[] parents, int parent) {
IntArrayList children = new IntArrayList();
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
children.add(i);
}
}
return children;
}
|
java
|
public static IntArrayList getChildrenOf(int[] parents, int parent) {
IntArrayList children = new IntArrayList();
for (int i=0; i<parents.length; i++) {
if (parents[i] == parent) {
children.add(i);
}
}
return children;
}
|
[
"public",
"static",
"IntArrayList",
"getChildrenOf",
"(",
"int",
"[",
"]",
"parents",
",",
"int",
"parent",
")",
"{",
"IntArrayList",
"children",
"=",
"new",
"IntArrayList",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parents",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"parents",
"[",
"i",
"]",
"==",
"parent",
")",
"{",
"children",
".",
"add",
"(",
"i",
")",
";",
"}",
"}",
"return",
"children",
";",
"}"
] |
Gets the children of the specified parent.
@param parents A parents array.
@param parent The parent for which the children should be extracted.
@return The indices of the children.
|
[
"Gets",
"the",
"children",
"of",
"the",
"specified",
"parent",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L200-L208
|
12,141
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.isAncestor
|
public static boolean isAncestor(int idx1, int idx2, int[] parents) {
int anc = parents[idx2];
while (anc != -1) {
if (anc == idx1) {
return true;
}
anc = parents[anc];
}
return false;
}
|
java
|
public static boolean isAncestor(int idx1, int idx2, int[] parents) {
int anc = parents[idx2];
while (anc != -1) {
if (anc == idx1) {
return true;
}
anc = parents[anc];
}
return false;
}
|
[
"public",
"static",
"boolean",
"isAncestor",
"(",
"int",
"idx1",
",",
"int",
"idx2",
",",
"int",
"[",
"]",
"parents",
")",
"{",
"int",
"anc",
"=",
"parents",
"[",
"idx2",
"]",
";",
"while",
"(",
"anc",
"!=",
"-",
"1",
")",
"{",
"if",
"(",
"anc",
"==",
"idx1",
")",
"{",
"return",
"true",
";",
"}",
"anc",
"=",
"parents",
"[",
"anc",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks whether idx1 is the ancestor of idx2. If idx1 is the parent of
idx2 this will return true, but if idx1 == idx2, it will return false.
@param idx1 The ancestor position.
@param idx2 The descendent position.
@param parents The parents array.
@return Whether idx is the ancestor of idx2.
|
[
"Checks",
"whether",
"idx1",
"is",
"the",
"ancestor",
"of",
"idx2",
".",
"If",
"idx1",
"is",
"the",
"parent",
"of",
"idx2",
"this",
"will",
"return",
"true",
"but",
"if",
"idx1",
"==",
"idx2",
"it",
"will",
"return",
"false",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L219-L228
|
12,142
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java
|
ParentsArray.getDependencyPath
|
public static List<Pair<Integer,Dir>> getDependencyPath(int start, int end, int[] parents) {
int n = parents.length;
if (start < -1 || start >= n || end < -1 || end >= n) {
throw new IllegalArgumentException(String.format("Invalid start/end: %d/%d", start, end));
}
// Build a hash set of the ancestors of end, including end and the
// wall node.
IntHashSet endAncSet = new IntHashSet();
IntArrayList endAncList = new IntArrayList();
int curPos = end;
while (curPos != ParentsArray.WALL_POSITION && curPos != -2 && !endAncSet.contains(curPos)) {
endAncSet.add(curPos);
endAncList.add(curPos);
curPos = parents[curPos];
}
if (curPos != -1) {
// No path to the wall. Possibly a cycle.
return null;
}
endAncSet.add(curPos); // Don't forget the wall node.
endAncList.add(curPos);
// Create the dependency path.
List<Pair<Integer,Dir>> path = new ArrayList<Pair<Integer,Dir>>();
// Add all the "edges" from the start up to the one pointing at the LCA.
IntHashSet startAncSet = new IntHashSet();
curPos = start;
while (!endAncSet.contains(curPos) && curPos != -2 && !startAncSet.contains(curPos)) {
path.add(new Pair<Integer,Dir>(curPos, Dir.UP));
startAncSet.add(curPos);
curPos = parents[curPos];
}
if (!endAncSet.contains(curPos)) {
// No path to any nodes in endAncSet or a cycle.
return null;
}
// Least common ancestor.
int lca = curPos;
// Add all the edges from the LCA to the end position.
int lcaIndex = endAncList.lookupIndex(lca);
for (int i = lcaIndex; i > 0; i--) {
path.add(new Pair<Integer,Dir>(endAncList.get(i), Dir.DOWN));
}
// TODO: Update unit tests to reflect this change.
path.add(new Pair<Integer,Dir>(end, Dir.NONE));
return path;
}
|
java
|
public static List<Pair<Integer,Dir>> getDependencyPath(int start, int end, int[] parents) {
int n = parents.length;
if (start < -1 || start >= n || end < -1 || end >= n) {
throw new IllegalArgumentException(String.format("Invalid start/end: %d/%d", start, end));
}
// Build a hash set of the ancestors of end, including end and the
// wall node.
IntHashSet endAncSet = new IntHashSet();
IntArrayList endAncList = new IntArrayList();
int curPos = end;
while (curPos != ParentsArray.WALL_POSITION && curPos != -2 && !endAncSet.contains(curPos)) {
endAncSet.add(curPos);
endAncList.add(curPos);
curPos = parents[curPos];
}
if (curPos != -1) {
// No path to the wall. Possibly a cycle.
return null;
}
endAncSet.add(curPos); // Don't forget the wall node.
endAncList.add(curPos);
// Create the dependency path.
List<Pair<Integer,Dir>> path = new ArrayList<Pair<Integer,Dir>>();
// Add all the "edges" from the start up to the one pointing at the LCA.
IntHashSet startAncSet = new IntHashSet();
curPos = start;
while (!endAncSet.contains(curPos) && curPos != -2 && !startAncSet.contains(curPos)) {
path.add(new Pair<Integer,Dir>(curPos, Dir.UP));
startAncSet.add(curPos);
curPos = parents[curPos];
}
if (!endAncSet.contains(curPos)) {
// No path to any nodes in endAncSet or a cycle.
return null;
}
// Least common ancestor.
int lca = curPos;
// Add all the edges from the LCA to the end position.
int lcaIndex = endAncList.lookupIndex(lca);
for (int i = lcaIndex; i > 0; i--) {
path.add(new Pair<Integer,Dir>(endAncList.get(i), Dir.DOWN));
}
// TODO: Update unit tests to reflect this change.
path.add(new Pair<Integer,Dir>(end, Dir.NONE));
return path;
}
|
[
"public",
"static",
"List",
"<",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
">",
"getDependencyPath",
"(",
"int",
"start",
",",
"int",
"end",
",",
"int",
"[",
"]",
"parents",
")",
"{",
"int",
"n",
"=",
"parents",
".",
"length",
";",
"if",
"(",
"start",
"<",
"-",
"1",
"||",
"start",
">=",
"n",
"||",
"end",
"<",
"-",
"1",
"||",
"end",
">=",
"n",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"format",
"(",
"\"Invalid start/end: %d/%d\"",
",",
"start",
",",
"end",
")",
")",
";",
"}",
"// Build a hash set of the ancestors of end, including end and the",
"// wall node.",
"IntHashSet",
"endAncSet",
"=",
"new",
"IntHashSet",
"(",
")",
";",
"IntArrayList",
"endAncList",
"=",
"new",
"IntArrayList",
"(",
")",
";",
"int",
"curPos",
"=",
"end",
";",
"while",
"(",
"curPos",
"!=",
"ParentsArray",
".",
"WALL_POSITION",
"&&",
"curPos",
"!=",
"-",
"2",
"&&",
"!",
"endAncSet",
".",
"contains",
"(",
"curPos",
")",
")",
"{",
"endAncSet",
".",
"add",
"(",
"curPos",
")",
";",
"endAncList",
".",
"add",
"(",
"curPos",
")",
";",
"curPos",
"=",
"parents",
"[",
"curPos",
"]",
";",
"}",
"if",
"(",
"curPos",
"!=",
"-",
"1",
")",
"{",
"// No path to the wall. Possibly a cycle.",
"return",
"null",
";",
"}",
"endAncSet",
".",
"add",
"(",
"curPos",
")",
";",
"// Don't forget the wall node.",
"endAncList",
".",
"add",
"(",
"curPos",
")",
";",
"// Create the dependency path.",
"List",
"<",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
">",
"path",
"=",
"new",
"ArrayList",
"<",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
">",
"(",
")",
";",
"// Add all the \"edges\" from the start up to the one pointing at the LCA.",
"IntHashSet",
"startAncSet",
"=",
"new",
"IntHashSet",
"(",
")",
";",
"curPos",
"=",
"start",
";",
"while",
"(",
"!",
"endAncSet",
".",
"contains",
"(",
"curPos",
")",
"&&",
"curPos",
"!=",
"-",
"2",
"&&",
"!",
"startAncSet",
".",
"contains",
"(",
"curPos",
")",
")",
"{",
"path",
".",
"add",
"(",
"new",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
"(",
"curPos",
",",
"Dir",
".",
"UP",
")",
")",
";",
"startAncSet",
".",
"add",
"(",
"curPos",
")",
";",
"curPos",
"=",
"parents",
"[",
"curPos",
"]",
";",
"}",
"if",
"(",
"!",
"endAncSet",
".",
"contains",
"(",
"curPos",
")",
")",
"{",
"// No path to any nodes in endAncSet or a cycle.",
"return",
"null",
";",
"}",
"// Least common ancestor.",
"int",
"lca",
"=",
"curPos",
";",
"// Add all the edges from the LCA to the end position.",
"int",
"lcaIndex",
"=",
"endAncList",
".",
"lookupIndex",
"(",
"lca",
")",
";",
"for",
"(",
"int",
"i",
"=",
"lcaIndex",
";",
"i",
">",
"0",
";",
"i",
"--",
")",
"{",
"path",
".",
"add",
"(",
"new",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
"(",
"endAncList",
".",
"get",
"(",
"i",
")",
",",
"Dir",
".",
"DOWN",
")",
")",
";",
"}",
"// TODO: Update unit tests to reflect this change.",
"path",
".",
"add",
"(",
"new",
"Pair",
"<",
"Integer",
",",
"Dir",
">",
"(",
"end",
",",
"Dir",
".",
"NONE",
")",
")",
";",
"return",
"path",
";",
"}"
] |
Gets the shortest dependency path between two tokens.
<p>
For the tree: x0 <-- x1 --> x2, represented by parents=[1, -1, 1] the
dependency path from x0 to x2 would be a list [(0, UP), (1, DOWN), (2, NONE)]
</p>
@param start The position of the start token.
@param end The position of the end token.
@param parents The parents array.
@return The path as a list of pairs containing the word positions and the
direction of the edge, inclusive of the start and end.
Or null if there is no path.
|
[
"Gets",
"the",
"shortest",
"dependency",
"path",
"between",
"two",
"tokens",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/ParentsArray.java#L245-L297
|
12,143
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Toposort.java
|
Toposort.toposort
|
public static <T> List<T> toposort(T root, Deps<T> deps) {
List<T> order = new ArrayList<T>();
HashSet<T> done = new HashSet<T>();
Stack<T> todo = new Stack<T>();
HashSet<T> ancestors = new HashSet<T>();
// Run a Tarjan (1976) style topological sort.
todo.push(root);
while (!todo.isEmpty()) {
T x = todo.peek();
// Whether all x's descendents are done.
boolean ready = true;
for (T y : deps.getDeps(x)) {
if (!done.contains(y)) {
ready = false;
todo.push(y);
}
}
if (ready) {
todo.pop();
ancestors.remove(x);
if (done.add(x)) {
order.add(x);
}
} else {
if (ancestors.contains(x)) {
throw new IllegalStateException("Graph is not a DAG. Cycle involves node: " + x);
}
ancestors.add(x);
}
}
return order;
}
|
java
|
public static <T> List<T> toposort(T root, Deps<T> deps) {
List<T> order = new ArrayList<T>();
HashSet<T> done = new HashSet<T>();
Stack<T> todo = new Stack<T>();
HashSet<T> ancestors = new HashSet<T>();
// Run a Tarjan (1976) style topological sort.
todo.push(root);
while (!todo.isEmpty()) {
T x = todo.peek();
// Whether all x's descendents are done.
boolean ready = true;
for (T y : deps.getDeps(x)) {
if (!done.contains(y)) {
ready = false;
todo.push(y);
}
}
if (ready) {
todo.pop();
ancestors.remove(x);
if (done.add(x)) {
order.add(x);
}
} else {
if (ancestors.contains(x)) {
throw new IllegalStateException("Graph is not a DAG. Cycle involves node: " + x);
}
ancestors.add(x);
}
}
return order;
}
|
[
"public",
"static",
"<",
"T",
">",
"List",
"<",
"T",
">",
"toposort",
"(",
"T",
"root",
",",
"Deps",
"<",
"T",
">",
"deps",
")",
"{",
"List",
"<",
"T",
">",
"order",
"=",
"new",
"ArrayList",
"<",
"T",
">",
"(",
")",
";",
"HashSet",
"<",
"T",
">",
"done",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
";",
"Stack",
"<",
"T",
">",
"todo",
"=",
"new",
"Stack",
"<",
"T",
">",
"(",
")",
";",
"HashSet",
"<",
"T",
">",
"ancestors",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
";",
"// Run a Tarjan (1976) style topological sort. ",
"todo",
".",
"push",
"(",
"root",
")",
";",
"while",
"(",
"!",
"todo",
".",
"isEmpty",
"(",
")",
")",
"{",
"T",
"x",
"=",
"todo",
".",
"peek",
"(",
")",
";",
"// Whether all x's descendents are done.",
"boolean",
"ready",
"=",
"true",
";",
"for",
"(",
"T",
"y",
":",
"deps",
".",
"getDeps",
"(",
"x",
")",
")",
"{",
"if",
"(",
"!",
"done",
".",
"contains",
"(",
"y",
")",
")",
"{",
"ready",
"=",
"false",
";",
"todo",
".",
"push",
"(",
"y",
")",
";",
"}",
"}",
"if",
"(",
"ready",
")",
"{",
"todo",
".",
"pop",
"(",
")",
";",
"ancestors",
".",
"remove",
"(",
"x",
")",
";",
"if",
"(",
"done",
".",
"add",
"(",
"x",
")",
")",
"{",
"order",
".",
"add",
"(",
"x",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"ancestors",
".",
"contains",
"(",
"x",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Graph is not a DAG. Cycle involves node: \"",
"+",
"x",
")",
";",
"}",
"ancestors",
".",
"add",
"(",
"x",
")",
";",
"}",
"}",
"return",
"order",
";",
"}"
] |
Gets a topological sort for the graph.
@param root The root of the graph.
@param deps Functional description of the graph's dependencies.
@return The topological sort.
|
[
"Gets",
"a",
"topological",
"sort",
"for",
"the",
"graph",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Toposort.java#L27-L59
|
12,144
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Toposort.java
|
Toposort.getCutoffDeps
|
public static <T> Deps<T> getCutoffDeps(final Set<T> inputSet, final Deps<T> deps) {
Deps<T> cutoffDeps = new Deps<T>() {
@Override
public Collection<T> getDeps(T x) {
HashSet<T> pruned = new HashSet<T>(deps.getDeps(x));
pruned.removeAll(inputSet);
return pruned;
}
};
return cutoffDeps;
}
|
java
|
public static <T> Deps<T> getCutoffDeps(final Set<T> inputSet, final Deps<T> deps) {
Deps<T> cutoffDeps = new Deps<T>() {
@Override
public Collection<T> getDeps(T x) {
HashSet<T> pruned = new HashSet<T>(deps.getDeps(x));
pruned.removeAll(inputSet);
return pruned;
}
};
return cutoffDeps;
}
|
[
"public",
"static",
"<",
"T",
">",
"Deps",
"<",
"T",
">",
"getCutoffDeps",
"(",
"final",
"Set",
"<",
"T",
">",
"inputSet",
",",
"final",
"Deps",
"<",
"T",
">",
"deps",
")",
"{",
"Deps",
"<",
"T",
">",
"cutoffDeps",
"=",
"new",
"Deps",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Collection",
"<",
"T",
">",
"getDeps",
"(",
"T",
"x",
")",
"{",
"HashSet",
"<",
"T",
">",
"pruned",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
"deps",
".",
"getDeps",
"(",
"x",
")",
")",
";",
"pruned",
".",
"removeAll",
"(",
"inputSet",
")",
";",
"return",
"pruned",
";",
"}",
"}",
";",
"return",
"cutoffDeps",
";",
"}"
] |
Gets a new Deps graph where each node in the input set is removed from the graph.
|
[
"Gets",
"a",
"new",
"Deps",
"graph",
"where",
"each",
"node",
"in",
"the",
"input",
"set",
"is",
"removed",
"from",
"the",
"graph",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Toposort.java#L100-L110
|
12,145
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Toposort.java
|
Toposort.checkAreDescendentsOf
|
public static <T> void checkAreDescendentsOf(Set<T> inputSet, T root, Deps<T> deps) {
// Check that all modules in the input set are descendents of the output module.
HashSet<T> visited = new HashSet<T>();
dfs(root, visited, deps);
if (!visited.containsAll(inputSet)) {
throw new IllegalStateException("Input set contains modules which are not descendents of the output module: " + inputSet);
}
}
|
java
|
public static <T> void checkAreDescendentsOf(Set<T> inputSet, T root, Deps<T> deps) {
// Check that all modules in the input set are descendents of the output module.
HashSet<T> visited = new HashSet<T>();
dfs(root, visited, deps);
if (!visited.containsAll(inputSet)) {
throw new IllegalStateException("Input set contains modules which are not descendents of the output module: " + inputSet);
}
}
|
[
"public",
"static",
"<",
"T",
">",
"void",
"checkAreDescendentsOf",
"(",
"Set",
"<",
"T",
">",
"inputSet",
",",
"T",
"root",
",",
"Deps",
"<",
"T",
">",
"deps",
")",
"{",
"// Check that all modules in the input set are descendents of the output module.",
"HashSet",
"<",
"T",
">",
"visited",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
";",
"dfs",
"(",
"root",
",",
"visited",
",",
"deps",
")",
";",
"if",
"(",
"!",
"visited",
".",
"containsAll",
"(",
"inputSet",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Input set contains modules which are not descendents of the output module: \"",
"+",
"inputSet",
")",
";",
"}",
"}"
] |
Checks that the given inputSet consists of only descendents of the root.
|
[
"Checks",
"that",
"the",
"given",
"inputSet",
"consists",
"of",
"only",
"descendents",
"of",
"the",
"root",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Toposort.java#L115-L122
|
12,146
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Toposort.java
|
Toposort.checkIsFullCut
|
public static <T> void checkIsFullCut(Set<T> inputSet, T root, Deps<T> deps) {
// Check that the input set defines a full cut through the graph with outMod as root.
HashSet<T> visited = new HashSet<T>();
// Mark the inputSet as visited. If it is a valid leaf set, then leaves will be empty upon
// completion of the DFS.
visited.addAll(inputSet);
HashSet<T> leaves = dfs(root, visited, deps);
if (leaves.size() != 0) {
throw new IllegalStateException("Input set is not a valid leaf set for the given output module. Extra leaves: " + leaves);
}
}
|
java
|
public static <T> void checkIsFullCut(Set<T> inputSet, T root, Deps<T> deps) {
// Check that the input set defines a full cut through the graph with outMod as root.
HashSet<T> visited = new HashSet<T>();
// Mark the inputSet as visited. If it is a valid leaf set, then leaves will be empty upon
// completion of the DFS.
visited.addAll(inputSet);
HashSet<T> leaves = dfs(root, visited, deps);
if (leaves.size() != 0) {
throw new IllegalStateException("Input set is not a valid leaf set for the given output module. Extra leaves: " + leaves);
}
}
|
[
"public",
"static",
"<",
"T",
">",
"void",
"checkIsFullCut",
"(",
"Set",
"<",
"T",
">",
"inputSet",
",",
"T",
"root",
",",
"Deps",
"<",
"T",
">",
"deps",
")",
"{",
"// Check that the input set defines a full cut through the graph with outMod as root.",
"HashSet",
"<",
"T",
">",
"visited",
"=",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
";",
"// Mark the inputSet as visited. If it is a valid leaf set, then leaves will be empty upon",
"// completion of the DFS.",
"visited",
".",
"addAll",
"(",
"inputSet",
")",
";",
"HashSet",
"<",
"T",
">",
"leaves",
"=",
"dfs",
"(",
"root",
",",
"visited",
",",
"deps",
")",
";",
"if",
"(",
"leaves",
".",
"size",
"(",
")",
"!=",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Input set is not a valid leaf set for the given output module. Extra leaves: \"",
"+",
"leaves",
")",
";",
"}",
"}"
] |
Checks that the given inputSet defines a full cut through the graph rooted at the given root.
|
[
"Checks",
"that",
"the",
"given",
"inputSet",
"defines",
"a",
"full",
"cut",
"through",
"the",
"graph",
"rooted",
"at",
"the",
"given",
"root",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Toposort.java#L128-L138
|
12,147
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/autodiff/Toposort.java
|
Toposort.getLeaves
|
public static <T> HashSet<T> getLeaves(T root, Deps<T> deps) {
return dfs(root, new HashSet<T>(), deps);
}
|
java
|
public static <T> HashSet<T> getLeaves(T root, Deps<T> deps) {
return dfs(root, new HashSet<T>(), deps);
}
|
[
"public",
"static",
"<",
"T",
">",
"HashSet",
"<",
"T",
">",
"getLeaves",
"(",
"T",
"root",
",",
"Deps",
"<",
"T",
">",
"deps",
")",
"{",
"return",
"dfs",
"(",
"root",
",",
"new",
"HashSet",
"<",
"T",
">",
"(",
")",
",",
"deps",
")",
";",
"}"
] |
Gets the leaves in DFS order.
|
[
"Gets",
"the",
"leaves",
"in",
"DFS",
"order",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/autodiff/Toposort.java#L175-L177
|
12,148
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/parse/dep/edmonds/SparseGraph.java
|
SparseGraph.reversed
|
public SparseGraph reversed() {
SparseGraph reverse = new SparseGraph();
for (Entry<Integer, Set<Integer>> entryFrom : edges.entrySet())
for (Integer to : entryFrom.getValue())
reverse.addEdge(to, entryFrom.getKey());
return reverse;
}
|
java
|
public SparseGraph reversed() {
SparseGraph reverse = new SparseGraph();
for (Entry<Integer, Set<Integer>> entryFrom : edges.entrySet())
for (Integer to : entryFrom.getValue())
reverse.addEdge(to, entryFrom.getKey());
return reverse;
}
|
[
"public",
"SparseGraph",
"reversed",
"(",
")",
"{",
"SparseGraph",
"reverse",
"=",
"new",
"SparseGraph",
"(",
")",
";",
"for",
"(",
"Entry",
"<",
"Integer",
",",
"Set",
"<",
"Integer",
">",
">",
"entryFrom",
":",
"edges",
".",
"entrySet",
"(",
")",
")",
"for",
"(",
"Integer",
"to",
":",
"entryFrom",
".",
"getValue",
"(",
")",
")",
"reverse",
".",
"addEdge",
"(",
"to",
",",
"entryFrom",
".",
"getKey",
"(",
")",
")",
";",
"return",
"reverse",
";",
"}"
] |
Build and return a sparse graph by reversing all edges in this graph.
@return
|
[
"Build",
"and",
"return",
"a",
"sparse",
"graph",
"by",
"reversing",
"all",
"edges",
"in",
"this",
"graph",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/parse/dep/edmonds/SparseGraph.java#L68-L74
|
12,149
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java
|
ZoneExtension.addServerEventHandlers
|
protected void addServerEventHandlers() {
Map<Object, Class<?>> handlers = getServerEventHandlers();
Set<Entry<Object, Class<?>>> entries = handlers.entrySet();
for(Entry<Object, Class<?>> entry : entries) {
SFSEventType type = SFSEventType.valueOf(
entry.getKey().toString());
ServerEventHandler handler = createServerEventHandler(
type, entry.getValue());
addEventHandler(type, handler);
}
}
|
java
|
protected void addServerEventHandlers() {
Map<Object, Class<?>> handlers = getServerEventHandlers();
Set<Entry<Object, Class<?>>> entries = handlers.entrySet();
for(Entry<Object, Class<?>> entry : entries) {
SFSEventType type = SFSEventType.valueOf(
entry.getKey().toString());
ServerEventHandler handler = createServerEventHandler(
type, entry.getValue());
addEventHandler(type, handler);
}
}
|
[
"protected",
"void",
"addServerEventHandlers",
"(",
")",
"{",
"Map",
"<",
"Object",
",",
"Class",
"<",
"?",
">",
">",
"handlers",
"=",
"getServerEventHandlers",
"(",
")",
";",
"Set",
"<",
"Entry",
"<",
"Object",
",",
"Class",
"<",
"?",
">",
">",
">",
"entries",
"=",
"handlers",
".",
"entrySet",
"(",
")",
";",
"for",
"(",
"Entry",
"<",
"Object",
",",
"Class",
"<",
"?",
">",
">",
"entry",
":",
"entries",
")",
"{",
"SFSEventType",
"type",
"=",
"SFSEventType",
".",
"valueOf",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"ServerEventHandler",
"handler",
"=",
"createServerEventHandler",
"(",
"type",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"addEventHandler",
"(",
"type",
",",
"handler",
")",
";",
"}",
"}"
] |
Add server event handlers
|
[
"Add",
"server",
"event",
"handlers"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java#L57-L67
|
12,150
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java
|
ZoneExtension.createServerEventHandler
|
private ServerEventHandler createServerEventHandler(
SFSEventType type, Class<?> clazz) {
try {
return (ServerEventHandler)
ReflectClassUtil.newInstance(
clazz, BaseAppContext.class, context);
} catch (ExtensionException e) {
getLogger().error("Error when create server event handlers", e);
throw new RuntimeException("Can not create event handler of class "
+ clazz, e);
}
}
|
java
|
private ServerEventHandler createServerEventHandler(
SFSEventType type, Class<?> clazz) {
try {
return (ServerEventHandler)
ReflectClassUtil.newInstance(
clazz, BaseAppContext.class, context);
} catch (ExtensionException e) {
getLogger().error("Error when create server event handlers", e);
throw new RuntimeException("Can not create event handler of class "
+ clazz, e);
}
}
|
[
"private",
"ServerEventHandler",
"createServerEventHandler",
"(",
"SFSEventType",
"type",
",",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"try",
"{",
"return",
"(",
"ServerEventHandler",
")",
"ReflectClassUtil",
".",
"newInstance",
"(",
"clazz",
",",
"BaseAppContext",
".",
"class",
",",
"context",
")",
";",
"}",
"catch",
"(",
"ExtensionException",
"e",
")",
"{",
"getLogger",
"(",
")",
".",
"error",
"(",
"\"Error when create server event handlers\"",
",",
"e",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"\"Can not create event handler of class \"",
"+",
"clazz",
",",
"e",
")",
";",
"}",
"}"
] |
Create server event handler by type and handler class
@param type event type
@param clazz handler class
@return a ServerEventHandler object
|
[
"Create",
"server",
"event",
"handler",
"by",
"type",
"and",
"handler",
"class"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java#L101-L112
|
12,151
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java
|
ZoneExtension.addSysControllerFilters
|
public void addSysControllerFilters() {
for(SystemRequest rq : SystemRequest.values()) {
ISystemFilterChain filterChain = new SysControllerFilterChain();
filterChain.addFilter("EzyFoxFilterChain#" + rq,
new BaseSysControllerFilter(appContext(), rq));
getParentZone().setFilterChain(rq, filterChain);
}
}
|
java
|
public void addSysControllerFilters() {
for(SystemRequest rq : SystemRequest.values()) {
ISystemFilterChain filterChain = new SysControllerFilterChain();
filterChain.addFilter("EzyFoxFilterChain#" + rq,
new BaseSysControllerFilter(appContext(), rq));
getParentZone().setFilterChain(rq, filterChain);
}
}
|
[
"public",
"void",
"addSysControllerFilters",
"(",
")",
"{",
"for",
"(",
"SystemRequest",
"rq",
":",
"SystemRequest",
".",
"values",
"(",
")",
")",
"{",
"ISystemFilterChain",
"filterChain",
"=",
"new",
"SysControllerFilterChain",
"(",
")",
";",
"filterChain",
".",
"addFilter",
"(",
"\"EzyFoxFilterChain#\"",
"+",
"rq",
",",
"new",
"BaseSysControllerFilter",
"(",
"appContext",
"(",
")",
",",
"rq",
")",
")",
";",
"getParentZone",
"(",
")",
".",
"setFilterChain",
"(",
"rq",
",",
"filterChain",
")",
";",
"}",
"}"
] |
Add System Controller Filters
|
[
"Add",
"System",
"Controller",
"Filters"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/extension/ZoneExtension.java#L145-L152
|
12,152
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java
|
LogSignAlgebra.toReal
|
@Override
public double toReal(double x) {
double unsignedReal = FastMath.exp(natlog(x));
return (sign(x) == POSITIVE) ? unsignedReal : -unsignedReal;
}
|
java
|
@Override
public double toReal(double x) {
double unsignedReal = FastMath.exp(natlog(x));
return (sign(x) == POSITIVE) ? unsignedReal : -unsignedReal;
}
|
[
"@",
"Override",
"public",
"double",
"toReal",
"(",
"double",
"x",
")",
"{",
"double",
"unsignedReal",
"=",
"FastMath",
".",
"exp",
"(",
"natlog",
"(",
"x",
")",
")",
";",
"return",
"(",
"sign",
"(",
"x",
")",
"==",
"POSITIVE",
")",
"?",
"unsignedReal",
":",
"-",
"unsignedReal",
";",
"}"
] |
Converts a compacted number to its real value.
|
[
"Converts",
"a",
"compacted",
"number",
"to",
"its",
"real",
"value",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java#L32-L36
|
12,153
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java
|
LogSignAlgebra.fromReal
|
@Override
public double fromReal(double x) {
long sign = POSITIVE;
if (x < 0) {
sign = NEGATIVE;
x = -x;
}
return compact(sign, FastMath.log(x));
}
|
java
|
@Override
public double fromReal(double x) {
long sign = POSITIVE;
if (x < 0) {
sign = NEGATIVE;
x = -x;
}
return compact(sign, FastMath.log(x));
}
|
[
"@",
"Override",
"public",
"double",
"fromReal",
"(",
"double",
"x",
")",
"{",
"long",
"sign",
"=",
"POSITIVE",
";",
"if",
"(",
"x",
"<",
"0",
")",
"{",
"sign",
"=",
"NEGATIVE",
";",
"x",
"=",
"-",
"x",
";",
"}",
"return",
"compact",
"(",
"sign",
",",
"FastMath",
".",
"log",
"(",
"x",
")",
")",
";",
"}"
] |
Converts a real value to its compacted representation.
|
[
"Converts",
"a",
"real",
"value",
"to",
"its",
"compacted",
"representation",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java#L39-L47
|
12,154
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java
|
LogSignAlgebra.compact
|
public static final double compact(long sign, double natlog) {
return Double.longBitsToDouble(sign | (FLOAT_MASK & Double.doubleToRawLongBits(natlog)));
}
|
java
|
public static final double compact(long sign, double natlog) {
return Double.longBitsToDouble(sign | (FLOAT_MASK & Double.doubleToRawLongBits(natlog)));
}
|
[
"public",
"static",
"final",
"double",
"compact",
"(",
"long",
"sign",
",",
"double",
"natlog",
")",
"{",
"return",
"Double",
".",
"longBitsToDouble",
"(",
"sign",
"|",
"(",
"FLOAT_MASK",
"&",
"Double",
".",
"doubleToRawLongBits",
"(",
"natlog",
")",
")",
")",
";",
"}"
] |
Gets the compacted version from the sign and natural log.
|
[
"Gets",
"the",
"compacted",
"version",
"from",
"the",
"sign",
"and",
"natural",
"log",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/semiring/LogSignAlgebra.java#L73-L75
|
12,155
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/feat/FactorTemplateList.java
|
FactorTemplateList.getNumObsFeats
|
public int getNumObsFeats() {
int count = 0;
for (FactorTemplate ft : fts) {
count += ft.getAlphabet().size();
}
return count;
}
|
java
|
public int getNumObsFeats() {
int count = 0;
for (FactorTemplate ft : fts) {
count += ft.getAlphabet().size();
}
return count;
}
|
[
"public",
"int",
"getNumObsFeats",
"(",
")",
"{",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"FactorTemplate",
"ft",
":",
"fts",
")",
"{",
"count",
"+=",
"ft",
".",
"getAlphabet",
"(",
")",
".",
"size",
"(",
")",
";",
"}",
"return",
"count",
";",
"}"
] |
Gets the number of observation function features.
|
[
"Gets",
"the",
"number",
"of",
"observation",
"function",
"features",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/feat/FactorTemplateList.java#L47-L53
|
12,156
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java
|
AddBuddyImpl.execute
|
@SuppressWarnings("unchecked")
public ApiBuddy execute() {
User sfsOwner = api.getUserByName(owner);
ApiUser targetUser = getUser(target);
ApiUser ownerUser = (ApiUser) sfsOwner.getProperty(APIKey.USER);
ISFSBuddyResponseApi responseAPI = SmartFoxServer.getInstance().getAPIManager()
.getBuddyApi().getResponseAPI();
ISFSEventManager eventManager = SmartFoxServer.getInstance().getEventManager();
BuddyList buddyList = sfsOwner.getZone()
.getBuddyListManager().getBuddyList(owner);
BuddyListManager buddyListManager = sfsOwner.getZone().getBuddyListManager();
checkBuddyManagerIsActive(buddyListManager, sfsOwner);
sfsOwner.updateLastRequestTime();
ApiBuddyImpl buddy = new ApiBuddyImpl(target, temp);
buddy.setOwner(ownerUser);
buddy.setParentBuddyList(buddyList);
if(targetUser != null) buddy.setUser(targetUser);
try {
buddyList.addBuddy(buddy);
if (fireClientEvent)
responseAPI.notifyAddBuddy(buddy, sfsOwner);
if (fireServerEvent) {
Map<ISFSEventParam, Object> evtParams = new HashMap<>();
evtParams.put(SFSEventParam.ZONE, sfsOwner.getZone());
evtParams.put(SFSEventParam.USER, sfsOwner);
evtParams.put(SFSBuddyEventParam.BUDDY, buddy);
eventManager.dispatchEvent(new SFSEvent(SFSEventType.BUDDY_ADD, evtParams));
}
} catch (SFSBuddyListException e) {
if (fireClientEvent) {
api.getResponseAPI().notifyRequestError(e, sfsOwner, SystemRequest.AddBuddy);
}
return null;
}
return buddy;
}
|
java
|
@SuppressWarnings("unchecked")
public ApiBuddy execute() {
User sfsOwner = api.getUserByName(owner);
ApiUser targetUser = getUser(target);
ApiUser ownerUser = (ApiUser) sfsOwner.getProperty(APIKey.USER);
ISFSBuddyResponseApi responseAPI = SmartFoxServer.getInstance().getAPIManager()
.getBuddyApi().getResponseAPI();
ISFSEventManager eventManager = SmartFoxServer.getInstance().getEventManager();
BuddyList buddyList = sfsOwner.getZone()
.getBuddyListManager().getBuddyList(owner);
BuddyListManager buddyListManager = sfsOwner.getZone().getBuddyListManager();
checkBuddyManagerIsActive(buddyListManager, sfsOwner);
sfsOwner.updateLastRequestTime();
ApiBuddyImpl buddy = new ApiBuddyImpl(target, temp);
buddy.setOwner(ownerUser);
buddy.setParentBuddyList(buddyList);
if(targetUser != null) buddy.setUser(targetUser);
try {
buddyList.addBuddy(buddy);
if (fireClientEvent)
responseAPI.notifyAddBuddy(buddy, sfsOwner);
if (fireServerEvent) {
Map<ISFSEventParam, Object> evtParams = new HashMap<>();
evtParams.put(SFSEventParam.ZONE, sfsOwner.getZone());
evtParams.put(SFSEventParam.USER, sfsOwner);
evtParams.put(SFSBuddyEventParam.BUDDY, buddy);
eventManager.dispatchEvent(new SFSEvent(SFSEventType.BUDDY_ADD, evtParams));
}
} catch (SFSBuddyListException e) {
if (fireClientEvent) {
api.getResponseAPI().notifyRequestError(e, sfsOwner, SystemRequest.AddBuddy);
}
return null;
}
return buddy;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"ApiBuddy",
"execute",
"(",
")",
"{",
"User",
"sfsOwner",
"=",
"api",
".",
"getUserByName",
"(",
"owner",
")",
";",
"ApiUser",
"targetUser",
"=",
"getUser",
"(",
"target",
")",
";",
"ApiUser",
"ownerUser",
"=",
"(",
"ApiUser",
")",
"sfsOwner",
".",
"getProperty",
"(",
"APIKey",
".",
"USER",
")",
";",
"ISFSBuddyResponseApi",
"responseAPI",
"=",
"SmartFoxServer",
".",
"getInstance",
"(",
")",
".",
"getAPIManager",
"(",
")",
".",
"getBuddyApi",
"(",
")",
".",
"getResponseAPI",
"(",
")",
";",
"ISFSEventManager",
"eventManager",
"=",
"SmartFoxServer",
".",
"getInstance",
"(",
")",
".",
"getEventManager",
"(",
")",
";",
"BuddyList",
"buddyList",
"=",
"sfsOwner",
".",
"getZone",
"(",
")",
".",
"getBuddyListManager",
"(",
")",
".",
"getBuddyList",
"(",
"owner",
")",
";",
"BuddyListManager",
"buddyListManager",
"=",
"sfsOwner",
".",
"getZone",
"(",
")",
".",
"getBuddyListManager",
"(",
")",
";",
"checkBuddyManagerIsActive",
"(",
"buddyListManager",
",",
"sfsOwner",
")",
";",
"sfsOwner",
".",
"updateLastRequestTime",
"(",
")",
";",
"ApiBuddyImpl",
"buddy",
"=",
"new",
"ApiBuddyImpl",
"(",
"target",
",",
"temp",
")",
";",
"buddy",
".",
"setOwner",
"(",
"ownerUser",
")",
";",
"buddy",
".",
"setParentBuddyList",
"(",
"buddyList",
")",
";",
"if",
"(",
"targetUser",
"!=",
"null",
")",
"buddy",
".",
"setUser",
"(",
"targetUser",
")",
";",
"try",
"{",
"buddyList",
".",
"addBuddy",
"(",
"buddy",
")",
";",
"if",
"(",
"fireClientEvent",
")",
"responseAPI",
".",
"notifyAddBuddy",
"(",
"buddy",
",",
"sfsOwner",
")",
";",
"if",
"(",
"fireServerEvent",
")",
"{",
"Map",
"<",
"ISFSEventParam",
",",
"Object",
">",
"evtParams",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"evtParams",
".",
"put",
"(",
"SFSEventParam",
".",
"ZONE",
",",
"sfsOwner",
".",
"getZone",
"(",
")",
")",
";",
"evtParams",
".",
"put",
"(",
"SFSEventParam",
".",
"USER",
",",
"sfsOwner",
")",
";",
"evtParams",
".",
"put",
"(",
"SFSBuddyEventParam",
".",
"BUDDY",
",",
"buddy",
")",
";",
"eventManager",
".",
"dispatchEvent",
"(",
"new",
"SFSEvent",
"(",
"SFSEventType",
".",
"BUDDY_ADD",
",",
"evtParams",
")",
")",
";",
"}",
"}",
"catch",
"(",
"SFSBuddyListException",
"e",
")",
"{",
"if",
"(",
"fireClientEvent",
")",
"{",
"api",
".",
"getResponseAPI",
"(",
")",
".",
"notifyRequestError",
"(",
"e",
",",
"sfsOwner",
",",
"SystemRequest",
".",
"AddBuddy",
")",
";",
"}",
"return",
"null",
";",
"}",
"return",
"buddy",
";",
"}"
] |
Execute to add a buddy to list
|
[
"Execute",
"to",
"add",
"a",
"buddy",
"to",
"list"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java#L131-L166
|
12,157
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java
|
AddBuddyImpl.checkBuddyManagerIsActive
|
private void checkBuddyManagerIsActive(BuddyListManager buddyListManager, User sfsOwner) {
if (!buddyListManager.isActive()) {
throw new IllegalStateException(
String.format("BuddyList operation failure. BuddyListManager is not active. Zone: %s, Sender: %s", new Object[] { sfsOwner.getZone(), sfsOwner }));
}
}
|
java
|
private void checkBuddyManagerIsActive(BuddyListManager buddyListManager, User sfsOwner) {
if (!buddyListManager.isActive()) {
throw new IllegalStateException(
String.format("BuddyList operation failure. BuddyListManager is not active. Zone: %s, Sender: %s", new Object[] { sfsOwner.getZone(), sfsOwner }));
}
}
|
[
"private",
"void",
"checkBuddyManagerIsActive",
"(",
"BuddyListManager",
"buddyListManager",
",",
"User",
"sfsOwner",
")",
"{",
"if",
"(",
"!",
"buddyListManager",
".",
"isActive",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"String",
".",
"format",
"(",
"\"BuddyList operation failure. BuddyListManager is not active. Zone: %s, Sender: %s\"",
",",
"new",
"Object",
"[",
"]",
"{",
"sfsOwner",
".",
"getZone",
"(",
")",
",",
"sfsOwner",
"}",
")",
")",
";",
"}",
"}"
] |
Check whether buddy manager is active
@param buddyListManager manager object
@param sfsOwner buddy's owner
|
[
"Check",
"whether",
"buddy",
"manager",
"is",
"active"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java#L174-L179
|
12,158
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java
|
AddBuddyImpl.getUser
|
public ApiUser getUser(String name) {
User sfsUser = CommandUtil.getSfsUser(name, api);
if(sfsUser == null)
return null;
return (ApiUser) sfsUser.getProperty(APIKey.USER);
}
|
java
|
public ApiUser getUser(String name) {
User sfsUser = CommandUtil.getSfsUser(name, api);
if(sfsUser == null)
return null;
return (ApiUser) sfsUser.getProperty(APIKey.USER);
}
|
[
"public",
"ApiUser",
"getUser",
"(",
"String",
"name",
")",
"{",
"User",
"sfsUser",
"=",
"CommandUtil",
".",
"getSfsUser",
"(",
"name",
",",
"api",
")",
";",
"if",
"(",
"sfsUser",
"==",
"null",
")",
"return",
"null",
";",
"return",
"(",
"ApiUser",
")",
"sfsUser",
".",
"getProperty",
"(",
"APIKey",
".",
"USER",
")",
";",
"}"
] |
Get user agent reference
@param name name of user agent
@return user agent object
|
[
"Get",
"user",
"agent",
"reference"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/command/impl/AddBuddyImpl.java#L187-L192
|
12,159
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerReadyEventHandler.java
|
ServerReadyEventHandler.assignDataToHandler
|
protected void assignDataToHandler(ServerHandlerClass handler, Object instance) {
if(getParentExtension().getConfigProperties() != null) {
new ConfigPropertyDeserializer().deserialize(
handler.getPropertiesClassWrapper(),
instance,
getParentExtension().getConfigProperties());
}
}
|
java
|
protected void assignDataToHandler(ServerHandlerClass handler, Object instance) {
if(getParentExtension().getConfigProperties() != null) {
new ConfigPropertyDeserializer().deserialize(
handler.getPropertiesClassWrapper(),
instance,
getParentExtension().getConfigProperties());
}
}
|
[
"protected",
"void",
"assignDataToHandler",
"(",
"ServerHandlerClass",
"handler",
",",
"Object",
"instance",
")",
"{",
"if",
"(",
"getParentExtension",
"(",
")",
".",
"getConfigProperties",
"(",
")",
"!=",
"null",
")",
"{",
"new",
"ConfigPropertyDeserializer",
"(",
")",
".",
"deserialize",
"(",
"handler",
".",
"getPropertiesClassWrapper",
"(",
")",
",",
"instance",
",",
"getParentExtension",
"(",
")",
".",
"getConfigProperties",
"(",
")",
")",
";",
"}",
"}"
] |
Map configuration properties to handler object
@param handler structure of handler class
@param instance a handler instance
|
[
"Map",
"configuration",
"properties",
"to",
"handler",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/ServerReadyEventHandler.java#L53-L60
|
12,160
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.handleClientRequest
|
@Override
public void handleClientRequest(User user, ISFSObject params) {
try {
debugLogRequestInfo(user, params);
ApiUser apiUser = getUserAgent(user);
for(RequestResponseClass clazz : listeners) {
Object userAgent = checkUserAgent(clazz, apiUser);
notifyListener(clazz, params, user, userAgent);
}
} catch(Exception e) {
processHandlerException(e, user);
}
}
|
java
|
@Override
public void handleClientRequest(User user, ISFSObject params) {
try {
debugLogRequestInfo(user, params);
ApiUser apiUser = getUserAgent(user);
for(RequestResponseClass clazz : listeners) {
Object userAgent = checkUserAgent(clazz, apiUser);
notifyListener(clazz, params, user, userAgent);
}
} catch(Exception e) {
processHandlerException(e, user);
}
}
|
[
"@",
"Override",
"public",
"void",
"handleClientRequest",
"(",
"User",
"user",
",",
"ISFSObject",
"params",
")",
"{",
"try",
"{",
"debugLogRequestInfo",
"(",
"user",
",",
"params",
")",
";",
"ApiUser",
"apiUser",
"=",
"getUserAgent",
"(",
"user",
")",
";",
"for",
"(",
"RequestResponseClass",
"clazz",
":",
"listeners",
")",
"{",
"Object",
"userAgent",
"=",
"checkUserAgent",
"(",
"clazz",
",",
"apiUser",
")",
";",
"notifyListener",
"(",
"clazz",
",",
"params",
",",
"user",
",",
"userAgent",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"processHandlerException",
"(",
"e",
",",
"user",
")",
";",
"}",
"}"
] |
Handle request from client
|
[
"Handle",
"request",
"from",
"client"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L45-L57
|
12,161
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.notifyListener
|
private void notifyListener(RequestResponseClass clazz,
ISFSObject params, User user, Object userAgent) throws Exception {
Object listener = clazz.newInstance();
setDataToListener(clazz, listener, params);
invokeExecuteMethod(clazz.getExecuteMethod(), listener, userAgent);
responseClient(clazz, listener, user);
}
|
java
|
private void notifyListener(RequestResponseClass clazz,
ISFSObject params, User user, Object userAgent) throws Exception {
Object listener = clazz.newInstance();
setDataToListener(clazz, listener, params);
invokeExecuteMethod(clazz.getExecuteMethod(), listener, userAgent);
responseClient(clazz, listener, user);
}
|
[
"private",
"void",
"notifyListener",
"(",
"RequestResponseClass",
"clazz",
",",
"ISFSObject",
"params",
",",
"User",
"user",
",",
"Object",
"userAgent",
")",
"throws",
"Exception",
"{",
"Object",
"listener",
"=",
"clazz",
".",
"newInstance",
"(",
")",
";",
"setDataToListener",
"(",
"clazz",
",",
"listener",
",",
"params",
")",
";",
"invokeExecuteMethod",
"(",
"clazz",
".",
"getExecuteMethod",
"(",
")",
",",
"listener",
",",
"userAgent",
")",
";",
"responseClient",
"(",
"clazz",
",",
"listener",
",",
"user",
")",
";",
"}"
] |
Notify all listeners
@param clazz structure of listener class
@param params request parameters
@param user request user
@param userAgent user agent's object
@throws Exception when has any error from listener
|
[
"Notify",
"all",
"listeners"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L92-L98
|
12,162
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.invokeExecuteMethod
|
protected void invokeExecuteMethod(Method method, Object listener, Object userAgent) {
ReflectMethodUtil.invokeExecuteMethod(
method, listener, context, userAgent);
}
|
java
|
protected void invokeExecuteMethod(Method method, Object listener, Object userAgent) {
ReflectMethodUtil.invokeExecuteMethod(
method, listener, context, userAgent);
}
|
[
"protected",
"void",
"invokeExecuteMethod",
"(",
"Method",
"method",
",",
"Object",
"listener",
",",
"Object",
"userAgent",
")",
"{",
"ReflectMethodUtil",
".",
"invokeExecuteMethod",
"(",
"method",
",",
"listener",
",",
"context",
",",
"userAgent",
")",
";",
"}"
] |
Invoke the execute method
@param method the execute method
@param listener the listener
@param userAgent the user agent object
|
[
"Invoke",
"the",
"execute",
"method"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L121-L124
|
12,163
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.checkUserAgent
|
private Object checkUserAgent(RequestResponseClass clazz, ApiUser userAgent) {
if(clazz.getUserClass().isAssignableFrom(userAgent.getClass()))
return userAgent;
return UserAgentUtil.getGameUser(userAgent, clazz.getUserClass());
}
|
java
|
private Object checkUserAgent(RequestResponseClass clazz, ApiUser userAgent) {
if(clazz.getUserClass().isAssignableFrom(userAgent.getClass()))
return userAgent;
return UserAgentUtil.getGameUser(userAgent, clazz.getUserClass());
}
|
[
"private",
"Object",
"checkUserAgent",
"(",
"RequestResponseClass",
"clazz",
",",
"ApiUser",
"userAgent",
")",
"{",
"if",
"(",
"clazz",
".",
"getUserClass",
"(",
")",
".",
"isAssignableFrom",
"(",
"userAgent",
".",
"getClass",
"(",
")",
")",
")",
"return",
"userAgent",
";",
"return",
"UserAgentUtil",
".",
"getGameUser",
"(",
"userAgent",
",",
"clazz",
".",
"getUserClass",
"(",
")",
")",
";",
"}"
] |
For each listener, we may use a class of user agent, so we need check it
@param clazz structure of listener class
@param userAgent user agent object
@return instance of user agent
|
[
"For",
"each",
"listener",
"we",
"may",
"use",
"a",
"class",
"of",
"user",
"agent",
"so",
"we",
"need",
"check",
"it"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L133-L137
|
12,164
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.responseClient
|
private void responseClient(RequestResponseClass clazz, Object listener, User user) {
if(!clazz.isResponseToClient()) return;
String command = clazz.getResponseCommand();
ISFSObject params = (ISFSObject) new ParamTransformer(context)
.transform(listener).getObject();
send(command, params, user);
}
|
java
|
private void responseClient(RequestResponseClass clazz, Object listener, User user) {
if(!clazz.isResponseToClient()) return;
String command = clazz.getResponseCommand();
ISFSObject params = (ISFSObject) new ParamTransformer(context)
.transform(listener).getObject();
send(command, params, user);
}
|
[
"private",
"void",
"responseClient",
"(",
"RequestResponseClass",
"clazz",
",",
"Object",
"listener",
",",
"User",
"user",
")",
"{",
"if",
"(",
"!",
"clazz",
".",
"isResponseToClient",
"(",
")",
")",
"return",
";",
"String",
"command",
"=",
"clazz",
".",
"getResponseCommand",
"(",
")",
";",
"ISFSObject",
"params",
"=",
"(",
"ISFSObject",
")",
"new",
"ParamTransformer",
"(",
"context",
")",
".",
"transform",
"(",
"listener",
")",
".",
"getObject",
"(",
")",
";",
"send",
"(",
"command",
",",
"params",
",",
"user",
")",
";",
"}"
] |
Response information to client
@param clazz structure of listener class
@param listener listener object
@param user smartfox user
|
[
"Response",
"information",
"to",
"client"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L146-L152
|
12,165
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.responseErrorToClient
|
private void responseErrorToClient(Exception ex, User user) {
BadRequestException e = getBadRequestException(ex);
if(!e.isSendToClient()) return;
ISFSObject params = new SFSObject();
params.putUtfString(APIKey.MESSAGE, e.getReason());
params.putInt(APIKey.CODE, e.getCode());
send(APIKey.ERROR, params, user);
}
|
java
|
private void responseErrorToClient(Exception ex, User user) {
BadRequestException e = getBadRequestException(ex);
if(!e.isSendToClient()) return;
ISFSObject params = new SFSObject();
params.putUtfString(APIKey.MESSAGE, e.getReason());
params.putInt(APIKey.CODE, e.getCode());
send(APIKey.ERROR, params, user);
}
|
[
"private",
"void",
"responseErrorToClient",
"(",
"Exception",
"ex",
",",
"User",
"user",
")",
"{",
"BadRequestException",
"e",
"=",
"getBadRequestException",
"(",
"ex",
")",
";",
"if",
"(",
"!",
"e",
".",
"isSendToClient",
"(",
")",
")",
"return",
";",
"ISFSObject",
"params",
"=",
"new",
"SFSObject",
"(",
")",
";",
"params",
".",
"putUtfString",
"(",
"APIKey",
".",
"MESSAGE",
",",
"e",
".",
"getReason",
"(",
")",
")",
";",
"params",
".",
"putInt",
"(",
"APIKey",
".",
"CODE",
",",
"e",
".",
"getCode",
"(",
")",
")",
";",
"send",
"(",
"APIKey",
".",
"ERROR",
",",
"params",
",",
"user",
")",
";",
"}"
] |
Response error to client
@param ex the exception
@param user the recipient
|
[
"Response",
"error",
"to",
"client"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L171-L178
|
12,166
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java
|
ClientEventHandler.getBadRequestException
|
private BadRequestException getBadRequestException(Exception ex) {
return (BadRequestException) ExceptionUtils
.getThrowables(ex)[ExceptionUtils.indexOfThrowable(ex, BadRequestException.class)];
}
|
java
|
private BadRequestException getBadRequestException(Exception ex) {
return (BadRequestException) ExceptionUtils
.getThrowables(ex)[ExceptionUtils.indexOfThrowable(ex, BadRequestException.class)];
}
|
[
"private",
"BadRequestException",
"getBadRequestException",
"(",
"Exception",
"ex",
")",
"{",
"return",
"(",
"BadRequestException",
")",
"ExceptionUtils",
".",
"getThrowables",
"(",
"ex",
")",
"[",
"ExceptionUtils",
".",
"indexOfThrowable",
"(",
"ex",
",",
"BadRequestException",
".",
"class",
")",
"]",
";",
"}"
] |
Get BadRequestException from the exception
@param ex the exception
@return BadRequestException
|
[
"Get",
"BadRequestException",
"from",
"the",
"exception"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/clienthandler/ClientEventHandler.java#L186-L189
|
12,167
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentDeserializer.java
|
AgentDeserializer.getValue
|
protected Object getValue(SetterMethodCover method, Variable variable) {
if(method.isTwoDimensionsArray())
return assignValuesToTwoDimensionsArray(method, variable.getSFSArrayValue());
if(method.isArray())
return assignValuesToArray(method, variable);
if(method.isColection())
return assignValuesToCollection(method, variable);
if(method.isObject())
return assignValuesToObject(method, variable.getSFSObjectValue());
if(method.isByte())
return variable.getIntValue().byteValue();
if(method.isChar())
return (char)variable.getIntValue().byteValue();
if(method.isFloat())
return variable.getDoubleValue().floatValue();
if(method.isLong())
return variable.getDoubleValue().longValue();
if(method.isShort())
return variable.getIntValue().shortValue();
return variable.getValue();
}
|
java
|
protected Object getValue(SetterMethodCover method, Variable variable) {
if(method.isTwoDimensionsArray())
return assignValuesToTwoDimensionsArray(method, variable.getSFSArrayValue());
if(method.isArray())
return assignValuesToArray(method, variable);
if(method.isColection())
return assignValuesToCollection(method, variable);
if(method.isObject())
return assignValuesToObject(method, variable.getSFSObjectValue());
if(method.isByte())
return variable.getIntValue().byteValue();
if(method.isChar())
return (char)variable.getIntValue().byteValue();
if(method.isFloat())
return variable.getDoubleValue().floatValue();
if(method.isLong())
return variable.getDoubleValue().longValue();
if(method.isShort())
return variable.getIntValue().shortValue();
return variable.getValue();
}
|
[
"protected",
"Object",
"getValue",
"(",
"SetterMethodCover",
"method",
",",
"Variable",
"variable",
")",
"{",
"if",
"(",
"method",
".",
"isTwoDimensionsArray",
"(",
")",
")",
"return",
"assignValuesToTwoDimensionsArray",
"(",
"method",
",",
"variable",
".",
"getSFSArrayValue",
"(",
")",
")",
";",
"if",
"(",
"method",
".",
"isArray",
"(",
")",
")",
"return",
"assignValuesToArray",
"(",
"method",
",",
"variable",
")",
";",
"if",
"(",
"method",
".",
"isColection",
"(",
")",
")",
"return",
"assignValuesToCollection",
"(",
"method",
",",
"variable",
")",
";",
"if",
"(",
"method",
".",
"isObject",
"(",
")",
")",
"return",
"assignValuesToObject",
"(",
"method",
",",
"variable",
".",
"getSFSObjectValue",
"(",
")",
")",
";",
"if",
"(",
"method",
".",
"isByte",
"(",
")",
")",
"return",
"variable",
".",
"getIntValue",
"(",
")",
".",
"byteValue",
"(",
")",
";",
"if",
"(",
"method",
".",
"isChar",
"(",
")",
")",
"return",
"(",
"char",
")",
"variable",
".",
"getIntValue",
"(",
")",
".",
"byteValue",
"(",
")",
";",
"if",
"(",
"method",
".",
"isFloat",
"(",
")",
")",
"return",
"variable",
".",
"getDoubleValue",
"(",
")",
".",
"floatValue",
"(",
")",
";",
"if",
"(",
"method",
".",
"isLong",
"(",
")",
")",
"return",
"variable",
".",
"getDoubleValue",
"(",
")",
".",
"longValue",
"(",
")",
";",
"if",
"(",
"method",
".",
"isShort",
"(",
")",
")",
"return",
"variable",
".",
"getIntValue",
"(",
")",
".",
"shortValue",
"(",
")",
";",
"return",
"variable",
".",
"getValue",
"(",
")",
";",
"}"
] |
Get value from the variable
@param method structure of setter method
@param variable the variable
@return a value
|
[
"Get",
"value",
"from",
"the",
"variable"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentDeserializer.java#L77-L99
|
12,168
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseMethods
|
protected ISFSObject parseMethods(ClassUnwrapper unwrapper,
Object object) {
return object2params(unwrapper, object, new SFSObject());
}
|
java
|
protected ISFSObject parseMethods(ClassUnwrapper unwrapper,
Object object) {
return object2params(unwrapper, object, new SFSObject());
}
|
[
"protected",
"ISFSObject",
"parseMethods",
"(",
"ClassUnwrapper",
"unwrapper",
",",
"Object",
"object",
")",
"{",
"return",
"object2params",
"(",
"unwrapper",
",",
"object",
",",
"new",
"SFSObject",
"(",
")",
")",
";",
"}"
] |
Invoke getter method and add returned value to SFSObject
@param unwrapper structure of java class
@param object the java object
@return the SFSObject
|
[
"Invoke",
"getter",
"method",
"and",
"add",
"returned",
"value",
"to",
"SFSObject"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L80-L84
|
12,169
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseTwoDimensionsArray
|
protected Object parseTwoDimensionsArray(GetterMethodCover method,
Object array) {
ISFSArray answer = new SFSArray();
int size = Array.getLength(array);
for(int i = 0 ; i < size ; i++) {
SFSDataType dtype = getSFSArrayDataType(method);
Object value = parseArrayOfTwoDimensionsArray(method, Array.get(array, i));
answer.add(new SFSDataWrapper(dtype, value));
}
return answer;
}
|
java
|
protected Object parseTwoDimensionsArray(GetterMethodCover method,
Object array) {
ISFSArray answer = new SFSArray();
int size = Array.getLength(array);
for(int i = 0 ; i < size ; i++) {
SFSDataType dtype = getSFSArrayDataType(method);
Object value = parseArrayOfTwoDimensionsArray(method, Array.get(array, i));
answer.add(new SFSDataWrapper(dtype, value));
}
return answer;
}
|
[
"protected",
"Object",
"parseTwoDimensionsArray",
"(",
"GetterMethodCover",
"method",
",",
"Object",
"array",
")",
"{",
"ISFSArray",
"answer",
"=",
"new",
"SFSArray",
"(",
")",
";",
"int",
"size",
"=",
"Array",
".",
"getLength",
"(",
"array",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"SFSDataType",
"dtype",
"=",
"getSFSArrayDataType",
"(",
"method",
")",
";",
"Object",
"value",
"=",
"parseArrayOfTwoDimensionsArray",
"(",
"method",
",",
"Array",
".",
"get",
"(",
"array",
",",
"i",
")",
")",
";",
"answer",
".",
"add",
"(",
"new",
"SFSDataWrapper",
"(",
"dtype",
",",
"value",
")",
")",
";",
"}",
"return",
"answer",
";",
"}"
] |
Serialize two-dimensions array to ISFSArray
@param method method's structure
@param array the two-dimensions array
@return ISFSArray object
|
[
"Serialize",
"two",
"-",
"dimensions",
"array",
"to",
"ISFSArray"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L123-L133
|
12,170
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseArray
|
protected Object parseArray(GetterMethodCover method,
Object array) {
if(method.isObjectArray()) {
return parseObjectArray(method, (Object[])array);
}
else if(method.isPrimitiveBooleanArray()) {
return primitiveArrayToBoolCollection((boolean[])array);
}
else if(method.isPrimitiveCharArray()) {
return charArrayToByteArray((char[])array);
}
else if(method.isPrimitiveDoubleArray()) {
return primitiveArrayToDoubleCollection((double[])array);
}
else if(method.isPrimitiveFloatArray()) {
return primitiveArrayToFloatCollection((float[])array);
}
else if(method.isPrimitiveIntArray()) {
return primitiveArrayToIntCollection((int[])array);
}
else if(method.isPrimitiveLongArray()) {
return primitiveArrayToLongCollection((long[])array);
}
else if(method.isPrimitiveShortArray()) {
return primitiveArrayToShortCollection((short[])array);
}
else if(method.isStringArray()) {
return stringArrayToCollection((String[])array);
}
else if(method.isWrapperBooleanArray()) {
return wrapperArrayToCollection((Boolean[])array);
}
else if(method.isWrapperByteArray()) {
return toPrimitiveByteArray((Byte[])array);
}
else if(method.isWrapperCharArray()) {
return charWrapperArrayToPrimitiveByteArray((Character[])array);
}
else if(method.isWrapperDoubleArray()) {
return wrapperArrayToCollection((Double[])array);
}
else if(method.isWrapperFloatArray()) {
return wrapperArrayToCollection((Float[])array);
}
else if(method.isWrapperIntArray()) {
return wrapperArrayToCollection((Integer[])array);
}
else if(method.isWrapperLongArray()) {
return wrapperArrayToCollection((Long[])array);
}
else if(method.isWrapperShortArray()) {
return wrapperArrayToCollection((Short[])array);
}
return array;
}
|
java
|
protected Object parseArray(GetterMethodCover method,
Object array) {
if(method.isObjectArray()) {
return parseObjectArray(method, (Object[])array);
}
else if(method.isPrimitiveBooleanArray()) {
return primitiveArrayToBoolCollection((boolean[])array);
}
else if(method.isPrimitiveCharArray()) {
return charArrayToByteArray((char[])array);
}
else if(method.isPrimitiveDoubleArray()) {
return primitiveArrayToDoubleCollection((double[])array);
}
else if(method.isPrimitiveFloatArray()) {
return primitiveArrayToFloatCollection((float[])array);
}
else if(method.isPrimitiveIntArray()) {
return primitiveArrayToIntCollection((int[])array);
}
else if(method.isPrimitiveLongArray()) {
return primitiveArrayToLongCollection((long[])array);
}
else if(method.isPrimitiveShortArray()) {
return primitiveArrayToShortCollection((short[])array);
}
else if(method.isStringArray()) {
return stringArrayToCollection((String[])array);
}
else if(method.isWrapperBooleanArray()) {
return wrapperArrayToCollection((Boolean[])array);
}
else if(method.isWrapperByteArray()) {
return toPrimitiveByteArray((Byte[])array);
}
else if(method.isWrapperCharArray()) {
return charWrapperArrayToPrimitiveByteArray((Character[])array);
}
else if(method.isWrapperDoubleArray()) {
return wrapperArrayToCollection((Double[])array);
}
else if(method.isWrapperFloatArray()) {
return wrapperArrayToCollection((Float[])array);
}
else if(method.isWrapperIntArray()) {
return wrapperArrayToCollection((Integer[])array);
}
else if(method.isWrapperLongArray()) {
return wrapperArrayToCollection((Long[])array);
}
else if(method.isWrapperShortArray()) {
return wrapperArrayToCollection((Short[])array);
}
return array;
}
|
[
"protected",
"Object",
"parseArray",
"(",
"GetterMethodCover",
"method",
",",
"Object",
"array",
")",
"{",
"if",
"(",
"method",
".",
"isObjectArray",
"(",
")",
")",
"{",
"return",
"parseObjectArray",
"(",
"method",
",",
"(",
"Object",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveBooleanArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToBoolCollection",
"(",
"(",
"boolean",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveCharArray",
"(",
")",
")",
"{",
"return",
"charArrayToByteArray",
"(",
"(",
"char",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveDoubleArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToDoubleCollection",
"(",
"(",
"double",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveFloatArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToFloatCollection",
"(",
"(",
"float",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveIntArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToIntCollection",
"(",
"(",
"int",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveLongArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToLongCollection",
"(",
"(",
"long",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isPrimitiveShortArray",
"(",
")",
")",
"{",
"return",
"primitiveArrayToShortCollection",
"(",
"(",
"short",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isStringArray",
"(",
")",
")",
"{",
"return",
"stringArrayToCollection",
"(",
"(",
"String",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperBooleanArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Boolean",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperByteArray",
"(",
")",
")",
"{",
"return",
"toPrimitiveByteArray",
"(",
"(",
"Byte",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperCharArray",
"(",
")",
")",
"{",
"return",
"charWrapperArrayToPrimitiveByteArray",
"(",
"(",
"Character",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperDoubleArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Double",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperFloatArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Float",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperIntArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Integer",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperLongArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Long",
"[",
"]",
")",
"array",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isWrapperShortArray",
"(",
")",
")",
"{",
"return",
"wrapperArrayToCollection",
"(",
"(",
"Short",
"[",
"]",
")",
"array",
")",
";",
"}",
"return",
"array",
";",
"}"
] |
Convert array of values to collection of values
@param method structure of getter method
@param array the array of values
@return the collection of values
|
[
"Convert",
"array",
"of",
"values",
"to",
"collection",
"of",
"values"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L198-L252
|
12,171
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseCollection
|
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object parseCollection(GetterMethodCover method,
Collection collection) {
if(method.isArrayObjectCollection()) {
return parseArrayObjectCollection(method, collection);
}
else if(method.isObjectCollection()) {
return parseObjectCollection(method, collection);
}
else if(method.isByteCollection()) {
return collectionToPrimitiveByteArray(collection);
}
else if(method.isCharCollection()) {
return charCollectionToPrimitiveByteArray(collection);
}
else if(method.isArrayCollection()) {
return parseArrayCollection(method, collection);
}
return collection;
}
|
java
|
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object parseCollection(GetterMethodCover method,
Collection collection) {
if(method.isArrayObjectCollection()) {
return parseArrayObjectCollection(method, collection);
}
else if(method.isObjectCollection()) {
return parseObjectCollection(method, collection);
}
else if(method.isByteCollection()) {
return collectionToPrimitiveByteArray(collection);
}
else if(method.isCharCollection()) {
return charCollectionToPrimitiveByteArray(collection);
}
else if(method.isArrayCollection()) {
return parseArrayCollection(method, collection);
}
return collection;
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"rawtypes\"",
",",
"\"unchecked\"",
"}",
")",
"protected",
"Object",
"parseCollection",
"(",
"GetterMethodCover",
"method",
",",
"Collection",
"collection",
")",
"{",
"if",
"(",
"method",
".",
"isArrayObjectCollection",
"(",
")",
")",
"{",
"return",
"parseArrayObjectCollection",
"(",
"method",
",",
"collection",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isObjectCollection",
"(",
")",
")",
"{",
"return",
"parseObjectCollection",
"(",
"method",
",",
"collection",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isByteCollection",
"(",
")",
")",
"{",
"return",
"collectionToPrimitiveByteArray",
"(",
"collection",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isCharCollection",
"(",
")",
")",
"{",
"return",
"charCollectionToPrimitiveByteArray",
"(",
"collection",
")",
";",
"}",
"else",
"if",
"(",
"method",
".",
"isArrayCollection",
"(",
")",
")",
"{",
"return",
"parseArrayCollection",
"(",
"method",
",",
"collection",
")",
";",
"}",
"return",
"collection",
";",
"}"
] |
Parse collection of values and get the value mapped to smartfox value
@param method structure of getter method
@param collection collection of value
@return the value after parsed
|
[
"Parse",
"collection",
"of",
"values",
"and",
"get",
"the",
"value",
"mapped",
"to",
"smartfox",
"value"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L261-L280
|
12,172
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseObjectCollection
|
@SuppressWarnings({ "rawtypes" })
protected ISFSArray parseObjectCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
for(Object obj : collection) {
result.addSFSObject(parseObject(
method, obj));
}
return result;
}
|
java
|
@SuppressWarnings({ "rawtypes" })
protected ISFSArray parseObjectCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
for(Object obj : collection) {
result.addSFSObject(parseObject(
method, obj));
}
return result;
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"rawtypes\"",
"}",
")",
"protected",
"ISFSArray",
"parseObjectCollection",
"(",
"GetterMethodCover",
"method",
",",
"Collection",
"collection",
")",
"{",
"ISFSArray",
"result",
"=",
"new",
"SFSArray",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"collection",
")",
"{",
"result",
".",
"addSFSObject",
"(",
"parseObject",
"(",
"method",
",",
"obj",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Serialize collection of objects to a SFSArray
@param method structure of getter method
@param collection collection of objects
@return the SFSArray
|
[
"Serialize",
"collection",
"of",
"objects",
"to",
"a",
"SFSArray"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L331-L340
|
12,173
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseArrayObjectCollection
|
@SuppressWarnings({ "rawtypes" })
protected ISFSArray parseArrayObjectCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
for(Object obj : collection) {
result.addSFSArray(parseObjectArray(
method,
(Object[])obj));
}
return result;
}
|
java
|
@SuppressWarnings({ "rawtypes" })
protected ISFSArray parseArrayObjectCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
for(Object obj : collection) {
result.addSFSArray(parseObjectArray(
method,
(Object[])obj));
}
return result;
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"rawtypes\"",
"}",
")",
"protected",
"ISFSArray",
"parseArrayObjectCollection",
"(",
"GetterMethodCover",
"method",
",",
"Collection",
"collection",
")",
"{",
"ISFSArray",
"result",
"=",
"new",
"SFSArray",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"collection",
")",
"{",
"result",
".",
"addSFSArray",
"(",
"parseObjectArray",
"(",
"method",
",",
"(",
"Object",
"[",
"]",
")",
"obj",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Serialize collection of java array object to a SFSArray
@param method structure of getter method
@param collection collection of java objects
@return the SFSArray
|
[
"Serialize",
"collection",
"of",
"java",
"array",
"object",
"to",
"a",
"SFSArray"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L349-L359
|
12,174
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.parseArrayCollection
|
@SuppressWarnings("rawtypes")
protected ISFSArray parseArrayCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
SFSDataType dataType = ParamTypeParser
.getParamType(method.getGenericType());
Class<?> type = method.getGenericType().getComponentType();
for(Object obj : collection) {
Object value = obj;
if(isPrimitiveChar(type)) {
value = charArrayToByteArray((char[])value);
}
else if(isWrapperByte(type)) {
value = toPrimitiveByteArray((Byte[])value);
}
else if(isWrapperChar(type)) {
value = charWrapperArrayToPrimitiveByteArray((Character[])value);
}
else {
value = arrayToList(value);
}
result.add(new SFSDataWrapper(dataType, value));
}
return result;
}
|
java
|
@SuppressWarnings("rawtypes")
protected ISFSArray parseArrayCollection(GetterMethodCover method,
Collection collection) {
ISFSArray result = new SFSArray();
SFSDataType dataType = ParamTypeParser
.getParamType(method.getGenericType());
Class<?> type = method.getGenericType().getComponentType();
for(Object obj : collection) {
Object value = obj;
if(isPrimitiveChar(type)) {
value = charArrayToByteArray((char[])value);
}
else if(isWrapperByte(type)) {
value = toPrimitiveByteArray((Byte[])value);
}
else if(isWrapperChar(type)) {
value = charWrapperArrayToPrimitiveByteArray((Character[])value);
}
else {
value = arrayToList(value);
}
result.add(new SFSDataWrapper(dataType, value));
}
return result;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"rawtypes\"",
")",
"protected",
"ISFSArray",
"parseArrayCollection",
"(",
"GetterMethodCover",
"method",
",",
"Collection",
"collection",
")",
"{",
"ISFSArray",
"result",
"=",
"new",
"SFSArray",
"(",
")",
";",
"SFSDataType",
"dataType",
"=",
"ParamTypeParser",
".",
"getParamType",
"(",
"method",
".",
"getGenericType",
"(",
")",
")",
";",
"Class",
"<",
"?",
">",
"type",
"=",
"method",
".",
"getGenericType",
"(",
")",
".",
"getComponentType",
"(",
")",
";",
"for",
"(",
"Object",
"obj",
":",
"collection",
")",
"{",
"Object",
"value",
"=",
"obj",
";",
"if",
"(",
"isPrimitiveChar",
"(",
"type",
")",
")",
"{",
"value",
"=",
"charArrayToByteArray",
"(",
"(",
"char",
"[",
"]",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"isWrapperByte",
"(",
"type",
")",
")",
"{",
"value",
"=",
"toPrimitiveByteArray",
"(",
"(",
"Byte",
"[",
"]",
")",
"value",
")",
";",
"}",
"else",
"if",
"(",
"isWrapperChar",
"(",
"type",
")",
")",
"{",
"value",
"=",
"charWrapperArrayToPrimitiveByteArray",
"(",
"(",
"Character",
"[",
"]",
")",
"value",
")",
";",
"}",
"else",
"{",
"value",
"=",
"arrayToList",
"(",
"value",
")",
";",
"}",
"result",
".",
"add",
"(",
"new",
"SFSDataWrapper",
"(",
"dataType",
",",
"value",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Serialize collection of array to a SFSArray
@param method structure of getter method
@param collection collection of objects
@return the SFSArray
|
[
"Serialize",
"collection",
"of",
"array",
"to",
"a",
"SFSArray"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L368-L392
|
12,175
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java
|
ParameterSerializer.getSFSDataType
|
private SFSDataType getSFSDataType(MethodCover method) {
if(method.isBoolean())
return SFSDataType.BOOL;
if(method.isByte())
return SFSDataType.BYTE;
if(method.isChar())
return SFSDataType.BYTE;
if(method.isDouble())
return SFSDataType.DOUBLE;
if(method.isFloat())
return SFSDataType.FLOAT;
if(method.isInt())
return SFSDataType.INT;
if(method.isLong())
return SFSDataType.LONG;
if(method.isShort())
return SFSDataType.SHORT;
if(method.isString())
return SFSDataType.UTF_STRING;
if(method.isObject())
return SFSDataType.SFS_OBJECT;
if(method.isBooleanArray())
return SFSDataType.BOOL_ARRAY;
if(method.isByteArray())
return SFSDataType.BYTE_ARRAY;
if(method.isCharArray())
return SFSDataType.BYTE_ARRAY;
if(method.isDoubleArray())
return SFSDataType.DOUBLE_ARRAY;
if(method.isFloatArray())
return SFSDataType.FLOAT_ARRAY;
if(method.isIntArray())
return SFSDataType.INT_ARRAY;
if(method.isLongArray())
return SFSDataType.LONG_ARRAY;
if(method.isShortArray())
return SFSDataType.SHORT_ARRAY;
if(method.isStringArray())
return SFSDataType.UTF_STRING_ARRAY;
if(method.isObjectArray())
return SFSDataType.SFS_ARRAY;
if(method.isBooleanCollection())
return SFSDataType.BOOL_ARRAY;
if(method.isByteCollection())
return SFSDataType.BYTE_ARRAY;
if(method.isCharCollection())
return SFSDataType.BYTE_ARRAY;
if(method.isDoubleCollection())
return SFSDataType.DOUBLE_ARRAY;
if(method.isFloatCollection())
return SFSDataType.FLOAT_ARRAY;
if(method.isIntCollection())
return SFSDataType.INT_ARRAY;
if(method.isLongCollection())
return SFSDataType.LONG_ARRAY;
if(method.isShortCollection())
return SFSDataType.SHORT_ARRAY;
if(method.isStringCollection())
return SFSDataType.UTF_STRING_ARRAY;
if(method.isObjectCollection())
return SFSDataType.SFS_ARRAY;
if(method.isArrayObjectCollection())
return SFSDataType.SFS_ARRAY;
return SFSDataType.SFS_ARRAY;
}
|
java
|
private SFSDataType getSFSDataType(MethodCover method) {
if(method.isBoolean())
return SFSDataType.BOOL;
if(method.isByte())
return SFSDataType.BYTE;
if(method.isChar())
return SFSDataType.BYTE;
if(method.isDouble())
return SFSDataType.DOUBLE;
if(method.isFloat())
return SFSDataType.FLOAT;
if(method.isInt())
return SFSDataType.INT;
if(method.isLong())
return SFSDataType.LONG;
if(method.isShort())
return SFSDataType.SHORT;
if(method.isString())
return SFSDataType.UTF_STRING;
if(method.isObject())
return SFSDataType.SFS_OBJECT;
if(method.isBooleanArray())
return SFSDataType.BOOL_ARRAY;
if(method.isByteArray())
return SFSDataType.BYTE_ARRAY;
if(method.isCharArray())
return SFSDataType.BYTE_ARRAY;
if(method.isDoubleArray())
return SFSDataType.DOUBLE_ARRAY;
if(method.isFloatArray())
return SFSDataType.FLOAT_ARRAY;
if(method.isIntArray())
return SFSDataType.INT_ARRAY;
if(method.isLongArray())
return SFSDataType.LONG_ARRAY;
if(method.isShortArray())
return SFSDataType.SHORT_ARRAY;
if(method.isStringArray())
return SFSDataType.UTF_STRING_ARRAY;
if(method.isObjectArray())
return SFSDataType.SFS_ARRAY;
if(method.isBooleanCollection())
return SFSDataType.BOOL_ARRAY;
if(method.isByteCollection())
return SFSDataType.BYTE_ARRAY;
if(method.isCharCollection())
return SFSDataType.BYTE_ARRAY;
if(method.isDoubleCollection())
return SFSDataType.DOUBLE_ARRAY;
if(method.isFloatCollection())
return SFSDataType.FLOAT_ARRAY;
if(method.isIntCollection())
return SFSDataType.INT_ARRAY;
if(method.isLongCollection())
return SFSDataType.LONG_ARRAY;
if(method.isShortCollection())
return SFSDataType.SHORT_ARRAY;
if(method.isStringCollection())
return SFSDataType.UTF_STRING_ARRAY;
if(method.isObjectCollection())
return SFSDataType.SFS_ARRAY;
if(method.isArrayObjectCollection())
return SFSDataType.SFS_ARRAY;
return SFSDataType.SFS_ARRAY;
}
|
[
"private",
"SFSDataType",
"getSFSDataType",
"(",
"MethodCover",
"method",
")",
"{",
"if",
"(",
"method",
".",
"isBoolean",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BOOL",
";",
"if",
"(",
"method",
".",
"isByte",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE",
";",
"if",
"(",
"method",
".",
"isChar",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE",
";",
"if",
"(",
"method",
".",
"isDouble",
"(",
")",
")",
"return",
"SFSDataType",
".",
"DOUBLE",
";",
"if",
"(",
"method",
".",
"isFloat",
"(",
")",
")",
"return",
"SFSDataType",
".",
"FLOAT",
";",
"if",
"(",
"method",
".",
"isInt",
"(",
")",
")",
"return",
"SFSDataType",
".",
"INT",
";",
"if",
"(",
"method",
".",
"isLong",
"(",
")",
")",
"return",
"SFSDataType",
".",
"LONG",
";",
"if",
"(",
"method",
".",
"isShort",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SHORT",
";",
"if",
"(",
"method",
".",
"isString",
"(",
")",
")",
"return",
"SFSDataType",
".",
"UTF_STRING",
";",
"if",
"(",
"method",
".",
"isObject",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SFS_OBJECT",
";",
"if",
"(",
"method",
".",
"isBooleanArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BOOL_ARRAY",
";",
"if",
"(",
"method",
".",
"isByteArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE_ARRAY",
";",
"if",
"(",
"method",
".",
"isCharArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE_ARRAY",
";",
"if",
"(",
"method",
".",
"isDoubleArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"DOUBLE_ARRAY",
";",
"if",
"(",
"method",
".",
"isFloatArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"FLOAT_ARRAY",
";",
"if",
"(",
"method",
".",
"isIntArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"INT_ARRAY",
";",
"if",
"(",
"method",
".",
"isLongArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"LONG_ARRAY",
";",
"if",
"(",
"method",
".",
"isShortArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SHORT_ARRAY",
";",
"if",
"(",
"method",
".",
"isStringArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"UTF_STRING_ARRAY",
";",
"if",
"(",
"method",
".",
"isObjectArray",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SFS_ARRAY",
";",
"if",
"(",
"method",
".",
"isBooleanCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BOOL_ARRAY",
";",
"if",
"(",
"method",
".",
"isByteCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE_ARRAY",
";",
"if",
"(",
"method",
".",
"isCharCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"BYTE_ARRAY",
";",
"if",
"(",
"method",
".",
"isDoubleCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"DOUBLE_ARRAY",
";",
"if",
"(",
"method",
".",
"isFloatCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"FLOAT_ARRAY",
";",
"if",
"(",
"method",
".",
"isIntCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"INT_ARRAY",
";",
"if",
"(",
"method",
".",
"isLongCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"LONG_ARRAY",
";",
"if",
"(",
"method",
".",
"isShortCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SHORT_ARRAY",
";",
"if",
"(",
"method",
".",
"isStringCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"UTF_STRING_ARRAY",
";",
"if",
"(",
"method",
".",
"isObjectCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SFS_ARRAY",
";",
"if",
"(",
"method",
".",
"isArrayObjectCollection",
"(",
")",
")",
"return",
"SFSDataType",
".",
"SFS_ARRAY",
";",
"return",
"SFSDataType",
".",
"SFS_ARRAY",
";",
"}"
] |
Get SFSDataType mapped to returned value type of getter method
@param method structure of getter method
@return the SFSDataType
|
[
"Get",
"SFSDataType",
"mapped",
"to",
"returned",
"value",
"type",
"of",
"getter",
"method"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/ParameterSerializer.java#L400-L470
|
12,176
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/extension/BaseExtension.java
|
BaseExtension.initContext
|
protected void initContext() {
context = createContext();
SmartFoxContext sfsContext = (SmartFoxContext)context;
sfsContext.setApi(getApi());
sfsContext.setExtension(this);
}
|
java
|
protected void initContext() {
context = createContext();
SmartFoxContext sfsContext = (SmartFoxContext)context;
sfsContext.setApi(getApi());
sfsContext.setExtension(this);
}
|
[
"protected",
"void",
"initContext",
"(",
")",
"{",
"context",
"=",
"createContext",
"(",
")",
";",
"SmartFoxContext",
"sfsContext",
"=",
"(",
"SmartFoxContext",
")",
"context",
";",
"sfsContext",
".",
"setApi",
"(",
"getApi",
"(",
")",
")",
";",
"sfsContext",
".",
"setExtension",
"(",
"this",
")",
";",
"}"
] |
Initialize application context
|
[
"Initialize",
"application",
"context"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/extension/BaseExtension.java#L43-L48
|
12,177
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/extension/BaseExtension.java
|
BaseExtension.addClientRequestHandlers
|
protected void addClientRequestHandlers() {
Set<String> commands =
context.getClientRequestCommands();
for(String command : commands)
addClientRequestHandler(command);
}
|
java
|
protected void addClientRequestHandlers() {
Set<String> commands =
context.getClientRequestCommands();
for(String command : commands)
addClientRequestHandler(command);
}
|
[
"protected",
"void",
"addClientRequestHandlers",
"(",
")",
"{",
"Set",
"<",
"String",
">",
"commands",
"=",
"context",
".",
"getClientRequestCommands",
"(",
")",
";",
"for",
"(",
"String",
"command",
":",
"commands",
")",
"addClientRequestHandler",
"(",
"command",
")",
";",
"}"
] |
Add client request handlers
|
[
"Add",
"client",
"request",
"handlers"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/extension/BaseExtension.java#L57-L62
|
12,178
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserJoinZoneEventHandler.java
|
UserJoinZoneEventHandler.createUserAgent
|
protected ApiUser createUserAgent(User sfsUser) {
ApiUser answer = UserAgentFactory.newUserAgent(
sfsUser.getName(),
context.getUserAgentClass(),
context.getGameUserAgentClasses());
sfsUser.setProperty(APIKey.USER, answer);
answer.setId(sfsUser.getId());
answer.setIp(sfsUser.getIpAddress());
answer.setSession(new ApiSessionImpl(sfsUser.getSession()));
answer.setCommand(context.command(UserInfo.class).user(sfsUser.getId()));
return answer;
}
|
java
|
protected ApiUser createUserAgent(User sfsUser) {
ApiUser answer = UserAgentFactory.newUserAgent(
sfsUser.getName(),
context.getUserAgentClass(),
context.getGameUserAgentClasses());
sfsUser.setProperty(APIKey.USER, answer);
answer.setId(sfsUser.getId());
answer.setIp(sfsUser.getIpAddress());
answer.setSession(new ApiSessionImpl(sfsUser.getSession()));
answer.setCommand(context.command(UserInfo.class).user(sfsUser.getId()));
return answer;
}
|
[
"protected",
"ApiUser",
"createUserAgent",
"(",
"User",
"sfsUser",
")",
"{",
"ApiUser",
"answer",
"=",
"UserAgentFactory",
".",
"newUserAgent",
"(",
"sfsUser",
".",
"getName",
"(",
")",
",",
"context",
".",
"getUserAgentClass",
"(",
")",
",",
"context",
".",
"getGameUserAgentClasses",
"(",
")",
")",
";",
"sfsUser",
".",
"setProperty",
"(",
"APIKey",
".",
"USER",
",",
"answer",
")",
";",
"answer",
".",
"setId",
"(",
"sfsUser",
".",
"getId",
"(",
")",
")",
";",
"answer",
".",
"setIp",
"(",
"sfsUser",
".",
"getIpAddress",
"(",
")",
")",
";",
"answer",
".",
"setSession",
"(",
"new",
"ApiSessionImpl",
"(",
"sfsUser",
".",
"getSession",
"(",
")",
")",
")",
";",
"answer",
".",
"setCommand",
"(",
"context",
".",
"command",
"(",
"UserInfo",
".",
"class",
")",
".",
"user",
"(",
"sfsUser",
".",
"getId",
"(",
")",
")",
")",
";",
"return",
"answer",
";",
"}"
] |
Create user agent object
@param sfsUser smartfox user object
@return user agent object
|
[
"Create",
"user",
"agent",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serverhandler/UserJoinZoneEventHandler.java#L58-L69
|
12,179
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/ForwardOnlyFactorsModule.java
|
ForwardOnlyFactorsModule.getFactorsModule
|
public static Module<Factors> getFactorsModule(FactorGraph fg, Algebra s) {
ForwardOnlyFactorsModule fm = new ForwardOnlyFactorsModule(null, fg, s);
fm.forward();
return fm;
}
|
java
|
public static Module<Factors> getFactorsModule(FactorGraph fg, Algebra s) {
ForwardOnlyFactorsModule fm = new ForwardOnlyFactorsModule(null, fg, s);
fm.forward();
return fm;
}
|
[
"public",
"static",
"Module",
"<",
"Factors",
">",
"getFactorsModule",
"(",
"FactorGraph",
"fg",
",",
"Algebra",
"s",
")",
"{",
"ForwardOnlyFactorsModule",
"fm",
"=",
"new",
"ForwardOnlyFactorsModule",
"(",
"null",
",",
"fg",
",",
"s",
")",
";",
"fm",
".",
"forward",
"(",
")",
";",
"return",
"fm",
";",
"}"
] |
Constructs a factors module and runs the forward computation.
|
[
"Constructs",
"a",
"factors",
"module",
"and",
"runs",
"the",
"forward",
"computation",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/ForwardOnlyFactorsModule.java#L103-L107
|
12,180
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java
|
FactorGraph.getClamped
|
public FactorGraph getClamped(VarConfig clampVars) {
FactorGraph clmpFg = new FactorGraph();
// Add ALL the original variables to the clamped factor graph.
for (Var v : this.getVars()) {
clmpFg.addVar(v);
}
// Add ALL the original factors to the clamped factor graph.
for (Factor origFactor : this.getFactors()) {
clmpFg.addFactor(origFactor);
}
// Add unary factors to the clamped variables to ensure they take on the correct value.
for (Var v : clampVars.getVars()) {
// TODO: We could skip these (cautiously) if there's already a
// ClampFactor attached to this variable.
int c = clampVars.getState(v);
clmpFg.addFactor(new ClampFactor(v, c));
}
return clmpFg;
}
|
java
|
public FactorGraph getClamped(VarConfig clampVars) {
FactorGraph clmpFg = new FactorGraph();
// Add ALL the original variables to the clamped factor graph.
for (Var v : this.getVars()) {
clmpFg.addVar(v);
}
// Add ALL the original factors to the clamped factor graph.
for (Factor origFactor : this.getFactors()) {
clmpFg.addFactor(origFactor);
}
// Add unary factors to the clamped variables to ensure they take on the correct value.
for (Var v : clampVars.getVars()) {
// TODO: We could skip these (cautiously) if there's already a
// ClampFactor attached to this variable.
int c = clampVars.getState(v);
clmpFg.addFactor(new ClampFactor(v, c));
}
return clmpFg;
}
|
[
"public",
"FactorGraph",
"getClamped",
"(",
"VarConfig",
"clampVars",
")",
"{",
"FactorGraph",
"clmpFg",
"=",
"new",
"FactorGraph",
"(",
")",
";",
"// Add ALL the original variables to the clamped factor graph.",
"for",
"(",
"Var",
"v",
":",
"this",
".",
"getVars",
"(",
")",
")",
"{",
"clmpFg",
".",
"addVar",
"(",
"v",
")",
";",
"}",
"// Add ALL the original factors to the clamped factor graph.",
"for",
"(",
"Factor",
"origFactor",
":",
"this",
".",
"getFactors",
"(",
")",
")",
"{",
"clmpFg",
".",
"addFactor",
"(",
"origFactor",
")",
";",
"}",
"// Add unary factors to the clamped variables to ensure they take on the correct value.",
"for",
"(",
"Var",
"v",
":",
"clampVars",
".",
"getVars",
"(",
")",
")",
"{",
"// TODO: We could skip these (cautiously) if there's already a",
"// ClampFactor attached to this variable.",
"int",
"c",
"=",
"clampVars",
".",
"getState",
"(",
"v",
")",
";",
"clmpFg",
".",
"addFactor",
"(",
"new",
"ClampFactor",
"(",
"v",
",",
"c",
")",
")",
";",
"}",
"return",
"clmpFg",
";",
"}"
] |
Gets a new factor graph, identical to this one, except that specified variables are clamped
to their values. This is accomplished by adding a unary factor on each clamped variable. The
original K factors are preserved in order with IDs 1...K.
@param clampVars The variables to clamp.
|
[
"Gets",
"a",
"new",
"factor",
"graph",
"identical",
"to",
"this",
"one",
"except",
"that",
"specified",
"variables",
"are",
"clamped",
"to",
"their",
"values",
".",
"This",
"is",
"accomplished",
"by",
"adding",
"a",
"unary",
"factor",
"on",
"each",
"clamped",
"variable",
".",
"The",
"original",
"K",
"factors",
"are",
"preserved",
"in",
"order",
"with",
"IDs",
"1",
"...",
"K",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java#L52-L71
|
12,181
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java
|
FactorGraph.addFactor
|
public void addFactor(Factor factor) {
int id = factor.getId();
boolean alreadyAdded = (0 <= id && id < factors.size());
if (alreadyAdded) {
if (factors.get(id) != factor) {
throw new IllegalStateException("Factor id already set, but factor not yet added.");
}
} else {
// Factor was not yet in the factor graph.
//
// Check and set the id.
if (id != -1 && id != factors.size()) {
throw new IllegalStateException("Factor id already set, but incorrect: " + id);
}
factor.setId(factors.size());
// Add the factor.
factors.add(factor);
// Add each variable...
for (Var var : factor.getVars()) {
// Add the variable.
addVar(var);
numUndirEdges++;
}
if (bg != null) { log.warn("Discarding BipartiteGraph. This may indicate inefficiency."); }
bg = null;
}
}
|
java
|
public void addFactor(Factor factor) {
int id = factor.getId();
boolean alreadyAdded = (0 <= id && id < factors.size());
if (alreadyAdded) {
if (factors.get(id) != factor) {
throw new IllegalStateException("Factor id already set, but factor not yet added.");
}
} else {
// Factor was not yet in the factor graph.
//
// Check and set the id.
if (id != -1 && id != factors.size()) {
throw new IllegalStateException("Factor id already set, but incorrect: " + id);
}
factor.setId(factors.size());
// Add the factor.
factors.add(factor);
// Add each variable...
for (Var var : factor.getVars()) {
// Add the variable.
addVar(var);
numUndirEdges++;
}
if (bg != null) { log.warn("Discarding BipartiteGraph. This may indicate inefficiency."); }
bg = null;
}
}
|
[
"public",
"void",
"addFactor",
"(",
"Factor",
"factor",
")",
"{",
"int",
"id",
"=",
"factor",
".",
"getId",
"(",
")",
";",
"boolean",
"alreadyAdded",
"=",
"(",
"0",
"<=",
"id",
"&&",
"id",
"<",
"factors",
".",
"size",
"(",
")",
")",
";",
"if",
"(",
"alreadyAdded",
")",
"{",
"if",
"(",
"factors",
".",
"get",
"(",
"id",
")",
"!=",
"factor",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Factor id already set, but factor not yet added.\"",
")",
";",
"}",
"}",
"else",
"{",
"// Factor was not yet in the factor graph.",
"//",
"// Check and set the id.",
"if",
"(",
"id",
"!=",
"-",
"1",
"&&",
"id",
"!=",
"factors",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Factor id already set, but incorrect: \"",
"+",
"id",
")",
";",
"}",
"factor",
".",
"setId",
"(",
"factors",
".",
"size",
"(",
")",
")",
";",
"// Add the factor.",
"factors",
".",
"add",
"(",
"factor",
")",
";",
"// Add each variable...",
"for",
"(",
"Var",
"var",
":",
"factor",
".",
"getVars",
"(",
")",
")",
"{",
"// Add the variable.",
"addVar",
"(",
"var",
")",
";",
"numUndirEdges",
"++",
";",
"}",
"if",
"(",
"bg",
"!=",
"null",
")",
"{",
"log",
".",
"warn",
"(",
"\"Discarding BipartiteGraph. This may indicate inefficiency.\"",
")",
";",
"}",
"bg",
"=",
"null",
";",
"}",
"}"
] |
Adds a factor to this factor graph, if not already present, additionally adding any variables
in its VarSet which have not already been added.
@param var The factor to add.
@return The node for this factor.
|
[
"Adds",
"a",
"factor",
"to",
"this",
"factor",
"graph",
"if",
"not",
"already",
"present",
"additionally",
"adding",
"any",
"variables",
"in",
"its",
"VarSet",
"which",
"have",
"not",
"already",
"been",
"added",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java#L88-L116
|
12,182
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java
|
FactorGraph.addVar
|
public void addVar(Var var) {
int id = var.getId();
boolean alreadyAdded = (0 <= id && id < vars.size());
if (alreadyAdded) {
if (vars.get(id) != var) {
throw new IllegalStateException("Var id already set, but factor not yet added.");
}
} else {
// Var was not yet in the factor graph.
//
// Check and set the id.
if (id != -1 && id != vars.size()) {
throw new IllegalStateException("Var id already set, but incorrect: " + id);
}
var.setId(vars.size());
// Add the Var.
vars.add(var);
if (bg != null) { log.warn("Discarding BipartiteGraph. This may indicate inefficiency."); }
bg = null;
}
}
|
java
|
public void addVar(Var var) {
int id = var.getId();
boolean alreadyAdded = (0 <= id && id < vars.size());
if (alreadyAdded) {
if (vars.get(id) != var) {
throw new IllegalStateException("Var id already set, but factor not yet added.");
}
} else {
// Var was not yet in the factor graph.
//
// Check and set the id.
if (id != -1 && id != vars.size()) {
throw new IllegalStateException("Var id already set, but incorrect: " + id);
}
var.setId(vars.size());
// Add the Var.
vars.add(var);
if (bg != null) { log.warn("Discarding BipartiteGraph. This may indicate inefficiency."); }
bg = null;
}
}
|
[
"public",
"void",
"addVar",
"(",
"Var",
"var",
")",
"{",
"int",
"id",
"=",
"var",
".",
"getId",
"(",
")",
";",
"boolean",
"alreadyAdded",
"=",
"(",
"0",
"<=",
"id",
"&&",
"id",
"<",
"vars",
".",
"size",
"(",
")",
")",
";",
"if",
"(",
"alreadyAdded",
")",
"{",
"if",
"(",
"vars",
".",
"get",
"(",
"id",
")",
"!=",
"var",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Var id already set, but factor not yet added.\"",
")",
";",
"}",
"}",
"else",
"{",
"// Var was not yet in the factor graph.",
"//",
"// Check and set the id.",
"if",
"(",
"id",
"!=",
"-",
"1",
"&&",
"id",
"!=",
"vars",
".",
"size",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Var id already set, but incorrect: \"",
"+",
"id",
")",
";",
"}",
"var",
".",
"setId",
"(",
"vars",
".",
"size",
"(",
")",
")",
";",
"// Add the Var.",
"vars",
".",
"add",
"(",
"var",
")",
";",
"if",
"(",
"bg",
"!=",
"null",
")",
"{",
"log",
".",
"warn",
"(",
"\"Discarding BipartiteGraph. This may indicate inefficiency.\"",
")",
";",
"}",
"bg",
"=",
"null",
";",
"}",
"}"
] |
Adds a variable to this factor graph, if not already present.
@param var The variable to add.
@return The node for this variable.
|
[
"Adds",
"a",
"variable",
"to",
"this",
"factor",
"graph",
"if",
"not",
"already",
"present",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/model/FactorGraph.java#L124-L145
|
12,183
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java
|
LogLinearXY.train
|
public FgModel train(LogLinearXYData data) {
IntObjectBimap<String> alphabet = data.getFeatAlphabet();
FgExampleList list = getData(data);
log.info("Number of train instances: " + list.size());
log.info("Number of model parameters: " + alphabet.size());
FgModel model = new FgModel(alphabet.size(), new StringIterable(alphabet.getObjects()));
CrfTrainer trainer = new CrfTrainer(prm.crfPrm);
trainer.train(model, list);
return model;
}
|
java
|
public FgModel train(LogLinearXYData data) {
IntObjectBimap<String> alphabet = data.getFeatAlphabet();
FgExampleList list = getData(data);
log.info("Number of train instances: " + list.size());
log.info("Number of model parameters: " + alphabet.size());
FgModel model = new FgModel(alphabet.size(), new StringIterable(alphabet.getObjects()));
CrfTrainer trainer = new CrfTrainer(prm.crfPrm);
trainer.train(model, list);
return model;
}
|
[
"public",
"FgModel",
"train",
"(",
"LogLinearXYData",
"data",
")",
"{",
"IntObjectBimap",
"<",
"String",
">",
"alphabet",
"=",
"data",
".",
"getFeatAlphabet",
"(",
")",
";",
"FgExampleList",
"list",
"=",
"getData",
"(",
"data",
")",
";",
"log",
".",
"info",
"(",
"\"Number of train instances: \"",
"+",
"list",
".",
"size",
"(",
")",
")",
";",
"log",
".",
"info",
"(",
"\"Number of model parameters: \"",
"+",
"alphabet",
".",
"size",
"(",
")",
")",
";",
"FgModel",
"model",
"=",
"new",
"FgModel",
"(",
"alphabet",
".",
"size",
"(",
")",
",",
"new",
"StringIterable",
"(",
"alphabet",
".",
"getObjects",
"(",
")",
")",
")",
";",
"CrfTrainer",
"trainer",
"=",
"new",
"CrfTrainer",
"(",
"prm",
".",
"crfPrm",
")",
";",
"trainer",
".",
"train",
"(",
"model",
",",
"list",
")",
";",
"return",
"model",
";",
"}"
] |
Trains a log-linear model.
@param data The log-linear model training examples created by
LogLinearData.
@return Trained model.
|
[
"Trains",
"a",
"log",
"-",
"linear",
"model",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java#L69-L78
|
12,184
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java
|
LogLinearXY.decode
|
public Pair<String, VarTensor> decode(FgModel model, LogLinearExample llex) {
LFgExample ex = getFgExample(llex);
MbrDecoderPrm prm = new MbrDecoderPrm();
prm.infFactory = getBpPrm();
MbrDecoder decoder = new MbrDecoder(prm);
decoder.decode(model, ex);
List<VarTensor> marginals = decoder.getVarMarginals();
VarConfig vc = decoder.getMbrVarConfig();
String stateName = vc.getStateName(ex.getFactorGraph().getVar(0));
if (marginals.size() != 1) {
throw new IllegalStateException("Example is not from a LogLinearData factory");
}
return new Pair<String,VarTensor>(stateName, marginals.get(0));
}
|
java
|
public Pair<String, VarTensor> decode(FgModel model, LogLinearExample llex) {
LFgExample ex = getFgExample(llex);
MbrDecoderPrm prm = new MbrDecoderPrm();
prm.infFactory = getBpPrm();
MbrDecoder decoder = new MbrDecoder(prm);
decoder.decode(model, ex);
List<VarTensor> marginals = decoder.getVarMarginals();
VarConfig vc = decoder.getMbrVarConfig();
String stateName = vc.getStateName(ex.getFactorGraph().getVar(0));
if (marginals.size() != 1) {
throw new IllegalStateException("Example is not from a LogLinearData factory");
}
return new Pair<String,VarTensor>(stateName, marginals.get(0));
}
|
[
"public",
"Pair",
"<",
"String",
",",
"VarTensor",
">",
"decode",
"(",
"FgModel",
"model",
",",
"LogLinearExample",
"llex",
")",
"{",
"LFgExample",
"ex",
"=",
"getFgExample",
"(",
"llex",
")",
";",
"MbrDecoderPrm",
"prm",
"=",
"new",
"MbrDecoderPrm",
"(",
")",
";",
"prm",
".",
"infFactory",
"=",
"getBpPrm",
"(",
")",
";",
"MbrDecoder",
"decoder",
"=",
"new",
"MbrDecoder",
"(",
"prm",
")",
";",
"decoder",
".",
"decode",
"(",
"model",
",",
"ex",
")",
";",
"List",
"<",
"VarTensor",
">",
"marginals",
"=",
"decoder",
".",
"getVarMarginals",
"(",
")",
";",
"VarConfig",
"vc",
"=",
"decoder",
".",
"getMbrVarConfig",
"(",
")",
";",
"String",
"stateName",
"=",
"vc",
".",
"getStateName",
"(",
"ex",
".",
"getFactorGraph",
"(",
")",
".",
"getVar",
"(",
"0",
")",
")",
";",
"if",
"(",
"marginals",
".",
"size",
"(",
")",
"!=",
"1",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Example is not from a LogLinearData factory\"",
")",
";",
"}",
"return",
"new",
"Pair",
"<",
"String",
",",
"VarTensor",
">",
"(",
"stateName",
",",
"marginals",
".",
"get",
"(",
"0",
")",
")",
";",
"}"
] |
Decodes a single example.
@param model The log-linear model.
@param ex The example to decode.
@return A pair containing the most likely label (i.e. value of y) and the
distribution over y values.
|
[
"Decodes",
"a",
"single",
"example",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java#L88-L102
|
12,185
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java
|
LogLinearXY.getData
|
public FgExampleList getData(LogLinearXYData data) {
IntObjectBimap<String> alphabet = data.getFeatAlphabet();
List<LogLinearExample> exList = data.getData();
if (this.alphabet == null) {
this.alphabet = alphabet;
this.stateNames = getStateNames(exList, data.getYAlphabet());
}
if (prm.cacheExamples) {
FgExampleMemoryStore store = new FgExampleMemoryStore();
for (final LogLinearExample desc : exList) {
LFgExample ex = getFgExample(desc);
store.add(ex);
}
return store;
} else {
return new FgExampleList() {
@Override
public LFgExample get(int i) {
return getFgExample(exList.get(i));
}
@Override
public int size() {
return exList.size();
}
};
}
}
|
java
|
public FgExampleList getData(LogLinearXYData data) {
IntObjectBimap<String> alphabet = data.getFeatAlphabet();
List<LogLinearExample> exList = data.getData();
if (this.alphabet == null) {
this.alphabet = alphabet;
this.stateNames = getStateNames(exList, data.getYAlphabet());
}
if (prm.cacheExamples) {
FgExampleMemoryStore store = new FgExampleMemoryStore();
for (final LogLinearExample desc : exList) {
LFgExample ex = getFgExample(desc);
store.add(ex);
}
return store;
} else {
return new FgExampleList() {
@Override
public LFgExample get(int i) {
return getFgExample(exList.get(i));
}
@Override
public int size() {
return exList.size();
}
};
}
}
|
[
"public",
"FgExampleList",
"getData",
"(",
"LogLinearXYData",
"data",
")",
"{",
"IntObjectBimap",
"<",
"String",
">",
"alphabet",
"=",
"data",
".",
"getFeatAlphabet",
"(",
")",
";",
"List",
"<",
"LogLinearExample",
">",
"exList",
"=",
"data",
".",
"getData",
"(",
")",
";",
"if",
"(",
"this",
".",
"alphabet",
"==",
"null",
")",
"{",
"this",
".",
"alphabet",
"=",
"alphabet",
";",
"this",
".",
"stateNames",
"=",
"getStateNames",
"(",
"exList",
",",
"data",
".",
"getYAlphabet",
"(",
")",
")",
";",
"}",
"if",
"(",
"prm",
".",
"cacheExamples",
")",
"{",
"FgExampleMemoryStore",
"store",
"=",
"new",
"FgExampleMemoryStore",
"(",
")",
";",
"for",
"(",
"final",
"LogLinearExample",
"desc",
":",
"exList",
")",
"{",
"LFgExample",
"ex",
"=",
"getFgExample",
"(",
"desc",
")",
";",
"store",
".",
"add",
"(",
"ex",
")",
";",
"}",
"return",
"store",
";",
"}",
"else",
"{",
"return",
"new",
"FgExampleList",
"(",
")",
"{",
"@",
"Override",
"public",
"LFgExample",
"get",
"(",
"int",
"i",
")",
"{",
"return",
"getFgExample",
"(",
"exList",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"@",
"Override",
"public",
"int",
"size",
"(",
")",
"{",
"return",
"exList",
".",
"size",
"(",
")",
";",
"}",
"}",
";",
"}",
"}"
] |
For testing only. Converts to the graphical model's representation of the data.
|
[
"For",
"testing",
"only",
".",
"Converts",
"to",
"the",
"graphical",
"model",
"s",
"representation",
"of",
"the",
"data",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/maxent/LogLinearXY.java#L107-L134
|
12,186
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/util/BipartiteGraph.java
|
BipartiteGraph.swapVals
|
private void swapVals(int e, int f, int[] vals) {
int vals_e = vals[e];
vals[e] = vals[f];
vals[f] = vals_e;
}
|
java
|
private void swapVals(int e, int f, int[] vals) {
int vals_e = vals[e];
vals[e] = vals[f];
vals[f] = vals_e;
}
|
[
"private",
"void",
"swapVals",
"(",
"int",
"e",
",",
"int",
"f",
",",
"int",
"[",
"]",
"vals",
")",
"{",
"int",
"vals_e",
"=",
"vals",
"[",
"e",
"]",
";",
"vals",
"[",
"e",
"]",
"=",
"vals",
"[",
"f",
"]",
";",
"vals",
"[",
"f",
"]",
"=",
"vals_e",
";",
"}"
] |
Swap the values of two positions in an array.
|
[
"Swap",
"the",
"values",
"of",
"two",
"positions",
"in",
"an",
"array",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/util/BipartiteGraph.java#L141-L145
|
12,187
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/gm/util/BipartiteGraph.java
|
BipartiteGraph.dfs
|
public int dfs(int root, boolean isRootT1, boolean[] marked1, boolean[] marked2, BipVisitor<T1,T2> visitor) {
IntStack sNode = new IntStack();
ByteStack sIsT1 = new ByteStack(); // TODO: This should be a boolean stack.
sNode.push(root);
sIsT1.push((byte)(isRootT1 ? 1 : 0));
// The number of times we check if any node is marked.
// For acyclic graphs this should be two times the number of nodes.
int numMarkedChecks = 0;
while (sNode.size() != 0) {
int node = sNode.pop();
boolean isT1 = (sIsT1.pop() == 1);
if (isT1) {
// Visit node only if not marked.
int t1 = node;
if (!marked1[t1]) {
marked1[t1] = true;
if (visitor != null) { visitor.visit(t1, true, this); }
for (int nb = numNbsT1(t1)-1; nb >= 0; nb--) {
int t2 = childT1(t1, nb);
if (!marked2[t2]) {
sNode.push(t2);
sIsT1.push((byte)0);
}
numMarkedChecks++;
}
}
numMarkedChecks++;
} else {
// Visit node only if not marked.
int t2 = node;
if (!marked2[t2]) {
marked2[t2] = true;
if (visitor != null) { visitor.visit(t2, false, this); }
for (int nb = numNbsT2(t2)-1; nb >= 0; nb--) {
int t1 = childT2(t2, nb);
if (!marked1[t1]) {
sNode.push(t1);
sIsT1.push((byte)1);
}
numMarkedChecks++;
}
}
numMarkedChecks++;
}
}
return numMarkedChecks;
}
|
java
|
public int dfs(int root, boolean isRootT1, boolean[] marked1, boolean[] marked2, BipVisitor<T1,T2> visitor) {
IntStack sNode = new IntStack();
ByteStack sIsT1 = new ByteStack(); // TODO: This should be a boolean stack.
sNode.push(root);
sIsT1.push((byte)(isRootT1 ? 1 : 0));
// The number of times we check if any node is marked.
// For acyclic graphs this should be two times the number of nodes.
int numMarkedChecks = 0;
while (sNode.size() != 0) {
int node = sNode.pop();
boolean isT1 = (sIsT1.pop() == 1);
if (isT1) {
// Visit node only if not marked.
int t1 = node;
if (!marked1[t1]) {
marked1[t1] = true;
if (visitor != null) { visitor.visit(t1, true, this); }
for (int nb = numNbsT1(t1)-1; nb >= 0; nb--) {
int t2 = childT1(t1, nb);
if (!marked2[t2]) {
sNode.push(t2);
sIsT1.push((byte)0);
}
numMarkedChecks++;
}
}
numMarkedChecks++;
} else {
// Visit node only if not marked.
int t2 = node;
if (!marked2[t2]) {
marked2[t2] = true;
if (visitor != null) { visitor.visit(t2, false, this); }
for (int nb = numNbsT2(t2)-1; nb >= 0; nb--) {
int t1 = childT2(t2, nb);
if (!marked1[t1]) {
sNode.push(t1);
sIsT1.push((byte)1);
}
numMarkedChecks++;
}
}
numMarkedChecks++;
}
}
return numMarkedChecks;
}
|
[
"public",
"int",
"dfs",
"(",
"int",
"root",
",",
"boolean",
"isRootT1",
",",
"boolean",
"[",
"]",
"marked1",
",",
"boolean",
"[",
"]",
"marked2",
",",
"BipVisitor",
"<",
"T1",
",",
"T2",
">",
"visitor",
")",
"{",
"IntStack",
"sNode",
"=",
"new",
"IntStack",
"(",
")",
";",
"ByteStack",
"sIsT1",
"=",
"new",
"ByteStack",
"(",
")",
";",
"// TODO: This should be a boolean stack.",
"sNode",
".",
"push",
"(",
"root",
")",
";",
"sIsT1",
".",
"push",
"(",
"(",
"byte",
")",
"(",
"isRootT1",
"?",
"1",
":",
"0",
")",
")",
";",
"// The number of times we check if any node is marked. ",
"// For acyclic graphs this should be two times the number of nodes.",
"int",
"numMarkedChecks",
"=",
"0",
";",
"while",
"(",
"sNode",
".",
"size",
"(",
")",
"!=",
"0",
")",
"{",
"int",
"node",
"=",
"sNode",
".",
"pop",
"(",
")",
";",
"boolean",
"isT1",
"=",
"(",
"sIsT1",
".",
"pop",
"(",
")",
"==",
"1",
")",
";",
"if",
"(",
"isT1",
")",
"{",
"// Visit node only if not marked.",
"int",
"t1",
"=",
"node",
";",
"if",
"(",
"!",
"marked1",
"[",
"t1",
"]",
")",
"{",
"marked1",
"[",
"t1",
"]",
"=",
"true",
";",
"if",
"(",
"visitor",
"!=",
"null",
")",
"{",
"visitor",
".",
"visit",
"(",
"t1",
",",
"true",
",",
"this",
")",
";",
"}",
"for",
"(",
"int",
"nb",
"=",
"numNbsT1",
"(",
"t1",
")",
"-",
"1",
";",
"nb",
">=",
"0",
";",
"nb",
"--",
")",
"{",
"int",
"t2",
"=",
"childT1",
"(",
"t1",
",",
"nb",
")",
";",
"if",
"(",
"!",
"marked2",
"[",
"t2",
"]",
")",
"{",
"sNode",
".",
"push",
"(",
"t2",
")",
";",
"sIsT1",
".",
"push",
"(",
"(",
"byte",
")",
"0",
")",
";",
"}",
"numMarkedChecks",
"++",
";",
"}",
"}",
"numMarkedChecks",
"++",
";",
"}",
"else",
"{",
"// Visit node only if not marked.",
"int",
"t2",
"=",
"node",
";",
"if",
"(",
"!",
"marked2",
"[",
"t2",
"]",
")",
"{",
"marked2",
"[",
"t2",
"]",
"=",
"true",
";",
"if",
"(",
"visitor",
"!=",
"null",
")",
"{",
"visitor",
".",
"visit",
"(",
"t2",
",",
"false",
",",
"this",
")",
";",
"}",
"for",
"(",
"int",
"nb",
"=",
"numNbsT2",
"(",
"t2",
")",
"-",
"1",
";",
"nb",
">=",
"0",
";",
"nb",
"--",
")",
"{",
"int",
"t1",
"=",
"childT2",
"(",
"t2",
",",
"nb",
")",
";",
"if",
"(",
"!",
"marked1",
"[",
"t1",
"]",
")",
"{",
"sNode",
".",
"push",
"(",
"t1",
")",
";",
"sIsT1",
".",
"push",
"(",
"(",
"byte",
")",
"1",
")",
";",
"}",
"numMarkedChecks",
"++",
";",
"}",
"}",
"numMarkedChecks",
"++",
";",
"}",
"}",
"return",
"numMarkedChecks",
";",
"}"
] |
Runs a depth-first-search starting at the root node.
|
[
"Runs",
"a",
"depth",
"-",
"first",
"-",
"search",
"starting",
"at",
"the",
"root",
"node",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/gm/util/BipartiteGraph.java#L290-L338
|
12,188
|
rtyley/roboguice-sherlock
|
src/main/java/com/github/rtyley/android/sherlock/roboguice/activity/RoboSherlockPreferenceActivity.java
|
RoboSherlockPreferenceActivity.onCreate
|
@Override
protected void onCreate(Bundle savedInstanceState) {
final RoboInjector injector = RoboGuice.getInjector(this);
eventManager = injector.getInstance(EventManager.class);
preferenceListener = injector.getInstance(PreferenceListener.class);
injector.injectMembersWithoutViews(this);
super.onCreate(savedInstanceState);
eventManager.fire(new OnCreateEvent(savedInstanceState));
}
|
java
|
@Override
protected void onCreate(Bundle savedInstanceState) {
final RoboInjector injector = RoboGuice.getInjector(this);
eventManager = injector.getInstance(EventManager.class);
preferenceListener = injector.getInstance(PreferenceListener.class);
injector.injectMembersWithoutViews(this);
super.onCreate(savedInstanceState);
eventManager.fire(new OnCreateEvent(savedInstanceState));
}
|
[
"@",
"Override",
"protected",
"void",
"onCreate",
"(",
"Bundle",
"savedInstanceState",
")",
"{",
"final",
"RoboInjector",
"injector",
"=",
"RoboGuice",
".",
"getInjector",
"(",
"this",
")",
";",
"eventManager",
"=",
"injector",
".",
"getInstance",
"(",
"EventManager",
".",
"class",
")",
";",
"preferenceListener",
"=",
"injector",
".",
"getInstance",
"(",
"PreferenceListener",
".",
"class",
")",
";",
"injector",
".",
"injectMembersWithoutViews",
"(",
"this",
")",
";",
"super",
".",
"onCreate",
"(",
"savedInstanceState",
")",
";",
"eventManager",
".",
"fire",
"(",
"new",
"OnCreateEvent",
"(",
"savedInstanceState",
")",
")",
";",
"}"
] |
BUG find a better place to put this
|
[
"BUG",
"find",
"a",
"better",
"place",
"to",
"put",
"this"
] |
691d41f41bd42d6d981c4b9f3451ab342efa0293
|
https://github.com/rtyley/roboguice-sherlock/blob/691d41f41bd42d6d981c4b9f3451ab342efa0293/src/main/java/com/github/rtyley/android/sherlock/roboguice/activity/RoboSherlockPreferenceActivity.java#L60-L68
|
12,189
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.insideAlgorithm
|
public static double[] insideAlgorithm(final Hypergraph graph, final Hyperpotential w, final Semiring s) {
final int n = graph.getNodes().size();
final double[] beta = new double[n];
// \beta_i = 0 \forall i
Arrays.fill(beta, s.zero());
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
// \beta_{H(e)} += w_e \prod_{j \in T(e)} \beta_j
double prod = s.one();
for (Hypernode jNode : e.getTailNodes()) {
prod = s.times(prod, beta[jNode.getId()]);
}
int i = e.getHeadNode().getId();
prod = s.times(w.getScore(e, s), prod);
beta[i] = s.plus(beta[i], prod);
//if (log.isTraceEnabled()) { log.trace(String.format("inside: %s w_e=%f prod=%f beta[%d] = %f", e.getLabel(), ((Algebra)s).toReal(w.getScore(e, s)), prod, i, ((Algebra)s).toReal(beta[i]))); }
}
});
return beta;
}
|
java
|
public static double[] insideAlgorithm(final Hypergraph graph, final Hyperpotential w, final Semiring s) {
final int n = graph.getNodes().size();
final double[] beta = new double[n];
// \beta_i = 0 \forall i
Arrays.fill(beta, s.zero());
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
// \beta_{H(e)} += w_e \prod_{j \in T(e)} \beta_j
double prod = s.one();
for (Hypernode jNode : e.getTailNodes()) {
prod = s.times(prod, beta[jNode.getId()]);
}
int i = e.getHeadNode().getId();
prod = s.times(w.getScore(e, s), prod);
beta[i] = s.plus(beta[i], prod);
//if (log.isTraceEnabled()) { log.trace(String.format("inside: %s w_e=%f prod=%f beta[%d] = %f", e.getLabel(), ((Algebra)s).toReal(w.getScore(e, s)), prod, i, ((Algebra)s).toReal(beta[i]))); }
}
});
return beta;
}
|
[
"public",
"static",
"double",
"[",
"]",
"insideAlgorithm",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"Hyperpotential",
"w",
",",
"final",
"Semiring",
"s",
")",
"{",
"final",
"int",
"n",
"=",
"graph",
".",
"getNodes",
"(",
")",
".",
"size",
"(",
")",
";",
"final",
"double",
"[",
"]",
"beta",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"// \\beta_i = 0 \\forall i",
"Arrays",
".",
"fill",
"(",
"beta",
",",
"s",
".",
"zero",
"(",
")",
")",
";",
"graph",
".",
"applyTopoSort",
"(",
"new",
"HyperedgeFn",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
")",
"{",
"// \\beta_{H(e)} += w_e \\prod_{j \\in T(e)} \\beta_j",
"double",
"prod",
"=",
"s",
".",
"one",
"(",
")",
";",
"for",
"(",
"Hypernode",
"jNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"beta",
"[",
"jNode",
".",
"getId",
"(",
")",
"]",
")",
";",
"}",
"int",
"i",
"=",
"e",
".",
"getHeadNode",
"(",
")",
".",
"getId",
"(",
")",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
",",
"prod",
")",
";",
"beta",
"[",
"i",
"]",
"=",
"s",
".",
"plus",
"(",
"beta",
"[",
"i",
"]",
",",
"prod",
")",
";",
"//if (log.isTraceEnabled()) { log.trace(String.format(\"inside: %s w_e=%f prod=%f beta[%d] = %f\", e.getLabel(), ((Algebra)s).toReal(w.getScore(e, s)), prod, i, ((Algebra)s).toReal(beta[i]))); }",
"}",
"}",
")",
";",
"return",
"beta",
";",
"}"
] |
Runs the inside algorithm on a hypergraph.
@param graph The hypergraph.
@return The beta value for each Hypernode. Where beta[i] is the inside
score for the i'th node in the Hypergraph, graph.getNodes().get(i).
|
[
"Runs",
"the",
"inside",
"algorithm",
"on",
"a",
"hypergraph",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L81-L103
|
12,190
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.outsideAlgorithm
|
public static double[] outsideAlgorithm(final Hypergraph graph, final Hyperpotential w, final Semiring s, final double[] beta) {
final int n = graph.getNodes().size();
final double[] alpha = new double[n];
// \alpha_i = 0 \forall i
Arrays.fill(alpha, s.zero());
// \alpha_{root} = 1
alpha[graph.getRoot().getId()] = s.one();
graph.applyRevTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
// \forall j \in T(e):
// \alpha_j += \alpha_{H(e)} * w_e * \prod_{k \in T(e) : k \neq j} \beta_k
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
double prod = s.one();
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (k == j) { continue; }
prod = s.times(prod, beta[k]);
}
prod = s.times(prod, alpha[i]);
prod = s.times(prod, w.getScore(e, s));
alpha[j] = s.plus(alpha[j], prod);
//if (log.isTraceEnabled()) { log.trace(String.format("outside: %s w_e=%f prod=%f alpha[%d]=%f", e.getLabel(), w.getScore(e,s), prod, j, alpha[j])); }
}
}
});
return alpha;
}
|
java
|
public static double[] outsideAlgorithm(final Hypergraph graph, final Hyperpotential w, final Semiring s, final double[] beta) {
final int n = graph.getNodes().size();
final double[] alpha = new double[n];
// \alpha_i = 0 \forall i
Arrays.fill(alpha, s.zero());
// \alpha_{root} = 1
alpha[graph.getRoot().getId()] = s.one();
graph.applyRevTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
// \forall j \in T(e):
// \alpha_j += \alpha_{H(e)} * w_e * \prod_{k \in T(e) : k \neq j} \beta_k
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
double prod = s.one();
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (k == j) { continue; }
prod = s.times(prod, beta[k]);
}
prod = s.times(prod, alpha[i]);
prod = s.times(prod, w.getScore(e, s));
alpha[j] = s.plus(alpha[j], prod);
//if (log.isTraceEnabled()) { log.trace(String.format("outside: %s w_e=%f prod=%f alpha[%d]=%f", e.getLabel(), w.getScore(e,s), prod, j, alpha[j])); }
}
}
});
return alpha;
}
|
[
"public",
"static",
"double",
"[",
"]",
"outsideAlgorithm",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"Hyperpotential",
"w",
",",
"final",
"Semiring",
"s",
",",
"final",
"double",
"[",
"]",
"beta",
")",
"{",
"final",
"int",
"n",
"=",
"graph",
".",
"getNodes",
"(",
")",
".",
"size",
"(",
")",
";",
"final",
"double",
"[",
"]",
"alpha",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"// \\alpha_i = 0 \\forall i",
"Arrays",
".",
"fill",
"(",
"alpha",
",",
"s",
".",
"zero",
"(",
")",
")",
";",
"// \\alpha_{root} = 1",
"alpha",
"[",
"graph",
".",
"getRoot",
"(",
")",
".",
"getId",
"(",
")",
"]",
"=",
"s",
".",
"one",
"(",
")",
";",
"graph",
".",
"applyRevTopoSort",
"(",
"new",
"HyperedgeFn",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
")",
"{",
"int",
"i",
"=",
"e",
".",
"getHeadNode",
"(",
")",
".",
"getId",
"(",
")",
";",
"// \\forall j \\in T(e): ",
"// \\alpha_j += \\alpha_{H(e)} * w_e * \\prod_{k \\in T(e) : k \\neq j} \\beta_k",
"for",
"(",
"Hypernode",
"jNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"j",
"=",
"jNode",
".",
"getId",
"(",
")",
";",
"double",
"prod",
"=",
"s",
".",
"one",
"(",
")",
";",
"for",
"(",
"Hypernode",
"kNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"k",
"=",
"kNode",
".",
"getId",
"(",
")",
";",
"if",
"(",
"k",
"==",
"j",
")",
"{",
"continue",
";",
"}",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"beta",
"[",
"k",
"]",
")",
";",
"}",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"alpha",
"[",
"i",
"]",
")",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
")",
";",
"alpha",
"[",
"j",
"]",
"=",
"s",
".",
"plus",
"(",
"alpha",
"[",
"j",
"]",
",",
"prod",
")",
";",
"//if (log.isTraceEnabled()) { log.trace(String.format(\"outside: %s w_e=%f prod=%f alpha[%d]=%f\", e.getLabel(), w.getScore(e,s), prod, j, alpha[j])); }",
"}",
"}",
"}",
")",
";",
"return",
"alpha",
";",
"}"
] |
Runs the outside algorithm on a hypergraph.
@param graph The hypergraph
@param w The potential function.
@param s The semiring.
@param beta The beta value for each Hypernode. Where beta[i] is the inside
score for the i'th node in the Hypergraph, graph.getNodes().get(i).
@return The alpha value for each Hypernode. Where alpha[i] is the outside
score for the i'th node in the Hypergraph, graph.getNodes().get(i).
|
[
"Runs",
"the",
"outside",
"algorithm",
"on",
"a",
"hypergraph",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L116-L147
|
12,191
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.insideAlgorithmFirstOrderExpect
|
public static void insideAlgorithmFirstOrderExpect(final Hypergraph graph, final HyperpotentialFoe w,
final Algebra s, final Scores scores) {
final int n = graph.getNodes().size();
final double[] beta = new double[n];
final double[] betaFoe = new double[n];
// \beta_i = 0 \forall i
Arrays.fill(beta, s.zero());
Arrays.fill(betaFoe, s.zero());
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
// \beta_{H(e)} += w_e \prod_{j \in T(e)} \beta_j
double prod = s.one();
double prodFoe = s.zero();
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
// prod = s.times(prod, beta[j]);
// prodFoe = s.plus(s.times(prod, betaFoe[j]), s.times(beta[j], prodFoe));
double p1 = prod;
double p2 = beta[j];
double r1 = prodFoe;
double r2 = betaFoe[j];
prod = s.times(p1, p2);
prodFoe = s.plus(s.times(p1, r2), s.times(p2, r1));
}
// prod = s.times(prod, w.getScore(e, s));
// prodFoe = s.plus(s.times(prod, w.getScoreFoe(e, s)), s.times(w.getScore(e, s), prodFoe));
double p1 = prod;
double p2 = w.getScore(e, s);
double r1 = prodFoe;
double r2 = w.getScoreFoe(e, s);
prod = s.times(p1, p2);
prodFoe = s.plus(s.times(p1, r2), s.times(p2, r1));
int i = e.getHeadNode().getId();
//if (log.isTraceEnabled()) { log.trace(String.format("old beta[%d] = %f", i, s.toReal(beta[i]))); }
beta[i] = s.plus(beta[i], prod);
betaFoe[i] = s.plus(betaFoe[i], prodFoe);
assert !s.isNaN(beta[i]);
assert !s.isNaN(betaFoe[i]);
// log.debug(String.format("%s w_e=%f beta[%d] = %.3f betaFoe[%d] = %.3f", e.getLabel(), s.toReal(w.getScore(e, s)), i, s.toReal(beta[i]), i, s.toReal(betaFoe[i])));
}
});
scores.beta = beta;
scores.betaFoe = betaFoe;
}
|
java
|
public static void insideAlgorithmFirstOrderExpect(final Hypergraph graph, final HyperpotentialFoe w,
final Algebra s, final Scores scores) {
final int n = graph.getNodes().size();
final double[] beta = new double[n];
final double[] betaFoe = new double[n];
// \beta_i = 0 \forall i
Arrays.fill(beta, s.zero());
Arrays.fill(betaFoe, s.zero());
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
// \beta_{H(e)} += w_e \prod_{j \in T(e)} \beta_j
double prod = s.one();
double prodFoe = s.zero();
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
// prod = s.times(prod, beta[j]);
// prodFoe = s.plus(s.times(prod, betaFoe[j]), s.times(beta[j], prodFoe));
double p1 = prod;
double p2 = beta[j];
double r1 = prodFoe;
double r2 = betaFoe[j];
prod = s.times(p1, p2);
prodFoe = s.plus(s.times(p1, r2), s.times(p2, r1));
}
// prod = s.times(prod, w.getScore(e, s));
// prodFoe = s.plus(s.times(prod, w.getScoreFoe(e, s)), s.times(w.getScore(e, s), prodFoe));
double p1 = prod;
double p2 = w.getScore(e, s);
double r1 = prodFoe;
double r2 = w.getScoreFoe(e, s);
prod = s.times(p1, p2);
prodFoe = s.plus(s.times(p1, r2), s.times(p2, r1));
int i = e.getHeadNode().getId();
//if (log.isTraceEnabled()) { log.trace(String.format("old beta[%d] = %f", i, s.toReal(beta[i]))); }
beta[i] = s.plus(beta[i], prod);
betaFoe[i] = s.plus(betaFoe[i], prodFoe);
assert !s.isNaN(beta[i]);
assert !s.isNaN(betaFoe[i]);
// log.debug(String.format("%s w_e=%f beta[%d] = %.3f betaFoe[%d] = %.3f", e.getLabel(), s.toReal(w.getScore(e, s)), i, s.toReal(beta[i]), i, s.toReal(betaFoe[i])));
}
});
scores.beta = beta;
scores.betaFoe = betaFoe;
}
|
[
"public",
"static",
"void",
"insideAlgorithmFirstOrderExpect",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"HyperpotentialFoe",
"w",
",",
"final",
"Algebra",
"s",
",",
"final",
"Scores",
"scores",
")",
"{",
"final",
"int",
"n",
"=",
"graph",
".",
"getNodes",
"(",
")",
".",
"size",
"(",
")",
";",
"final",
"double",
"[",
"]",
"beta",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"final",
"double",
"[",
"]",
"betaFoe",
"=",
"new",
"double",
"[",
"n",
"]",
";",
"// \\beta_i = 0 \\forall i",
"Arrays",
".",
"fill",
"(",
"beta",
",",
"s",
".",
"zero",
"(",
")",
")",
";",
"Arrays",
".",
"fill",
"(",
"betaFoe",
",",
"s",
".",
"zero",
"(",
")",
")",
";",
"graph",
".",
"applyTopoSort",
"(",
"new",
"HyperedgeFn",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
")",
"{",
"// \\beta_{H(e)} += w_e \\prod_{j \\in T(e)} \\beta_j",
"double",
"prod",
"=",
"s",
".",
"one",
"(",
")",
";",
"double",
"prodFoe",
"=",
"s",
".",
"zero",
"(",
")",
";",
"for",
"(",
"Hypernode",
"jNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"j",
"=",
"jNode",
".",
"getId",
"(",
")",
";",
"// prod = s.times(prod, beta[j]);",
"// prodFoe = s.plus(s.times(prod, betaFoe[j]), s.times(beta[j], prodFoe));",
"double",
"p1",
"=",
"prod",
";",
"double",
"p2",
"=",
"beta",
"[",
"j",
"]",
";",
"double",
"r1",
"=",
"prodFoe",
";",
"double",
"r2",
"=",
"betaFoe",
"[",
"j",
"]",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"p1",
",",
"p2",
")",
";",
"prodFoe",
"=",
"s",
".",
"plus",
"(",
"s",
".",
"times",
"(",
"p1",
",",
"r2",
")",
",",
"s",
".",
"times",
"(",
"p2",
",",
"r1",
")",
")",
";",
"}",
"// prod = s.times(prod, w.getScore(e, s));",
"// prodFoe = s.plus(s.times(prod, w.getScoreFoe(e, s)), s.times(w.getScore(e, s), prodFoe));",
"double",
"p1",
"=",
"prod",
";",
"double",
"p2",
"=",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
";",
"double",
"r1",
"=",
"prodFoe",
";",
"double",
"r2",
"=",
"w",
".",
"getScoreFoe",
"(",
"e",
",",
"s",
")",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"p1",
",",
"p2",
")",
";",
"prodFoe",
"=",
"s",
".",
"plus",
"(",
"s",
".",
"times",
"(",
"p1",
",",
"r2",
")",
",",
"s",
".",
"times",
"(",
"p2",
",",
"r1",
")",
")",
";",
"int",
"i",
"=",
"e",
".",
"getHeadNode",
"(",
")",
".",
"getId",
"(",
")",
";",
"//if (log.isTraceEnabled()) { log.trace(String.format(\"old beta[%d] = %f\", i, s.toReal(beta[i]))); }",
"beta",
"[",
"i",
"]",
"=",
"s",
".",
"plus",
"(",
"beta",
"[",
"i",
"]",
",",
"prod",
")",
";",
"betaFoe",
"[",
"i",
"]",
"=",
"s",
".",
"plus",
"(",
"betaFoe",
"[",
"i",
"]",
",",
"prodFoe",
")",
";",
"assert",
"!",
"s",
".",
"isNaN",
"(",
"beta",
"[",
"i",
"]",
")",
";",
"assert",
"!",
"s",
".",
"isNaN",
"(",
"betaFoe",
"[",
"i",
"]",
")",
";",
"// log.debug(String.format(\"%s w_e=%f beta[%d] = %.3f betaFoe[%d] = %.3f\", e.getLabel(), s.toReal(w.getScore(e, s)), i, s.toReal(beta[i]), i, s.toReal(betaFoe[i]))); ",
"}",
"}",
")",
";",
"scores",
".",
"beta",
"=",
"beta",
";",
"scores",
".",
"betaFoe",
"=",
"betaFoe",
";",
"}"
] |
Runs the inside algorithm on a hypergraph with the first-order expectation semiring.
@param graph The hypergraph.
@return The beta value for each Hypernode. Where beta[i] is the inside
score for the i'th node in the Hypergraph, graph.getNodes().get(i).
|
[
"Runs",
"the",
"inside",
"algorithm",
"on",
"a",
"hypergraph",
"with",
"the",
"first",
"-",
"order",
"expectation",
"semiring",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L156-L203
|
12,192
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.outsideAdjoint
|
private static void outsideAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores) {
final double[] beta = scores.beta;
final double[] alphaAdj = scores.alphaAdj;
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
// \forall j \in T(e):
// \adj{\alpha_i} += \adj{\alpha_j} * w_e * \prod_{k \in T(e): k \neq j} \beta_k
for (Hypernode j : e.getTailNodes()) {
double prod = s.times(alphaAdj[j.getId()], w.getScore(e, s));
for (Hypernode k : e.getTailNodes()) {
if (k == j) { continue; }
prod = s.times(prod, beta[k.getId()]);
}
alphaAdj[i] = s.plus(alphaAdj[i], prod);
}
}
});
scores.alphaAdj = alphaAdj;
}
|
java
|
private static void outsideAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores) {
final double[] beta = scores.beta;
final double[] alphaAdj = scores.alphaAdj;
graph.applyTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
// \forall j \in T(e):
// \adj{\alpha_i} += \adj{\alpha_j} * w_e * \prod_{k \in T(e): k \neq j} \beta_k
for (Hypernode j : e.getTailNodes()) {
double prod = s.times(alphaAdj[j.getId()], w.getScore(e, s));
for (Hypernode k : e.getTailNodes()) {
if (k == j) { continue; }
prod = s.times(prod, beta[k.getId()]);
}
alphaAdj[i] = s.plus(alphaAdj[i], prod);
}
}
});
scores.alphaAdj = alphaAdj;
}
|
[
"private",
"static",
"void",
"outsideAdjoint",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"Hyperpotential",
"w",
",",
"final",
"Algebra",
"s",
",",
"final",
"Scores",
"scores",
")",
"{",
"final",
"double",
"[",
"]",
"beta",
"=",
"scores",
".",
"beta",
";",
"final",
"double",
"[",
"]",
"alphaAdj",
"=",
"scores",
".",
"alphaAdj",
";",
"graph",
".",
"applyTopoSort",
"(",
"new",
"HyperedgeFn",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
")",
"{",
"int",
"i",
"=",
"e",
".",
"getHeadNode",
"(",
")",
".",
"getId",
"(",
")",
";",
"// \\forall j \\in T(e):",
"// \\adj{\\alpha_i} += \\adj{\\alpha_j} * w_e * \\prod_{k \\in T(e): k \\neq j} \\beta_k",
"for",
"(",
"Hypernode",
"j",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"double",
"prod",
"=",
"s",
".",
"times",
"(",
"alphaAdj",
"[",
"j",
".",
"getId",
"(",
")",
"]",
",",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
")",
";",
"for",
"(",
"Hypernode",
"k",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"if",
"(",
"k",
"==",
"j",
")",
"{",
"continue",
";",
"}",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"beta",
"[",
"k",
".",
"getId",
"(",
")",
"]",
")",
";",
"}",
"alphaAdj",
"[",
"i",
"]",
"=",
"s",
".",
"plus",
"(",
"alphaAdj",
"[",
"i",
"]",
",",
"prod",
")",
";",
"}",
"}",
"}",
")",
";",
"scores",
".",
"alphaAdj",
"=",
"alphaAdj",
";",
"}"
] |
Computes the adjoints of the outside scores only.
Performs only a partial backwards pass through the outside algorithm.
INPUT: scores.beta, scores.alphaAdj.
OUTPUT: scores.alphaAdj.
@param graph The hypergraph
@param w The potential function.
@param s The semiring.
@param scores Input and output struct.
|
[
"Computes",
"the",
"adjoints",
"of",
"the",
"outside",
"scores",
"only",
".",
"Performs",
"only",
"a",
"partial",
"backwards",
"pass",
"through",
"the",
"outside",
"algorithm",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L398-L422
|
12,193
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.insideAdjoint
|
private static void insideAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores, final boolean backOutside) {
final double[] alpha = scores.alpha;
final double[] beta = scores.beta;
final double[] alphaAdj = scores.alphaAdj;
final double[] betaAdj = scores.betaAdj;
graph.applyRevTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
// \adj{\beta_{j}} += \sum_{e \in O(j)} \adj{\beta_{H(e)}} * w_e * \prod_{k \in T(e) : k \neq j} \beta_k
double prod = s.times(betaAdj[i], w.getScore(e, s));
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (j == k) { continue; }
prod = s.times(prod, beta[k]);
}
betaAdj[j] = s.plus(betaAdj[j], prod);
if (backOutside) {
// \adj{\beta_{j}} += \sum_{e \in O(j)} \sum_{k \in T(e) : k \neq j} \adj{\alpha_k} * w_e * \alpha_{H(e)} * \prod_{l \in T(e) : l \neq k, l \neq j} \beta_l
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (k == j) { continue; };
prod = s.times(alphaAdj[k], w.getScore(e, s));
prod = s.times(prod, alpha[i]);
for (Hypernode lNode : e.getTailNodes()) {
int l = lNode.getId();
if (l == j || l == k) { continue; }
prod = s.times(prod, beta[l]);
}
betaAdj[j] = s.plus(betaAdj[j], prod);
}
}
}
}
});
scores.betaAdj = betaAdj;
}
|
java
|
private static void insideAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores, final boolean backOutside) {
final double[] alpha = scores.alpha;
final double[] beta = scores.beta;
final double[] alphaAdj = scores.alphaAdj;
final double[] betaAdj = scores.betaAdj;
graph.applyRevTopoSort(new HyperedgeFn() {
@Override
public void apply(Hyperedge e) {
int i = e.getHeadNode().getId();
for (Hypernode jNode : e.getTailNodes()) {
int j = jNode.getId();
// \adj{\beta_{j}} += \sum_{e \in O(j)} \adj{\beta_{H(e)}} * w_e * \prod_{k \in T(e) : k \neq j} \beta_k
double prod = s.times(betaAdj[i], w.getScore(e, s));
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (j == k) { continue; }
prod = s.times(prod, beta[k]);
}
betaAdj[j] = s.plus(betaAdj[j], prod);
if (backOutside) {
// \adj{\beta_{j}} += \sum_{e \in O(j)} \sum_{k \in T(e) : k \neq j} \adj{\alpha_k} * w_e * \alpha_{H(e)} * \prod_{l \in T(e) : l \neq k, l \neq j} \beta_l
for (Hypernode kNode : e.getTailNodes()) {
int k = kNode.getId();
if (k == j) { continue; };
prod = s.times(alphaAdj[k], w.getScore(e, s));
prod = s.times(prod, alpha[i]);
for (Hypernode lNode : e.getTailNodes()) {
int l = lNode.getId();
if (l == j || l == k) { continue; }
prod = s.times(prod, beta[l]);
}
betaAdj[j] = s.plus(betaAdj[j], prod);
}
}
}
}
});
scores.betaAdj = betaAdj;
}
|
[
"private",
"static",
"void",
"insideAdjoint",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"Hyperpotential",
"w",
",",
"final",
"Algebra",
"s",
",",
"final",
"Scores",
"scores",
",",
"final",
"boolean",
"backOutside",
")",
"{",
"final",
"double",
"[",
"]",
"alpha",
"=",
"scores",
".",
"alpha",
";",
"final",
"double",
"[",
"]",
"beta",
"=",
"scores",
".",
"beta",
";",
"final",
"double",
"[",
"]",
"alphaAdj",
"=",
"scores",
".",
"alphaAdj",
";",
"final",
"double",
"[",
"]",
"betaAdj",
"=",
"scores",
".",
"betaAdj",
";",
"graph",
".",
"applyRevTopoSort",
"(",
"new",
"HyperedgeFn",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
")",
"{",
"int",
"i",
"=",
"e",
".",
"getHeadNode",
"(",
")",
".",
"getId",
"(",
")",
";",
"for",
"(",
"Hypernode",
"jNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"j",
"=",
"jNode",
".",
"getId",
"(",
")",
";",
"// \\adj{\\beta_{j}} += \\sum_{e \\in O(j)} \\adj{\\beta_{H(e)}} * w_e * \\prod_{k \\in T(e) : k \\neq j} \\beta_k ",
"double",
"prod",
"=",
"s",
".",
"times",
"(",
"betaAdj",
"[",
"i",
"]",
",",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
")",
";",
"for",
"(",
"Hypernode",
"kNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"k",
"=",
"kNode",
".",
"getId",
"(",
")",
";",
"if",
"(",
"j",
"==",
"k",
")",
"{",
"continue",
";",
"}",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"beta",
"[",
"k",
"]",
")",
";",
"}",
"betaAdj",
"[",
"j",
"]",
"=",
"s",
".",
"plus",
"(",
"betaAdj",
"[",
"j",
"]",
",",
"prod",
")",
";",
"if",
"(",
"backOutside",
")",
"{",
"// \\adj{\\beta_{j}} += \\sum_{e \\in O(j)} \\sum_{k \\in T(e) : k \\neq j} \\adj{\\alpha_k} * w_e * \\alpha_{H(e)} * \\prod_{l \\in T(e) : l \\neq k, l \\neq j} \\beta_l",
"for",
"(",
"Hypernode",
"kNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"k",
"=",
"kNode",
".",
"getId",
"(",
")",
";",
"if",
"(",
"k",
"==",
"j",
")",
"{",
"continue",
";",
"}",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"alphaAdj",
"[",
"k",
"]",
",",
"w",
".",
"getScore",
"(",
"e",
",",
"s",
")",
")",
";",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"alpha",
"[",
"i",
"]",
")",
";",
"for",
"(",
"Hypernode",
"lNode",
":",
"e",
".",
"getTailNodes",
"(",
")",
")",
"{",
"int",
"l",
"=",
"lNode",
".",
"getId",
"(",
")",
";",
"if",
"(",
"l",
"==",
"j",
"||",
"l",
"==",
"k",
")",
"{",
"continue",
";",
"}",
"prod",
"=",
"s",
".",
"times",
"(",
"prod",
",",
"beta",
"[",
"l",
"]",
")",
";",
"}",
"betaAdj",
"[",
"j",
"]",
"=",
"s",
".",
"plus",
"(",
"betaAdj",
"[",
"j",
"]",
",",
"prod",
")",
";",
"}",
"}",
"}",
"}",
"}",
")",
";",
"scores",
".",
"betaAdj",
"=",
"betaAdj",
";",
"}"
] |
Computes the adjoints of the inside scores only. Performs a partial
backwards pass through the outside algorithm, and a partial backwards
pass through the inside algorithm.
INPUT: scores.alpha, scores.beta, scores.betaAdj.
OUTPUT: scores.betaAdj.
@param graph The hypergraph
@param w The potential function.
@param s The semiring.
@param scores Input and output struct.
|
[
"Computes",
"the",
"adjoints",
"of",
"the",
"inside",
"scores",
"only",
".",
"Performs",
"a",
"partial",
"backwards",
"pass",
"through",
"the",
"outside",
"algorithm",
"and",
"a",
"partial",
"backwards",
"pass",
"through",
"the",
"inside",
"algorithm",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L437-L480
|
12,194
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java
|
Hyperalgo.weightAdjoint
|
private static void weightAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores, boolean backOutside) {
final double[] weightAdj = new double[graph.getNumEdges()];
HyperedgeDoubleFn lambda = new HyperedgeDoubleFn() {
public void apply(Hyperedge e, double val) {
weightAdj[e.getId()] = val;
}
};
weightAdjoint(graph, w, s, scores, lambda, backOutside);
scores.weightAdj = weightAdj;
}
|
java
|
private static void weightAdjoint(final Hypergraph graph, final Hyperpotential w, final Algebra s,
final Scores scores, boolean backOutside) {
final double[] weightAdj = new double[graph.getNumEdges()];
HyperedgeDoubleFn lambda = new HyperedgeDoubleFn() {
public void apply(Hyperedge e, double val) {
weightAdj[e.getId()] = val;
}
};
weightAdjoint(graph, w, s, scores, lambda, backOutside);
scores.weightAdj = weightAdj;
}
|
[
"private",
"static",
"void",
"weightAdjoint",
"(",
"final",
"Hypergraph",
"graph",
",",
"final",
"Hyperpotential",
"w",
",",
"final",
"Algebra",
"s",
",",
"final",
"Scores",
"scores",
",",
"boolean",
"backOutside",
")",
"{",
"final",
"double",
"[",
"]",
"weightAdj",
"=",
"new",
"double",
"[",
"graph",
".",
"getNumEdges",
"(",
")",
"]",
";",
"HyperedgeDoubleFn",
"lambda",
"=",
"new",
"HyperedgeDoubleFn",
"(",
")",
"{",
"public",
"void",
"apply",
"(",
"Hyperedge",
"e",
",",
"double",
"val",
")",
"{",
"weightAdj",
"[",
"e",
".",
"getId",
"(",
")",
"]",
"=",
"val",
";",
"}",
"}",
";",
"weightAdjoint",
"(",
"graph",
",",
"w",
",",
"s",
",",
"scores",
",",
"lambda",
",",
"backOutside",
")",
";",
"scores",
".",
"weightAdj",
"=",
"weightAdj",
";",
"}"
] |
Computes the adjoints of the hyperedge weights.
INPUT: scores.alpha, scores.beta, scores.alphaAdj, scores.betaAdj.
OUTPUT: scores.weightsAdj.
@param graph The hypergraph
@param w The potential function.
@param s The semiring.
@param scores Input and output struct.
|
[
"Computes",
"the",
"adjoints",
"of",
"the",
"hyperedge",
"weights",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/hypergraph/Hyperalgo.java#L494-L504
|
12,195
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java
|
ArgParser.registerClass
|
public void registerClass(Class<?> clazz) {
registeredClasses.add(clazz);
for (Field field : clazz.getFields()) {
if (field.isAnnotationPresent(Opt.class)) {
int mod = field.getModifiers();
if (!Modifier.isPublic(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on non-public field: " + field); }
if (Modifier.isFinal(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on final field: " + field); }
if (Modifier.isAbstract(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on abstract field: " + field); }
// Add an Apache Commons CLI Option for this field.
Opt opt = field.getAnnotation(Opt.class);
String name = getName(opt, field);
if (!names.add(name)) {
throw new RuntimeException("Multiple options have the same name: --" + name);
}
String shortName = null;
if (createShortNames) {
shortName = getAndAddUniqueShortName(name);
}
Option apacheOpt = new Option(shortName, name, opt.hasArg(), opt.description());
apacheOpt.setRequired(opt.required());
options.addOption(apacheOpt);
optionFieldMap.put(apacheOpt, field);
// Check that only boolean has hasArg() == false.
if (!field.getType().equals(Boolean.TYPE) && !opt.hasArg()) {
throw new RuntimeException("Only booleans can not have arguments.");
}
}
}
}
|
java
|
public void registerClass(Class<?> clazz) {
registeredClasses.add(clazz);
for (Field field : clazz.getFields()) {
if (field.isAnnotationPresent(Opt.class)) {
int mod = field.getModifiers();
if (!Modifier.isPublic(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on non-public field: " + field); }
if (Modifier.isFinal(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on final field: " + field); }
if (Modifier.isAbstract(mod)) { throw new IllegalStateException("@"+Opt.class.getName()+" on abstract field: " + field); }
// Add an Apache Commons CLI Option for this field.
Opt opt = field.getAnnotation(Opt.class);
String name = getName(opt, field);
if (!names.add(name)) {
throw new RuntimeException("Multiple options have the same name: --" + name);
}
String shortName = null;
if (createShortNames) {
shortName = getAndAddUniqueShortName(name);
}
Option apacheOpt = new Option(shortName, name, opt.hasArg(), opt.description());
apacheOpt.setRequired(opt.required());
options.addOption(apacheOpt);
optionFieldMap.put(apacheOpt, field);
// Check that only boolean has hasArg() == false.
if (!field.getType().equals(Boolean.TYPE) && !opt.hasArg()) {
throw new RuntimeException("Only booleans can not have arguments.");
}
}
}
}
|
[
"public",
"void",
"registerClass",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"registeredClasses",
".",
"add",
"(",
"clazz",
")",
";",
"for",
"(",
"Field",
"field",
":",
"clazz",
".",
"getFields",
"(",
")",
")",
"{",
"if",
"(",
"field",
".",
"isAnnotationPresent",
"(",
"Opt",
".",
"class",
")",
")",
"{",
"int",
"mod",
"=",
"field",
".",
"getModifiers",
"(",
")",
";",
"if",
"(",
"!",
"Modifier",
".",
"isPublic",
"(",
"mod",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"@\"",
"+",
"Opt",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\" on non-public field: \"",
"+",
"field",
")",
";",
"}",
"if",
"(",
"Modifier",
".",
"isFinal",
"(",
"mod",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"@\"",
"+",
"Opt",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\" on final field: \"",
"+",
"field",
")",
";",
"}",
"if",
"(",
"Modifier",
".",
"isAbstract",
"(",
"mod",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"@\"",
"+",
"Opt",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\" on abstract field: \"",
"+",
"field",
")",
";",
"}",
"// Add an Apache Commons CLI Option for this field.",
"Opt",
"opt",
"=",
"field",
".",
"getAnnotation",
"(",
"Opt",
".",
"class",
")",
";",
"String",
"name",
"=",
"getName",
"(",
"opt",
",",
"field",
")",
";",
"if",
"(",
"!",
"names",
".",
"add",
"(",
"name",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Multiple options have the same name: --\"",
"+",
"name",
")",
";",
"}",
"String",
"shortName",
"=",
"null",
";",
"if",
"(",
"createShortNames",
")",
"{",
"shortName",
"=",
"getAndAddUniqueShortName",
"(",
"name",
")",
";",
"}",
"Option",
"apacheOpt",
"=",
"new",
"Option",
"(",
"shortName",
",",
"name",
",",
"opt",
".",
"hasArg",
"(",
")",
",",
"opt",
".",
"description",
"(",
")",
")",
";",
"apacheOpt",
".",
"setRequired",
"(",
"opt",
".",
"required",
"(",
")",
")",
";",
"options",
".",
"addOption",
"(",
"apacheOpt",
")",
";",
"optionFieldMap",
".",
"put",
"(",
"apacheOpt",
",",
"field",
")",
";",
"// Check that only boolean has hasArg() == false.",
"if",
"(",
"!",
"field",
".",
"getType",
"(",
")",
".",
"equals",
"(",
"Boolean",
".",
"TYPE",
")",
"&&",
"!",
"opt",
".",
"hasArg",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Only booleans can not have arguments.\"",
")",
";",
"}",
"}",
"}",
"}"
] |
Registers all the @Opt annotations on a class with this ArgParser.
|
[
"Registers",
"all",
"the"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java#L89-L123
|
12,196
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java
|
ArgParser.getName
|
private static String getName(Opt option, Field field) {
if (option.name().equals(Opt.DEFAULT_STRING)) {
return field.getName();
} else {
return option.name();
}
}
|
java
|
private static String getName(Opt option, Field field) {
if (option.name().equals(Opt.DEFAULT_STRING)) {
return field.getName();
} else {
return option.name();
}
}
|
[
"private",
"static",
"String",
"getName",
"(",
"Opt",
"option",
",",
"Field",
"field",
")",
"{",
"if",
"(",
"option",
".",
"name",
"(",
")",
".",
"equals",
"(",
"Opt",
".",
"DEFAULT_STRING",
")",
")",
"{",
"return",
"field",
".",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"return",
"option",
".",
"name",
"(",
")",
";",
"}",
"}"
] |
Gets the name specified in @Opt(name=...) if present, or the name of the field otherwise.
|
[
"Gets",
"the",
"name",
"specified",
"in"
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java#L157-L163
|
12,197
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java
|
ArgParser.printUsage
|
public void printUsage() {
String name = mainClass == null ? "<MainClass>" : mainClass.getName();
String usage = "java " + name + " [OPTIONS]";
final HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(usage, options, true);
}
|
java
|
public void printUsage() {
String name = mainClass == null ? "<MainClass>" : mainClass.getName();
String usage = "java " + name + " [OPTIONS]";
final HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(usage, options, true);
}
|
[
"public",
"void",
"printUsage",
"(",
")",
"{",
"String",
"name",
"=",
"mainClass",
"==",
"null",
"?",
"\"<MainClass>\"",
":",
"mainClass",
".",
"getName",
"(",
")",
";",
"String",
"usage",
"=",
"\"java \"",
"+",
"name",
"+",
"\" [OPTIONS]\"",
";",
"final",
"HelpFormatter",
"formatter",
"=",
"new",
"HelpFormatter",
"(",
")",
";",
"formatter",
".",
"setWidth",
"(",
"120",
")",
";",
"formatter",
".",
"printHelp",
"(",
"usage",
",",
"options",
",",
"true",
")",
";",
"}"
] |
Prints the usage of the main class for this ArgParser.
|
[
"Prints",
"the",
"usage",
"of",
"the",
"main",
"class",
"for",
"this",
"ArgParser",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java#L269-L275
|
12,198
|
mgormley/pacaya
|
src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java
|
ArgParser.safeStrToInt
|
public static int safeStrToInt(String str) {
if (sciInt.matcher(str).find()) {
return SafeCast.safeDoubleToInt(Double.parseDouble(str.toUpperCase()));
} else {
return Integer.parseInt(str);
}
}
|
java
|
public static int safeStrToInt(String str) {
if (sciInt.matcher(str).find()) {
return SafeCast.safeDoubleToInt(Double.parseDouble(str.toUpperCase()));
} else {
return Integer.parseInt(str);
}
}
|
[
"public",
"static",
"int",
"safeStrToInt",
"(",
"String",
"str",
")",
"{",
"if",
"(",
"sciInt",
".",
"matcher",
"(",
"str",
")",
".",
"find",
"(",
")",
")",
"{",
"return",
"SafeCast",
".",
"safeDoubleToInt",
"(",
"Double",
".",
"parseDouble",
"(",
"str",
".",
"toUpperCase",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"str",
")",
";",
"}",
"}"
] |
Correctly casts 1e+06 to 1000000.
|
[
"Correctly",
"casts",
"1e",
"+",
"06",
"to",
"1000000",
"."
] |
786294cbac7cc65dbc32210c10acc32ed0c69233
|
https://github.com/mgormley/pacaya/blob/786294cbac7cc65dbc32210c10acc32ed0c69233/src/main/java/edu/jhu/pacaya/util/cli/ArgParser.java#L330-L336
|
12,199
|
youngmonkeys/ezyfox-sfs2x
|
src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentSerializer.java
|
AgentSerializer.serialize
|
@SuppressWarnings({ "unchecked", "rawtypes" })
public List serialize(ClassUnwrapper unwrapper, Object agent) {
List variables = new ArrayList<>();
List<GetterMethodCover> methods = unwrapper.getMethods();
for(GetterMethodCover method : methods) {
Object value = method.invoke(agent);
if(value == null)
continue;
variables.add(newVariable(method.getKey(),
getValue(method, value),
method.isHidden()));
}
return variables;
}
|
java
|
@SuppressWarnings({ "unchecked", "rawtypes" })
public List serialize(ClassUnwrapper unwrapper, Object agent) {
List variables = new ArrayList<>();
List<GetterMethodCover> methods = unwrapper.getMethods();
for(GetterMethodCover method : methods) {
Object value = method.invoke(agent);
if(value == null)
continue;
variables.add(newVariable(method.getKey(),
getValue(method, value),
method.isHidden()));
}
return variables;
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
",",
"\"rawtypes\"",
"}",
")",
"public",
"List",
"serialize",
"(",
"ClassUnwrapper",
"unwrapper",
",",
"Object",
"agent",
")",
"{",
"List",
"variables",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"List",
"<",
"GetterMethodCover",
">",
"methods",
"=",
"unwrapper",
".",
"getMethods",
"(",
")",
";",
"for",
"(",
"GetterMethodCover",
"method",
":",
"methods",
")",
"{",
"Object",
"value",
"=",
"method",
".",
"invoke",
"(",
"agent",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"continue",
";",
"variables",
".",
"add",
"(",
"newVariable",
"(",
"method",
".",
"getKey",
"(",
")",
",",
"getValue",
"(",
"method",
",",
"value",
")",
",",
"method",
".",
"isHidden",
"(",
")",
")",
")",
";",
"}",
"return",
"variables",
";",
"}"
] |
Serialize java object
@param unwrapper structure of agent class
@param agent the agent object
@return List of variables
|
[
"Serialize",
"java",
"object"
] |
7e004033a3b551c3ae970a0c8f45db7b1ec144de
|
https://github.com/youngmonkeys/ezyfox-sfs2x/blob/7e004033a3b551c3ae970a0c8f45db7b1ec144de/src/main/java/com/tvd12/ezyfox/sfs2x/serializer/AgentSerializer.java#L42-L55
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.