id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
13,900
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/diff/DiffSet.java
|
DiffSet.diffSet
|
public static DiffSet diffSet(GraphQLSchema schemaOld, GraphQLSchema schemaNew) {
Map<String, Object> introspectionOld = introspect(schemaOld);
Map<String, Object> introspectionNew = introspect(schemaNew);
return diffSet(introspectionOld, introspectionNew);
}
|
java
|
public static DiffSet diffSet(GraphQLSchema schemaOld, GraphQLSchema schemaNew) {
Map<String, Object> introspectionOld = introspect(schemaOld);
Map<String, Object> introspectionNew = introspect(schemaNew);
return diffSet(introspectionOld, introspectionNew);
}
|
[
"public",
"static",
"DiffSet",
"diffSet",
"(",
"GraphQLSchema",
"schemaOld",
",",
"GraphQLSchema",
"schemaNew",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionOld",
"=",
"introspect",
"(",
"schemaOld",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionNew",
"=",
"introspect",
"(",
"schemaNew",
")",
";",
"return",
"diffSet",
"(",
"introspectionOld",
",",
"introspectionNew",
")",
";",
"}"
] |
Creates a diff set out of the result of 2 schemas.
@param schemaOld the older schema
@param schemaNew the newer schema
@return a diff set representing them
|
[
"Creates",
"a",
"diff",
"set",
"out",
"of",
"the",
"result",
"of",
"2",
"schemas",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/diff/DiffSet.java#L63-L67
|
13,901
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLArgument.java
|
GraphQLArgument.transform
|
public GraphQLArgument transform(Consumer<Builder> builderConsumer) {
Builder builder = newArgument(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLArgument transform(Consumer<Builder> builderConsumer) {
Builder builder = newArgument(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLArgument",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newArgument",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLArgument into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new field based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLArgument",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLArgument.java#L159-L163
|
13,902
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/diff/SchemaDiff.java
|
SchemaDiff.diffSchema
|
@SuppressWarnings("unchecked")
public int diffSchema(DiffSet diffSet, DifferenceReporter reporter) {
CountingReporter countingReporter = new CountingReporter(reporter);
diffSchemaImpl(diffSet, countingReporter);
return countingReporter.breakingCount;
}
|
java
|
@SuppressWarnings("unchecked")
public int diffSchema(DiffSet diffSet, DifferenceReporter reporter) {
CountingReporter countingReporter = new CountingReporter(reporter);
diffSchemaImpl(diffSet, countingReporter);
return countingReporter.breakingCount;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"int",
"diffSchema",
"(",
"DiffSet",
"diffSet",
",",
"DifferenceReporter",
"reporter",
")",
"{",
"CountingReporter",
"countingReporter",
"=",
"new",
"CountingReporter",
"(",
"reporter",
")",
";",
"diffSchemaImpl",
"(",
"diffSet",
",",
"countingReporter",
")",
";",
"return",
"countingReporter",
".",
"breakingCount",
";",
"}"
] |
This will perform a difference on the two schemas. The reporter callback
interface will be called when differences are encountered.
@param diffSet the two schemas to compare for difference
@param reporter the place to report difference events to
@return the number of API breaking changes
|
[
"This",
"will",
"perform",
"a",
"difference",
"on",
"the",
"two",
"schemas",
".",
"The",
"reporter",
"callback",
"interface",
"will",
"be",
"called",
"when",
"differences",
"are",
"encountered",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/diff/SchemaDiff.java#L120-L126
|
13,903
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/diff/SchemaDiff.java
|
SchemaDiff.synthOperationTypeDefinition
|
private Optional<OperationTypeDefinition> synthOperationTypeDefinition(Function<Type, Optional<ObjectTypeDefinition>> typeReteriver, String opName) {
TypeName type = TypeName.newTypeName().name(capitalize(opName)).build();
Optional<ObjectTypeDefinition> typeDef = typeReteriver.apply(type);
return typeDef.map(objectTypeDefinition -> OperationTypeDefinition.newOperationTypeDefinition().name(opName).typeName(type).build());
}
|
java
|
private Optional<OperationTypeDefinition> synthOperationTypeDefinition(Function<Type, Optional<ObjectTypeDefinition>> typeReteriver, String opName) {
TypeName type = TypeName.newTypeName().name(capitalize(opName)).build();
Optional<ObjectTypeDefinition> typeDef = typeReteriver.apply(type);
return typeDef.map(objectTypeDefinition -> OperationTypeDefinition.newOperationTypeDefinition().name(opName).typeName(type).build());
}
|
[
"private",
"Optional",
"<",
"OperationTypeDefinition",
">",
"synthOperationTypeDefinition",
"(",
"Function",
"<",
"Type",
",",
"Optional",
"<",
"ObjectTypeDefinition",
">",
">",
"typeReteriver",
",",
"String",
"opName",
")",
"{",
"TypeName",
"type",
"=",
"TypeName",
".",
"newTypeName",
"(",
")",
".",
"name",
"(",
"capitalize",
"(",
"opName",
")",
")",
".",
"build",
"(",
")",
";",
"Optional",
"<",
"ObjectTypeDefinition",
">",
"typeDef",
"=",
"typeReteriver",
".",
"apply",
"(",
"type",
")",
";",
"return",
"typeDef",
".",
"map",
"(",
"objectTypeDefinition",
"->",
"OperationTypeDefinition",
".",
"newOperationTypeDefinition",
"(",
")",
".",
"name",
"(",
"opName",
")",
".",
"typeName",
"(",
"type",
")",
".",
"build",
"(",
")",
")",
";",
"}"
] |
looks for a type called `Query|Mutation|Subscription` and if it exist then assumes it as an operation def
|
[
"looks",
"for",
"a",
"type",
"called",
"Query|Mutation|Subscription",
"and",
"if",
"it",
"exist",
"then",
"assumes",
"it",
"as",
"an",
"operation",
"def"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/diff/SchemaDiff.java#L835-L839
|
13,904
|
graphql-java/graphql-java
|
src/main/java/graphql/relay/SimpleListConnection.java
|
SimpleListConnection.cursorForObjectInConnection
|
public ConnectionCursor cursorForObjectInConnection(T object) {
int index = data.indexOf(object);
if (index == -1) {
return null;
}
String cursor = createCursor(index);
return new DefaultConnectionCursor(cursor);
}
|
java
|
public ConnectionCursor cursorForObjectInConnection(T object) {
int index = data.indexOf(object);
if (index == -1) {
return null;
}
String cursor = createCursor(index);
return new DefaultConnectionCursor(cursor);
}
|
[
"public",
"ConnectionCursor",
"cursorForObjectInConnection",
"(",
"T",
"object",
")",
"{",
"int",
"index",
"=",
"data",
".",
"indexOf",
"(",
"object",
")",
";",
"if",
"(",
"index",
"==",
"-",
"1",
")",
"{",
"return",
"null",
";",
"}",
"String",
"cursor",
"=",
"createCursor",
"(",
"index",
")",
";",
"return",
"new",
"DefaultConnectionCursor",
"(",
"cursor",
")",
";",
"}"
] |
find the object's cursor, or null if the object is not in this connection.
@param object the object in play
@return a connection cursor
|
[
"find",
"the",
"object",
"s",
"cursor",
"or",
"null",
"if",
"the",
"object",
"is",
"not",
"in",
"this",
"connection",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/relay/SimpleListConnection.java#L117-L124
|
13,905
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLInputObjectField.java
|
GraphQLInputObjectField.transform
|
public GraphQLInputObjectField transform(Consumer<Builder> builderConsumer) {
Builder builder = newInputObjectField(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLInputObjectField transform(Consumer<Builder> builderConsumer) {
Builder builder = newInputObjectField(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLInputObjectField",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newInputObjectField",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLInputObjectField into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new object based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLInputObjectField",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLInputObjectField.java#L129-L133
|
13,906
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/FieldCollector.java
|
FieldCollector.collectFields
|
public MergedSelectionSet collectFields(FieldCollectorParameters parameters, SelectionSet selectionSet) {
Map<String, MergedField> subFields = new LinkedHashMap<>();
List<String> visitedFragments = new ArrayList<>();
this.collectFields(parameters, selectionSet, visitedFragments, subFields);
return newMergedSelectionSet().subFields(subFields).build();
}
|
java
|
public MergedSelectionSet collectFields(FieldCollectorParameters parameters, SelectionSet selectionSet) {
Map<String, MergedField> subFields = new LinkedHashMap<>();
List<String> visitedFragments = new ArrayList<>();
this.collectFields(parameters, selectionSet, visitedFragments, subFields);
return newMergedSelectionSet().subFields(subFields).build();
}
|
[
"public",
"MergedSelectionSet",
"collectFields",
"(",
"FieldCollectorParameters",
"parameters",
",",
"SelectionSet",
"selectionSet",
")",
"{",
"Map",
"<",
"String",
",",
"MergedField",
">",
"subFields",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"List",
"<",
"String",
">",
"visitedFragments",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"this",
".",
"collectFields",
"(",
"parameters",
",",
"selectionSet",
",",
"visitedFragments",
",",
"subFields",
")",
";",
"return",
"newMergedSelectionSet",
"(",
")",
".",
"subFields",
"(",
"subFields",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Given a selection set this will collect the sub-field selections and return it as a map
@param parameters the parameters to this method
@param selectionSet the selection set to collect on
@return a map of the sub field selections
|
[
"Given",
"a",
"selection",
"set",
"this",
"will",
"collect",
"the",
"sub",
"-",
"field",
"selections",
"and",
"return",
"it",
"as",
"a",
"map"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/FieldCollector.java#L53-L58
|
13,907
|
graphql-java/graphql-java
|
src/main/java/graphql/GraphQL.java
|
GraphQL.execute
|
public ExecutionResult execute(ExecutionInput executionInput) {
try {
return executeAsync(executionInput).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
|
java
|
public ExecutionResult execute(ExecutionInput executionInput) {
try {
return executeAsync(executionInput).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
|
[
"public",
"ExecutionResult",
"execute",
"(",
"ExecutionInput",
"executionInput",
")",
"{",
"try",
"{",
"return",
"executeAsync",
"(",
"executionInput",
")",
".",
"join",
"(",
")",
";",
"}",
"catch",
"(",
"CompletionException",
"e",
")",
"{",
"if",
"(",
"e",
".",
"getCause",
"(",
")",
"instanceof",
"RuntimeException",
")",
"{",
"throw",
"(",
"RuntimeException",
")",
"e",
".",
"getCause",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}"
] |
Executes the graphql query using the provided input object
@param executionInput {@link ExecutionInput}
@return an {@link ExecutionResult} which can include errors
|
[
"Executes",
"the",
"graphql",
"query",
"using",
"the",
"provided",
"input",
"object"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/GraphQL.java#L425-L435
|
13,908
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/SchemaPrinter.java
|
SchemaPrinter.print
|
public String print(GraphQLSchema schema) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
GraphqlFieldVisibility visibility = schema.getCodeRegistry().getFieldVisibility();
printer(schema.getClass()).print(out, schema, visibility);
List<GraphQLType> typesAsList = schema.getAllTypesAsList()
.stream()
.sorted(Comparator.comparing(GraphQLType::getName))
.collect(toList());
printType(out, typesAsList, GraphQLInterfaceType.class, visibility);
printType(out, typesAsList, GraphQLUnionType.class, visibility);
printType(out, typesAsList, GraphQLObjectType.class, visibility);
printType(out, typesAsList, GraphQLEnumType.class, visibility);
printType(out, typesAsList, GraphQLScalarType.class, visibility);
printType(out, typesAsList, GraphQLInputObjectType.class, visibility);
String result = sw.toString();
if (result.endsWith("\n\n")) {
result = result.substring(0, result.length() - 1);
}
return result;
}
|
java
|
public String print(GraphQLSchema schema) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
GraphqlFieldVisibility visibility = schema.getCodeRegistry().getFieldVisibility();
printer(schema.getClass()).print(out, schema, visibility);
List<GraphQLType> typesAsList = schema.getAllTypesAsList()
.stream()
.sorted(Comparator.comparing(GraphQLType::getName))
.collect(toList());
printType(out, typesAsList, GraphQLInterfaceType.class, visibility);
printType(out, typesAsList, GraphQLUnionType.class, visibility);
printType(out, typesAsList, GraphQLObjectType.class, visibility);
printType(out, typesAsList, GraphQLEnumType.class, visibility);
printType(out, typesAsList, GraphQLScalarType.class, visibility);
printType(out, typesAsList, GraphQLInputObjectType.class, visibility);
String result = sw.toString();
if (result.endsWith("\n\n")) {
result = result.substring(0, result.length() - 1);
}
return result;
}
|
[
"public",
"String",
"print",
"(",
"GraphQLSchema",
"schema",
")",
"{",
"StringWriter",
"sw",
"=",
"new",
"StringWriter",
"(",
")",
";",
"PrintWriter",
"out",
"=",
"new",
"PrintWriter",
"(",
"sw",
")",
";",
"GraphqlFieldVisibility",
"visibility",
"=",
"schema",
".",
"getCodeRegistry",
"(",
")",
".",
"getFieldVisibility",
"(",
")",
";",
"printer",
"(",
"schema",
".",
"getClass",
"(",
")",
")",
".",
"print",
"(",
"out",
",",
"schema",
",",
"visibility",
")",
";",
"List",
"<",
"GraphQLType",
">",
"typesAsList",
"=",
"schema",
".",
"getAllTypesAsList",
"(",
")",
".",
"stream",
"(",
")",
".",
"sorted",
"(",
"Comparator",
".",
"comparing",
"(",
"GraphQLType",
"::",
"getName",
")",
")",
".",
"collect",
"(",
"toList",
"(",
")",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLInterfaceType",
".",
"class",
",",
"visibility",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLUnionType",
".",
"class",
",",
"visibility",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLObjectType",
".",
"class",
",",
"visibility",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLEnumType",
".",
"class",
",",
"visibility",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLScalarType",
".",
"class",
",",
"visibility",
")",
";",
"printType",
"(",
"out",
",",
"typesAsList",
",",
"GraphQLInputObjectType",
".",
"class",
",",
"visibility",
")",
";",
"String",
"result",
"=",
"sw",
".",
"toString",
"(",
")",
";",
"if",
"(",
"result",
".",
"endsWith",
"(",
"\"\\n\\n\"",
")",
")",
"{",
"result",
"=",
"result",
".",
"substring",
"(",
"0",
",",
"result",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
This can print an in memory GraphQL schema back to a logical schema definition
@param schema the schema in play
@return the logical schema definition
|
[
"This",
"can",
"print",
"an",
"in",
"memory",
"GraphQL",
"schema",
"back",
"to",
"a",
"logical",
"schema",
"definition"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/SchemaPrinter.java#L225-L250
|
13,909
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionContext.java
|
ExecutionContext.addError
|
public void addError(GraphQLError error, ExecutionPath fieldPath) {
//
// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability about how per
// field errors should be handled - ie only once per field if its already there for nullability
// but unclear if its not that error path
//
for (GraphQLError graphQLError : errors) {
List<Object> path = graphQLError.getPath();
if (path != null) {
if (fieldPath.equals(ExecutionPath.fromList(path))) {
return;
}
}
}
this.errors.add(error);
}
|
java
|
public void addError(GraphQLError error, ExecutionPath fieldPath) {
//
// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability about how per
// field errors should be handled - ie only once per field if its already there for nullability
// but unclear if its not that error path
//
for (GraphQLError graphQLError : errors) {
List<Object> path = graphQLError.getPath();
if (path != null) {
if (fieldPath.equals(ExecutionPath.fromList(path))) {
return;
}
}
}
this.errors.add(error);
}
|
[
"public",
"void",
"addError",
"(",
"GraphQLError",
"error",
",",
"ExecutionPath",
"fieldPath",
")",
"{",
"//",
"// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability about how per",
"// field errors should be handled - ie only once per field if its already there for nullability",
"// but unclear if its not that error path",
"//",
"for",
"(",
"GraphQLError",
"graphQLError",
":",
"errors",
")",
"{",
"List",
"<",
"Object",
">",
"path",
"=",
"graphQLError",
".",
"getPath",
"(",
")",
";",
"if",
"(",
"path",
"!=",
"null",
")",
"{",
"if",
"(",
"fieldPath",
".",
"equals",
"(",
"ExecutionPath",
".",
"fromList",
"(",
"path",
")",
")",
")",
"{",
"return",
";",
"}",
"}",
"}",
"this",
".",
"errors",
".",
"add",
"(",
"error",
")",
";",
"}"
] |
This method will only put one error per field path.
@param error the error to add
@param fieldPath the field path to put it under
|
[
"This",
"method",
"will",
"only",
"put",
"one",
"error",
"per",
"field",
"path",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionContext.java#L125-L140
|
13,910
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionContext.java
|
ExecutionContext.transform
|
public ExecutionContext transform(Consumer<ExecutionContextBuilder> builderConsumer) {
ExecutionContextBuilder builder = ExecutionContextBuilder.newExecutionContextBuilder(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public ExecutionContext transform(Consumer<ExecutionContextBuilder> builderConsumer) {
ExecutionContextBuilder builder = ExecutionContextBuilder.newExecutionContextBuilder(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"ExecutionContext",
"transform",
"(",
"Consumer",
"<",
"ExecutionContextBuilder",
">",
"builderConsumer",
")",
"{",
"ExecutionContextBuilder",
"builder",
"=",
"ExecutionContextBuilder",
".",
"newExecutionContextBuilder",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current ExecutionContext object into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new ExecutionContext object based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"ExecutionContext",
"object",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionContext.java#L186-L190
|
13,911
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLInputObjectType.java
|
GraphQLInputObjectType.transform
|
public GraphQLInputObjectType transform(Consumer<Builder> builderConsumer) {
Builder builder = newInputObject(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLInputObjectType transform(Consumer<Builder> builderConsumer) {
Builder builder = newInputObject(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLInputObjectType",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newInputObject",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLInputObjectType into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new object based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLInputObjectType",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLInputObjectType.java#L128-L132
|
13,912
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLDirective.java
|
GraphQLDirective.transform
|
public GraphQLDirective transform(Consumer<Builder> builderConsumer) {
Builder builder = newDirective(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLDirective transform(Consumer<Builder> builderConsumer) {
Builder builder = newDirective(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLDirective",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newDirective",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLDirective into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new field based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLDirective",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLDirective.java#L126-L130
|
13,913
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
|
SchemaGeneratorHelper.buildDirectiveInputType
|
public GraphQLInputType buildDirectiveInputType(Value value) {
if (value instanceof NullValue) {
return Scalars.GraphQLString;
}
if (value instanceof FloatValue) {
return Scalars.GraphQLFloat;
}
if (value instanceof StringValue) {
return Scalars.GraphQLString;
}
if (value instanceof IntValue) {
return Scalars.GraphQLInt;
}
if (value instanceof BooleanValue) {
return Scalars.GraphQLBoolean;
}
if (value instanceof ArrayValue) {
ArrayValue arrayValue = (ArrayValue) value;
return list(buildDirectiveInputType(getArrayValueWrappedType(arrayValue)));
}
return assertShouldNeverHappen("Directive values of type '%s' are not supported yet", value.getClass().getSimpleName());
}
|
java
|
public GraphQLInputType buildDirectiveInputType(Value value) {
if (value instanceof NullValue) {
return Scalars.GraphQLString;
}
if (value instanceof FloatValue) {
return Scalars.GraphQLFloat;
}
if (value instanceof StringValue) {
return Scalars.GraphQLString;
}
if (value instanceof IntValue) {
return Scalars.GraphQLInt;
}
if (value instanceof BooleanValue) {
return Scalars.GraphQLBoolean;
}
if (value instanceof ArrayValue) {
ArrayValue arrayValue = (ArrayValue) value;
return list(buildDirectiveInputType(getArrayValueWrappedType(arrayValue)));
}
return assertShouldNeverHappen("Directive values of type '%s' are not supported yet", value.getClass().getSimpleName());
}
|
[
"public",
"GraphQLInputType",
"buildDirectiveInputType",
"(",
"Value",
"value",
")",
"{",
"if",
"(",
"value",
"instanceof",
"NullValue",
")",
"{",
"return",
"Scalars",
".",
"GraphQLString",
";",
"}",
"if",
"(",
"value",
"instanceof",
"FloatValue",
")",
"{",
"return",
"Scalars",
".",
"GraphQLFloat",
";",
"}",
"if",
"(",
"value",
"instanceof",
"StringValue",
")",
"{",
"return",
"Scalars",
".",
"GraphQLString",
";",
"}",
"if",
"(",
"value",
"instanceof",
"IntValue",
")",
"{",
"return",
"Scalars",
".",
"GraphQLInt",
";",
"}",
"if",
"(",
"value",
"instanceof",
"BooleanValue",
")",
"{",
"return",
"Scalars",
".",
"GraphQLBoolean",
";",
"}",
"if",
"(",
"value",
"instanceof",
"ArrayValue",
")",
"{",
"ArrayValue",
"arrayValue",
"=",
"(",
"ArrayValue",
")",
"value",
";",
"return",
"list",
"(",
"buildDirectiveInputType",
"(",
"getArrayValueWrappedType",
"(",
"arrayValue",
")",
")",
")",
";",
"}",
"return",
"assertShouldNeverHappen",
"(",
"\"Directive values of type '%s' are not supported yet\"",
",",
"value",
".",
"getClass",
"(",
")",
".",
"getSimpleName",
"(",
")",
")",
";",
"}"
] |
We support the basic types as directive types
@param value the value to use
@return a graphql input type
|
[
"We",
"support",
"the",
"basic",
"types",
"as",
"directive",
"types"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L162-L183
|
13,914
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java
|
SchemaGeneratorHelper.buildDirective
|
public GraphQLDirective buildDirective(Directive directive, Set<GraphQLDirective> directiveDefinitions, DirectiveLocation directiveLocation) {
Optional<GraphQLDirective> directiveDefinition = directiveDefinitions.stream().filter(dd -> dd.getName().equals(directive.getName())).findFirst();
GraphQLDirective.Builder builder = GraphQLDirective.newDirective()
.name(directive.getName())
.description(buildDescription(directive, null))
.validLocations(directiveLocation);
List<GraphQLArgument> arguments = directive.getArguments().stream()
.map(arg -> buildDirectiveArgument(arg, directiveDefinition))
.collect(Collectors.toList());
if (directiveDefinition.isPresent()) {
arguments = transferMissingArguments(arguments, directiveDefinition.get());
}
arguments.forEach(builder::argument);
return builder.build();
}
|
java
|
public GraphQLDirective buildDirective(Directive directive, Set<GraphQLDirective> directiveDefinitions, DirectiveLocation directiveLocation) {
Optional<GraphQLDirective> directiveDefinition = directiveDefinitions.stream().filter(dd -> dd.getName().equals(directive.getName())).findFirst();
GraphQLDirective.Builder builder = GraphQLDirective.newDirective()
.name(directive.getName())
.description(buildDescription(directive, null))
.validLocations(directiveLocation);
List<GraphQLArgument> arguments = directive.getArguments().stream()
.map(arg -> buildDirectiveArgument(arg, directiveDefinition))
.collect(Collectors.toList());
if (directiveDefinition.isPresent()) {
arguments = transferMissingArguments(arguments, directiveDefinition.get());
}
arguments.forEach(builder::argument);
return builder.build();
}
|
[
"public",
"GraphQLDirective",
"buildDirective",
"(",
"Directive",
"directive",
",",
"Set",
"<",
"GraphQLDirective",
">",
"directiveDefinitions",
",",
"DirectiveLocation",
"directiveLocation",
")",
"{",
"Optional",
"<",
"GraphQLDirective",
">",
"directiveDefinition",
"=",
"directiveDefinitions",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"dd",
"->",
"dd",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"directive",
".",
"getName",
"(",
")",
")",
")",
".",
"findFirst",
"(",
")",
";",
"GraphQLDirective",
".",
"Builder",
"builder",
"=",
"GraphQLDirective",
".",
"newDirective",
"(",
")",
".",
"name",
"(",
"directive",
".",
"getName",
"(",
")",
")",
".",
"description",
"(",
"buildDescription",
"(",
"directive",
",",
"null",
")",
")",
".",
"validLocations",
"(",
"directiveLocation",
")",
";",
"List",
"<",
"GraphQLArgument",
">",
"arguments",
"=",
"directive",
".",
"getArguments",
"(",
")",
".",
"stream",
"(",
")",
".",
"map",
"(",
"arg",
"->",
"buildDirectiveArgument",
"(",
"arg",
",",
"directiveDefinition",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"if",
"(",
"directiveDefinition",
".",
"isPresent",
"(",
")",
")",
"{",
"arguments",
"=",
"transferMissingArguments",
"(",
"arguments",
",",
"directiveDefinition",
".",
"get",
"(",
")",
")",
";",
"}",
"arguments",
".",
"forEach",
"(",
"builder",
"::",
"argument",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
builds directives from a type and its extensions
|
[
"builds",
"directives",
"from",
"a",
"type",
"and",
"its",
"extensions"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L221-L238
|
13,915
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLEnumValueDefinition.java
|
GraphQLEnumValueDefinition.transform
|
public GraphQLEnumValueDefinition transform(Consumer<Builder> builderConsumer) {
Builder builder = newEnumValueDefinition(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLEnumValueDefinition transform(Consumer<Builder> builderConsumer) {
Builder builder = newEnumValueDefinition(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLEnumValueDefinition",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newEnumValueDefinition",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLEnumValueDefinition into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new field based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLEnumValueDefinition",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLEnumValueDefinition.java#L142-L146
|
13,916
|
graphql-java/graphql-java
|
src/main/java/graphql/ExecutionInput.java
|
ExecutionInput.transform
|
public ExecutionInput transform(Consumer<Builder> builderConsumer) {
Builder builder = new Builder()
.query(this.query)
.operationName(this.operationName)
.context(this.context)
.root(this.root)
.dataLoaderRegistry(this.dataLoaderRegistry)
.cacheControl(this.cacheControl)
.variables(this.variables);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public ExecutionInput transform(Consumer<Builder> builderConsumer) {
Builder builder = new Builder()
.query(this.query)
.operationName(this.operationName)
.context(this.context)
.root(this.root)
.dataLoaderRegistry(this.dataLoaderRegistry)
.cacheControl(this.cacheControl)
.variables(this.variables);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"ExecutionInput",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"new",
"Builder",
"(",
")",
".",
"query",
"(",
"this",
".",
"query",
")",
".",
"operationName",
"(",
"this",
".",
"operationName",
")",
".",
"context",
"(",
"this",
".",
"context",
")",
".",
"root",
"(",
"this",
".",
"root",
")",
".",
"dataLoaderRegistry",
"(",
"this",
".",
"dataLoaderRegistry",
")",
".",
"cacheControl",
"(",
"this",
".",
"cacheControl",
")",
".",
"variables",
"(",
"this",
".",
"variables",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current ExecutionInput object into another one by starting a builder with all
the current values and allows you to transform it how you want.
@param builderConsumer the consumer code that will be given a builder to transform
@return a new ExecutionInput object based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"ExecutionInput",
"object",
"into",
"another",
"one",
"by",
"starting",
"a",
"builder",
"with",
"all",
"the",
"current",
"values",
"and",
"allows",
"you",
"to",
"transform",
"it",
"how",
"you",
"want",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/ExecutionInput.java#L99-L112
|
13,917
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionStepInfo.java
|
ExecutionStepInfo.getArgument
|
@SuppressWarnings("unchecked")
public <T> T getArgument(String name) {
return (T) arguments.get(name);
}
|
java
|
@SuppressWarnings("unchecked")
public <T> T getArgument(String name) {
return (T) arguments.get(name);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"getArgument",
"(",
"String",
"name",
")",
"{",
"return",
"(",
"T",
")",
"arguments",
".",
"get",
"(",
"name",
")",
";",
"}"
] |
Returns the named argument
@param name the name of the argument
@param <T> you decide what type it is
@return the named argument or null if its not present
|
[
"Returns",
"the",
"named",
"argument"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionStepInfo.java#L140-L143
|
13,918
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/SchemaGenerator.java
|
SchemaGenerator.buildOutputType
|
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
private <T extends GraphQLOutputType> T buildOutputType(BuildContext buildCtx, Type rawType) {
TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
GraphQLOutputType outputType = buildCtx.hasOutputType(typeDefinition);
if (outputType != null) {
return typeInfo.decorate(outputType);
}
if (buildCtx.stackContains(typeInfo)) {
// we have circled around so put in a type reference and fix it up later
// otherwise we will go into an infinite loop
return typeInfo.decorate(typeRef(typeInfo.getName()));
}
buildCtx.push(typeInfo);
if (typeDefinition instanceof ObjectTypeDefinition) {
outputType = buildObjectType(buildCtx, (ObjectTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof InterfaceTypeDefinition) {
outputType = buildInterfaceType(buildCtx, (InterfaceTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof UnionTypeDefinition) {
outputType = buildUnionType(buildCtx, (UnionTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof EnumTypeDefinition) {
outputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof ScalarTypeDefinition) {
outputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
} else {
// typeDefinition is not a valid output type
throw new NotAnOutputTypeError(rawType, typeDefinition);
}
buildCtx.putOutputType(outputType);
buildCtx.pop();
return (T) typeInfo.decorate(outputType);
}
|
java
|
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
private <T extends GraphQLOutputType> T buildOutputType(BuildContext buildCtx, Type rawType) {
TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
GraphQLOutputType outputType = buildCtx.hasOutputType(typeDefinition);
if (outputType != null) {
return typeInfo.decorate(outputType);
}
if (buildCtx.stackContains(typeInfo)) {
// we have circled around so put in a type reference and fix it up later
// otherwise we will go into an infinite loop
return typeInfo.decorate(typeRef(typeInfo.getName()));
}
buildCtx.push(typeInfo);
if (typeDefinition instanceof ObjectTypeDefinition) {
outputType = buildObjectType(buildCtx, (ObjectTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof InterfaceTypeDefinition) {
outputType = buildInterfaceType(buildCtx, (InterfaceTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof UnionTypeDefinition) {
outputType = buildUnionType(buildCtx, (UnionTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof EnumTypeDefinition) {
outputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof ScalarTypeDefinition) {
outputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
} else {
// typeDefinition is not a valid output type
throw new NotAnOutputTypeError(rawType, typeDefinition);
}
buildCtx.putOutputType(outputType);
buildCtx.pop();
return (T) typeInfo.decorate(outputType);
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
",",
"\"TypeParameterUnusedInFormals\"",
"}",
")",
"private",
"<",
"T",
"extends",
"GraphQLOutputType",
">",
"T",
"buildOutputType",
"(",
"BuildContext",
"buildCtx",
",",
"Type",
"rawType",
")",
"{",
"TypeDefinition",
"typeDefinition",
"=",
"buildCtx",
".",
"getTypeDefinition",
"(",
"rawType",
")",
";",
"TypeInfo",
"typeInfo",
"=",
"TypeInfo",
".",
"typeInfo",
"(",
"rawType",
")",
";",
"GraphQLOutputType",
"outputType",
"=",
"buildCtx",
".",
"hasOutputType",
"(",
"typeDefinition",
")",
";",
"if",
"(",
"outputType",
"!=",
"null",
")",
"{",
"return",
"typeInfo",
".",
"decorate",
"(",
"outputType",
")",
";",
"}",
"if",
"(",
"buildCtx",
".",
"stackContains",
"(",
"typeInfo",
")",
")",
"{",
"// we have circled around so put in a type reference and fix it up later",
"// otherwise we will go into an infinite loop",
"return",
"typeInfo",
".",
"decorate",
"(",
"typeRef",
"(",
"typeInfo",
".",
"getName",
"(",
")",
")",
")",
";",
"}",
"buildCtx",
".",
"push",
"(",
"typeInfo",
")",
";",
"if",
"(",
"typeDefinition",
"instanceof",
"ObjectTypeDefinition",
")",
"{",
"outputType",
"=",
"buildObjectType",
"(",
"buildCtx",
",",
"(",
"ObjectTypeDefinition",
")",
"typeDefinition",
")",
";",
"}",
"else",
"if",
"(",
"typeDefinition",
"instanceof",
"InterfaceTypeDefinition",
")",
"{",
"outputType",
"=",
"buildInterfaceType",
"(",
"buildCtx",
",",
"(",
"InterfaceTypeDefinition",
")",
"typeDefinition",
")",
";",
"}",
"else",
"if",
"(",
"typeDefinition",
"instanceof",
"UnionTypeDefinition",
")",
"{",
"outputType",
"=",
"buildUnionType",
"(",
"buildCtx",
",",
"(",
"UnionTypeDefinition",
")",
"typeDefinition",
")",
";",
"}",
"else",
"if",
"(",
"typeDefinition",
"instanceof",
"EnumTypeDefinition",
")",
"{",
"outputType",
"=",
"buildEnumType",
"(",
"buildCtx",
",",
"(",
"EnumTypeDefinition",
")",
"typeDefinition",
")",
";",
"}",
"else",
"if",
"(",
"typeDefinition",
"instanceof",
"ScalarTypeDefinition",
")",
"{",
"outputType",
"=",
"buildScalar",
"(",
"buildCtx",
",",
"(",
"ScalarTypeDefinition",
")",
"typeDefinition",
")",
";",
"}",
"else",
"{",
"// typeDefinition is not a valid output type",
"throw",
"new",
"NotAnOutputTypeError",
"(",
"rawType",
",",
"typeDefinition",
")",
";",
"}",
"buildCtx",
".",
"putOutputType",
"(",
"outputType",
")",
";",
"buildCtx",
".",
"pop",
"(",
")",
";",
"return",
"(",
"T",
")",
"typeInfo",
".",
"decorate",
"(",
"outputType",
")",
";",
"}"
] |
This is the main recursive spot that builds out the various forms of Output types
@param buildCtx the context we need to work out what we are doing
@param rawType the type to be built
@return an output type
|
[
"This",
"is",
"the",
"main",
"recursive",
"spot",
"that",
"builds",
"out",
"the",
"various",
"forms",
"of",
"Output",
"types"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/SchemaGenerator.java#L391-L428
|
13,919
|
graphql-java/graphql-java
|
src/main/java/graphql/language/AstValueHelper.java
|
AstValueHelper.astFromValue
|
public static Value astFromValue(Object value, GraphQLType type) {
if (value == null) {
return null;
}
if (isNonNull(type)) {
return handleNonNull(value, (GraphQLNonNull) type);
}
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
// the value is not an array, convert the value using the list's item type.
if (isList(type)) {
return handleList(value, (GraphQLList) type);
}
// Populate the fields of the input object by creating ASTs from each value
// in the JavaScript object according to the fields in the input type.
if (type instanceof GraphQLInputObjectType) {
return handleInputObject(value, (GraphQLInputObjectType) type);
}
if (!(type instanceof GraphQLScalarType || type instanceof GraphQLEnumType)) {
throw new AssertException("Must provide Input Type, cannot use: " + type.getClass());
}
// Since value is an internally represented value, it must be serialized
// to an externally represented value before converting into an AST.
final Object serialized = serialize(type, value);
if (isNullish(serialized)) {
return null;
}
// Others serialize based on their corresponding JavaScript scalar types.
if (serialized instanceof Boolean) {
return BooleanValue.newBooleanValue().value((Boolean) serialized).build();
}
String stringValue = serialized.toString();
// numbers can be Int or Float values.
if (serialized instanceof Number) {
return handleNumber(stringValue);
}
if (serialized instanceof String) {
// Enum types use Enum literals.
if (type instanceof GraphQLEnumType) {
return EnumValue.newEnumValue().name(stringValue).build();
}
// ID types can use Int literals.
if (type == Scalars.GraphQLID && stringValue.matches("^[0-9]+$")) {
return IntValue.newIntValue().value(new BigInteger(stringValue)).build();
}
// String types are just strings but JSON'ised
return StringValue.newStringValue().value(jsonStringify(stringValue)).build();
}
throw new AssertException("'Cannot convert value to AST: " + serialized);
}
|
java
|
public static Value astFromValue(Object value, GraphQLType type) {
if (value == null) {
return null;
}
if (isNonNull(type)) {
return handleNonNull(value, (GraphQLNonNull) type);
}
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
// the value is not an array, convert the value using the list's item type.
if (isList(type)) {
return handleList(value, (GraphQLList) type);
}
// Populate the fields of the input object by creating ASTs from each value
// in the JavaScript object according to the fields in the input type.
if (type instanceof GraphQLInputObjectType) {
return handleInputObject(value, (GraphQLInputObjectType) type);
}
if (!(type instanceof GraphQLScalarType || type instanceof GraphQLEnumType)) {
throw new AssertException("Must provide Input Type, cannot use: " + type.getClass());
}
// Since value is an internally represented value, it must be serialized
// to an externally represented value before converting into an AST.
final Object serialized = serialize(type, value);
if (isNullish(serialized)) {
return null;
}
// Others serialize based on their corresponding JavaScript scalar types.
if (serialized instanceof Boolean) {
return BooleanValue.newBooleanValue().value((Boolean) serialized).build();
}
String stringValue = serialized.toString();
// numbers can be Int or Float values.
if (serialized instanceof Number) {
return handleNumber(stringValue);
}
if (serialized instanceof String) {
// Enum types use Enum literals.
if (type instanceof GraphQLEnumType) {
return EnumValue.newEnumValue().name(stringValue).build();
}
// ID types can use Int literals.
if (type == Scalars.GraphQLID && stringValue.matches("^[0-9]+$")) {
return IntValue.newIntValue().value(new BigInteger(stringValue)).build();
}
// String types are just strings but JSON'ised
return StringValue.newStringValue().value(jsonStringify(stringValue)).build();
}
throw new AssertException("'Cannot convert value to AST: " + serialized);
}
|
[
"public",
"static",
"Value",
"astFromValue",
"(",
"Object",
"value",
",",
"GraphQLType",
"type",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"isNonNull",
"(",
"type",
")",
")",
"{",
"return",
"handleNonNull",
"(",
"value",
",",
"(",
"GraphQLNonNull",
")",
"type",
")",
";",
"}",
"// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but",
"// the value is not an array, convert the value using the list's item type.",
"if",
"(",
"isList",
"(",
"type",
")",
")",
"{",
"return",
"handleList",
"(",
"value",
",",
"(",
"GraphQLList",
")",
"type",
")",
";",
"}",
"// Populate the fields of the input object by creating ASTs from each value",
"// in the JavaScript object according to the fields in the input type.",
"if",
"(",
"type",
"instanceof",
"GraphQLInputObjectType",
")",
"{",
"return",
"handleInputObject",
"(",
"value",
",",
"(",
"GraphQLInputObjectType",
")",
"type",
")",
";",
"}",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"GraphQLScalarType",
"||",
"type",
"instanceof",
"GraphQLEnumType",
")",
")",
"{",
"throw",
"new",
"AssertException",
"(",
"\"Must provide Input Type, cannot use: \"",
"+",
"type",
".",
"getClass",
"(",
")",
")",
";",
"}",
"// Since value is an internally represented value, it must be serialized",
"// to an externally represented value before converting into an AST.",
"final",
"Object",
"serialized",
"=",
"serialize",
"(",
"type",
",",
"value",
")",
";",
"if",
"(",
"isNullish",
"(",
"serialized",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Others serialize based on their corresponding JavaScript scalar types.",
"if",
"(",
"serialized",
"instanceof",
"Boolean",
")",
"{",
"return",
"BooleanValue",
".",
"newBooleanValue",
"(",
")",
".",
"value",
"(",
"(",
"Boolean",
")",
"serialized",
")",
".",
"build",
"(",
")",
";",
"}",
"String",
"stringValue",
"=",
"serialized",
".",
"toString",
"(",
")",
";",
"// numbers can be Int or Float values.",
"if",
"(",
"serialized",
"instanceof",
"Number",
")",
"{",
"return",
"handleNumber",
"(",
"stringValue",
")",
";",
"}",
"if",
"(",
"serialized",
"instanceof",
"String",
")",
"{",
"// Enum types use Enum literals.",
"if",
"(",
"type",
"instanceof",
"GraphQLEnumType",
")",
"{",
"return",
"EnumValue",
".",
"newEnumValue",
"(",
")",
".",
"name",
"(",
"stringValue",
")",
".",
"build",
"(",
")",
";",
"}",
"// ID types can use Int literals.",
"if",
"(",
"type",
"==",
"Scalars",
".",
"GraphQLID",
"&&",
"stringValue",
".",
"matches",
"(",
"\"^[0-9]+$\"",
")",
")",
"{",
"return",
"IntValue",
".",
"newIntValue",
"(",
")",
".",
"value",
"(",
"new",
"BigInteger",
"(",
"stringValue",
")",
")",
".",
"build",
"(",
")",
";",
"}",
"// String types are just strings but JSON'ised",
"return",
"StringValue",
".",
"newStringValue",
"(",
")",
".",
"value",
"(",
"jsonStringify",
"(",
"stringValue",
")",
")",
".",
"build",
"(",
")",
";",
"}",
"throw",
"new",
"AssertException",
"(",
"\"'Cannot convert value to AST: \"",
"+",
"serialized",
")",
";",
"}"
] |
Produces a GraphQL Value AST given a Java value.
A GraphQL type must be provided, which will be used to interpret different
Java values.
<pre>
| Value | GraphQL Value |
| ------------- | -------------------- |
| Object | Input Object |
| Array | List |
| Boolean | Boolean |
| String | String / Enum Value |
| Number | Int / Float |
| Mixed | Enum Value |
</pre>
@param value - the java value to be converted into graphql ast
@param type the graphql type of the object
@return a grapql language ast {@link Value}
|
[
"Produces",
"a",
"GraphQL",
"Value",
"AST",
"given",
"a",
"Java",
"value",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/language/AstValueHelper.java#L60-L119
|
13,920
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/validation/ObjectsImplementInterfaces.java
|
ObjectsImplementInterfaces.checkObjectImplementsInterface
|
private void checkObjectImplementsInterface(GraphQLObjectType objectType, GraphQLInterfaceType interfaceType, SchemaValidationErrorCollector validationErrorCollector) {
List<GraphQLFieldDefinition> fieldDefinitions = interfaceType.getFieldDefinitions();
for (GraphQLFieldDefinition interfaceFieldDef : fieldDefinitions) {
GraphQLFieldDefinition objectFieldDef = objectType.getFieldDefinition(interfaceFieldDef.getName());
if (objectFieldDef == null) {
validationErrorCollector.addError(
error(format("object type '%s' does not implement interface '%s' because field '%s' is missing",
objectType.getName(), interfaceType.getName(), interfaceFieldDef.getName())));
} else {
checkFieldTypeCompatibility(objectType, interfaceType, validationErrorCollector, interfaceFieldDef, objectFieldDef);
}
}
}
|
java
|
private void checkObjectImplementsInterface(GraphQLObjectType objectType, GraphQLInterfaceType interfaceType, SchemaValidationErrorCollector validationErrorCollector) {
List<GraphQLFieldDefinition> fieldDefinitions = interfaceType.getFieldDefinitions();
for (GraphQLFieldDefinition interfaceFieldDef : fieldDefinitions) {
GraphQLFieldDefinition objectFieldDef = objectType.getFieldDefinition(interfaceFieldDef.getName());
if (objectFieldDef == null) {
validationErrorCollector.addError(
error(format("object type '%s' does not implement interface '%s' because field '%s' is missing",
objectType.getName(), interfaceType.getName(), interfaceFieldDef.getName())));
} else {
checkFieldTypeCompatibility(objectType, interfaceType, validationErrorCollector, interfaceFieldDef, objectFieldDef);
}
}
}
|
[
"private",
"void",
"checkObjectImplementsInterface",
"(",
"GraphQLObjectType",
"objectType",
",",
"GraphQLInterfaceType",
"interfaceType",
",",
"SchemaValidationErrorCollector",
"validationErrorCollector",
")",
"{",
"List",
"<",
"GraphQLFieldDefinition",
">",
"fieldDefinitions",
"=",
"interfaceType",
".",
"getFieldDefinitions",
"(",
")",
";",
"for",
"(",
"GraphQLFieldDefinition",
"interfaceFieldDef",
":",
"fieldDefinitions",
")",
"{",
"GraphQLFieldDefinition",
"objectFieldDef",
"=",
"objectType",
".",
"getFieldDefinition",
"(",
"interfaceFieldDef",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"objectFieldDef",
"==",
"null",
")",
"{",
"validationErrorCollector",
".",
"addError",
"(",
"error",
"(",
"format",
"(",
"\"object type '%s' does not implement interface '%s' because field '%s' is missing\"",
",",
"objectType",
".",
"getName",
"(",
")",
",",
"interfaceType",
".",
"getName",
"(",
")",
",",
"interfaceFieldDef",
".",
"getName",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"checkFieldTypeCompatibility",
"(",
"objectType",
",",
"interfaceType",
",",
"validationErrorCollector",
",",
"interfaceFieldDef",
",",
"objectFieldDef",
")",
";",
"}",
"}",
"}"
] |
when completely open
|
[
"when",
"completely",
"open"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/validation/ObjectsImplementInterfaces.java#L49-L61
|
13,921
|
knightliao/disconf
|
disconf-client/src/main/java/com/baidu/disconf/client/DisconfMgr.java
|
DisconfMgr.reloadableScan
|
public synchronized void reloadableScan(String fileName) {
if (!isFirstInit) {
return;
}
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
try {
if (!DisClientConfig.getInstance().getIgnoreDisconfKeySet().contains(fileName)) {
if (scanMgr != null) {
scanMgr.reloadableScan(fileName);
}
if (disconfCoreMgr != null) {
disconfCoreMgr.processFile(fileName);
}
LOGGER.debug("disconf reloadable file: {}", fileName);
}
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
}
}
|
java
|
public synchronized void reloadableScan(String fileName) {
if (!isFirstInit) {
return;
}
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
try {
if (!DisClientConfig.getInstance().getIgnoreDisconfKeySet().contains(fileName)) {
if (scanMgr != null) {
scanMgr.reloadableScan(fileName);
}
if (disconfCoreMgr != null) {
disconfCoreMgr.processFile(fileName);
}
LOGGER.debug("disconf reloadable file: {}", fileName);
}
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
}
}
|
[
"public",
"synchronized",
"void",
"reloadableScan",
"(",
"String",
"fileName",
")",
"{",
"if",
"(",
"!",
"isFirstInit",
")",
"{",
"return",
";",
"}",
"if",
"(",
"DisClientConfig",
".",
"getInstance",
"(",
")",
".",
"ENABLE_DISCONF",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"DisClientConfig",
".",
"getInstance",
"(",
")",
".",
"getIgnoreDisconfKeySet",
"(",
")",
".",
"contains",
"(",
"fileName",
")",
")",
"{",
"if",
"(",
"scanMgr",
"!=",
"null",
")",
"{",
"scanMgr",
".",
"reloadableScan",
"(",
"fileName",
")",
";",
"}",
"if",
"(",
"disconfCoreMgr",
"!=",
"null",
")",
"{",
"disconfCoreMgr",
".",
"processFile",
"(",
"fileName",
")",
";",
"}",
"LOGGER",
".",
"debug",
"(",
"\"disconf reloadable file: {}\"",
",",
"fileName",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOGGER",
".",
"error",
"(",
"e",
".",
"toString",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
reloadable config file scan, for xml config
|
[
"reloadable",
"config",
"file",
"scan",
"for",
"xml",
"config"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-client/src/main/java/com/baidu/disconf/client/DisconfMgr.java#L174-L200
|
13,922
|
knightliao/disconf
|
disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java
|
ProtocolSupport.retryOperation
|
protected Object retryOperation(ZooKeeperOperation operation) throws KeeperException, InterruptedException {
KeeperException exception = null;
for (int i = 0; i < retryCount; i++) {
try {
return operation.execute();
} catch (KeeperException.SessionExpiredException e) {
LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e);
throw e;
} catch (KeeperException.ConnectionLossException e) {
if (exception == null) {
exception = e;
}
LOG.debug("Attempt " + i + " failed with connection loss so " +
"attempting to reconnect: " + e, e);
retryDelay(i);
}
}
throw exception;
}
|
java
|
protected Object retryOperation(ZooKeeperOperation operation) throws KeeperException, InterruptedException {
KeeperException exception = null;
for (int i = 0; i < retryCount; i++) {
try {
return operation.execute();
} catch (KeeperException.SessionExpiredException e) {
LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e);
throw e;
} catch (KeeperException.ConnectionLossException e) {
if (exception == null) {
exception = e;
}
LOG.debug("Attempt " + i + " failed with connection loss so " +
"attempting to reconnect: " + e, e);
retryDelay(i);
}
}
throw exception;
}
|
[
"protected",
"Object",
"retryOperation",
"(",
"ZooKeeperOperation",
"operation",
")",
"throws",
"KeeperException",
",",
"InterruptedException",
"{",
"KeeperException",
"exception",
"=",
"null",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"retryCount",
";",
"i",
"++",
")",
"{",
"try",
"{",
"return",
"operation",
".",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"KeeperException",
".",
"SessionExpiredException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Session expired for: \"",
"+",
"zookeeper",
"+",
"\" so reconnecting due to: \"",
"+",
"e",
",",
"e",
")",
";",
"throw",
"e",
";",
"}",
"catch",
"(",
"KeeperException",
".",
"ConnectionLossException",
"e",
")",
"{",
"if",
"(",
"exception",
"==",
"null",
")",
"{",
"exception",
"=",
"e",
";",
"}",
"LOG",
".",
"debug",
"(",
"\"Attempt \"",
"+",
"i",
"+",
"\" failed with connection loss so \"",
"+",
"\"attempting to reconnect: \"",
"+",
"e",
",",
"e",
")",
";",
"retryDelay",
"(",
"i",
")",
";",
"}",
"}",
"throw",
"exception",
";",
"}"
] |
Perform the given operation, retrying if the connection fails
@return object. it needs to be cast to the callee's expected
return type.
|
[
"Perform",
"the",
"given",
"operation",
"retrying",
"if",
"the",
"connection",
"fails"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java#L118-L136
|
13,923
|
knightliao/disconf
|
disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java
|
ProtocolSupport.ensureExists
|
protected void ensureExists(final String path, final byte[] data, final List<ACL> acl, final CreateMode flags) {
try {
retryOperation(new ZooKeeperOperation() {
public boolean execute() throws KeeperException, InterruptedException {
Stat stat = zookeeper.exists(path, false);
if (stat != null) {
return true;
}
zookeeper.create(path, data, acl, flags);
return true;
}
});
} catch (KeeperException e) {
LOG.warn("Caught: " + e, e);
} catch (InterruptedException e) {
LOG.warn("Caught: " + e, e);
}
}
|
java
|
protected void ensureExists(final String path, final byte[] data, final List<ACL> acl, final CreateMode flags) {
try {
retryOperation(new ZooKeeperOperation() {
public boolean execute() throws KeeperException, InterruptedException {
Stat stat = zookeeper.exists(path, false);
if (stat != null) {
return true;
}
zookeeper.create(path, data, acl, flags);
return true;
}
});
} catch (KeeperException e) {
LOG.warn("Caught: " + e, e);
} catch (InterruptedException e) {
LOG.warn("Caught: " + e, e);
}
}
|
[
"protected",
"void",
"ensureExists",
"(",
"final",
"String",
"path",
",",
"final",
"byte",
"[",
"]",
"data",
",",
"final",
"List",
"<",
"ACL",
">",
"acl",
",",
"final",
"CreateMode",
"flags",
")",
"{",
"try",
"{",
"retryOperation",
"(",
"new",
"ZooKeeperOperation",
"(",
")",
"{",
"public",
"boolean",
"execute",
"(",
")",
"throws",
"KeeperException",
",",
"InterruptedException",
"{",
"Stat",
"stat",
"=",
"zookeeper",
".",
"exists",
"(",
"path",
",",
"false",
")",
";",
"if",
"(",
"stat",
"!=",
"null",
")",
"{",
"return",
"true",
";",
"}",
"zookeeper",
".",
"create",
"(",
"path",
",",
"data",
",",
"acl",
",",
"flags",
")",
";",
"return",
"true",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"KeeperException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Caught: \"",
"+",
"e",
",",
"e",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Caught: \"",
"+",
"e",
",",
"e",
")",
";",
"}",
"}"
] |
Ensures that the given path exists with the given data, ACL and flags
@param path
@param acl
@param flags
|
[
"Ensures",
"that",
"the",
"given",
"path",
"exists",
"with",
"the",
"given",
"data",
"ACL",
"and",
"flags"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java#L155-L172
|
13,924
|
knightliao/disconf
|
disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java
|
ProtocolSupport.retryDelay
|
protected void retryDelay(int attemptCount) {
if (attemptCount > 0) {
try {
Thread.sleep(attemptCount * retryDelay);
} catch (InterruptedException e) {
LOG.debug("Failed to sleep: " + e, e);
}
}
}
|
java
|
protected void retryDelay(int attemptCount) {
if (attemptCount > 0) {
try {
Thread.sleep(attemptCount * retryDelay);
} catch (InterruptedException e) {
LOG.debug("Failed to sleep: " + e, e);
}
}
}
|
[
"protected",
"void",
"retryDelay",
"(",
"int",
"attemptCount",
")",
"{",
"if",
"(",
"attemptCount",
">",
"0",
")",
"{",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"attemptCount",
"*",
"retryDelay",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Failed to sleep: \"",
"+",
"e",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Performs a retry delay if this is not the first attempt
@param attemptCount the number of the attempts performed so far
|
[
"Performs",
"a",
"retry",
"delay",
"if",
"this",
"is",
"not",
"the",
"first",
"attempt"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/ProtocolSupport.java#L188-L196
|
13,925
|
knightliao/disconf
|
disconf-client/src/main/java/com/baidu/disconf/client/addons/properties/ReloadablePropertiesFactoryBean.java
|
ReloadablePropertiesFactoryBean.getFileName
|
private String getFileName(String fileName) {
if (fileName != null) {
int index = fileName.indexOf(':');
if (index < 0) {
return fileName;
} else {
fileName = fileName.substring(index + 1);
index = fileName.lastIndexOf('/');
if (index < 0) {
return fileName;
} else {
return fileName.substring(index + 1);
}
}
}
return null;
}
|
java
|
private String getFileName(String fileName) {
if (fileName != null) {
int index = fileName.indexOf(':');
if (index < 0) {
return fileName;
} else {
fileName = fileName.substring(index + 1);
index = fileName.lastIndexOf('/');
if (index < 0) {
return fileName;
} else {
return fileName.substring(index + 1);
}
}
}
return null;
}
|
[
"private",
"String",
"getFileName",
"(",
"String",
"fileName",
")",
"{",
"if",
"(",
"fileName",
"!=",
"null",
")",
"{",
"int",
"index",
"=",
"fileName",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"return",
"fileName",
";",
"}",
"else",
"{",
"fileName",
"=",
"fileName",
".",
"substring",
"(",
"index",
"+",
"1",
")",
";",
"index",
"=",
"fileName",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"return",
"fileName",
";",
"}",
"else",
"{",
"return",
"fileName",
".",
"substring",
"(",
"index",
"+",
"1",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
get file name from resource
@param fileName
@return
|
[
"get",
"file",
"name",
"from",
"resource"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-client/src/main/java/com/baidu/disconf/client/addons/properties/ReloadablePropertiesFactoryBean.java#L99-L119
|
13,926
|
knightliao/disconf
|
disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/WriteLock.java
|
WriteLock.unlock
|
public synchronized void unlock() throws RuntimeException {
if (!isClosed() && id != null) {
// we don't need to retry this operation in the case of failure
// as ZK will remove ephemeral files and we don't wanna hang
// this process when closing if we cannot reconnect to ZK
try {
ZooKeeperOperation zopdel = new ZooKeeperOperation() {
public boolean execute() throws KeeperException, InterruptedException {
zookeeper.delete(id, -1);
return Boolean.TRUE;
}
};
zopdel.execute();
} catch (InterruptedException e) {
LOG.warn("Caught: " + e, e);
//set that we have been interrupted.
Thread.currentThread().interrupt();
} catch (KeeperException.NoNodeException e) {
// do nothing
} catch (KeeperException e) {
LOG.warn("Caught: " + e, e);
throw (RuntimeException) new RuntimeException(e.getMessage()).
initCause(e);
} finally {
if (callback != null) {
callback.lockReleased();
}
id = null;
}
}
}
|
java
|
public synchronized void unlock() throws RuntimeException {
if (!isClosed() && id != null) {
// we don't need to retry this operation in the case of failure
// as ZK will remove ephemeral files and we don't wanna hang
// this process when closing if we cannot reconnect to ZK
try {
ZooKeeperOperation zopdel = new ZooKeeperOperation() {
public boolean execute() throws KeeperException, InterruptedException {
zookeeper.delete(id, -1);
return Boolean.TRUE;
}
};
zopdel.execute();
} catch (InterruptedException e) {
LOG.warn("Caught: " + e, e);
//set that we have been interrupted.
Thread.currentThread().interrupt();
} catch (KeeperException.NoNodeException e) {
// do nothing
} catch (KeeperException e) {
LOG.warn("Caught: " + e, e);
throw (RuntimeException) new RuntimeException(e.getMessage()).
initCause(e);
} finally {
if (callback != null) {
callback.lockReleased();
}
id = null;
}
}
}
|
[
"public",
"synchronized",
"void",
"unlock",
"(",
")",
"throws",
"RuntimeException",
"{",
"if",
"(",
"!",
"isClosed",
"(",
")",
"&&",
"id",
"!=",
"null",
")",
"{",
"// we don't need to retry this operation in the case of failure",
"// as ZK will remove ephemeral files and we don't wanna hang",
"// this process when closing if we cannot reconnect to ZK",
"try",
"{",
"ZooKeeperOperation",
"zopdel",
"=",
"new",
"ZooKeeperOperation",
"(",
")",
"{",
"public",
"boolean",
"execute",
"(",
")",
"throws",
"KeeperException",
",",
"InterruptedException",
"{",
"zookeeper",
".",
"delete",
"(",
"id",
",",
"-",
"1",
")",
";",
"return",
"Boolean",
".",
"TRUE",
";",
"}",
"}",
";",
"zopdel",
".",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Caught: \"",
"+",
"e",
",",
"e",
")",
";",
"//set that we have been interrupted.",
"Thread",
".",
"currentThread",
"(",
")",
".",
"interrupt",
"(",
")",
";",
"}",
"catch",
"(",
"KeeperException",
".",
"NoNodeException",
"e",
")",
"{",
"// do nothing",
"}",
"catch",
"(",
"KeeperException",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Caught: \"",
"+",
"e",
",",
"e",
")",
";",
"throw",
"(",
"RuntimeException",
")",
"new",
"RuntimeException",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
".",
"initCause",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"callback",
"!=",
"null",
")",
"{",
"callback",
".",
"lockReleased",
"(",
")",
";",
"}",
"id",
"=",
"null",
";",
"}",
"}",
"}"
] |
Removes the lock or associated znode if
you no longer require the lock. this also
removes your request in the queue for locking
in case you do not already hold the lock.
@throws RuntimeException throws a runtime exception
if it cannot connect to zookeeper.
|
[
"Removes",
"the",
"lock",
"or",
"associated",
"znode",
"if",
"you",
"no",
"longer",
"require",
"the",
"lock",
".",
"this",
"also",
"removes",
"your",
"request",
"in",
"the",
"queue",
"for",
"locking",
"in",
"case",
"you",
"do",
"not",
"already",
"hold",
"the",
"lock",
"."
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/WriteLock.java#L111-L143
|
13,927
|
knightliao/disconf
|
disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/WriteLock.java
|
WriteLock.lock
|
public synchronized boolean lock() throws KeeperException, InterruptedException {
if (isClosed()) {
return false;
}
ensurePathExists(dir);
return (Boolean) retryOperation(zop);
}
|
java
|
public synchronized boolean lock() throws KeeperException, InterruptedException {
if (isClosed()) {
return false;
}
ensurePathExists(dir);
return (Boolean) retryOperation(zop);
}
|
[
"public",
"synchronized",
"boolean",
"lock",
"(",
")",
"throws",
"KeeperException",
",",
"InterruptedException",
"{",
"if",
"(",
"isClosed",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"ensurePathExists",
"(",
"dir",
")",
";",
"return",
"(",
"Boolean",
")",
"retryOperation",
"(",
"zop",
")",
";",
"}"
] |
Attempts to acquire the exclusive write lock returning whether or not it was
acquired. Note that the exclusive lock may be acquired some time later after
this method has been invoked due to the current lock owner going away.
|
[
"Attempts",
"to",
"acquire",
"the",
"exclusive",
"write",
"lock",
"returning",
"whether",
"or",
"not",
"it",
"was",
"acquired",
".",
"Note",
"that",
"the",
"exclusive",
"lock",
"may",
"be",
"acquired",
"some",
"time",
"later",
"after",
"this",
"method",
"has",
"been",
"invoked",
"due",
"to",
"the",
"current",
"lock",
"owner",
"going",
"away",
"."
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/org/apache/zookeeper/recipes/lock/WriteLock.java#L267-L274
|
13,928
|
knightliao/disconf
|
disconf-core/src/main/java/com/baidu/disconf/core/common/utils/GsonUtils.java
|
GsonUtils.parse2Map
|
public static Map<String, String> parse2Map(String json) {
Type stringStringMap = new TypeToken<Map<String, String>>() {
}.getType();
Gson gson = new Gson();
Map<String, String> map = gson.fromJson(json, stringStringMap);
return map;
}
|
java
|
public static Map<String, String> parse2Map(String json) {
Type stringStringMap = new TypeToken<Map<String, String>>() {
}.getType();
Gson gson = new Gson();
Map<String, String> map = gson.fromJson(json, stringStringMap);
return map;
}
|
[
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"parse2Map",
"(",
"String",
"json",
")",
"{",
"Type",
"stringStringMap",
"=",
"new",
"TypeToken",
"<",
"Map",
"<",
"String",
",",
"String",
">",
">",
"(",
")",
"{",
"}",
".",
"getType",
"(",
")",
";",
"Gson",
"gson",
"=",
"new",
"Gson",
"(",
")",
";",
"Map",
"<",
"String",
",",
"String",
">",
"map",
"=",
"gson",
".",
"fromJson",
"(",
"json",
",",
"stringStringMap",
")",
";",
"return",
"map",
";",
"}"
] |
Parse json to map
@param json
@return
|
[
"Parse",
"json",
"to",
"map"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-core/src/main/java/com/baidu/disconf/core/common/utils/GsonUtils.java#L38-L47
|
13,929
|
knightliao/disconf
|
disconf-client/src/main/java/com/baidu/disconf/client/DisconfMgrBean.java
|
DisconfMgrBean.registerAspect
|
private void registerAspect(BeanDefinitionRegistry registry) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DisconfAspectJ.class);
beanDefinition.setLazyInit(false);
beanDefinition.setAbstract(false);
beanDefinition.setAutowireCandidate(true);
beanDefinition.setScope("singleton");
registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
|
java
|
private void registerAspect(BeanDefinitionRegistry registry) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DisconfAspectJ.class);
beanDefinition.setLazyInit(false);
beanDefinition.setAbstract(false);
beanDefinition.setAutowireCandidate(true);
beanDefinition.setScope("singleton");
registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
|
[
"private",
"void",
"registerAspect",
"(",
"BeanDefinitionRegistry",
"registry",
")",
"{",
"GenericBeanDefinition",
"beanDefinition",
"=",
"new",
"GenericBeanDefinition",
"(",
")",
";",
"beanDefinition",
".",
"setBeanClass",
"(",
"DisconfAspectJ",
".",
"class",
")",
";",
"beanDefinition",
".",
"setLazyInit",
"(",
"false",
")",
";",
"beanDefinition",
".",
"setAbstract",
"(",
"false",
")",
";",
"beanDefinition",
".",
"setAutowireCandidate",
"(",
"true",
")",
";",
"beanDefinition",
".",
"setScope",
"(",
"\"singleton\"",
")",
";",
"registry",
".",
"registerBeanDefinition",
"(",
"\"disconfAspectJ\"",
",",
"beanDefinition",
")",
";",
"}"
] |
register aspectJ for disconf get request
@param registry
|
[
"register",
"aspectJ",
"for",
"disconf",
"get",
"request"
] |
d413cbce9334fe38a5a24982ce4db3a6ed8e98ea
|
https://github.com/knightliao/disconf/blob/d413cbce9334fe38a5a24982ce4db3a6ed8e98ea/disconf-client/src/main/java/com/baidu/disconf/client/DisconfMgrBean.java#L91-L101
|
13,930
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/recording/RequestPatternTransformer.java
|
RequestPatternTransformer.apply
|
@Override
public RequestPatternBuilder apply(Request request) {
final RequestPatternBuilder builder = new RequestPatternBuilder(request.getMethod(), urlEqualTo(request.getUrl()));
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, CaptureHeadersSpec> header : headers.entrySet()) {
String headerName = header.getKey();
if (request.containsHeader(headerName)) {
CaptureHeadersSpec spec = header.getValue();
StringValuePattern headerMatcher = new EqualToPattern(request.getHeader(headerName), spec.getCaseInsensitive());
builder.withHeader(headerName, headerMatcher);
}
}
}
byte[] body = request.getBody();
if (bodyPatternFactory != null && body != null && body.length > 0) {
builder.withRequestBody(bodyPatternFactory.forRequest(request));
}
return builder;
}
|
java
|
@Override
public RequestPatternBuilder apply(Request request) {
final RequestPatternBuilder builder = new RequestPatternBuilder(request.getMethod(), urlEqualTo(request.getUrl()));
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, CaptureHeadersSpec> header : headers.entrySet()) {
String headerName = header.getKey();
if (request.containsHeader(headerName)) {
CaptureHeadersSpec spec = header.getValue();
StringValuePattern headerMatcher = new EqualToPattern(request.getHeader(headerName), spec.getCaseInsensitive());
builder.withHeader(headerName, headerMatcher);
}
}
}
byte[] body = request.getBody();
if (bodyPatternFactory != null && body != null && body.length > 0) {
builder.withRequestBody(bodyPatternFactory.forRequest(request));
}
return builder;
}
|
[
"@",
"Override",
"public",
"RequestPatternBuilder",
"apply",
"(",
"Request",
"request",
")",
"{",
"final",
"RequestPatternBuilder",
"builder",
"=",
"new",
"RequestPatternBuilder",
"(",
"request",
".",
"getMethod",
"(",
")",
",",
"urlEqualTo",
"(",
"request",
".",
"getUrl",
"(",
")",
")",
")",
";",
"if",
"(",
"headers",
"!=",
"null",
"&&",
"!",
"headers",
".",
"isEmpty",
"(",
")",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"CaptureHeadersSpec",
">",
"header",
":",
"headers",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"headerName",
"=",
"header",
".",
"getKey",
"(",
")",
";",
"if",
"(",
"request",
".",
"containsHeader",
"(",
"headerName",
")",
")",
"{",
"CaptureHeadersSpec",
"spec",
"=",
"header",
".",
"getValue",
"(",
")",
";",
"StringValuePattern",
"headerMatcher",
"=",
"new",
"EqualToPattern",
"(",
"request",
".",
"getHeader",
"(",
"headerName",
")",
",",
"spec",
".",
"getCaseInsensitive",
"(",
")",
")",
";",
"builder",
".",
"withHeader",
"(",
"headerName",
",",
"headerMatcher",
")",
";",
"}",
"}",
"}",
"byte",
"[",
"]",
"body",
"=",
"request",
".",
"getBody",
"(",
")",
";",
"if",
"(",
"bodyPatternFactory",
"!=",
"null",
"&&",
"body",
"!=",
"null",
"&&",
"body",
".",
"length",
">",
"0",
")",
"{",
"builder",
".",
"withRequestBody",
"(",
"bodyPatternFactory",
".",
"forRequest",
"(",
"request",
")",
")",
";",
"}",
"return",
"builder",
";",
"}"
] |
Returns a RequestPatternBuilder matching a given Request
|
[
"Returns",
"a",
"RequestPatternBuilder",
"matching",
"a",
"given",
"Request"
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/recording/RequestPatternTransformer.java#L43-L64
|
13,931
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/ResponseTemplateTransformer.java
|
ResponseTemplateTransformer.addExtraModelElements
|
protected Map<String, Object> addExtraModelElements(Request request, ResponseDefinition responseDefinition, FileSource files, Parameters parameters) {
return Collections.emptyMap();
}
|
java
|
protected Map<String, Object> addExtraModelElements(Request request, ResponseDefinition responseDefinition, FileSource files, Parameters parameters) {
return Collections.emptyMap();
}
|
[
"protected",
"Map",
"<",
"String",
",",
"Object",
">",
"addExtraModelElements",
"(",
"Request",
"request",
",",
"ResponseDefinition",
"responseDefinition",
",",
"FileSource",
"files",
",",
"Parameters",
"parameters",
")",
"{",
"return",
"Collections",
".",
"emptyMap",
"(",
")",
";",
"}"
] |
Override this to add extra elements to the template model
|
[
"Override",
"this",
"to",
"add",
"extra",
"elements",
"to",
"the",
"template",
"model"
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/ResponseTemplateTransformer.java#L186-L188
|
13,932
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/matching/RequestPatternBuilder.java
|
RequestPatternBuilder.like
|
public static RequestPatternBuilder like(RequestPattern requestPattern) {
RequestPatternBuilder builder = new RequestPatternBuilder();
builder.url = requestPattern.getUrlMatcher();
builder.method = requestPattern.getMethod();
if (requestPattern.getHeaders() != null) {
builder.headers = requestPattern.getHeaders();
}
if (requestPattern.getQueryParameters() != null) {
builder.queryParams = requestPattern.getQueryParameters();
}
if (requestPattern.getCookies() != null) {
builder.cookies = requestPattern.getCookies();
}
if (requestPattern.getBodyPatterns() != null) {
builder.bodyPatterns = requestPattern.getBodyPatterns();
}
if (requestPattern.hasInlineCustomMatcher()) {
builder.customMatcher = requestPattern.getMatcher();
}
if (requestPattern.getMultipartPatterns() != null) {
builder.multiparts = requestPattern.getMultipartPatterns();
}
builder.basicCredentials = requestPattern.getBasicAuthCredentials();
builder.customMatcherDefinition = requestPattern.getCustomMatcher();
return builder;
}
|
java
|
public static RequestPatternBuilder like(RequestPattern requestPattern) {
RequestPatternBuilder builder = new RequestPatternBuilder();
builder.url = requestPattern.getUrlMatcher();
builder.method = requestPattern.getMethod();
if (requestPattern.getHeaders() != null) {
builder.headers = requestPattern.getHeaders();
}
if (requestPattern.getQueryParameters() != null) {
builder.queryParams = requestPattern.getQueryParameters();
}
if (requestPattern.getCookies() != null) {
builder.cookies = requestPattern.getCookies();
}
if (requestPattern.getBodyPatterns() != null) {
builder.bodyPatterns = requestPattern.getBodyPatterns();
}
if (requestPattern.hasInlineCustomMatcher()) {
builder.customMatcher = requestPattern.getMatcher();
}
if (requestPattern.getMultipartPatterns() != null) {
builder.multiparts = requestPattern.getMultipartPatterns();
}
builder.basicCredentials = requestPattern.getBasicAuthCredentials();
builder.customMatcherDefinition = requestPattern.getCustomMatcher();
return builder;
}
|
[
"public",
"static",
"RequestPatternBuilder",
"like",
"(",
"RequestPattern",
"requestPattern",
")",
"{",
"RequestPatternBuilder",
"builder",
"=",
"new",
"RequestPatternBuilder",
"(",
")",
";",
"builder",
".",
"url",
"=",
"requestPattern",
".",
"getUrlMatcher",
"(",
")",
";",
"builder",
".",
"method",
"=",
"requestPattern",
".",
"getMethod",
"(",
")",
";",
"if",
"(",
"requestPattern",
".",
"getHeaders",
"(",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"headers",
"=",
"requestPattern",
".",
"getHeaders",
"(",
")",
";",
"}",
"if",
"(",
"requestPattern",
".",
"getQueryParameters",
"(",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"queryParams",
"=",
"requestPattern",
".",
"getQueryParameters",
"(",
")",
";",
"}",
"if",
"(",
"requestPattern",
".",
"getCookies",
"(",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"cookies",
"=",
"requestPattern",
".",
"getCookies",
"(",
")",
";",
"}",
"if",
"(",
"requestPattern",
".",
"getBodyPatterns",
"(",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"bodyPatterns",
"=",
"requestPattern",
".",
"getBodyPatterns",
"(",
")",
";",
"}",
"if",
"(",
"requestPattern",
".",
"hasInlineCustomMatcher",
"(",
")",
")",
"{",
"builder",
".",
"customMatcher",
"=",
"requestPattern",
".",
"getMatcher",
"(",
")",
";",
"}",
"if",
"(",
"requestPattern",
".",
"getMultipartPatterns",
"(",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"multiparts",
"=",
"requestPattern",
".",
"getMultipartPatterns",
"(",
")",
";",
"}",
"builder",
".",
"basicCredentials",
"=",
"requestPattern",
".",
"getBasicAuthCredentials",
"(",
")",
";",
"builder",
".",
"customMatcherDefinition",
"=",
"requestPattern",
".",
"getCustomMatcher",
"(",
")",
";",
"return",
"builder",
";",
"}"
] |
Construct a builder that uses an existing RequestPattern as a template
@param requestPattern A RequestPattern to copy
@return A builder based on the RequestPattern
|
[
"Construct",
"a",
"builder",
"that",
"uses",
"an",
"existing",
"RequestPattern",
"as",
"a",
"template"
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/matching/RequestPatternBuilder.java#L88-L113
|
13,933
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java
|
WireMockServer.shutdown
|
@Override
public void shutdown() {
final WireMockServer server = this;
Thread shutdownThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// We have to sleep briefly to finish serving the shutdown request before stopping the server, as
// there's no support in Jetty for shutting down after the current request.
// See http://stackoverflow.com/questions/4650713
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
server.stop();
}
});
shutdownThread.start();
}
|
java
|
@Override
public void shutdown() {
final WireMockServer server = this;
Thread shutdownThread = new Thread(new Runnable() {
@Override
public void run() {
try {
// We have to sleep briefly to finish serving the shutdown request before stopping the server, as
// there's no support in Jetty for shutting down after the current request.
// See http://stackoverflow.com/questions/4650713
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
server.stop();
}
});
shutdownThread.start();
}
|
[
"@",
"Override",
"public",
"void",
"shutdown",
"(",
")",
"{",
"final",
"WireMockServer",
"server",
"=",
"this",
";",
"Thread",
"shutdownThread",
"=",
"new",
"Thread",
"(",
"new",
"Runnable",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"// We have to sleep briefly to finish serving the shutdown request before stopping the server, as",
"// there's no support in Jetty for shutting down after the current request.",
"// See http://stackoverflow.com/questions/4650713",
"Thread",
".",
"sleep",
"(",
"100",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"server",
".",
"stop",
"(",
")",
";",
"}",
"}",
")",
";",
"shutdownThread",
".",
"start",
"(",
")",
";",
"}"
] |
Gracefully shutdown the server.
This method assumes it is being called as the result of an incoming HTTP request.
|
[
"Gracefully",
"shutdown",
"the",
"server",
"."
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java#L157-L175
|
13,934
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/recording/SnapshotStubMappingBodyExtractor.java
|
SnapshotStubMappingBodyExtractor.extractInPlace
|
public void extractInPlace(StubMapping stubMapping) {
byte[] body = stubMapping.getResponse().getByteBody();
HttpHeaders responseHeaders = stubMapping.getResponse().getHeaders();
String extension = ContentTypes.determineFileExtension(
stubMapping.getRequest().getUrl(),
responseHeaders != null ? responseHeaders.getContentTypeHeader() : ContentTypeHeader.absent(),
body);
String bodyFileName = SafeNames.makeSafeFileName(stubMapping, extension);
// used to prevent ambiguous method call error for withBody()
String noStringBody = null;
byte[] noByteBody = null;
stubMapping.setResponse(
ResponseDefinitionBuilder
.like(stubMapping.getResponse())
.withBodyFile(bodyFileName)
.withBody(noStringBody)
.withBody(noByteBody)
.withBase64Body(null)
.build()
);
fileSource.writeBinaryFile(bodyFileName, body);
}
|
java
|
public void extractInPlace(StubMapping stubMapping) {
byte[] body = stubMapping.getResponse().getByteBody();
HttpHeaders responseHeaders = stubMapping.getResponse().getHeaders();
String extension = ContentTypes.determineFileExtension(
stubMapping.getRequest().getUrl(),
responseHeaders != null ? responseHeaders.getContentTypeHeader() : ContentTypeHeader.absent(),
body);
String bodyFileName = SafeNames.makeSafeFileName(stubMapping, extension);
// used to prevent ambiguous method call error for withBody()
String noStringBody = null;
byte[] noByteBody = null;
stubMapping.setResponse(
ResponseDefinitionBuilder
.like(stubMapping.getResponse())
.withBodyFile(bodyFileName)
.withBody(noStringBody)
.withBody(noByteBody)
.withBase64Body(null)
.build()
);
fileSource.writeBinaryFile(bodyFileName, body);
}
|
[
"public",
"void",
"extractInPlace",
"(",
"StubMapping",
"stubMapping",
")",
"{",
"byte",
"[",
"]",
"body",
"=",
"stubMapping",
".",
"getResponse",
"(",
")",
".",
"getByteBody",
"(",
")",
";",
"HttpHeaders",
"responseHeaders",
"=",
"stubMapping",
".",
"getResponse",
"(",
")",
".",
"getHeaders",
"(",
")",
";",
"String",
"extension",
"=",
"ContentTypes",
".",
"determineFileExtension",
"(",
"stubMapping",
".",
"getRequest",
"(",
")",
".",
"getUrl",
"(",
")",
",",
"responseHeaders",
"!=",
"null",
"?",
"responseHeaders",
".",
"getContentTypeHeader",
"(",
")",
":",
"ContentTypeHeader",
".",
"absent",
"(",
")",
",",
"body",
")",
";",
"String",
"bodyFileName",
"=",
"SafeNames",
".",
"makeSafeFileName",
"(",
"stubMapping",
",",
"extension",
")",
";",
"// used to prevent ambiguous method call error for withBody()",
"String",
"noStringBody",
"=",
"null",
";",
"byte",
"[",
"]",
"noByteBody",
"=",
"null",
";",
"stubMapping",
".",
"setResponse",
"(",
"ResponseDefinitionBuilder",
".",
"like",
"(",
"stubMapping",
".",
"getResponse",
"(",
")",
")",
".",
"withBodyFile",
"(",
"bodyFileName",
")",
".",
"withBody",
"(",
"noStringBody",
")",
".",
"withBody",
"(",
"noByteBody",
")",
".",
"withBase64Body",
"(",
"null",
")",
".",
"build",
"(",
")",
")",
";",
"fileSource",
".",
"writeBinaryFile",
"(",
"bodyFileName",
",",
"body",
")",
";",
"}"
] |
Extracts body of the ResponseDefinition to a file written to the files source.
Modifies the ResponseDefinition to point to the file in-place.
@param stubMapping Stub mapping to extract
|
[
"Extracts",
"body",
"of",
"the",
"ResponseDefinition",
"to",
"a",
"file",
"written",
"to",
"the",
"files",
"source",
".",
"Modifies",
"the",
"ResponseDefinition",
"to",
"point",
"to",
"the",
"file",
"in",
"-",
"place",
"."
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/recording/SnapshotStubMappingBodyExtractor.java#L37-L62
|
13,935
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsHelper.java
|
HandlebarsHelper.handleError
|
protected String handleError(final String message) {
notifier().error(formatMessage(message));
return formatMessage(message);
}
|
java
|
protected String handleError(final String message) {
notifier().error(formatMessage(message));
return formatMessage(message);
}
|
[
"protected",
"String",
"handleError",
"(",
"final",
"String",
"message",
")",
"{",
"notifier",
"(",
")",
".",
"error",
"(",
"formatMessage",
"(",
"message",
")",
")",
";",
"return",
"formatMessage",
"(",
"message",
")",
";",
"}"
] |
Handle invalid helper data without exception details or because none was thrown.
@param message message to log and return
@return a message which will be used as content
|
[
"Handle",
"invalid",
"helper",
"data",
"without",
"exception",
"details",
"or",
"because",
"none",
"was",
"thrown",
"."
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsHelper.java#L39-L42
|
13,936
|
tomakehurst/wiremock
|
src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsHelper.java
|
HandlebarsHelper.handleError
|
protected String handleError(final String message, final Throwable cause) {
notifier().error(formatMessage(message), cause);
return formatMessage(message);
}
|
java
|
protected String handleError(final String message, final Throwable cause) {
notifier().error(formatMessage(message), cause);
return formatMessage(message);
}
|
[
"protected",
"String",
"handleError",
"(",
"final",
"String",
"message",
",",
"final",
"Throwable",
"cause",
")",
"{",
"notifier",
"(",
")",
".",
"error",
"(",
"formatMessage",
"(",
"message",
")",
",",
"cause",
")",
";",
"return",
"formatMessage",
"(",
"message",
")",
";",
"}"
] |
Handle invalid helper data with exception details in the log message.
@param message message to log and return
@param cause which occurred during application of the helper
@return a message which will be used as content
|
[
"Handle",
"invalid",
"helper",
"data",
"with",
"exception",
"details",
"in",
"the",
"log",
"message",
"."
] |
9d9d73463a82184ec129d620f21133ee7d52f632
|
https://github.com/tomakehurst/wiremock/blob/9d9d73463a82184ec129d620f21133ee7d52f632/src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsHelper.java#L51-L54
|
13,937
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Collector.java
|
Collector.collect
|
public static Elements collect (Evaluator eval, Element root) {
Elements elements = new Elements();
NodeTraversor.traverse(new Accumulator(root, elements, eval), root);
return elements;
}
|
java
|
public static Elements collect (Evaluator eval, Element root) {
Elements elements = new Elements();
NodeTraversor.traverse(new Accumulator(root, elements, eval), root);
return elements;
}
|
[
"public",
"static",
"Elements",
"collect",
"(",
"Evaluator",
"eval",
",",
"Element",
"root",
")",
"{",
"Elements",
"elements",
"=",
"new",
"Elements",
"(",
")",
";",
"NodeTraversor",
".",
"traverse",
"(",
"new",
"Accumulator",
"(",
"root",
",",
"elements",
",",
"eval",
")",
",",
"root",
")",
";",
"return",
"elements",
";",
"}"
] |
Build a list of elements, by visiting root and every descendant of root, and testing it against the evaluator.
@param eval Evaluator to test elements against
@param root root of tree to descend
@return list of matches; empty if none
|
[
"Build",
"a",
"list",
"of",
"elements",
"by",
"visiting",
"root",
"and",
"every",
"descendant",
"of",
"root",
"and",
"testing",
"it",
"against",
"the",
"evaluator",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Collector.java#L25-L29
|
13,938
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attribute.java
|
Attribute.setKey
|
public void setKey(String key) {
Validate.notNull(key);
key = key.trim();
Validate.notEmpty(key); // trimming could potentially make empty, so validate here
if (parent != null) {
int i = parent.indexOfKey(this.key);
if (i != Attributes.NotFound)
parent.keys[i] = key;
}
this.key = key;
}
|
java
|
public void setKey(String key) {
Validate.notNull(key);
key = key.trim();
Validate.notEmpty(key); // trimming could potentially make empty, so validate here
if (parent != null) {
int i = parent.indexOfKey(this.key);
if (i != Attributes.NotFound)
parent.keys[i] = key;
}
this.key = key;
}
|
[
"public",
"void",
"setKey",
"(",
"String",
"key",
")",
"{",
"Validate",
".",
"notNull",
"(",
"key",
")",
";",
"key",
"=",
"key",
".",
"trim",
"(",
")",
";",
"Validate",
".",
"notEmpty",
"(",
"key",
")",
";",
"// trimming could potentially make empty, so validate here",
"if",
"(",
"parent",
"!=",
"null",
")",
"{",
"int",
"i",
"=",
"parent",
".",
"indexOfKey",
"(",
"this",
".",
"key",
")",
";",
"if",
"(",
"i",
"!=",
"Attributes",
".",
"NotFound",
")",
"parent",
".",
"keys",
"[",
"i",
"]",
"=",
"key",
";",
"}",
"this",
".",
"key",
"=",
"key",
";",
"}"
] |
Set the attribute key; case is preserved.
@param key the new key; must not be null
|
[
"Set",
"the",
"attribute",
"key",
";",
"case",
"is",
"preserved",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attribute.java#L63-L73
|
13,939
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Attribute.java
|
Attribute.createFromEncoded
|
public static Attribute createFromEncoded(String unencodedKey, String encodedValue) {
String value = Entities.unescape(encodedValue, true);
return new Attribute(unencodedKey, value, null); // parent will get set when Put
}
|
java
|
public static Attribute createFromEncoded(String unencodedKey, String encodedValue) {
String value = Entities.unescape(encodedValue, true);
return new Attribute(unencodedKey, value, null); // parent will get set when Put
}
|
[
"public",
"static",
"Attribute",
"createFromEncoded",
"(",
"String",
"unencodedKey",
",",
"String",
"encodedValue",
")",
"{",
"String",
"value",
"=",
"Entities",
".",
"unescape",
"(",
"encodedValue",
",",
"true",
")",
";",
"return",
"new",
"Attribute",
"(",
"unencodedKey",
",",
"value",
",",
"null",
")",
";",
"// parent will get set when Put",
"}"
] |
Create a new Attribute from an unencoded key and a HTML attribute encoded value.
@param unencodedKey assumes the key is not encoded, as can be only run of simple \w chars.
@param encodedValue HTML attribute encoded value
@return attribute
|
[
"Create",
"a",
"new",
"Attribute",
"from",
"an",
"unencoded",
"key",
"and",
"a",
"HTML",
"attribute",
"encoded",
"value",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Attribute.java#L142-L145
|
13,940
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/W3CDom.java
|
W3CDom.fromJsoup
|
public Document fromJsoup(org.jsoup.nodes.Document in) {
Validate.notNull(in);
DocumentBuilder builder;
try {
//set the factory to be namespace-aware
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
Document out = builder.newDocument();
convert(in, out);
return out;
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}
|
java
|
public Document fromJsoup(org.jsoup.nodes.Document in) {
Validate.notNull(in);
DocumentBuilder builder;
try {
//set the factory to be namespace-aware
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
Document out = builder.newDocument();
convert(in, out);
return out;
} catch (ParserConfigurationException e) {
throw new IllegalStateException(e);
}
}
|
[
"public",
"Document",
"fromJsoup",
"(",
"org",
".",
"jsoup",
".",
"nodes",
".",
"Document",
"in",
")",
"{",
"Validate",
".",
"notNull",
"(",
"in",
")",
";",
"DocumentBuilder",
"builder",
";",
"try",
"{",
"//set the factory to be namespace-aware",
"factory",
".",
"setNamespaceAware",
"(",
"true",
")",
";",
"builder",
"=",
"factory",
".",
"newDocumentBuilder",
"(",
")",
";",
"Document",
"out",
"=",
"builder",
".",
"newDocument",
"(",
")",
";",
"convert",
"(",
"in",
",",
"out",
")",
";",
"return",
"out",
";",
"}",
"catch",
"(",
"ParserConfigurationException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
")",
";",
"}",
"}"
] |
Convert a jsoup Document to a W3C Document.
@param in jsoup doc
@return w3c doc
|
[
"Convert",
"a",
"jsoup",
"Document",
"to",
"a",
"W3C",
"Document",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/W3CDom.java#L37-L50
|
13,941
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/W3CDom.java
|
W3CDom.convert
|
public void convert(org.jsoup.nodes.Document in, Document out) {
if (!StringUtil.isBlank(in.location()))
out.setDocumentURI(in.location());
org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
|
java
|
public void convert(org.jsoup.nodes.Document in, Document out) {
if (!StringUtil.isBlank(in.location()))
out.setDocumentURI(in.location());
org.jsoup.nodes.Element rootEl = in.child(0); // skip the #root node
NodeTraversor.traverse(new W3CBuilder(out), rootEl);
}
|
[
"public",
"void",
"convert",
"(",
"org",
".",
"jsoup",
".",
"nodes",
".",
"Document",
"in",
",",
"Document",
"out",
")",
"{",
"if",
"(",
"!",
"StringUtil",
".",
"isBlank",
"(",
"in",
".",
"location",
"(",
")",
")",
")",
"out",
".",
"setDocumentURI",
"(",
"in",
".",
"location",
"(",
")",
")",
";",
"org",
".",
"jsoup",
".",
"nodes",
".",
"Element",
"rootEl",
"=",
"in",
".",
"child",
"(",
"0",
")",
";",
"// skip the #root node",
"NodeTraversor",
".",
"traverse",
"(",
"new",
"W3CBuilder",
"(",
"out",
")",
",",
"rootEl",
")",
";",
"}"
] |
Converts a jsoup document into the provided W3C Document. If required, you can set options on the output document
before converting.
@param in jsoup doc
@param out w3c doc
@see org.jsoup.helper.W3CDom#fromJsoup(org.jsoup.nodes.Document)
|
[
"Converts",
"a",
"jsoup",
"document",
"into",
"the",
"provided",
"W3C",
"Document",
".",
"If",
"required",
"you",
"can",
"set",
"options",
"on",
"the",
"output",
"document",
"before",
"converting",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/W3CDom.java#L59-L65
|
13,942
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/W3CDom.java
|
W3CDom.asString
|
public String asString(Document doc) {
try {
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
} catch (TransformerException e) {
throw new IllegalStateException(e);
}
}
|
java
|
public String asString(Document doc) {
try {
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
} catch (TransformerException e) {
throw new IllegalStateException(e);
}
}
|
[
"public",
"String",
"asString",
"(",
"Document",
"doc",
")",
"{",
"try",
"{",
"DOMSource",
"domSource",
"=",
"new",
"DOMSource",
"(",
"doc",
")",
";",
"StringWriter",
"writer",
"=",
"new",
"StringWriter",
"(",
")",
";",
"StreamResult",
"result",
"=",
"new",
"StreamResult",
"(",
"writer",
")",
";",
"TransformerFactory",
"tf",
"=",
"TransformerFactory",
".",
"newInstance",
"(",
")",
";",
"Transformer",
"transformer",
"=",
"tf",
".",
"newTransformer",
"(",
")",
";",
"transformer",
".",
"transform",
"(",
"domSource",
",",
"result",
")",
";",
"return",
"writer",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"TransformerException",
"e",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"e",
")",
";",
"}",
"}"
] |
Serialize a W3C document to a String.
@param doc Document
@return Document as string
|
[
"Serialize",
"a",
"W3C",
"document",
"to",
"a",
"String",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/W3CDom.java#L167-L179
|
13,943
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.nextIndexOf
|
int nextIndexOf(char c) {
// doesn't handle scanning for surrogates
bufferUp();
for (int i = bufPos; i < bufLength; i++) {
if (c == charBuf[i])
return i - bufPos;
}
return -1;
}
|
java
|
int nextIndexOf(char c) {
// doesn't handle scanning for surrogates
bufferUp();
for (int i = bufPos; i < bufLength; i++) {
if (c == charBuf[i])
return i - bufPos;
}
return -1;
}
|
[
"int",
"nextIndexOf",
"(",
"char",
"c",
")",
"{",
"// doesn't handle scanning for surrogates",
"bufferUp",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"bufPos",
";",
"i",
"<",
"bufLength",
";",
"i",
"++",
")",
"{",
"if",
"(",
"c",
"==",
"charBuf",
"[",
"i",
"]",
")",
"return",
"i",
"-",
"bufPos",
";",
"}",
"return",
"-",
"1",
";",
"}"
] |
Returns the number of characters between the current position and the next instance of the input char
@param c scan target
@return offset between current position and next instance of target. -1 if not found.
|
[
"Returns",
"the",
"number",
"of",
"characters",
"between",
"the",
"current",
"position",
"and",
"the",
"next",
"instance",
"of",
"the",
"input",
"char"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L138-L146
|
13,944
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.nextIndexOf
|
int nextIndexOf(CharSequence seq) {
bufferUp();
// doesn't handle scanning for surrogates
char startChar = seq.charAt(0);
for (int offset = bufPos; offset < bufLength; offset++) {
// scan to first instance of startchar:
if (startChar != charBuf[offset])
while(++offset < bufLength && startChar != charBuf[offset]) { /* empty */ }
int i = offset + 1;
int last = i + seq.length()-1;
if (offset < bufLength && last <= bufLength) {
for (int j = 1; i < last && seq.charAt(j) == charBuf[i]; i++, j++) { /* empty */ }
if (i == last) // found full sequence
return offset - bufPos;
}
}
return -1;
}
|
java
|
int nextIndexOf(CharSequence seq) {
bufferUp();
// doesn't handle scanning for surrogates
char startChar = seq.charAt(0);
for (int offset = bufPos; offset < bufLength; offset++) {
// scan to first instance of startchar:
if (startChar != charBuf[offset])
while(++offset < bufLength && startChar != charBuf[offset]) { /* empty */ }
int i = offset + 1;
int last = i + seq.length()-1;
if (offset < bufLength && last <= bufLength) {
for (int j = 1; i < last && seq.charAt(j) == charBuf[i]; i++, j++) { /* empty */ }
if (i == last) // found full sequence
return offset - bufPos;
}
}
return -1;
}
|
[
"int",
"nextIndexOf",
"(",
"CharSequence",
"seq",
")",
"{",
"bufferUp",
"(",
")",
";",
"// doesn't handle scanning for surrogates",
"char",
"startChar",
"=",
"seq",
".",
"charAt",
"(",
"0",
")",
";",
"for",
"(",
"int",
"offset",
"=",
"bufPos",
";",
"offset",
"<",
"bufLength",
";",
"offset",
"++",
")",
"{",
"// scan to first instance of startchar:",
"if",
"(",
"startChar",
"!=",
"charBuf",
"[",
"offset",
"]",
")",
"while",
"(",
"++",
"offset",
"<",
"bufLength",
"&&",
"startChar",
"!=",
"charBuf",
"[",
"offset",
"]",
")",
"{",
"/* empty */",
"}",
"int",
"i",
"=",
"offset",
"+",
"1",
";",
"int",
"last",
"=",
"i",
"+",
"seq",
".",
"length",
"(",
")",
"-",
"1",
";",
"if",
"(",
"offset",
"<",
"bufLength",
"&&",
"last",
"<=",
"bufLength",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"1",
";",
"i",
"<",
"last",
"&&",
"seq",
".",
"charAt",
"(",
"j",
")",
"==",
"charBuf",
"[",
"i",
"]",
";",
"i",
"++",
",",
"j",
"++",
")",
"{",
"/* empty */",
"}",
"if",
"(",
"i",
"==",
"last",
")",
"// found full sequence",
"return",
"offset",
"-",
"bufPos",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] |
Returns the number of characters between the current position and the next instance of the input sequence
@param seq scan target
@return offset between current position and next instance of target. -1 if not found.
|
[
"Returns",
"the",
"number",
"of",
"characters",
"between",
"the",
"current",
"position",
"and",
"the",
"next",
"instance",
"of",
"the",
"input",
"sequence"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L154-L171
|
13,945
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.consumeTo
|
public String consumeTo(char c) {
int offset = nextIndexOf(c);
if (offset != -1) {
String consumed = cacheString(charBuf, stringCache, bufPos, offset);
bufPos += offset;
return consumed;
} else {
return consumeToEnd();
}
}
|
java
|
public String consumeTo(char c) {
int offset = nextIndexOf(c);
if (offset != -1) {
String consumed = cacheString(charBuf, stringCache, bufPos, offset);
bufPos += offset;
return consumed;
} else {
return consumeToEnd();
}
}
|
[
"public",
"String",
"consumeTo",
"(",
"char",
"c",
")",
"{",
"int",
"offset",
"=",
"nextIndexOf",
"(",
"c",
")",
";",
"if",
"(",
"offset",
"!=",
"-",
"1",
")",
"{",
"String",
"consumed",
"=",
"cacheString",
"(",
"charBuf",
",",
"stringCache",
",",
"bufPos",
",",
"offset",
")",
";",
"bufPos",
"+=",
"offset",
";",
"return",
"consumed",
";",
"}",
"else",
"{",
"return",
"consumeToEnd",
"(",
")",
";",
"}",
"}"
] |
Reads characters up to the specific char.
@param c the delimiter
@return the chars read
|
[
"Reads",
"characters",
"up",
"to",
"the",
"specific",
"char",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L178-L187
|
13,946
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.consumeToAny
|
public String consumeToAny(final char... chars) {
bufferUp();
int pos = bufPos;
final int start = pos;
final int remaining = bufLength;
final char[] val = charBuf;
final int charLen = chars.length;
int i;
OUTER: while (pos < remaining) {
for (i = 0; i < charLen; i++) {
if (val[pos] == chars[i])
break OUTER;
}
pos++;
}
bufPos = pos;
return pos > start ? cacheString(charBuf, stringCache, start, pos -start) : "";
}
|
java
|
public String consumeToAny(final char... chars) {
bufferUp();
int pos = bufPos;
final int start = pos;
final int remaining = bufLength;
final char[] val = charBuf;
final int charLen = chars.length;
int i;
OUTER: while (pos < remaining) {
for (i = 0; i < charLen; i++) {
if (val[pos] == chars[i])
break OUTER;
}
pos++;
}
bufPos = pos;
return pos > start ? cacheString(charBuf, stringCache, start, pos -start) : "";
}
|
[
"public",
"String",
"consumeToAny",
"(",
"final",
"char",
"...",
"chars",
")",
"{",
"bufferUp",
"(",
")",
";",
"int",
"pos",
"=",
"bufPos",
";",
"final",
"int",
"start",
"=",
"pos",
";",
"final",
"int",
"remaining",
"=",
"bufLength",
";",
"final",
"char",
"[",
"]",
"val",
"=",
"charBuf",
";",
"final",
"int",
"charLen",
"=",
"chars",
".",
"length",
";",
"int",
"i",
";",
"OUTER",
":",
"while",
"(",
"pos",
"<",
"remaining",
")",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"charLen",
";",
"i",
"++",
")",
"{",
"if",
"(",
"val",
"[",
"pos",
"]",
"==",
"chars",
"[",
"i",
"]",
")",
"break",
"OUTER",
";",
"}",
"pos",
"++",
";",
"}",
"bufPos",
"=",
"pos",
";",
"return",
"pos",
">",
"start",
"?",
"cacheString",
"(",
"charBuf",
",",
"stringCache",
",",
"start",
",",
"pos",
"-",
"start",
")",
":",
"\"\"",
";",
"}"
] |
Read characters until the first of any delimiters is found.
@param chars delimiters to scan for
@return characters read up to the matched delimiter.
|
[
"Read",
"characters",
"until",
"the",
"first",
"of",
"any",
"delimiters",
"is",
"found",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L205-L224
|
13,947
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.rangeEquals
|
static boolean rangeEquals(final char[] charBuf, final int start, int count, final String cached) {
if (count == cached.length()) {
int i = start;
int j = 0;
while (count-- != 0) {
if (charBuf[i++] != cached.charAt(j++))
return false;
}
return true;
}
return false;
}
|
java
|
static boolean rangeEquals(final char[] charBuf, final int start, int count, final String cached) {
if (count == cached.length()) {
int i = start;
int j = 0;
while (count-- != 0) {
if (charBuf[i++] != cached.charAt(j++))
return false;
}
return true;
}
return false;
}
|
[
"static",
"boolean",
"rangeEquals",
"(",
"final",
"char",
"[",
"]",
"charBuf",
",",
"final",
"int",
"start",
",",
"int",
"count",
",",
"final",
"String",
"cached",
")",
"{",
"if",
"(",
"count",
"==",
"cached",
".",
"length",
"(",
")",
")",
"{",
"int",
"i",
"=",
"start",
";",
"int",
"j",
"=",
"0",
";",
"while",
"(",
"count",
"--",
"!=",
"0",
")",
"{",
"if",
"(",
"charBuf",
"[",
"i",
"++",
"]",
"!=",
"cached",
".",
"charAt",
"(",
"j",
"++",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Check if the value of the provided range equals the string.
|
[
"Check",
"if",
"the",
"value",
"of",
"the",
"provided",
"range",
"equals",
"the",
"string",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L498-L509
|
13,948
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/CharacterReader.java
|
CharacterReader.rangeEquals
|
boolean rangeEquals(final int start, final int count, final String cached) {
return rangeEquals(charBuf, start, count, cached);
}
|
java
|
boolean rangeEquals(final int start, final int count, final String cached) {
return rangeEquals(charBuf, start, count, cached);
}
|
[
"boolean",
"rangeEquals",
"(",
"final",
"int",
"start",
",",
"final",
"int",
"count",
",",
"final",
"String",
"cached",
")",
"{",
"return",
"rangeEquals",
"(",
"charBuf",
",",
"start",
",",
"count",
",",
"cached",
")",
";",
"}"
] |
just used for testing
|
[
"just",
"used",
"for",
"testing"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/CharacterReader.java#L512-L514
|
13,949
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Entities.java
|
Entities.escape
|
static void escape(Appendable accum, String string, Document.OutputSettings out,
boolean inAttribute, boolean normaliseWhite, boolean stripLeadingWhite) throws IOException {
boolean lastWasWhite = false;
boolean reachedNonWhite = false;
final EscapeMode escapeMode = out.escapeMode();
final CharsetEncoder encoder = out.encoder();
final CoreCharset coreCharset = out.coreCharset; // init in out.prepareEncoder()
final int length = string.length();
int codePoint;
for (int offset = 0; offset < length; offset += Character.charCount(codePoint)) {
codePoint = string.codePointAt(offset);
if (normaliseWhite) {
if (StringUtil.isWhitespace(codePoint)) {
if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite)
continue;
accum.append(' ');
lastWasWhite = true;
continue;
} else {
lastWasWhite = false;
reachedNonWhite = true;
}
}
// surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]):
if (codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
final char c = (char) codePoint;
// html specific and required escapes:
switch (c) {
case '&':
accum.append("&");
break;
case 0xA0:
if (escapeMode != EscapeMode.xhtml)
accum.append(" ");
else
accum.append(" ");
break;
case '<':
// escape when in character data or when in a xml attribue val; not needed in html attr val
if (!inAttribute || escapeMode == EscapeMode.xhtml)
accum.append("<");
else
accum.append(c);
break;
case '>':
if (!inAttribute)
accum.append(">");
else
accum.append(c);
break;
case '"':
if (inAttribute)
accum.append(""");
else
accum.append(c);
break;
default:
if (canEncode(coreCharset, c, encoder))
accum.append(c);
else
appendEncoded(accum, escapeMode, codePoint);
}
} else {
final String c = new String(Character.toChars(codePoint));
if (encoder.canEncode(c)) // uses fallback encoder for simplicity
accum.append(c);
else
appendEncoded(accum, escapeMode, codePoint);
}
}
}
|
java
|
static void escape(Appendable accum, String string, Document.OutputSettings out,
boolean inAttribute, boolean normaliseWhite, boolean stripLeadingWhite) throws IOException {
boolean lastWasWhite = false;
boolean reachedNonWhite = false;
final EscapeMode escapeMode = out.escapeMode();
final CharsetEncoder encoder = out.encoder();
final CoreCharset coreCharset = out.coreCharset; // init in out.prepareEncoder()
final int length = string.length();
int codePoint;
for (int offset = 0; offset < length; offset += Character.charCount(codePoint)) {
codePoint = string.codePointAt(offset);
if (normaliseWhite) {
if (StringUtil.isWhitespace(codePoint)) {
if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite)
continue;
accum.append(' ');
lastWasWhite = true;
continue;
} else {
lastWasWhite = false;
reachedNonWhite = true;
}
}
// surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]):
if (codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
final char c = (char) codePoint;
// html specific and required escapes:
switch (c) {
case '&':
accum.append("&");
break;
case 0xA0:
if (escapeMode != EscapeMode.xhtml)
accum.append(" ");
else
accum.append(" ");
break;
case '<':
// escape when in character data or when in a xml attribue val; not needed in html attr val
if (!inAttribute || escapeMode == EscapeMode.xhtml)
accum.append("<");
else
accum.append(c);
break;
case '>':
if (!inAttribute)
accum.append(">");
else
accum.append(c);
break;
case '"':
if (inAttribute)
accum.append(""");
else
accum.append(c);
break;
default:
if (canEncode(coreCharset, c, encoder))
accum.append(c);
else
appendEncoded(accum, escapeMode, codePoint);
}
} else {
final String c = new String(Character.toChars(codePoint));
if (encoder.canEncode(c)) // uses fallback encoder for simplicity
accum.append(c);
else
appendEncoded(accum, escapeMode, codePoint);
}
}
}
|
[
"static",
"void",
"escape",
"(",
"Appendable",
"accum",
",",
"String",
"string",
",",
"Document",
".",
"OutputSettings",
"out",
",",
"boolean",
"inAttribute",
",",
"boolean",
"normaliseWhite",
",",
"boolean",
"stripLeadingWhite",
")",
"throws",
"IOException",
"{",
"boolean",
"lastWasWhite",
"=",
"false",
";",
"boolean",
"reachedNonWhite",
"=",
"false",
";",
"final",
"EscapeMode",
"escapeMode",
"=",
"out",
".",
"escapeMode",
"(",
")",
";",
"final",
"CharsetEncoder",
"encoder",
"=",
"out",
".",
"encoder",
"(",
")",
";",
"final",
"CoreCharset",
"coreCharset",
"=",
"out",
".",
"coreCharset",
";",
"// init in out.prepareEncoder()",
"final",
"int",
"length",
"=",
"string",
".",
"length",
"(",
")",
";",
"int",
"codePoint",
";",
"for",
"(",
"int",
"offset",
"=",
"0",
";",
"offset",
"<",
"length",
";",
"offset",
"+=",
"Character",
".",
"charCount",
"(",
"codePoint",
")",
")",
"{",
"codePoint",
"=",
"string",
".",
"codePointAt",
"(",
"offset",
")",
";",
"if",
"(",
"normaliseWhite",
")",
"{",
"if",
"(",
"StringUtil",
".",
"isWhitespace",
"(",
"codePoint",
")",
")",
"{",
"if",
"(",
"(",
"stripLeadingWhite",
"&&",
"!",
"reachedNonWhite",
")",
"||",
"lastWasWhite",
")",
"continue",
";",
"accum",
".",
"append",
"(",
"'",
"'",
")",
";",
"lastWasWhite",
"=",
"true",
";",
"continue",
";",
"}",
"else",
"{",
"lastWasWhite",
"=",
"false",
";",
"reachedNonWhite",
"=",
"true",
";",
"}",
"}",
"// surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]):",
"if",
"(",
"codePoint",
"<",
"Character",
".",
"MIN_SUPPLEMENTARY_CODE_POINT",
")",
"{",
"final",
"char",
"c",
"=",
"(",
"char",
")",
"codePoint",
";",
"// html specific and required escapes:",
"switch",
"(",
"c",
")",
"{",
"case",
"'",
"'",
":",
"accum",
".",
"append",
"(",
"\"&\"",
")",
";",
"break",
";",
"case",
"0xA0",
":",
"if",
"(",
"escapeMode",
"!=",
"EscapeMode",
".",
"xhtml",
")",
"accum",
".",
"append",
"(",
"\" \"",
")",
";",
"else",
"accum",
".",
"append",
"(",
"\" \"",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"// escape when in character data or when in a xml attribue val; not needed in html attr val",
"if",
"(",
"!",
"inAttribute",
"||",
"escapeMode",
"==",
"EscapeMode",
".",
"xhtml",
")",
"accum",
".",
"append",
"(",
"\"<\"",
")",
";",
"else",
"accum",
".",
"append",
"(",
"c",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"if",
"(",
"!",
"inAttribute",
")",
"accum",
".",
"append",
"(",
"\">\"",
")",
";",
"else",
"accum",
".",
"append",
"(",
"c",
")",
";",
"break",
";",
"case",
"'",
"'",
":",
"if",
"(",
"inAttribute",
")",
"accum",
".",
"append",
"(",
"\""\"",
")",
";",
"else",
"accum",
".",
"append",
"(",
"c",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"canEncode",
"(",
"coreCharset",
",",
"c",
",",
"encoder",
")",
")",
"accum",
".",
"append",
"(",
"c",
")",
";",
"else",
"appendEncoded",
"(",
"accum",
",",
"escapeMode",
",",
"codePoint",
")",
";",
"}",
"}",
"else",
"{",
"final",
"String",
"c",
"=",
"new",
"String",
"(",
"Character",
".",
"toChars",
"(",
"codePoint",
")",
")",
";",
"if",
"(",
"encoder",
".",
"canEncode",
"(",
"c",
")",
")",
"// uses fallback encoder for simplicity",
"accum",
".",
"append",
"(",
"c",
")",
";",
"else",
"appendEncoded",
"(",
"accum",
",",
"escapeMode",
",",
"codePoint",
")",
";",
"}",
"}",
"}"
] |
this method is ugly, and does a lot. but other breakups cause rescanning and stringbuilder generations
|
[
"this",
"method",
"is",
"ugly",
"and",
"does",
"a",
"lot",
".",
"but",
"other",
"breakups",
"cause",
"rescanning",
"and",
"stringbuilder",
"generations"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Entities.java#L173-L246
|
13,950
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.removeAttr
|
public Node removeAttr(String attributeKey) {
Validate.notNull(attributeKey);
attributes().removeIgnoreCase(attributeKey);
return this;
}
|
java
|
public Node removeAttr(String attributeKey) {
Validate.notNull(attributeKey);
attributes().removeIgnoreCase(attributeKey);
return this;
}
|
[
"public",
"Node",
"removeAttr",
"(",
"String",
"attributeKey",
")",
"{",
"Validate",
".",
"notNull",
"(",
"attributeKey",
")",
";",
"attributes",
"(",
")",
".",
"removeIgnoreCase",
"(",
"attributeKey",
")",
";",
"return",
"this",
";",
"}"
] |
Remove an attribute from this element.
@param attributeKey The attribute to remove.
@return this (for chaining)
|
[
"Remove",
"an",
"attribute",
"from",
"this",
"element",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L111-L115
|
13,951
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.setBaseUri
|
public void setBaseUri(final String baseUri) {
Validate.notNull(baseUri);
traverse(new NodeVisitor() {
public void head(Node node, int depth) {
node.doSetBaseUri(baseUri);
}
public void tail(Node node, int depth) {
}
});
}
|
java
|
public void setBaseUri(final String baseUri) {
Validate.notNull(baseUri);
traverse(new NodeVisitor() {
public void head(Node node, int depth) {
node.doSetBaseUri(baseUri);
}
public void tail(Node node, int depth) {
}
});
}
|
[
"public",
"void",
"setBaseUri",
"(",
"final",
"String",
"baseUri",
")",
"{",
"Validate",
".",
"notNull",
"(",
"baseUri",
")",
";",
"traverse",
"(",
"new",
"NodeVisitor",
"(",
")",
"{",
"public",
"void",
"head",
"(",
"Node",
"node",
",",
"int",
"depth",
")",
"{",
"node",
".",
"doSetBaseUri",
"(",
"baseUri",
")",
";",
"}",
"public",
"void",
"tail",
"(",
"Node",
"node",
",",
"int",
"depth",
")",
"{",
"}",
"}",
")",
";",
"}"
] |
Update the base URI of this node and all of its descendants.
@param baseUri base URI to set
|
[
"Update",
"the",
"base",
"URI",
"of",
"this",
"node",
"and",
"all",
"of",
"its",
"descendants",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L146-L157
|
13,952
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.childNodesCopy
|
public List<Node> childNodesCopy() {
final List<Node> nodes = ensureChildNodes();
final ArrayList<Node> children = new ArrayList<>(nodes.size());
for (Node node : nodes) {
children.add(node.clone());
}
return children;
}
|
java
|
public List<Node> childNodesCopy() {
final List<Node> nodes = ensureChildNodes();
final ArrayList<Node> children = new ArrayList<>(nodes.size());
for (Node node : nodes) {
children.add(node.clone());
}
return children;
}
|
[
"public",
"List",
"<",
"Node",
">",
"childNodesCopy",
"(",
")",
"{",
"final",
"List",
"<",
"Node",
">",
"nodes",
"=",
"ensureChildNodes",
"(",
")",
";",
"final",
"ArrayList",
"<",
"Node",
">",
"children",
"=",
"new",
"ArrayList",
"<>",
"(",
"nodes",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Node",
"node",
":",
"nodes",
")",
"{",
"children",
".",
"add",
"(",
"node",
".",
"clone",
"(",
")",
")",
";",
"}",
"return",
"children",
";",
"}"
] |
Returns a deep copy of this node's children. Changes made to these nodes will not be reflected in the original
nodes
@return a deep copy of this node's children
|
[
"Returns",
"a",
"deep",
"copy",
"of",
"this",
"node",
"s",
"children",
".",
"Changes",
"made",
"to",
"these",
"nodes",
"will",
"not",
"be",
"reflected",
"in",
"the",
"original",
"nodes"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L217-L224
|
13,953
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.ownerDocument
|
public Document ownerDocument() {
Node root = root();
return (root instanceof Document) ? (Document) root : null;
}
|
java
|
public Document ownerDocument() {
Node root = root();
return (root instanceof Document) ? (Document) root : null;
}
|
[
"public",
"Document",
"ownerDocument",
"(",
")",
"{",
"Node",
"root",
"=",
"root",
"(",
")",
";",
"return",
"(",
"root",
"instanceof",
"Document",
")",
"?",
"(",
"Document",
")",
"root",
":",
"null",
";",
"}"
] |
Gets the Document associated with this Node.
@return the Document associated with this Node, or null if there is no such Document.
|
[
"Gets",
"the",
"Document",
"associated",
"with",
"this",
"Node",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L267-L270
|
13,954
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.wrap
|
public Node wrap(String html) {
Validate.notEmpty(html);
Element context = parent() instanceof Element ? (Element) parent() : null;
List<Node> wrapChildren = NodeUtils.parser(this).parseFragmentInput(html, context, baseUri());
Node wrapNode = wrapChildren.get(0);
if (!(wrapNode instanceof Element)) // nothing to wrap with; noop
return null;
Element wrap = (Element) wrapNode;
Element deepest = getDeepChild(wrap);
parentNode.replaceChild(this, wrap);
deepest.addChildren(this);
// remainder (unbalanced wrap, like <div></div><p></p> -- The <p> is remainder
if (wrapChildren.size() > 0) {
//noinspection ForLoopReplaceableByForEach (beacause it allocates an Iterator which is wasteful here)
for (int i = 0; i < wrapChildren.size(); i++) {
Node remainder = wrapChildren.get(i);
remainder.parentNode.removeChild(remainder);
wrap.appendChild(remainder);
}
}
return this;
}
|
java
|
public Node wrap(String html) {
Validate.notEmpty(html);
Element context = parent() instanceof Element ? (Element) parent() : null;
List<Node> wrapChildren = NodeUtils.parser(this).parseFragmentInput(html, context, baseUri());
Node wrapNode = wrapChildren.get(0);
if (!(wrapNode instanceof Element)) // nothing to wrap with; noop
return null;
Element wrap = (Element) wrapNode;
Element deepest = getDeepChild(wrap);
parentNode.replaceChild(this, wrap);
deepest.addChildren(this);
// remainder (unbalanced wrap, like <div></div><p></p> -- The <p> is remainder
if (wrapChildren.size() > 0) {
//noinspection ForLoopReplaceableByForEach (beacause it allocates an Iterator which is wasteful here)
for (int i = 0; i < wrapChildren.size(); i++) {
Node remainder = wrapChildren.get(i);
remainder.parentNode.removeChild(remainder);
wrap.appendChild(remainder);
}
}
return this;
}
|
[
"public",
"Node",
"wrap",
"(",
"String",
"html",
")",
"{",
"Validate",
".",
"notEmpty",
"(",
"html",
")",
";",
"Element",
"context",
"=",
"parent",
"(",
")",
"instanceof",
"Element",
"?",
"(",
"Element",
")",
"parent",
"(",
")",
":",
"null",
";",
"List",
"<",
"Node",
">",
"wrapChildren",
"=",
"NodeUtils",
".",
"parser",
"(",
"this",
")",
".",
"parseFragmentInput",
"(",
"html",
",",
"context",
",",
"baseUri",
"(",
")",
")",
";",
"Node",
"wrapNode",
"=",
"wrapChildren",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"!",
"(",
"wrapNode",
"instanceof",
"Element",
")",
")",
"// nothing to wrap with; noop",
"return",
"null",
";",
"Element",
"wrap",
"=",
"(",
"Element",
")",
"wrapNode",
";",
"Element",
"deepest",
"=",
"getDeepChild",
"(",
"wrap",
")",
";",
"parentNode",
".",
"replaceChild",
"(",
"this",
",",
"wrap",
")",
";",
"deepest",
".",
"addChildren",
"(",
"this",
")",
";",
"// remainder (unbalanced wrap, like <div></div><p></p> -- The <p> is remainder",
"if",
"(",
"wrapChildren",
".",
"size",
"(",
")",
">",
"0",
")",
"{",
"//noinspection ForLoopReplaceableByForEach (beacause it allocates an Iterator which is wasteful here)",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"wrapChildren",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"Node",
"remainder",
"=",
"wrapChildren",
".",
"get",
"(",
"i",
")",
";",
"remainder",
".",
"parentNode",
".",
"removeChild",
"(",
"remainder",
")",
";",
"wrap",
".",
"appendChild",
"(",
"remainder",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] |
Wrap the supplied HTML around this node.
@param html HTML to wrap around this element, e.g. {@code <div class="head"></div>}. Can be arbitrarily deep.
@return this node, for chaining.
|
[
"Wrap",
"the",
"supplied",
"HTML",
"around",
"this",
"node",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L344-L368
|
13,955
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.replaceWith
|
public void replaceWith(Node in) {
Validate.notNull(in);
Validate.notNull(parentNode);
parentNode.replaceChild(this, in);
}
|
java
|
public void replaceWith(Node in) {
Validate.notNull(in);
Validate.notNull(parentNode);
parentNode.replaceChild(this, in);
}
|
[
"public",
"void",
"replaceWith",
"(",
"Node",
"in",
")",
"{",
"Validate",
".",
"notNull",
"(",
"in",
")",
";",
"Validate",
".",
"notNull",
"(",
"parentNode",
")",
";",
"parentNode",
".",
"replaceChild",
"(",
"this",
",",
"in",
")",
";",
"}"
] |
Replace this node in the DOM with the supplied node.
@param in the node that will will replace the existing node.
|
[
"Replace",
"this",
"node",
"in",
"the",
"DOM",
"with",
"the",
"supplied",
"node",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L411-L415
|
13,956
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.nextSibling
|
public Node nextSibling() {
if (parentNode == null)
return null; // root
final List<Node> siblings = parentNode.ensureChildNodes();
final int index = siblingIndex+1;
if (siblings.size() > index)
return siblings.get(index);
else
return null;
}
|
java
|
public Node nextSibling() {
if (parentNode == null)
return null; // root
final List<Node> siblings = parentNode.ensureChildNodes();
final int index = siblingIndex+1;
if (siblings.size() > index)
return siblings.get(index);
else
return null;
}
|
[
"public",
"Node",
"nextSibling",
"(",
")",
"{",
"if",
"(",
"parentNode",
"==",
"null",
")",
"return",
"null",
";",
"// root",
"final",
"List",
"<",
"Node",
">",
"siblings",
"=",
"parentNode",
".",
"ensureChildNodes",
"(",
")",
";",
"final",
"int",
"index",
"=",
"siblingIndex",
"+",
"1",
";",
"if",
"(",
"siblings",
".",
"size",
"(",
")",
">",
"index",
")",
"return",
"siblings",
".",
"get",
"(",
"index",
")",
";",
"else",
"return",
"null",
";",
"}"
] |
Get this node's next sibling.
@return next sibling, or null if this is the last sibling
|
[
"Get",
"this",
"node",
"s",
"next",
"sibling",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L500-L510
|
13,957
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.previousSibling
|
public Node previousSibling() {
if (parentNode == null)
return null; // root
if (siblingIndex > 0)
return parentNode.ensureChildNodes().get(siblingIndex-1);
else
return null;
}
|
java
|
public Node previousSibling() {
if (parentNode == null)
return null; // root
if (siblingIndex > 0)
return parentNode.ensureChildNodes().get(siblingIndex-1);
else
return null;
}
|
[
"public",
"Node",
"previousSibling",
"(",
")",
"{",
"if",
"(",
"parentNode",
"==",
"null",
")",
"return",
"null",
";",
"// root",
"if",
"(",
"siblingIndex",
">",
"0",
")",
"return",
"parentNode",
".",
"ensureChildNodes",
"(",
")",
".",
"get",
"(",
"siblingIndex",
"-",
"1",
")",
";",
"else",
"return",
"null",
";",
"}"
] |
Get this node's previous sibling.
@return the previous sibling, or null if this is the first sibling
|
[
"Get",
"this",
"node",
"s",
"previous",
"sibling",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L516-L524
|
13,958
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.traverse
|
public Node traverse(NodeVisitor nodeVisitor) {
Validate.notNull(nodeVisitor);
NodeTraversor.traverse(nodeVisitor, this);
return this;
}
|
java
|
public Node traverse(NodeVisitor nodeVisitor) {
Validate.notNull(nodeVisitor);
NodeTraversor.traverse(nodeVisitor, this);
return this;
}
|
[
"public",
"Node",
"traverse",
"(",
"NodeVisitor",
"nodeVisitor",
")",
"{",
"Validate",
".",
"notNull",
"(",
"nodeVisitor",
")",
";",
"NodeTraversor",
".",
"traverse",
"(",
"nodeVisitor",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
] |
Perform a depth-first traversal through this node and its descendants.
@param nodeVisitor the visitor callbacks to perform on each node
@return this node, for chaining
|
[
"Perform",
"a",
"depth",
"-",
"first",
"traversal",
"through",
"this",
"node",
"and",
"its",
"descendants",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L545-L549
|
13,959
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.filter
|
public Node filter(NodeFilter nodeFilter) {
Validate.notNull(nodeFilter);
NodeTraversor.filter(nodeFilter, this);
return this;
}
|
java
|
public Node filter(NodeFilter nodeFilter) {
Validate.notNull(nodeFilter);
NodeTraversor.filter(nodeFilter, this);
return this;
}
|
[
"public",
"Node",
"filter",
"(",
"NodeFilter",
"nodeFilter",
")",
"{",
"Validate",
".",
"notNull",
"(",
"nodeFilter",
")",
";",
"NodeTraversor",
".",
"filter",
"(",
"nodeFilter",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
] |
Perform a depth-first filtering through this node and its descendants.
@param nodeFilter the filter callbacks to perform on each node
@return this node, for chaining
|
[
"Perform",
"a",
"depth",
"-",
"first",
"filtering",
"through",
"this",
"node",
"and",
"its",
"descendants",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L556-L560
|
13,960
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Node.java
|
Node.hasSameValue
|
public boolean hasSameValue(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return this.outerHtml().equals(((Node) o).outerHtml());
}
|
java
|
public boolean hasSameValue(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return this.outerHtml().equals(((Node) o).outerHtml());
}
|
[
"public",
"boolean",
"hasSameValue",
"(",
"Object",
"o",
")",
"{",
"if",
"(",
"this",
"==",
"o",
")",
"return",
"true",
";",
"if",
"(",
"o",
"==",
"null",
"||",
"getClass",
"(",
")",
"!=",
"o",
".",
"getClass",
"(",
")",
")",
"return",
"false",
";",
"return",
"this",
".",
"outerHtml",
"(",
")",
".",
"equals",
"(",
"(",
"(",
"Node",
")",
"o",
")",
".",
"outerHtml",
"(",
")",
")",
";",
"}"
] |
Check if this node is has the same content as another node. A node is considered the same if its name, attributes and content match the
other node; particularly its position in the tree does not influence its similarity.
@param o other object to compare to
@return true if the content of this node is the same as the other
|
[
"Check",
"if",
"this",
"node",
"is",
"has",
"the",
"same",
"content",
"as",
"another",
"node",
".",
"A",
"node",
"is",
"considered",
"the",
"same",
"if",
"its",
"name",
"attributes",
"and",
"content",
"match",
"the",
"other",
"node",
";",
"particularly",
"its",
"position",
"in",
"the",
"tree",
"does",
"not",
"influence",
"its",
"similarity",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Node.java#L629-L634
|
13,961
|
jhy/jsoup
|
src/main/java/org/jsoup/Jsoup.java
|
Jsoup.parse
|
public static Document parse(String html, String baseUri) {
return Parser.parse(html, baseUri);
}
|
java
|
public static Document parse(String html, String baseUri) {
return Parser.parse(html, baseUri);
}
|
[
"public",
"static",
"Document",
"parse",
"(",
"String",
"html",
",",
"String",
"baseUri",
")",
"{",
"return",
"Parser",
".",
"parse",
"(",
"html",
",",
"baseUri",
")",
";",
"}"
] |
Parse HTML into a Document. The parser will make a sensible, balanced document tree out of any HTML.
@param html HTML to parse
@param baseUri The URL where the HTML was retrieved from. Used to resolve relative URLs to absolute URLs, that occur
before the HTML declares a {@code <base href>} tag.
@return sane HTML
|
[
"Parse",
"HTML",
"into",
"a",
"Document",
".",
"The",
"parser",
"will",
"make",
"a",
"sensible",
"balanced",
"document",
"tree",
"out",
"of",
"any",
"HTML",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/Jsoup.java#L30-L32
|
13,962
|
jhy/jsoup
|
src/main/java/org/jsoup/Jsoup.java
|
Jsoup.parse
|
public static Document parse(File in, String charsetName, String baseUri) throws IOException {
return DataUtil.load(in, charsetName, baseUri);
}
|
java
|
public static Document parse(File in, String charsetName, String baseUri) throws IOException {
return DataUtil.load(in, charsetName, baseUri);
}
|
[
"public",
"static",
"Document",
"parse",
"(",
"File",
"in",
",",
"String",
"charsetName",
",",
"String",
"baseUri",
")",
"throws",
"IOException",
"{",
"return",
"DataUtil",
".",
"load",
"(",
"in",
",",
"charsetName",
",",
"baseUri",
")",
";",
"}"
] |
Parse the contents of a file as HTML.
@param in file to load HTML from
@param charsetName (optional) character set of file contents. Set to {@code null} to determine from {@code http-equiv} meta tag, if
present, or fall back to {@code UTF-8} (which is often safe to do).
@param baseUri The URL where the HTML was retrieved from, to resolve relative links against.
@return sane HTML
@throws IOException if the file could not be found, or read, or if the charsetName is invalid.
|
[
"Parse",
"the",
"contents",
"of",
"a",
"file",
"as",
"HTML",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/Jsoup.java#L87-L89
|
13,963
|
jhy/jsoup
|
src/main/java/org/jsoup/Jsoup.java
|
Jsoup.parse
|
public static Document parse(File in, String charsetName) throws IOException {
return DataUtil.load(in, charsetName, in.getAbsolutePath());
}
|
java
|
public static Document parse(File in, String charsetName) throws IOException {
return DataUtil.load(in, charsetName, in.getAbsolutePath());
}
|
[
"public",
"static",
"Document",
"parse",
"(",
"File",
"in",
",",
"String",
"charsetName",
")",
"throws",
"IOException",
"{",
"return",
"DataUtil",
".",
"load",
"(",
"in",
",",
"charsetName",
",",
"in",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"}"
] |
Parse the contents of a file as HTML. The location of the file is used as the base URI to qualify relative URLs.
@param in file to load HTML from
@param charsetName (optional) character set of file contents. Set to {@code null} to determine from {@code http-equiv} meta tag, if
present, or fall back to {@code UTF-8} (which is often safe to do).
@return sane HTML
@throws IOException if the file could not be found, or read, or if the charsetName is invalid.
@see #parse(File, String, String)
|
[
"Parse",
"the",
"contents",
"of",
"a",
"file",
"as",
"HTML",
".",
"The",
"location",
"of",
"the",
"file",
"is",
"used",
"as",
"the",
"base",
"URI",
"to",
"qualify",
"relative",
"URLs",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/Jsoup.java#L102-L104
|
13,964
|
jhy/jsoup
|
src/main/java/org/jsoup/Jsoup.java
|
Jsoup.clean
|
public static String clean(String bodyHtml, String baseUri, Whitelist whitelist) {
Document dirty = parseBodyFragment(bodyHtml, baseUri);
Cleaner cleaner = new Cleaner(whitelist);
Document clean = cleaner.clean(dirty);
return clean.body().html();
}
|
java
|
public static String clean(String bodyHtml, String baseUri, Whitelist whitelist) {
Document dirty = parseBodyFragment(bodyHtml, baseUri);
Cleaner cleaner = new Cleaner(whitelist);
Document clean = cleaner.clean(dirty);
return clean.body().html();
}
|
[
"public",
"static",
"String",
"clean",
"(",
"String",
"bodyHtml",
",",
"String",
"baseUri",
",",
"Whitelist",
"whitelist",
")",
"{",
"Document",
"dirty",
"=",
"parseBodyFragment",
"(",
"bodyHtml",
",",
"baseUri",
")",
";",
"Cleaner",
"cleaner",
"=",
"new",
"Cleaner",
"(",
"whitelist",
")",
";",
"Document",
"clean",
"=",
"cleaner",
".",
"clean",
"(",
"dirty",
")",
";",
"return",
"clean",
".",
"body",
"(",
")",
".",
"html",
"(",
")",
";",
"}"
] |
Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of permitted
tags and attributes.
@param bodyHtml input untrusted HTML (body fragment)
@param baseUri URL to resolve relative URLs against
@param whitelist white-list of permitted HTML elements
@return safe HTML (body fragment)
@see Cleaner#clean(Document)
|
[
"Get",
"safe",
"HTML",
"from",
"untrusted",
"input",
"HTML",
"by",
"parsing",
"input",
"HTML",
"and",
"filtering",
"it",
"through",
"a",
"white",
"-",
"list",
"of",
"permitted",
"tags",
"and",
"attributes",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/Jsoup.java#L197-L202
|
13,965
|
jhy/jsoup
|
src/main/java/org/jsoup/safety/Whitelist.java
|
Whitelist.removeEnforcedAttribute
|
public Whitelist removeEnforcedAttribute(String tag, String attribute) {
Validate.notEmpty(tag);
Validate.notEmpty(attribute);
TagName tagName = TagName.valueOf(tag);
if(tagNames.contains(tagName) && enforcedAttributes.containsKey(tagName)) {
AttributeKey attrKey = AttributeKey.valueOf(attribute);
Map<AttributeKey, AttributeValue> attrMap = enforcedAttributes.get(tagName);
attrMap.remove(attrKey);
if(attrMap.isEmpty()) // Remove tag from enforced attribute map if no enforced attributes are present
enforcedAttributes.remove(tagName);
}
return this;
}
|
java
|
public Whitelist removeEnforcedAttribute(String tag, String attribute) {
Validate.notEmpty(tag);
Validate.notEmpty(attribute);
TagName tagName = TagName.valueOf(tag);
if(tagNames.contains(tagName) && enforcedAttributes.containsKey(tagName)) {
AttributeKey attrKey = AttributeKey.valueOf(attribute);
Map<AttributeKey, AttributeValue> attrMap = enforcedAttributes.get(tagName);
attrMap.remove(attrKey);
if(attrMap.isEmpty()) // Remove tag from enforced attribute map if no enforced attributes are present
enforcedAttributes.remove(tagName);
}
return this;
}
|
[
"public",
"Whitelist",
"removeEnforcedAttribute",
"(",
"String",
"tag",
",",
"String",
"attribute",
")",
"{",
"Validate",
".",
"notEmpty",
"(",
"tag",
")",
";",
"Validate",
".",
"notEmpty",
"(",
"attribute",
")",
";",
"TagName",
"tagName",
"=",
"TagName",
".",
"valueOf",
"(",
"tag",
")",
";",
"if",
"(",
"tagNames",
".",
"contains",
"(",
"tagName",
")",
"&&",
"enforcedAttributes",
".",
"containsKey",
"(",
"tagName",
")",
")",
"{",
"AttributeKey",
"attrKey",
"=",
"AttributeKey",
".",
"valueOf",
"(",
"attribute",
")",
";",
"Map",
"<",
"AttributeKey",
",",
"AttributeValue",
">",
"attrMap",
"=",
"enforcedAttributes",
".",
"get",
"(",
"tagName",
")",
";",
"attrMap",
".",
"remove",
"(",
"attrKey",
")",
";",
"if",
"(",
"attrMap",
".",
"isEmpty",
"(",
")",
")",
"// Remove tag from enforced attribute map if no enforced attributes are present",
"enforcedAttributes",
".",
"remove",
"(",
"tagName",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Remove a previously configured enforced attribute from a tag.
@param tag The tag the enforced attribute is for.
@param attribute The attribute name
@return this (for chaining)
|
[
"Remove",
"a",
"previously",
"configured",
"enforced",
"attribute",
"from",
"a",
"tag",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/safety/Whitelist.java#L358-L372
|
13,966
|
jhy/jsoup
|
src/main/java/org/jsoup/safety/Whitelist.java
|
Whitelist.isSafeAttribute
|
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
TagName tag = TagName.valueOf(tagName);
AttributeKey key = AttributeKey.valueOf(attr.getKey());
Set<AttributeKey> okSet = attributes.get(tag);
if (okSet != null && okSet.contains(key)) {
if (protocols.containsKey(tag)) {
Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
// ok if not defined protocol; otherwise test
return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
} else { // attribute found, no protocols defined, so OK
return true;
}
}
// might be an enforced attribute?
Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
if (enforcedSet != null) {
Attributes expect = getEnforcedAttributes(tagName);
String attrKey = attr.getKey();
if (expect.hasKeyIgnoreCase(attrKey)) {
return expect.getIgnoreCase(attrKey).equals(attr.getValue());
}
}
// no attributes defined for tag, try :all tag
return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
|
java
|
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) {
TagName tag = TagName.valueOf(tagName);
AttributeKey key = AttributeKey.valueOf(attr.getKey());
Set<AttributeKey> okSet = attributes.get(tag);
if (okSet != null && okSet.contains(key)) {
if (protocols.containsKey(tag)) {
Map<AttributeKey, Set<Protocol>> attrProts = protocols.get(tag);
// ok if not defined protocol; otherwise test
return !attrProts.containsKey(key) || testValidProtocol(el, attr, attrProts.get(key));
} else { // attribute found, no protocols defined, so OK
return true;
}
}
// might be an enforced attribute?
Map<AttributeKey, AttributeValue> enforcedSet = enforcedAttributes.get(tag);
if (enforcedSet != null) {
Attributes expect = getEnforcedAttributes(tagName);
String attrKey = attr.getKey();
if (expect.hasKeyIgnoreCase(attrKey)) {
return expect.getIgnoreCase(attrKey).equals(attr.getValue());
}
}
// no attributes defined for tag, try :all tag
return !tagName.equals(":all") && isSafeAttribute(":all", el, attr);
}
|
[
"protected",
"boolean",
"isSafeAttribute",
"(",
"String",
"tagName",
",",
"Element",
"el",
",",
"Attribute",
"attr",
")",
"{",
"TagName",
"tag",
"=",
"TagName",
".",
"valueOf",
"(",
"tagName",
")",
";",
"AttributeKey",
"key",
"=",
"AttributeKey",
".",
"valueOf",
"(",
"attr",
".",
"getKey",
"(",
")",
")",
";",
"Set",
"<",
"AttributeKey",
">",
"okSet",
"=",
"attributes",
".",
"get",
"(",
"tag",
")",
";",
"if",
"(",
"okSet",
"!=",
"null",
"&&",
"okSet",
".",
"contains",
"(",
"key",
")",
")",
"{",
"if",
"(",
"protocols",
".",
"containsKey",
"(",
"tag",
")",
")",
"{",
"Map",
"<",
"AttributeKey",
",",
"Set",
"<",
"Protocol",
">",
">",
"attrProts",
"=",
"protocols",
".",
"get",
"(",
"tag",
")",
";",
"// ok if not defined protocol; otherwise test",
"return",
"!",
"attrProts",
".",
"containsKey",
"(",
"key",
")",
"||",
"testValidProtocol",
"(",
"el",
",",
"attr",
",",
"attrProts",
".",
"get",
"(",
"key",
")",
")",
";",
"}",
"else",
"{",
"// attribute found, no protocols defined, so OK",
"return",
"true",
";",
"}",
"}",
"// might be an enforced attribute?",
"Map",
"<",
"AttributeKey",
",",
"AttributeValue",
">",
"enforcedSet",
"=",
"enforcedAttributes",
".",
"get",
"(",
"tag",
")",
";",
"if",
"(",
"enforcedSet",
"!=",
"null",
")",
"{",
"Attributes",
"expect",
"=",
"getEnforcedAttributes",
"(",
"tagName",
")",
";",
"String",
"attrKey",
"=",
"attr",
".",
"getKey",
"(",
")",
";",
"if",
"(",
"expect",
".",
"hasKeyIgnoreCase",
"(",
"attrKey",
")",
")",
"{",
"return",
"expect",
".",
"getIgnoreCase",
"(",
"attrKey",
")",
".",
"equals",
"(",
"attr",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"// no attributes defined for tag, try :all tag",
"return",
"!",
"tagName",
".",
"equals",
"(",
"\":all\"",
")",
"&&",
"isSafeAttribute",
"(",
"\":all\"",
",",
"el",
",",
"attr",
")",
";",
"}"
] |
Test if the supplied attribute is allowed by this whitelist for this tag
@param tagName tag to consider allowing the attribute in
@param el element under test, to confirm protocol
@param attr attribute under test
@return true if allowed
|
[
"Test",
"if",
"the",
"supplied",
"attribute",
"is",
"allowed",
"by",
"this",
"whitelist",
"for",
"this",
"tag"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/safety/Whitelist.java#L496-L521
|
13,967
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/DataNode.java
|
DataNode.createFromEncoded
|
public static DataNode createFromEncoded(String encodedData, String baseUri) {
String data = Entities.unescape(encodedData);
return new DataNode(data);
}
|
java
|
public static DataNode createFromEncoded(String encodedData, String baseUri) {
String data = Entities.unescape(encodedData);
return new DataNode(data);
}
|
[
"public",
"static",
"DataNode",
"createFromEncoded",
"(",
"String",
"encodedData",
",",
"String",
"baseUri",
")",
"{",
"String",
"data",
"=",
"Entities",
".",
"unescape",
"(",
"encodedData",
")",
";",
"return",
"new",
"DataNode",
"(",
"data",
")",
";",
"}"
] |
Create a new DataNode from HTML encoded data.
@param encodedData encoded data
@param baseUri bass URI
@return new DataNode
|
[
"Create",
"a",
"new",
"DataNode",
"from",
"HTML",
"encoded",
"data",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/DataNode.java#L68-L71
|
13,968
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Document.java
|
Document.createShell
|
public static Document createShell(String baseUri) {
Validate.notNull(baseUri);
Document doc = new Document(baseUri);
doc.parser = doc.parser();
Element html = doc.appendElement("html");
html.appendElement("head");
html.appendElement("body");
return doc;
}
|
java
|
public static Document createShell(String baseUri) {
Validate.notNull(baseUri);
Document doc = new Document(baseUri);
doc.parser = doc.parser();
Element html = doc.appendElement("html");
html.appendElement("head");
html.appendElement("body");
return doc;
}
|
[
"public",
"static",
"Document",
"createShell",
"(",
"String",
"baseUri",
")",
"{",
"Validate",
".",
"notNull",
"(",
"baseUri",
")",
";",
"Document",
"doc",
"=",
"new",
"Document",
"(",
"baseUri",
")",
";",
"doc",
".",
"parser",
"=",
"doc",
".",
"parser",
"(",
")",
";",
"Element",
"html",
"=",
"doc",
".",
"appendElement",
"(",
"\"html\"",
")",
";",
"html",
".",
"appendElement",
"(",
"\"head\"",
")",
";",
"html",
".",
"appendElement",
"(",
"\"body\"",
")",
";",
"return",
"doc",
";",
"}"
] |
Create a valid, empty shell of a document, suitable for adding more elements to.
@param baseUri baseUri of document
@return document with html, head, and body elements.
|
[
"Create",
"a",
"valid",
"empty",
"shell",
"of",
"a",
"document",
"suitable",
"for",
"adding",
"more",
"elements",
"to",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Document.java#L42-L52
|
13,969
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Document.java
|
Document.createElement
|
public Element createElement(String tagName) {
return new Element(Tag.valueOf(tagName, ParseSettings.preserveCase), this.baseUri());
}
|
java
|
public Element createElement(String tagName) {
return new Element(Tag.valueOf(tagName, ParseSettings.preserveCase), this.baseUri());
}
|
[
"public",
"Element",
"createElement",
"(",
"String",
"tagName",
")",
"{",
"return",
"new",
"Element",
"(",
"Tag",
".",
"valueOf",
"(",
"tagName",
",",
"ParseSettings",
".",
"preserveCase",
")",
",",
"this",
".",
"baseUri",
"(",
")",
")",
";",
"}"
] |
Create a new Element, with this document's base uri. Does not make the new element a child of this document.
@param tagName element tag name (e.g. {@code a})
@return new element
|
[
"Create",
"a",
"new",
"Element",
"with",
"this",
"document",
"s",
"base",
"uri",
".",
"Does",
"not",
"make",
"the",
"new",
"element",
"a",
"child",
"of",
"this",
"document",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Document.java#L109-L111
|
13,970
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Document.java
|
Document.normalise
|
public Document normalise() {
Element htmlEl = findFirstElementByTagName("html", this);
if (htmlEl == null)
htmlEl = appendElement("html");
if (head() == null)
htmlEl.prependElement("head");
if (body() == null)
htmlEl.appendElement("body");
// pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care
// of. do in inverse order to maintain text order.
normaliseTextNodes(head());
normaliseTextNodes(htmlEl);
normaliseTextNodes(this);
normaliseStructure("head", htmlEl);
normaliseStructure("body", htmlEl);
ensureMetaCharsetElement();
return this;
}
|
java
|
public Document normalise() {
Element htmlEl = findFirstElementByTagName("html", this);
if (htmlEl == null)
htmlEl = appendElement("html");
if (head() == null)
htmlEl.prependElement("head");
if (body() == null)
htmlEl.appendElement("body");
// pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care
// of. do in inverse order to maintain text order.
normaliseTextNodes(head());
normaliseTextNodes(htmlEl);
normaliseTextNodes(this);
normaliseStructure("head", htmlEl);
normaliseStructure("body", htmlEl);
ensureMetaCharsetElement();
return this;
}
|
[
"public",
"Document",
"normalise",
"(",
")",
"{",
"Element",
"htmlEl",
"=",
"findFirstElementByTagName",
"(",
"\"html\"",
",",
"this",
")",
";",
"if",
"(",
"htmlEl",
"==",
"null",
")",
"htmlEl",
"=",
"appendElement",
"(",
"\"html\"",
")",
";",
"if",
"(",
"head",
"(",
")",
"==",
"null",
")",
"htmlEl",
".",
"prependElement",
"(",
"\"head\"",
")",
";",
"if",
"(",
"body",
"(",
")",
"==",
"null",
")",
"htmlEl",
".",
"appendElement",
"(",
"\"body\"",
")",
";",
"// pull text nodes out of root, html, and head els, and push into body. non-text nodes are already taken care",
"// of. do in inverse order to maintain text order.",
"normaliseTextNodes",
"(",
"head",
"(",
")",
")",
";",
"normaliseTextNodes",
"(",
"htmlEl",
")",
";",
"normaliseTextNodes",
"(",
"this",
")",
";",
"normaliseStructure",
"(",
"\"head\"",
",",
"htmlEl",
")",
";",
"normaliseStructure",
"(",
"\"body\"",
",",
"htmlEl",
")",
";",
"ensureMetaCharsetElement",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
Normalise the document. This happens after the parse phase so generally does not need to be called.
Moves any text content that is not in the body element into the body.
@return this document after normalisation
|
[
"Normalise",
"the",
"document",
".",
"This",
"happens",
"after",
"the",
"parse",
"phase",
"so",
"generally",
"does",
"not",
"need",
"to",
"be",
"called",
".",
"Moves",
"any",
"text",
"content",
"that",
"is",
"not",
"in",
"the",
"body",
"element",
"into",
"the",
"body",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Document.java#L118-L139
|
13,971
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Document.java
|
Document.normaliseTextNodes
|
private void normaliseTextNodes(Element element) {
List<Node> toMove = new ArrayList<>();
for (Node node: element.childNodes) {
if (node instanceof TextNode) {
TextNode tn = (TextNode) node;
if (!tn.isBlank())
toMove.add(tn);
}
}
for (int i = toMove.size()-1; i >= 0; i--) {
Node node = toMove.get(i);
element.removeChild(node);
body().prependChild(new TextNode(" "));
body().prependChild(node);
}
}
|
java
|
private void normaliseTextNodes(Element element) {
List<Node> toMove = new ArrayList<>();
for (Node node: element.childNodes) {
if (node instanceof TextNode) {
TextNode tn = (TextNode) node;
if (!tn.isBlank())
toMove.add(tn);
}
}
for (int i = toMove.size()-1; i >= 0; i--) {
Node node = toMove.get(i);
element.removeChild(node);
body().prependChild(new TextNode(" "));
body().prependChild(node);
}
}
|
[
"private",
"void",
"normaliseTextNodes",
"(",
"Element",
"element",
")",
"{",
"List",
"<",
"Node",
">",
"toMove",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Node",
"node",
":",
"element",
".",
"childNodes",
")",
"{",
"if",
"(",
"node",
"instanceof",
"TextNode",
")",
"{",
"TextNode",
"tn",
"=",
"(",
"TextNode",
")",
"node",
";",
"if",
"(",
"!",
"tn",
".",
"isBlank",
"(",
")",
")",
"toMove",
".",
"add",
"(",
"tn",
")",
";",
"}",
"}",
"for",
"(",
"int",
"i",
"=",
"toMove",
".",
"size",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"Node",
"node",
"=",
"toMove",
".",
"get",
"(",
"i",
")",
";",
"element",
".",
"removeChild",
"(",
"node",
")",
";",
"body",
"(",
")",
".",
"prependChild",
"(",
"new",
"TextNode",
"(",
"\" \"",
")",
")",
";",
"body",
"(",
")",
".",
"prependChild",
"(",
"node",
")",
";",
"}",
"}"
] |
does not recurse.
|
[
"does",
"not",
"recurse",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Document.java#L142-L158
|
13,972
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Document.java
|
Document.findFirstElementByTagName
|
private Element findFirstElementByTagName(String tag, Node node) {
if (node.nodeName().equals(tag))
return (Element) node;
else {
int size = node.childNodeSize();
for (int i = 0; i < size; i++) {
Element found = findFirstElementByTagName(tag, node.childNode(i));
if (found != null)
return found;
}
}
return null;
}
|
java
|
private Element findFirstElementByTagName(String tag, Node node) {
if (node.nodeName().equals(tag))
return (Element) node;
else {
int size = node.childNodeSize();
for (int i = 0; i < size; i++) {
Element found = findFirstElementByTagName(tag, node.childNode(i));
if (found != null)
return found;
}
}
return null;
}
|
[
"private",
"Element",
"findFirstElementByTagName",
"(",
"String",
"tag",
",",
"Node",
"node",
")",
"{",
"if",
"(",
"node",
".",
"nodeName",
"(",
")",
".",
"equals",
"(",
"tag",
")",
")",
"return",
"(",
"Element",
")",
"node",
";",
"else",
"{",
"int",
"size",
"=",
"node",
".",
"childNodeSize",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"size",
";",
"i",
"++",
")",
"{",
"Element",
"found",
"=",
"findFirstElementByTagName",
"(",
"tag",
",",
"node",
".",
"childNode",
"(",
"i",
")",
")",
";",
"if",
"(",
"found",
"!=",
"null",
")",
"return",
"found",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
fast method to get first by tag name, used for html, head, body finders
|
[
"fast",
"method",
"to",
"get",
"first",
"by",
"tag",
"name",
"used",
"for",
"html",
"head",
"body",
"finders"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Document.java#L182-L194
|
13,973
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/HttpConnection.java
|
HttpConnection.encodeUrl
|
private static String encodeUrl(String url) {
try {
URL u = new URL(url);
return encodeUrl(u).toExternalForm();
} catch (Exception e) {
return url;
}
}
|
java
|
private static String encodeUrl(String url) {
try {
URL u = new URL(url);
return encodeUrl(u).toExternalForm();
} catch (Exception e) {
return url;
}
}
|
[
"private",
"static",
"String",
"encodeUrl",
"(",
"String",
"url",
")",
"{",
"try",
"{",
"URL",
"u",
"=",
"new",
"URL",
"(",
"url",
")",
";",
"return",
"encodeUrl",
"(",
"u",
")",
".",
"toExternalForm",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"url",
";",
"}",
"}"
] |
Encodes the input URL into a safe ASCII URL string
@param url unescaped URL
@return escaped URL
|
[
"Encodes",
"the",
"input",
"URL",
"into",
"a",
"safe",
"ASCII",
"URL",
"string"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/HttpConnection.java#L89-L96
|
13,974
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/FormElement.java
|
FormElement.formData
|
public List<Connection.KeyVal> formData() {
ArrayList<Connection.KeyVal> data = new ArrayList<>();
// iterate the form control elements and accumulate their values
for (Element el: elements) {
if (!el.tag().isFormSubmittable()) continue; // contents are form listable, superset of submitable
if (el.hasAttr("disabled")) continue; // skip disabled form inputs
String name = el.attr("name");
if (name.length() == 0) continue;
String type = el.attr("type");
if ("select".equals(el.tagName())) {
Elements options = el.select("option[selected]");
boolean set = false;
for (Element option: options) {
data.add(HttpConnection.KeyVal.create(name, option.val()));
set = true;
}
if (!set) {
Element option = el.select("option").first();
if (option != null)
data.add(HttpConnection.KeyVal.create(name, option.val()));
}
} else if ("checkbox".equalsIgnoreCase(type) || "radio".equalsIgnoreCase(type)) {
// only add checkbox or radio if they have the checked attribute
if (el.hasAttr("checked")) {
final String val = el.val().length() > 0 ? el.val() : "on";
data.add(HttpConnection.KeyVal.create(name, val));
}
} else {
data.add(HttpConnection.KeyVal.create(name, el.val()));
}
}
return data;
}
|
java
|
public List<Connection.KeyVal> formData() {
ArrayList<Connection.KeyVal> data = new ArrayList<>();
// iterate the form control elements and accumulate their values
for (Element el: elements) {
if (!el.tag().isFormSubmittable()) continue; // contents are form listable, superset of submitable
if (el.hasAttr("disabled")) continue; // skip disabled form inputs
String name = el.attr("name");
if (name.length() == 0) continue;
String type = el.attr("type");
if ("select".equals(el.tagName())) {
Elements options = el.select("option[selected]");
boolean set = false;
for (Element option: options) {
data.add(HttpConnection.KeyVal.create(name, option.val()));
set = true;
}
if (!set) {
Element option = el.select("option").first();
if (option != null)
data.add(HttpConnection.KeyVal.create(name, option.val()));
}
} else if ("checkbox".equalsIgnoreCase(type) || "radio".equalsIgnoreCase(type)) {
// only add checkbox or radio if they have the checked attribute
if (el.hasAttr("checked")) {
final String val = el.val().length() > 0 ? el.val() : "on";
data.add(HttpConnection.KeyVal.create(name, val));
}
} else {
data.add(HttpConnection.KeyVal.create(name, el.val()));
}
}
return data;
}
|
[
"public",
"List",
"<",
"Connection",
".",
"KeyVal",
">",
"formData",
"(",
")",
"{",
"ArrayList",
"<",
"Connection",
".",
"KeyVal",
">",
"data",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"// iterate the form control elements and accumulate their values",
"for",
"(",
"Element",
"el",
":",
"elements",
")",
"{",
"if",
"(",
"!",
"el",
".",
"tag",
"(",
")",
".",
"isFormSubmittable",
"(",
")",
")",
"continue",
";",
"// contents are form listable, superset of submitable",
"if",
"(",
"el",
".",
"hasAttr",
"(",
"\"disabled\"",
")",
")",
"continue",
";",
"// skip disabled form inputs",
"String",
"name",
"=",
"el",
".",
"attr",
"(",
"\"name\"",
")",
";",
"if",
"(",
"name",
".",
"length",
"(",
")",
"==",
"0",
")",
"continue",
";",
"String",
"type",
"=",
"el",
".",
"attr",
"(",
"\"type\"",
")",
";",
"if",
"(",
"\"select\"",
".",
"equals",
"(",
"el",
".",
"tagName",
"(",
")",
")",
")",
"{",
"Elements",
"options",
"=",
"el",
".",
"select",
"(",
"\"option[selected]\"",
")",
";",
"boolean",
"set",
"=",
"false",
";",
"for",
"(",
"Element",
"option",
":",
"options",
")",
"{",
"data",
".",
"add",
"(",
"HttpConnection",
".",
"KeyVal",
".",
"create",
"(",
"name",
",",
"option",
".",
"val",
"(",
")",
")",
")",
";",
"set",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"set",
")",
"{",
"Element",
"option",
"=",
"el",
".",
"select",
"(",
"\"option\"",
")",
".",
"first",
"(",
")",
";",
"if",
"(",
"option",
"!=",
"null",
")",
"data",
".",
"add",
"(",
"HttpConnection",
".",
"KeyVal",
".",
"create",
"(",
"name",
",",
"option",
".",
"val",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"\"checkbox\"",
".",
"equalsIgnoreCase",
"(",
"type",
")",
"||",
"\"radio\"",
".",
"equalsIgnoreCase",
"(",
"type",
")",
")",
"{",
"// only add checkbox or radio if they have the checked attribute",
"if",
"(",
"el",
".",
"hasAttr",
"(",
"\"checked\"",
")",
")",
"{",
"final",
"String",
"val",
"=",
"el",
".",
"val",
"(",
")",
".",
"length",
"(",
")",
">",
"0",
"?",
"el",
".",
"val",
"(",
")",
":",
"\"on\"",
";",
"data",
".",
"add",
"(",
"HttpConnection",
".",
"KeyVal",
".",
"create",
"(",
"name",
",",
"val",
")",
")",
";",
"}",
"}",
"else",
"{",
"data",
".",
"add",
"(",
"HttpConnection",
".",
"KeyVal",
".",
"create",
"(",
"name",
",",
"el",
".",
"val",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"data",
";",
"}"
] |
Get the data that this form submits. The returned list is a copy of the data, and changes to the contents of the
list will not be reflected in the DOM.
@return a list of key vals
|
[
"Get",
"the",
"data",
"that",
"this",
"form",
"submits",
".",
"The",
"returned",
"list",
"is",
"a",
"copy",
"of",
"the",
"data",
"and",
"changes",
"to",
"the",
"contents",
"of",
"the",
"list",
"will",
"not",
"be",
"reflected",
"in",
"the",
"DOM",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/FormElement.java#L78-L112
|
13,975
|
jhy/jsoup
|
src/main/java/org/jsoup/parser/XmlTreeBuilder.java
|
XmlTreeBuilder.popStackToClose
|
private void popStackToClose(Token.EndTag endTag) {
String elName = settings.normalizeTag(endTag.tagName);
Element firstFound = null;
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
if (next.nodeName().equals(elName)) {
firstFound = next;
break;
}
}
if (firstFound == null)
return; // not found, skip
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
stack.remove(pos);
if (next == firstFound)
break;
}
}
|
java
|
private void popStackToClose(Token.EndTag endTag) {
String elName = settings.normalizeTag(endTag.tagName);
Element firstFound = null;
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
if (next.nodeName().equals(elName)) {
firstFound = next;
break;
}
}
if (firstFound == null)
return; // not found, skip
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element next = stack.get(pos);
stack.remove(pos);
if (next == firstFound)
break;
}
}
|
[
"private",
"void",
"popStackToClose",
"(",
"Token",
".",
"EndTag",
"endTag",
")",
"{",
"String",
"elName",
"=",
"settings",
".",
"normalizeTag",
"(",
"endTag",
".",
"tagName",
")",
";",
"Element",
"firstFound",
"=",
"null",
";",
"for",
"(",
"int",
"pos",
"=",
"stack",
".",
"size",
"(",
")",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"{",
"Element",
"next",
"=",
"stack",
".",
"get",
"(",
"pos",
")",
";",
"if",
"(",
"next",
".",
"nodeName",
"(",
")",
".",
"equals",
"(",
"elName",
")",
")",
"{",
"firstFound",
"=",
"next",
";",
"break",
";",
"}",
"}",
"if",
"(",
"firstFound",
"==",
"null",
")",
"return",
";",
"// not found, skip",
"for",
"(",
"int",
"pos",
"=",
"stack",
".",
"size",
"(",
")",
"-",
"1",
";",
"pos",
">=",
"0",
";",
"pos",
"--",
")",
"{",
"Element",
"next",
"=",
"stack",
".",
"get",
"(",
"pos",
")",
";",
"stack",
".",
"remove",
"(",
"pos",
")",
";",
"if",
"(",
"next",
"==",
"firstFound",
")",
"break",
";",
"}",
"}"
] |
If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence. If not
found, skips.
@param endTag tag to close
|
[
"If",
"the",
"stack",
"contains",
"an",
"element",
"with",
"this",
"tag",
"s",
"name",
"pop",
"up",
"the",
"stack",
"to",
"remove",
"the",
"first",
"occurrence",
".",
"If",
"not",
"found",
"skips",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/parser/XmlTreeBuilder.java#L119-L139
|
13,976
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/StringUtil.java
|
StringUtil.join
|
public static String join(String[] strings, String sep) {
return join(Arrays.asList(strings), sep);
}
|
java
|
public static String join(String[] strings, String sep) {
return join(Arrays.asList(strings), sep);
}
|
[
"public",
"static",
"String",
"join",
"(",
"String",
"[",
"]",
"strings",
",",
"String",
"sep",
")",
"{",
"return",
"join",
"(",
"Arrays",
".",
"asList",
"(",
"strings",
")",
",",
"sep",
")",
";",
"}"
] |
Join an array of strings by a separator
@param strings collection of string objects
@param sep string to place between strings
@return joined string
|
[
"Join",
"an",
"array",
"of",
"strings",
"by",
"a",
"separator"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/StringUtil.java#L59-L61
|
13,977
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/StringUtil.java
|
StringUtil.padding
|
public static String padding(int width) {
if (width < 0)
throw new IllegalArgumentException("width must be > 0");
if (width < padding.length)
return padding[width];
char[] out = new char[width];
for (int i = 0; i < width; i++)
out[i] = ' ';
return String.valueOf(out);
}
|
java
|
public static String padding(int width) {
if (width < 0)
throw new IllegalArgumentException("width must be > 0");
if (width < padding.length)
return padding[width];
char[] out = new char[width];
for (int i = 0; i < width; i++)
out[i] = ' ';
return String.valueOf(out);
}
|
[
"public",
"static",
"String",
"padding",
"(",
"int",
"width",
")",
"{",
"if",
"(",
"width",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"width must be > 0\"",
")",
";",
"if",
"(",
"width",
"<",
"padding",
".",
"length",
")",
"return",
"padding",
"[",
"width",
"]",
";",
"char",
"[",
"]",
"out",
"=",
"new",
"char",
"[",
"width",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"width",
";",
"i",
"++",
")",
"out",
"[",
"i",
"]",
"=",
"'",
"'",
";",
"return",
"String",
".",
"valueOf",
"(",
"out",
")",
";",
"}"
] |
Returns space padding
@param width amount of padding desired
@return string of spaces * width
|
[
"Returns",
"space",
"padding"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/StringUtil.java#L68-L78
|
13,978
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/StringUtil.java
|
StringUtil.isNumeric
|
public static boolean isNumeric(String string) {
if (string == null || string.length() == 0)
return false;
int l = string.length();
for (int i = 0; i < l; i++) {
if (!Character.isDigit(string.codePointAt(i)))
return false;
}
return true;
}
|
java
|
public static boolean isNumeric(String string) {
if (string == null || string.length() == 0)
return false;
int l = string.length();
for (int i = 0; i < l; i++) {
if (!Character.isDigit(string.codePointAt(i)))
return false;
}
return true;
}
|
[
"public",
"static",
"boolean",
"isNumeric",
"(",
"String",
"string",
")",
"{",
"if",
"(",
"string",
"==",
"null",
"||",
"string",
".",
"length",
"(",
")",
"==",
"0",
")",
"return",
"false",
";",
"int",
"l",
"=",
"string",
".",
"length",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"Character",
".",
"isDigit",
"(",
"string",
".",
"codePointAt",
"(",
"i",
")",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Tests if a string is numeric, i.e. contains only digit characters
@param string string to test
@return true if only digit chars, false if empty or null or contains non-digit chars
|
[
"Tests",
"if",
"a",
"string",
"is",
"numeric",
"i",
".",
"e",
".",
"contains",
"only",
"digit",
"characters"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/StringUtil.java#L102-L112
|
13,979
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/StringUtil.java
|
StringUtil.appendNormalisedWhitespace
|
public static void appendNormalisedWhitespace(StringBuilder accum, String string, boolean stripLeading) {
boolean lastWasWhite = false;
boolean reachedNonWhite = false;
int len = string.length();
int c;
for (int i = 0; i < len; i+= Character.charCount(c)) {
c = string.codePointAt(i);
if (isActuallyWhitespace(c)) {
if ((stripLeading && !reachedNonWhite) || lastWasWhite)
continue;
accum.append(' ');
lastWasWhite = true;
}
else if (!isInvisibleChar(c)) {
accum.appendCodePoint(c);
lastWasWhite = false;
reachedNonWhite = true;
}
}
}
|
java
|
public static void appendNormalisedWhitespace(StringBuilder accum, String string, boolean stripLeading) {
boolean lastWasWhite = false;
boolean reachedNonWhite = false;
int len = string.length();
int c;
for (int i = 0; i < len; i+= Character.charCount(c)) {
c = string.codePointAt(i);
if (isActuallyWhitespace(c)) {
if ((stripLeading && !reachedNonWhite) || lastWasWhite)
continue;
accum.append(' ');
lastWasWhite = true;
}
else if (!isInvisibleChar(c)) {
accum.appendCodePoint(c);
lastWasWhite = false;
reachedNonWhite = true;
}
}
}
|
[
"public",
"static",
"void",
"appendNormalisedWhitespace",
"(",
"StringBuilder",
"accum",
",",
"String",
"string",
",",
"boolean",
"stripLeading",
")",
"{",
"boolean",
"lastWasWhite",
"=",
"false",
";",
"boolean",
"reachedNonWhite",
"=",
"false",
";",
"int",
"len",
"=",
"string",
".",
"length",
"(",
")",
";",
"int",
"c",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"+=",
"Character",
".",
"charCount",
"(",
"c",
")",
")",
"{",
"c",
"=",
"string",
".",
"codePointAt",
"(",
"i",
")",
";",
"if",
"(",
"isActuallyWhitespace",
"(",
"c",
")",
")",
"{",
"if",
"(",
"(",
"stripLeading",
"&&",
"!",
"reachedNonWhite",
")",
"||",
"lastWasWhite",
")",
"continue",
";",
"accum",
".",
"append",
"(",
"'",
"'",
")",
";",
"lastWasWhite",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"!",
"isInvisibleChar",
"(",
"c",
")",
")",
"{",
"accum",
".",
"appendCodePoint",
"(",
"c",
")",
";",
"lastWasWhite",
"=",
"false",
";",
"reachedNonWhite",
"=",
"true",
";",
"}",
"}",
"}"
] |
After normalizing the whitespace within a string, appends it to a string builder.
@param accum builder to append to
@param string string to normalize whitespace within
@param stripLeading set to true if you wish to remove any leading whitespace
|
[
"After",
"normalizing",
"the",
"whitespace",
"within",
"a",
"string",
"appends",
"it",
"to",
"a",
"string",
"builder",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/StringUtil.java#L157-L177
|
13,980
|
jhy/jsoup
|
src/main/java/org/jsoup/internal/StringUtil.java
|
StringUtil.releaseBuilder
|
public static String releaseBuilder(StringBuilder sb) {
Validate.notNull(sb);
String string = sb.toString();
if (sb.length() > MaxCachedBuilderSize)
sb = new StringBuilder(MaxCachedBuilderSize); // make sure it hasn't grown too big
else
sb.delete(0, sb.length()); // make sure it's emptied on release
synchronized (builders) {
builders.push(sb);
while (builders.size() > MaxIdleBuilders) {
builders.pop();
}
}
return string;
}
|
java
|
public static String releaseBuilder(StringBuilder sb) {
Validate.notNull(sb);
String string = sb.toString();
if (sb.length() > MaxCachedBuilderSize)
sb = new StringBuilder(MaxCachedBuilderSize); // make sure it hasn't grown too big
else
sb.delete(0, sb.length()); // make sure it's emptied on release
synchronized (builders) {
builders.push(sb);
while (builders.size() > MaxIdleBuilders) {
builders.pop();
}
}
return string;
}
|
[
"public",
"static",
"String",
"releaseBuilder",
"(",
"StringBuilder",
"sb",
")",
"{",
"Validate",
".",
"notNull",
"(",
"sb",
")",
";",
"String",
"string",
"=",
"sb",
".",
"toString",
"(",
")",
";",
"if",
"(",
"sb",
".",
"length",
"(",
")",
">",
"MaxCachedBuilderSize",
")",
"sb",
"=",
"new",
"StringBuilder",
"(",
"MaxCachedBuilderSize",
")",
";",
"// make sure it hasn't grown too big",
"else",
"sb",
".",
"delete",
"(",
"0",
",",
"sb",
".",
"length",
"(",
")",
")",
";",
"// make sure it's emptied on release",
"synchronized",
"(",
"builders",
")",
"{",
"builders",
".",
"push",
"(",
"sb",
")",
";",
"while",
"(",
"builders",
".",
"size",
"(",
")",
">",
"MaxIdleBuilders",
")",
"{",
"builders",
".",
"pop",
"(",
")",
";",
"}",
"}",
"return",
"string",
";",
"}"
] |
Release a borrowed builder. Care must be taken not to use the builder after it has been returned, as its
contents may be changed by this method, or by a concurrent thread.
@param sb the StringBuilder to release.
@return the string value of the released String Builder (as an incentive to release it!).
|
[
"Release",
"a",
"borrowed",
"builder",
".",
"Care",
"must",
"be",
"taken",
"not",
"to",
"use",
"the",
"builder",
"after",
"it",
"has",
"been",
"returned",
"as",
"its",
"contents",
"may",
"be",
"changed",
"by",
"this",
"method",
"or",
"by",
"a",
"concurrent",
"thread",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/internal/StringUtil.java#L256-L273
|
13,981
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/DataUtil.java
|
DataUtil.load
|
public static Document load(File in, String charsetName, String baseUri) throws IOException {
return parseInputStream(new FileInputStream(in), charsetName, baseUri, Parser.htmlParser());
}
|
java
|
public static Document load(File in, String charsetName, String baseUri) throws IOException {
return parseInputStream(new FileInputStream(in), charsetName, baseUri, Parser.htmlParser());
}
|
[
"public",
"static",
"Document",
"load",
"(",
"File",
"in",
",",
"String",
"charsetName",
",",
"String",
"baseUri",
")",
"throws",
"IOException",
"{",
"return",
"parseInputStream",
"(",
"new",
"FileInputStream",
"(",
"in",
")",
",",
"charsetName",
",",
"baseUri",
",",
"Parser",
".",
"htmlParser",
"(",
")",
")",
";",
"}"
] |
Loads a file to a Document.
@param in file to load
@param charsetName character set of input
@param baseUri base URI of document, to resolve relative links against
@return Document
@throws IOException on IO error
|
[
"Loads",
"a",
"file",
"to",
"a",
"Document",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/DataUtil.java#L53-L55
|
13,982
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/DataUtil.java
|
DataUtil.load
|
public static Document load(InputStream in, String charsetName, String baseUri) throws IOException {
return parseInputStream(in, charsetName, baseUri, Parser.htmlParser());
}
|
java
|
public static Document load(InputStream in, String charsetName, String baseUri) throws IOException {
return parseInputStream(in, charsetName, baseUri, Parser.htmlParser());
}
|
[
"public",
"static",
"Document",
"load",
"(",
"InputStream",
"in",
",",
"String",
"charsetName",
",",
"String",
"baseUri",
")",
"throws",
"IOException",
"{",
"return",
"parseInputStream",
"(",
"in",
",",
"charsetName",
",",
"baseUri",
",",
"Parser",
".",
"htmlParser",
"(",
")",
")",
";",
"}"
] |
Parses a Document from an input steam.
@param in input stream to parse. You will need to close it.
@param charsetName character set of input
@param baseUri base URI of document, to resolve relative links against
@return Document
@throws IOException on IO error
|
[
"Parses",
"a",
"Document",
"from",
"an",
"input",
"steam",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/DataUtil.java#L65-L67
|
13,983
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/DataUtil.java
|
DataUtil.crossStreams
|
static void crossStreams(final InputStream in, final OutputStream out) throws IOException {
final byte[] buffer = new byte[bufferSize];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
}
|
java
|
static void crossStreams(final InputStream in, final OutputStream out) throws IOException {
final byte[] buffer = new byte[bufferSize];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
}
|
[
"static",
"void",
"crossStreams",
"(",
"final",
"InputStream",
"in",
",",
"final",
"OutputStream",
"out",
")",
"throws",
"IOException",
"{",
"final",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"bufferSize",
"]",
";",
"int",
"len",
";",
"while",
"(",
"(",
"len",
"=",
"in",
".",
"read",
"(",
"buffer",
")",
")",
"!=",
"-",
"1",
")",
"{",
"out",
".",
"write",
"(",
"buffer",
",",
"0",
",",
"len",
")",
";",
"}",
"}"
] |
Writes the input stream to the output stream. Doesn't close them.
@param in input stream to read from
@param out output stream to write to
@throws IOException on IO error
|
[
"Writes",
"the",
"input",
"stream",
"to",
"the",
"output",
"stream",
".",
"Doesn",
"t",
"close",
"them",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/DataUtil.java#L88-L94
|
13,984
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/DataUtil.java
|
DataUtil.readToByteBuffer
|
public static ByteBuffer readToByteBuffer(InputStream inStream, int maxSize) throws IOException {
Validate.isTrue(maxSize >= 0, "maxSize must be 0 (unlimited) or larger");
final ConstrainableInputStream input = ConstrainableInputStream.wrap(inStream, bufferSize, maxSize);
return input.readToByteBuffer(maxSize);
}
|
java
|
public static ByteBuffer readToByteBuffer(InputStream inStream, int maxSize) throws IOException {
Validate.isTrue(maxSize >= 0, "maxSize must be 0 (unlimited) or larger");
final ConstrainableInputStream input = ConstrainableInputStream.wrap(inStream, bufferSize, maxSize);
return input.readToByteBuffer(maxSize);
}
|
[
"public",
"static",
"ByteBuffer",
"readToByteBuffer",
"(",
"InputStream",
"inStream",
",",
"int",
"maxSize",
")",
"throws",
"IOException",
"{",
"Validate",
".",
"isTrue",
"(",
"maxSize",
">=",
"0",
",",
"\"maxSize must be 0 (unlimited) or larger\"",
")",
";",
"final",
"ConstrainableInputStream",
"input",
"=",
"ConstrainableInputStream",
".",
"wrap",
"(",
"inStream",
",",
"bufferSize",
",",
"maxSize",
")",
";",
"return",
"input",
".",
"readToByteBuffer",
"(",
"maxSize",
")",
";",
"}"
] |
Read the input stream into a byte buffer. To deal with slow input streams, you may interrupt the thread this
method is executing on. The data read until being interrupted will be available.
@param inStream the input stream to read from
@param maxSize the maximum size in bytes to read from the stream. Set to 0 to be unlimited.
@return the filled byte buffer
@throws IOException if an exception occurs whilst reading from the input stream.
|
[
"Read",
"the",
"input",
"stream",
"into",
"a",
"byte",
"buffer",
".",
"To",
"deal",
"with",
"slow",
"input",
"streams",
"you",
"may",
"interrupt",
"the",
"thread",
"this",
"method",
"is",
"executing",
"on",
".",
"The",
"data",
"read",
"until",
"being",
"interrupted",
"will",
"be",
"available",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/DataUtil.java#L189-L193
|
13,985
|
jhy/jsoup
|
src/main/java/org/jsoup/helper/DataUtil.java
|
DataUtil.mimeBoundary
|
static String mimeBoundary() {
final StringBuilder mime = StringUtil.borrowBuilder();
final Random rand = new Random();
for (int i = 0; i < boundaryLength; i++) {
mime.append(mimeBoundaryChars[rand.nextInt(mimeBoundaryChars.length)]);
}
return StringUtil.releaseBuilder(mime);
}
|
java
|
static String mimeBoundary() {
final StringBuilder mime = StringUtil.borrowBuilder();
final Random rand = new Random();
for (int i = 0; i < boundaryLength; i++) {
mime.append(mimeBoundaryChars[rand.nextInt(mimeBoundaryChars.length)]);
}
return StringUtil.releaseBuilder(mime);
}
|
[
"static",
"String",
"mimeBoundary",
"(",
")",
"{",
"final",
"StringBuilder",
"mime",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"final",
"Random",
"rand",
"=",
"new",
"Random",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"boundaryLength",
";",
"i",
"++",
")",
"{",
"mime",
".",
"append",
"(",
"mimeBoundaryChars",
"[",
"rand",
".",
"nextInt",
"(",
"mimeBoundaryChars",
".",
"length",
")",
"]",
")",
";",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"mime",
")",
";",
"}"
] |
Creates a random string, suitable for use as a mime boundary
|
[
"Creates",
"a",
"random",
"string",
"suitable",
"for",
"use",
"as",
"a",
"mime",
"boundary"
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/helper/DataUtil.java#L232-L239
|
13,986
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.hasAttr
|
public boolean hasAttr(String attributeKey) {
for (Element element : this) {
if (element.hasAttr(attributeKey))
return true;
}
return false;
}
|
java
|
public boolean hasAttr(String attributeKey) {
for (Element element : this) {
if (element.hasAttr(attributeKey))
return true;
}
return false;
}
|
[
"public",
"boolean",
"hasAttr",
"(",
"String",
"attributeKey",
")",
"{",
"for",
"(",
"Element",
"element",
":",
"this",
")",
"{",
"if",
"(",
"element",
".",
"hasAttr",
"(",
"attributeKey",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if any of the matched elements have this attribute defined.
@param attributeKey attribute key
@return true if any of the elements have the attribute; false if none do.
|
[
"Checks",
"if",
"any",
"of",
"the",
"matched",
"elements",
"have",
"this",
"attribute",
"defined",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L78-L84
|
13,987
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.eachAttr
|
public List<String> eachAttr(String attributeKey) {
List<String> attrs = new ArrayList<>(size());
for (Element element : this) {
if (element.hasAttr(attributeKey))
attrs.add(element.attr(attributeKey));
}
return attrs;
}
|
java
|
public List<String> eachAttr(String attributeKey) {
List<String> attrs = new ArrayList<>(size());
for (Element element : this) {
if (element.hasAttr(attributeKey))
attrs.add(element.attr(attributeKey));
}
return attrs;
}
|
[
"public",
"List",
"<",
"String",
">",
"eachAttr",
"(",
"String",
"attributeKey",
")",
"{",
"List",
"<",
"String",
">",
"attrs",
"=",
"new",
"ArrayList",
"<>",
"(",
"size",
"(",
")",
")",
";",
"for",
"(",
"Element",
"element",
":",
"this",
")",
"{",
"if",
"(",
"element",
".",
"hasAttr",
"(",
"attributeKey",
")",
")",
"attrs",
".",
"add",
"(",
"element",
".",
"attr",
"(",
"attributeKey",
")",
")",
";",
"}",
"return",
"attrs",
";",
"}"
] |
Get the attribute value for each of the matched elements. If an element does not have this attribute, no value is
included in the result set for that element.
@param attributeKey the attribute name to return values for. You can add the {@code abs:} prefix to the key to
get absolute URLs from relative URLs, e.g.: {@code doc.select("a").eachAttr("abs:href")} .
@return a list of each element's attribute value for the attribute
|
[
"Get",
"the",
"attribute",
"value",
"for",
"each",
"of",
"the",
"matched",
"elements",
".",
"If",
"an",
"element",
"does",
"not",
"have",
"this",
"attribute",
"no",
"value",
"is",
"included",
"in",
"the",
"result",
"set",
"for",
"that",
"element",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L93-L100
|
13,988
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.attr
|
public Elements attr(String attributeKey, String attributeValue) {
for (Element element : this) {
element.attr(attributeKey, attributeValue);
}
return this;
}
|
java
|
public Elements attr(String attributeKey, String attributeValue) {
for (Element element : this) {
element.attr(attributeKey, attributeValue);
}
return this;
}
|
[
"public",
"Elements",
"attr",
"(",
"String",
"attributeKey",
",",
"String",
"attributeValue",
")",
"{",
"for",
"(",
"Element",
"element",
":",
"this",
")",
"{",
"element",
".",
"attr",
"(",
"attributeKey",
",",
"attributeValue",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Set an attribute on all matched elements.
@param attributeKey attribute key
@param attributeValue attribute value
@return this
|
[
"Set",
"an",
"attribute",
"on",
"all",
"matched",
"elements",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L108-L113
|
13,989
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.eachText
|
public List<String> eachText() {
ArrayList<String> texts = new ArrayList<>(size());
for (Element el: this) {
if (el.hasText())
texts.add(el.text());
}
return texts;
}
|
java
|
public List<String> eachText() {
ArrayList<String> texts = new ArrayList<>(size());
for (Element el: this) {
if (el.hasText())
texts.add(el.text());
}
return texts;
}
|
[
"public",
"List",
"<",
"String",
">",
"eachText",
"(",
")",
"{",
"ArrayList",
"<",
"String",
">",
"texts",
"=",
"new",
"ArrayList",
"<>",
"(",
"size",
"(",
")",
")",
";",
"for",
"(",
"Element",
"el",
":",
"this",
")",
"{",
"if",
"(",
"el",
".",
"hasText",
"(",
")",
")",
"texts",
".",
"add",
"(",
"el",
".",
"text",
"(",
")",
")",
";",
"}",
"return",
"texts",
";",
"}"
] |
Get the text content of each of the matched elements. If an element has no text, then it is not included in the
result.
@return A list of each matched element's text content.
@see Element#text()
@see Element#hasText()
@see #text()
|
[
"Get",
"the",
"text",
"content",
"of",
"each",
"of",
"the",
"matched",
"elements",
".",
"If",
"an",
"element",
"has",
"no",
"text",
"then",
"it",
"is",
"not",
"included",
"in",
"the",
"result",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L239-L246
|
13,990
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.html
|
public String html() {
StringBuilder sb = StringUtil.borrowBuilder();
for (Element element : this) {
if (sb.length() != 0)
sb.append("\n");
sb.append(element.html());
}
return StringUtil.releaseBuilder(sb);
}
|
java
|
public String html() {
StringBuilder sb = StringUtil.borrowBuilder();
for (Element element : this) {
if (sb.length() != 0)
sb.append("\n");
sb.append(element.html());
}
return StringUtil.releaseBuilder(sb);
}
|
[
"public",
"String",
"html",
"(",
")",
"{",
"StringBuilder",
"sb",
"=",
"StringUtil",
".",
"borrowBuilder",
"(",
")",
";",
"for",
"(",
"Element",
"element",
":",
"this",
")",
"{",
"if",
"(",
"sb",
".",
"length",
"(",
")",
"!=",
"0",
")",
"sb",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"sb",
".",
"append",
"(",
"element",
".",
"html",
"(",
")",
")",
";",
"}",
"return",
"StringUtil",
".",
"releaseBuilder",
"(",
"sb",
")",
";",
"}"
] |
Get the combined inner HTML of all matched elements.
@return string of all element's inner HTML.
@see #text()
@see #outerHtml()
|
[
"Get",
"the",
"combined",
"inner",
"HTML",
"of",
"all",
"matched",
"elements",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L254-L262
|
13,991
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.is
|
public boolean is(String query) {
Evaluator eval = QueryParser.parse(query);
for (Element e : this) {
if (e.is(eval))
return true;
}
return false;
}
|
java
|
public boolean is(String query) {
Evaluator eval = QueryParser.parse(query);
for (Element e : this) {
if (e.is(eval))
return true;
}
return false;
}
|
[
"public",
"boolean",
"is",
"(",
"String",
"query",
")",
"{",
"Evaluator",
"eval",
"=",
"QueryParser",
".",
"parse",
"(",
"query",
")",
";",
"for",
"(",
"Element",
"e",
":",
"this",
")",
"{",
"if",
"(",
"e",
".",
"is",
"(",
"eval",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Test if any of the matched elements match the supplied query.
@param query A selector
@return true if at least one element in the list matches the query.
|
[
"Test",
"if",
"any",
"of",
"the",
"matched",
"elements",
"match",
"the",
"supplied",
"query",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L487-L494
|
13,992
|
jhy/jsoup
|
src/main/java/org/jsoup/select/Elements.java
|
Elements.parents
|
public Elements parents() {
HashSet<Element> combo = new LinkedHashSet<>();
for (Element e: this) {
combo.addAll(e.parents());
}
return new Elements(combo);
}
|
java
|
public Elements parents() {
HashSet<Element> combo = new LinkedHashSet<>();
for (Element e: this) {
combo.addAll(e.parents());
}
return new Elements(combo);
}
|
[
"public",
"Elements",
"parents",
"(",
")",
"{",
"HashSet",
"<",
"Element",
">",
"combo",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"for",
"(",
"Element",
"e",
":",
"this",
")",
"{",
"combo",
".",
"addAll",
"(",
"e",
".",
"parents",
"(",
")",
")",
";",
"}",
"return",
"new",
"Elements",
"(",
"combo",
")",
";",
"}"
] |
Get all of the parents and ancestor elements of the matched elements.
@return all of the parents and ancestor elements of the matched elements
|
[
"Get",
"all",
"of",
"the",
"parents",
"and",
"ancestor",
"elements",
"of",
"the",
"matched",
"elements",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/select/Elements.java#L585-L591
|
13,993
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.appendChild
|
public Element appendChild(Node child) {
Validate.notNull(child);
// was - Node#addChildren(child). short-circuits an array create and a loop.
reparentChild(child);
ensureChildNodes();
childNodes.add(child);
child.setSiblingIndex(childNodes.size() - 1);
return this;
}
|
java
|
public Element appendChild(Node child) {
Validate.notNull(child);
// was - Node#addChildren(child). short-circuits an array create and a loop.
reparentChild(child);
ensureChildNodes();
childNodes.add(child);
child.setSiblingIndex(childNodes.size() - 1);
return this;
}
|
[
"public",
"Element",
"appendChild",
"(",
"Node",
"child",
")",
"{",
"Validate",
".",
"notNull",
"(",
"child",
")",
";",
"// was - Node#addChildren(child). short-circuits an array create and a loop.",
"reparentChild",
"(",
"child",
")",
";",
"ensureChildNodes",
"(",
")",
";",
"childNodes",
".",
"add",
"(",
"child",
")",
";",
"child",
".",
"setSiblingIndex",
"(",
"childNodes",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"return",
"this",
";",
"}"
] |
Add a node child node to this element.
@param child node to add.
@return this element, so that you can add more child nodes or elements.
|
[
"Add",
"a",
"node",
"child",
"node",
"to",
"this",
"element",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L410-L419
|
13,994
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.appendElement
|
public Element appendElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName, NodeUtils.parser(this).settings()), baseUri());
appendChild(child);
return child;
}
|
java
|
public Element appendElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName, NodeUtils.parser(this).settings()), baseUri());
appendChild(child);
return child;
}
|
[
"public",
"Element",
"appendElement",
"(",
"String",
"tagName",
")",
"{",
"Element",
"child",
"=",
"new",
"Element",
"(",
"Tag",
".",
"valueOf",
"(",
"tagName",
",",
"NodeUtils",
".",
"parser",
"(",
"this",
")",
".",
"settings",
"(",
")",
")",
",",
"baseUri",
"(",
")",
")",
";",
"appendChild",
"(",
"child",
")",
";",
"return",
"child",
";",
"}"
] |
Create a new element by tag name, and add it as the last child.
@param tagName the name of the tag (e.g. {@code div}).
@return the new element, to allow you to add content to it, e.g.:
{@code parent.appendElement("h1").attr("id", "header").text("Welcome");}
|
[
"Create",
"a",
"new",
"element",
"by",
"tag",
"name",
"and",
"add",
"it",
"as",
"the",
"last",
"child",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L494-L498
|
13,995
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.prependElement
|
public Element prependElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName, NodeUtils.parser(this).settings()), baseUri());
prependChild(child);
return child;
}
|
java
|
public Element prependElement(String tagName) {
Element child = new Element(Tag.valueOf(tagName, NodeUtils.parser(this).settings()), baseUri());
prependChild(child);
return child;
}
|
[
"public",
"Element",
"prependElement",
"(",
"String",
"tagName",
")",
"{",
"Element",
"child",
"=",
"new",
"Element",
"(",
"Tag",
".",
"valueOf",
"(",
"tagName",
",",
"NodeUtils",
".",
"parser",
"(",
"this",
")",
".",
"settings",
"(",
")",
")",
",",
"baseUri",
"(",
")",
")",
";",
"prependChild",
"(",
"child",
")",
";",
"return",
"child",
";",
"}"
] |
Create a new element by tag name, and add it as the first child.
@param tagName the name of the tag (e.g. {@code div}).
@return the new element, to allow you to add content to it, e.g.:
{@code parent.prependElement("h1").attr("id", "header").text("Welcome");}
|
[
"Create",
"a",
"new",
"element",
"by",
"tag",
"name",
"and",
"add",
"it",
"as",
"the",
"first",
"child",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L507-L511
|
13,996
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.appendText
|
public Element appendText(String text) {
Validate.notNull(text);
TextNode node = new TextNode(text);
appendChild(node);
return this;
}
|
java
|
public Element appendText(String text) {
Validate.notNull(text);
TextNode node = new TextNode(text);
appendChild(node);
return this;
}
|
[
"public",
"Element",
"appendText",
"(",
"String",
"text",
")",
"{",
"Validate",
".",
"notNull",
"(",
"text",
")",
";",
"TextNode",
"node",
"=",
"new",
"TextNode",
"(",
"text",
")",
";",
"appendChild",
"(",
"node",
")",
";",
"return",
"this",
";",
"}"
] |
Create and append a new TextNode to this element.
@param text the unencoded text to add
@return this element
|
[
"Create",
"and",
"append",
"a",
"new",
"TextNode",
"to",
"this",
"element",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L519-L524
|
13,997
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.prependText
|
public Element prependText(String text) {
Validate.notNull(text);
TextNode node = new TextNode(text);
prependChild(node);
return this;
}
|
java
|
public Element prependText(String text) {
Validate.notNull(text);
TextNode node = new TextNode(text);
prependChild(node);
return this;
}
|
[
"public",
"Element",
"prependText",
"(",
"String",
"text",
")",
"{",
"Validate",
".",
"notNull",
"(",
"text",
")",
";",
"TextNode",
"node",
"=",
"new",
"TextNode",
"(",
"text",
")",
";",
"prependChild",
"(",
"node",
")",
";",
"return",
"this",
";",
"}"
] |
Create and prepend a new TextNode to this element.
@param text the unencoded text to add
@return this element
|
[
"Create",
"and",
"prepend",
"a",
"new",
"TextNode",
"to",
"this",
"element",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L532-L537
|
13,998
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.prepend
|
public Element prepend(String html) {
Validate.notNull(html);
List<Node> nodes = NodeUtils.parser(this).parseFragmentInput(html, this, baseUri());
addChildren(0, nodes.toArray(new Node[0]));
return this;
}
|
java
|
public Element prepend(String html) {
Validate.notNull(html);
List<Node> nodes = NodeUtils.parser(this).parseFragmentInput(html, this, baseUri());
addChildren(0, nodes.toArray(new Node[0]));
return this;
}
|
[
"public",
"Element",
"prepend",
"(",
"String",
"html",
")",
"{",
"Validate",
".",
"notNull",
"(",
"html",
")",
";",
"List",
"<",
"Node",
">",
"nodes",
"=",
"NodeUtils",
".",
"parser",
"(",
"this",
")",
".",
"parseFragmentInput",
"(",
"html",
",",
"this",
",",
"baseUri",
"(",
")",
")",
";",
"addChildren",
"(",
"0",
",",
"nodes",
".",
"toArray",
"(",
"new",
"Node",
"[",
"0",
"]",
")",
")",
";",
"return",
"this",
";",
"}"
] |
Add inner HTML into this element. The supplied HTML will be parsed, and each node prepended to the start of the element's children.
@param html HTML to add inside this element, before the existing HTML
@return this element
@see #html(String)
|
[
"Add",
"inner",
"HTML",
"into",
"this",
"element",
".",
"The",
"supplied",
"HTML",
"will",
"be",
"parsed",
"and",
"each",
"node",
"prepended",
"to",
"the",
"start",
"of",
"the",
"element",
"s",
"children",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L558-L563
|
13,999
|
jhy/jsoup
|
src/main/java/org/jsoup/nodes/Element.java
|
Element.siblingElements
|
public Elements siblingElements() {
if (parentNode == null)
return new Elements(0);
List<Element> elements = parent().childElementsList();
Elements siblings = new Elements(elements.size() - 1);
for (Element el: elements)
if (el != this)
siblings.add(el);
return siblings;
}
|
java
|
public Elements siblingElements() {
if (parentNode == null)
return new Elements(0);
List<Element> elements = parent().childElementsList();
Elements siblings = new Elements(elements.size() - 1);
for (Element el: elements)
if (el != this)
siblings.add(el);
return siblings;
}
|
[
"public",
"Elements",
"siblingElements",
"(",
")",
"{",
"if",
"(",
"parentNode",
"==",
"null",
")",
"return",
"new",
"Elements",
"(",
"0",
")",
";",
"List",
"<",
"Element",
">",
"elements",
"=",
"parent",
"(",
")",
".",
"childElementsList",
"(",
")",
";",
"Elements",
"siblings",
"=",
"new",
"Elements",
"(",
"elements",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"for",
"(",
"Element",
"el",
":",
"elements",
")",
"if",
"(",
"el",
"!=",
"this",
")",
"siblings",
".",
"add",
"(",
"el",
")",
";",
"return",
"siblings",
";",
"}"
] |
Get sibling elements. If the element has no sibling elements, returns an empty list. An element is not a sibling
of itself, so will not be included in the returned list.
@return sibling elements
|
[
"Get",
"sibling",
"elements",
".",
"If",
"the",
"element",
"has",
"no",
"sibling",
"elements",
"returns",
"an",
"empty",
"list",
".",
"An",
"element",
"is",
"not",
"a",
"sibling",
"of",
"itself",
"so",
"will",
"not",
"be",
"included",
"in",
"the",
"returned",
"list",
"."
] |
68ff8cbe7ad847059737a09c567a501a7f1d251f
|
https://github.com/jhy/jsoup/blob/68ff8cbe7ad847059737a09c567a501a7f1d251f/src/main/java/org/jsoup/nodes/Element.java#L668-L678
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.