id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,200 | kefirfromperm/kefirbb | src/org/kefirsf/bb/DomConfigurationFactory.java | DomConfigurationFactory.nodeAttribute | private boolean nodeAttribute(Node node, String attributeName, boolean defaultValue) {
boolean value = defaultValue;
if (node.hasAttributes()) {
Node attribute = node.getAttributes().getNamedItem(attributeName);
if (attribute != null) {
value = Boolean.valueOf(attribute.getNodeValue());
}
}
return value;
} | java | private boolean nodeAttribute(Node node, String attributeName, boolean defaultValue) {
boolean value = defaultValue;
if (node.hasAttributes()) {
Node attribute = node.getAttributes().getNamedItem(attributeName);
if (attribute != null) {
value = Boolean.valueOf(attribute.getNodeValue());
}
}
return value;
} | [
"private",
"boolean",
"nodeAttribute",
"(",
"Node",
"node",
",",
"String",
"attributeName",
",",
"boolean",
"defaultValue",
")",
"{",
"boolean",
"value",
"=",
"defaultValue",
";",
"if",
"(",
"node",
".",
"hasAttributes",
"(",
")",
")",
"{",
"Node",
"attribute",
"=",
"node",
".",
"getAttributes",
"(",
")",
".",
"getNamedItem",
"(",
"attributeName",
")",
";",
"if",
"(",
"attribute",
"!=",
"null",
")",
"{",
"value",
"=",
"Boolean",
".",
"valueOf",
"(",
"attribute",
".",
"getNodeValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Return node attribute value, if exists or default attribute value
@param node XML-node
@param attributeName attributeName
@param defaultValue attribute default value
@return attribute value or default value | [
"Return",
"node",
"attribute",
"value",
"if",
"exists",
"or",
"default",
"attribute",
"value"
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/DomConfigurationFactory.java#L602-L611 |
2,201 | kefirfromperm/kefirbb | src/org/kefirsf/bb/DomConfigurationFactory.java | DomConfigurationFactory.nodeHasAttribute | private boolean nodeHasAttribute(Node node, String attributeName) {
return node.hasAttributes() && node.getAttributes().getNamedItem(attributeName) != null;
} | java | private boolean nodeHasAttribute(Node node, String attributeName) {
return node.hasAttributes() && node.getAttributes().getNamedItem(attributeName) != null;
} | [
"private",
"boolean",
"nodeHasAttribute",
"(",
"Node",
"node",
",",
"String",
"attributeName",
")",
"{",
"return",
"node",
".",
"hasAttributes",
"(",
")",
"&&",
"node",
".",
"getAttributes",
"(",
")",
".",
"getNamedItem",
"(",
"attributeName",
")",
"!=",
"null",
";",
"}"
] | Check node attribute.
@param node XML-node
@param attributeName name of attribute
@return true if node has attribute with specified name
false if has not | [
"Check",
"node",
"attribute",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/DomConfigurationFactory.java#L677-L679 |
2,202 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/ProcPattern.java | ProcPattern.parse | public boolean parse(Context context) throws NestingException {
boolean flag = true;
Source source = context.getSource();
int offset = source.getOffset();
// Log start parsing
if (log.isTraceEnabled()) {
log.trace("[{}] Begin {}", offset, this);
}
int i;
for (i = 0; i < patternSize && flag; i++) {
ProcPatternElement current = elements.get(i);
ProcPatternElement next;
if (i < patternSize - 1) {
next = elements.get(i + 1);
} else {
next = context.getTerminator();
}
flag = current.parse(context, next);
}
if (!flag) {
if (log.isTraceEnabled()) {
log.trace("[{}] Rollback {} on {} element", source.getOffset(), this, i);
}
source.setOffset(offset);
} else {
if (log.isTraceEnabled()) {
log.trace("[{}] Complete {}", source.getOffset(), this);
}
}
return flag;
} | java | public boolean parse(Context context) throws NestingException {
boolean flag = true;
Source source = context.getSource();
int offset = source.getOffset();
// Log start parsing
if (log.isTraceEnabled()) {
log.trace("[{}] Begin {}", offset, this);
}
int i;
for (i = 0; i < patternSize && flag; i++) {
ProcPatternElement current = elements.get(i);
ProcPatternElement next;
if (i < patternSize - 1) {
next = elements.get(i + 1);
} else {
next = context.getTerminator();
}
flag = current.parse(context, next);
}
if (!flag) {
if (log.isTraceEnabled()) {
log.trace("[{}] Rollback {} on {} element", source.getOffset(), this, i);
}
source.setOffset(offset);
} else {
if (log.isTraceEnabled()) {
log.trace("[{}] Complete {}", source.getOffset(), this);
}
}
return flag;
} | [
"public",
"boolean",
"parse",
"(",
"Context",
"context",
")",
"throws",
"NestingException",
"{",
"boolean",
"flag",
"=",
"true",
";",
"Source",
"source",
"=",
"context",
".",
"getSource",
"(",
")",
";",
"int",
"offset",
"=",
"source",
".",
"getOffset",
"(",
")",
";",
"// Log start parsing",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"[{}] Begin {}\"",
",",
"offset",
",",
"this",
")",
";",
"}",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"patternSize",
"&&",
"flag",
";",
"i",
"++",
")",
"{",
"ProcPatternElement",
"current",
"=",
"elements",
".",
"get",
"(",
"i",
")",
";",
"ProcPatternElement",
"next",
";",
"if",
"(",
"i",
"<",
"patternSize",
"-",
"1",
")",
"{",
"next",
"=",
"elements",
".",
"get",
"(",
"i",
"+",
"1",
")",
";",
"}",
"else",
"{",
"next",
"=",
"context",
".",
"getTerminator",
"(",
")",
";",
"}",
"flag",
"=",
"current",
".",
"parse",
"(",
"context",
",",
"next",
")",
";",
"}",
"if",
"(",
"!",
"flag",
")",
"{",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"[{}] Rollback {} on {} element\"",
",",
"source",
".",
"getOffset",
"(",
")",
",",
"this",
",",
"i",
")",
";",
"}",
"source",
".",
"setOffset",
"(",
"offset",
")",
";",
"}",
"else",
"{",
"if",
"(",
"log",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"log",
".",
"trace",
"(",
"\"[{}] Complete {}\"",
",",
"source",
".",
"getOffset",
"(",
")",
",",
"this",
")",
";",
"}",
"}",
"return",
"flag",
";",
"}"
] | Parse context with this pattern
@param context current context
@return true if next subsequence is valid to this pattern,
false others
@throws NestingException if nesting is too big. | [
"Parse",
"context",
"with",
"this",
"pattern"
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/ProcPattern.java#L62-L97 |
2,203 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/ProcCode.java | ProcCode.process | public boolean process(Context context) throws NestingException {
for(ProcPattern pattern: patterns){
Context codeContext = new Context(context);
if (pattern.parse(codeContext)) {
if(transparent) {
codeContext.mergeWithParent();
}
template.generate(codeContext);
if(logContext.isTraceEnabled()){
for(Map.Entry<String, CharSequence> entry:context.getAttributes().entrySet()){
logContext.trace("Context: {} = {}", entry.getKey(), entry.getValue());
}
}
if(logGenerate.isTraceEnabled()){
logGenerate.trace("Generated text: {}", codeContext.getTarget());
}
return true;
}
}
return false;
} | java | public boolean process(Context context) throws NestingException {
for(ProcPattern pattern: patterns){
Context codeContext = new Context(context);
if (pattern.parse(codeContext)) {
if(transparent) {
codeContext.mergeWithParent();
}
template.generate(codeContext);
if(logContext.isTraceEnabled()){
for(Map.Entry<String, CharSequence> entry:context.getAttributes().entrySet()){
logContext.trace("Context: {} = {}", entry.getKey(), entry.getValue());
}
}
if(logGenerate.isTraceEnabled()){
logGenerate.trace("Generated text: {}", codeContext.getTarget());
}
return true;
}
}
return false;
} | [
"public",
"boolean",
"process",
"(",
"Context",
"context",
")",
"throws",
"NestingException",
"{",
"for",
"(",
"ProcPattern",
"pattern",
":",
"patterns",
")",
"{",
"Context",
"codeContext",
"=",
"new",
"Context",
"(",
"context",
")",
";",
"if",
"(",
"pattern",
".",
"parse",
"(",
"codeContext",
")",
")",
"{",
"if",
"(",
"transparent",
")",
"{",
"codeContext",
".",
"mergeWithParent",
"(",
")",
";",
"}",
"template",
".",
"generate",
"(",
"codeContext",
")",
";",
"if",
"(",
"logContext",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"CharSequence",
">",
"entry",
":",
"context",
".",
"getAttributes",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"logContext",
".",
"trace",
"(",
"\"Context: {} = {}\"",
",",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"logGenerate",
".",
"isTraceEnabled",
"(",
")",
")",
"{",
"logGenerate",
".",
"trace",
"(",
"\"Generated text: {}\"",
",",
"codeContext",
".",
"getTarget",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Parse bb-code
Before invocation suspicious method must be call
@param context the bb-processing context
@return true - if parse source
false - if can't parse code
@throws NestingException if nesting is too big. | [
"Parse",
"bb",
"-",
"code"
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/ProcCode.java#L66-L90 |
2,204 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/ProcCode.java | ProcCode.suspicious | public boolean suspicious(Context context) {
for(ProcPattern pattern:patterns){
if(pattern.suspicious(context)){
return true;
}
}
return false;
} | java | public boolean suspicious(Context context) {
for(ProcPattern pattern:patterns){
if(pattern.suspicious(context)){
return true;
}
}
return false;
} | [
"public",
"boolean",
"suspicious",
"(",
"Context",
"context",
")",
"{",
"for",
"(",
"ProcPattern",
"pattern",
":",
"patterns",
")",
"{",
"if",
"(",
"pattern",
".",
"suspicious",
"(",
"context",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if next sequence can be parsed with this code.
It's most called method in this project.
@param context current context
@return true - if next sequence can be parsed with this code;
false - only if next sequence can't be parsed with this code. | [
"Check",
"if",
"next",
"sequence",
"can",
"be",
"parsed",
"with",
"this",
"code",
".",
"It",
"s",
"most",
"called",
"method",
"in",
"this",
"project",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/ProcCode.java#L100-L107 |
2,205 | kefirfromperm/kefirbb | src/org/kefirsf/bb/util/Utils.java | Utils.openResourceStream | public static InputStream openResourceStream(String resourceName) {
InputStream stream = null;
ClassLoader classLoader = Utils.class.getClassLoader();
if (classLoader != null) {
stream = classLoader.getResourceAsStream(resourceName);
}
if (stream == null) {
stream = ClassLoader.getSystemResourceAsStream(resourceName);
}
return stream;
} | java | public static InputStream openResourceStream(String resourceName) {
InputStream stream = null;
ClassLoader classLoader = Utils.class.getClassLoader();
if (classLoader != null) {
stream = classLoader.getResourceAsStream(resourceName);
}
if (stream == null) {
stream = ClassLoader.getSystemResourceAsStream(resourceName);
}
return stream;
} | [
"public",
"static",
"InputStream",
"openResourceStream",
"(",
"String",
"resourceName",
")",
"{",
"InputStream",
"stream",
"=",
"null",
";",
"ClassLoader",
"classLoader",
"=",
"Utils",
".",
"class",
".",
"getClassLoader",
"(",
")",
";",
"if",
"(",
"classLoader",
"!=",
"null",
")",
"{",
"stream",
"=",
"classLoader",
".",
"getResourceAsStream",
"(",
"resourceName",
")",
";",
"}",
"if",
"(",
"stream",
"==",
"null",
")",
"{",
"stream",
"=",
"ClassLoader",
".",
"getSystemResourceAsStream",
"(",
"resourceName",
")",
";",
"}",
"return",
"stream",
";",
"}"
] | Open the resource stream for named resource.
Stream must be closed by user after usage.
@param resourceName resource name
@return input stream | [
"Open",
"the",
"resource",
"stream",
"for",
"named",
"resource",
".",
"Stream",
"must",
"be",
"closed",
"by",
"user",
"after",
"usage",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/util/Utils.java#L22-L33 |
2,206 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/Source.java | Source.getConstantChars | private char[] getConstantChars() {
Set<Character> chars = new TreeSet<Character>();
chars.add('\n');
chars.add('\r');
for (PatternConstant constant : constantSet) {
char c = constant.getValue().charAt(0);
if (constant.isIgnoreCase()) {
chars.add(Character.toLowerCase(c));
chars.add(Character.toUpperCase(c));
} else {
chars.add(c);
}
}
char[] cs = new char[chars.size()];
int j = 0;
for (Character c : chars) {
cs[j] = c;
j++;
}
Arrays.sort(cs);
return cs;
} | java | private char[] getConstantChars() {
Set<Character> chars = new TreeSet<Character>();
chars.add('\n');
chars.add('\r');
for (PatternConstant constant : constantSet) {
char c = constant.getValue().charAt(0);
if (constant.isIgnoreCase()) {
chars.add(Character.toLowerCase(c));
chars.add(Character.toUpperCase(c));
} else {
chars.add(c);
}
}
char[] cs = new char[chars.size()];
int j = 0;
for (Character c : chars) {
cs[j] = c;
j++;
}
Arrays.sort(cs);
return cs;
} | [
"private",
"char",
"[",
"]",
"getConstantChars",
"(",
")",
"{",
"Set",
"<",
"Character",
">",
"chars",
"=",
"new",
"TreeSet",
"<",
"Character",
">",
"(",
")",
";",
"chars",
".",
"add",
"(",
"'",
"'",
")",
";",
"chars",
".",
"add",
"(",
"'",
"'",
")",
";",
"for",
"(",
"PatternConstant",
"constant",
":",
"constantSet",
")",
"{",
"char",
"c",
"=",
"constant",
".",
"getValue",
"(",
")",
".",
"charAt",
"(",
"0",
")",
";",
"if",
"(",
"constant",
".",
"isIgnoreCase",
"(",
")",
")",
"{",
"chars",
".",
"add",
"(",
"Character",
".",
"toLowerCase",
"(",
"c",
")",
")",
";",
"chars",
".",
"add",
"(",
"Character",
".",
"toUpperCase",
"(",
"c",
")",
")",
";",
"}",
"else",
"{",
"chars",
".",
"add",
"(",
"c",
")",
";",
"}",
"}",
"char",
"[",
"]",
"cs",
"=",
"new",
"char",
"[",
"chars",
".",
"size",
"(",
")",
"]",
";",
"int",
"j",
"=",
"0",
";",
"for",
"(",
"Character",
"c",
":",
"chars",
")",
"{",
"cs",
"[",
"j",
"]",
"=",
"c",
";",
"j",
"++",
";",
"}",
"Arrays",
".",
"sort",
"(",
"cs",
")",
";",
"return",
"cs",
";",
"}"
] | Collect first chars of constants of configuration.
@return array of first chars of constants. | [
"Collect",
"first",
"chars",
"of",
"constants",
"of",
"configuration",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/Source.java#L82-L104 |
2,207 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/Source.java | Source.nextIs | public boolean nextIs(PatternConstant constant) {
char[] cs = constant.getCharArray();
int length = cs.length;
if (length > textLength - offset) {
return false;
}
if (!constant.isIgnoreCase()) {
int i;
//noinspection StatementWithEmptyBody
for (i = 0; i < length && text[offset + i] == cs[i]; i++);
return i == length;
} else {
for (int i = 0; i < length; i++) {
char ct = text[offset + i];
char cv = cs[i];
if (
ct == cv ||
Character.toUpperCase(ct) == Character.toUpperCase(cv) ||
Character.toLowerCase(ct) == Character.toLowerCase(cv)
) {
continue;
}
return false;
}
return true;
}
} | java | public boolean nextIs(PatternConstant constant) {
char[] cs = constant.getCharArray();
int length = cs.length;
if (length > textLength - offset) {
return false;
}
if (!constant.isIgnoreCase()) {
int i;
//noinspection StatementWithEmptyBody
for (i = 0; i < length && text[offset + i] == cs[i]; i++);
return i == length;
} else {
for (int i = 0; i < length; i++) {
char ct = text[offset + i];
char cv = cs[i];
if (
ct == cv ||
Character.toUpperCase(ct) == Character.toUpperCase(cv) ||
Character.toLowerCase(ct) == Character.toLowerCase(cv)
) {
continue;
}
return false;
}
return true;
}
} | [
"public",
"boolean",
"nextIs",
"(",
"PatternConstant",
"constant",
")",
"{",
"char",
"[",
"]",
"cs",
"=",
"constant",
".",
"getCharArray",
"(",
")",
";",
"int",
"length",
"=",
"cs",
".",
"length",
";",
"if",
"(",
"length",
">",
"textLength",
"-",
"offset",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"constant",
".",
"isIgnoreCase",
"(",
")",
")",
"{",
"int",
"i",
";",
"//noinspection StatementWithEmptyBody",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
"&&",
"text",
"[",
"offset",
"+",
"i",
"]",
"==",
"cs",
"[",
"i",
"]",
";",
"i",
"++",
")",
";",
"return",
"i",
"==",
"length",
";",
"}",
"else",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"char",
"ct",
"=",
"text",
"[",
"offset",
"+",
"i",
"]",
";",
"char",
"cv",
"=",
"cs",
"[",
"i",
"]",
";",
"if",
"(",
"ct",
"==",
"cv",
"||",
"Character",
".",
"toUpperCase",
"(",
"ct",
")",
"==",
"Character",
".",
"toUpperCase",
"(",
"cv",
")",
"||",
"Character",
".",
"toLowerCase",
"(",
"ct",
")",
"==",
"Character",
".",
"toLowerCase",
"(",
"cv",
")",
")",
"{",
"continue",
";",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"}"
] | Test id next sequence the constant?
@param constant constant pattern element
@return true if next sub sequence is constant. | [
"Test",
"id",
"next",
"sequence",
"the",
"constant?"
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/Source.java#L112-L140 |
2,208 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/Source.java | Source.find | public int find(PatternConstant constant) {
char[] cs = constant.getCharArray();
boolean ignoreCase = constant.isIgnoreCase();
return find(cs, ignoreCase);
} | java | public int find(PatternConstant constant) {
char[] cs = constant.getCharArray();
boolean ignoreCase = constant.isIgnoreCase();
return find(cs, ignoreCase);
} | [
"public",
"int",
"find",
"(",
"PatternConstant",
"constant",
")",
"{",
"char",
"[",
"]",
"cs",
"=",
"constant",
".",
"getCharArray",
"(",
")",
";",
"boolean",
"ignoreCase",
"=",
"constant",
".",
"isIgnoreCase",
"(",
")",
";",
"return",
"find",
"(",
"cs",
",",
"ignoreCase",
")",
";",
"}"
] | Find constant in source text.
@param constant constant pattern element
@return index of constant of negative if don't find. | [
"Find",
"constant",
"in",
"source",
"text",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/Source.java#L148-L153 |
2,209 | kefirfromperm/kefirbb | src/org/kefirsf/bb/proc/ProcTemplate.java | ProcTemplate.generate | public void generate(Context context) {
Appendable target = context.getTarget();
for (ProcTemplateElement element : elements) {
try {
target.append(element.generate(context));
} catch (IOException e) {
// Nothing! Because StringBuilder doesn't catch IOException
}
}
} | java | public void generate(Context context) {
Appendable target = context.getTarget();
for (ProcTemplateElement element : elements) {
try {
target.append(element.generate(context));
} catch (IOException e) {
// Nothing! Because StringBuilder doesn't catch IOException
}
}
} | [
"public",
"void",
"generate",
"(",
"Context",
"context",
")",
"{",
"Appendable",
"target",
"=",
"context",
".",
"getTarget",
"(",
")",
";",
"for",
"(",
"ProcTemplateElement",
"element",
":",
"elements",
")",
"{",
"try",
"{",
"target",
".",
"append",
"(",
"element",
".",
"generate",
"(",
"context",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// Nothing! Because StringBuilder doesn't catch IOException",
"}",
"}",
"}"
] | Append to result string processed text.
@param context current context. | [
"Append",
"to",
"result",
"string",
"processed",
"text",
"."
] | 8c36fc3d3dc27459b0cdc179b87582df30420856 | https://github.com/kefirfromperm/kefirbb/blob/8c36fc3d3dc27459b0cdc179b87582df30420856/src/org/kefirsf/bb/proc/ProcTemplate.java#L32-L42 |
2,210 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/RecyclerViewPager.java | RecyclerViewPager.getCurrentPosition | public int getCurrentPosition() {
int curPosition = -1;
if (getLayoutManager().canScrollHorizontally()) {
curPosition = ViewUtils.getCenterXChildPosition(this);
} else {
curPosition = ViewUtils.getCenterYChildPosition(this);
}
if (curPosition < 0) {
curPosition = mSmoothScrollTargetPosition;
}
return curPosition;
} | java | public int getCurrentPosition() {
int curPosition = -1;
if (getLayoutManager().canScrollHorizontally()) {
curPosition = ViewUtils.getCenterXChildPosition(this);
} else {
curPosition = ViewUtils.getCenterYChildPosition(this);
}
if (curPosition < 0) {
curPosition = mSmoothScrollTargetPosition;
}
return curPosition;
} | [
"public",
"int",
"getCurrentPosition",
"(",
")",
"{",
"int",
"curPosition",
"=",
"-",
"1",
";",
"if",
"(",
"getLayoutManager",
"(",
")",
".",
"canScrollHorizontally",
"(",
")",
")",
"{",
"curPosition",
"=",
"ViewUtils",
".",
"getCenterXChildPosition",
"(",
"this",
")",
";",
"}",
"else",
"{",
"curPosition",
"=",
"ViewUtils",
".",
"getCenterYChildPosition",
"(",
"this",
")",
";",
"}",
"if",
"(",
"curPosition",
"<",
"0",
")",
"{",
"curPosition",
"=",
"mSmoothScrollTargetPosition",
";",
"}",
"return",
"curPosition",
";",
"}"
] | get item position in center of viewpager | [
"get",
"item",
"position",
"in",
"center",
"of",
"viewpager"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/RecyclerViewPager.java#L246-L257 |
2,211 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java | ViewUtils.getCenterXChild | public static View getCenterXChild(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterX(recyclerView, child)) {
return child;
}
}
return null;
} | java | public static View getCenterXChild(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterX(recyclerView, child)) {
return child;
}
}
return null;
} | [
"public",
"static",
"View",
"getCenterXChild",
"(",
"RecyclerView",
"recyclerView",
")",
"{",
"int",
"childCount",
"=",
"recyclerView",
".",
"getChildCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"childCount",
";",
"i",
"++",
")",
"{",
"View",
"child",
"=",
"recyclerView",
".",
"getChildAt",
"(",
"i",
")",
";",
"if",
"(",
"isChildInCenterX",
"(",
"recyclerView",
",",
"child",
")",
")",
"{",
"return",
"child",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get center child in X Axes | [
"Get",
"center",
"child",
"in",
"X",
"Axes"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java#L12-L21 |
2,212 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java | ViewUtils.getCenterXChildPosition | public static int getCenterXChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterX(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
return childCount;
} | java | public static int getCenterXChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterX(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
return childCount;
} | [
"public",
"static",
"int",
"getCenterXChildPosition",
"(",
"RecyclerView",
"recyclerView",
")",
"{",
"int",
"childCount",
"=",
"recyclerView",
".",
"getChildCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"childCount",
";",
"i",
"++",
")",
"{",
"View",
"child",
"=",
"recyclerView",
".",
"getChildAt",
"(",
"i",
")",
";",
"if",
"(",
"isChildInCenterX",
"(",
"recyclerView",
",",
"child",
")",
")",
"{",
"return",
"recyclerView",
".",
"getChildAdapterPosition",
"(",
"child",
")",
";",
"}",
"}",
"return",
"childCount",
";",
"}"
] | Get position of center child in X Axes | [
"Get",
"position",
"of",
"center",
"child",
"in",
"X",
"Axes"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java#L26-L35 |
2,213 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java | ViewUtils.getCenterYChild | public static View getCenterYChild(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterY(recyclerView, child)) {
return child;
}
}
return null;
} | java | public static View getCenterYChild(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterY(recyclerView, child)) {
return child;
}
}
return null;
} | [
"public",
"static",
"View",
"getCenterYChild",
"(",
"RecyclerView",
"recyclerView",
")",
"{",
"int",
"childCount",
"=",
"recyclerView",
".",
"getChildCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"childCount",
";",
"i",
"++",
")",
"{",
"View",
"child",
"=",
"recyclerView",
".",
"getChildAt",
"(",
"i",
")",
";",
"if",
"(",
"isChildInCenterY",
"(",
"recyclerView",
",",
"child",
")",
")",
"{",
"return",
"child",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get center child in Y Axes | [
"Get",
"center",
"child",
"in",
"Y",
"Axes"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java#L56-L65 |
2,214 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java | ViewUtils.getCenterYChildPosition | public static int getCenterYChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterY(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
return childCount;
} | java | public static int getCenterYChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterY(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
return childCount;
} | [
"public",
"static",
"int",
"getCenterYChildPosition",
"(",
"RecyclerView",
"recyclerView",
")",
"{",
"int",
"childCount",
"=",
"recyclerView",
".",
"getChildCount",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"childCount",
";",
"i",
"++",
")",
"{",
"View",
"child",
"=",
"recyclerView",
".",
"getChildAt",
"(",
"i",
")",
";",
"if",
"(",
"isChildInCenterY",
"(",
"recyclerView",
",",
"child",
")",
")",
"{",
"return",
"recyclerView",
".",
"getChildAdapterPosition",
"(",
"child",
")",
";",
"}",
"}",
"return",
"childCount",
";",
"}"
] | Get position of center child in Y Axes | [
"Get",
"position",
"of",
"center",
"child",
"in",
"Y",
"Axes"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/pageview/ViewUtils.java#L70-L79 |
2,215 | buyi/RecyclerViewPagerIndicator | sample/src/main/java/com/viewpagerindicator/as/sample/ListSamples.java | ListSamples.setStatusBarColor | public void setStatusBarColor(View statusBar,int color){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//status bar height
int actionBarHeight = getActionBarHeight();
int statusBarHeight = getStatusBarHeight();
// System.out.println("actionBarHeight:" + actionBarHeight);
// System.out.println("statusBarHeight:" + statusBarHeight);
//action bar height
statusBar.getLayoutParams().height = statusBarHeight;
statusBar.setBackgroundColor(color);
}
} | java | public void setStatusBarColor(View statusBar,int color){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//status bar height
int actionBarHeight = getActionBarHeight();
int statusBarHeight = getStatusBarHeight();
// System.out.println("actionBarHeight:" + actionBarHeight);
// System.out.println("statusBarHeight:" + statusBarHeight);
//action bar height
statusBar.getLayoutParams().height = statusBarHeight;
statusBar.setBackgroundColor(color);
}
} | [
"public",
"void",
"setStatusBarColor",
"(",
"View",
"statusBar",
",",
"int",
"color",
")",
"{",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"KITKAT",
")",
"{",
"Window",
"w",
"=",
"getWindow",
"(",
")",
";",
"w",
".",
"setFlags",
"(",
"WindowManager",
".",
"LayoutParams",
".",
"FLAG_TRANSLUCENT_STATUS",
",",
"WindowManager",
".",
"LayoutParams",
".",
"FLAG_TRANSLUCENT_STATUS",
")",
";",
"//status bar height",
"int",
"actionBarHeight",
"=",
"getActionBarHeight",
"(",
")",
";",
"int",
"statusBarHeight",
"=",
"getStatusBarHeight",
"(",
")",
";",
"// System.out.println(\"actionBarHeight:\" + actionBarHeight);",
"// System.out.println(\"statusBarHeight:\" + statusBarHeight);",
"//action bar height",
"statusBar",
".",
"getLayoutParams",
"(",
")",
".",
"height",
"=",
"statusBarHeight",
";",
"statusBar",
".",
"setBackgroundColor",
"(",
"color",
")",
";",
"}",
"}"
] | only work for >=19 | [
"only",
"work",
"for",
">",
"=",
"19"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/sample/src/main/java/com/viewpagerindicator/as/sample/ListSamples.java#L132-L145 |
2,216 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java | RecyclerTitlePageIndicator.clipViewOnTheRight | private void clipViewOnTheRight(Rect curViewBound, float curViewWidth, int right) {
curViewBound.right = (int) (right - mClipPadding);
curViewBound.left = (int) (curViewBound.right - curViewWidth);
} | java | private void clipViewOnTheRight(Rect curViewBound, float curViewWidth, int right) {
curViewBound.right = (int) (right - mClipPadding);
curViewBound.left = (int) (curViewBound.right - curViewWidth);
} | [
"private",
"void",
"clipViewOnTheRight",
"(",
"Rect",
"curViewBound",
",",
"float",
"curViewWidth",
",",
"int",
"right",
")",
"{",
"curViewBound",
".",
"right",
"=",
"(",
"int",
")",
"(",
"right",
"-",
"mClipPadding",
")",
";",
"curViewBound",
".",
"left",
"=",
"(",
"int",
")",
"(",
"curViewBound",
".",
"right",
"-",
"curViewWidth",
")",
";",
"}"
] | Set bounds for the right textView including clip padding.
@param curViewBound
current bounds.
@param curViewWidth
width of the view. | [
"Set",
"bounds",
"for",
"the",
"right",
"textView",
"including",
"clip",
"padding",
"."
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java#L647-L650 |
2,217 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java | RecyclerTitlePageIndicator.clipViewOnTheLeft | private void clipViewOnTheLeft(Rect curViewBound, float curViewWidth, int left) {
curViewBound.left = (int) (left + mClipPadding);
curViewBound.right = (int) (mClipPadding + curViewWidth);
} | java | private void clipViewOnTheLeft(Rect curViewBound, float curViewWidth, int left) {
curViewBound.left = (int) (left + mClipPadding);
curViewBound.right = (int) (mClipPadding + curViewWidth);
} | [
"private",
"void",
"clipViewOnTheLeft",
"(",
"Rect",
"curViewBound",
",",
"float",
"curViewWidth",
",",
"int",
"left",
")",
"{",
"curViewBound",
".",
"left",
"=",
"(",
"int",
")",
"(",
"left",
"+",
"mClipPadding",
")",
";",
"curViewBound",
".",
"right",
"=",
"(",
"int",
")",
"(",
"mClipPadding",
"+",
"curViewWidth",
")",
";",
"}"
] | Set bounds for the left textView including clip padding.
@param curViewBound
current bounds.
@param curViewWidth
width of the view. | [
"Set",
"bounds",
"for",
"the",
"left",
"textView",
"including",
"clip",
"padding",
"."
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java#L660-L663 |
2,218 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java | RecyclerTitlePageIndicator.calculateAllBounds | private ArrayList<Rect> calculateAllBounds(Paint paint) {
ArrayList<Rect> list = new ArrayList<Rect>();
//For each views (If no values then add a fake one)
final int count = mRecyclerView.getAdapter().getItemCount();
final int width = getWidth();
final int halfWidth = width / 2;
for (int i = 0; i < count; i++) {
Rect bounds = calcBounds(i, paint);
int w = bounds.right - bounds.left;
int h = bounds.bottom - bounds.top;
bounds.left = (int)(halfWidth - (w / 2f) + ((i - mCurrentPage - mPageOffset) * width));
bounds.right = bounds.left + w;
bounds.top = 0;
bounds.bottom = h;
list.add(bounds);
}
return list;
} | java | private ArrayList<Rect> calculateAllBounds(Paint paint) {
ArrayList<Rect> list = new ArrayList<Rect>();
//For each views (If no values then add a fake one)
final int count = mRecyclerView.getAdapter().getItemCount();
final int width = getWidth();
final int halfWidth = width / 2;
for (int i = 0; i < count; i++) {
Rect bounds = calcBounds(i, paint);
int w = bounds.right - bounds.left;
int h = bounds.bottom - bounds.top;
bounds.left = (int)(halfWidth - (w / 2f) + ((i - mCurrentPage - mPageOffset) * width));
bounds.right = bounds.left + w;
bounds.top = 0;
bounds.bottom = h;
list.add(bounds);
}
return list;
} | [
"private",
"ArrayList",
"<",
"Rect",
">",
"calculateAllBounds",
"(",
"Paint",
"paint",
")",
"{",
"ArrayList",
"<",
"Rect",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"Rect",
">",
"(",
")",
";",
"//For each views (If no values then add a fake one)",
"final",
"int",
"count",
"=",
"mRecyclerView",
".",
"getAdapter",
"(",
")",
".",
"getItemCount",
"(",
")",
";",
"final",
"int",
"width",
"=",
"getWidth",
"(",
")",
";",
"final",
"int",
"halfWidth",
"=",
"width",
"/",
"2",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"Rect",
"bounds",
"=",
"calcBounds",
"(",
"i",
",",
"paint",
")",
";",
"int",
"w",
"=",
"bounds",
".",
"right",
"-",
"bounds",
".",
"left",
";",
"int",
"h",
"=",
"bounds",
".",
"bottom",
"-",
"bounds",
".",
"top",
";",
"bounds",
".",
"left",
"=",
"(",
"int",
")",
"(",
"halfWidth",
"-",
"(",
"w",
"/",
"2f",
")",
"+",
"(",
"(",
"i",
"-",
"mCurrentPage",
"-",
"mPageOffset",
")",
"*",
"width",
")",
")",
";",
"bounds",
".",
"right",
"=",
"bounds",
".",
"left",
"+",
"w",
";",
"bounds",
".",
"top",
"=",
"0",
";",
"bounds",
".",
"bottom",
"=",
"h",
";",
"list",
".",
"add",
"(",
"bounds",
")",
";",
"}",
"return",
"list",
";",
"}"
] | Calculate views bounds and scroll them according to the current index
@param paint
@return | [
"Calculate",
"views",
"bounds",
"and",
"scroll",
"them",
"according",
"to",
"the",
"current",
"index"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java#L671-L689 |
2,219 | buyi/RecyclerViewPagerIndicator | recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java | RecyclerTitlePageIndicator.calcBounds | private Rect calcBounds(int index, Paint paint) {
//Calculate the text bounds
Rect bounds = new Rect();
CharSequence title = getTitle(index);
bounds.right = (int) paint.measureText(title, 0, title.length());
bounds.bottom = (int) (paint.descent() - paint.ascent());
return bounds;
} | java | private Rect calcBounds(int index, Paint paint) {
//Calculate the text bounds
Rect bounds = new Rect();
CharSequence title = getTitle(index);
bounds.right = (int) paint.measureText(title, 0, title.length());
bounds.bottom = (int) (paint.descent() - paint.ascent());
return bounds;
} | [
"private",
"Rect",
"calcBounds",
"(",
"int",
"index",
",",
"Paint",
"paint",
")",
"{",
"//Calculate the text bounds",
"Rect",
"bounds",
"=",
"new",
"Rect",
"(",
")",
";",
"CharSequence",
"title",
"=",
"getTitle",
"(",
"index",
")",
";",
"bounds",
".",
"right",
"=",
"(",
"int",
")",
"paint",
".",
"measureText",
"(",
"title",
",",
"0",
",",
"title",
".",
"length",
"(",
")",
")",
";",
"bounds",
".",
"bottom",
"=",
"(",
"int",
")",
"(",
"paint",
".",
"descent",
"(",
")",
"-",
"paint",
".",
"ascent",
"(",
")",
")",
";",
"return",
"bounds",
";",
"}"
] | Calculate the bounds for a view's title
@param index
@param paint
@return | [
"Calculate",
"the",
"bounds",
"for",
"a",
"view",
"s",
"title"
] | b3b5283801b60d40f7325c7f590c945262194fad | https://github.com/buyi/RecyclerViewPagerIndicator/blob/b3b5283801b60d40f7325c7f590c945262194fad/recycler-viewpager-indicator/src/main/java/com/viewpagerindicator/as/library/indicator/RecyclerTitlePageIndicator.java#L698-L705 |
2,220 | sniffy/sniffy | sniffy-core/src/main/java/io/sniffy/Sniffy.java | Sniffy.initialize | public static void initialize() {
if (initialized) return;
SniffyConfiguration.INSTANCE.addTopSqlCapacityListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
ConcurrentLinkedHashMap<String, Timer> oldValues = globalSqlStats;
globalSqlStats =
new ConcurrentLinkedHashMap.Builder<String, Timer>().
maximumWeightedCapacity(SniffyConfiguration.INSTANCE.getTopSqlCapacity()).
build();
globalSqlStats.putAll(oldValues);
}
});
if (SniffyConfiguration.INSTANCE.isMonitorSocket()) {
try {
SnifferSocketImplFactory.install();
} catch (IOException e) {
e.printStackTrace();
}
} else {
SniffyConfiguration.INSTANCE.addMonitorSocketListener(new PropertyChangeListener() {
private boolean sniffySocketImplFactoryInstalled = false;
@Override
public synchronized void propertyChange(PropertyChangeEvent evt) {
if (sniffySocketImplFactoryInstalled) return;
if (Boolean.TRUE.equals(evt.getNewValue())) {
try {
SnifferSocketImplFactory.install();
sniffySocketImplFactoryInstalled = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
initialized = true;
} | java | public static void initialize() {
if (initialized) return;
SniffyConfiguration.INSTANCE.addTopSqlCapacityListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
ConcurrentLinkedHashMap<String, Timer> oldValues = globalSqlStats;
globalSqlStats =
new ConcurrentLinkedHashMap.Builder<String, Timer>().
maximumWeightedCapacity(SniffyConfiguration.INSTANCE.getTopSqlCapacity()).
build();
globalSqlStats.putAll(oldValues);
}
});
if (SniffyConfiguration.INSTANCE.isMonitorSocket()) {
try {
SnifferSocketImplFactory.install();
} catch (IOException e) {
e.printStackTrace();
}
} else {
SniffyConfiguration.INSTANCE.addMonitorSocketListener(new PropertyChangeListener() {
private boolean sniffySocketImplFactoryInstalled = false;
@Override
public synchronized void propertyChange(PropertyChangeEvent evt) {
if (sniffySocketImplFactoryInstalled) return;
if (Boolean.TRUE.equals(evt.getNewValue())) {
try {
SnifferSocketImplFactory.install();
sniffySocketImplFactoryInstalled = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
initialized = true;
} | [
"public",
"static",
"void",
"initialize",
"(",
")",
"{",
"if",
"(",
"initialized",
")",
"return",
";",
"SniffyConfiguration",
".",
"INSTANCE",
".",
"addTopSqlCapacityListener",
"(",
"new",
"PropertyChangeListener",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"propertyChange",
"(",
"PropertyChangeEvent",
"evt",
")",
"{",
"ConcurrentLinkedHashMap",
"<",
"String",
",",
"Timer",
">",
"oldValues",
"=",
"globalSqlStats",
";",
"globalSqlStats",
"=",
"new",
"ConcurrentLinkedHashMap",
".",
"Builder",
"<",
"String",
",",
"Timer",
">",
"(",
")",
".",
"maximumWeightedCapacity",
"(",
"SniffyConfiguration",
".",
"INSTANCE",
".",
"getTopSqlCapacity",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"globalSqlStats",
".",
"putAll",
"(",
"oldValues",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"SniffyConfiguration",
".",
"INSTANCE",
".",
"isMonitorSocket",
"(",
")",
")",
"{",
"try",
"{",
"SnifferSocketImplFactory",
".",
"install",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"else",
"{",
"SniffyConfiguration",
".",
"INSTANCE",
".",
"addMonitorSocketListener",
"(",
"new",
"PropertyChangeListener",
"(",
")",
"{",
"private",
"boolean",
"sniffySocketImplFactoryInstalled",
"=",
"false",
";",
"@",
"Override",
"public",
"synchronized",
"void",
"propertyChange",
"(",
"PropertyChangeEvent",
"evt",
")",
"{",
"if",
"(",
"sniffySocketImplFactoryInstalled",
")",
"return",
";",
"if",
"(",
"Boolean",
".",
"TRUE",
".",
"equals",
"(",
"evt",
".",
"getNewValue",
"(",
")",
")",
")",
"{",
"try",
"{",
"SnifferSocketImplFactory",
".",
"install",
"(",
")",
";",
"sniffySocketImplFactoryInstalled",
"=",
"true",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}",
"initialized",
"=",
"true",
";",
"}"
] | If socket monitoring is already enabled it cannot be disabled afterwards
Otherwise one webapp would enable it but another one would disable | [
"If",
"socket",
"monitoring",
"is",
"already",
"enabled",
"it",
"cannot",
"be",
"disabled",
"afterwards",
"Otherwise",
"one",
"webapp",
"would",
"enable",
"it",
"but",
"another",
"one",
"would",
"disable"
] | 7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0 | https://github.com/sniffy/sniffy/blob/7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0/sniffy-core/src/main/java/io/sniffy/Sniffy.java#L66-L118 |
2,221 | sniffy/sniffy | sniffy-web/src/main/java/io/sniffy/servlet/Buffer.java | Buffer.grow | private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = buf.length;
int newCapacity = oldCapacity << 1;
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity < 0) {
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
newCapacity = Integer.MAX_VALUE;
}
buf = copyOf(buf, newCapacity);
} | java | private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = buf.length;
int newCapacity = oldCapacity << 1;
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity < 0) {
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
newCapacity = Integer.MAX_VALUE;
}
buf = copyOf(buf, newCapacity);
} | [
"private",
"void",
"grow",
"(",
"int",
"minCapacity",
")",
"{",
"// overflow-conscious code",
"int",
"oldCapacity",
"=",
"buf",
".",
"length",
";",
"int",
"newCapacity",
"=",
"oldCapacity",
"<<",
"1",
";",
"if",
"(",
"newCapacity",
"-",
"minCapacity",
"<",
"0",
")",
"newCapacity",
"=",
"minCapacity",
";",
"if",
"(",
"newCapacity",
"<",
"0",
")",
"{",
"if",
"(",
"minCapacity",
"<",
"0",
")",
"// overflow",
"throw",
"new",
"OutOfMemoryError",
"(",
")",
";",
"newCapacity",
"=",
"Integer",
".",
"MAX_VALUE",
";",
"}",
"buf",
"=",
"copyOf",
"(",
"buf",
",",
"newCapacity",
")",
";",
"}"
] | Increases the capacity to ensure that it can hold at least the
number of elements specified by the minimum capacity argument.
@param minCapacity the desired minimum capacity | [
"Increases",
"the",
"capacity",
"to",
"ensure",
"that",
"it",
"can",
"hold",
"at",
"least",
"the",
"number",
"of",
"elements",
"specified",
"by",
"the",
"minimum",
"capacity",
"argument",
"."
] | 7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0 | https://github.com/sniffy/sniffy/blob/7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0/sniffy-web/src/main/java/io/sniffy/servlet/Buffer.java#L57-L69 |
2,222 | sniffy/sniffy | sniffy-web/src/main/java/io/sniffy/servlet/BufferedServletResponseWrapper.java | BufferedServletResponseWrapper.flushIfPossible | protected void flushIfPossible() throws IOException {
// TODO: do not flush if wasn't requested by underlying application
if (null != bufferedServletOutputStream) bufferedServletOutputStream.setLastChunk();
if (null != writer) writer.flushIfOpen();
else if (null != outputStream) outputStream.flushIfOpen();
else {
if (!isCommitted()) {
notifyBeforeCommit();
}
notifyBeforeClose();
}
} | java | protected void flushIfPossible() throws IOException {
// TODO: do not flush if wasn't requested by underlying application
if (null != bufferedServletOutputStream) bufferedServletOutputStream.setLastChunk();
if (null != writer) writer.flushIfOpen();
else if (null != outputStream) outputStream.flushIfOpen();
else {
if (!isCommitted()) {
notifyBeforeCommit();
}
notifyBeforeClose();
}
} | [
"protected",
"void",
"flushIfPossible",
"(",
")",
"throws",
"IOException",
"{",
"// TODO: do not flush if wasn't requested by underlying application",
"if",
"(",
"null",
"!=",
"bufferedServletOutputStream",
")",
"bufferedServletOutputStream",
".",
"setLastChunk",
"(",
")",
";",
"if",
"(",
"null",
"!=",
"writer",
")",
"writer",
".",
"flushIfOpen",
"(",
")",
";",
"else",
"if",
"(",
"null",
"!=",
"outputStream",
")",
"outputStream",
".",
"flushIfOpen",
"(",
")",
";",
"else",
"{",
"if",
"(",
"!",
"isCommitted",
"(",
")",
")",
"{",
"notifyBeforeCommit",
"(",
")",
";",
"}",
"notifyBeforeClose",
"(",
")",
";",
"}",
"}"
] | Flush the sniffer buffer and append the information about the executed queries to the output stream
@throws IOException | [
"Flush",
"the",
"sniffer",
"buffer",
"and",
"append",
"the",
"information",
"about",
"the",
"executed",
"queries",
"to",
"the",
"output",
"stream"
] | 7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0 | https://github.com/sniffy/sniffy/blob/7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0/sniffy-web/src/main/java/io/sniffy/servlet/BufferedServletResponseWrapper.java#L84-L97 |
2,223 | sniffy/sniffy | sniffy-web/src/main/java/io/sniffy/servlet/BufferedServletResponseWrapper.java | BufferedServletResponseWrapper.sendError | @Override
public void sendError(int sc, String msg) throws IOException {
if (isCommitted()) {
throw new IllegalStateException("Cannot set error status - response is already committed");
}
notifyBeforeCommit();
super.sendError(sc, msg);
setCommitted();
} | java | @Override
public void sendError(int sc, String msg) throws IOException {
if (isCommitted()) {
throw new IllegalStateException("Cannot set error status - response is already committed");
}
notifyBeforeCommit();
super.sendError(sc, msg);
setCommitted();
} | [
"@",
"Override",
"public",
"void",
"sendError",
"(",
"int",
"sc",
",",
"String",
"msg",
")",
"throws",
"IOException",
"{",
"if",
"(",
"isCommitted",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Cannot set error status - response is already committed\"",
")",
";",
"}",
"notifyBeforeCommit",
"(",
")",
";",
"super",
".",
"sendError",
"(",
"sc",
",",
"msg",
")",
";",
"setCommitted",
"(",
")",
";",
"}"
] | headers relates methods | [
"headers",
"relates",
"methods"
] | 7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0 | https://github.com/sniffy/sniffy/blob/7bdddb9593e6b6e9fe5c7c87519f864acbc3a5c0/sniffy-web/src/main/java/io/sniffy/servlet/BufferedServletResponseWrapper.java#L215-L223 |
2,224 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/evaluation/DefaultXPathEvaluator.java | DefaultXPathEvaluator.asArrayOf | @SuppressWarnings("unchecked")
@Override
public <T> T[] asArrayOf(final Class<T> componentType) {
Class<?> callerClass = ReflectionHelper.getDirectCallerClass();
List<T> list = evaluateMultiValues(componentType, callerClass);
return list.toArray((T[]) java.lang.reflect.Array.newInstance(componentType, list.size()));
} | java | @SuppressWarnings("unchecked")
@Override
public <T> T[] asArrayOf(final Class<T> componentType) {
Class<?> callerClass = ReflectionHelper.getDirectCallerClass();
List<T> list = evaluateMultiValues(componentType, callerClass);
return list.toArray((T[]) java.lang.reflect.Array.newInstance(componentType, list.size()));
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"[",
"]",
"asArrayOf",
"(",
"final",
"Class",
"<",
"T",
">",
"componentType",
")",
"{",
"Class",
"<",
"?",
">",
"callerClass",
"=",
"ReflectionHelper",
".",
"getDirectCallerClass",
"(",
")",
";",
"List",
"<",
"T",
">",
"list",
"=",
"evaluateMultiValues",
"(",
"componentType",
",",
"callerClass",
")",
";",
"return",
"list",
".",
"toArray",
"(",
"(",
"T",
"[",
"]",
")",
"java",
".",
"lang",
".",
"reflect",
".",
"Array",
".",
"newInstance",
"(",
"componentType",
",",
"list",
".",
"size",
"(",
")",
")",
")",
";",
"}"
] | Evaluate the XPath as an array of the given type.
@param componentType
Possible values: primitive types (e.g. Short.Type), Projection interfaces, any
class with a String constructor or a String factory method, and org.w3c.Node
@return an array of return type that reflects the evaluation result. | [
"Evaluate",
"the",
"XPath",
"as",
"an",
"array",
"of",
"the",
"given",
"type",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/evaluation/DefaultXPathEvaluator.java#L196-L202 |
2,225 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/evaluation/DefaultXPathEvaluator.java | DefaultXPathEvaluator.evaluateAsList | public static List<?> evaluateAsList(final XPathExpression expression, final Node node, final Method method, final InvocationContext invocationContext) throws XPathExpressionException {
//assert targetComponentType != null;
final Class<?> targetComponentType = invocationContext.getTargetComponentType();
final NodeList nodes = (NodeList) expression.evaluate(node, XPathConstants.NODESET);
final List<Object> linkedList = new LinkedList<Object>();
final TypeConverter typeConverter = invocationContext.getProjector().config().getTypeConverter();
if (typeConverter.isConvertable(targetComponentType)) {
for (int i = 0; i < nodes.getLength(); ++i) {
linkedList.add(typeConverter.convertTo(targetComponentType, nodes.item(i).getTextContent(), invocationContext.getExpressionFormatPattern()));
}
return linkedList;
}
if (Node.class.equals(targetComponentType)) {
for (int i = 0; i < nodes.getLength(); ++i) {
linkedList.add(nodes.item(i));
}
return linkedList;
}
if (targetComponentType.isInterface()) {
for (int i = 0; i < nodes.getLength(); ++i) {
Object subprojection = invocationContext.getProjector().projectDOMNode(nodes.item(i), targetComponentType);
linkedList.add(subprojection);
}
return linkedList;
}
throw new IllegalArgumentException("Return type " + targetComponentType + " is not valid for list or array component type returning from method " + method + " using the current type converter:" + invocationContext.getProjector().config().getTypeConverter()
+ ". Please change the return type to a sub projection or add a conversion to the type converter.");
} | java | public static List<?> evaluateAsList(final XPathExpression expression, final Node node, final Method method, final InvocationContext invocationContext) throws XPathExpressionException {
//assert targetComponentType != null;
final Class<?> targetComponentType = invocationContext.getTargetComponentType();
final NodeList nodes = (NodeList) expression.evaluate(node, XPathConstants.NODESET);
final List<Object> linkedList = new LinkedList<Object>();
final TypeConverter typeConverter = invocationContext.getProjector().config().getTypeConverter();
if (typeConverter.isConvertable(targetComponentType)) {
for (int i = 0; i < nodes.getLength(); ++i) {
linkedList.add(typeConverter.convertTo(targetComponentType, nodes.item(i).getTextContent(), invocationContext.getExpressionFormatPattern()));
}
return linkedList;
}
if (Node.class.equals(targetComponentType)) {
for (int i = 0; i < nodes.getLength(); ++i) {
linkedList.add(nodes.item(i));
}
return linkedList;
}
if (targetComponentType.isInterface()) {
for (int i = 0; i < nodes.getLength(); ++i) {
Object subprojection = invocationContext.getProjector().projectDOMNode(nodes.item(i), targetComponentType);
linkedList.add(subprojection);
}
return linkedList;
}
throw new IllegalArgumentException("Return type " + targetComponentType + " is not valid for list or array component type returning from method " + method + " using the current type converter:" + invocationContext.getProjector().config().getTypeConverter()
+ ". Please change the return type to a sub projection or add a conversion to the type converter.");
} | [
"public",
"static",
"List",
"<",
"?",
">",
"evaluateAsList",
"(",
"final",
"XPathExpression",
"expression",
",",
"final",
"Node",
"node",
",",
"final",
"Method",
"method",
",",
"final",
"InvocationContext",
"invocationContext",
")",
"throws",
"XPathExpressionException",
"{",
"//assert targetComponentType != null;",
"final",
"Class",
"<",
"?",
">",
"targetComponentType",
"=",
"invocationContext",
".",
"getTargetComponentType",
"(",
")",
";",
"final",
"NodeList",
"nodes",
"=",
"(",
"NodeList",
")",
"expression",
".",
"evaluate",
"(",
"node",
",",
"XPathConstants",
".",
"NODESET",
")",
";",
"final",
"List",
"<",
"Object",
">",
"linkedList",
"=",
"new",
"LinkedList",
"<",
"Object",
">",
"(",
")",
";",
"final",
"TypeConverter",
"typeConverter",
"=",
"invocationContext",
".",
"getProjector",
"(",
")",
".",
"config",
"(",
")",
".",
"getTypeConverter",
"(",
")",
";",
"if",
"(",
"typeConverter",
".",
"isConvertable",
"(",
"targetComponentType",
")",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"getLength",
"(",
")",
";",
"++",
"i",
")",
"{",
"linkedList",
".",
"add",
"(",
"typeConverter",
".",
"convertTo",
"(",
"targetComponentType",
",",
"nodes",
".",
"item",
"(",
"i",
")",
".",
"getTextContent",
"(",
")",
",",
"invocationContext",
".",
"getExpressionFormatPattern",
"(",
")",
")",
")",
";",
"}",
"return",
"linkedList",
";",
"}",
"if",
"(",
"Node",
".",
"class",
".",
"equals",
"(",
"targetComponentType",
")",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"getLength",
"(",
")",
";",
"++",
"i",
")",
"{",
"linkedList",
".",
"add",
"(",
"nodes",
".",
"item",
"(",
"i",
")",
")",
";",
"}",
"return",
"linkedList",
";",
"}",
"if",
"(",
"targetComponentType",
".",
"isInterface",
"(",
")",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"getLength",
"(",
")",
";",
"++",
"i",
")",
"{",
"Object",
"subprojection",
"=",
"invocationContext",
".",
"getProjector",
"(",
")",
".",
"projectDOMNode",
"(",
"nodes",
".",
"item",
"(",
"i",
")",
",",
"targetComponentType",
")",
";",
"linkedList",
".",
"add",
"(",
"subprojection",
")",
";",
"}",
"return",
"linkedList",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Return type \"",
"+",
"targetComponentType",
"+",
"\" is not valid for list or array component type returning from method \"",
"+",
"method",
"+",
"\" using the current type converter:\"",
"+",
"invocationContext",
".",
"getProjector",
"(",
")",
".",
"config",
"(",
")",
".",
"getTypeConverter",
"(",
")",
"+",
"\". Please change the return type to a sub projection or add a conversion to the type converter.\"",
")",
";",
"}"
] | Perform an XPath evaluation on an invocation context.
@param expression
@param node
@param method
@param invocationContext
@return a list of evaluation results
@throws XPathExpressionException | [
"Perform",
"an",
"XPath",
"evaluation",
"on",
"an",
"invocation",
"context",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/evaluation/DefaultXPathEvaluator.java#L243-L271 |
2,226 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/XBProjector.java | XBProjector.checkProjectionInstance | private DOMAccess checkProjectionInstance(final Object projection) {
if (java.lang.reflect.Proxy.isProxyClass(projection.getClass())) {
InvocationHandler invocationHandler = java.lang.reflect.Proxy.getInvocationHandler(projection);
if (invocationHandler instanceof ProjectionInvocationHandler) {
if (projection instanceof DOMAccess) {
return (DOMAccess) projection;
}
}
}
throw new IllegalArgumentException("Given object " + projection + " is not a projection.");
} | java | private DOMAccess checkProjectionInstance(final Object projection) {
if (java.lang.reflect.Proxy.isProxyClass(projection.getClass())) {
InvocationHandler invocationHandler = java.lang.reflect.Proxy.getInvocationHandler(projection);
if (invocationHandler instanceof ProjectionInvocationHandler) {
if (projection instanceof DOMAccess) {
return (DOMAccess) projection;
}
}
}
throw new IllegalArgumentException("Given object " + projection + " is not a projection.");
} | [
"private",
"DOMAccess",
"checkProjectionInstance",
"(",
"final",
"Object",
"projection",
")",
"{",
"if",
"(",
"java",
".",
"lang",
".",
"reflect",
".",
"Proxy",
".",
"isProxyClass",
"(",
"projection",
".",
"getClass",
"(",
")",
")",
")",
"{",
"InvocationHandler",
"invocationHandler",
"=",
"java",
".",
"lang",
".",
"reflect",
".",
"Proxy",
".",
"getInvocationHandler",
"(",
"projection",
")",
";",
"if",
"(",
"invocationHandler",
"instanceof",
"ProjectionInvocationHandler",
")",
"{",
"if",
"(",
"projection",
"instanceof",
"DOMAccess",
")",
"{",
"return",
"(",
"DOMAccess",
")",
"projection",
";",
"}",
"}",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Given object \"",
"+",
"projection",
"+",
"\" is not a projection.\"",
")",
";",
"}"
] | Ensures that the given object is a projection created by a projector.
@param projection
@return | [
"Ensures",
"that",
"the",
"given",
"object",
"is",
"a",
"projection",
"created",
"by",
"a",
"projector",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/XBProjector.java#L647-L657 |
2,227 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/XBProjector.java | XBProjector.countTrue | private static int countTrue(final boolean... b) {
if (b == null) {
return 0;
}
int count = 0;
for (boolean bb : b) {
if (bb) {
++count;
}
}
return count;
} | java | private static int countTrue(final boolean... b) {
if (b == null) {
return 0;
}
int count = 0;
for (boolean bb : b) {
if (bb) {
++count;
}
}
return count;
} | [
"private",
"static",
"int",
"countTrue",
"(",
"final",
"boolean",
"...",
"b",
")",
"{",
"if",
"(",
"b",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"boolean",
"bb",
":",
"b",
")",
"{",
"if",
"(",
"bb",
")",
"{",
"++",
"count",
";",
"}",
"}",
"return",
"count",
";",
"}"
] | Count how many parameters are true.
@return number of true values in parameter list. | [
"Count",
"how",
"many",
"parameters",
"are",
"true",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/XBProjector.java#L743-L754 |
2,228 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/XBProjector.java | XBProjector.autoMapEmptyDocument | public <T> XBAutoMap<T> autoMapEmptyDocument(final Class<T> valueType) {
Document document = xMLFactoriesConfig.createDocumentBuilder().newDocument();
return createAutoMapForDocument(valueType, document);
} | java | public <T> XBAutoMap<T> autoMapEmptyDocument(final Class<T> valueType) {
Document document = xMLFactoriesConfig.createDocumentBuilder().newDocument();
return createAutoMapForDocument(valueType, document);
} | [
"public",
"<",
"T",
">",
"XBAutoMap",
"<",
"T",
">",
"autoMapEmptyDocument",
"(",
"final",
"Class",
"<",
"T",
">",
"valueType",
")",
"{",
"Document",
"document",
"=",
"xMLFactoriesConfig",
".",
"createDocumentBuilder",
"(",
")",
".",
"newDocument",
"(",
")",
";",
"return",
"createAutoMapForDocument",
"(",
"valueType",
",",
"document",
")",
";",
"}"
] | Create an empty document and bind an XBAutoMap to it.
@param valueType
component type of map
@return an empty Map view to the document | [
"Create",
"an",
"empty",
"document",
"and",
"bind",
"an",
"XBAutoMap",
"to",
"it",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/XBProjector.java#L825-L828 |
2,229 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/StreamInput.java | StreamInput.read | @Scope(DocScope.IO)
public <T> T read(final Class<T> projectionInterface) throws IOException {
Document document = readDocument();
return projector.projectDOMNode(document, projectionInterface);
} | java | @Scope(DocScope.IO)
public <T> T read(final Class<T> projectionInterface) throws IOException {
Document document = readDocument();
return projector.projectDOMNode(document, projectionInterface);
} | [
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"<",
"T",
">",
"T",
"read",
"(",
"final",
"Class",
"<",
"T",
">",
"projectionInterface",
")",
"throws",
"IOException",
"{",
"Document",
"document",
"=",
"readDocument",
"(",
")",
";",
"return",
"projector",
".",
"projectDOMNode",
"(",
"document",
",",
"projectionInterface",
")",
";",
"}"
] | Create a new projection by parsing the data provided by the input stream.
@param projectionInterface
A Java interface to project the data on.
@return a new projection instance pointing to the stream content.
@throws IOException | [
"Create",
"a",
"new",
"projection",
"by",
"parsing",
"the",
"data",
"provided",
"by",
"the",
"input",
"stream",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/StreamInput.java#L62-L66 |
2,230 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/duplex/DuplexExpression.java | DuplexExpression.getExpressionType | public ExpressionType getExpressionType() {
try { //TODO: cache expression type ?
final ExpressionType expressionType = node.firstChildAccept(new ExpressionTypeEvaluationVisitor(), null);
return expressionType;
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Please report this bug: Can not determine type of XPath:" + xpath, e);
}
} | java | public ExpressionType getExpressionType() {
try { //TODO: cache expression type ?
final ExpressionType expressionType = node.firstChildAccept(new ExpressionTypeEvaluationVisitor(), null);
return expressionType;
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Please report this bug: Can not determine type of XPath:" + xpath, e);
}
} | [
"public",
"ExpressionType",
"getExpressionType",
"(",
")",
"{",
"try",
"{",
"//TODO: cache expression type ?",
"final",
"ExpressionType",
"expressionType",
"=",
"node",
".",
"firstChildAccept",
"(",
"new",
"ExpressionTypeEvaluationVisitor",
"(",
")",
",",
"null",
")",
";",
"return",
"expressionType",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Please report this bug: Can not determine type of XPath:\"",
"+",
"xpath",
",",
"e",
")",
";",
"}",
"}"
] | Calculates the return type of the expression.
@return ExpressionType | [
"Calculates",
"the",
"return",
"type",
"of",
"the",
"expression",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/duplex/DuplexExpression.java#L169-L176 |
2,231 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/duplex/DuplexExpression.java | DuplexExpression.ensureExistence | @SuppressWarnings("unchecked")
public org.w3c.dom.Node ensureExistence(final org.w3c.dom.Node contextNode) {
final Document document = DOMHelper.getOwnerDocumentFor(contextNode);
final Map<String, String> namespaceMapping = new HashMap<String, String>(userDefinedMapping);
namespaceMapping.putAll(DOMHelper.getNamespaceMapping(document));
//node.dump("");
return ((List<org.w3c.dom.Node>) node.firstChildAccept(new BuildDocumentVisitor(variableResolver, namespaceMapping), contextNode)).get(0);
} | java | @SuppressWarnings("unchecked")
public org.w3c.dom.Node ensureExistence(final org.w3c.dom.Node contextNode) {
final Document document = DOMHelper.getOwnerDocumentFor(contextNode);
final Map<String, String> namespaceMapping = new HashMap<String, String>(userDefinedMapping);
namespaceMapping.putAll(DOMHelper.getNamespaceMapping(document));
//node.dump("");
return ((List<org.w3c.dom.Node>) node.firstChildAccept(new BuildDocumentVisitor(variableResolver, namespaceMapping), contextNode)).get(0);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"org",
".",
"w3c",
".",
"dom",
".",
"Node",
"ensureExistence",
"(",
"final",
"org",
".",
"w3c",
".",
"dom",
".",
"Node",
"contextNode",
")",
"{",
"final",
"Document",
"document",
"=",
"DOMHelper",
".",
"getOwnerDocumentFor",
"(",
"contextNode",
")",
";",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"namespaceMapping",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
"userDefinedMapping",
")",
";",
"namespaceMapping",
".",
"putAll",
"(",
"DOMHelper",
".",
"getNamespaceMapping",
"(",
"document",
")",
")",
";",
"//node.dump(\"\");",
"return",
"(",
"(",
"List",
"<",
"org",
".",
"w3c",
".",
"dom",
".",
"Node",
">",
")",
"node",
".",
"firstChildAccept",
"(",
"new",
"BuildDocumentVisitor",
"(",
"variableResolver",
",",
"namespaceMapping",
")",
",",
"contextNode",
")",
")",
".",
"get",
"(",
"0",
")",
";",
"}"
] | Creates nodes until selecting such a path would return something.
@param contextNode
@return the node that this expression would select. | [
"Creates",
"nodes",
"until",
"selecting",
"such",
"a",
"path",
"would",
"return",
"something",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/duplex/DuplexExpression.java#L184-L191 |
2,232 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/UrlIO.java | UrlIO.write | @SuppressWarnings("unchecked")
@Scope(DocScope.IO)
public String write(final Object projection) throws IOException {
return IOHelper.inputStreamToString(IOHelper.httpPost(url, projection.toString(), requestProperties));
} | java | @SuppressWarnings("unchecked")
@Scope(DocScope.IO)
public String write(final Object projection) throws IOException {
return IOHelper.inputStreamToString(IOHelper.httpPost(url, projection.toString(), requestProperties));
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"String",
"write",
"(",
"final",
"Object",
"projection",
")",
"throws",
"IOException",
"{",
"return",
"IOHelper",
".",
"inputStreamToString",
"(",
"IOHelper",
".",
"httpPost",
"(",
"url",
",",
"projection",
".",
"toString",
"(",
")",
",",
"requestProperties",
")",
")",
";",
"}"
] | Post the projected document to a HTTP URL. The response is provided as a raw string.
@param projection
@return response as String
@throws IOException | [
"Post",
"the",
"projected",
"document",
"to",
"a",
"HTTP",
"URL",
".",
"The",
"response",
"is",
"provided",
"as",
"a",
"raw",
"string",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/UrlIO.java#L86-L90 |
2,233 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/UrlIO.java | UrlIO.addRequestProperties | @Scope(DocScope.IO)
public UrlIO addRequestProperties(final Map<String, String> params) {
requestProperties.putAll(params);
return this;
} | java | @Scope(DocScope.IO)
public UrlIO addRequestProperties(final Map<String, String> params) {
requestProperties.putAll(params);
return this;
} | [
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"UrlIO",
"addRequestProperties",
"(",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"params",
")",
"{",
"requestProperties",
".",
"putAll",
"(",
"params",
")",
";",
"return",
"this",
";",
"}"
] | Allows to add some request properties.
@param params
@return this for convenience. | [
"Allows",
"to",
"add",
"some",
"request",
"properties",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/UrlIO.java#L98-L102 |
2,234 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/UrlIO.java | UrlIO.addRequestProperty | @Scope(DocScope.IO)
public UrlIO addRequestProperty(final String name, final String value) {
requestProperties.put(name, value);
return this;
} | java | @Scope(DocScope.IO)
public UrlIO addRequestProperty(final String name, final String value) {
requestProperties.put(name, value);
return this;
} | [
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"UrlIO",
"addRequestProperty",
"(",
"final",
"String",
"name",
",",
"final",
"String",
"value",
")",
"{",
"requestProperties",
".",
"put",
"(",
"name",
",",
"value",
")",
";",
"return",
"this",
";",
"}"
] | Allows to add a single request property.
@param name
@param value
@return this for convenience. | [
"Allows",
"to",
"add",
"a",
"single",
"request",
"property",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/UrlIO.java#L111-L115 |
2,235 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/UrlIO.java | UrlIO.evalXPath | @Override
@Scope(DocScope.IO)
public XPathEvaluator evalXPath(final String xpath) {
return new DefaultXPathEvaluator(projector, new DocumentResolver() {
@Override
public Document resolve(final Class<?>... resourceAwareClasses) throws IOException {
return IOHelper.getDocumentFromURL(projector.config().createDocumentBuilder(), url, requestProperties, resourceAwareClasses);
}
}, xpath);
} | java | @Override
@Scope(DocScope.IO)
public XPathEvaluator evalXPath(final String xpath) {
return new DefaultXPathEvaluator(projector, new DocumentResolver() {
@Override
public Document resolve(final Class<?>... resourceAwareClasses) throws IOException {
return IOHelper.getDocumentFromURL(projector.config().createDocumentBuilder(), url, requestProperties, resourceAwareClasses);
}
}, xpath);
} | [
"@",
"Override",
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"XPathEvaluator",
"evalXPath",
"(",
"final",
"String",
"xpath",
")",
"{",
"return",
"new",
"DefaultXPathEvaluator",
"(",
"projector",
",",
"new",
"DocumentResolver",
"(",
")",
"{",
"@",
"Override",
"public",
"Document",
"resolve",
"(",
"final",
"Class",
"<",
"?",
">",
"...",
"resourceAwareClasses",
")",
"throws",
"IOException",
"{",
"return",
"IOHelper",
".",
"getDocumentFromURL",
"(",
"projector",
".",
"config",
"(",
")",
".",
"createDocumentBuilder",
"(",
")",
",",
"url",
",",
"requestProperties",
",",
"resourceAwareClasses",
")",
";",
"}",
"}",
",",
"xpath",
")",
";",
"}"
] | Evaluate XPath on the url document.
@param xpath
@return xpath evaluator
@see org.xmlbeam.evaluation.CanEvaluate#evalXPath(java.lang.String) | [
"Evaluate",
"XPath",
"on",
"the",
"url",
"document",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/UrlIO.java#L124-L133 |
2,236 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/io/UrlIO.java | UrlIO.readAsMapOf | @Scope(DocScope.IO)
public <T> XBAutoMap<T> readAsMapOf(final Class<T> valueType) throws IOException {
DefaultXPathBinder.validateEvaluationType(valueType);
final Class<?> resourceAwareClass = ReflectionHelper.getDirectCallerClass();
Document document = IOHelper.getDocumentFromURL(projector.config().createDocumentBuilder(), url, requestProperties, resourceAwareClass);
InvocationContext invocationContext = new InvocationContext(null, null, null, null, null, valueType, projector);
return new AutoMap<T>(document, invocationContext, valueType);
} | java | @Scope(DocScope.IO)
public <T> XBAutoMap<T> readAsMapOf(final Class<T> valueType) throws IOException {
DefaultXPathBinder.validateEvaluationType(valueType);
final Class<?> resourceAwareClass = ReflectionHelper.getDirectCallerClass();
Document document = IOHelper.getDocumentFromURL(projector.config().createDocumentBuilder(), url, requestProperties, resourceAwareClass);
InvocationContext invocationContext = new InvocationContext(null, null, null, null, null, valueType, projector);
return new AutoMap<T>(document, invocationContext, valueType);
} | [
"@",
"Scope",
"(",
"DocScope",
".",
"IO",
")",
"public",
"<",
"T",
">",
"XBAutoMap",
"<",
"T",
">",
"readAsMapOf",
"(",
"final",
"Class",
"<",
"T",
">",
"valueType",
")",
"throws",
"IOException",
"{",
"DefaultXPathBinder",
".",
"validateEvaluationType",
"(",
"valueType",
")",
";",
"final",
"Class",
"<",
"?",
">",
"resourceAwareClass",
"=",
"ReflectionHelper",
".",
"getDirectCallerClass",
"(",
")",
";",
"Document",
"document",
"=",
"IOHelper",
".",
"getDocumentFromURL",
"(",
"projector",
".",
"config",
"(",
")",
".",
"createDocumentBuilder",
"(",
")",
",",
"url",
",",
"requestProperties",
",",
"resourceAwareClass",
")",
";",
"InvocationContext",
"invocationContext",
"=",
"new",
"InvocationContext",
"(",
"null",
",",
"null",
",",
"null",
",",
"null",
",",
"null",
",",
"valueType",
",",
"projector",
")",
";",
"return",
"new",
"AutoMap",
"<",
"T",
">",
"(",
"document",
",",
"invocationContext",
",",
"valueType",
")",
";",
"}"
] | Read complete document to a Map.
@param valueType
@return Closeable map bound to complete document.
@throws IOException | [
"Read",
"complete",
"document",
"to",
"a",
"Map",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/io/UrlIO.java#L142-L149 |
2,237 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/ProjectionInvocationHandler.java | ProjectionInvocationHandler.unwrapArgs | private static void unwrapArgs(final Class<?>[] types, final Object[] args) {
if (args == null) {
return;
}
try {
for (int i = 0; i < args.length; ++i) {
args[i] = ReflectionHelper.unwrap(types[i], args[i]);
}
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
} | java | private static void unwrapArgs(final Class<?>[] types, final Object[] args) {
if (args == null) {
return;
}
try {
for (int i = 0; i < args.length; ++i) {
args[i] = ReflectionHelper.unwrap(types[i], args[i]);
}
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
} | [
"private",
"static",
"void",
"unwrapArgs",
"(",
"final",
"Class",
"<",
"?",
">",
"[",
"]",
"types",
",",
"final",
"Object",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"args",
"==",
"null",
")",
"{",
"return",
";",
"}",
"try",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"++",
"i",
")",
"{",
"args",
"[",
"i",
"]",
"=",
"ReflectionHelper",
".",
"unwrap",
"(",
"types",
"[",
"i",
"]",
",",
"args",
"[",
"i",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"e",
")",
";",
"}",
"}"
] | If parameter is instance of Callable or Supplier then resolve its value.
@param args
@param args2 | [
"If",
"parameter",
"is",
"instance",
"of",
"Callable",
"or",
"Supplier",
"then",
"resolve",
"its",
"value",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/ProjectionInvocationHandler.java#L893-L905 |
2,238 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/ProjectionInvocationHandler.java | ProjectionInvocationHandler.findTargetComponentType | private static Class<?> findTargetComponentType(final Method method) {
final Class<?> returnType = method.getReturnType();
if (returnType.isArray()) {
return method.getReturnType().getComponentType();
}
if (!(List.class.equals(returnType) || (Map.class.equals(returnType)) || XBAutoMap.class.isAssignableFrom(returnType) || XBAutoList.class.equals(returnType) || XBAutoValue.class.equals(returnType) || ReflectionHelper.isStreamClass(returnType))) {
return null;
}
final Type type = method.getGenericReturnType();
if (!(type instanceof ParameterizedType) || (((ParameterizedType) type).getActualTypeArguments() == null) || (((ParameterizedType) type).getActualTypeArguments().length < 1)) {
throw new IllegalArgumentException("When using List as return type for method " + method + ", please specify a generic type for the List. Otherwise I do not know which type I should fill the List with.");
}
int index = Map.class.equals(returnType) ? 1 : 0;
assert index < ((ParameterizedType) type).getActualTypeArguments().length;
Type componentType = ((ParameterizedType) type).getActualTypeArguments()[index];
if (!(componentType instanceof Class)) {
throw new IllegalArgumentException("I don't know how to instantiate the generic type for the return type of method " + method);
}
return (Class<?>) componentType;
} | java | private static Class<?> findTargetComponentType(final Method method) {
final Class<?> returnType = method.getReturnType();
if (returnType.isArray()) {
return method.getReturnType().getComponentType();
}
if (!(List.class.equals(returnType) || (Map.class.equals(returnType)) || XBAutoMap.class.isAssignableFrom(returnType) || XBAutoList.class.equals(returnType) || XBAutoValue.class.equals(returnType) || ReflectionHelper.isStreamClass(returnType))) {
return null;
}
final Type type = method.getGenericReturnType();
if (!(type instanceof ParameterizedType) || (((ParameterizedType) type).getActualTypeArguments() == null) || (((ParameterizedType) type).getActualTypeArguments().length < 1)) {
throw new IllegalArgumentException("When using List as return type for method " + method + ", please specify a generic type for the List. Otherwise I do not know which type I should fill the List with.");
}
int index = Map.class.equals(returnType) ? 1 : 0;
assert index < ((ParameterizedType) type).getActualTypeArguments().length;
Type componentType = ((ParameterizedType) type).getActualTypeArguments()[index];
if (!(componentType instanceof Class)) {
throw new IllegalArgumentException("I don't know how to instantiate the generic type for the return type of method " + method);
}
return (Class<?>) componentType;
} | [
"private",
"static",
"Class",
"<",
"?",
">",
"findTargetComponentType",
"(",
"final",
"Method",
"method",
")",
"{",
"final",
"Class",
"<",
"?",
">",
"returnType",
"=",
"method",
".",
"getReturnType",
"(",
")",
";",
"if",
"(",
"returnType",
".",
"isArray",
"(",
")",
")",
"{",
"return",
"method",
".",
"getReturnType",
"(",
")",
".",
"getComponentType",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"List",
".",
"class",
".",
"equals",
"(",
"returnType",
")",
"||",
"(",
"Map",
".",
"class",
".",
"equals",
"(",
"returnType",
")",
")",
"||",
"XBAutoMap",
".",
"class",
".",
"isAssignableFrom",
"(",
"returnType",
")",
"||",
"XBAutoList",
".",
"class",
".",
"equals",
"(",
"returnType",
")",
"||",
"XBAutoValue",
".",
"class",
".",
"equals",
"(",
"returnType",
")",
"||",
"ReflectionHelper",
".",
"isStreamClass",
"(",
"returnType",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"final",
"Type",
"type",
"=",
"method",
".",
"getGenericReturnType",
"(",
")",
";",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"ParameterizedType",
")",
"||",
"(",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"(",
")",
"==",
"null",
")",
"||",
"(",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"(",
")",
".",
"length",
"<",
"1",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"When using List as return type for method \"",
"+",
"method",
"+",
"\", please specify a generic type for the List. Otherwise I do not know which type I should fill the List with.\"",
")",
";",
"}",
"int",
"index",
"=",
"Map",
".",
"class",
".",
"equals",
"(",
"returnType",
")",
"?",
"1",
":",
"0",
";",
"assert",
"index",
"<",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"(",
")",
".",
"length",
";",
"Type",
"componentType",
"=",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"(",
")",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"(",
"componentType",
"instanceof",
"Class",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"I don't know how to instantiate the generic type for the return type of method \"",
"+",
"method",
")",
";",
"}",
"return",
"(",
"Class",
"<",
"?",
">",
")",
"componentType",
";",
"}"
] | When reading collections, determine the collection component type.
@param method
@return | [
"When",
"reading",
"collections",
"determine",
"the",
"collection",
"component",
"type",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/ProjectionInvocationHandler.java#L921-L942 |
2,239 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/AutoMap.java | AutoMap.remove | public T remove(final CharSequence xpath) {
if ((xpath == null) || (xpath.length() == 0)) {
throw new IllegalArgumentException("Parameter path must not be empty or null");
}
domChangeTracker.refreshForReadIfNeeded();
final Document document = DOMHelper.getOwnerDocumentFor(baseNode);
final DuplexExpression duplexExpression = new DuplexXPathParser(invocationContext.getProjector().config().getUserDefinedNamespaceMapping()).compile(xpath);
try {
final XPathExpression expression = invocationContext.getProjector().config().createXPath(document).compile(duplexExpression.getExpressionAsStringWithoutFormatPatterns());
Node prevNode = (Node) expression.evaluate(boundNode, XPathConstants.NODE);
if (prevNode == null) {
return null;
}
final T value = DefaultXPathEvaluator.convertToComponentType(invocationContext, prevNode, invocationContext.getTargetComponentType());
duplexExpression.deleteAllMatchingChildren(prevNode.getParentNode());
return value;
} catch (XPathExpressionException e) {
throw new XBPathException(e, xpath);
}
} | java | public T remove(final CharSequence xpath) {
if ((xpath == null) || (xpath.length() == 0)) {
throw new IllegalArgumentException("Parameter path must not be empty or null");
}
domChangeTracker.refreshForReadIfNeeded();
final Document document = DOMHelper.getOwnerDocumentFor(baseNode);
final DuplexExpression duplexExpression = new DuplexXPathParser(invocationContext.getProjector().config().getUserDefinedNamespaceMapping()).compile(xpath);
try {
final XPathExpression expression = invocationContext.getProjector().config().createXPath(document).compile(duplexExpression.getExpressionAsStringWithoutFormatPatterns());
Node prevNode = (Node) expression.evaluate(boundNode, XPathConstants.NODE);
if (prevNode == null) {
return null;
}
final T value = DefaultXPathEvaluator.convertToComponentType(invocationContext, prevNode, invocationContext.getTargetComponentType());
duplexExpression.deleteAllMatchingChildren(prevNode.getParentNode());
return value;
} catch (XPathExpressionException e) {
throw new XBPathException(e, xpath);
}
} | [
"public",
"T",
"remove",
"(",
"final",
"CharSequence",
"xpath",
")",
"{",
"if",
"(",
"(",
"xpath",
"==",
"null",
")",
"||",
"(",
"xpath",
".",
"length",
"(",
")",
"==",
"0",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Parameter path must not be empty or null\"",
")",
";",
"}",
"domChangeTracker",
".",
"refreshForReadIfNeeded",
"(",
")",
";",
"final",
"Document",
"document",
"=",
"DOMHelper",
".",
"getOwnerDocumentFor",
"(",
"baseNode",
")",
";",
"final",
"DuplexExpression",
"duplexExpression",
"=",
"new",
"DuplexXPathParser",
"(",
"invocationContext",
".",
"getProjector",
"(",
")",
".",
"config",
"(",
")",
".",
"getUserDefinedNamespaceMapping",
"(",
")",
")",
".",
"compile",
"(",
"xpath",
")",
";",
"try",
"{",
"final",
"XPathExpression",
"expression",
"=",
"invocationContext",
".",
"getProjector",
"(",
")",
".",
"config",
"(",
")",
".",
"createXPath",
"(",
"document",
")",
".",
"compile",
"(",
"duplexExpression",
".",
"getExpressionAsStringWithoutFormatPatterns",
"(",
")",
")",
";",
"Node",
"prevNode",
"=",
"(",
"Node",
")",
"expression",
".",
"evaluate",
"(",
"boundNode",
",",
"XPathConstants",
".",
"NODE",
")",
";",
"if",
"(",
"prevNode",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"final",
"T",
"value",
"=",
"DefaultXPathEvaluator",
".",
"convertToComponentType",
"(",
"invocationContext",
",",
"prevNode",
",",
"invocationContext",
".",
"getTargetComponentType",
"(",
")",
")",
";",
"duplexExpression",
".",
"deleteAllMatchingChildren",
"(",
"prevNode",
".",
"getParentNode",
"(",
")",
")",
";",
"return",
"value",
";",
"}",
"catch",
"(",
"XPathExpressionException",
"e",
")",
"{",
"throw",
"new",
"XBPathException",
"(",
"e",
",",
"xpath",
")",
";",
"}",
"}"
] | Remove element at relative location.
@param xpath
@return previous value. | [
"Remove",
"element",
"at",
"relative",
"location",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/AutoMap.java#L310-L330 |
2,240 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.hasReturnType | public static boolean hasReturnType(final Method method) {
if (method == null) {
return false;
}
if (method.getReturnType() == null) {
return false;
}
if (Void.class.equals(method.getReturnType())) {
return false;
}
return !Void.TYPE.equals(method.getReturnType());
} | java | public static boolean hasReturnType(final Method method) {
if (method == null) {
return false;
}
if (method.getReturnType() == null) {
return false;
}
if (Void.class.equals(method.getReturnType())) {
return false;
}
return !Void.TYPE.equals(method.getReturnType());
} | [
"public",
"static",
"boolean",
"hasReturnType",
"(",
"final",
"Method",
"method",
")",
"{",
"if",
"(",
"method",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"method",
".",
"getReturnType",
"(",
")",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"Void",
".",
"class",
".",
"equals",
"(",
"method",
".",
"getReturnType",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"Void",
".",
"TYPE",
".",
"equals",
"(",
"method",
".",
"getReturnType",
"(",
")",
")",
";",
"}"
] | Defensive implemented method to determine if method has a return type.
@param method
@return true if and only if it is not a void method. | [
"Defensive",
"implemented",
"method",
"to",
"determine",
"if",
"method",
"has",
"a",
"return",
"type",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L161-L172 |
2,241 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.getCallableFactoryForParams | public static Method getCallableFactoryForParams(final Class<?> type, final Class<?>... params) {
for (Method m : type.getMethods()) {
if ((m.getModifiers() & PUBLIC_STATIC_MODIFIER) != PUBLIC_STATIC_MODIFIER) {
continue;
}
if (!type.isAssignableFrom(m.getReturnType())) {
continue;
}
if (!Arrays.equals(m.getParameterTypes(), params)) {
continue;
}
if (!VALID_FACTORY_METHOD_NAMES.matcher(m.getName()).matches()) {
continue;
}
return m;
}
return null;
} | java | public static Method getCallableFactoryForParams(final Class<?> type, final Class<?>... params) {
for (Method m : type.getMethods()) {
if ((m.getModifiers() & PUBLIC_STATIC_MODIFIER) != PUBLIC_STATIC_MODIFIER) {
continue;
}
if (!type.isAssignableFrom(m.getReturnType())) {
continue;
}
if (!Arrays.equals(m.getParameterTypes(), params)) {
continue;
}
if (!VALID_FACTORY_METHOD_NAMES.matcher(m.getName()).matches()) {
continue;
}
return m;
}
return null;
} | [
"public",
"static",
"Method",
"getCallableFactoryForParams",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
",",
"final",
"Class",
"<",
"?",
">",
"...",
"params",
")",
"{",
"for",
"(",
"Method",
"m",
":",
"type",
".",
"getMethods",
"(",
")",
")",
"{",
"if",
"(",
"(",
"m",
".",
"getModifiers",
"(",
")",
"&",
"PUBLIC_STATIC_MODIFIER",
")",
"!=",
"PUBLIC_STATIC_MODIFIER",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"type",
".",
"isAssignableFrom",
"(",
"m",
".",
"getReturnType",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"Arrays",
".",
"equals",
"(",
"m",
".",
"getParameterTypes",
"(",
")",
",",
"params",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"VALID_FACTORY_METHOD_NAMES",
".",
"matcher",
"(",
"m",
".",
"getName",
"(",
")",
")",
".",
"matches",
"(",
")",
")",
"{",
"continue",
";",
"}",
"return",
"m",
";",
"}",
"return",
"null",
";",
"}"
] | Search for a static factory method returning the target type.
@param type
@param params
@return factory method or null if it is not found. | [
"Search",
"for",
"a",
"static",
"factory",
"method",
"returning",
"the",
"target",
"type",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L330-L347 |
2,242 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.unwrap | public static Object unwrap(final Class<?> type, final Object object) throws Exception {
if (object == null) {
return null;
}
if (type == null) {
return object;
}
if (Callable.class.equals(type)) {
assert (object instanceof Callable);
return ((Callable<?>) object).call();
}
if ("java.util.function.Supplier".equals(type.getName())) {
return findMethodByName(type, "get").invoke(object, (Object[]) null);
}
return object;
} | java | public static Object unwrap(final Class<?> type, final Object object) throws Exception {
if (object == null) {
return null;
}
if (type == null) {
return object;
}
if (Callable.class.equals(type)) {
assert (object instanceof Callable);
return ((Callable<?>) object).call();
}
if ("java.util.function.Supplier".equals(type.getName())) {
return findMethodByName(type, "get").invoke(object, (Object[]) null);
}
return object;
} | [
"public",
"static",
"Object",
"unwrap",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
",",
"final",
"Object",
"object",
")",
"throws",
"Exception",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"type",
"==",
"null",
")",
"{",
"return",
"object",
";",
"}",
"if",
"(",
"Callable",
".",
"class",
".",
"equals",
"(",
"type",
")",
")",
"{",
"assert",
"(",
"object",
"instanceof",
"Callable",
")",
";",
"return",
"(",
"(",
"Callable",
"<",
"?",
">",
")",
"object",
")",
".",
"call",
"(",
")",
";",
"}",
"if",
"(",
"\"java.util.function.Supplier\"",
".",
"equals",
"(",
"type",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"findMethodByName",
"(",
"type",
",",
"\"get\"",
")",
".",
"invoke",
"(",
"object",
",",
"(",
"Object",
"[",
"]",
")",
"null",
")",
";",
"}",
"return",
"object",
";",
"}"
] | Unwrap a given object until we assume it is a value. Supports Callable and Supplier so far.
@param type
@param object
@return object if it's a value. Unwrapped object if its a Callable or a Supplier
@throws Exception
may be thrown by given objects method | [
"Unwrap",
"a",
"given",
"object",
"until",
"we",
"assume",
"it",
"is",
"a",
"value",
".",
"Supports",
"Callable",
"and",
"Supplier",
"so",
"far",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L365-L382 |
2,243 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.isOptional | public static boolean isOptional(final Type type) {
if (OPTIONAL_CLASS == null) {
return false;
}
if (!(type instanceof ParameterizedType)) {
// Either this is no Optional, or it's a raw optional which is useless for us anyway...
return false;
}
return OPTIONAL_CLASS.equals(((ParameterizedType) type).getRawType());
} | java | public static boolean isOptional(final Type type) {
if (OPTIONAL_CLASS == null) {
return false;
}
if (!(type instanceof ParameterizedType)) {
// Either this is no Optional, or it's a raw optional which is useless for us anyway...
return false;
}
return OPTIONAL_CLASS.equals(((ParameterizedType) type).getRawType());
} | [
"public",
"static",
"boolean",
"isOptional",
"(",
"final",
"Type",
"type",
")",
"{",
"if",
"(",
"OPTIONAL_CLASS",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"ParameterizedType",
")",
")",
"{",
"// Either this is no Optional, or it's a raw optional which is useless for us anyway...",
"return",
"false",
";",
"}",
"return",
"OPTIONAL_CLASS",
".",
"equals",
"(",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getRawType",
"(",
")",
")",
";",
"}"
] | Checks if given type is java.util.Optional with a generic type parameter.
@param type
@return true if and only if type is a parameterized Optional | [
"Checks",
"if",
"given",
"type",
"is",
"java",
".",
"util",
".",
"Optional",
"with",
"a",
"generic",
"type",
"parameter",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L411-L422 |
2,244 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.isRawType | public static boolean isRawType(final Type type) {
if (type instanceof Class) {
final Class<?> clazz = (Class<?>) type;
return (clazz.getTypeParameters().length > 0);
}
if (type instanceof ParameterizedType) {
final ParameterizedType ptype = (ParameterizedType) type;
return (ptype.getActualTypeArguments().length == 0);
}
return false;
} | java | public static boolean isRawType(final Type type) {
if (type instanceof Class) {
final Class<?> clazz = (Class<?>) type;
return (clazz.getTypeParameters().length > 0);
}
if (type instanceof ParameterizedType) {
final ParameterizedType ptype = (ParameterizedType) type;
return (ptype.getActualTypeArguments().length == 0);
}
return false;
} | [
"public",
"static",
"boolean",
"isRawType",
"(",
"final",
"Type",
"type",
")",
"{",
"if",
"(",
"type",
"instanceof",
"Class",
")",
"{",
"final",
"Class",
"<",
"?",
">",
"clazz",
"=",
"(",
"Class",
"<",
"?",
">",
")",
"type",
";",
"return",
"(",
"clazz",
".",
"getTypeParameters",
"(",
")",
".",
"length",
">",
"0",
")",
";",
"}",
"if",
"(",
"type",
"instanceof",
"ParameterizedType",
")",
"{",
"final",
"ParameterizedType",
"ptype",
"=",
"(",
"ParameterizedType",
")",
"type",
";",
"return",
"(",
"ptype",
".",
"getActualTypeArguments",
"(",
")",
".",
"length",
"==",
"0",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if a given type is a raw type.
@param type
@return true if and only if the type may be parameterized but has no parameter type. | [
"Checks",
"if",
"a",
"given",
"type",
"is",
"a",
"raw",
"type",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L430-L440 |
2,245 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.createOptional | public static Object createOptional(final Object value) {
if ((OPTIONAL_CLASS == null) || (OFNULLABLE == null)) {
throw new IllegalStateException("Unreachable Code executed. You just found a bug. Please report!");
}
try {
return OFNULLABLE.invoke(null, value);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
} | java | public static Object createOptional(final Object value) {
if ((OPTIONAL_CLASS == null) || (OFNULLABLE == null)) {
throw new IllegalStateException("Unreachable Code executed. You just found a bug. Please report!");
}
try {
return OFNULLABLE.invoke(null, value);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
} | [
"public",
"static",
"Object",
"createOptional",
"(",
"final",
"Object",
"value",
")",
"{",
"if",
"(",
"(",
"OPTIONAL_CLASS",
"==",
"null",
")",
"||",
"(",
"OFNULLABLE",
"==",
"null",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Unreachable Code executed. You just found a bug. Please report!\"",
")",
";",
"}",
"try",
"{",
"return",
"OFNULLABLE",
".",
"invoke",
"(",
"null",
",",
"value",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"InvocationTargetException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] | Create an instance of java.util.Optional for given value.
@param value
@return a new instance of Optional | [
"Create",
"an",
"instance",
"of",
"java",
".",
"util",
".",
"Optional",
"for",
"given",
"value",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L448-L461 |
2,246 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java | ReflectionHelper.throwThrowable | public static void throwThrowable(final Class<?> throwableType, final Object[] args, final Throwable optionalCause) throws Throwable {
Class<?>[] argsClasses = getClassesOfObjects(args);
Constructor<?> constructor = ReflectionHelper.getCallableConstructorForParams(throwableType, argsClasses);
Throwable throwable = null;
if (constructor != null) {
throwable = (Throwable) constructor.newInstance(args);
} else {
throwable = (Throwable) throwableType.newInstance();
}
if (optionalCause != null) {
throwable.initCause(optionalCause);
}
throw throwable;
} | java | public static void throwThrowable(final Class<?> throwableType, final Object[] args, final Throwable optionalCause) throws Throwable {
Class<?>[] argsClasses = getClassesOfObjects(args);
Constructor<?> constructor = ReflectionHelper.getCallableConstructorForParams(throwableType, argsClasses);
Throwable throwable = null;
if (constructor != null) {
throwable = (Throwable) constructor.newInstance(args);
} else {
throwable = (Throwable) throwableType.newInstance();
}
if (optionalCause != null) {
throwable.initCause(optionalCause);
}
throw throwable;
} | [
"public",
"static",
"void",
"throwThrowable",
"(",
"final",
"Class",
"<",
"?",
">",
"throwableType",
",",
"final",
"Object",
"[",
"]",
"args",
",",
"final",
"Throwable",
"optionalCause",
")",
"throws",
"Throwable",
"{",
"Class",
"<",
"?",
">",
"[",
"]",
"argsClasses",
"=",
"getClassesOfObjects",
"(",
"args",
")",
";",
"Constructor",
"<",
"?",
">",
"constructor",
"=",
"ReflectionHelper",
".",
"getCallableConstructorForParams",
"(",
"throwableType",
",",
"argsClasses",
")",
";",
"Throwable",
"throwable",
"=",
"null",
";",
"if",
"(",
"constructor",
"!=",
"null",
")",
"{",
"throwable",
"=",
"(",
"Throwable",
")",
"constructor",
".",
"newInstance",
"(",
"args",
")",
";",
"}",
"else",
"{",
"throwable",
"=",
"(",
"Throwable",
")",
"throwableType",
".",
"newInstance",
"(",
")",
";",
"}",
"if",
"(",
"optionalCause",
"!=",
"null",
")",
"{",
"throwable",
".",
"initCause",
"(",
"optionalCause",
")",
";",
"}",
"throw",
"throwable",
";",
"}"
] | Throws a throwable of type throwableType. The throwable will be created using an args
matching constructor or the default constructor if no matching constructor can be found.
@param throwableType
type of throwable to be thrown
@param args
for the throwable construction
@param optionalCause
cause to be set, may be null
@throws Throwable | [
"Throws",
"a",
"throwable",
"of",
"type",
"throwableType",
".",
"The",
"throwable",
"will",
"be",
"created",
"using",
"an",
"args",
"matching",
"constructor",
"or",
"the",
"default",
"constructor",
"if",
"no",
"matching",
"constructor",
"can",
"be",
"found",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/ReflectionHelper.java#L522-L536 |
2,247 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/DOMHelper.java | DOMHelper.getNamespaceMapping | public static Map<String, String> getNamespaceMapping(final Document document) {
Map<String, String> map = new HashMap<String, String>();
map.put("xmlns", "http://www.w3.org/2000/xmlns/");
map.put("xml", "http://www.w3.org/XML/1998/namespace");
// if (childName.equals("xmlns") || childName.startsWith("xmlns:")) {
// return "http://www.w3.org/2000/xmlns/";
// }
// if (childName.startsWith("xml:")) {
// return "http://www.w3.org/XML/1998/namespace";
// }
Element root = document.getDocumentElement();
if (root == null) {
// No document, no namespaces.
return map;
}
fillNSMapWithPrefixesDeclaredInElement(map, root);
return map;
} | java | public static Map<String, String> getNamespaceMapping(final Document document) {
Map<String, String> map = new HashMap<String, String>();
map.put("xmlns", "http://www.w3.org/2000/xmlns/");
map.put("xml", "http://www.w3.org/XML/1998/namespace");
// if (childName.equals("xmlns") || childName.startsWith("xmlns:")) {
// return "http://www.w3.org/2000/xmlns/";
// }
// if (childName.startsWith("xml:")) {
// return "http://www.w3.org/XML/1998/namespace";
// }
Element root = document.getDocumentElement();
if (root == null) {
// No document, no namespaces.
return map;
}
fillNSMapWithPrefixesDeclaredInElement(map, root);
return map;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"getNamespaceMapping",
"(",
"final",
"Document",
"document",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"map",
"=",
"new",
"HashMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"map",
".",
"put",
"(",
"\"xmlns\"",
",",
"\"http://www.w3.org/2000/xmlns/\"",
")",
";",
"map",
".",
"put",
"(",
"\"xml\"",
",",
"\"http://www.w3.org/XML/1998/namespace\"",
")",
";",
"// if (childName.equals(\"xmlns\") || childName.startsWith(\"xmlns:\")) {",
"// return \"http://www.w3.org/2000/xmlns/\";",
"// }",
"// if (childName.startsWith(\"xml:\")) {",
"// return \"http://www.w3.org/XML/1998/namespace\";",
"// }",
"Element",
"root",
"=",
"document",
".",
"getDocumentElement",
"(",
")",
";",
"if",
"(",
"root",
"==",
"null",
")",
"{",
"// No document, no namespaces.",
"return",
"map",
";",
"}",
"fillNSMapWithPrefixesDeclaredInElement",
"(",
"map",
",",
"root",
")",
";",
"return",
"map",
";",
"}"
] | Parse namespace prefixes defined anywhere in the document.
@param document
source document.
@return map with prefix->uri relationships. | [
"Parse",
"namespace",
"prefixes",
"defined",
"anywhere",
"in",
"the",
"document",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/DOMHelper.java#L93-L112 |
2,248 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/DOMHelper.java | DOMHelper.setDocumentElement | public static void setDocumentElement(final Document document, final Element element) {
Element documentElement = document.getDocumentElement();
if (documentElement != null) {
document.removeChild(documentElement);
}
if (element != null) {
if (element.getOwnerDocument().equals(document)) {
document.appendChild(element);
return;
}
Node node = document.adoptNode(element);
document.appendChild(node);
}
} | java | public static void setDocumentElement(final Document document, final Element element) {
Element documentElement = document.getDocumentElement();
if (documentElement != null) {
document.removeChild(documentElement);
}
if (element != null) {
if (element.getOwnerDocument().equals(document)) {
document.appendChild(element);
return;
}
Node node = document.adoptNode(element);
document.appendChild(node);
}
} | [
"public",
"static",
"void",
"setDocumentElement",
"(",
"final",
"Document",
"document",
",",
"final",
"Element",
"element",
")",
"{",
"Element",
"documentElement",
"=",
"document",
".",
"getDocumentElement",
"(",
")",
";",
"if",
"(",
"documentElement",
"!=",
"null",
")",
"{",
"document",
".",
"removeChild",
"(",
"documentElement",
")",
";",
"}",
"if",
"(",
"element",
"!=",
"null",
")",
"{",
"if",
"(",
"element",
".",
"getOwnerDocument",
"(",
")",
".",
"equals",
"(",
"document",
")",
")",
"{",
"document",
".",
"appendChild",
"(",
"element",
")",
";",
"return",
";",
"}",
"Node",
"node",
"=",
"document",
".",
"adoptNode",
"(",
"element",
")",
";",
"document",
".",
"appendChild",
"(",
"node",
")",
";",
"}",
"}"
] | Replace the current root element. If element is null, the current root element will be
removed.
@param document
@param element | [
"Replace",
"the",
"current",
"root",
"element",
".",
"If",
"element",
"is",
"null",
"the",
"current",
"root",
"element",
"will",
"be",
"removed",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/DOMHelper.java#L154-L167 |
2,249 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/DOMHelper.java | DOMHelper.nodeListsAreEqual | private static boolean nodeListsAreEqual(final NodeList a, final NodeList b) {
if (a == b) {
return true;
}
if ((a == null) || (b == null)) {
return false;
}
if (a.getLength() != b.getLength()) {
return false;
}
for (int i = 0; i < a.getLength(); ++i) {
if (!nodesAreEqual(a.item(i), b.item(i))) {
return false;
}
}
return true;
} | java | private static boolean nodeListsAreEqual(final NodeList a, final NodeList b) {
if (a == b) {
return true;
}
if ((a == null) || (b == null)) {
return false;
}
if (a.getLength() != b.getLength()) {
return false;
}
for (int i = 0; i < a.getLength(); ++i) {
if (!nodesAreEqual(a.item(i), b.item(i))) {
return false;
}
}
return true;
} | [
"private",
"static",
"boolean",
"nodeListsAreEqual",
"(",
"final",
"NodeList",
"a",
",",
"final",
"NodeList",
"b",
")",
"{",
"if",
"(",
"a",
"==",
"b",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"(",
"a",
"==",
"null",
")",
"||",
"(",
"b",
"==",
"null",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"a",
".",
"getLength",
"(",
")",
"!=",
"b",
".",
"getLength",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"getLength",
"(",
")",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"nodesAreEqual",
"(",
"a",
".",
"item",
"(",
"i",
")",
",",
"b",
".",
"item",
"(",
"i",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | NodelLists are equal if and only if their size is equal and the containing nodes at the same
indexes are equal.
@param a
@param b
@return | [
"NodelLists",
"are",
"equal",
"if",
"and",
"only",
"if",
"their",
"size",
"is",
"equal",
"and",
"the",
"containing",
"nodes",
"at",
"the",
"same",
"indexes",
"are",
"equal",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/DOMHelper.java#L229-L245 |
2,250 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/DOMHelper.java | DOMHelper.removeAllChildren | public static void removeAllChildren(final Node node) {
assert node != null;
assert node.getNodeType() != Node.ATTRIBUTE_NODE;
if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
Element documentElement = ((Document) node).getDocumentElement();
if (documentElement != null) {
((Document) node).removeChild(documentElement);
}
return;
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
for (Node n = element.getFirstChild(); n != null; n = element.getFirstChild()) {
element.removeChild(n);
}
}
} | java | public static void removeAllChildren(final Node node) {
assert node != null;
assert node.getNodeType() != Node.ATTRIBUTE_NODE;
if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
Element documentElement = ((Document) node).getDocumentElement();
if (documentElement != null) {
((Document) node).removeChild(documentElement);
}
return;
}
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
for (Node n = element.getFirstChild(); n != null; n = element.getFirstChild()) {
element.removeChild(n);
}
}
} | [
"public",
"static",
"void",
"removeAllChildren",
"(",
"final",
"Node",
"node",
")",
"{",
"assert",
"node",
"!=",
"null",
";",
"assert",
"node",
".",
"getNodeType",
"(",
")",
"!=",
"Node",
".",
"ATTRIBUTE_NODE",
";",
"if",
"(",
"node",
".",
"getNodeType",
"(",
")",
"==",
"Node",
".",
"DOCUMENT_TYPE_NODE",
")",
"{",
"Element",
"documentElement",
"=",
"(",
"(",
"Document",
")",
"node",
")",
".",
"getDocumentElement",
"(",
")",
";",
"if",
"(",
"documentElement",
"!=",
"null",
")",
"{",
"(",
"(",
"Document",
")",
"node",
")",
".",
"removeChild",
"(",
"documentElement",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"node",
".",
"getNodeType",
"(",
")",
"==",
"Node",
".",
"ELEMENT_NODE",
")",
"{",
"Element",
"element",
"=",
"(",
"Element",
")",
"node",
";",
"for",
"(",
"Node",
"n",
"=",
"element",
".",
"getFirstChild",
"(",
")",
";",
"n",
"!=",
"null",
";",
"n",
"=",
"element",
".",
"getFirstChild",
"(",
")",
")",
"{",
"element",
".",
"removeChild",
"(",
"n",
")",
";",
"}",
"}",
"}"
] | Simply removes all child nodes.
@param node | [
"Simply",
"removes",
"all",
"child",
"nodes",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/DOMHelper.java#L504-L520 |
2,251 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/intern/DOMHelper.java | DOMHelper.setDirectTextContent | public static void setDirectTextContent(final Node elementToChange, final String asString) {
assert elementToChange.getNodeType() != Node.DOCUMENT_NODE;
if (Node.ATTRIBUTE_NODE == elementToChange.getNodeType()) {
elementToChange.setTextContent(asString);
return;
}
List<Node> nodes = new LinkedList<Node>();
List<Node> nodes2 = new LinkedList<Node>();
for (Node n : nodeListToIterator(elementToChange.getChildNodes())) {
if (Node.TEXT_NODE == n.getNodeType()) {
continue;
}
nodes.add(n);
}
if ((asString != null) && (!asString.isEmpty())) {
elementToChange.setTextContent(asString);
for (Node n : nodeListToIterator(elementToChange.getChildNodes())) {
if (Node.TEXT_NODE != n.getNodeType()) {
continue;
}
nodes.add(n);
}
}
removeAllChildren(elementToChange);
for (Node n : nodes) {
elementToChange.appendChild(n);
}
for (Node n : nodes2) {
elementToChange.appendChild(n);
}
} | java | public static void setDirectTextContent(final Node elementToChange, final String asString) {
assert elementToChange.getNodeType() != Node.DOCUMENT_NODE;
if (Node.ATTRIBUTE_NODE == elementToChange.getNodeType()) {
elementToChange.setTextContent(asString);
return;
}
List<Node> nodes = new LinkedList<Node>();
List<Node> nodes2 = new LinkedList<Node>();
for (Node n : nodeListToIterator(elementToChange.getChildNodes())) {
if (Node.TEXT_NODE == n.getNodeType()) {
continue;
}
nodes.add(n);
}
if ((asString != null) && (!asString.isEmpty())) {
elementToChange.setTextContent(asString);
for (Node n : nodeListToIterator(elementToChange.getChildNodes())) {
if (Node.TEXT_NODE != n.getNodeType()) {
continue;
}
nodes.add(n);
}
}
removeAllChildren(elementToChange);
for (Node n : nodes) {
elementToChange.appendChild(n);
}
for (Node n : nodes2) {
elementToChange.appendChild(n);
}
} | [
"public",
"static",
"void",
"setDirectTextContent",
"(",
"final",
"Node",
"elementToChange",
",",
"final",
"String",
"asString",
")",
"{",
"assert",
"elementToChange",
".",
"getNodeType",
"(",
")",
"!=",
"Node",
".",
"DOCUMENT_NODE",
";",
"if",
"(",
"Node",
".",
"ATTRIBUTE_NODE",
"==",
"elementToChange",
".",
"getNodeType",
"(",
")",
")",
"{",
"elementToChange",
".",
"setTextContent",
"(",
"asString",
")",
";",
"return",
";",
"}",
"List",
"<",
"Node",
">",
"nodes",
"=",
"new",
"LinkedList",
"<",
"Node",
">",
"(",
")",
";",
"List",
"<",
"Node",
">",
"nodes2",
"=",
"new",
"LinkedList",
"<",
"Node",
">",
"(",
")",
";",
"for",
"(",
"Node",
"n",
":",
"nodeListToIterator",
"(",
"elementToChange",
".",
"getChildNodes",
"(",
")",
")",
")",
"{",
"if",
"(",
"Node",
".",
"TEXT_NODE",
"==",
"n",
".",
"getNodeType",
"(",
")",
")",
"{",
"continue",
";",
"}",
"nodes",
".",
"add",
"(",
"n",
")",
";",
"}",
"if",
"(",
"(",
"asString",
"!=",
"null",
")",
"&&",
"(",
"!",
"asString",
".",
"isEmpty",
"(",
")",
")",
")",
"{",
"elementToChange",
".",
"setTextContent",
"(",
"asString",
")",
";",
"for",
"(",
"Node",
"n",
":",
"nodeListToIterator",
"(",
"elementToChange",
".",
"getChildNodes",
"(",
")",
")",
")",
"{",
"if",
"(",
"Node",
".",
"TEXT_NODE",
"!=",
"n",
".",
"getNodeType",
"(",
")",
")",
"{",
"continue",
";",
"}",
"nodes",
".",
"add",
"(",
"n",
")",
";",
"}",
"}",
"removeAllChildren",
"(",
"elementToChange",
")",
";",
"for",
"(",
"Node",
"n",
":",
"nodes",
")",
"{",
"elementToChange",
".",
"appendChild",
"(",
"n",
")",
";",
"}",
"for",
"(",
"Node",
"n",
":",
"nodes2",
")",
"{",
"elementToChange",
".",
"appendChild",
"(",
"n",
")",
";",
"}",
"}"
] | Set text content of given element without removing existing child nodes. Text nodes are added
after child element nodes always.
@param elementToChange
@param asString | [
"Set",
"text",
"content",
"of",
"given",
"element",
"without",
"removing",
"existing",
"child",
"nodes",
".",
"Text",
"nodes",
"are",
"added",
"after",
"child",
"element",
"nodes",
"always",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/intern/DOMHelper.java#L632-L663 |
2,252 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/IOHelper.java | IOHelper.addRequestProperties | private static void addRequestProperties(final Map<String, String> requestProperties, final HttpURLConnection connection) {
if (requestProperties != null) {
for (Entry<String, String> entry : requestProperties.entrySet()) {
connection.addRequestProperty(entry.getKey(), entry.getValue());
}
}
} | java | private static void addRequestProperties(final Map<String, String> requestProperties, final HttpURLConnection connection) {
if (requestProperties != null) {
for (Entry<String, String> entry : requestProperties.entrySet()) {
connection.addRequestProperty(entry.getKey(), entry.getValue());
}
}
} | [
"private",
"static",
"void",
"addRequestProperties",
"(",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"requestProperties",
",",
"final",
"HttpURLConnection",
"connection",
")",
"{",
"if",
"(",
"requestProperties",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"requestProperties",
".",
"entrySet",
"(",
")",
")",
"{",
"connection",
".",
"addRequestProperty",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Copies request properties to a connection.
@param requestProperties
(if null, connection will not be changed)
@param connection | [
"Copies",
"request",
"properties",
"to",
"a",
"connection",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/IOHelper.java#L59-L65 |
2,253 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/IOHelper.java | IOHelper.createBasicAuthenticationProperty | public static Map<String, String> createBasicAuthenticationProperty(final String username, final String password) {
Map<String, String> map = new TreeMap<String, String>();
try {
String base64Binary = DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("US-ASCII"));
map.put("Authorization", "Basic " + base64Binary);
} catch (UnsupportedEncodingException e) {
// unreachable code
throw new RuntimeException(e);
}
return map;
} | java | public static Map<String, String> createBasicAuthenticationProperty(final String username, final String password) {
Map<String, String> map = new TreeMap<String, String>();
try {
String base64Binary = DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("US-ASCII"));
map.put("Authorization", "Basic " + base64Binary);
} catch (UnsupportedEncodingException e) {
// unreachable code
throw new RuntimeException(e);
}
return map;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"createBasicAuthenticationProperty",
"(",
"final",
"String",
"username",
",",
"final",
"String",
"password",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"map",
"=",
"new",
"TreeMap",
"<",
"String",
",",
"String",
">",
"(",
")",
";",
"try",
"{",
"String",
"base64Binary",
"=",
"DatatypeConverter",
".",
"printBase64Binary",
"(",
"(",
"username",
"+",
"\":\"",
"+",
"password",
")",
".",
"getBytes",
"(",
"\"US-ASCII\"",
")",
")",
";",
"map",
".",
"put",
"(",
"\"Authorization\"",
",",
"\"Basic \"",
"+",
"base64Binary",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"// unreachable code",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"return",
"map",
";",
"}"
] | Create HTTP Basic credentials to be used in HTTP get or post methods.
@param username
@param password
@return Map containing | [
"Create",
"HTTP",
"Basic",
"credentials",
"to",
"be",
"used",
"in",
"HTTP",
"get",
"or",
"post",
"methods",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/IOHelper.java#L74-L84 |
2,254 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/util/IOHelper.java | IOHelper.dropUTF8BOM | public static byte[] dropUTF8BOM(final byte[] source) {
if (source == null) {
return null;
}
if (source.length < 3) {
return source;
}
if ((source[0] == (byte) 0xef) && (source[1] == (byte) 0xbb) && (source[2] == (byte) 0xbf)) {
return Arrays.copyOfRange(source, 3, source.length);
}
return source;
} | java | public static byte[] dropUTF8BOM(final byte[] source) {
if (source == null) {
return null;
}
if (source.length < 3) {
return source;
}
if ((source[0] == (byte) 0xef) && (source[1] == (byte) 0xbb) && (source[2] == (byte) 0xbf)) {
return Arrays.copyOfRange(source, 3, source.length);
}
return source;
} | [
"public",
"static",
"byte",
"[",
"]",
"dropUTF8BOM",
"(",
"final",
"byte",
"[",
"]",
"source",
")",
"{",
"if",
"(",
"source",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"source",
".",
"length",
"<",
"3",
")",
"{",
"return",
"source",
";",
"}",
"if",
"(",
"(",
"source",
"[",
"0",
"]",
"==",
"(",
"byte",
")",
"0xef",
")",
"&&",
"(",
"source",
"[",
"1",
"]",
"==",
"(",
"byte",
")",
"0xbb",
")",
"&&",
"(",
"source",
"[",
"2",
"]",
"==",
"(",
"byte",
")",
"0xbf",
")",
")",
"{",
"return",
"Arrays",
".",
"copyOfRange",
"(",
"source",
",",
"3",
",",
"source",
".",
"length",
")",
";",
"}",
"return",
"source",
";",
"}"
] | Silently drop UTF8 BOM
@param source
@return data without UTF8 BOM | [
"Silently",
"drop",
"UTF8",
"BOM"
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/util/IOHelper.java#L156-L167 |
2,255 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/DefaultFileIO.java | DefaultFileIO.read | @Override
public <T> T read(final Class<T> projectionInterface) throws IOException {
try {
Document document = projector.config().createDocumentBuilder().parse(file);
return projector.projectDOMNode(document, projectionInterface);
} catch (SAXException e) {
throw new XBDocumentParsingException(e);
}
} | java | @Override
public <T> T read(final Class<T> projectionInterface) throws IOException {
try {
Document document = projector.config().createDocumentBuilder().parse(file);
return projector.projectDOMNode(document, projectionInterface);
} catch (SAXException e) {
throw new XBDocumentParsingException(e);
}
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"read",
"(",
"final",
"Class",
"<",
"T",
">",
"projectionInterface",
")",
"throws",
"IOException",
"{",
"try",
"{",
"Document",
"document",
"=",
"projector",
".",
"config",
"(",
")",
".",
"createDocumentBuilder",
"(",
")",
".",
"parse",
"(",
"file",
")",
";",
"return",
"projector",
".",
"projectDOMNode",
"(",
"document",
",",
"projectionInterface",
")",
";",
"}",
"catch",
"(",
"SAXException",
"e",
")",
"{",
"throw",
"new",
"XBDocumentParsingException",
"(",
"e",
")",
";",
"}",
"}"
] | Read a XML document and return a projection to it.
@param projectionInterface
@return a new projection pointing to the content of the file.
@throws IOException | [
"Read",
"a",
"XML",
"document",
"and",
"return",
"a",
"projection",
"to",
"it",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/DefaultFileIO.java#L93-L101 |
2,256 | SvenEwald/xmlbeam | src/main/java/org/xmlbeam/DefaultFileIO.java | DefaultFileIO.setAppend | @Override
public FileIO setAppend(final boolean... append) {
this.append = (append != null) && ((append.length == 0) || ((append.length > 0) && append[0]));
return this;
} | java | @Override
public FileIO setAppend(final boolean... append) {
this.append = (append != null) && ((append.length == 0) || ((append.length > 0) && append[0]));
return this;
} | [
"@",
"Override",
"public",
"FileIO",
"setAppend",
"(",
"final",
"boolean",
"...",
"append",
")",
"{",
"this",
".",
"append",
"=",
"(",
"append",
"!=",
"null",
")",
"&&",
"(",
"(",
"append",
".",
"length",
"==",
"0",
")",
"||",
"(",
"(",
"append",
".",
"length",
">",
"0",
")",
"&&",
"append",
"[",
"0",
"]",
")",
")",
";",
"return",
"this",
";",
"}"
] | Set whether output should be append to existing file. When this method is not invoked, or
invoked with 'false', The file will be replaced on writing operations.
@param append
optional parameter, default is true.
@return this to provide a fluent API. | [
"Set",
"whether",
"output",
"should",
"be",
"append",
"to",
"existing",
"file",
".",
"When",
"this",
"method",
"is",
"not",
"invoked",
"or",
"invoked",
"with",
"false",
"The",
"file",
"will",
"be",
"replaced",
"on",
"writing",
"operations",
"."
] | acaac1b8fa28d246f17187f5e3c6696458a0b447 | https://github.com/SvenEwald/xmlbeam/blob/acaac1b8fa28d246f17187f5e3c6696458a0b447/src/main/java/org/xmlbeam/DefaultFileIO.java#L123-L127 |
2,257 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java | JMXetricXmlConfigurationService.configureProcessName | private void configureProcessName() throws XPathExpressionException {
if (processName != null) {
return;
}
processName = "";
Node jvm = getXmlNode("/jmxetric-config/jvm", inputSource);
if (jvm != null) {
processName = jvm.getAttributes().getNamedItem("process")
.getNodeValue();
}
} | java | private void configureProcessName() throws XPathExpressionException {
if (processName != null) {
return;
}
processName = "";
Node jvm = getXmlNode("/jmxetric-config/jvm", inputSource);
if (jvm != null) {
processName = jvm.getAttributes().getNamedItem("process")
.getNodeValue();
}
} | [
"private",
"void",
"configureProcessName",
"(",
")",
"throws",
"XPathExpressionException",
"{",
"if",
"(",
"processName",
"!=",
"null",
")",
"{",
"return",
";",
"}",
"processName",
"=",
"\"\"",
";",
"Node",
"jvm",
"=",
"getXmlNode",
"(",
"\"/jmxetric-config/jvm\"",
",",
"inputSource",
")",
";",
"if",
"(",
"jvm",
"!=",
"null",
")",
"{",
"processName",
"=",
"jvm",
".",
"getAttributes",
"(",
")",
".",
"getNamedItem",
"(",
"\"process\"",
")",
".",
"getNodeValue",
"(",
")",
";",
"}",
"}"
] | The XML file may specify a processName to be used, which can be different
from the one used in the constructor. The name in XML takes priority.
@throws XPathExpressionException | [
"The",
"XML",
"file",
"may",
"specify",
"a",
"processName",
"to",
"be",
"used",
"which",
"can",
"be",
"different",
"from",
"the",
"one",
"used",
"in",
"the",
"constructor",
".",
"The",
"name",
"in",
"XML",
"takes",
"priority",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java#L62-L72 |
2,258 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java | JMXetricXmlConfigurationService.addMBeanAttributeToSampler | private void addMBeanAttributeToSampler(MBeanSampler mBeanSampler,
String mBeanName, MBeanAttribute mBeanAttribute) throws Exception {
if (mBeanAttribute.getSampler() == null) {
mBeanAttribute.setSampler(mBeanSampler);
}
mBeanSampler.addMBeanAttribute(mBeanName, mBeanAttribute);
} | java | private void addMBeanAttributeToSampler(MBeanSampler mBeanSampler,
String mBeanName, MBeanAttribute mBeanAttribute) throws Exception {
if (mBeanAttribute.getSampler() == null) {
mBeanAttribute.setSampler(mBeanSampler);
}
mBeanSampler.addMBeanAttribute(mBeanName, mBeanAttribute);
} | [
"private",
"void",
"addMBeanAttributeToSampler",
"(",
"MBeanSampler",
"mBeanSampler",
",",
"String",
"mBeanName",
",",
"MBeanAttribute",
"mBeanAttribute",
")",
"throws",
"Exception",
"{",
"if",
"(",
"mBeanAttribute",
".",
"getSampler",
"(",
")",
"==",
"null",
")",
"{",
"mBeanAttribute",
".",
"setSampler",
"(",
"mBeanSampler",
")",
";",
"}",
"mBeanSampler",
".",
"addMBeanAttribute",
"(",
"mBeanName",
",",
"mBeanAttribute",
")",
";",
"}"
] | Adds a MBeanAttribute to an MBeanSampler. This also checks if the
MBeanAttribute to be added already has a MBeanSampler set, if not it will
set it.
@param mBeanSampler
@param mBeanName
@param mBeanAttribute
@throws Exception | [
"Adds",
"a",
"MBeanAttribute",
"to",
"an",
"MBeanSampler",
".",
"This",
"also",
"checks",
"if",
"the",
"MBeanAttribute",
"to",
"be",
"added",
"already",
"has",
"a",
"MBeanSampler",
"set",
"if",
"not",
"it",
"will",
"set",
"it",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java#L137-L143 |
2,259 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java | JMXetricXmlConfigurationService.parseDMax | private int parseDMax(String dMaxString) {
int dMax;
try {
dMax = Integer.parseInt(dMaxString);
} catch (NumberFormatException e) {
dMax = 0;
}
return dMax;
} | java | private int parseDMax(String dMaxString) {
int dMax;
try {
dMax = Integer.parseInt(dMaxString);
} catch (NumberFormatException e) {
dMax = 0;
}
return dMax;
} | [
"private",
"int",
"parseDMax",
"(",
"String",
"dMaxString",
")",
"{",
"int",
"dMax",
";",
"try",
"{",
"dMax",
"=",
"Integer",
".",
"parseInt",
"(",
"dMaxString",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"dMax",
"=",
"0",
";",
"}",
"return",
"dMax",
";",
"}"
] | Parses dMaxString, which is the value of dmax read in from a
configuration file.
@param dMaxString
value read in from configuration
@return int value of dMaxString if parse is successful, 0 (default value)
otherwise | [
"Parses",
"dMaxString",
"which",
"is",
"the",
"value",
"of",
"dmax",
"read",
"in",
"from",
"a",
"configuration",
"file",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java#L288-L296 |
2,260 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java | JMXetricXmlConfigurationService.buildMetricName | private String buildMetricName(String process, String mbeanName,
String mbeanPublishName, String attribute, String attrPublishName) {
StringBuilder buf = new StringBuilder();
if (process != null) {
buf.append(process);
buf.append("_");
}
if (mbeanPublishName != null) {
buf.append(mbeanPublishName);
} else {
buf.append(mbeanName);
}
buf.append("_");
if (!"".equals(attrPublishName)) {
buf.append(attrPublishName);
} else {
buf.append(attribute);
}
return buf.toString();
} | java | private String buildMetricName(String process, String mbeanName,
String mbeanPublishName, String attribute, String attrPublishName) {
StringBuilder buf = new StringBuilder();
if (process != null) {
buf.append(process);
buf.append("_");
}
if (mbeanPublishName != null) {
buf.append(mbeanPublishName);
} else {
buf.append(mbeanName);
}
buf.append("_");
if (!"".equals(attrPublishName)) {
buf.append(attrPublishName);
} else {
buf.append(attribute);
}
return buf.toString();
} | [
"private",
"String",
"buildMetricName",
"(",
"String",
"process",
",",
"String",
"mbeanName",
",",
"String",
"mbeanPublishName",
",",
"String",
"attribute",
",",
"String",
"attrPublishName",
")",
"{",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"process",
"!=",
"null",
")",
"{",
"buf",
".",
"append",
"(",
"process",
")",
";",
"buf",
".",
"append",
"(",
"\"_\"",
")",
";",
"}",
"if",
"(",
"mbeanPublishName",
"!=",
"null",
")",
"{",
"buf",
".",
"append",
"(",
"mbeanPublishName",
")",
";",
"}",
"else",
"{",
"buf",
".",
"append",
"(",
"mbeanName",
")",
";",
"}",
"buf",
".",
"append",
"(",
"\"_\"",
")",
";",
"if",
"(",
"!",
"\"\"",
".",
"equals",
"(",
"attrPublishName",
")",
")",
"{",
"buf",
".",
"append",
"(",
"attrPublishName",
")",
";",
"}",
"else",
"{",
"buf",
".",
"append",
"(",
"attribute",
")",
";",
"}",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] | Builds the metric name in ganglia
@param process
the process name, or null if not used
@param mbeanName
the mbean name
@param mbeanPublishName
the mbean publish name, or null if not used
@param attribute
the mbean attribute name
@param attrPublishName
the mbean attribute publish name
@return the metric name | [
"Builds",
"the",
"metric",
"name",
"in",
"ganglia"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricXmlConfigurationService.java#L313-L332 |
2,261 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.main | public static void main(String[] args) {
PrintStream out = System.out;
if (args.length > 0) {
try {
out = new PrintStream(new File(args[0]));
} catch (FileNotFoundException e) {
System.out.printf(ERR_FILE, args[0]);
}
}
MBeanScanner mBeanScanner = new MBeanScanner();
List<Config> configs = mBeanScanner.scan();
ConfigWriter cw;
cw = new ConfigWriter(out, configs);
cw.write();
} | java | public static void main(String[] args) {
PrintStream out = System.out;
if (args.length > 0) {
try {
out = new PrintStream(new File(args[0]));
} catch (FileNotFoundException e) {
System.out.printf(ERR_FILE, args[0]);
}
}
MBeanScanner mBeanScanner = new MBeanScanner();
List<Config> configs = mBeanScanner.scan();
ConfigWriter cw;
cw = new ConfigWriter(out, configs);
cw.write();
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"PrintStream",
"out",
"=",
"System",
".",
"out",
";",
"if",
"(",
"args",
".",
"length",
">",
"0",
")",
"{",
"try",
"{",
"out",
"=",
"new",
"PrintStream",
"(",
"new",
"File",
"(",
"args",
"[",
"0",
"]",
")",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"System",
".",
"out",
".",
"printf",
"(",
"ERR_FILE",
",",
"args",
"[",
"0",
"]",
")",
";",
"}",
"}",
"MBeanScanner",
"mBeanScanner",
"=",
"new",
"MBeanScanner",
"(",
")",
";",
"List",
"<",
"Config",
">",
"configs",
"=",
"mBeanScanner",
".",
"scan",
"(",
")",
";",
"ConfigWriter",
"cw",
";",
"cw",
"=",
"new",
"ConfigWriter",
"(",
"out",
",",
"configs",
")",
";",
"cw",
".",
"write",
"(",
")",
";",
"}"
] | Used mainly for testing purposed to output a test configuration file to
System.out. Also shows how to use this class.
@param args | [
"Used",
"mainly",
"for",
"testing",
"purposed",
"to",
"output",
"a",
"test",
"configuration",
"file",
"to",
"System",
".",
"out",
".",
"Also",
"shows",
"how",
"to",
"use",
"this",
"class",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L45-L59 |
2,262 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.scan | public List<Config> scan() {
Set<ObjectInstance> mBeanObjects = mBeanServer.queryMBeans(null, null);
List<Config> configs = getConfigForAllMBeans(mBeanObjects);
return configs;
} | java | public List<Config> scan() {
Set<ObjectInstance> mBeanObjects = mBeanServer.queryMBeans(null, null);
List<Config> configs = getConfigForAllMBeans(mBeanObjects);
return configs;
} | [
"public",
"List",
"<",
"Config",
">",
"scan",
"(",
")",
"{",
"Set",
"<",
"ObjectInstance",
">",
"mBeanObjects",
"=",
"mBeanServer",
".",
"queryMBeans",
"(",
"null",
",",
"null",
")",
";",
"List",
"<",
"Config",
">",
"configs",
"=",
"getConfigForAllMBeans",
"(",
"mBeanObjects",
")",
";",
"return",
"configs",
";",
"}"
] | Scans the platform MBean server for registered MBeans, creating
see Config objects to represent these MBeans. | [
"Scans",
"the",
"platform",
"MBean",
"server",
"for",
"registered",
"MBeans",
"creating",
"see",
"Config",
"objects",
"to",
"represent",
"these",
"MBeans",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L65-L69 |
2,263 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.getConfigForAllMBeans | private List<Config> getConfigForAllMBeans(Set<ObjectInstance> mBeanObjects) {
List<Config> configs = new Vector<Config>();
for (ObjectInstance objectInstance : mBeanObjects) {
Config configMB = scanOneMBeanObject(objectInstance);
configs.add(configMB);
}
return configs;
} | java | private List<Config> getConfigForAllMBeans(Set<ObjectInstance> mBeanObjects) {
List<Config> configs = new Vector<Config>();
for (ObjectInstance objectInstance : mBeanObjects) {
Config configMB = scanOneMBeanObject(objectInstance);
configs.add(configMB);
}
return configs;
} | [
"private",
"List",
"<",
"Config",
">",
"getConfigForAllMBeans",
"(",
"Set",
"<",
"ObjectInstance",
">",
"mBeanObjects",
")",
"{",
"List",
"<",
"Config",
">",
"configs",
"=",
"new",
"Vector",
"<",
"Config",
">",
"(",
")",
";",
"for",
"(",
"ObjectInstance",
"objectInstance",
":",
"mBeanObjects",
")",
"{",
"Config",
"configMB",
"=",
"scanOneMBeanObject",
"(",
"objectInstance",
")",
";",
"configs",
".",
"add",
"(",
"configMB",
")",
";",
"}",
"return",
"configs",
";",
"}"
] | Constructs a configuration for all MBeans.
@param mBeanObjects
@return a list of Config for the MBeans | [
"Constructs",
"a",
"configuration",
"for",
"all",
"MBeans",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L77-L84 |
2,264 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.scanMBeanAttributes | private void scanMBeanAttributes(MBeanConfig mBeanConfig,
ObjectName mBeanName) {
MBeanInfo mBeanInfo;
try {
mBeanInfo = mBeanServer.getMBeanInfo(mBeanName);
MBeanAttributeInfo[] infos = mBeanInfo.getAttributes();
for (int i = 0; i < infos.length; i++) {
MBeanAttributeConfig cMBAttr = makeConfigMBeanAttribute(
mBeanName, infos[i]);
mBeanConfig.addChild(cMBAttr);
}
} catch (IntrospectionException e) {
System.err.println(e.getMessage());
} catch (InstanceNotFoundException e) {
System.err.println(e.getMessage());
} catch (ReflectionException e) {
System.err.println(e.getMessage());
}
} | java | private void scanMBeanAttributes(MBeanConfig mBeanConfig,
ObjectName mBeanName) {
MBeanInfo mBeanInfo;
try {
mBeanInfo = mBeanServer.getMBeanInfo(mBeanName);
MBeanAttributeInfo[] infos = mBeanInfo.getAttributes();
for (int i = 0; i < infos.length; i++) {
MBeanAttributeConfig cMBAttr = makeConfigMBeanAttribute(
mBeanName, infos[i]);
mBeanConfig.addChild(cMBAttr);
}
} catch (IntrospectionException e) {
System.err.println(e.getMessage());
} catch (InstanceNotFoundException e) {
System.err.println(e.getMessage());
} catch (ReflectionException e) {
System.err.println(e.getMessage());
}
} | [
"private",
"void",
"scanMBeanAttributes",
"(",
"MBeanConfig",
"mBeanConfig",
",",
"ObjectName",
"mBeanName",
")",
"{",
"MBeanInfo",
"mBeanInfo",
";",
"try",
"{",
"mBeanInfo",
"=",
"mBeanServer",
".",
"getMBeanInfo",
"(",
"mBeanName",
")",
";",
"MBeanAttributeInfo",
"[",
"]",
"infos",
"=",
"mBeanInfo",
".",
"getAttributes",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"infos",
".",
"length",
";",
"i",
"++",
")",
"{",
"MBeanAttributeConfig",
"cMBAttr",
"=",
"makeConfigMBeanAttribute",
"(",
"mBeanName",
",",
"infos",
"[",
"i",
"]",
")",
";",
"mBeanConfig",
".",
"addChild",
"(",
"cMBAttr",
")",
";",
"}",
"}",
"catch",
"(",
"IntrospectionException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"InstanceNotFoundException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Stores all attributes of an MBean into its MBeanConfig object
@param mBeanConfig
the configuration object to store the attributes into
@param mBeanName
the name of the MBean object we are getting the attributes
from | [
"Stores",
"all",
"attributes",
"of",
"an",
"MBean",
"into",
"its",
"MBeanConfig",
"object"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L112-L130 |
2,265 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.makeConfigMBeanAttribute | private MBeanAttributeConfig makeConfigMBeanAttribute(ObjectName mBeanName,
MBeanAttributeInfo attributeInfo) {
// type determines if this should be composite
Object attr;
try {
attr = mBeanServer.getAttribute(mBeanName,
attributeInfo.getName());
MBeanAttributeConfig config = new MBeanAttributeConfig();
config.addField("name", attributeInfo.getName());
if (attr == null) {
return null;
} else if (attr instanceof CompositeData) {
addComposites(config, (CompositeData) attr);
} else {
config.addField("type",
translateDataType(attributeInfo.getType()));
}
return config;
} catch (RuntimeMBeanException e) {
System.err.println(e.getMessage());
} catch (AttributeNotFoundException e) {
System.err.println(e.getMessage());
} catch (InstanceNotFoundException e) {
System.err.println(e.getMessage());
} catch (MBeanException e) {
System.err.println(e.getMessage());
} catch (ReflectionException e) {
System.err.println(e.getMessage());
}
return null;
} | java | private MBeanAttributeConfig makeConfigMBeanAttribute(ObjectName mBeanName,
MBeanAttributeInfo attributeInfo) {
// type determines if this should be composite
Object attr;
try {
attr = mBeanServer.getAttribute(mBeanName,
attributeInfo.getName());
MBeanAttributeConfig config = new MBeanAttributeConfig();
config.addField("name", attributeInfo.getName());
if (attr == null) {
return null;
} else if (attr instanceof CompositeData) {
addComposites(config, (CompositeData) attr);
} else {
config.addField("type",
translateDataType(attributeInfo.getType()));
}
return config;
} catch (RuntimeMBeanException e) {
System.err.println(e.getMessage());
} catch (AttributeNotFoundException e) {
System.err.println(e.getMessage());
} catch (InstanceNotFoundException e) {
System.err.println(e.getMessage());
} catch (MBeanException e) {
System.err.println(e.getMessage());
} catch (ReflectionException e) {
System.err.println(e.getMessage());
}
return null;
} | [
"private",
"MBeanAttributeConfig",
"makeConfigMBeanAttribute",
"(",
"ObjectName",
"mBeanName",
",",
"MBeanAttributeInfo",
"attributeInfo",
")",
"{",
"// type determines if this should be composite",
"Object",
"attr",
";",
"try",
"{",
"attr",
"=",
"mBeanServer",
".",
"getAttribute",
"(",
"mBeanName",
",",
"attributeInfo",
".",
"getName",
"(",
")",
")",
";",
"MBeanAttributeConfig",
"config",
"=",
"new",
"MBeanAttributeConfig",
"(",
")",
";",
"config",
".",
"addField",
"(",
"\"name\"",
",",
"attributeInfo",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"attr",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"attr",
"instanceof",
"CompositeData",
")",
"{",
"addComposites",
"(",
"config",
",",
"(",
"CompositeData",
")",
"attr",
")",
";",
"}",
"else",
"{",
"config",
".",
"addField",
"(",
"\"type\"",
",",
"translateDataType",
"(",
"attributeInfo",
".",
"getType",
"(",
")",
")",
")",
";",
"}",
"return",
"config",
";",
"}",
"catch",
"(",
"RuntimeMBeanException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"AttributeNotFoundException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"InstanceNotFoundException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"MBeanException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
"e",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Creates an object to represent a single attribute of an MBean. An
attribute can be a simple attribute, or made up composites.
@param mBeanName
@param attributeInfo
@return an AttributeConfig for this MBean | [
"Creates",
"an",
"object",
"to",
"represent",
"a",
"single",
"attribute",
"of",
"an",
"MBean",
".",
"An",
"attribute",
"can",
"be",
"a",
"simple",
"attribute",
"or",
"made",
"up",
"composites",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L140-L171 |
2,266 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.addComposites | private void addComposites(MBeanAttributeConfig config,
CompositeData compositeData) {
CompositeType compositeType = compositeData.getCompositeType();
for (String key : compositeType.keySet()) {
config.addChild(makeComposite(compositeType, key));
}
} | java | private void addComposites(MBeanAttributeConfig config,
CompositeData compositeData) {
CompositeType compositeType = compositeData.getCompositeType();
for (String key : compositeType.keySet()) {
config.addChild(makeComposite(compositeType, key));
}
} | [
"private",
"void",
"addComposites",
"(",
"MBeanAttributeConfig",
"config",
",",
"CompositeData",
"compositeData",
")",
"{",
"CompositeType",
"compositeType",
"=",
"compositeData",
".",
"getCompositeType",
"(",
")",
";",
"for",
"(",
"String",
"key",
":",
"compositeType",
".",
"keySet",
"(",
")",
")",
"{",
"config",
".",
"addChild",
"(",
"makeComposite",
"(",
"compositeType",
",",
"key",
")",
")",
";",
"}",
"}"
] | Adds the composite data of an MBean's attribute to an
MBeanAttributeConfig
@param config
configuration which the composite belongs to
@param compositeData
object representing the composite data | [
"Adds",
"the",
"composite",
"data",
"of",
"an",
"MBean",
"s",
"attribute",
"to",
"an",
"MBeanAttributeConfig"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L182-L188 |
2,267 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanScanner.java | MBeanScanner.makeComposite | private MBeanCompositeConfig makeComposite(CompositeType compositeType,
String name) {
MBeanCompositeConfig config = new MBeanCompositeConfig();
config.addField("name", name);
String rawType = compositeType.getType(name).toString();
config.addField("type", translateDataType(rawType));
return config;
} | java | private MBeanCompositeConfig makeComposite(CompositeType compositeType,
String name) {
MBeanCompositeConfig config = new MBeanCompositeConfig();
config.addField("name", name);
String rawType = compositeType.getType(name).toString();
config.addField("type", translateDataType(rawType));
return config;
} | [
"private",
"MBeanCompositeConfig",
"makeComposite",
"(",
"CompositeType",
"compositeType",
",",
"String",
"name",
")",
"{",
"MBeanCompositeConfig",
"config",
"=",
"new",
"MBeanCompositeConfig",
"(",
")",
";",
"config",
".",
"addField",
"(",
"\"name\"",
",",
"name",
")",
";",
"String",
"rawType",
"=",
"compositeType",
".",
"getType",
"(",
"name",
")",
".",
"toString",
"(",
")",
";",
"config",
".",
"addField",
"(",
"\"type\"",
",",
"translateDataType",
"(",
"rawType",
")",
")",
";",
"return",
"config",
";",
"}"
] | Makes a configuration for JMXetric that represents the composite tag
@param compositeType
@param name
@return a CompositeConfig for a composite MBean | [
"Makes",
"a",
"configuration",
"for",
"JMXetric",
"that",
"represents",
"the",
"composite",
"tag"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanScanner.java#L197-L204 |
2,268 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getConfig | public GMetric getConfig() throws IOException, XPathExpressionException {
// TODO what happens when the node cannot be found? do we use all
// default values?
ganglia = getXmlNode("/jmxetric-config/ganglia", inputSource);
// Gets the config for ganglia
// Note that the ganglia config needs to be found before the samplers
// are created.
GMetric gmetric = makeGMetricFromXml();
return gmetric;
} | java | public GMetric getConfig() throws IOException, XPathExpressionException {
// TODO what happens when the node cannot be found? do we use all
// default values?
ganglia = getXmlNode("/jmxetric-config/ganglia", inputSource);
// Gets the config for ganglia
// Note that the ganglia config needs to be found before the samplers
// are created.
GMetric gmetric = makeGMetricFromXml();
return gmetric;
} | [
"public",
"GMetric",
"getConfig",
"(",
")",
"throws",
"IOException",
",",
"XPathExpressionException",
"{",
"// TODO what happens when the node cannot be found? do we use all",
"// default values?",
"ganglia",
"=",
"getXmlNode",
"(",
"\"/jmxetric-config/ganglia\"",
",",
"inputSource",
")",
";",
"// Gets the config for ganglia",
"// Note that the ganglia config needs to be found before the samplers",
"// are created.",
"GMetric",
"gmetric",
"=",
"makeGMetricFromXml",
"(",
")",
";",
"return",
"gmetric",
";",
"}"
] | Creates a GMetric attribute on the JMXetricAgent from the XML config
@return
@throws IOException
@throws XPathExpressionException | [
"Creates",
"a",
"GMetric",
"attribute",
"on",
"the",
"JMXetricAgent",
"from",
"the",
"XML",
"config"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L67-L76 |
2,269 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.makeGMetricFromXml | GMetric makeGMetricFromXml() throws IOException {
String hostname = getHostName();
int port = getPort();
UDPAddressingMode addressingMode = getAddressingMode();
boolean v31x = getV31();
String spoof = getSpoof();
StringBuilder buf = new StringBuilder();
buf.append("GMetric host=").append(hostname);
buf.append(" port=").append(port);
buf.append(" mode=").append(addressingMode);
buf.append(" v31x=").append(v31x);
buf.append(" spoof=").append(spoof);
log.fine(buf.toString());
System.out.println(buf.toString());
return new GMetric(hostname, port, addressingMode, DEFAULT_TTL, v31x,
null, spoof);
} | java | GMetric makeGMetricFromXml() throws IOException {
String hostname = getHostName();
int port = getPort();
UDPAddressingMode addressingMode = getAddressingMode();
boolean v31x = getV31();
String spoof = getSpoof();
StringBuilder buf = new StringBuilder();
buf.append("GMetric host=").append(hostname);
buf.append(" port=").append(port);
buf.append(" mode=").append(addressingMode);
buf.append(" v31x=").append(v31x);
buf.append(" spoof=").append(spoof);
log.fine(buf.toString());
System.out.println(buf.toString());
return new GMetric(hostname, port, addressingMode, DEFAULT_TTL, v31x,
null, spoof);
} | [
"GMetric",
"makeGMetricFromXml",
"(",
")",
"throws",
"IOException",
"{",
"String",
"hostname",
"=",
"getHostName",
"(",
")",
";",
"int",
"port",
"=",
"getPort",
"(",
")",
";",
"UDPAddressingMode",
"addressingMode",
"=",
"getAddressingMode",
"(",
")",
";",
"boolean",
"v31x",
"=",
"getV31",
"(",
")",
";",
"String",
"spoof",
"=",
"getSpoof",
"(",
")",
";",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"buf",
".",
"append",
"(",
"\"GMetric host=\"",
")",
".",
"append",
"(",
"hostname",
")",
";",
"buf",
".",
"append",
"(",
"\" port=\"",
")",
".",
"append",
"(",
"port",
")",
";",
"buf",
".",
"append",
"(",
"\" mode=\"",
")",
".",
"append",
"(",
"addressingMode",
")",
";",
"buf",
".",
"append",
"(",
"\" v31x=\"",
")",
".",
"append",
"(",
"v31x",
")",
";",
"buf",
".",
"append",
"(",
"\" spoof=\"",
")",
".",
"append",
"(",
"spoof",
")",
";",
"log",
".",
"fine",
"(",
"buf",
".",
"toString",
"(",
")",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"buf",
".",
"toString",
"(",
")",
")",
";",
"return",
"new",
"GMetric",
"(",
"hostname",
",",
"port",
",",
"addressingMode",
",",
"DEFAULT_TTL",
",",
"v31x",
",",
"null",
",",
"spoof",
")",
";",
"}"
] | Makes a GMetric object that can be use to define configuration for an
agent.
@return GMetric object with the configuration
@throws IOException | [
"Makes",
"a",
"GMetric",
"object",
"that",
"can",
"be",
"use",
"to",
"define",
"configuration",
"for",
"an",
"agent",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L85-L102 |
2,270 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getPort | private int getPort() {
String port = getGangliaConfig(args.getPort(), ganglia, "port",
DEFAULT_PORT);
return Integer.parseInt(port);
} | java | private int getPort() {
String port = getGangliaConfig(args.getPort(), ganglia, "port",
DEFAULT_PORT);
return Integer.parseInt(port);
} | [
"private",
"int",
"getPort",
"(",
")",
"{",
"String",
"port",
"=",
"getGangliaConfig",
"(",
"args",
".",
"getPort",
"(",
")",
",",
"ganglia",
",",
"\"port\"",
",",
"DEFAULT_PORT",
")",
";",
"return",
"Integer",
".",
"parseInt",
"(",
"port",
")",
";",
"}"
] | Gets the port that JMXetric will announce to, this is usually the port
gmond is running on
@return port number, defaults to 8649 | [
"Gets",
"the",
"port",
"that",
"JMXetric",
"will",
"announce",
"to",
"this",
"is",
"usually",
"the",
"port",
"gmond",
"is",
"running",
"on"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L120-L124 |
2,271 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getAddressingMode | private UDPAddressingMode getAddressingMode() {
String mode = getGangliaConfig(args.getMode(), ganglia, "mode",
DEFAULT_MODE);
if (mode.toLowerCase().equals("unicast")) {
return UDPAddressingMode.UNICAST;
} else {
return UDPAddressingMode.MULTICAST;
}
} | java | private UDPAddressingMode getAddressingMode() {
String mode = getGangliaConfig(args.getMode(), ganglia, "mode",
DEFAULT_MODE);
if (mode.toLowerCase().equals("unicast")) {
return UDPAddressingMode.UNICAST;
} else {
return UDPAddressingMode.MULTICAST;
}
} | [
"private",
"UDPAddressingMode",
"getAddressingMode",
"(",
")",
"{",
"String",
"mode",
"=",
"getGangliaConfig",
"(",
"args",
".",
"getMode",
"(",
")",
",",
"ganglia",
",",
"\"mode\"",
",",
"DEFAULT_MODE",
")",
";",
"if",
"(",
"mode",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"unicast\"",
")",
")",
"{",
"return",
"UDPAddressingMode",
".",
"UNICAST",
";",
"}",
"else",
"{",
"return",
"UDPAddressingMode",
".",
"MULTICAST",
";",
"}",
"}"
] | UDPAddressingMode to use for reporting
@return {@link info.ganglia.gmetric4j.gmetric.UDPAddressingMode.UNICAST}
or
{@link info.ganglia.gmetric4j.gmetric.UDPAddressingMode.MULTICAST} | [
"UDPAddressingMode",
"to",
"use",
"for",
"reporting"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L133-L141 |
2,272 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getV31 | private boolean getV31() {
String stringv31x = getGangliaConfig(args.getWireformat(), ganglia,
"wireformat31x", "false");
return Boolean.parseBoolean(stringv31x);
} | java | private boolean getV31() {
String stringv31x = getGangliaConfig(args.getWireformat(), ganglia,
"wireformat31x", "false");
return Boolean.parseBoolean(stringv31x);
} | [
"private",
"boolean",
"getV31",
"(",
")",
"{",
"String",
"stringv31x",
"=",
"getGangliaConfig",
"(",
"args",
".",
"getWireformat",
"(",
")",
",",
"ganglia",
",",
"\"wireformat31x\"",
",",
"\"false\"",
")",
";",
"return",
"Boolean",
".",
"parseBoolean",
"(",
"stringv31x",
")",
";",
"}"
] | Whether the reporting be done on the new wire format 31.
@return true if new format is to be used | [
"Whether",
"the",
"reporting",
"be",
"done",
"on",
"the",
"new",
"wire",
"format",
"31",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L148-L152 |
2,273 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getGangliaConfig | private String getGangliaConfig(String cmdLine, Node ganglia,
String attributeName, String defaultValue) {
if (cmdLine == null) {
return selectParameterFromNode(ganglia, attributeName, defaultValue);
} else {
return cmdLine;
}
} | java | private String getGangliaConfig(String cmdLine, Node ganglia,
String attributeName, String defaultValue) {
if (cmdLine == null) {
return selectParameterFromNode(ganglia, attributeName, defaultValue);
} else {
return cmdLine;
}
} | [
"private",
"String",
"getGangliaConfig",
"(",
"String",
"cmdLine",
",",
"Node",
"ganglia",
",",
"String",
"attributeName",
",",
"String",
"defaultValue",
")",
"{",
"if",
"(",
"cmdLine",
"==",
"null",
")",
"{",
"return",
"selectParameterFromNode",
"(",
"ganglia",
",",
"attributeName",
",",
"defaultValue",
")",
";",
"}",
"else",
"{",
"return",
"cmdLine",
";",
"}",
"}"
] | Gets a configuration parameter for Ganglia. First checks if it was given
on the command line arguments. If it is not available, it looks for the
value in the XML node.
@param cmdLine
command line value for this attribute
@param ganglia
the XML node
@param attributeName
name of the attribute
@param defaultValue
default value if this attribute cannot be found
@return the string value of the specified attribute | [
"Gets",
"a",
"configuration",
"parameter",
"for",
"Ganglia",
".",
"First",
"checks",
"if",
"it",
"was",
"given",
"on",
"the",
"command",
"line",
"arguments",
".",
"If",
"it",
"is",
"not",
"available",
"it",
"looks",
"for",
"the",
"value",
"in",
"the",
"XML",
"node",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L178-L185 |
2,274 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java | GangliaXmlConfigurationService.getConfigString | String getConfigString() throws XPathExpressionException {
ganglia = getXmlNode("/jmxetric-config/ganglia", inputSource);
String hostname = getHostName();
int port = getPort();
UDPAddressingMode addressingMode = getAddressingMode();
boolean v31x = getV31();
String spoof = getSpoof();
StringBuilder buf = new StringBuilder();
buf.append("GMetric host=").append(hostname);
buf.append(" port=").append(port);
buf.append(" mode=").append(addressingMode);
buf.append(" v31x=").append(v31x);
buf.append(" spoof=").append(spoof);
return buf.toString();
} | java | String getConfigString() throws XPathExpressionException {
ganglia = getXmlNode("/jmxetric-config/ganglia", inputSource);
String hostname = getHostName();
int port = getPort();
UDPAddressingMode addressingMode = getAddressingMode();
boolean v31x = getV31();
String spoof = getSpoof();
StringBuilder buf = new StringBuilder();
buf.append("GMetric host=").append(hostname);
buf.append(" port=").append(port);
buf.append(" mode=").append(addressingMode);
buf.append(" v31x=").append(v31x);
buf.append(" spoof=").append(spoof);
return buf.toString();
} | [
"String",
"getConfigString",
"(",
")",
"throws",
"XPathExpressionException",
"{",
"ganglia",
"=",
"getXmlNode",
"(",
"\"/jmxetric-config/ganglia\"",
",",
"inputSource",
")",
";",
"String",
"hostname",
"=",
"getHostName",
"(",
")",
";",
"int",
"port",
"=",
"getPort",
"(",
")",
";",
"UDPAddressingMode",
"addressingMode",
"=",
"getAddressingMode",
"(",
")",
";",
"boolean",
"v31x",
"=",
"getV31",
"(",
")",
";",
"String",
"spoof",
"=",
"getSpoof",
"(",
")",
";",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"buf",
".",
"append",
"(",
"\"GMetric host=\"",
")",
".",
"append",
"(",
"hostname",
")",
";",
"buf",
".",
"append",
"(",
"\" port=\"",
")",
".",
"append",
"(",
"port",
")",
";",
"buf",
".",
"append",
"(",
"\" mode=\"",
")",
".",
"append",
"(",
"addressingMode",
")",
";",
"buf",
".",
"append",
"(",
"\" v31x=\"",
")",
".",
"append",
"(",
"v31x",
")",
";",
"buf",
".",
"append",
"(",
"\" spoof=\"",
")",
".",
"append",
"(",
"spoof",
")",
";",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] | Method used by tests to print out the read in configuration.
@return string representation of configuration
@throws XPathExpressionException | [
"Method",
"used",
"by",
"tests",
"to",
"print",
"out",
"the",
"read",
"in",
"configuration",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/GangliaXmlConfigurationService.java#L193-L208 |
2,275 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricAgent.java | JMXetricAgent.main | public static void main(String[] args) throws Exception {
while( true ) {
Thread.sleep(1000*60*5);
System.out.println("Test wakeup");
}
} | java | public static void main(String[] args) throws Exception {
while( true ) {
Thread.sleep(1000*60*5);
System.out.println("Test wakeup");
}
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"Exception",
"{",
"while",
"(",
"true",
")",
"{",
"Thread",
".",
"sleep",
"(",
"1000",
"*",
"60",
"*",
"5",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"Test wakeup\"",
")",
";",
"}",
"}"
] | A log running, trivial main method for test purposes
premain method
@param args Not used | [
"A",
"log",
"running",
"trivial",
"main",
"method",
"for",
"test",
"purposes",
"premain",
"method"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricAgent.java#L35-L40 |
2,276 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/JMXetricAgent.java | JMXetricAgent.premain | public static void premain(String agentArgs, Instrumentation inst) {
System.out.println(STARTUP_NOTICE) ;
JMXetricAgent a = null ;
try {
a = new JMXetricAgent();
XMLConfigurationService.configure(a, agentArgs);
a.start();
} catch ( Exception ex ) {
// log.severe("Exception starting JMXetricAgent");
ex.printStackTrace();
}
} | java | public static void premain(String agentArgs, Instrumentation inst) {
System.out.println(STARTUP_NOTICE) ;
JMXetricAgent a = null ;
try {
a = new JMXetricAgent();
XMLConfigurationService.configure(a, agentArgs);
a.start();
} catch ( Exception ex ) {
// log.severe("Exception starting JMXetricAgent");
ex.printStackTrace();
}
} | [
"public",
"static",
"void",
"premain",
"(",
"String",
"agentArgs",
",",
"Instrumentation",
"inst",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"STARTUP_NOTICE",
")",
";",
"JMXetricAgent",
"a",
"=",
"null",
";",
"try",
"{",
"a",
"=",
"new",
"JMXetricAgent",
"(",
")",
";",
"XMLConfigurationService",
".",
"configure",
"(",
"a",
",",
"agentArgs",
")",
";",
"a",
".",
"start",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"// log.severe(\"Exception starting JMXetricAgent\");",
"ex",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | The JVM agent entry point
@param agentArgs
@param inst | [
"The",
"JVM",
"agent",
"entry",
"point"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/JMXetricAgent.java#L46-L57 |
2,277 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/MBeanSampler.java | MBeanSampler.run | public void run() {
try {
for (String mbean : mbeanMap.keySet()) {
MBeanHolder h = mbeanMap.get(mbean);
h.publish();
}
} catch (Exception ex) {
// Robust exception to prevent thread death
log.warning("Exception thrown sampling Mbeans");
log.throwing(this.getClass().getName(),
"Exception thrown sampling Mbeans:", ex);
}
} | java | public void run() {
try {
for (String mbean : mbeanMap.keySet()) {
MBeanHolder h = mbeanMap.get(mbean);
h.publish();
}
} catch (Exception ex) {
// Robust exception to prevent thread death
log.warning("Exception thrown sampling Mbeans");
log.throwing(this.getClass().getName(),
"Exception thrown sampling Mbeans:", ex);
}
} | [
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"for",
"(",
"String",
"mbean",
":",
"mbeanMap",
".",
"keySet",
"(",
")",
")",
"{",
"MBeanHolder",
"h",
"=",
"mbeanMap",
".",
"get",
"(",
"mbean",
")",
";",
"h",
".",
"publish",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"// Robust exception to prevent thread death",
"log",
".",
"warning",
"(",
"\"Exception thrown sampling Mbeans\"",
")",
";",
"log",
".",
"throwing",
"(",
"this",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
",",
"\"Exception thrown sampling Mbeans:\"",
",",
"ex",
")",
";",
"}",
"}"
] | Called by the JMXAgent periodically to sample the mbeans | [
"Called",
"by",
"the",
"JMXAgent",
"periodically",
"to",
"sample",
"the",
"mbeans"
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/MBeanSampler.java#L122-L134 |
2,278 | ganglia/jmxetric | src/main/java/info/ganglia/jmxetric/XMLConfigurationService.java | XMLConfigurationService.configure | public static void configure(JMXetricAgent agent, String agentArgs)
throws Exception {
CommandLineArgs args = new CommandLineArgs(agentArgs);
InputSource inputSource = new InputSource(args.getConfig());
configureGanglia(agent, inputSource, args);
configureJMXetric(agent, inputSource, args);
} | java | public static void configure(JMXetricAgent agent, String agentArgs)
throws Exception {
CommandLineArgs args = new CommandLineArgs(agentArgs);
InputSource inputSource = new InputSource(args.getConfig());
configureGanglia(agent, inputSource, args);
configureJMXetric(agent, inputSource, args);
} | [
"public",
"static",
"void",
"configure",
"(",
"JMXetricAgent",
"agent",
",",
"String",
"agentArgs",
")",
"throws",
"Exception",
"{",
"CommandLineArgs",
"args",
"=",
"new",
"CommandLineArgs",
"(",
"agentArgs",
")",
";",
"InputSource",
"inputSource",
"=",
"new",
"InputSource",
"(",
"args",
".",
"getConfig",
"(",
")",
")",
";",
"configureGanglia",
"(",
"agent",
",",
"inputSource",
",",
"args",
")",
";",
"configureJMXetric",
"(",
"agent",
",",
"inputSource",
",",
"args",
")",
";",
"}"
] | Configures the JMXetricAgent based on the supplied agentArgs Command line
arguments overwrites XML arguments. Any arguments that is required but no
supplied will be defaulted.
@param agent
the agent to configure
@param agentArgs
the agent arguments list
@throws java.lang.Exception | [
"Configures",
"the",
"JMXetricAgent",
"based",
"on",
"the",
"supplied",
"agentArgs",
"Command",
"line",
"arguments",
"overwrites",
"XML",
"arguments",
".",
"Any",
"arguments",
"that",
"is",
"required",
"but",
"no",
"supplied",
"will",
"be",
"defaulted",
"."
] | 0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca | https://github.com/ganglia/jmxetric/blob/0b21edb9bd75e0b2df8370ad1c77a1ea47f502ca/src/main/java/info/ganglia/jmxetric/XMLConfigurationService.java#L34-L42 |
2,279 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/TokenReader.java | TokenReader.readString | String readString() throws IOException {
StringBuilder sb = new StringBuilder(50);
// first char must be ":
char ch = reader.next();
if (ch != '\"') {
throw new JsonParseException("Expected \" but actual is: " + ch,
reader.readed);
}
for (;;) {
ch = reader.next();
if (ch == '\\') {
// escape: \" \\ \/ \b \f \n \r \t
char ech = reader.next();
switch (ech) {
case '\"':
sb.append('\"');
break;
case '\\':
sb.append('\\');
break;
case '/':
sb.append('/');
break;
case 'b':
sb.append('\b');
break;
case 'f':
sb.append('\f');
break;
case 'n':
sb.append('\n');
break;
case 'r':
sb.append('\r');
break;
case 't':
sb.append('\t');
break;
case 'u':
// read an unicode uXXXX:
int u = 0;
for (int i = 0; i < 4; i++) {
char uch = reader.next();
if (uch >= '0' && uch <= '9') {
u = (u << 4) + (uch - '0');
} else if (uch >= 'a' && uch <= 'f') {
u = (u << 4) + (uch - 'a') + 10;
} else if (uch >= 'A' && uch <= 'F') {
u = (u << 4) + (uch - 'A') + 10;
} else {
throw new JsonParseException("Unexpected char: " + uch,
reader.readed);
}
}
sb.append((char) u);
break;
default:
throw new JsonParseException("Unexpected char: " + ch,
reader.readed);
}
} else if (ch == '\"') {
// end of string:
break;
} else if (ch == '\r' || ch == '\n') {
throw new JsonParseException("Unexpected char: " + ch,
reader.readed);
} else {
sb.append(ch);
}
}
return sb.toString();
} | java | String readString() throws IOException {
StringBuilder sb = new StringBuilder(50);
// first char must be ":
char ch = reader.next();
if (ch != '\"') {
throw new JsonParseException("Expected \" but actual is: " + ch,
reader.readed);
}
for (;;) {
ch = reader.next();
if (ch == '\\') {
// escape: \" \\ \/ \b \f \n \r \t
char ech = reader.next();
switch (ech) {
case '\"':
sb.append('\"');
break;
case '\\':
sb.append('\\');
break;
case '/':
sb.append('/');
break;
case 'b':
sb.append('\b');
break;
case 'f':
sb.append('\f');
break;
case 'n':
sb.append('\n');
break;
case 'r':
sb.append('\r');
break;
case 't':
sb.append('\t');
break;
case 'u':
// read an unicode uXXXX:
int u = 0;
for (int i = 0; i < 4; i++) {
char uch = reader.next();
if (uch >= '0' && uch <= '9') {
u = (u << 4) + (uch - '0');
} else if (uch >= 'a' && uch <= 'f') {
u = (u << 4) + (uch - 'a') + 10;
} else if (uch >= 'A' && uch <= 'F') {
u = (u << 4) + (uch - 'A') + 10;
} else {
throw new JsonParseException("Unexpected char: " + uch,
reader.readed);
}
}
sb.append((char) u);
break;
default:
throw new JsonParseException("Unexpected char: " + ch,
reader.readed);
}
} else if (ch == '\"') {
// end of string:
break;
} else if (ch == '\r' || ch == '\n') {
throw new JsonParseException("Unexpected char: " + ch,
reader.readed);
} else {
sb.append(ch);
}
}
return sb.toString();
} | [
"String",
"readString",
"(",
")",
"throws",
"IOException",
"{",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
"50",
")",
";",
"// first char must be \":",
"char",
"ch",
"=",
"reader",
".",
"next",
"(",
")",
";",
"if",
"(",
"ch",
"!=",
"'",
"'",
")",
"{",
"throw",
"new",
"JsonParseException",
"(",
"\"Expected \\\" but actual is: \"",
"+",
"ch",
",",
"reader",
".",
"readed",
")",
";",
"}",
"for",
"(",
";",
";",
")",
"{",
"ch",
"=",
"reader",
".",
"next",
"(",
")",
";",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"// escape: \\\" \\\\ \\/ \\b \\f \\n \\r \\t",
"char",
"ech",
"=",
"reader",
".",
"next",
"(",
")",
";",
"switch",
"(",
"ech",
")",
"{",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"// read an unicode uXXXX:",
"int",
"u",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"char",
"uch",
"=",
"reader",
".",
"next",
"(",
")",
";",
"if",
"(",
"uch",
">=",
"'",
"'",
"&&",
"uch",
"<=",
"'",
"'",
")",
"{",
"u",
"=",
"(",
"u",
"<<",
"4",
")",
"+",
"(",
"uch",
"-",
"'",
"'",
")",
";",
"}",
"else",
"if",
"(",
"uch",
">=",
"'",
"'",
"&&",
"uch",
"<=",
"'",
"'",
")",
"{",
"u",
"=",
"(",
"u",
"<<",
"4",
")",
"+",
"(",
"uch",
"-",
"'",
"'",
")",
"+",
"10",
";",
"}",
"else",
"if",
"(",
"uch",
">=",
"'",
"'",
"&&",
"uch",
"<=",
"'",
"'",
")",
"{",
"u",
"=",
"(",
"u",
"<<",
"4",
")",
"+",
"(",
"uch",
"-",
"'",
"'",
")",
"+",
"10",
";",
"}",
"else",
"{",
"throw",
"new",
"JsonParseException",
"(",
"\"Unexpected char: \"",
"+",
"uch",
",",
"reader",
".",
"readed",
")",
";",
"}",
"}",
"sb",
".",
"append",
"(",
"(",
"char",
")",
"u",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"JsonParseException",
"(",
"\"Unexpected char: \"",
"+",
"ch",
",",
"reader",
".",
"readed",
")",
";",
"}",
"}",
"else",
"if",
"(",
"ch",
"==",
"'",
"'",
")",
"{",
"// end of string:",
"break",
";",
"}",
"else",
"if",
"(",
"ch",
"==",
"'",
"'",
"||",
"ch",
"==",
"'",
"'",
")",
"{",
"throw",
"new",
"JsonParseException",
"(",
"\"Unexpected char: \"",
"+",
"ch",
",",
"reader",
".",
"readed",
")",
";",
"}",
"else",
"{",
"sb",
".",
"append",
"(",
"ch",
")",
";",
"}",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] | read string like "a encoded \u0098 \" str" | [
"read",
"string",
"like",
"a",
"encoded",
"\\",
"u0098",
"\\",
"str"
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/TokenReader.java#L73-L144 |
2,280 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/TokenReader.java | TokenReader.string2Fraction | double string2Fraction(CharSequence cs, int readed) {
if (cs.length() > 16) {
throw new JsonParseException("Number string is too long.", readed);
}
double d = 0.0;
for (int i = 0; i < cs.length(); i++) {
int n = cs.charAt(i) - '0';
d = d + (n == 0 ? 0 : n / Math.pow(10, i + 1));
}
return d;
} | java | double string2Fraction(CharSequence cs, int readed) {
if (cs.length() > 16) {
throw new JsonParseException("Number string is too long.", readed);
}
double d = 0.0;
for (int i = 0; i < cs.length(); i++) {
int n = cs.charAt(i) - '0';
d = d + (n == 0 ? 0 : n / Math.pow(10, i + 1));
}
return d;
} | [
"double",
"string2Fraction",
"(",
"CharSequence",
"cs",
",",
"int",
"readed",
")",
"{",
"if",
"(",
"cs",
".",
"length",
"(",
")",
">",
"16",
")",
"{",
"throw",
"new",
"JsonParseException",
"(",
"\"Number string is too long.\"",
",",
"readed",
")",
";",
"}",
"double",
"d",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"cs",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"int",
"n",
"=",
"cs",
".",
"charAt",
"(",
"i",
")",
"-",
"'",
"'",
";",
"d",
"=",
"d",
"+",
"(",
"n",
"==",
"0",
"?",
"0",
":",
"n",
"/",
"Math",
".",
"pow",
"(",
"10",
",",
"i",
"+",
"1",
")",
")",
";",
"}",
"return",
"d",
";",
"}"
] | parse "0123" as 0.0123 | [
"parse",
"0123",
"as",
"0",
".",
"0123"
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/TokenReader.java#L329-L339 |
2,281 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/JsonBuilder.java | JsonBuilder.registerTypeAdapter | public <T> JsonBuilder registerTypeAdapter(Class<T> clazz, TypeAdapter<T> typeAdapter) {
typeAdapters.registerTypeAdapter(clazz, typeAdapter);
return this;
} | java | public <T> JsonBuilder registerTypeAdapter(Class<T> clazz, TypeAdapter<T> typeAdapter) {
typeAdapters.registerTypeAdapter(clazz, typeAdapter);
return this;
} | [
"public",
"<",
"T",
">",
"JsonBuilder",
"registerTypeAdapter",
"(",
"Class",
"<",
"T",
">",
"clazz",
",",
"TypeAdapter",
"<",
"T",
">",
"typeAdapter",
")",
"{",
"typeAdapters",
".",
"registerTypeAdapter",
"(",
"clazz",
",",
"typeAdapter",
")",
";",
"return",
"this",
";",
"}"
] | Register a TypeAdapter.
@param <T> Type to adapted-to.
@param clazz The adapted-to class.
@param typeAdapter The TypeAdapter instance.
@return JsonBuilder itself. | [
"Register",
"a",
"TypeAdapter",
"."
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/JsonBuilder.java#L38-L41 |
2,282 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/JsonBuilder.java | JsonBuilder.createReader | public JsonReader createReader(Reader reader) {
return new JsonReader(reader, jsonObjectFactory, jsonArrayFactory, objectMapper, typeAdapters);
} | java | public JsonReader createReader(Reader reader) {
return new JsonReader(reader, jsonObjectFactory, jsonArrayFactory, objectMapper, typeAdapters);
} | [
"public",
"JsonReader",
"createReader",
"(",
"Reader",
"reader",
")",
"{",
"return",
"new",
"JsonReader",
"(",
"reader",
",",
"jsonObjectFactory",
",",
"jsonArrayFactory",
",",
"objectMapper",
",",
"typeAdapters",
")",
";",
"}"
] | Create a JsonReader by providing a Reader.
@param reader The Reader object.
@return JsonReader object. | [
"Create",
"a",
"JsonReader",
"by",
"providing",
"a",
"Reader",
"."
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/JsonBuilder.java#L92-L94 |
2,283 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/JsonBuilder.java | JsonBuilder.createReader | public JsonReader createReader(InputStream input) {
try {
return createReader(new InputStreamReader(input, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} | java | public JsonReader createReader(InputStream input) {
try {
return createReader(new InputStreamReader(input, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} | [
"public",
"JsonReader",
"createReader",
"(",
"InputStream",
"input",
")",
"{",
"try",
"{",
"return",
"createReader",
"(",
"new",
"InputStreamReader",
"(",
"input",
",",
"\"UTF-8\"",
")",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] | Create a JsonReader by providing an InputStream.
@param input The InputStream object.
@return JsonReader object. | [
"Create",
"a",
"JsonReader",
"by",
"providing",
"an",
"InputStream",
"."
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/JsonBuilder.java#L102-L109 |
2,284 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/JsonBuilder.java | JsonBuilder.createWriter | public JsonWriter createWriter(OutputStream output) {
Writer writer = null;
try {
writer = new OutputStreamWriter(output, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new JsonWriter(writer, typeAdapters);
} | java | public JsonWriter createWriter(OutputStream output) {
Writer writer = null;
try {
writer = new OutputStreamWriter(output, "UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return new JsonWriter(writer, typeAdapters);
} | [
"public",
"JsonWriter",
"createWriter",
"(",
"OutputStream",
"output",
")",
"{",
"Writer",
"writer",
"=",
"null",
";",
"try",
"{",
"writer",
"=",
"new",
"OutputStreamWriter",
"(",
"output",
",",
"\"UTF-8\"",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"return",
"new",
"JsonWriter",
"(",
"writer",
",",
"typeAdapters",
")",
";",
"}"
] | Create a JsonWriter that write JSON to specified OutputStream.
@param output The OutputStream object.
@return JsonWriter object. | [
"Create",
"a",
"JsonWriter",
"that",
"write",
"JSON",
"to",
"specified",
"OutputStream",
"."
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/JsonBuilder.java#L136-L145 |
2,285 | michaelliao/jsonstream | src/main/java/com/itranswarp/jsonstream/PropertyUtils.java | PropertyUtils.getSetterName | private static String getSetterName(Method m) {
String name = m.getName();
if (name.startsWith("set") && (name.length() >= 4)
&& m.getReturnType().equals(void.class)
&& (m.getParameterTypes().length == 1)
) {
return Character.toLowerCase(name.charAt(3)) + name.substring(4);
}
return null;
} | java | private static String getSetterName(Method m) {
String name = m.getName();
if (name.startsWith("set") && (name.length() >= 4)
&& m.getReturnType().equals(void.class)
&& (m.getParameterTypes().length == 1)
) {
return Character.toLowerCase(name.charAt(3)) + name.substring(4);
}
return null;
} | [
"private",
"static",
"String",
"getSetterName",
"(",
"Method",
"m",
")",
"{",
"String",
"name",
"=",
"m",
".",
"getName",
"(",
")",
";",
"if",
"(",
"name",
".",
"startsWith",
"(",
"\"set\"",
")",
"&&",
"(",
"name",
".",
"length",
"(",
")",
">=",
"4",
")",
"&&",
"m",
".",
"getReturnType",
"(",
")",
".",
"equals",
"(",
"void",
".",
"class",
")",
"&&",
"(",
"m",
".",
"getParameterTypes",
"(",
")",
".",
"length",
"==",
"1",
")",
")",
"{",
"return",
"Character",
".",
"toLowerCase",
"(",
"name",
".",
"charAt",
"(",
"3",
")",
")",
"+",
"name",
".",
"substring",
"(",
"4",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get setter name. "setName" -> "name"
@param m Method object.
@return Property name of this setter. | [
"Get",
"setter",
"name",
".",
"setName",
"-",
">",
"name"
] | 50adcff2e1293e655462eef5fc5f1b59277de514 | https://github.com/michaelliao/jsonstream/blob/50adcff2e1293e655462eef5fc5f1b59277de514/src/main/java/com/itranswarp/jsonstream/PropertyUtils.java#L42-L51 |
2,286 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/animations/Fade.java | Fade.remove | public void remove(final View view) {
if (view.getParent() instanceof ViewGroup) {
final ViewGroup parent = (ViewGroup) view.getParent();
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(0f).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
parent.removeView(view);
view.setAlpha(1);
view.animate().setListener(null);
}
});
}
} | java | public void remove(final View view) {
if (view.getParent() instanceof ViewGroup) {
final ViewGroup parent = (ViewGroup) view.getParent();
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(0f).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
parent.removeView(view);
view.setAlpha(1);
view.animate().setListener(null);
}
});
}
} | [
"public",
"void",
"remove",
"(",
"final",
"View",
"view",
")",
"{",
"if",
"(",
"view",
".",
"getParent",
"(",
")",
"instanceof",
"ViewGroup",
")",
"{",
"final",
"ViewGroup",
"parent",
"=",
"(",
"ViewGroup",
")",
"view",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"durationSet",
")",
"{",
"view",
".",
"animate",
"(",
")",
".",
"setDuration",
"(",
"duration",
")",
";",
"}",
"view",
".",
"animate",
"(",
")",
".",
"alpha",
"(",
"0f",
")",
".",
"setListener",
"(",
"new",
"AnimatorListenerAdapter",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"onAnimationEnd",
"(",
"Animator",
"animation",
")",
"{",
"parent",
".",
"removeView",
"(",
"view",
")",
";",
"view",
".",
"setAlpha",
"(",
"1",
")",
";",
"view",
".",
"animate",
"(",
")",
".",
"setListener",
"(",
"null",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Fades out the given view and then removes in from its parent.
If the view is not currently parented, the method simply returns without doing anything.
@param view The view that will be faded and removed. | [
"Fades",
"out",
"the",
"given",
"view",
"and",
"then",
"removes",
"in",
"from",
"its",
"parent",
".",
"If",
"the",
"view",
"is",
"not",
"currently",
"parented",
"the",
"method",
"simply",
"returns",
"without",
"doing",
"anything",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/animations/Fade.java#L36-L51 |
2,287 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/animations/Fade.java | Fade.add | public void add(final View view, final ViewGroup parent, int index) {
if (view.getParent() == null) {
view.setAlpha(0);
parent.addView(view, index);
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(1);
}
} | java | public void add(final View view, final ViewGroup parent, int index) {
if (view.getParent() == null) {
view.setAlpha(0);
parent.addView(view, index);
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(1);
}
} | [
"public",
"void",
"add",
"(",
"final",
"View",
"view",
",",
"final",
"ViewGroup",
"parent",
",",
"int",
"index",
")",
"{",
"if",
"(",
"view",
".",
"getParent",
"(",
")",
"==",
"null",
")",
"{",
"view",
".",
"setAlpha",
"(",
"0",
")",
";",
"parent",
".",
"addView",
"(",
"view",
",",
"index",
")",
";",
"if",
"(",
"durationSet",
")",
"{",
"view",
".",
"animate",
"(",
")",
".",
"setDuration",
"(",
"duration",
")",
";",
"}",
"view",
".",
"animate",
"(",
")",
".",
"alpha",
"(",
"1",
")",
";",
"}",
"}"
] | Adds a view to the specified parent at the specified index in the parent's
child list and then fades in the view. The view must
not currently be parented - if its parent is not null, the method returns without
doing anything.
@param view The view to be added
@param parent The parent to which the view is added
@param index The index at which the view is added in the parent's child list | [
"Adds",
"a",
"view",
"to",
"the",
"specified",
"parent",
"at",
"the",
"specified",
"index",
"in",
"the",
"parent",
"s",
"child",
"list",
"and",
"then",
"fades",
"in",
"the",
"view",
".",
"The",
"view",
"must",
"not",
"currently",
"be",
"parented",
"-",
"if",
"its",
"parent",
"is",
"not",
"null",
"the",
"method",
"returns",
"without",
"doing",
"anything",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/animations/Fade.java#L76-L85 |
2,288 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/animations/Fade.java | Fade.show | public void show(final View view) {
if (view.getVisibility() != View.VISIBLE) {
view.setAlpha(0);
view.setVisibility(View.VISIBLE);
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(1);
}
} | java | public void show(final View view) {
if (view.getVisibility() != View.VISIBLE) {
view.setAlpha(0);
view.setVisibility(View.VISIBLE);
if (durationSet) {
view.animate().setDuration(duration);
}
view.animate().alpha(1);
}
} | [
"public",
"void",
"show",
"(",
"final",
"View",
"view",
")",
"{",
"if",
"(",
"view",
".",
"getVisibility",
"(",
")",
"!=",
"View",
".",
"VISIBLE",
")",
"{",
"view",
".",
"setAlpha",
"(",
"0",
")",
";",
"view",
".",
"setVisibility",
"(",
"View",
".",
"VISIBLE",
")",
";",
"if",
"(",
"durationSet",
")",
"{",
"view",
".",
"animate",
"(",
")",
".",
"setDuration",
"(",
"duration",
")",
";",
"}",
"view",
".",
"animate",
"(",
")",
".",
"alpha",
"(",
"1",
")",
";",
"}",
"}"
] | Sets the visibility of the specified view to View.VISIBLE and then fades it in. If the
view is already visible, the method will return without doing anything.
@param view The view to be faded in | [
"Sets",
"the",
"visibility",
"of",
"the",
"specified",
"view",
"to",
"View",
".",
"VISIBLE",
"and",
"then",
"fades",
"it",
"in",
".",
"If",
"the",
"view",
"is",
"already",
"visible",
"the",
"method",
"will",
"return",
"without",
"doing",
"anything",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/animations/Fade.java#L130-L139 |
2,289 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/timer.java | timer.start | public static long start(String key) {
if (key.isEmpty()) {
throw new InvalidKeyForTimeStampException();
}
// current timestamp
long timestamp = QuickUtils.date.getCurrentTimeInMiliseconds();
// save the timestamp
QuickUtils.prefs.save(TIMER_PREFIX + key, timestamp);
return timestamp;
} | java | public static long start(String key) {
if (key.isEmpty()) {
throw new InvalidKeyForTimeStampException();
}
// current timestamp
long timestamp = QuickUtils.date.getCurrentTimeInMiliseconds();
// save the timestamp
QuickUtils.prefs.save(TIMER_PREFIX + key, timestamp);
return timestamp;
} | [
"public",
"static",
"long",
"start",
"(",
"String",
"key",
")",
"{",
"if",
"(",
"key",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidKeyForTimeStampException",
"(",
")",
";",
"}",
"// current timestamp",
"long",
"timestamp",
"=",
"QuickUtils",
".",
"date",
".",
"getCurrentTimeInMiliseconds",
"(",
")",
";",
"// save the timestamp",
"QuickUtils",
".",
"prefs",
".",
"save",
"(",
"TIMER_PREFIX",
"+",
"key",
",",
"timestamp",
")",
";",
"return",
"timestamp",
";",
"}"
] | Start counting time
@param key the key for the timestamp
@return the timestamp | [
"Start",
"counting",
"time"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/timer.java#L24-L37 |
2,290 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/timer.java | timer.resetAllTimestamps | public static void resetAllTimestamps() {
Map<String, ?> allEntries = QuickUtils.prefs.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
if (entry.getKey().startsWith(TIMER_PREFIX)) {
QuickUtils.prefs.remove(entry.getKey());
}
}
} | java | public static void resetAllTimestamps() {
Map<String, ?> allEntries = QuickUtils.prefs.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
if (entry.getKey().startsWith(TIMER_PREFIX)) {
QuickUtils.prefs.remove(entry.getKey());
}
}
} | [
"public",
"static",
"void",
"resetAllTimestamps",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"?",
">",
"allEntries",
"=",
"QuickUtils",
".",
"prefs",
".",
"getAll",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"?",
">",
"entry",
":",
"allEntries",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"startsWith",
"(",
"TIMER_PREFIX",
")",
")",
"{",
"QuickUtils",
".",
"prefs",
".",
"remove",
"(",
"entry",
".",
"getKey",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Resets all the timestamps | [
"Resets",
"all",
"the",
"timestamps"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/timer.java#L107-L114 |
2,291 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/math.java | math.round | public static double round(double toBeRounded, int digits) {
if (digits < 0) {
QuickUtils.log.e("must be greater than 0");
return 0;
}
String formater = "";
for (int i = 0; i < digits; i++) {
formater += "#";
}
DecimalFormat twoDForm = new DecimalFormat("#." + formater, new DecimalFormatSymbols(Locale.US));
return Double.valueOf(twoDForm.format(toBeRounded));
} | java | public static double round(double toBeRounded, int digits) {
if (digits < 0) {
QuickUtils.log.e("must be greater than 0");
return 0;
}
String formater = "";
for (int i = 0; i < digits; i++) {
formater += "#";
}
DecimalFormat twoDForm = new DecimalFormat("#." + formater, new DecimalFormatSymbols(Locale.US));
return Double.valueOf(twoDForm.format(toBeRounded));
} | [
"public",
"static",
"double",
"round",
"(",
"double",
"toBeRounded",
",",
"int",
"digits",
")",
"{",
"if",
"(",
"digits",
"<",
"0",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"must be greater than 0\"",
")",
";",
"return",
"0",
";",
"}",
"String",
"formater",
"=",
"\"\"",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"digits",
";",
"i",
"++",
")",
"{",
"formater",
"+=",
"\"#\"",
";",
"}",
"DecimalFormat",
"twoDForm",
"=",
"new",
"DecimalFormat",
"(",
"\"#.\"",
"+",
"formater",
",",
"new",
"DecimalFormatSymbols",
"(",
"Locale",
".",
"US",
")",
")",
";",
"return",
"Double",
".",
"valueOf",
"(",
"twoDForm",
".",
"format",
"(",
"toBeRounded",
")",
")",
";",
"}"
] | Rounds a double value to a certain number of digits
@param toBeRounded
number to be rounded
@param digits
number of digits to be rounded
@return the double rounded | [
"Rounds",
"a",
"double",
"value",
"to",
"a",
"certain",
"number",
"of",
"digits"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/math.java#L31-L43 |
2,292 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/math.java | math.getRandomInteger | public static int getRandomInteger(int min, int max) {
Random r = new Random();
return r.nextInt(max - min + 1) + min;
} | java | public static int getRandomInteger(int min, int max) {
Random r = new Random();
return r.nextInt(max - min + 1) + min;
} | [
"public",
"static",
"int",
"getRandomInteger",
"(",
"int",
"min",
",",
"int",
"max",
")",
"{",
"Random",
"r",
"=",
"new",
"Random",
"(",
")",
";",
"return",
"r",
".",
"nextInt",
"(",
"max",
"-",
"min",
"+",
"1",
")",
"+",
"min",
";",
"}"
] | Returns a random integer between MIN inclusive and MAX inclusive.
@param min
value inclusive
@param max
value inclusive
@return an int between MIN inclusive and MAX exclusive. | [
"Returns",
"a",
"random",
"integer",
"between",
"MIN",
"inclusive",
"and",
"MAX",
"inclusive",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/math.java#L98-L101 |
2,293 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/math.java | math.getRandomDouble | public static double getRandomDouble(double min, double max) {
Random r = new Random();
return min + (max - min) * r.nextDouble();
} | java | public static double getRandomDouble(double min, double max) {
Random r = new Random();
return min + (max - min) * r.nextDouble();
} | [
"public",
"static",
"double",
"getRandomDouble",
"(",
"double",
"min",
",",
"double",
"max",
")",
"{",
"Random",
"r",
"=",
"new",
"Random",
"(",
")",
";",
"return",
"min",
"+",
"(",
"max",
"-",
"min",
")",
"*",
"r",
".",
"nextDouble",
"(",
")",
";",
"}"
] | Returns a random double between MIN inclusive and MAX inclusive.
@param min
value inclusive
@param max
value inclusive
@return an int between 0 inclusive and MAX exclusive. | [
"Returns",
"a",
"random",
"double",
"between",
"MIN",
"inclusive",
"and",
"MAX",
"inclusive",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/math.java#L125-L128 |
2,294 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/math.java | math.getRandomNumber | public static int getRandomNumber(int min, int max) {
Random r = new Random();
return r.nextInt(max - min + 1) + min;
} | java | public static int getRandomNumber(int min, int max) {
Random r = new Random();
return r.nextInt(max - min + 1) + min;
} | [
"public",
"static",
"int",
"getRandomNumber",
"(",
"int",
"min",
",",
"int",
"max",
")",
"{",
"Random",
"r",
"=",
"new",
"Random",
"(",
")",
";",
"return",
"r",
".",
"nextInt",
"(",
"max",
"-",
"min",
"+",
"1",
")",
"+",
"min",
";",
"}"
] | Returns a random number between MIN inclusive and MAX exclusive.
@param min
value inclusive
@param max
value exclusive
@return an int between MIN inclusive and MAX exclusive. | [
"Returns",
"a",
"random",
"number",
"between",
"MIN",
"inclusive",
"and",
"MAX",
"exclusive",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/math.java#L386-L389 |
2,295 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/math.java | math.truncate | public static double truncate(double value, int places) {
if (places < 0) {
throw new IllegalArgumentException();
}
long factor = (long) java.lang.Math.pow(10, places);
value = value * factor;
long tmp = (long) value;
return (double) tmp / factor;
} | java | public static double truncate(double value, int places) {
if (places < 0) {
throw new IllegalArgumentException();
}
long factor = (long) java.lang.Math.pow(10, places);
value = value * factor;
long tmp = (long) value;
return (double) tmp / factor;
} | [
"public",
"static",
"double",
"truncate",
"(",
"double",
"value",
",",
"int",
"places",
")",
"{",
"if",
"(",
"places",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"}",
"long",
"factor",
"=",
"(",
"long",
")",
"java",
".",
"lang",
".",
"Math",
".",
"pow",
"(",
"10",
",",
"places",
")",
";",
"value",
"=",
"value",
"*",
"factor",
";",
"long",
"tmp",
"=",
"(",
"long",
")",
"value",
";",
"return",
"(",
"double",
")",
"tmp",
"/",
"factor",
";",
"}"
] | Truncates a value
@param value - value to be truncated
@param places - decimal places
@return | [
"Truncates",
"a",
"value"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/math.java#L397-L406 |
2,296 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/security.java | security.privateBase64Encoder | private static String privateBase64Encoder(String toEncode, int flags) {
byte[] data = null;
try {
data = toEncode.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
if (flags == -1) {
flags = Base64.DEFAULT;
}
return Base64.encodeToString(data, flags);
} | java | private static String privateBase64Encoder(String toEncode, int flags) {
byte[] data = null;
try {
data = toEncode.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
if (flags == -1) {
flags = Base64.DEFAULT;
}
return Base64.encodeToString(data, flags);
} | [
"private",
"static",
"String",
"privateBase64Encoder",
"(",
"String",
"toEncode",
",",
"int",
"flags",
")",
"{",
"byte",
"[",
"]",
"data",
"=",
"null",
";",
"try",
"{",
"data",
"=",
"toEncode",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e1",
")",
"{",
"e1",
".",
"printStackTrace",
"(",
")",
";",
"}",
"if",
"(",
"flags",
"==",
"-",
"1",
")",
"{",
"flags",
"=",
"Base64",
".",
"DEFAULT",
";",
"}",
"return",
"Base64",
".",
"encodeToString",
"(",
"data",
",",
"flags",
")",
";",
"}"
] | private Encoder in base64
@param toEncode
String to be encoded
@param flags
flags to encode the String
@return encoded String in base64 | [
"private",
"Encoder",
"in",
"base64"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/security.java#L53-L66 |
2,297 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/security.java | security.privateBase64Decoder | private static String privateBase64Decoder(String decode, int flags) {
if (flags == -1) {
flags = Base64.DEFAULT;
}
byte[] data1 = Base64.decode(decode, flags);
String decodedBase64 = null;
try {
decodedBase64 = new String(data1, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return decodedBase64;
} | java | private static String privateBase64Decoder(String decode, int flags) {
if (flags == -1) {
flags = Base64.DEFAULT;
}
byte[] data1 = Base64.decode(decode, flags);
String decodedBase64 = null;
try {
decodedBase64 = new String(data1, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return decodedBase64;
} | [
"private",
"static",
"String",
"privateBase64Decoder",
"(",
"String",
"decode",
",",
"int",
"flags",
")",
"{",
"if",
"(",
"flags",
"==",
"-",
"1",
")",
"{",
"flags",
"=",
"Base64",
".",
"DEFAULT",
";",
"}",
"byte",
"[",
"]",
"data1",
"=",
"Base64",
".",
"decode",
"(",
"decode",
",",
"flags",
")",
";",
"String",
"decodedBase64",
"=",
"null",
";",
"try",
"{",
"decodedBase64",
"=",
"new",
"String",
"(",
"data1",
",",
"\"UTF-8\"",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"return",
"decodedBase64",
";",
"}"
] | Private decoder in base64
@param toDecode
String to be encoded
@param flags
flags to decode the String
@return decoded String in base64 | [
"Private",
"decoder",
"in",
"base64"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/security.java#L101-L115 |
2,298 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/security.java | security.calculateMD5 | public static String calculateMD5(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Huh, MD5 should be supported?", e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e);
}
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
int i = (b & 0xFF);
if (i < 0x10)
hex.append('0');
hex.append(Integer.toHexString(i));
}
return hex.toString();
} | java | public static String calculateMD5(String string) {
byte[] hash;
try {
hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Huh, MD5 should be supported?", e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e);
}
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
int i = (b & 0xFF);
if (i < 0x10)
hex.append('0');
hex.append(Integer.toHexString(i));
}
return hex.toString();
} | [
"public",
"static",
"String",
"calculateMD5",
"(",
"String",
"string",
")",
"{",
"byte",
"[",
"]",
"hash",
";",
"try",
"{",
"hash",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"MD5\"",
")",
".",
"digest",
"(",
"string",
".",
"getBytes",
"(",
"\"UTF-8\"",
")",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Huh, MD5 should be supported?\"",
",",
"e",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Huh, UTF-8 should be supported?\"",
",",
"e",
")",
";",
"}",
"StringBuilder",
"hex",
"=",
"new",
"StringBuilder",
"(",
"hash",
".",
"length",
"*",
"2",
")",
";",
"for",
"(",
"byte",
"b",
":",
"hash",
")",
"{",
"int",
"i",
"=",
"(",
"b",
"&",
"0xFF",
")",
";",
"if",
"(",
"i",
"<",
"0x10",
")",
"hex",
".",
"append",
"(",
"'",
"'",
")",
";",
"hex",
".",
"append",
"(",
"Integer",
".",
"toHexString",
"(",
"i",
")",
")",
";",
"}",
"return",
"hex",
".",
"toString",
"(",
")",
";",
"}"
] | Calculate the MD5 of a given String
@param string
String to be MD5'ed
@return MD5'ed String | [
"Calculate",
"the",
"MD5",
"of",
"a",
"given",
"String"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/security.java#L124-L145 |
2,299 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/security.java | security.calculateSHA1 | public static String calculateSHA1(String string) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
QuickUtils.log.e("NoSuchAlgorithmException", e);
}
try {
md.update(string.getBytes("iso-8859-1"), 0, string.length());
} catch (UnsupportedEncodingException e) {
QuickUtils.log.e("UnsupportedEncodingException", e);
}
byte[] sha1hash = md.digest();
return convertToHex(sha1hash);
} | java | public static String calculateSHA1(String string) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
QuickUtils.log.e("NoSuchAlgorithmException", e);
}
try {
md.update(string.getBytes("iso-8859-1"), 0, string.length());
} catch (UnsupportedEncodingException e) {
QuickUtils.log.e("UnsupportedEncodingException", e);
}
byte[] sha1hash = md.digest();
return convertToHex(sha1hash);
} | [
"public",
"static",
"String",
"calculateSHA1",
"(",
"String",
"string",
")",
"{",
"MessageDigest",
"md",
"=",
"null",
";",
"try",
"{",
"md",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"SHA-1\"",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"NoSuchAlgorithmException\"",
",",
"e",
")",
";",
"}",
"try",
"{",
"md",
".",
"update",
"(",
"string",
".",
"getBytes",
"(",
"\"iso-8859-1\"",
")",
",",
"0",
",",
"string",
".",
"length",
"(",
")",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"UnsupportedEncodingException\"",
",",
"e",
")",
";",
"}",
"byte",
"[",
"]",
"sha1hash",
"=",
"md",
".",
"digest",
"(",
")",
";",
"return",
"convertToHex",
"(",
"sha1hash",
")",
";",
"}"
] | Calculate the SHA-1 of a given String
@param string
String to be SHA1'ed
@return SHA1'ed String | [
"Calculate",
"the",
"SHA",
"-",
"1",
"of",
"a",
"given",
"String"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/security.java#L154-L169 |
Subsets and Splits