repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
spockframework/spock | spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java | GenericTypeReflector.capture | public static Type capture(Type type) {
VarMap varMap = new VarMap();
List<CaptureTypeImpl> toInit = new ArrayList<>();
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType)type;
Class<?> clazz = (Class<?>)pType.getRawType();
Type[] arguments = pType.getActualTypeArguments();
TypeVariable<?>[] vars = clazz.getTypeParameters();
Type[] capturedArguments = new Type[arguments.length];
assert arguments.length == vars.length;
for (int i = 0; i < arguments.length; i++) {
Type argument = arguments[i];
if (argument instanceof WildcardType) {
CaptureTypeImpl captured = new CaptureTypeImpl((WildcardType)argument, vars[i]);
argument = captured;
toInit.add(captured);
}
capturedArguments[i] = argument;
varMap.add(vars[i], argument);
}
for (CaptureTypeImpl captured : toInit) {
captured.init(varMap);
}
Type ownerType = (pType.getOwnerType() == null) ? null : capture(pType.getOwnerType());
return new ParameterizedTypeImpl(clazz, capturedArguments, ownerType);
} else {
return type;
}
} | java | public static Type capture(Type type) {
VarMap varMap = new VarMap();
List<CaptureTypeImpl> toInit = new ArrayList<>();
if (type instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType)type;
Class<?> clazz = (Class<?>)pType.getRawType();
Type[] arguments = pType.getActualTypeArguments();
TypeVariable<?>[] vars = clazz.getTypeParameters();
Type[] capturedArguments = new Type[arguments.length];
assert arguments.length == vars.length;
for (int i = 0; i < arguments.length; i++) {
Type argument = arguments[i];
if (argument instanceof WildcardType) {
CaptureTypeImpl captured = new CaptureTypeImpl((WildcardType)argument, vars[i]);
argument = captured;
toInit.add(captured);
}
capturedArguments[i] = argument;
varMap.add(vars[i], argument);
}
for (CaptureTypeImpl captured : toInit) {
captured.init(varMap);
}
Type ownerType = (pType.getOwnerType() == null) ? null : capture(pType.getOwnerType());
return new ParameterizedTypeImpl(clazz, capturedArguments, ownerType);
} else {
return type;
}
} | [
"public",
"static",
"Type",
"capture",
"(",
"Type",
"type",
")",
"{",
"VarMap",
"varMap",
"=",
"new",
"VarMap",
"(",
")",
";",
"List",
"<",
"CaptureTypeImpl",
">",
"toInit",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"type",
"instanceof",... | Applies capture conversion to the given type. | [
"Applies",
"capture",
"conversion",
"to",
"the",
"given",
"type",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java#L364-L392 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java | GenericTypeReflector.getTypeName | public static String getTypeName(Type type) {
if(type instanceof Class) {
Class<?> clazz = (Class<?>) type;
return clazz.isArray() ? (getTypeName(clazz.getComponentType()) + "[]") : clazz.getName();
} else {
return type.toString();
}
} | java | public static String getTypeName(Type type) {
if(type instanceof Class) {
Class<?> clazz = (Class<?>) type;
return clazz.isArray() ? (getTypeName(clazz.getComponentType()) + "[]") : clazz.getName();
} else {
return type.toString();
}
} | [
"public",
"static",
"String",
"getTypeName",
"(",
"Type",
"type",
")",
"{",
"if",
"(",
"type",
"instanceof",
"Class",
")",
"{",
"Class",
"<",
"?",
">",
"clazz",
"=",
"(",
"Class",
"<",
"?",
">",
")",
"type",
";",
"return",
"clazz",
".",
"isArray",
... | Returns the display name of a Type. | [
"Returns",
"the",
"display",
"name",
"of",
"a",
"Type",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java#L397-L404 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java | GenericTypeReflector.buildUpperBoundClassAndInterfaces | private static void buildUpperBoundClassAndInterfaces(Type type, Set<Class<?>> result) {
if (type instanceof ParameterizedType || type instanceof Class<?>) {
result.add(erase(type));
return;
}
for (Type superType: getExactDirectSuperTypes(type)) {
buildUpperBoundClassAndInterfaces(superType, result);
}
} | java | private static void buildUpperBoundClassAndInterfaces(Type type, Set<Class<?>> result) {
if (type instanceof ParameterizedType || type instanceof Class<?>) {
result.add(erase(type));
return;
}
for (Type superType: getExactDirectSuperTypes(type)) {
buildUpperBoundClassAndInterfaces(superType, result);
}
} | [
"private",
"static",
"void",
"buildUpperBoundClassAndInterfaces",
"(",
"Type",
"type",
",",
"Set",
"<",
"Class",
"<",
"?",
">",
">",
"result",
")",
"{",
"if",
"(",
"type",
"instanceof",
"ParameterizedType",
"||",
"type",
"instanceof",
"Class",
"<",
"?",
">",... | Helper method for getUpperBoundClassAndInterfaces, adding the result to the given set. | [
"Helper",
"method",
"for",
"getUpperBoundClassAndInterfaces",
"adding",
"the",
"result",
"to",
"the",
"given",
"set",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/gentyref/GenericTypeReflector.java#L431-L440 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/MockingApi.java | MockingApi.Mock | @Beta
public <T> T Mock(
@NamedParams({
@NamedParam(value = "name", type = String.class),
@NamedParam(value = "additionalInterfaces", type = List.class),
@NamedParam(value = "defaultResponse", type = IDefaultResponse.class),
@NamedParam(value = "verified", type = Boolean.class),
@NamedParam(value = "useObjenesis", type = Boolean.class)
})
Map<String, Object> options) {
invalidMockCreation();
return null;
} | java | @Beta
public <T> T Mock(
@NamedParams({
@NamedParam(value = "name", type = String.class),
@NamedParam(value = "additionalInterfaces", type = List.class),
@NamedParam(value = "defaultResponse", type = IDefaultResponse.class),
@NamedParam(value = "verified", type = Boolean.class),
@NamedParam(value = "useObjenesis", type = Boolean.class)
})
Map<String, Object> options) {
invalidMockCreation();
return null;
} | [
"@",
"Beta",
"public",
"<",
"T",
">",
"T",
"Mock",
"(",
"@",
"NamedParams",
"(",
"{",
"@",
"NamedParam",
"(",
"value",
"=",
"\"name\"",
",",
"type",
"=",
"String",
".",
"class",
")",
",",
"@",
"NamedParam",
"(",
"value",
"=",
"\"additionalInterfaces\""... | Creates a mock with the specified options whose type and name are inferred from the left-hand side of the
enclosing variable assignment.
Example:
<pre>
Person person = Mock(name: "myPerson") // type is Person.class, name is "myPerson"
</pre>
@param options optional options for creating the mock
@return a mock with the specified options whose type and name are inferred from the left-hand side of the
enclosing variable assignment | [
"Creates",
"a",
"mock",
"with",
"the",
"specified",
"options",
"whose",
"type",
"and",
"name",
"are",
"inferred",
"from",
"the",
"left",
"-",
"hand",
"side",
"of",
"the",
"enclosing",
"variable",
"assignment",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/MockingApi.java#L167-L179 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/MockingApi.java | MockingApi.Mock | @Beta
public <T> T Mock(Map<String, Object> options, Closure interactions) {
invalidMockCreation();
return null;
} | java | @Beta
public <T> T Mock(Map<String, Object> options, Closure interactions) {
invalidMockCreation();
return null;
} | [
"@",
"Beta",
"public",
"<",
"T",
">",
"T",
"Mock",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"options",
",",
"Closure",
"interactions",
")",
"{",
"invalidMockCreation",
"(",
")",
";",
"return",
"null",
";",
"}"
] | Creates a mock with the specified options and interactions whose type and name are inferred
from the left-hand side of the enclosing assignment.
Example:
<pre>
// type is Person.class, name is "myPerson", returns hard-coded value for {@code name}, expects one call to {@code sing()}
Person person = Mock(name: "myPerson") {
name << "Fred"
1 * sing()
}
</pre>
@param options optional options for creating the mock
@param interactions a description of the mock's interactions
@return a mock with the specified options and interactions whose type and name are inferred
from the left-hand side of the enclosing assignment | [
"Creates",
"a",
"mock",
"with",
"the",
"specified",
"options",
"and",
"interactions",
"whose",
"type",
"and",
"name",
"are",
"inferred",
"from",
"the",
"left",
"-",
"hand",
"side",
"of",
"the",
"enclosing",
"assignment",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/MockingApi.java#L278-L282 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/MockingApi.java | MockingApi.Stub | @Override
@Beta
public <T> T Stub(Class<T> type) {
invalidMockCreation();
return null;
} | java | @Override
@Beta
public <T> T Stub(Class<T> type) {
invalidMockCreation();
return null;
} | [
"@",
"Override",
"@",
"Beta",
"public",
"<",
"T",
">",
"T",
"Stub",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"invalidMockCreation",
"(",
")",
";",
"return",
"null",
";",
"}"
] | Creates a stub with the specified type. If enclosed in a variable assignment, the variable name will be
used as the stub's name.
Example:
<pre>
def person = Stub(Person) // type is Person.class, name is "person"
</pre>
@param type the interface or class type of the stub
@param <T> the interface or class type of the stub
@return a stub with the specified type | [
"Creates",
"a",
"stub",
"with",
"the",
"specified",
"type",
".",
"If",
"enclosed",
"in",
"a",
"variable",
"assignment",
"the",
"variable",
"name",
"will",
"be",
"used",
"as",
"the",
"stub",
"s",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/MockingApi.java#L416-L421 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/MockingApi.java | MockingApi.Spy | @Override
@Beta
public <T> T Spy(Class<T> type) {
invalidMockCreation();
return null;
} | java | @Override
@Beta
public <T> T Spy(Class<T> type) {
invalidMockCreation();
return null;
} | [
"@",
"Override",
"@",
"Beta",
"public",
"<",
"T",
">",
"T",
"Spy",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"invalidMockCreation",
"(",
")",
";",
"return",
"null",
";",
"}"
] | Creates a spy with the specified type. If enclosed in a variable assignment, the variable name will be
used as the spy's name.
Example:
<pre>
def person = Spy(Person) // type is Person.class, name is "person"
</pre>
@param type the class type of the spy
@param <T> the class type of the spy
@return a spy with the specified type | [
"Creates",
"a",
"spy",
"with",
"the",
"specified",
"type",
".",
"If",
"enclosed",
"in",
"a",
"variable",
"assignment",
"the",
"variable",
"name",
"will",
"be",
"used",
"as",
"the",
"spy",
"s",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/MockingApi.java#L645-L650 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/mock/constraint/PositionalArgumentListConstraint.java | PositionalArgumentListConstraint.hasExpandableVarArgs | private boolean hasExpandableVarArgs(IMockMethod method, List<Object> args) {
List<Class<?>> paramTypes = method.getParameterTypes();
return !paramTypes.isEmpty()
&& CollectionUtil.getLastElement(paramTypes).isArray()
&& CollectionUtil.getLastElement(args) != null;
} | java | private boolean hasExpandableVarArgs(IMockMethod method, List<Object> args) {
List<Class<?>> paramTypes = method.getParameterTypes();
return !paramTypes.isEmpty()
&& CollectionUtil.getLastElement(paramTypes).isArray()
&& CollectionUtil.getLastElement(args) != null;
} | [
"private",
"boolean",
"hasExpandableVarArgs",
"(",
"IMockMethod",
"method",
",",
"List",
"<",
"Object",
">",
"args",
")",
"{",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"paramTypes",
"=",
"method",
".",
"getParameterTypes",
"(",
")",
";",
"return",
"!",
... | Tells if the given method call has expandable varargs. Note that Groovy
supports vararg syntax for all methods whose last parameter is of array type. | [
"Tells",
"if",
"the",
"given",
"method",
"call",
"has",
"expandable",
"varargs",
".",
"Note",
"that",
"Groovy",
"supports",
"vararg",
"syntax",
"for",
"all",
"methods",
"whose",
"last",
"parameter",
"is",
"of",
"array",
"type",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/mock/constraint/PositionalArgumentListConstraint.java#L80-L85 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/util/inspector/AstInspector.java | AstInspector.load | public void load(@Language("Groovy") String sourceText) throws CompilationFailedException {
reset();
try {
classLoader.parseClass(sourceText);
} catch (AstSuccessfullyCaptured e) {
indexAstNodes();
return;
}
throw new AstInspectorException("internal error");
} | java | public void load(@Language("Groovy") String sourceText) throws CompilationFailedException {
reset();
try {
classLoader.parseClass(sourceText);
} catch (AstSuccessfullyCaptured e) {
indexAstNodes();
return;
}
throw new AstInspectorException("internal error");
} | [
"public",
"void",
"load",
"(",
"@",
"Language",
"(",
"\"Groovy\"",
")",
"String",
"sourceText",
")",
"throws",
"CompilationFailedException",
"{",
"reset",
"(",
")",
";",
"try",
"{",
"classLoader",
".",
"parseClass",
"(",
"sourceText",
")",
";",
"}",
"catch",... | Compiles the specified source text up to the configured compile
phase and stores the resulting AST for subsequent inspection.
@param sourceText the source text to compile
@throws CompilationFailedException if an error occurs during compilation | [
"Compiles",
"the",
"specified",
"source",
"text",
"up",
"to",
"the",
"configured",
"compile",
"phase",
"and",
"stores",
"the",
"resulting",
"AST",
"for",
"subsequent",
"inspection",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/util/inspector/AstInspector.java#L137-L148 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/util/inspector/AstInspector.java | AstInspector.load | public void load(File sourceFile) throws CompilationFailedException {
reset();
try {
classLoader.parseClass(sourceFile);
} catch (IOException e) {
throw new AstInspectorException("cannot read source file", e);
} catch (AstSuccessfullyCaptured e) {
indexAstNodes();
return;
}
throw new AstInspectorException("internal error");
} | java | public void load(File sourceFile) throws CompilationFailedException {
reset();
try {
classLoader.parseClass(sourceFile);
} catch (IOException e) {
throw new AstInspectorException("cannot read source file", e);
} catch (AstSuccessfullyCaptured e) {
indexAstNodes();
return;
}
throw new AstInspectorException("internal error");
} | [
"public",
"void",
"load",
"(",
"File",
"sourceFile",
")",
"throws",
"CompilationFailedException",
"{",
"reset",
"(",
")",
";",
"try",
"{",
"classLoader",
".",
"parseClass",
"(",
"sourceFile",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"thro... | Compiles the source text in the specified file up to the
configured compile phase and stores the resulting AST for subsequent
inspection.
@param sourceFile the file containing the source text to compile
@throws CompilationFailedException if an error occurs during compilation
@throws AstInspectorException if an IOException occurs when reading from
the file | [
"Compiles",
"the",
"source",
"text",
"in",
"the",
"specified",
"file",
"up",
"to",
"the",
"configured",
"compile",
"phase",
"and",
"stores",
"the",
"resulting",
"AST",
"for",
"subsequent",
"inspection",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/util/inspector/AstInspector.java#L160-L173 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/runtime/ParameterizedSpecRunner.java | ParameterizedSpecRunner.estimateNumIterations | private int estimateNumIterations(Object[] dataProviders) {
if (runStatus != OK) return -1;
if (dataProviders.length == 0) return 1;
int result = Integer.MAX_VALUE;
for (Object prov : dataProviders) {
if (prov instanceof Iterator)
// unbelievably, DGM provides a size() method for Iterators,
// although it is of course destructive (i.e. it exhausts the Iterator)
continue;
Object rawSize = GroovyRuntimeUtil.invokeMethodQuietly(prov, "size");
if (!(rawSize instanceof Number)) continue;
int size = ((Number) rawSize).intValue();
if (size < 0 || size >= result) continue;
result = size;
}
return result == Integer.MAX_VALUE ? -1 : result;
} | java | private int estimateNumIterations(Object[] dataProviders) {
if (runStatus != OK) return -1;
if (dataProviders.length == 0) return 1;
int result = Integer.MAX_VALUE;
for (Object prov : dataProviders) {
if (prov instanceof Iterator)
// unbelievably, DGM provides a size() method for Iterators,
// although it is of course destructive (i.e. it exhausts the Iterator)
continue;
Object rawSize = GroovyRuntimeUtil.invokeMethodQuietly(prov, "size");
if (!(rawSize instanceof Number)) continue;
int size = ((Number) rawSize).intValue();
if (size < 0 || size >= result) continue;
result = size;
}
return result == Integer.MAX_VALUE ? -1 : result;
} | [
"private",
"int",
"estimateNumIterations",
"(",
"Object",
"[",
"]",
"dataProviders",
")",
"{",
"if",
"(",
"runStatus",
"!=",
"OK",
")",
"return",
"-",
"1",
";",
"if",
"(",
"dataProviders",
".",
"length",
"==",
"0",
")",
"return",
"1",
";",
"int",
"resu... | -1 => unknown | [
"-",
"1",
"=",
">",
"unknown"
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/runtime/ParameterizedSpecRunner.java#L112-L133 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/runtime/ParameterizedSpecRunner.java | ParameterizedSpecRunner.nextArgs | private Object[] nextArgs(Iterator[] iterators) {
if (runStatus != OK) return null;
Object[] next = new Object[iterators.length];
for (int i = 0; i < iterators.length; i++)
try {
next[i] = iterators[i].next();
} catch (Throwable t) {
runStatus = supervisor.error(
new ErrorInfo(currentFeature.getDataProviders().get(i).getDataProviderMethod(), t));
return null;
}
try {
return (Object[])invokeRaw(sharedInstance, currentFeature.getDataProcessorMethod(), next);
} catch (Throwable t) {
runStatus = supervisor.error(
new ErrorInfo(currentFeature.getDataProcessorMethod(), t));
return null;
}
} | java | private Object[] nextArgs(Iterator[] iterators) {
if (runStatus != OK) return null;
Object[] next = new Object[iterators.length];
for (int i = 0; i < iterators.length; i++)
try {
next[i] = iterators[i].next();
} catch (Throwable t) {
runStatus = supervisor.error(
new ErrorInfo(currentFeature.getDataProviders().get(i).getDataProviderMethod(), t));
return null;
}
try {
return (Object[])invokeRaw(sharedInstance, currentFeature.getDataProcessorMethod(), next);
} catch (Throwable t) {
runStatus = supervisor.error(
new ErrorInfo(currentFeature.getDataProcessorMethod(), t));
return null;
}
} | [
"private",
"Object",
"[",
"]",
"nextArgs",
"(",
"Iterator",
"[",
"]",
"iterators",
")",
"{",
"if",
"(",
"runStatus",
"!=",
"OK",
")",
"return",
"null",
";",
"Object",
"[",
"]",
"next",
"=",
"new",
"Object",
"[",
"iterators",
".",
"length",
"]",
";",
... | advances iterators and computes args | [
"advances",
"iterators",
"and",
"computes",
"args"
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/runtime/ParameterizedSpecRunner.java#L195-L215 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Mock | @Override
public <T> T Mock(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.MOCK, Collections.<String, Object>emptyMap());
} | java | @Override
public <T> T Mock(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.MOCK, Collections.<String, Object>emptyMap());
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Mock",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"MockNature",
".",
"MOCK",
",",
"Collections",
".",
"<",
"Stri... | Creates a mock with the specified type. The mock name will be the types simple name.
Example:
<pre>
def person = Mock(Person) // type is Person.class, name is "person"
</pre>
@param type the interface or class type of the mock
@param <T> the interface or class type of the mock
@return a mock with the specified type | [
"Creates",
"a",
"mock",
"with",
"the",
"specified",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L45-L48 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Mock | @Override
public <T> T Mock(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.MOCK, options);
} | java | @Override
public <T> T Mock(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.MOCK, options);
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Mock",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"options",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"M... | Creates a mock with the specified options and type. The mock name will be the types simple name.
Example:
<pre>
def person = Mock(Person, name: "myPerson") // type is Person.class, name is "myPerson"
</pre>
@param options optional options for creating the mock
@param type the interface or class type of the mock
@param <T> the interface or class type of the mock
@return a mock with the specified options and type | [
"Creates",
"a",
"mock",
"with",
"the",
"specified",
"options",
"and",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L65-L68 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Stub | @Override
public <T> T Stub(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.STUB, Collections.<String, Object>emptyMap());
} | java | @Override
public <T> T Stub(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.STUB, Collections.<String, Object>emptyMap());
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Stub",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"MockNature",
".",
"STUB",
",",
"Collections",
".",
"<",
"Stri... | Creates a stub with the specified type. The mock name will be the types simple name.
Example:
<pre>
def person = Stub(Person) // type is Person.class, name is "person"
</pre>
@param type the interface or class type of the stub
@param <T> the interface or class type of the stub
@return a stub with the specified type | [
"Creates",
"a",
"stub",
"with",
"the",
"specified",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L84-L87 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Stub | @Override
public <T> T Stub(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.STUB, options);
} | java | @Override
public <T> T Stub(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.STUB, options);
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Stub",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"options",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"M... | Creates a stub with the specified options and type. The mock name will be the types simple name.
Example:
<pre>
def person = Stub(Person, name: "myPerson") // type is Person.class, name is "myPerson"
</pre>
@param options optional options for creating the stub
@param type the interface or class type of the stub
@param <T> the interface or class type of the stub
@return a stub with the specified options and type | [
"Creates",
"a",
"stub",
"with",
"the",
"specified",
"options",
"and",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L104-L107 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Spy | @Override
public <T> T Spy(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.SPY, Collections.<String, Object>emptyMap());
} | java | @Override
public <T> T Spy(Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.SPY, Collections.<String, Object>emptyMap());
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Spy",
"(",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"MockNature",
".",
"SPY",
",",
"Collections",
".",
"<",
"String... | Creates a spy with the specified type. The mock name will be the types simple name.
Example:
<pre>
def person = Spy(Person) // type is Person.class, name is "person"
</pre>
@param type the class type of the spy
@param <T> the class type of the spy
@return a spy with the specified type | [
"Creates",
"a",
"spy",
"with",
"the",
"specified",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L123-L126 | train |
spockframework/spock | spock-core/src/main/java/spock/mock/DetachedMockFactory.java | DetachedMockFactory.Spy | @Override
public <T> T Spy(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.SPY, options);
} | java | @Override
public <T> T Spy(Map<String, Object> options, Class<T> type) {
return createMock(inferNameFromType(type), type, MockNature.SPY, options);
} | [
"@",
"Override",
"public",
"<",
"T",
">",
"T",
"Spy",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"options",
",",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"createMock",
"(",
"inferNameFromType",
"(",
"type",
")",
",",
"type",
",",
"Mo... | Creates a spy with the specified options and type. The mock name will be the types simple name.
Example:
<pre>
def person = Spy(Person, name: "myPerson") // type is Person.class, name is "myPerson"
</pre>
@param options optional options for creating the spy
@param type the class type of the spy
@param <T> the class type of the spy
@return a spy with the specified options and type | [
"Creates",
"a",
"spy",
"with",
"the",
"specified",
"options",
"and",
"type",
".",
"The",
"mock",
"name",
"will",
"be",
"the",
"types",
"simple",
"name",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/spock/mock/DetachedMockFactory.java#L148-L151 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/runtime/SpecUtil.java | SpecUtil.getFeatureCount | public static int getFeatureCount(Class<?> spec) {
checkIsSpec(spec);
int count = 0;
do {
for (Method method : spec.getDeclaredMethods())
if (method.isAnnotationPresent(FeatureMetadata.class))
count++;
spec = spec.getSuperclass();
} while (spec != null && isSpec(spec));
return count;
} | java | public static int getFeatureCount(Class<?> spec) {
checkIsSpec(spec);
int count = 0;
do {
for (Method method : spec.getDeclaredMethods())
if (method.isAnnotationPresent(FeatureMetadata.class))
count++;
spec = spec.getSuperclass();
} while (spec != null && isSpec(spec));
return count;
} | [
"public",
"static",
"int",
"getFeatureCount",
"(",
"Class",
"<",
"?",
">",
"spec",
")",
"{",
"checkIsSpec",
"(",
"spec",
")",
";",
"int",
"count",
"=",
"0",
";",
"do",
"{",
"for",
"(",
"Method",
"method",
":",
"spec",
".",
"getDeclaredMethods",
"(",
... | Returns the number of features contained in the given specification.
Because Spock allows for the dynamic creation of new features at
specification run time, this number is only an estimate. | [
"Returns",
"the",
"number",
"of",
"features",
"contained",
"in",
"the",
"given",
"specification",
".",
"Because",
"Spock",
"allows",
"for",
"the",
"dynamic",
"creation",
"of",
"new",
"features",
"at",
"specification",
"run",
"time",
"this",
"number",
"is",
"on... | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/runtime/SpecUtil.java#L76-L89 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/runtime/model/FeatureInfo.java | FeatureInfo.hasBytecodeName | public boolean hasBytecodeName(String name) {
if (featureMethod.hasBytecodeName(name)) return true;
if (dataProcessorMethod != null && dataProcessorMethod.hasBytecodeName(name)) return true;
for (DataProviderInfo provider : dataProviders)
if (provider.getDataProviderMethod().hasBytecodeName(name)) return true;
return false;
} | java | public boolean hasBytecodeName(String name) {
if (featureMethod.hasBytecodeName(name)) return true;
if (dataProcessorMethod != null && dataProcessorMethod.hasBytecodeName(name)) return true;
for (DataProviderInfo provider : dataProviders)
if (provider.getDataProviderMethod().hasBytecodeName(name)) return true;
return false;
} | [
"public",
"boolean",
"hasBytecodeName",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"featureMethod",
".",
"hasBytecodeName",
"(",
"name",
")",
")",
"return",
"true",
";",
"if",
"(",
"dataProcessorMethod",
"!=",
"null",
"&&",
"dataProcessorMethod",
".",
"hasByt... | Tells if any of the methods associated with this feature has the specified
name in bytecode.
@param name a method name in bytecode
@return <tt>true</tt iff any of the methods associated with this feature
has the specified name in bytecode | [
"Tells",
"if",
"any",
"of",
"the",
"methods",
"associated",
"with",
"this",
"feature",
"has",
"the",
"specified",
"name",
"in",
"bytecode",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/runtime/model/FeatureInfo.java#L133-L139 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/compiler/AstUtil.java | AstUtil.getStatements | @SuppressWarnings("unchecked")
public static List<Statement> getStatements(MethodNode method) {
Statement code = method.getCode();
if (!(code instanceof BlockStatement)) { // null or single statement
BlockStatement block = new BlockStatement();
if (code != null) block.addStatement(code);
method.setCode(block);
}
return ((BlockStatement)method.getCode()).getStatements();
} | java | @SuppressWarnings("unchecked")
public static List<Statement> getStatements(MethodNode method) {
Statement code = method.getCode();
if (!(code instanceof BlockStatement)) { // null or single statement
BlockStatement block = new BlockStatement();
if (code != null) block.addStatement(code);
method.setCode(block);
}
return ((BlockStatement)method.getCode()).getStatements();
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"List",
"<",
"Statement",
">",
"getStatements",
"(",
"MethodNode",
"method",
")",
"{",
"Statement",
"code",
"=",
"method",
".",
"getCode",
"(",
")",
";",
"if",
"(",
"!",
"(",
"code",
... | Returns a list of statements of the given method. Modifications to the returned list
will affect the method's statements.
@param method a method (node)
@return a list of statements of the given method | [
"Returns",
"a",
"list",
"of",
"statements",
"of",
"the",
"given",
"method",
".",
"Modifications",
"to",
"the",
"returned",
"list",
"will",
"affect",
"the",
"method",
"s",
"statements",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/compiler/AstUtil.java#L69-L78 | train |
spockframework/spock | spock-core/src/main/java/org/spockframework/compiler/AstUtil.java | AstUtil.fixUpLocalVariables | public static void fixUpLocalVariables(List<? extends Variable> localVariables, VariableScope scope, boolean isClosureScope) {
for (Variable localVar : localVariables) {
Variable scopeVar = scope.getReferencedClassVariable(localVar.getName());
if (scopeVar instanceof DynamicVariable) {
scope.removeReferencedClassVariable(localVar.getName());
scope.putReferencedLocalVariable(localVar);
if (isClosureScope)
localVar.setClosureSharedVariable(true);
}
}
} | java | public static void fixUpLocalVariables(List<? extends Variable> localVariables, VariableScope scope, boolean isClosureScope) {
for (Variable localVar : localVariables) {
Variable scopeVar = scope.getReferencedClassVariable(localVar.getName());
if (scopeVar instanceof DynamicVariable) {
scope.removeReferencedClassVariable(localVar.getName());
scope.putReferencedLocalVariable(localVar);
if (isClosureScope)
localVar.setClosureSharedVariable(true);
}
}
} | [
"public",
"static",
"void",
"fixUpLocalVariables",
"(",
"List",
"<",
"?",
"extends",
"Variable",
">",
"localVariables",
",",
"VariableScope",
"scope",
",",
"boolean",
"isClosureScope",
")",
"{",
"for",
"(",
"Variable",
"localVar",
":",
"localVariables",
")",
"{"... | Fixes up scope references to variables that used to be free or class variables,
and have been changed to local variables. | [
"Fixes",
"up",
"scope",
"references",
"to",
"variables",
"that",
"used",
"to",
"be",
"free",
"or",
"class",
"variables",
"and",
"have",
"been",
"changed",
"to",
"local",
"variables",
"."
] | d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9 | https://github.com/spockframework/spock/blob/d751a0abd8d5a2ec5338aa10bc2d19371b3b3ad9/spock-core/src/main/java/org/spockframework/compiler/AstUtil.java#L326-L336 | train |
Twitter4J/Twitter4J | twitter4j-core/src/internal-json/java/twitter4j/JSONStringer.java | JSONStringer.beforeKey | private void beforeKey() throws JSONException {
Scope context = peek();
if (context == Scope.NONEMPTY_OBJECT) { // first in object
out.append(',');
} else if (context != Scope.EMPTY_OBJECT) { // not in an object!
throw new JSONException("Nesting problem");
}
newline();
replaceTop(Scope.DANGLING_KEY);
} | java | private void beforeKey() throws JSONException {
Scope context = peek();
if (context == Scope.NONEMPTY_OBJECT) { // first in object
out.append(',');
} else if (context != Scope.EMPTY_OBJECT) { // not in an object!
throw new JSONException("Nesting problem");
}
newline();
replaceTop(Scope.DANGLING_KEY);
} | [
"private",
"void",
"beforeKey",
"(",
")",
"throws",
"JSONException",
"{",
"Scope",
"context",
"=",
"peek",
"(",
")",
";",
"if",
"(",
"context",
"==",
"Scope",
".",
"NONEMPTY_OBJECT",
")",
"{",
"// first in object",
"out",
".",
"append",
"(",
"'",
"'",
")... | Inserts any necessary separators and whitespace before a name. Also
adjusts the stack to expect the key's value. | [
"Inserts",
"any",
"necessary",
"separators",
"and",
"whitespace",
"before",
"a",
"name",
".",
"Also",
"adjusts",
"the",
"stack",
"to",
"expect",
"the",
"key",
"s",
"value",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/internal-json/java/twitter4j/JSONStringer.java#L396-L405 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/auth/OAuthAuthorization.java | OAuthAuthorization.getAuthorizationHeader | @Override
public String getAuthorizationHeader(HttpRequest req) {
return generateAuthorizationHeader(req.getMethod().name(), req.getURL(), req.getParameters(), oauthToken);
} | java | @Override
public String getAuthorizationHeader(HttpRequest req) {
return generateAuthorizationHeader(req.getMethod().name(), req.getURL(), req.getParameters(), oauthToken);
} | [
"@",
"Override",
"public",
"String",
"getAuthorizationHeader",
"(",
"HttpRequest",
"req",
")",
"{",
"return",
"generateAuthorizationHeader",
"(",
"req",
".",
"getMethod",
"(",
")",
".",
"name",
"(",
")",
",",
"req",
".",
"getURL",
"(",
")",
",",
"req",
"."... | implementations for Authorization | [
"implementations",
"for",
"Authorization"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/auth/OAuthAuthorization.java#L64-L67 | train |
Twitter4J/Twitter4J | twitter4j-stream/src/main/java/twitter4j/TwitterStreamImpl.java | TwitterStreamImpl.getSampleStream | StatusStream getSampleStream() throws TwitterException {
ensureAuthorizationEnabled();
try {
return new StatusStreamImpl(getDispatcher(), http.get(conf.getStreamBaseURL() + "statuses/sample.json?"
+ stallWarningsGetParam, null, auth, null), conf);
} catch (IOException e) {
throw new TwitterException(e);
}
} | java | StatusStream getSampleStream() throws TwitterException {
ensureAuthorizationEnabled();
try {
return new StatusStreamImpl(getDispatcher(), http.get(conf.getStreamBaseURL() + "statuses/sample.json?"
+ stallWarningsGetParam, null, auth, null), conf);
} catch (IOException e) {
throw new TwitterException(e);
}
} | [
"StatusStream",
"getSampleStream",
"(",
")",
"throws",
"TwitterException",
"{",
"ensureAuthorizationEnabled",
"(",
")",
";",
"try",
"{",
"return",
"new",
"StatusStreamImpl",
"(",
"getDispatcher",
"(",
")",
",",
"http",
".",
"get",
"(",
"conf",
".",
"getStreamBas... | Returns a stream of random sample of all public statuses. The default access level provides a small proportion of the Firehose. The "Gardenhose" access level provides a proportion more suitable for data mining and research applications that desire a larger proportion to be statistically significant sample.
@return StatusStream
@throws TwitterException when Twitter service or network is unavailable
@see twitter4j.StatusStream
@see <a href="https://dev.twitter.com/docs/streaming-api/methods">Streaming API: Methods statuses/sample</a>
@since Twitter4J 2.0.10 | [
"Returns",
"a",
"stream",
"of",
"random",
"sample",
"of",
"all",
"public",
"statuses",
".",
"The",
"default",
"access",
"level",
"provides",
"a",
"small",
"proportion",
"of",
"the",
"Firehose",
".",
"The",
"Gardenhose",
"access",
"level",
"provides",
"a",
"p... | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-stream/src/main/java/twitter4j/TwitterStreamImpl.java#L198-L206 | train |
Twitter4J/Twitter4J | twitter4j-core/src/internal-http/java/twitter4j/HttpClientImpl.java | HttpClientImpl.setHeaders | private void setHeaders(HttpRequest req, HttpURLConnection connection) {
if (logger.isDebugEnabled()) {
logger.debug("Request: ");
logger.debug(req.getMethod().name() + " ", req.getURL());
}
String authorizationHeader;
if (req.getAuthorization() != null && (authorizationHeader = req.getAuthorization().getAuthorizationHeader(req)) != null) {
if (logger.isDebugEnabled()) {
logger.debug("Authorization: ", authorizationHeader.replaceAll(".", "*"));
}
connection.addRequestProperty("Authorization", authorizationHeader);
}
if (req.getRequestHeaders() != null) {
for (String key : req.getRequestHeaders().keySet()) {
connection.addRequestProperty(key, req.getRequestHeaders().get(key));
logger.debug(key + ": " + req.getRequestHeaders().get(key));
}
}
} | java | private void setHeaders(HttpRequest req, HttpURLConnection connection) {
if (logger.isDebugEnabled()) {
logger.debug("Request: ");
logger.debug(req.getMethod().name() + " ", req.getURL());
}
String authorizationHeader;
if (req.getAuthorization() != null && (authorizationHeader = req.getAuthorization().getAuthorizationHeader(req)) != null) {
if (logger.isDebugEnabled()) {
logger.debug("Authorization: ", authorizationHeader.replaceAll(".", "*"));
}
connection.addRequestProperty("Authorization", authorizationHeader);
}
if (req.getRequestHeaders() != null) {
for (String key : req.getRequestHeaders().keySet()) {
connection.addRequestProperty(key, req.getRequestHeaders().get(key));
logger.debug(key + ": " + req.getRequestHeaders().get(key));
}
}
} | [
"private",
"void",
"setHeaders",
"(",
"HttpRequest",
"req",
",",
"HttpURLConnection",
"connection",
")",
"{",
"if",
"(",
"logger",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Request: \"",
")",
";",
"logger",
".",
"debug",
"(... | sets HTTP headers
@param req The request
@param connection HttpURLConnection | [
"sets",
"HTTP",
"headers"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/internal-http/java/twitter4j/HttpClientImpl.java#L207-L226 | train |
Twitter4J/Twitter4J | twitter4j-core/src/internal-http/java/twitter4j/HttpParameter.java | HttpParameter.decodeParameters | public static List<HttpParameter> decodeParameters(String queryParameters) {
List<HttpParameter> result=new ArrayList<HttpParameter>();
for (String pair : queryParameters.split("&")) {
String[] parts=pair.split("=", 2);
if(parts.length == 2) {
String name=decode(parts[0]);
String value=decode(parts[1]);
if(!name.equals("") && !value.equals(""))
result.add(new HttpParameter(name, value));
}
}
return result;
} | java | public static List<HttpParameter> decodeParameters(String queryParameters) {
List<HttpParameter> result=new ArrayList<HttpParameter>();
for (String pair : queryParameters.split("&")) {
String[] parts=pair.split("=", 2);
if(parts.length == 2) {
String name=decode(parts[0]);
String value=decode(parts[1]);
if(!name.equals("") && !value.equals(""))
result.add(new HttpParameter(name, value));
}
}
return result;
} | [
"public",
"static",
"List",
"<",
"HttpParameter",
">",
"decodeParameters",
"(",
"String",
"queryParameters",
")",
"{",
"List",
"<",
"HttpParameter",
">",
"result",
"=",
"new",
"ArrayList",
"<",
"HttpParameter",
">",
"(",
")",
";",
"for",
"(",
"String",
"pair... | Parses a query string without the leading "?"
@param queryParameters a query parameter string, like a=hello&b=world
@return decoded parameters | [
"Parses",
"a",
"query",
"string",
"without",
"the",
"leading",
"?"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/internal-http/java/twitter4j/HttpParameter.java#L332-L344 | train |
Twitter4J/Twitter4J | twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java | AsyncTwitterImpl.getOAuthRequestTokenAsync | @Override
public void getOAuthRequestTokenAsync() {
getDispatcher().invokeLater(new AsyncTask(OAUTH_REQUEST_TOKEN, listeners) {
@Override
public void invoke(List<TwitterListener> listeners) throws TwitterException {
RequestToken token = twitter.getOAuthRequestToken();
for (TwitterListener listener : listeners) {
try {
listener.gotOAuthRequestToken(token);
} catch (Exception e) {
logger.warn("Exception at getOAuthRequestTokenAsync", e);
}
}
}
});
} | java | @Override
public void getOAuthRequestTokenAsync() {
getDispatcher().invokeLater(new AsyncTask(OAUTH_REQUEST_TOKEN, listeners) {
@Override
public void invoke(List<TwitterListener> listeners) throws TwitterException {
RequestToken token = twitter.getOAuthRequestToken();
for (TwitterListener listener : listeners) {
try {
listener.gotOAuthRequestToken(token);
} catch (Exception e) {
logger.warn("Exception at getOAuthRequestTokenAsync", e);
}
}
}
});
} | [
"@",
"Override",
"public",
"void",
"getOAuthRequestTokenAsync",
"(",
")",
"{",
"getDispatcher",
"(",
")",
".",
"invokeLater",
"(",
"new",
"AsyncTask",
"(",
"OAUTH_REQUEST_TOKEN",
",",
"listeners",
")",
"{",
"@",
"Override",
"public",
"void",
"invoke",
"(",
"Li... | implementation for AsyncOAuthSupport | [
"implementation",
"for",
"AsyncOAuthSupport"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java#L2578-L2593 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createStatus | public static Status createStatus(String rawJSON) throws TwitterException {
try {
return new StatusJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Status createStatus(String rawJSON) throws TwitterException {
try {
return new StatusJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Status",
"createStatus",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"StatusJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
"... | Constructs a Status object from rawJSON string.
@param rawJSON raw JSON form as String
@return Status
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Status",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L53-L59 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createUser | public static User createUser(String rawJSON) throws TwitterException {
try {
return new UserJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static User createUser(String rawJSON) throws TwitterException {
try {
return new UserJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"User",
"createUser",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"UserJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",
... | Constructs a User object from rawJSON string.
@param rawJSON raw JSON form as String
@return User
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"User",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L69-L75 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createAccountTotals | public static AccountTotals createAccountTotals(String rawJSON) throws TwitterException {
try {
return new AccountTotalsJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static AccountTotals createAccountTotals(String rawJSON) throws TwitterException {
try {
return new AccountTotalsJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"AccountTotals",
"createAccountTotals",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"AccountTotalsJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONE... | Constructs an AccountTotals object from rawJSON string.
@param rawJSON raw JSON form as String
@return AccountTotals
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.9 | [
"Constructs",
"an",
"AccountTotals",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L85-L91 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createRelationship | public static Relationship createRelationship(String rawJSON) throws TwitterException {
try {
return new RelationshipJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Relationship createRelationship(String rawJSON) throws TwitterException {
try {
return new RelationshipJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Relationship",
"createRelationship",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"RelationshipJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONExce... | Constructs a Relationship object from rawJSON string.
@param rawJSON raw JSON form as String
@return Relationship
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Relationship",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L101-L107 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createPlace | public static Place createPlace(String rawJSON) throws TwitterException {
try {
return new PlaceJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Place createPlace(String rawJSON) throws TwitterException {
try {
return new PlaceJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Place",
"createPlace",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"PlaceJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",... | Constructs a Place object from rawJSON string.
@param rawJSON raw JSON form as String
@return Place
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Place",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L117-L123 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createSavedSearch | public static SavedSearch createSavedSearch(String rawJSON) throws TwitterException {
try {
return new SavedSearchJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static SavedSearch createSavedSearch(String rawJSON) throws TwitterException {
try {
return new SavedSearchJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"SavedSearch",
"createSavedSearch",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"SavedSearchJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONExcepti... | Constructs a SavedSearch object from rawJSON string.
@param rawJSON raw JSON form as String
@return SavedSearch
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"SavedSearch",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L133-L139 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createTrend | public static Trend createTrend(String rawJSON) throws TwitterException {
try {
return new TrendJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Trend createTrend(String rawJSON) throws TwitterException {
try {
return new TrendJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Trend",
"createTrend",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"TrendJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",... | Constructs a Trend object from rawJSON string.
@param rawJSON raw JSON form as String
@return Trend
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Trend",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L149-L155 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createRateLimitStatus | public static Map<String, RateLimitStatus> createRateLimitStatus(String rawJSON) throws TwitterException {
try {
return RateLimitStatusJSONImpl.createRateLimitStatuses(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Map<String, RateLimitStatus> createRateLimitStatus(String rawJSON) throws TwitterException {
try {
return RateLimitStatusJSONImpl.createRateLimitStatuses(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"RateLimitStatus",
">",
"createRateLimitStatus",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"RateLimitStatusJSONImpl",
".",
"createRateLimitStatuses",
"(",
"new",
"JSONObject",... | Constructs a RateLimitStatus object from rawJSON string.
@param rawJSON raw JSON form as String
@return RateLimitStatus
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"RateLimitStatus",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L189-L195 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createCategory | public static Category createCategory(String rawJSON) throws TwitterException {
try {
return new CategoryJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Category createCategory(String rawJSON) throws TwitterException {
try {
return new CategoryJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Category",
"createCategory",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"CategoryJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e... | Constructs a Category object from rawJSON string.
@param rawJSON raw JSON form as String
@return Category
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Category",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L205-L211 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createDirectMessage | public static DirectMessage createDirectMessage(String rawJSON) throws TwitterException {
try {
return new DirectMessageJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static DirectMessage createDirectMessage(String rawJSON) throws TwitterException {
try {
return new DirectMessageJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"DirectMessage",
"createDirectMessage",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"DirectMessageJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONE... | Constructs a DirectMessage object from rawJSON string.
@param rawJSON raw JSON form as String
@return DirectMessage
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"DirectMessage",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L221-L227 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createLocation | public static Location createLocation(String rawJSON) throws TwitterException {
try {
return new LocationJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static Location createLocation(String rawJSON) throws TwitterException {
try {
return new LocationJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"Location",
"createLocation",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"LocationJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e... | Constructs a Location object from rawJSON string.
@param rawJSON raw JSON form as String
@return Location
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"Location",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L237-L243 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createUserList | public static UserList createUserList(String rawJSON) throws TwitterException {
try {
return new UserListJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static UserList createUserList(String rawJSON) throws TwitterException {
try {
return new UserListJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"UserList",
"createUserList",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"UserListJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e... | Constructs a UserList object from rawJSON string.
@param rawJSON raw JSON form as String
@return UserList
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 2.1.7 | [
"Constructs",
"a",
"UserList",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L253-L259 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java | TwitterObjectFactory.createOEmbed | public static OEmbed createOEmbed(String rawJSON) throws TwitterException {
try {
return new OEmbedJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | java | public static OEmbed createOEmbed(String rawJSON) throws TwitterException {
try {
return new OEmbedJSONImpl(new JSONObject(rawJSON));
} catch (JSONException e) {
throw new TwitterException(e);
}
} | [
"public",
"static",
"OEmbed",
"createOEmbed",
"(",
"String",
"rawJSON",
")",
"throws",
"TwitterException",
"{",
"try",
"{",
"return",
"new",
"OEmbedJSONImpl",
"(",
"new",
"JSONObject",
"(",
"rawJSON",
")",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
"... | Constructs an OEmbed object from rawJSON string.
@param rawJSON raw JSON form as String
@return OEmbed
@throws TwitterException when provided string is not a valid JSON string.
@since Twitter4J 3.0.2 | [
"Constructs",
"an",
"OEmbed",
"object",
"from",
"rawJSON",
"string",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterObjectFactory.java#L269-L275 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java | ConfigurationBase.setHttpProxyHost | protected final void setHttpProxyHost(String proxyHost) {
httpConf = new MyHttpClientConfiguration(proxyHost
, httpConf.getHttpProxyUser()
, httpConf.getHttpProxyPassword()
, httpConf.getHttpProxyPort()
, httpConf.isHttpProxySocks()
, httpConf.getHttpConnectionTimeout()
, httpConf.getHttpReadTimeout()
, httpConf.isPrettyDebugEnabled(), httpConf.isGZIPEnabled()
);
} | java | protected final void setHttpProxyHost(String proxyHost) {
httpConf = new MyHttpClientConfiguration(proxyHost
, httpConf.getHttpProxyUser()
, httpConf.getHttpProxyPassword()
, httpConf.getHttpProxyPort()
, httpConf.isHttpProxySocks()
, httpConf.getHttpConnectionTimeout()
, httpConf.getHttpReadTimeout()
, httpConf.isPrettyDebugEnabled(), httpConf.isGZIPEnabled()
);
} | [
"protected",
"final",
"void",
"setHttpProxyHost",
"(",
"String",
"proxyHost",
")",
"{",
"httpConf",
"=",
"new",
"MyHttpClientConfiguration",
"(",
"proxyHost",
",",
"httpConf",
".",
"getHttpProxyUser",
"(",
")",
",",
"httpConf",
".",
"getHttpProxyPassword",
"(",
")... | methods for HttpClientConfiguration | [
"methods",
"for",
"HttpClientConfiguration"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java#L320-L330 | train |
Twitter4J/Twitter4J | twitter4j-core/src/internal-async/java/twitter4j/DispatcherFactory.java | DispatcherFactory.getInstance | public Dispatcher getInstance() {
try {
return (Dispatcher) Class.forName(dispatcherImpl)
.getConstructor(Configuration.class).newInstance(conf);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
} catch (ClassCastException e) {
throw new AssertionError(e);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
} | java | public Dispatcher getInstance() {
try {
return (Dispatcher) Class.forName(dispatcherImpl)
.getConstructor(Configuration.class).newInstance(conf);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
} catch (ClassCastException e) {
throw new AssertionError(e);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
} | [
"public",
"Dispatcher",
"getInstance",
"(",
")",
"{",
"try",
"{",
"return",
"(",
"Dispatcher",
")",
"Class",
".",
"forName",
"(",
"dispatcherImpl",
")",
".",
"getConstructor",
"(",
"Configuration",
".",
"class",
")",
".",
"newInstance",
"(",
"conf",
")",
"... | returns a Dispatcher instance.
@return dispatcher instance | [
"returns",
"a",
"Dispatcher",
"instance",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/internal-async/java/twitter4j/DispatcherFactory.java#L46-L63 | train |
Twitter4J/Twitter4J | twitter4j-core/src/internal-json/java/twitter4j/JSON.java | JSON.checkDouble | static double checkDouble(double d) throws JSONException {
if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new JSONException("Forbidden numeric value: " + d);
}
return d;
} | java | static double checkDouble(double d) throws JSONException {
if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new JSONException("Forbidden numeric value: " + d);
}
return d;
} | [
"static",
"double",
"checkDouble",
"(",
"double",
"d",
")",
"throws",
"JSONException",
"{",
"if",
"(",
"Double",
".",
"isInfinite",
"(",
"d",
")",
"||",
"Double",
".",
"isNaN",
"(",
"d",
")",
")",
"{",
"throw",
"new",
"JSONException",
"(",
"\"Forbidden n... | Returns the input if it is a JSON-permissible value; throws otherwise. | [
"Returns",
"the",
"input",
"if",
"it",
"is",
"a",
"JSON",
"-",
"permissible",
"value",
";",
"throws",
"otherwise",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/internal-json/java/twitter4j/JSON.java#L22-L27 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/conf/PropertyConfigurationFactory.java | PropertyConfigurationFactory.getInstance | @Override
public Configuration getInstance(String configTreePath) {
PropertyConfiguration conf = new PropertyConfiguration(configTreePath);
conf.dumpConfiguration();
return conf;
} | java | @Override
public Configuration getInstance(String configTreePath) {
PropertyConfiguration conf = new PropertyConfiguration(configTreePath);
conf.dumpConfiguration();
return conf;
} | [
"@",
"Override",
"public",
"Configuration",
"getInstance",
"(",
"String",
"configTreePath",
")",
"{",
"PropertyConfiguration",
"conf",
"=",
"new",
"PropertyConfiguration",
"(",
"configTreePath",
")",
";",
"conf",
".",
"dumpConfiguration",
"(",
")",
";",
"return",
... | It may be preferable to cache the config instance | [
"It",
"may",
"be",
"preferable",
"to",
"cache",
"the",
"config",
"instance"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/conf/PropertyConfigurationFactory.java#L41-L46 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterImpl.java | TwitterImpl.uploadMediaChunkedFinalize | private UploadedMedia uploadMediaChunkedFinalize(long mediaId) throws TwitterException {
int tries = 0;
int maxTries = 20;
int lastProgressPercent = 0;
int currentProgressPercent = 0;
UploadedMedia uploadedMedia = uploadMediaChunkedFinalize0(mediaId);
while (tries < maxTries) {
if(lastProgressPercent == currentProgressPercent) {
tries++;
}
lastProgressPercent = currentProgressPercent;
String state = uploadedMedia.getProcessingState();
if (state.equals("failed")) {
throw new TwitterException("Failed to finalize the chuncked upload.");
}
if (state.equals("pending") || state.equals("in_progress")) {
currentProgressPercent = uploadedMedia.getProgressPercent();
int waitSec = Math.max(uploadedMedia.getProcessingCheckAfterSecs(), 1);
logger.debug("Chunked finalize, wait for:" + waitSec + " sec");
try {
Thread.sleep(waitSec * 1000);
} catch (InterruptedException e) {
throw new TwitterException("Failed to finalize the chuncked upload.", e);
}
}
if (state.equals("succeeded")) {
return uploadedMedia;
}
uploadedMedia = uploadMediaChunkedStatus(mediaId);
}
throw new TwitterException("Failed to finalize the chuncked upload, progress has stopped, tried " + tries+1 + " times.");
} | java | private UploadedMedia uploadMediaChunkedFinalize(long mediaId) throws TwitterException {
int tries = 0;
int maxTries = 20;
int lastProgressPercent = 0;
int currentProgressPercent = 0;
UploadedMedia uploadedMedia = uploadMediaChunkedFinalize0(mediaId);
while (tries < maxTries) {
if(lastProgressPercent == currentProgressPercent) {
tries++;
}
lastProgressPercent = currentProgressPercent;
String state = uploadedMedia.getProcessingState();
if (state.equals("failed")) {
throw new TwitterException("Failed to finalize the chuncked upload.");
}
if (state.equals("pending") || state.equals("in_progress")) {
currentProgressPercent = uploadedMedia.getProgressPercent();
int waitSec = Math.max(uploadedMedia.getProcessingCheckAfterSecs(), 1);
logger.debug("Chunked finalize, wait for:" + waitSec + " sec");
try {
Thread.sleep(waitSec * 1000);
} catch (InterruptedException e) {
throw new TwitterException("Failed to finalize the chuncked upload.", e);
}
}
if (state.equals("succeeded")) {
return uploadedMedia;
}
uploadedMedia = uploadMediaChunkedStatus(mediaId);
}
throw new TwitterException("Failed to finalize the chuncked upload, progress has stopped, tried " + tries+1 + " times.");
} | [
"private",
"UploadedMedia",
"uploadMediaChunkedFinalize",
"(",
"long",
"mediaId",
")",
"throws",
"TwitterException",
"{",
"int",
"tries",
"=",
"0",
";",
"int",
"maxTries",
"=",
"20",
";",
"int",
"lastProgressPercent",
"=",
"0",
";",
"int",
"currentProgressPercent"... | "command=FINALIZE&media_id=601413451156586496" | [
"command",
"=",
"FINALIZE&media_id",
"=",
"601413451156586496"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterImpl.java#L346-L377 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterImpl.java | TwitterImpl.checkFileValidity | private void checkFileValidity(File image) throws TwitterException {
if (!image.exists()) {
//noinspection ThrowableInstanceNeverThrown
throw new TwitterException(new FileNotFoundException(image + " is not found."));
}
if (!image.isFile()) {
//noinspection ThrowableInstanceNeverThrown
throw new TwitterException(new IOException(image + " is not a file."));
}
} | java | private void checkFileValidity(File image) throws TwitterException {
if (!image.exists()) {
//noinspection ThrowableInstanceNeverThrown
throw new TwitterException(new FileNotFoundException(image + " is not found."));
}
if (!image.isFile()) {
//noinspection ThrowableInstanceNeverThrown
throw new TwitterException(new IOException(image + " is not a file."));
}
} | [
"private",
"void",
"checkFileValidity",
"(",
"File",
"image",
")",
"throws",
"TwitterException",
"{",
"if",
"(",
"!",
"image",
".",
"exists",
"(",
")",
")",
"{",
"//noinspection ThrowableInstanceNeverThrown",
"throw",
"new",
"TwitterException",
"(",
"new",
"FileNo... | Check the existence, and the type of the specified file.
@param image image to be uploaded
@throws TwitterException when the specified file is not found (FileNotFoundException will be nested)
, or when the specified file object is not representing a file(IOException will be nested). | [
"Check",
"the",
"existence",
"and",
"the",
"type",
"of",
"the",
"specified",
"file",
"."
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterImpl.java#L887-L896 | train |
Twitter4J/Twitter4J | twitter4j-core/src/main/java/twitter4j/TwitterBaseImpl.java | TwitterBaseImpl.setOAuthConsumer | @Override
public synchronized void setOAuthConsumer(String consumerKey, String consumerSecret) {
if (null == consumerKey) {
throw new NullPointerException("consumer key is null");
}
if (null == consumerSecret) {
throw new NullPointerException("consumer secret is null");
}
if (auth instanceof NullAuthorization) {
if (conf.isApplicationOnlyAuthEnabled()) {
OAuth2Authorization oauth2 = new OAuth2Authorization(conf);
oauth2.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth2;
} else {
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth;
}
} else if (auth instanceof BasicAuthorization) {
XAuthAuthorization xauth = new XAuthAuthorization((BasicAuthorization) auth);
xauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = xauth;
} else if (auth instanceof OAuthAuthorization || auth instanceof OAuth2Authorization) {
throw new IllegalStateException("consumer key/secret pair already set.");
}
} | java | @Override
public synchronized void setOAuthConsumer(String consumerKey, String consumerSecret) {
if (null == consumerKey) {
throw new NullPointerException("consumer key is null");
}
if (null == consumerSecret) {
throw new NullPointerException("consumer secret is null");
}
if (auth instanceof NullAuthorization) {
if (conf.isApplicationOnlyAuthEnabled()) {
OAuth2Authorization oauth2 = new OAuth2Authorization(conf);
oauth2.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth2;
} else {
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth;
}
} else if (auth instanceof BasicAuthorization) {
XAuthAuthorization xauth = new XAuthAuthorization((BasicAuthorization) auth);
xauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = xauth;
} else if (auth instanceof OAuthAuthorization || auth instanceof OAuth2Authorization) {
throw new IllegalStateException("consumer key/secret pair already set.");
}
} | [
"@",
"Override",
"public",
"synchronized",
"void",
"setOAuthConsumer",
"(",
"String",
"consumerKey",
",",
"String",
"consumerSecret",
")",
"{",
"if",
"(",
"null",
"==",
"consumerKey",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"consumer key is null\"",... | methods declared in OAuthSupport interface | [
"methods",
"declared",
"in",
"OAuthSupport",
"interface"
] | 8376fade8d557896bb9319fb46e39a55b134b166 | https://github.com/Twitter4J/Twitter4J/blob/8376fade8d557896bb9319fb46e39a55b134b166/twitter4j-core/src/main/java/twitter4j/TwitterBaseImpl.java#L262-L287 | train |
grantland/android-autofittextview | library/src/main/java/me/grantland/widget/AutofitHelper.java | AutofitHelper.autofit | private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
} | java | private static void autofit(TextView view, TextPaint paint, float minTextSize, float maxTextSize,
int maxLines, float precision) {
if (maxLines <= 0 || maxLines == Integer.MAX_VALUE) {
// Don't auto-size since there's no limit on lines.
return;
}
int targetWidth = view.getWidth() - view.getPaddingLeft() - view.getPaddingRight();
if (targetWidth <= 0) {
return;
}
CharSequence text = view.getText();
TransformationMethod method = view.getTransformationMethod();
if (method != null) {
text = method.getTransformation(text, view);
}
Context context = view.getContext();
Resources r = Resources.getSystem();
DisplayMetrics displayMetrics;
float size = maxTextSize;
float high = size;
float low = 0;
if (context != null) {
r = context.getResources();
}
displayMetrics = r.getDisplayMetrics();
paint.set(view.getPaint());
paint.setTextSize(size);
if ((maxLines == 1 && paint.measureText(text, 0, text.length()) > targetWidth)
|| getLineCount(text, paint, size, targetWidth, displayMetrics) > maxLines) {
size = getAutofitTextSize(text, paint, targetWidth, maxLines, low, high, precision,
displayMetrics);
}
if (size < minTextSize) {
size = minTextSize;
}
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
} | [
"private",
"static",
"void",
"autofit",
"(",
"TextView",
"view",
",",
"TextPaint",
"paint",
",",
"float",
"minTextSize",
",",
"float",
"maxTextSize",
",",
"int",
"maxLines",
",",
"float",
"precision",
")",
"{",
"if",
"(",
"maxLines",
"<=",
"0",
"||",
"maxL... | Re-sizes the textSize of the TextView so that the text fits within the bounds of the View. | [
"Re",
"-",
"sizes",
"the",
"textSize",
"of",
"the",
"TextView",
"so",
"that",
"the",
"text",
"fits",
"within",
"the",
"bounds",
"of",
"the",
"View",
"."
] | 5c565aa5c3ed62aaa31140440bb526e7435e7947 | https://github.com/grantland/android-autofittextview/blob/5c565aa5c3ed62aaa31140440bb526e7435e7947/library/src/main/java/me/grantland/widget/AutofitHelper.java#L91-L136 | train |
grantland/android-autofittextview | library/src/main/java/me/grantland/widget/AutofitHelper.java | AutofitHelper.getAutofitTextSize | private static float getAutofitTextSize(CharSequence text, TextPaint paint,
float targetWidth, int maxLines, float low, float high, float precision,
DisplayMetrics displayMetrics) {
float mid = (low + high) / 2.0f;
int lineCount = 1;
StaticLayout layout = null;
paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid,
displayMetrics));
if (maxLines != 1) {
layout = new StaticLayout(text, paint, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL,
1.0f, 0.0f, true);
lineCount = layout.getLineCount();
}
if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
" target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);
if (lineCount > maxLines) {
// For the case that `text` has more newline characters than `maxLines`.
if ((high - low) < precision) {
return low;
}
return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
displayMetrics);
}
else if (lineCount < maxLines) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
displayMetrics);
}
else {
float maxLineWidth = 0;
if (maxLines == 1) {
maxLineWidth = paint.measureText(text, 0, text.length());
} else {
for (int i = 0; i < lineCount; i++) {
if (layout.getLineWidth(i) > maxLineWidth) {
maxLineWidth = layout.getLineWidth(i);
}
}
}
if ((high - low) < precision) {
return low;
} else if (maxLineWidth > targetWidth) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
displayMetrics);
} else if (maxLineWidth < targetWidth) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
displayMetrics);
} else {
return mid;
}
}
} | java | private static float getAutofitTextSize(CharSequence text, TextPaint paint,
float targetWidth, int maxLines, float low, float high, float precision,
DisplayMetrics displayMetrics) {
float mid = (low + high) / 2.0f;
int lineCount = 1;
StaticLayout layout = null;
paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid,
displayMetrics));
if (maxLines != 1) {
layout = new StaticLayout(text, paint, (int)targetWidth, Layout.Alignment.ALIGN_NORMAL,
1.0f, 0.0f, true);
lineCount = layout.getLineCount();
}
if (SPEW) Log.d(TAG, "low=" + low + " high=" + high + " mid=" + mid +
" target=" + targetWidth + " maxLines=" + maxLines + " lineCount=" + lineCount);
if (lineCount > maxLines) {
// For the case that `text` has more newline characters than `maxLines`.
if ((high - low) < precision) {
return low;
}
return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
displayMetrics);
}
else if (lineCount < maxLines) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
displayMetrics);
}
else {
float maxLineWidth = 0;
if (maxLines == 1) {
maxLineWidth = paint.measureText(text, 0, text.length());
} else {
for (int i = 0; i < lineCount; i++) {
if (layout.getLineWidth(i) > maxLineWidth) {
maxLineWidth = layout.getLineWidth(i);
}
}
}
if ((high - low) < precision) {
return low;
} else if (maxLineWidth > targetWidth) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, low, mid, precision,
displayMetrics);
} else if (maxLineWidth < targetWidth) {
return getAutofitTextSize(text, paint, targetWidth, maxLines, mid, high, precision,
displayMetrics);
} else {
return mid;
}
}
} | [
"private",
"static",
"float",
"getAutofitTextSize",
"(",
"CharSequence",
"text",
",",
"TextPaint",
"paint",
",",
"float",
"targetWidth",
",",
"int",
"maxLines",
",",
"float",
"low",
",",
"float",
"high",
",",
"float",
"precision",
",",
"DisplayMetrics",
"display... | Recursive binary search to find the best size for the text. | [
"Recursive",
"binary",
"search",
"to",
"find",
"the",
"best",
"size",
"for",
"the",
"text",
"."
] | 5c565aa5c3ed62aaa31140440bb526e7435e7947 | https://github.com/grantland/android-autofittextview/blob/5c565aa5c3ed62aaa31140440bb526e7435e7947/library/src/main/java/me/grantland/widget/AutofitHelper.java#L141-L196 | train |
grantland/android-autofittextview | library/src/main/java/me/grantland/widget/AutofitHelper.java | AutofitHelper.setMinTextSize | public AutofitHelper setMinTextSize(int unit, float size) {
Context context = mTextView.getContext();
Resources r = Resources.getSystem();
if (context != null) {
r = context.getResources();
}
setRawMinTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
return this;
} | java | public AutofitHelper setMinTextSize(int unit, float size) {
Context context = mTextView.getContext();
Resources r = Resources.getSystem();
if (context != null) {
r = context.getResources();
}
setRawMinTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
return this;
} | [
"public",
"AutofitHelper",
"setMinTextSize",
"(",
"int",
"unit",
",",
"float",
"size",
")",
"{",
"Context",
"context",
"=",
"mTextView",
".",
"getContext",
"(",
")",
";",
"Resources",
"r",
"=",
"Resources",
".",
"getSystem",
"(",
")",
";",
"if",
"(",
"co... | Set the minimum text size to a given unit and value. See TypedValue for the possible
dimension units.
@param unit The desired dimension unit.
@param size The desired size in the given units.
@attr ref me.grantland.R.styleable#AutofitTextView_minTextSize | [
"Set",
"the",
"minimum",
"text",
"size",
"to",
"a",
"given",
"unit",
"and",
"value",
".",
"See",
"TypedValue",
"for",
"the",
"possible",
"dimension",
"units",
"."
] | 5c565aa5c3ed62aaa31140440bb526e7435e7947 | https://github.com/grantland/android-autofittextview/blob/5c565aa5c3ed62aaa31140440bb526e7435e7947/library/src/main/java/me/grantland/widget/AutofitHelper.java#L333-L343 | train |
grantland/android-autofittextview | library/src/main/java/me/grantland/widget/AutofitHelper.java | AutofitHelper.setMaxTextSize | public AutofitHelper setMaxTextSize(int unit, float size) {
Context context = mTextView.getContext();
Resources r = Resources.getSystem();
if (context != null) {
r = context.getResources();
}
setRawMaxTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
return this;
} | java | public AutofitHelper setMaxTextSize(int unit, float size) {
Context context = mTextView.getContext();
Resources r = Resources.getSystem();
if (context != null) {
r = context.getResources();
}
setRawMaxTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()));
return this;
} | [
"public",
"AutofitHelper",
"setMaxTextSize",
"(",
"int",
"unit",
",",
"float",
"size",
")",
"{",
"Context",
"context",
"=",
"mTextView",
".",
"getContext",
"(",
")",
";",
"Resources",
"r",
"=",
"Resources",
".",
"getSystem",
"(",
")",
";",
"if",
"(",
"co... | Set the maximum text size to a given unit and value. See TypedValue for the possible
dimension units.
@param unit The desired dimension unit.
@param size The desired size in the given units.
@attr ref android.R.styleable#TextView_textSize | [
"Set",
"the",
"maximum",
"text",
"size",
"to",
"a",
"given",
"unit",
"and",
"value",
".",
"See",
"TypedValue",
"for",
"the",
"possible",
"dimension",
"units",
"."
] | 5c565aa5c3ed62aaa31140440bb526e7435e7947 | https://github.com/grantland/android-autofittextview/blob/5c565aa5c3ed62aaa31140440bb526e7435e7947/library/src/main/java/me/grantland/widget/AutofitHelper.java#L381-L391 | train |
grantland/android-autofittextview | library/src/main/java/me/grantland/widget/AutofitHelper.java | AutofitHelper.setEnabled | public AutofitHelper setEnabled(boolean enabled) {
if (mEnabled != enabled) {
mEnabled = enabled;
if (enabled) {
mTextView.addTextChangedListener(mTextWatcher);
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener);
autofit();
} else {
mTextView.removeTextChangedListener(mTextWatcher);
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
}
return this;
} | java | public AutofitHelper setEnabled(boolean enabled) {
if (mEnabled != enabled) {
mEnabled = enabled;
if (enabled) {
mTextView.addTextChangedListener(mTextWatcher);
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener);
autofit();
} else {
mTextView.removeTextChangedListener(mTextWatcher);
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
}
return this;
} | [
"public",
"AutofitHelper",
"setEnabled",
"(",
"boolean",
"enabled",
")",
"{",
"if",
"(",
"mEnabled",
"!=",
"enabled",
")",
"{",
"mEnabled",
"=",
"enabled",
";",
"if",
"(",
"enabled",
")",
"{",
"mTextView",
".",
"addTextChangedListener",
"(",
"mTextWatcher",
... | Set the enabled state of automatically resizing text. | [
"Set",
"the",
"enabled",
"state",
"of",
"automatically",
"resizing",
"text",
"."
] | 5c565aa5c3ed62aaa31140440bb526e7435e7947 | https://github.com/grantland/android-autofittextview/blob/5c565aa5c3ed62aaa31140440bb526e7435e7947/library/src/main/java/me/grantland/widget/AutofitHelper.java#L430-L447 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.getDeclaredFields | public static <T> List<Field> getDeclaredFields(T type) {
return new ArrayList<>(asList(type.getClass().getDeclaredFields()));
} | java | public static <T> List<Field> getDeclaredFields(T type) {
return new ArrayList<>(asList(type.getClass().getDeclaredFields()));
} | [
"public",
"static",
"<",
"T",
">",
"List",
"<",
"Field",
">",
"getDeclaredFields",
"(",
"T",
"type",
")",
"{",
"return",
"new",
"ArrayList",
"<>",
"(",
"asList",
"(",
"type",
".",
"getClass",
"(",
")",
".",
"getDeclaredFields",
"(",
")",
")",
")",
";... | Get declared fields of a given type.
@param type the type to introspect
@param <T> the actual type to introspect
@return list of declared fields | [
"Get",
"declared",
"fields",
"of",
"a",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L102-L104 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.getInheritedFields | public static List<Field> getInheritedFields(Class<?> type) {
List<Field> inheritedFields = new ArrayList<>();
while (type.getSuperclass() != null) {
Class<?> superclass = type.getSuperclass();
inheritedFields.addAll(asList(superclass.getDeclaredFields()));
type = superclass;
}
return inheritedFields;
} | java | public static List<Field> getInheritedFields(Class<?> type) {
List<Field> inheritedFields = new ArrayList<>();
while (type.getSuperclass() != null) {
Class<?> superclass = type.getSuperclass();
inheritedFields.addAll(asList(superclass.getDeclaredFields()));
type = superclass;
}
return inheritedFields;
} | [
"public",
"static",
"List",
"<",
"Field",
">",
"getInheritedFields",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"List",
"<",
"Field",
">",
"inheritedFields",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"while",
"(",
"type",
".",
"getSuperclass",
... | Get inherited fields of a given type.
@param type the type to introspect
@return list of inherited fields | [
"Get",
"inherited",
"fields",
"of",
"a",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L112-L120 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.getWrapperType | public Class<?> getWrapperType(Class<?> primitiveType) {
for(PrimitiveEnum p : PrimitiveEnum.values()) {
if(p.getType().equals(primitiveType)) {
return p.getClazz();
}
}
return primitiveType; // if not primitive, return it as is
} | java | public Class<?> getWrapperType(Class<?> primitiveType) {
for(PrimitiveEnum p : PrimitiveEnum.values()) {
if(p.getType().equals(primitiveType)) {
return p.getClazz();
}
}
return primitiveType; // if not primitive, return it as is
} | [
"public",
"Class",
"<",
"?",
">",
"getWrapperType",
"(",
"Class",
"<",
"?",
">",
"primitiveType",
")",
"{",
"for",
"(",
"PrimitiveEnum",
"p",
":",
"PrimitiveEnum",
".",
"values",
"(",
")",
")",
"{",
"if",
"(",
"p",
".",
"getType",
"(",
")",
".",
"e... | Get wrapper type of a primitive type.
@param primitiveType to get its wrapper type
@return the wrapper type of the given primitive type | [
"Get",
"wrapper",
"type",
"of",
"a",
"primitive",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L159-L167 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isPrimitiveFieldWithDefaultValue | public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException {
Class<?> fieldType = field.getType();
if (!fieldType.isPrimitive()) {
return false;
}
Object fieldValue = getFieldValue(object, field);
if (fieldValue == null) {
return false;
}
if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) {
return true;
}
if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) {
return true;
}
if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) {
return true;
}
if (fieldType.equals(int.class) && (int) fieldValue == 0) {
return true;
}
if (fieldType.equals(long.class) && (long) fieldValue == 0L) {
return true;
}
if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) {
return true;
}
if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) {
return true;
}
if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') {
return true;
}
return false;
} | java | public static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field) throws IllegalAccessException {
Class<?> fieldType = field.getType();
if (!fieldType.isPrimitive()) {
return false;
}
Object fieldValue = getFieldValue(object, field);
if (fieldValue == null) {
return false;
}
if (fieldType.equals(boolean.class) && (boolean) fieldValue == false) {
return true;
}
if (fieldType.equals(byte.class) && (byte) fieldValue == (byte) 0) {
return true;
}
if (fieldType.equals(short.class) && (short) fieldValue == (short) 0) {
return true;
}
if (fieldType.equals(int.class) && (int) fieldValue == 0) {
return true;
}
if (fieldType.equals(long.class) && (long) fieldValue == 0L) {
return true;
}
if (fieldType.equals(float.class) && (float) fieldValue == 0.0F) {
return true;
}
if (fieldType.equals(double.class) && (double) fieldValue == 0.0D) {
return true;
}
if (fieldType.equals(char.class) && (char) fieldValue == '\u0000') {
return true;
}
return false;
} | [
"public",
"static",
"boolean",
"isPrimitiveFieldWithDefaultValue",
"(",
"final",
"Object",
"object",
",",
"final",
"Field",
"field",
")",
"throws",
"IllegalAccessException",
"{",
"Class",
"<",
"?",
">",
"fieldType",
"=",
"field",
".",
"getType",
"(",
")",
";",
... | Check if a field has a primitive type and matching default value which is set by the compiler.
@param object instance to get the field value of
@param field field to check
@return true if the field is primitive and is set to the default value, false otherwise
@throws IllegalAccessException if field cannot be accessed | [
"Check",
"if",
"a",
"field",
"has",
"a",
"primitive",
"type",
"and",
"matching",
"default",
"value",
"which",
"is",
"set",
"by",
"the",
"compiler",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L177-L211 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isCollectionType | public static boolean isCollectionType(final Type type) {
return isParameterizedType(type) && isCollectionType((Class<?>) ((ParameterizedType) type).getRawType());
} | java | public static boolean isCollectionType(final Type type) {
return isParameterizedType(type) && isCollectionType((Class<?>) ((ParameterizedType) type).getRawType());
} | [
"public",
"static",
"boolean",
"isCollectionType",
"(",
"final",
"Type",
"type",
")",
"{",
"return",
"isParameterizedType",
"(",
"type",
")",
"&&",
"isCollectionType",
"(",
"(",
"Class",
"<",
"?",
">",
")",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
... | Check if a type is a collection type.
@param type the type to check.
@return true if the type is a collection type, false otherwise | [
"Check",
"if",
"a",
"type",
"is",
"a",
"collection",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L291-L293 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isPopulatable | public static boolean isPopulatable(final Type type) {
return !isWildcardType(type) && !isTypeVariable(type) && !isCollectionType(type) && !isParameterizedType(type);
} | java | public static boolean isPopulatable(final Type type) {
return !isWildcardType(type) && !isTypeVariable(type) && !isCollectionType(type) && !isParameterizedType(type);
} | [
"public",
"static",
"boolean",
"isPopulatable",
"(",
"final",
"Type",
"type",
")",
"{",
"return",
"!",
"isWildcardType",
"(",
"type",
")",
"&&",
"!",
"isTypeVariable",
"(",
"type",
")",
"&&",
"!",
"isCollectionType",
"(",
"type",
")",
"&&",
"!",
"isParamet... | Check if a type is populatable.
@param type the type to check
@return true if the type is populatable, false otherwise | [
"Check",
"if",
"a",
"type",
"is",
"populatable",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L301-L303 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isIntrospectable | public static boolean isIntrospectable(final Class<?> type) {
return !isEnumType(type)
&& !isArrayType(type)
&& !(isCollectionType(type) && isJdkBuiltIn(type))
&& !(isMapType(type) && isJdkBuiltIn(type));
} | java | public static boolean isIntrospectable(final Class<?> type) {
return !isEnumType(type)
&& !isArrayType(type)
&& !(isCollectionType(type) && isJdkBuiltIn(type))
&& !(isMapType(type) && isJdkBuiltIn(type));
} | [
"public",
"static",
"boolean",
"isIntrospectable",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"return",
"!",
"isEnumType",
"(",
"type",
")",
"&&",
"!",
"isArrayType",
"(",
"type",
")",
"&&",
"!",
"(",
"isCollectionType",
"(",
"type",
")",
... | Check if a type should be introspected for internal fields.
@param type the type to check
@return true if the type should be introspected, false otherwise | [
"Check",
"if",
"a",
"type",
"should",
"be",
"introspected",
"for",
"internal",
"fields",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L311-L316 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isParameterizedType | public static boolean isParameterizedType(final Type type) {
return type != null && type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length > 0;
} | java | public static boolean isParameterizedType(final Type type) {
return type != null && type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length > 0;
} | [
"public",
"static",
"boolean",
"isParameterizedType",
"(",
"final",
"Type",
"type",
")",
"{",
"return",
"type",
"!=",
"null",
"&&",
"type",
"instanceof",
"ParameterizedType",
"&&",
"(",
"(",
"ParameterizedType",
")",
"type",
")",
".",
"getActualTypeArguments",
"... | Check if a type is a parameterized type
@param type the type to check
@return true if the type is parameterized, false otherwise | [
"Check",
"if",
"a",
"type",
"is",
"a",
"parameterized",
"type"
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L344-L346 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.filterSameParameterizedTypes | public static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type) {
if (type instanceof ParameterizedType) {
Type[] fieldArugmentTypes = ((ParameterizedType) type).getActualTypeArguments();
List<Class<?>> typesWithSameParameterizedTypes = new ArrayList<>();
for (Class<?> currentConcreteType : types) {
List<Type[]> actualTypeArguments = getActualTypeArgumentsOfGenericInterfaces(currentConcreteType);
typesWithSameParameterizedTypes.addAll(actualTypeArguments.stream().filter(currentTypeArguments -> Arrays.equals(fieldArugmentTypes, currentTypeArguments)).map(currentTypeArguments -> currentConcreteType).collect(toList()));
}
return typesWithSameParameterizedTypes;
}
return types;
} | java | public static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type) {
if (type instanceof ParameterizedType) {
Type[] fieldArugmentTypes = ((ParameterizedType) type).getActualTypeArguments();
List<Class<?>> typesWithSameParameterizedTypes = new ArrayList<>();
for (Class<?> currentConcreteType : types) {
List<Type[]> actualTypeArguments = getActualTypeArgumentsOfGenericInterfaces(currentConcreteType);
typesWithSameParameterizedTypes.addAll(actualTypeArguments.stream().filter(currentTypeArguments -> Arrays.equals(fieldArugmentTypes, currentTypeArguments)).map(currentTypeArguments -> currentConcreteType).collect(toList()));
}
return typesWithSameParameterizedTypes;
}
return types;
} | [
"public",
"static",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"filterSameParameterizedTypes",
"(",
"final",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"types",
",",
"final",
"Type",
"type",
")",
"{",
"if",
"(",
"type",
"instanceof",
"ParameterizedType",
"... | Filters a list of types to keep only elements having the same parameterized types as the given type.
@param type the type to use for the search
@param types a list of types to filter
@return a list of types having the same parameterized types as the given type | [
"Filters",
"a",
"list",
"of",
"types",
"to",
"keep",
"only",
"elements",
"having",
"the",
"same",
"parameterized",
"types",
"as",
"the",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L386-L397 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.getAnnotation | public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) {
return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null),
annotationType) : field.getAnnotation(annotationType);
} | java | public static <T extends Annotation> T getAnnotation(Field field, Class<T> annotationType) {
return field.getAnnotation(annotationType) == null ? getAnnotationFromReadMethod(getReadMethod(field).orElse(null),
annotationType) : field.getAnnotation(annotationType);
} | [
"public",
"static",
"<",
"T",
"extends",
"Annotation",
">",
"T",
"getAnnotation",
"(",
"Field",
"field",
",",
"Class",
"<",
"T",
">",
"annotationType",
")",
"{",
"return",
"field",
".",
"getAnnotation",
"(",
"annotationType",
")",
"==",
"null",
"?",
"getAn... | Looks for given annotationType on given field or read method for field.
@param field field to check
@param annotationType Type of annotation you're looking for.
@param <T> the actual type of annotation
@return given annotation if field or read method has this annotation or null. | [
"Looks",
"for",
"given",
"annotationType",
"on",
"given",
"field",
"or",
"read",
"method",
"for",
"field",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L407-L410 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.isAnnotationPresent | public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) {
final Optional<Method> readMethod = getReadMethod(field);
return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType);
} | java | public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType) {
final Optional<Method> readMethod = getReadMethod(field);
return field.isAnnotationPresent(annotationType) || readMethod.isPresent() && readMethod.get().isAnnotationPresent(annotationType);
} | [
"public",
"static",
"boolean",
"isAnnotationPresent",
"(",
"Field",
"field",
",",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"annotationType",
")",
"{",
"final",
"Optional",
"<",
"Method",
">",
"readMethod",
"=",
"getReadMethod",
"(",
"field",
")",
";",
... | Checks if field or corresponding read method is annotated with given annotationType.
@param field Field to check
@param annotationType Annotation you're looking for.
@return true if field or read method it annotated with given annotationType or false. | [
"Checks",
"if",
"field",
"or",
"corresponding",
"read",
"method",
"is",
"annotated",
"with",
"given",
"annotationType",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L419-L422 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.createEmptyCollectionForType | public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) {
rejectUnsupportedTypes(fieldType);
Collection<?> collection;
try {
collection = (Collection<?>) fieldType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
if (fieldType.equals(ArrayBlockingQueue.class)) {
collection = new ArrayBlockingQueue<>(initialSize);
} else {
collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType);
}
}
return collection;
} | java | public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) {
rejectUnsupportedTypes(fieldType);
Collection<?> collection;
try {
collection = (Collection<?>) fieldType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
if (fieldType.equals(ArrayBlockingQueue.class)) {
collection = new ArrayBlockingQueue<>(initialSize);
} else {
collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType);
}
}
return collection;
} | [
"public",
"static",
"Collection",
"<",
"?",
">",
"createEmptyCollectionForType",
"(",
"Class",
"<",
"?",
">",
"fieldType",
",",
"int",
"initialSize",
")",
"{",
"rejectUnsupportedTypes",
"(",
"fieldType",
")",
";",
"Collection",
"<",
"?",
">",
"collection",
";"... | Create an empty collection for the given type.
@param fieldType for which an empty collection should we created
@param initialSize initial size of the collection
@return empty collection | [
"Create",
"an",
"empty",
"collection",
"for",
"the",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L460-L473 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java | ReflectionUtils.getReadMethod | public static Optional<Method> getReadMethod(Field field) {
String fieldName = field.getName();
Class<?> fieldClass = field.getDeclaringClass();
String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1);
// try to find getProperty
Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass);
if (getter.isPresent()) {
return getter;
}
// try to find isProperty for boolean properties
return getPublicMethod("is" + capitalizedFieldName, fieldClass);
} | java | public static Optional<Method> getReadMethod(Field field) {
String fieldName = field.getName();
Class<?> fieldClass = field.getDeclaringClass();
String capitalizedFieldName = fieldName.substring(0, 1).toUpperCase(ENGLISH) + fieldName.substring(1);
// try to find getProperty
Optional<Method> getter = getPublicMethod("get" + capitalizedFieldName, fieldClass);
if (getter.isPresent()) {
return getter;
}
// try to find isProperty for boolean properties
return getPublicMethod("is" + capitalizedFieldName, fieldClass);
} | [
"public",
"static",
"Optional",
"<",
"Method",
">",
"getReadMethod",
"(",
"Field",
"field",
")",
"{",
"String",
"fieldName",
"=",
"field",
".",
"getName",
"(",
")",
";",
"Class",
"<",
"?",
">",
"fieldClass",
"=",
"field",
".",
"getDeclaringClass",
"(",
"... | Get the read method for given field.
@param field field to get the read method for.
@return Optional of read method or empty if field has no read method | [
"Get",
"the",
"read",
"method",
"for",
"given",
"field",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/ReflectionUtils.java#L510-L521 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/randomizers/registry/AnnotationRandomizerRegistry.java | AnnotationRandomizerRegistry.getRandomizer | @Override
public Randomizer<?> getRandomizer(Field field) {
if (field.isAnnotationPresent(org.jeasy.random.annotation.Randomizer.class)) {
org.jeasy.random.annotation.Randomizer randomizer = field.getAnnotation(org.jeasy.random.annotation.Randomizer.class);
Class<?> type = randomizer.value();
RandomizerArgument[] arguments = randomizer.args();
return ReflectionUtils.newInstance(type, arguments);
}
return null;
} | java | @Override
public Randomizer<?> getRandomizer(Field field) {
if (field.isAnnotationPresent(org.jeasy.random.annotation.Randomizer.class)) {
org.jeasy.random.annotation.Randomizer randomizer = field.getAnnotation(org.jeasy.random.annotation.Randomizer.class);
Class<?> type = randomizer.value();
RandomizerArgument[] arguments = randomizer.args();
return ReflectionUtils.newInstance(type, arguments);
}
return null;
} | [
"@",
"Override",
"public",
"Randomizer",
"<",
"?",
">",
"getRandomizer",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isAnnotationPresent",
"(",
"org",
".",
"jeasy",
".",
"random",
".",
"annotation",
".",
"Randomizer",
".",
"class",
")",
")... | Retrieves a randomizer for the given field.
@param field the field for which a randomizer was registered
@return the randomizer registered for the given field | [
"Retrieves",
"a",
"randomizer",
"for",
"the",
"given",
"field",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/randomizers/registry/AnnotationRandomizerRegistry.java#L54-L63 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/randomizers/AbstractRandomizer.java | AbstractRandomizer.nextDouble | protected double nextDouble(final double min, final double max) {
double value = min + (random.nextDouble() * (max - min));
if (value < min) {
return min;
} else if (value > max) {
return max;
} else {
return value;
}
// NB: ThreadLocalRandom.current().nextDouble(min, max)) cannot be use because the seed is not configurable
// and is created per thread (see Javadoc)
} | java | protected double nextDouble(final double min, final double max) {
double value = min + (random.nextDouble() * (max - min));
if (value < min) {
return min;
} else if (value > max) {
return max;
} else {
return value;
}
// NB: ThreadLocalRandom.current().nextDouble(min, max)) cannot be use because the seed is not configurable
// and is created per thread (see Javadoc)
} | [
"protected",
"double",
"nextDouble",
"(",
"final",
"double",
"min",
",",
"final",
"double",
"max",
")",
"{",
"double",
"value",
"=",
"min",
"+",
"(",
"random",
".",
"nextDouble",
"(",
")",
"*",
"(",
"max",
"-",
"min",
")",
")",
";",
"if",
"(",
"val... | Return a random double in the given range.
@param min value
@param max value
@return random double in the given range | [
"Return",
"a",
"random",
"double",
"in",
"the",
"given",
"range",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/randomizers/AbstractRandomizer.java#L65-L76 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java | TypePredicates.named | public static Predicate<Class<?>> named(final String name) {
return clazz -> clazz.getName().equals(name);
} | java | public static Predicate<Class<?>> named(final String name) {
return clazz -> clazz.getName().equals(name);
} | [
"public",
"static",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
"named",
"(",
"final",
"String",
"name",
")",
"{",
"return",
"clazz",
"->",
"clazz",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
";",
"}"
] | Create a predicate to check that a type has a given name.
@param name name on the type
@return Predicate to check that a type has a given name. | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"type",
"has",
"a",
"given",
"name",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java#L47-L49 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java | TypePredicates.inPackage | public static Predicate<Class<?>> inPackage(final String packageNamePrefix) {
return clazz -> clazz.getPackage().getName().startsWith(packageNamePrefix);
} | java | public static Predicate<Class<?>> inPackage(final String packageNamePrefix) {
return clazz -> clazz.getPackage().getName().startsWith(packageNamePrefix);
} | [
"public",
"static",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
"inPackage",
"(",
"final",
"String",
"packageNamePrefix",
")",
"{",
"return",
"clazz",
"->",
"clazz",
".",
"getPackage",
"(",
")",
".",
"getName",
"(",
")",
".",
"startsWith",
"(",
"packa... | Create a predicate to check that a type is defined in a given package.
@param packageNamePrefix prefix of the package name
@return Predicate to check that a type is defined in a given package. | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"type",
"is",
"defined",
"in",
"a",
"given",
"package",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java#L67-L69 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java | TypePredicates.isAnnotatedWith | public static Predicate<Class<?>> isAnnotatedWith(Class<? extends Annotation>... annotations) {
return clazz -> {
for (Class<? extends Annotation> annotation : annotations) {
if (clazz.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
};
} | java | public static Predicate<Class<?>> isAnnotatedWith(Class<? extends Annotation>... annotations) {
return clazz -> {
for (Class<? extends Annotation> annotation : annotations) {
if (clazz.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
};
} | [
"public",
"static",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
"isAnnotatedWith",
"(",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"...",
"annotations",
")",
"{",
"return",
"clazz",
"->",
"{",
"for",
"(",
"Class",
"<",
"?",
"extends",
"Annotatio... | Create a predicate to check that a type is annotated with one of the given annotations.
@param annotations present on the type
@return Predicate to check that a type is annotated with one of the given annotations. | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"type",
"is",
"annotated",
"with",
"one",
"of",
"the",
"given",
"annotations",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java#L77-L86 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java | TypePredicates.hasModifiers | public static Predicate<Class<?>> hasModifiers(final Integer modifiers) {
return clazz -> (modifiers & clazz.getModifiers()) == modifiers;
} | java | public static Predicate<Class<?>> hasModifiers(final Integer modifiers) {
return clazz -> (modifiers & clazz.getModifiers()) == modifiers;
} | [
"public",
"static",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
"hasModifiers",
"(",
"final",
"Integer",
"modifiers",
")",
"{",
"return",
"clazz",
"->",
"(",
"modifiers",
"&",
"clazz",
".",
"getModifiers",
"(",
")",
")",
"==",
"modifiers",
";",
"}"
] | Create a predicate to check that a type has a given set of modifiers.
@param modifiers of the type to check
@return Predicate to check that a type has a given set of modifiers | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"type",
"has",
"a",
"given",
"set",
"of",
"modifiers",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java#L121-L123 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.randomize | public <T> EasyRandomParameters randomize(Class<T> type, Randomizer<T> randomizer) {
Objects.requireNonNull(type, "Type must not be null");
Objects.requireNonNull(randomizer, "Randomizer must not be null");
customRandomizerRegistry.registerRandomizer(type, randomizer);
return this;
} | java | public <T> EasyRandomParameters randomize(Class<T> type, Randomizer<T> randomizer) {
Objects.requireNonNull(type, "Type must not be null");
Objects.requireNonNull(randomizer, "Randomizer must not be null");
customRandomizerRegistry.registerRandomizer(type, randomizer);
return this;
} | [
"public",
"<",
"T",
">",
"EasyRandomParameters",
"randomize",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"Randomizer",
"<",
"T",
">",
"randomizer",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"type",
",",
"\"Type must not be null\"",
")",
";",
"Objects",... | Register a custom randomizer for a given type.
@param type class of the type to randomize
@param randomizer the custom {@link Randomizer} to use
@param <T> The field type
@return the current {@link EasyRandomParameters} instance for method chaining | [
"Register",
"a",
"custom",
"randomizer",
"for",
"a",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L295-L300 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.excludeField | public EasyRandomParameters excludeField(Predicate<Field> predicate) {
Objects.requireNonNull(predicate, "Predicate must not be null");
fieldExclusionPredicates.add(predicate);
exclusionRandomizerRegistry.addFieldPredicate(predicate);
return this;
} | java | public EasyRandomParameters excludeField(Predicate<Field> predicate) {
Objects.requireNonNull(predicate, "Predicate must not be null");
fieldExclusionPredicates.add(predicate);
exclusionRandomizerRegistry.addFieldPredicate(predicate);
return this;
} | [
"public",
"EasyRandomParameters",
"excludeField",
"(",
"Predicate",
"<",
"Field",
">",
"predicate",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"predicate",
",",
"\"Predicate must not be null\"",
")",
";",
"fieldExclusionPredicates",
".",
"add",
"(",
"predicate",... | Exclude a field from being randomized.
@param predicate to identify the field to exclude
@return the current {@link EasyRandomParameters} instance for method chaining
@see FieldPredicates | [
"Exclude",
"a",
"field",
"from",
"being",
"randomized",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L310-L315 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.excludeType | public EasyRandomParameters excludeType(Predicate<Class<?>> predicate) {
Objects.requireNonNull(predicate, "Predicate must not be null");
typeExclusionPredicates.add(predicate);
exclusionRandomizerRegistry.addTypePredicate(predicate);
return this;
} | java | public EasyRandomParameters excludeType(Predicate<Class<?>> predicate) {
Objects.requireNonNull(predicate, "Predicate must not be null");
typeExclusionPredicates.add(predicate);
exclusionRandomizerRegistry.addTypePredicate(predicate);
return this;
} | [
"public",
"EasyRandomParameters",
"excludeType",
"(",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
"predicate",
")",
"{",
"Objects",
".",
"requireNonNull",
"(",
"predicate",
",",
"\"Predicate must not be null\"",
")",
";",
"typeExclusionPredicates",
".",
"add",
... | Exclude a type from being randomized.
@param predicate to identify the type to exclude
@return the current {@link EasyRandomParameters} instance for method chaining
@see FieldPredicates | [
"Exclude",
"a",
"type",
"from",
"being",
"randomized",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L325-L330 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.collectionSizeRange | public EasyRandomParameters collectionSizeRange(final int minCollectionSize, final int maxCollectionSize) {
if (minCollectionSize < 0) {
throw new IllegalArgumentException("minCollectionSize must be >= 0");
}
if (minCollectionSize > maxCollectionSize) {
throw new IllegalArgumentException(format("minCollectionSize (%s) must be <= than maxCollectionSize (%s)",
minCollectionSize, maxCollectionSize));
}
setCollectionSizeRange(new Range<>(minCollectionSize, maxCollectionSize));
return this;
} | java | public EasyRandomParameters collectionSizeRange(final int minCollectionSize, final int maxCollectionSize) {
if (minCollectionSize < 0) {
throw new IllegalArgumentException("minCollectionSize must be >= 0");
}
if (minCollectionSize > maxCollectionSize) {
throw new IllegalArgumentException(format("minCollectionSize (%s) must be <= than maxCollectionSize (%s)",
minCollectionSize, maxCollectionSize));
}
setCollectionSizeRange(new Range<>(minCollectionSize, maxCollectionSize));
return this;
} | [
"public",
"EasyRandomParameters",
"collectionSizeRange",
"(",
"final",
"int",
"minCollectionSize",
",",
"final",
"int",
"maxCollectionSize",
")",
"{",
"if",
"(",
"minCollectionSize",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"minCollection... | Set the collection size range.
@param minCollectionSize the minimum collection size
@param maxCollectionSize the maximum collection size
@return the current {@link EasyRandomParameters} instance for method chaining | [
"Set",
"the",
"collection",
"size",
"range",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L383-L393 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.stringLengthRange | public EasyRandomParameters stringLengthRange(final int minStringLength, final int maxStringLength) {
if (minStringLength < 0) {
throw new IllegalArgumentException("minStringLength must be >= 0");
}
if (minStringLength > maxStringLength) {
throw new IllegalArgumentException(format("minStringLength (%s) must be <= than maxStringLength (%s)",
minStringLength, maxStringLength));
}
setStringLengthRange(new Range<>(minStringLength, maxStringLength));
return this;
} | java | public EasyRandomParameters stringLengthRange(final int minStringLength, final int maxStringLength) {
if (minStringLength < 0) {
throw new IllegalArgumentException("minStringLength must be >= 0");
}
if (minStringLength > maxStringLength) {
throw new IllegalArgumentException(format("minStringLength (%s) must be <= than maxStringLength (%s)",
minStringLength, maxStringLength));
}
setStringLengthRange(new Range<>(minStringLength, maxStringLength));
return this;
} | [
"public",
"EasyRandomParameters",
"stringLengthRange",
"(",
"final",
"int",
"minStringLength",
",",
"final",
"int",
"maxStringLength",
")",
"{",
"if",
"(",
"minStringLength",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"minStringLength must ... | Set the string length range.
@param minStringLength the minimum string length
@param maxStringLength the maximum string length
@return the current {@link EasyRandomParameters} instance for method chaining | [
"Set",
"the",
"string",
"length",
"range",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L402-L412 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.dateRange | public EasyRandomParameters dateRange(final LocalDate min, final LocalDate max) {
if (min.isAfter(max)) {
throw new IllegalArgumentException("Min date should be before max date");
}
setDateRange(new Range<>(min, max));
return this;
} | java | public EasyRandomParameters dateRange(final LocalDate min, final LocalDate max) {
if (min.isAfter(max)) {
throw new IllegalArgumentException("Min date should be before max date");
}
setDateRange(new Range<>(min, max));
return this;
} | [
"public",
"EasyRandomParameters",
"dateRange",
"(",
"final",
"LocalDate",
"min",
",",
"final",
"LocalDate",
"max",
")",
"{",
"if",
"(",
"min",
".",
"isAfter",
"(",
"max",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Min date should be befor... | Set the date range.
@param min date
@param max date
@return the current {@link EasyRandomParameters} instance for method chaining | [
"Set",
"the",
"date",
"range",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L455-L461 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java | EasyRandomParameters.timeRange | public EasyRandomParameters timeRange(final LocalTime min, final LocalTime max) {
if (min.isAfter(max)) {
throw new IllegalArgumentException("Min time should be before max time");
}
setTimeRange(new Range<>(min, max));
return this;
} | java | public EasyRandomParameters timeRange(final LocalTime min, final LocalTime max) {
if (min.isAfter(max)) {
throw new IllegalArgumentException("Min time should be before max time");
}
setTimeRange(new Range<>(min, max));
return this;
} | [
"public",
"EasyRandomParameters",
"timeRange",
"(",
"final",
"LocalTime",
"min",
",",
"final",
"LocalTime",
"max",
")",
"{",
"if",
"(",
"min",
".",
"isAfter",
"(",
"max",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Min time should be befor... | Set the time range.
@param min time
@param max time
@return the current {@link EasyRandomParameters} instance for method chaining | [
"Set",
"the",
"time",
"range",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandomParameters.java#L470-L476 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/ExclusionChecker.java | ExclusionChecker.shouldBeExcluded | public boolean shouldBeExcluded(final Field field, final RandomizerContext context) {
if (isStatic(field)) {
return true;
}
Set<Predicate<Field>> fieldExclusionPredicates = context.getParameters().getFieldExclusionPredicates();
for (Predicate<Field> fieldExclusionPredicate : fieldExclusionPredicates) {
if (fieldExclusionPredicate.test(field)) {
return true;
}
}
return false;
} | java | public boolean shouldBeExcluded(final Field field, final RandomizerContext context) {
if (isStatic(field)) {
return true;
}
Set<Predicate<Field>> fieldExclusionPredicates = context.getParameters().getFieldExclusionPredicates();
for (Predicate<Field> fieldExclusionPredicate : fieldExclusionPredicates) {
if (fieldExclusionPredicate.test(field)) {
return true;
}
}
return false;
} | [
"public",
"boolean",
"shouldBeExcluded",
"(",
"final",
"Field",
"field",
",",
"final",
"RandomizerContext",
"context",
")",
"{",
"if",
"(",
"isStatic",
"(",
"field",
")",
")",
"{",
"return",
"true",
";",
"}",
"Set",
"<",
"Predicate",
"<",
"Field",
">",
"... | Given the current randomization context, should the field be excluded from being populated ?
@param field the field to check
@param context the current randomization context
@return true if the field should be excluded, false otherwise | [
"Given",
"the",
"current",
"randomization",
"context",
"should",
"the",
"field",
"be",
"excluded",
"from",
"being",
"populated",
"?"
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/ExclusionChecker.java#L50-L61 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/ExclusionChecker.java | ExclusionChecker.shouldBeExcluded | public boolean shouldBeExcluded(final Class<?> type, final RandomizerContext context) {
Set<Predicate<Class<?>>> typeExclusionPredicates = context.getParameters().getTypeExclusionPredicates();
for (Predicate<Class<?>> typeExclusionPredicate : typeExclusionPredicates) {
if (typeExclusionPredicate.test(type)) {
return true;
}
}
return false;
} | java | public boolean shouldBeExcluded(final Class<?> type, final RandomizerContext context) {
Set<Predicate<Class<?>>> typeExclusionPredicates = context.getParameters().getTypeExclusionPredicates();
for (Predicate<Class<?>> typeExclusionPredicate : typeExclusionPredicates) {
if (typeExclusionPredicate.test(type)) {
return true;
}
}
return false;
} | [
"public",
"boolean",
"shouldBeExcluded",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
",",
"final",
"RandomizerContext",
"context",
")",
"{",
"Set",
"<",
"Predicate",
"<",
"Class",
"<",
"?",
">",
">",
">",
"typeExclusionPredicates",
"=",
"context",
".",
"... | Given the current randomization context, should the type be excluded from being populated ?
@param type the type to check
@param context the current randomization context
@return true if the type should be excluded, false otherwise | [
"Given",
"the",
"current",
"randomization",
"context",
"should",
"the",
"type",
"be",
"excluded",
"from",
"being",
"populated",
"?"
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/ExclusionChecker.java#L70-L78 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/CharacterUtils.java | CharacterUtils.collectPrintableCharactersOf | public static List<Character> collectPrintableCharactersOf(Charset charset) {
List<Character> chars = new ArrayList<>();
for (int i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
char character = (char) i;
if (isPrintable(character)) {
String characterAsString = Character.toString(character);
byte[] encoded = characterAsString.getBytes(charset);
String decoded = new String(encoded, charset);
if (characterAsString.equals(decoded)) {
chars.add(character);
}
}
}
return chars;
} | java | public static List<Character> collectPrintableCharactersOf(Charset charset) {
List<Character> chars = new ArrayList<>();
for (int i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
char character = (char) i;
if (isPrintable(character)) {
String characterAsString = Character.toString(character);
byte[] encoded = characterAsString.getBytes(charset);
String decoded = new String(encoded, charset);
if (characterAsString.equals(decoded)) {
chars.add(character);
}
}
}
return chars;
} | [
"public",
"static",
"List",
"<",
"Character",
">",
"collectPrintableCharactersOf",
"(",
"Charset",
"charset",
")",
"{",
"List",
"<",
"Character",
">",
"chars",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"Character",
".",
"... | Returns a list of all printable charaters of the given charset.
@param charset
Charset to use
@return list of printable characters | [
"Returns",
"a",
"list",
"of",
"all",
"printable",
"charaters",
"of",
"the",
"given",
"charset",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/CharacterUtils.java#L49-L63 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/CharacterUtils.java | CharacterUtils.filterLetters | public static List<Character> filterLetters(List<Character> characters) {
return characters.stream().filter(Character::isLetter).collect(toList());
} | java | public static List<Character> filterLetters(List<Character> characters) {
return characters.stream().filter(Character::isLetter).collect(toList());
} | [
"public",
"static",
"List",
"<",
"Character",
">",
"filterLetters",
"(",
"List",
"<",
"Character",
">",
"characters",
")",
"{",
"return",
"characters",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"Character",
"::",
"isLetter",
")",
".",
"collect",
"(",
... | Keep only letters from a list of characters.
@param characters to filter
@return only letters | [
"Keep",
"only",
"letters",
"from",
"a",
"list",
"of",
"characters",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/CharacterUtils.java#L70-L72 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java | FieldPredicates.named | public static Predicate<Field> named(final String name) {
return field -> Pattern.compile(name).matcher(field.getName()).matches();
} | java | public static Predicate<Field> named(final String name) {
return field -> Pattern.compile(name).matcher(field.getName()).matches();
} | [
"public",
"static",
"Predicate",
"<",
"Field",
">",
"named",
"(",
"final",
"String",
"name",
")",
"{",
"return",
"field",
"->",
"Pattern",
".",
"compile",
"(",
"name",
")",
".",
"matcher",
"(",
"field",
".",
"getName",
"(",
")",
")",
".",
"matches",
... | Create a predicate to check that a field has a certain name pattern.
@param name pattern of the field name to check
@return Predicate to check that a field has a certain name pattern | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"field",
"has",
"a",
"certain",
"name",
"pattern",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java#L49-L51 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java | FieldPredicates.ofType | public static Predicate<Field> ofType(Class<?> type) {
return field -> field.getType().equals(type);
} | java | public static Predicate<Field> ofType(Class<?> type) {
return field -> field.getType().equals(type);
} | [
"public",
"static",
"Predicate",
"<",
"Field",
">",
"ofType",
"(",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"return",
"field",
"->",
"field",
".",
"getType",
"(",
")",
".",
"equals",
"(",
"type",
")",
";",
"}"
] | Create a predicate to check that a field has a certain type.
@param type of the field to check
@return Predicate to check that a field has a certain type | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"field",
"has",
"a",
"certain",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java#L59-L61 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java | FieldPredicates.inClass | public static Predicate<Field> inClass(Class<?> clazz) {
return field -> field.getDeclaringClass().equals(clazz);
} | java | public static Predicate<Field> inClass(Class<?> clazz) {
return field -> field.getDeclaringClass().equals(clazz);
} | [
"public",
"static",
"Predicate",
"<",
"Field",
">",
"inClass",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"return",
"field",
"->",
"field",
".",
"getDeclaringClass",
"(",
")",
".",
"equals",
"(",
"clazz",
")",
";",
"}"
] | Create a predicate to check that a field is defined in a given class.
@param clazz enclosing type of the field to check
@return Predicate to check that a field is defined in a given class. | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"field",
"is",
"defined",
"in",
"a",
"given",
"class",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java#L69-L71 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java | FieldPredicates.isAnnotatedWith | public static Predicate<Field> isAnnotatedWith(Class<? extends Annotation>... annotations) {
return field -> {
for (Class<? extends Annotation> annotation : annotations) {
if (field.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
};
} | java | public static Predicate<Field> isAnnotatedWith(Class<? extends Annotation>... annotations) {
return field -> {
for (Class<? extends Annotation> annotation : annotations) {
if (field.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
};
} | [
"public",
"static",
"Predicate",
"<",
"Field",
">",
"isAnnotatedWith",
"(",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"...",
"annotations",
")",
"{",
"return",
"field",
"->",
"{",
"for",
"(",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
"annotat... | Create a predicate to check that a field is annotated with one of the given annotations.
@param annotations present on the field
@return Predicate to check that a field is annotated with one of the given annotations. | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"field",
"is",
"annotated",
"with",
"one",
"of",
"the",
"given",
"annotations",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java#L79-L88 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java | FieldPredicates.hasModifiers | public static Predicate<Field> hasModifiers(final Integer modifiers) {
return field -> (modifiers & field.getModifiers()) == modifiers;
} | java | public static Predicate<Field> hasModifiers(final Integer modifiers) {
return field -> (modifiers & field.getModifiers()) == modifiers;
} | [
"public",
"static",
"Predicate",
"<",
"Field",
">",
"hasModifiers",
"(",
"final",
"Integer",
"modifiers",
")",
"{",
"return",
"field",
"->",
"(",
"modifiers",
"&",
"field",
".",
"getModifiers",
"(",
")",
")",
"==",
"modifiers",
";",
"}"
] | Create a predicate to check that a field has a given set of modifiers.
@param modifiers of the field to check
@return Predicate to check that a field has a given set of modifiers | [
"Create",
"a",
"predicate",
"to",
"check",
"that",
"a",
"field",
"has",
"a",
"given",
"set",
"of",
"modifiers",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java#L96-L98 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/util/CollectionUtils.java | CollectionUtils.randomElementOf | public static <T> T randomElementOf(final List<T> list) {
if (list.isEmpty()) {
return null;
}
return list.get(nextInt(0, list.size()));
} | java | public static <T> T randomElementOf(final List<T> list) {
if (list.isEmpty()) {
return null;
}
return list.get(nextInt(0, list.size()));
} | [
"public",
"static",
"<",
"T",
">",
"T",
"randomElementOf",
"(",
"final",
"List",
"<",
"T",
">",
"list",
")",
"{",
"if",
"(",
"list",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"list",
".",
"get",
"(",
"nextInt",
"("... | Get a random element from the list.
@param list the input list
@param <T> the type of elements in the list
@return a random element from the list or null if the list is empty | [
"Get",
"a",
"random",
"element",
"from",
"the",
"list",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/util/CollectionUtils.java#L46-L51 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandom.java | EasyRandom.nextObject | public <T> T nextObject(final Class<T> type) {
return doPopulateBean(type, new RandomizationContext(type, parameters));
} | java | public <T> T nextObject(final Class<T> type) {
return doPopulateBean(type, new RandomizationContext(type, parameters));
} | [
"public",
"<",
"T",
">",
"T",
"nextObject",
"(",
"final",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"doPopulateBean",
"(",
"type",
",",
"new",
"RandomizationContext",
"(",
"type",
",",
"parameters",
")",
")",
";",
"}"
] | Generate a random instance of the given type.
@param type the type for which an instance will be generated
@param <T> the actual type of the target object
@return a random instance of the given type
@throws ObjectCreationException when unable to create a new instance of the given type | [
"Generate",
"a",
"random",
"instance",
"of",
"the",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandom.java#L96-L98 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/EasyRandom.java | EasyRandom.objects | public <T> Stream<T> objects(final Class<T> type, final int streamSize) {
if (streamSize < 0) {
throw new IllegalArgumentException("The stream size must be positive");
}
return Stream.generate(() -> nextObject(type)).limit(streamSize);
} | java | public <T> Stream<T> objects(final Class<T> type, final int streamSize) {
if (streamSize < 0) {
throw new IllegalArgumentException("The stream size must be positive");
}
return Stream.generate(() -> nextObject(type)).limit(streamSize);
} | [
"public",
"<",
"T",
">",
"Stream",
"<",
"T",
">",
"objects",
"(",
"final",
"Class",
"<",
"T",
">",
"type",
",",
"final",
"int",
"streamSize",
")",
"{",
"if",
"(",
"streamSize",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"T... | Generate a stream of random instances of the given type.
@param type the type for which instances will be generated
@param streamSize the number of instances to generate
@param <T> the actual type of the target objects
@return a stream of random instances of the given type
@throws ObjectCreationException when unable to create a new instance of the given type | [
"Generate",
"a",
"stream",
"of",
"random",
"instances",
"of",
"the",
"given",
"type",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/EasyRandom.java#L109-L115 | train |
j-easy/easy-random | easy-random-core/src/main/java/org/jeasy/random/randomizers/misc/EnumRandomizer.java | EnumRandomizer.getFilteredList | private List<E> getFilteredList(Class<E> enumeration, E... excludedValues) {
List<E> filteredValues = new ArrayList<>();
Collections.addAll(filteredValues, enumeration.getEnumConstants());
if (excludedValues != null) {
for (E element : excludedValues) {
filteredValues.remove(element);
}
}
return filteredValues;
} | java | private List<E> getFilteredList(Class<E> enumeration, E... excludedValues) {
List<E> filteredValues = new ArrayList<>();
Collections.addAll(filteredValues, enumeration.getEnumConstants());
if (excludedValues != null) {
for (E element : excludedValues) {
filteredValues.remove(element);
}
}
return filteredValues;
} | [
"private",
"List",
"<",
"E",
">",
"getFilteredList",
"(",
"Class",
"<",
"E",
">",
"enumeration",
",",
"E",
"...",
"excludedValues",
")",
"{",
"List",
"<",
"E",
">",
"filteredValues",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Collections",
".",
"ad... | Get a subset of enumeration.
@return the enumeration values minus those excluded. | [
"Get",
"a",
"subset",
"of",
"enumeration",
"."
] | 816b0d6a74c7288af111e70ae1b0b57d7fe3b59d | https://github.com/j-easy/easy-random/blob/816b0d6a74c7288af111e70ae1b0b57d7fe3b59d/easy-random-core/src/main/java/org/jeasy/random/randomizers/misc/EnumRandomizer.java#L136-L145 | train |
TNG/ArchUnit | archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java | JavaPackage.accept | @PublicAPI(usage = ACCESS)
public void accept(Predicate<? super JavaClass> predicate, ClassVisitor visitor) {
for (JavaClass javaClass : getClassesWith(predicate)) {
visitor.visit(javaClass);
}
for (JavaPackage subPackage : getSubPackages()) {
subPackage.accept(predicate, visitor);
}
} | java | @PublicAPI(usage = ACCESS)
public void accept(Predicate<? super JavaClass> predicate, ClassVisitor visitor) {
for (JavaClass javaClass : getClassesWith(predicate)) {
visitor.visit(javaClass);
}
for (JavaPackage subPackage : getSubPackages()) {
subPackage.accept(predicate, visitor);
}
} | [
"@",
"PublicAPI",
"(",
"usage",
"=",
"ACCESS",
")",
"public",
"void",
"accept",
"(",
"Predicate",
"<",
"?",
"super",
"JavaClass",
">",
"predicate",
",",
"ClassVisitor",
"visitor",
")",
"{",
"for",
"(",
"JavaClass",
"javaClass",
":",
"getClassesWith",
"(",
... | Traverses the package tree visiting each matching class.
@param predicate determines which classes within the package tree should be visited
@param visitor will receive each class in the package tree matching the given predicate
@see #accept(Predicate, PackageVisitor) | [
"Traverses",
"the",
"package",
"tree",
"visiting",
"each",
"matching",
"class",
"."
] | 024c5d2502e91de6cb586b86c7084dbd12f3ef37 | https://github.com/TNG/ArchUnit/blob/024c5d2502e91de6cb586b86c7084dbd12f3ef37/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java#L350-L358 | train |
TNG/ArchUnit | archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java | JavaPackage.accept | @PublicAPI(usage = ACCESS)
public void accept(Predicate<? super JavaPackage> predicate, PackageVisitor visitor) {
if (predicate.apply(this)) {
visitor.visit(this);
}
for (JavaPackage subPackage : getSubPackages()) {
subPackage.accept(predicate, visitor);
}
} | java | @PublicAPI(usage = ACCESS)
public void accept(Predicate<? super JavaPackage> predicate, PackageVisitor visitor) {
if (predicate.apply(this)) {
visitor.visit(this);
}
for (JavaPackage subPackage : getSubPackages()) {
subPackage.accept(predicate, visitor);
}
} | [
"@",
"PublicAPI",
"(",
"usage",
"=",
"ACCESS",
")",
"public",
"void",
"accept",
"(",
"Predicate",
"<",
"?",
"super",
"JavaPackage",
">",
"predicate",
",",
"PackageVisitor",
"visitor",
")",
"{",
"if",
"(",
"predicate",
".",
"apply",
"(",
"this",
")",
")",... | Traverses the package tree visiting each matching package.
@param predicate determines which packages within the package tree should be visited
@param visitor will receive each package in the package tree matching the given predicate
@see #accept(Predicate, ClassVisitor) | [
"Traverses",
"the",
"package",
"tree",
"visiting",
"each",
"matching",
"package",
"."
] | 024c5d2502e91de6cb586b86c7084dbd12f3ef37 | https://github.com/TNG/ArchUnit/blob/024c5d2502e91de6cb586b86c7084dbd12f3ef37/archunit/src/main/java/com/tngtech/archunit/core/domain/JavaPackage.java#L366-L374 | train |
TNG/ArchUnit | archunit-example/example-plain/src/main/java/com/tngtech/archunit/example/ClassViolatingCodingRules.java | ClassViolatingCodingRules.printToStandardStream | public void printToStandardStream() throws FileNotFoundException {
System.out.println("I'm gonna print to the command line"); // Violates rule not to write to standard streams
System.err.println("I'm gonna print to the command line"); // Violates rule not to write to standard streams
new SomeCustomException().printStackTrace(); // Violates rule not to write to standard streams
new SomeCustomException().printStackTrace(new PrintStream("/some/file")); // this is okay, since it's a custom PrintStream
new SomeCustomException().printStackTrace(new PrintWriter("/some/file")); // this is okay, since it's a custom PrintWriter
} | java | public void printToStandardStream() throws FileNotFoundException {
System.out.println("I'm gonna print to the command line"); // Violates rule not to write to standard streams
System.err.println("I'm gonna print to the command line"); // Violates rule not to write to standard streams
new SomeCustomException().printStackTrace(); // Violates rule not to write to standard streams
new SomeCustomException().printStackTrace(new PrintStream("/some/file")); // this is okay, since it's a custom PrintStream
new SomeCustomException().printStackTrace(new PrintWriter("/some/file")); // this is okay, since it's a custom PrintWriter
} | [
"public",
"void",
"printToStandardStream",
"(",
")",
"throws",
"FileNotFoundException",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"I'm gonna print to the command line\"",
")",
";",
"// Violates rule not to write to standard streams",
"System",
".",
"err",
".",
"pr... | Violates rules not to use java.util.logging & that loggers should be private static final | [
"Violates",
"rules",
"not",
"to",
"use",
"java",
".",
"util",
".",
"logging",
"&",
"that",
"loggers",
"should",
"be",
"private",
"static",
"final"
] | 024c5d2502e91de6cb586b86c7084dbd12f3ef37 | https://github.com/TNG/ArchUnit/blob/024c5d2502e91de6cb586b86c7084dbd12f3ef37/archunit-example/example-plain/src/main/java/com/tngtech/archunit/example/ClassViolatingCodingRules.java#L11-L18 | train |
b3log/latke | latke-core/src/main/java/org/json/JSONTokener.java | JSONTokener.back | public void back() throws JSONException {
if (this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported");
}
this.decrementIndexes();
this.usePrevious = true;
this.eof = false;
} | java | public void back() throws JSONException {
if (this.usePrevious || this.index <= 0) {
throw new JSONException("Stepping back two steps is not supported");
}
this.decrementIndexes();
this.usePrevious = true;
this.eof = false;
} | [
"public",
"void",
"back",
"(",
")",
"throws",
"JSONException",
"{",
"if",
"(",
"this",
".",
"usePrevious",
"||",
"this",
".",
"index",
"<=",
"0",
")",
"{",
"throw",
"new",
"JSONException",
"(",
"\"Stepping back two steps is not supported\"",
")",
";",
"}",
"... | Back up one character. This provides a sort of lookahead capability,
so that you can test for a digit or letter before attempting to parse
the next number or identifier.
@throws JSONException Thrown if trying to step back more than 1 step
or if already at the start of the string | [
"Back",
"up",
"one",
"character",
".",
"This",
"provides",
"a",
"sort",
"of",
"lookahead",
"capability",
"so",
"that",
"you",
"can",
"test",
"for",
"a",
"digit",
"or",
"letter",
"before",
"attempting",
"to",
"parse",
"the",
"next",
"number",
"or",
"identif... | f7e08a47eeecea5f7c94006382c24f353585de33 | https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/JSONTokener.java#L105-L112 | train |
b3log/latke | latke-core/src/main/java/org/json/JSONTokener.java | JSONTokener.incrementIndexes | private void incrementIndexes(int c) {
if(c > 0) {
this.index++;
if(c=='\r') {
this.line++;
this.characterPreviousLine = this.character;
this.character=0;
}else if (c=='\n') {
if(this.previous != '\r') {
this.line++;
this.characterPreviousLine = this.character;
}
this.character=0;
} else {
this.character++;
}
}
} | java | private void incrementIndexes(int c) {
if(c > 0) {
this.index++;
if(c=='\r') {
this.line++;
this.characterPreviousLine = this.character;
this.character=0;
}else if (c=='\n') {
if(this.previous != '\r') {
this.line++;
this.characterPreviousLine = this.character;
}
this.character=0;
} else {
this.character++;
}
}
} | [
"private",
"void",
"incrementIndexes",
"(",
"int",
"c",
")",
"{",
"if",
"(",
"c",
">",
"0",
")",
"{",
"this",
".",
"index",
"++",
";",
"if",
"(",
"c",
"==",
"'",
"'",
")",
"{",
"this",
".",
"line",
"++",
";",
"this",
".",
"characterPreviousLine",... | Increments the internal indexes according to the previous character
read and the character passed as the current character.
@param c the current character read. | [
"Increments",
"the",
"internal",
"indexes",
"according",
"to",
"the",
"previous",
"character",
"read",
"and",
"the",
"character",
"passed",
"as",
"the",
"current",
"character",
"."
] | f7e08a47eeecea5f7c94006382c24f353585de33 | https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/JSONTokener.java#L218-L235 | train |
b3log/latke | latke-core/src/main/java/org/json/JSONTokener.java | JSONTokener.syntaxError | public JSONException syntaxError(String message, Throwable causedBy) {
return new JSONException(message + this.toString(), causedBy);
} | java | public JSONException syntaxError(String message, Throwable causedBy) {
return new JSONException(message + this.toString(), causedBy);
} | [
"public",
"JSONException",
"syntaxError",
"(",
"String",
"message",
",",
"Throwable",
"causedBy",
")",
"{",
"return",
"new",
"JSONException",
"(",
"message",
"+",
"this",
".",
"toString",
"(",
")",
",",
"causedBy",
")",
";",
"}"
] | Make a JSONException to signal a syntax error.
@param message The error message.
@param causedBy The throwable that caused the error.
@return A JSONException object, suitable for throwing | [
"Make",
"a",
"JSONException",
"to",
"signal",
"a",
"syntax",
"error",
"."
] | f7e08a47eeecea5f7c94006382c24f353585de33 | https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/JSONTokener.java#L515-L517 | train |
b3log/latke | latke-core/src/main/java/org/json/JSONPointer.java | JSONPointer.readByIndexToken | private Object readByIndexToken(Object current, String indexToken) throws JSONPointerException {
try {
int index = Integer.parseInt(indexToken);
JSONArray currentArr = (JSONArray) current;
if (index >= currentArr.length()) {
throw new JSONPointerException(format("index %s is out of bounds - the array has %d elements", indexToken,
Integer.valueOf(currentArr.length())));
}
try {
return currentArr.get(index);
} catch (JSONException e) {
throw new JSONPointerException("Error reading value at index position " + index, e);
}
} catch (NumberFormatException e) {
throw new JSONPointerException(format("%s is not an array index", indexToken), e);
}
} | java | private Object readByIndexToken(Object current, String indexToken) throws JSONPointerException {
try {
int index = Integer.parseInt(indexToken);
JSONArray currentArr = (JSONArray) current;
if (index >= currentArr.length()) {
throw new JSONPointerException(format("index %s is out of bounds - the array has %d elements", indexToken,
Integer.valueOf(currentArr.length())));
}
try {
return currentArr.get(index);
} catch (JSONException e) {
throw new JSONPointerException("Error reading value at index position " + index, e);
}
} catch (NumberFormatException e) {
throw new JSONPointerException(format("%s is not an array index", indexToken), e);
}
} | [
"private",
"Object",
"readByIndexToken",
"(",
"Object",
"current",
",",
"String",
"indexToken",
")",
"throws",
"JSONPointerException",
"{",
"try",
"{",
"int",
"index",
"=",
"Integer",
".",
"parseInt",
"(",
"indexToken",
")",
";",
"JSONArray",
"currentArr",
"=",
... | Matches a JSONArray element by ordinal position
@param current the JSONArray to be evaluated
@param indexToken the array index in string form
@return the matched object. If no matching item is found a
@throws JSONPointerException is thrown if the index is out of bounds | [
"Matches",
"a",
"JSONArray",
"element",
"by",
"ordinal",
"position"
] | f7e08a47eeecea5f7c94006382c24f353585de33 | https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/JSONPointer.java#L231-L247 | train |
b3log/latke | latke-core/src/main/java/org/json/JSONPointer.java | JSONPointer.toURIFragment | public String toURIFragment() {
try {
StringBuilder rval = new StringBuilder("#");
for (String token : this.refTokens) {
rval.append('/').append(URLEncoder.encode(token, ENCODING));
}
return rval.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} | java | public String toURIFragment() {
try {
StringBuilder rval = new StringBuilder("#");
for (String token : this.refTokens) {
rval.append('/').append(URLEncoder.encode(token, ENCODING));
}
return rval.toString();
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} | [
"public",
"String",
"toURIFragment",
"(",
")",
"{",
"try",
"{",
"StringBuilder",
"rval",
"=",
"new",
"StringBuilder",
"(",
"\"#\"",
")",
";",
"for",
"(",
"String",
"token",
":",
"this",
".",
"refTokens",
")",
"{",
"rval",
".",
"append",
"(",
"'",
"'",
... | Returns a string representing the JSONPointer path value using URI
fragment identifier representation | [
"Returns",
"a",
"string",
"representing",
"the",
"JSONPointer",
"path",
"value",
"using",
"URI",
"fragment",
"identifier",
"representation"
] | f7e08a47eeecea5f7c94006382c24f353585de33 | https://github.com/b3log/latke/blob/f7e08a47eeecea5f7c94006382c24f353585de33/latke-core/src/main/java/org/json/JSONPointer.java#L281-L291 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.