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,800
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.add
|
public void add(HttpMethod httpMethod, FilterImpl filter) {
add(httpMethod, filter.getPath() , filter.getAcceptType(), filter);
}
|
java
|
public void add(HttpMethod httpMethod, FilterImpl filter) {
add(httpMethod, filter.getPath() , filter.getAcceptType(), filter);
}
|
[
"public",
"void",
"add",
"(",
"HttpMethod",
"httpMethod",
",",
"FilterImpl",
"filter",
")",
"{",
"add",
"(",
"httpMethod",
",",
"filter",
".",
"getPath",
"(",
")",
",",
"filter",
".",
"getAcceptType",
"(",
")",
",",
"filter",
")",
";",
"}"
] |
Add a filter
@param httpMethod the http-method of the route
@param filter the filter to add
|
[
"Add",
"a",
"filter"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L71-L73
|
13,801
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.find
|
public RouteMatch find(HttpMethod httpMethod, String path, String acceptType) {
List<RouteEntry> routeEntries = this.findTargetsForRequestedRoute(httpMethod, path);
RouteEntry entry = findTargetWithGivenAcceptType(routeEntries, acceptType);
return entry != null ? new RouteMatch(entry.target, entry.path, path, acceptType) : null;
}
|
java
|
public RouteMatch find(HttpMethod httpMethod, String path, String acceptType) {
List<RouteEntry> routeEntries = this.findTargetsForRequestedRoute(httpMethod, path);
RouteEntry entry = findTargetWithGivenAcceptType(routeEntries, acceptType);
return entry != null ? new RouteMatch(entry.target, entry.path, path, acceptType) : null;
}
|
[
"public",
"RouteMatch",
"find",
"(",
"HttpMethod",
"httpMethod",
",",
"String",
"path",
",",
"String",
"acceptType",
")",
"{",
"List",
"<",
"RouteEntry",
">",
"routeEntries",
"=",
"this",
".",
"findTargetsForRequestedRoute",
"(",
"httpMethod",
",",
"path",
")",
";",
"RouteEntry",
"entry",
"=",
"findTargetWithGivenAcceptType",
"(",
"routeEntries",
",",
"acceptType",
")",
";",
"return",
"entry",
"!=",
"null",
"?",
"new",
"RouteMatch",
"(",
"entry",
".",
"target",
",",
"entry",
".",
"path",
",",
"path",
",",
"acceptType",
")",
":",
"null",
";",
"}"
] |
finds target for a requested route
@param httpMethod the http method
@param path the path
@param acceptType the accept type
@return the target
|
[
"finds",
"target",
"for",
"a",
"requested",
"route"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L83-L87
|
13,802
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.findMultiple
|
public List<RouteMatch> findMultiple(HttpMethod httpMethod, String path, String acceptType) {
List<RouteMatch> matchSet = new ArrayList<>();
List<RouteEntry> routeEntries = findTargetsForRequestedRoute(httpMethod, path);
for (RouteEntry routeEntry : routeEntries) {
if (acceptType != null) {
String bestMatch = MimeParse.bestMatch(Arrays.asList(routeEntry.acceptedType), acceptType);
if (routeWithGivenAcceptType(bestMatch)) {
matchSet.add(new RouteMatch(routeEntry.target, routeEntry.path, path, acceptType));
}
} else {
matchSet.add(new RouteMatch(routeEntry.target, routeEntry.path, path, acceptType));
}
}
return matchSet;
}
|
java
|
public List<RouteMatch> findMultiple(HttpMethod httpMethod, String path, String acceptType) {
List<RouteMatch> matchSet = new ArrayList<>();
List<RouteEntry> routeEntries = findTargetsForRequestedRoute(httpMethod, path);
for (RouteEntry routeEntry : routeEntries) {
if (acceptType != null) {
String bestMatch = MimeParse.bestMatch(Arrays.asList(routeEntry.acceptedType), acceptType);
if (routeWithGivenAcceptType(bestMatch)) {
matchSet.add(new RouteMatch(routeEntry.target, routeEntry.path, path, acceptType));
}
} else {
matchSet.add(new RouteMatch(routeEntry.target, routeEntry.path, path, acceptType));
}
}
return matchSet;
}
|
[
"public",
"List",
"<",
"RouteMatch",
">",
"findMultiple",
"(",
"HttpMethod",
"httpMethod",
",",
"String",
"path",
",",
"String",
"acceptType",
")",
"{",
"List",
"<",
"RouteMatch",
">",
"matchSet",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"List",
"<",
"RouteEntry",
">",
"routeEntries",
"=",
"findTargetsForRequestedRoute",
"(",
"httpMethod",
",",
"path",
")",
";",
"for",
"(",
"RouteEntry",
"routeEntry",
":",
"routeEntries",
")",
"{",
"if",
"(",
"acceptType",
"!=",
"null",
")",
"{",
"String",
"bestMatch",
"=",
"MimeParse",
".",
"bestMatch",
"(",
"Arrays",
".",
"asList",
"(",
"routeEntry",
".",
"acceptedType",
")",
",",
"acceptType",
")",
";",
"if",
"(",
"routeWithGivenAcceptType",
"(",
"bestMatch",
")",
")",
"{",
"matchSet",
".",
"add",
"(",
"new",
"RouteMatch",
"(",
"routeEntry",
".",
"target",
",",
"routeEntry",
".",
"path",
",",
"path",
",",
"acceptType",
")",
")",
";",
"}",
"}",
"else",
"{",
"matchSet",
".",
"add",
"(",
"new",
"RouteMatch",
"(",
"routeEntry",
".",
"target",
",",
"routeEntry",
".",
"path",
",",
"path",
",",
"acceptType",
")",
")",
";",
"}",
"}",
"return",
"matchSet",
";",
"}"
] |
Finds multiple targets for a requested route.
@param httpMethod the http method
@param path the route path
@param acceptType the accept type
@return the targets
|
[
"Finds",
"multiple",
"targets",
"for",
"a",
"requested",
"route",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L97-L114
|
13,803
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.remove
|
public boolean remove(String path, String httpMethod) {
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("path cannot be null or blank");
}
if (StringUtils.isEmpty(httpMethod)) {
throw new IllegalArgumentException("httpMethod cannot be null or blank");
}
// Catches invalid input and throws IllegalArgumentException
HttpMethod method = HttpMethod.valueOf(httpMethod);
return removeRoute(method, path);
}
|
java
|
public boolean remove(String path, String httpMethod) {
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("path cannot be null or blank");
}
if (StringUtils.isEmpty(httpMethod)) {
throw new IllegalArgumentException("httpMethod cannot be null or blank");
}
// Catches invalid input and throws IllegalArgumentException
HttpMethod method = HttpMethod.valueOf(httpMethod);
return removeRoute(method, path);
}
|
[
"public",
"boolean",
"remove",
"(",
"String",
"path",
",",
"String",
"httpMethod",
")",
"{",
"if",
"(",
"StringUtils",
".",
"isEmpty",
"(",
"path",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"path cannot be null or blank\"",
")",
";",
"}",
"if",
"(",
"StringUtils",
".",
"isEmpty",
"(",
"httpMethod",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"httpMethod cannot be null or blank\"",
")",
";",
"}",
"// Catches invalid input and throws IllegalArgumentException",
"HttpMethod",
"method",
"=",
"HttpMethod",
".",
"valueOf",
"(",
"httpMethod",
")",
";",
"return",
"removeRoute",
"(",
"method",
",",
"path",
")",
";",
"}"
] |
Removes a particular route from the collection of those that have been previously routed.
Search for a previously established routes using the given path and HTTP method, removing
any matches that are found.
@param path the route path
@param httpMethod the http method
@return <tt>true</tt> if this a matching route has been previously routed
@throws IllegalArgumentException if <tt>path</tt> is null or blank or if <tt>httpMethod</tt> is null, blank
or an invalid HTTP method
@since 2.2
|
[
"Removes",
"a",
"particular",
"route",
"from",
"the",
"collection",
"of",
"those",
"that",
"have",
"been",
"previously",
"routed",
".",
"Search",
"for",
"a",
"previously",
"established",
"routes",
"using",
"the",
"given",
"path",
"and",
"HTTP",
"method",
"removing",
"any",
"matches",
"that",
"are",
"found",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L135-L148
|
13,804
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.remove
|
public boolean remove(String path) {
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("path cannot be null or blank");
}
return removeRoute((HttpMethod) null, path);
}
|
java
|
public boolean remove(String path) {
if (StringUtils.isEmpty(path)) {
throw new IllegalArgumentException("path cannot be null or blank");
}
return removeRoute((HttpMethod) null, path);
}
|
[
"public",
"boolean",
"remove",
"(",
"String",
"path",
")",
"{",
"if",
"(",
"StringUtils",
".",
"isEmpty",
"(",
"path",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"path cannot be null or blank\"",
")",
";",
"}",
"return",
"removeRoute",
"(",
"(",
"HttpMethod",
")",
"null",
",",
"path",
")",
";",
"}"
] |
Removes a particular route from the collection of those that have been previously routed.
Search for a previously established routes using the given path and removes any matches that are found.
@param path the route path
@return <tt>true</tt> if this a matching route has been previously routed
@throws java.lang.IllegalArgumentException if <tt>path</tt> is null or blank
@since 2.2
|
[
"Removes",
"a",
"particular",
"route",
"from",
"the",
"collection",
"of",
"those",
"that",
"have",
"been",
"previously",
"routed",
".",
"Search",
"for",
"a",
"previously",
"established",
"routes",
"using",
"the",
"given",
"path",
"and",
"removes",
"any",
"matches",
"that",
"are",
"found",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L159-L165
|
13,805
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.getAcceptedMimeTypes
|
private Map<String, RouteEntry> getAcceptedMimeTypes(List<RouteEntry> routes) {
Map<String, RouteEntry> acceptedTypes = new HashMap<>();
for (RouteEntry routeEntry : routes) {
if (!acceptedTypes.containsKey(routeEntry.acceptedType)) {
acceptedTypes.put(routeEntry.acceptedType, routeEntry);
}
}
return acceptedTypes;
}
|
java
|
private Map<String, RouteEntry> getAcceptedMimeTypes(List<RouteEntry> routes) {
Map<String, RouteEntry> acceptedTypes = new HashMap<>();
for (RouteEntry routeEntry : routes) {
if (!acceptedTypes.containsKey(routeEntry.acceptedType)) {
acceptedTypes.put(routeEntry.acceptedType, routeEntry);
}
}
return acceptedTypes;
}
|
[
"private",
"Map",
"<",
"String",
",",
"RouteEntry",
">",
"getAcceptedMimeTypes",
"(",
"List",
"<",
"RouteEntry",
">",
"routes",
")",
"{",
"Map",
"<",
"String",
",",
"RouteEntry",
">",
"acceptedTypes",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"RouteEntry",
"routeEntry",
":",
"routes",
")",
"{",
"if",
"(",
"!",
"acceptedTypes",
".",
"containsKey",
"(",
"routeEntry",
".",
"acceptedType",
")",
")",
"{",
"acceptedTypes",
".",
"put",
"(",
"routeEntry",
".",
"acceptedType",
",",
"routeEntry",
")",
";",
"}",
"}",
"return",
"acceptedTypes",
";",
"}"
] |
can be cached? I don't think so.
|
[
"can",
"be",
"cached?",
"I",
"don",
"t",
"think",
"so",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L183-L193
|
13,806
|
perwendel/spark
|
src/main/java/spark/route/Routes.java
|
Routes.add
|
@Deprecated
public void add(String route, String acceptType, Object target) {
try {
int singleQuoteIndex = route.indexOf(SINGLE_QUOTE);
String httpMethod = route.substring(0, singleQuoteIndex).trim().toLowerCase(); // NOSONAR
String url = route.substring(singleQuoteIndex + 1, route.length() - 1).trim(); // NOSONAR
// Use special enum stuff to get from value
HttpMethod method;
try {
method = HttpMethod.valueOf(httpMethod);
} catch (IllegalArgumentException e) {
LOG.error("The @Route value: "
+ route
+ " has an invalid HTTP method part: "
+ httpMethod
+ ".");
return;
}
add(method, url, acceptType, target);
} catch (Exception e) {
LOG.error("The @Route value: " + route + " is not in the correct format", e);
}
}
|
java
|
@Deprecated
public void add(String route, String acceptType, Object target) {
try {
int singleQuoteIndex = route.indexOf(SINGLE_QUOTE);
String httpMethod = route.substring(0, singleQuoteIndex).trim().toLowerCase(); // NOSONAR
String url = route.substring(singleQuoteIndex + 1, route.length() - 1).trim(); // NOSONAR
// Use special enum stuff to get from value
HttpMethod method;
try {
method = HttpMethod.valueOf(httpMethod);
} catch (IllegalArgumentException e) {
LOG.error("The @Route value: "
+ route
+ " has an invalid HTTP method part: "
+ httpMethod
+ ".");
return;
}
add(method, url, acceptType, target);
} catch (Exception e) {
LOG.error("The @Route value: " + route + " is not in the correct format", e);
}
}
|
[
"@",
"Deprecated",
"public",
"void",
"add",
"(",
"String",
"route",
",",
"String",
"acceptType",
",",
"Object",
"target",
")",
"{",
"try",
"{",
"int",
"singleQuoteIndex",
"=",
"route",
".",
"indexOf",
"(",
"SINGLE_QUOTE",
")",
";",
"String",
"httpMethod",
"=",
"route",
".",
"substring",
"(",
"0",
",",
"singleQuoteIndex",
")",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"// NOSONAR",
"String",
"url",
"=",
"route",
".",
"substring",
"(",
"singleQuoteIndex",
"+",
"1",
",",
"route",
".",
"length",
"(",
")",
"-",
"1",
")",
".",
"trim",
"(",
")",
";",
"// NOSONAR",
"// Use special enum stuff to get from value",
"HttpMethod",
"method",
";",
"try",
"{",
"method",
"=",
"HttpMethod",
".",
"valueOf",
"(",
"httpMethod",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"The @Route value: \"",
"+",
"route",
"+",
"\" has an invalid HTTP method part: \"",
"+",
"httpMethod",
"+",
"\".\"",
")",
";",
"return",
";",
"}",
"add",
"(",
"method",
",",
"url",
",",
"acceptType",
",",
"target",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"The @Route value: \"",
"+",
"route",
"+",
"\" is not in the correct format\"",
",",
"e",
")",
";",
"}",
"}"
] |
Parse and validates a route and adds it
@param route the route path
@param acceptType the accept type
@param target the invocation target
|
[
"Parse",
"and",
"validates",
"a",
"route",
"and",
"adds",
"it"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/route/Routes.java#L257-L280
|
13,807
|
perwendel/spark
|
src/main/java/spark/Request.java
|
Request.queryParamOrDefault
|
public String queryParamOrDefault(String queryParam, String defaultValue) {
String value = queryParams(queryParam);
return value != null ? value : defaultValue;
}
|
java
|
public String queryParamOrDefault(String queryParam, String defaultValue) {
String value = queryParams(queryParam);
return value != null ? value : defaultValue;
}
|
[
"public",
"String",
"queryParamOrDefault",
"(",
"String",
"queryParam",
",",
"String",
"defaultValue",
")",
"{",
"String",
"value",
"=",
"queryParams",
"(",
"queryParam",
")",
";",
"return",
"value",
"!=",
"null",
"?",
"value",
":",
"defaultValue",
";",
"}"
] |
Gets the query param, or returns default value
@param queryParam the query parameter
@param defaultValue the default value
@return the value of the provided queryParam, or default if value is null
Example: query parameter 'id' from the following request URI: /hello?id=foo
|
[
"Gets",
"the",
"query",
"param",
"or",
"returns",
"default",
"value"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Request.java#L303-L306
|
13,808
|
perwendel/spark
|
src/main/java/spark/Request.java
|
Request.attribute
|
@SuppressWarnings("unchecked")
public <T> T attribute(String attribute) {
return (T) servletRequest.getAttribute(attribute);
}
|
java
|
@SuppressWarnings("unchecked")
public <T> T attribute(String attribute) {
return (T) servletRequest.getAttribute(attribute);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"attribute",
"(",
"String",
"attribute",
")",
"{",
"return",
"(",
"T",
")",
"servletRequest",
".",
"getAttribute",
"(",
"attribute",
")",
";",
"}"
] |
Gets the value of the provided attribute
@param attribute The attribute value or null if not present
@param <T> the type parameter.
@return the value for the provided attribute
|
[
"Gets",
"the",
"value",
"of",
"the",
"provided",
"attribute"
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Request.java#L374-L377
|
13,809
|
perwendel/spark
|
src/main/java/spark/Request.java
|
Request.session
|
public Session session() {
if (session == null || !validSession) {
validSession(true);
session = new Session(servletRequest.getSession(), this);
}
return session;
}
|
java
|
public Session session() {
if (session == null || !validSession) {
validSession(true);
session = new Session(servletRequest.getSession(), this);
}
return session;
}
|
[
"public",
"Session",
"session",
"(",
")",
"{",
"if",
"(",
"session",
"==",
"null",
"||",
"!",
"validSession",
")",
"{",
"validSession",
"(",
"true",
")",
";",
"session",
"=",
"new",
"Session",
"(",
"servletRequest",
".",
"getSession",
"(",
")",
",",
"this",
")",
";",
"}",
"return",
"session",
";",
"}"
] |
Returns the current session associated with this request,
or if the request does not have a session, creates one.
@return the session associated with this request
|
[
"Returns",
"the",
"current",
"session",
"associated",
"with",
"this",
"request",
"or",
"if",
"the",
"request",
"does",
"not",
"have",
"a",
"session",
"creates",
"one",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Request.java#L428-L434
|
13,810
|
perwendel/spark
|
src/main/java/spark/Request.java
|
Request.cookie
|
public String cookie(String name) {
Cookie[] cookies = servletRequest.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
return cookie.getValue();
}
}
}
return null;
}
|
java
|
public String cookie(String name) {
Cookie[] cookies = servletRequest.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
return cookie.getValue();
}
}
}
return null;
}
|
[
"public",
"String",
"cookie",
"(",
"String",
"name",
")",
"{",
"Cookie",
"[",
"]",
"cookies",
"=",
"servletRequest",
".",
"getCookies",
"(",
")",
";",
"if",
"(",
"cookies",
"!=",
"null",
")",
"{",
"for",
"(",
"Cookie",
"cookie",
":",
"cookies",
")",
"{",
"if",
"(",
"cookie",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"return",
"cookie",
".",
"getValue",
"(",
")",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Gets cookie by name.
@param name name of the cookie
@return cookie value or null if the cookie was not found
|
[
"Gets",
"cookie",
"by",
"name",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/Request.java#L478-L488
|
13,811
|
perwendel/spark
|
src/main/java/spark/embeddedserver/jetty/SocketConnectorFactory.java
|
SocketConnectorFactory.createSocketConnector
|
public static ServerConnector createSocketConnector(Server server, String host, int port) {
Assert.notNull(server, "'server' must not be null");
Assert.notNull(host, "'host' must not be null");
HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory();
ServerConnector connector = new ServerConnector(server, httpConnectionFactory);
initializeConnector(connector, host, port);
return connector;
}
|
java
|
public static ServerConnector createSocketConnector(Server server, String host, int port) {
Assert.notNull(server, "'server' must not be null");
Assert.notNull(host, "'host' must not be null");
HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory();
ServerConnector connector = new ServerConnector(server, httpConnectionFactory);
initializeConnector(connector, host, port);
return connector;
}
|
[
"public",
"static",
"ServerConnector",
"createSocketConnector",
"(",
"Server",
"server",
",",
"String",
"host",
",",
"int",
"port",
")",
"{",
"Assert",
".",
"notNull",
"(",
"server",
",",
"\"'server' must not be null\"",
")",
";",
"Assert",
".",
"notNull",
"(",
"host",
",",
"\"'host' must not be null\"",
")",
";",
"HttpConnectionFactory",
"httpConnectionFactory",
"=",
"createHttpConnectionFactory",
"(",
")",
";",
"ServerConnector",
"connector",
"=",
"new",
"ServerConnector",
"(",
"server",
",",
"httpConnectionFactory",
")",
";",
"initializeConnector",
"(",
"connector",
",",
"host",
",",
"port",
")",
";",
"return",
"connector",
";",
"}"
] |
Creates an ordinary, non-secured Jetty server jetty.
@param server Jetty server
@param host host
@param port port
@return - a server jetty
|
[
"Creates",
"an",
"ordinary",
"non",
"-",
"secured",
"Jetty",
"server",
"jetty",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/jetty/SocketConnectorFactory.java#L44-L52
|
13,812
|
perwendel/spark
|
src/main/java/spark/embeddedserver/jetty/SocketConnectorFactory.java
|
SocketConnectorFactory.createSecureSocketConnector
|
public static ServerConnector createSecureSocketConnector(Server server,
String host,
int port,
SslStores sslStores) {
Assert.notNull(server, "'server' must not be null");
Assert.notNull(host, "'host' must not be null");
Assert.notNull(sslStores, "'sslStores' must not be null");
SslContextFactory sslContextFactory = new SslContextFactory(sslStores.keystoreFile());
if (sslStores.keystorePassword() != null) {
sslContextFactory.setKeyStorePassword(sslStores.keystorePassword());
}
if (sslStores.certAlias() != null) {
sslContextFactory.setCertAlias(sslStores.certAlias());
}
if (sslStores.trustStoreFile() != null) {
sslContextFactory.setTrustStorePath(sslStores.trustStoreFile());
}
if (sslStores.trustStorePassword() != null) {
sslContextFactory.setTrustStorePassword(sslStores.trustStorePassword());
}
if (sslStores.needsClientCert()) {
sslContextFactory.setNeedClientAuth(true);
sslContextFactory.setWantClientAuth(true);
}
HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory();
ServerConnector connector = new ServerConnector(server, sslContextFactory, httpConnectionFactory);
initializeConnector(connector, host, port);
return connector;
}
|
java
|
public static ServerConnector createSecureSocketConnector(Server server,
String host,
int port,
SslStores sslStores) {
Assert.notNull(server, "'server' must not be null");
Assert.notNull(host, "'host' must not be null");
Assert.notNull(sslStores, "'sslStores' must not be null");
SslContextFactory sslContextFactory = new SslContextFactory(sslStores.keystoreFile());
if (sslStores.keystorePassword() != null) {
sslContextFactory.setKeyStorePassword(sslStores.keystorePassword());
}
if (sslStores.certAlias() != null) {
sslContextFactory.setCertAlias(sslStores.certAlias());
}
if (sslStores.trustStoreFile() != null) {
sslContextFactory.setTrustStorePath(sslStores.trustStoreFile());
}
if (sslStores.trustStorePassword() != null) {
sslContextFactory.setTrustStorePassword(sslStores.trustStorePassword());
}
if (sslStores.needsClientCert()) {
sslContextFactory.setNeedClientAuth(true);
sslContextFactory.setWantClientAuth(true);
}
HttpConnectionFactory httpConnectionFactory = createHttpConnectionFactory();
ServerConnector connector = new ServerConnector(server, sslContextFactory, httpConnectionFactory);
initializeConnector(connector, host, port);
return connector;
}
|
[
"public",
"static",
"ServerConnector",
"createSecureSocketConnector",
"(",
"Server",
"server",
",",
"String",
"host",
",",
"int",
"port",
",",
"SslStores",
"sslStores",
")",
"{",
"Assert",
".",
"notNull",
"(",
"server",
",",
"\"'server' must not be null\"",
")",
";",
"Assert",
".",
"notNull",
"(",
"host",
",",
"\"'host' must not be null\"",
")",
";",
"Assert",
".",
"notNull",
"(",
"sslStores",
",",
"\"'sslStores' must not be null\"",
")",
";",
"SslContextFactory",
"sslContextFactory",
"=",
"new",
"SslContextFactory",
"(",
"sslStores",
".",
"keystoreFile",
"(",
")",
")",
";",
"if",
"(",
"sslStores",
".",
"keystorePassword",
"(",
")",
"!=",
"null",
")",
"{",
"sslContextFactory",
".",
"setKeyStorePassword",
"(",
"sslStores",
".",
"keystorePassword",
"(",
")",
")",
";",
"}",
"if",
"(",
"sslStores",
".",
"certAlias",
"(",
")",
"!=",
"null",
")",
"{",
"sslContextFactory",
".",
"setCertAlias",
"(",
"sslStores",
".",
"certAlias",
"(",
")",
")",
";",
"}",
"if",
"(",
"sslStores",
".",
"trustStoreFile",
"(",
")",
"!=",
"null",
")",
"{",
"sslContextFactory",
".",
"setTrustStorePath",
"(",
"sslStores",
".",
"trustStoreFile",
"(",
")",
")",
";",
"}",
"if",
"(",
"sslStores",
".",
"trustStorePassword",
"(",
")",
"!=",
"null",
")",
"{",
"sslContextFactory",
".",
"setTrustStorePassword",
"(",
"sslStores",
".",
"trustStorePassword",
"(",
")",
")",
";",
"}",
"if",
"(",
"sslStores",
".",
"needsClientCert",
"(",
")",
")",
"{",
"sslContextFactory",
".",
"setNeedClientAuth",
"(",
"true",
")",
";",
"sslContextFactory",
".",
"setWantClientAuth",
"(",
"true",
")",
";",
"}",
"HttpConnectionFactory",
"httpConnectionFactory",
"=",
"createHttpConnectionFactory",
"(",
")",
";",
"ServerConnector",
"connector",
"=",
"new",
"ServerConnector",
"(",
"server",
",",
"sslContextFactory",
",",
"httpConnectionFactory",
")",
";",
"initializeConnector",
"(",
"connector",
",",
"host",
",",
"port",
")",
";",
"return",
"connector",
";",
"}"
] |
Creates a ssl jetty socket jetty. Keystore required, truststore
optional. If truststore not specified keystore will be reused.
@param server Jetty server
@param sslStores the security sslStores.
@param host host
@param port port
@return a ssl socket jetty
|
[
"Creates",
"a",
"ssl",
"jetty",
"socket",
"jetty",
".",
"Keystore",
"required",
"truststore",
"optional",
".",
"If",
"truststore",
"not",
"specified",
"keystore",
"will",
"be",
"reused",
"."
] |
080fb1f9d6e580f6742e9589044c7420d3157b8b
|
https://github.com/perwendel/spark/blob/080fb1f9d6e580f6742e9589044c7420d3157b8b/src/main/java/spark/embeddedserver/jetty/SocketConnectorFactory.java#L64-L100
|
13,813
|
NLPchina/ansj_seg
|
plugin/ansj_lucene4_plugin/src/main/java/org/ansj/lucene/util/PorterStemmer.java
|
PorterStemmer.stem
|
public String stem(String s) {
if (stem(s.toCharArray(), s.length()))
return toString();
else
return s;
}
|
java
|
public String stem(String s) {
if (stem(s.toCharArray(), s.length()))
return toString();
else
return s;
}
|
[
"public",
"String",
"stem",
"(",
"String",
"s",
")",
"{",
"if",
"(",
"stem",
"(",
"s",
".",
"toCharArray",
"(",
")",
",",
"s",
".",
"length",
"(",
")",
")",
")",
"return",
"toString",
"(",
")",
";",
"else",
"return",
"s",
";",
"}"
] |
Stem a word provided as a String. Returns the result as a String.
|
[
"Stem",
"a",
"word",
"provided",
"as",
"a",
"String",
".",
"Returns",
"the",
"result",
"as",
"a",
"String",
"."
] |
1addfa08c9dc86872fcdb06c7f0955dd5d197585
|
https://github.com/NLPchina/ansj_seg/blob/1addfa08c9dc86872fcdb06c7f0955dd5d197585/plugin/ansj_lucene4_plugin/src/main/java/org/ansj/lucene/util/PorterStemmer.java#L509-L514
|
13,814
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
|
JsonPath.set
|
public <T> T set(Object jsonObject, Object newVal, Configuration configuration) {
notNull(jsonObject, "json can not be null");
notNull(configuration, "configuration can not be null");
EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true);
for (PathRef updateOperation : evaluationContext.updateOperations()) {
updateOperation.set(newVal, configuration);
}
return resultByConfiguration(jsonObject, configuration, evaluationContext);
}
|
java
|
public <T> T set(Object jsonObject, Object newVal, Configuration configuration) {
notNull(jsonObject, "json can not be null");
notNull(configuration, "configuration can not be null");
EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true);
for (PathRef updateOperation : evaluationContext.updateOperations()) {
updateOperation.set(newVal, configuration);
}
return resultByConfiguration(jsonObject, configuration, evaluationContext);
}
|
[
"public",
"<",
"T",
">",
"T",
"set",
"(",
"Object",
"jsonObject",
",",
"Object",
"newVal",
",",
"Configuration",
"configuration",
")",
"{",
"notNull",
"(",
"jsonObject",
",",
"\"json can not be null\"",
")",
";",
"notNull",
"(",
"configuration",
",",
"\"configuration can not be null\"",
")",
";",
"EvaluationContext",
"evaluationContext",
"=",
"path",
".",
"evaluate",
"(",
"jsonObject",
",",
"jsonObject",
",",
"configuration",
",",
"true",
")",
";",
"for",
"(",
"PathRef",
"updateOperation",
":",
"evaluationContext",
".",
"updateOperations",
"(",
")",
")",
"{",
"updateOperation",
".",
"set",
"(",
"newVal",
",",
"configuration",
")",
";",
"}",
"return",
"resultByConfiguration",
"(",
"jsonObject",
",",
"configuration",
",",
"evaluationContext",
")",
";",
"}"
] |
Set the value this path points to in the provided jsonObject
@param jsonObject a json object
@param configuration configuration to use
@param <T> expected return type
@return the updated jsonObject or the path list to updated objects if option AS_PATH_LIST is set.
|
[
"Set",
"the",
"value",
"this",
"path",
"points",
"to",
"in",
"the",
"provided",
"jsonObject"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L217-L225
|
13,815
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
|
JsonPath.put
|
public <T> T put(Object jsonObject, String key, Object value, Configuration configuration) {
notNull(jsonObject, "json can not be null");
notEmpty(key, "key can not be null or empty");
notNull(configuration, "configuration can not be null");
EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true);
for (PathRef updateOperation : evaluationContext.updateOperations()) {
updateOperation.put(key, value, configuration);
}
return resultByConfiguration(jsonObject, configuration, evaluationContext);
}
|
java
|
public <T> T put(Object jsonObject, String key, Object value, Configuration configuration) {
notNull(jsonObject, "json can not be null");
notEmpty(key, "key can not be null or empty");
notNull(configuration, "configuration can not be null");
EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration, true);
for (PathRef updateOperation : evaluationContext.updateOperations()) {
updateOperation.put(key, value, configuration);
}
return resultByConfiguration(jsonObject, configuration, evaluationContext);
}
|
[
"public",
"<",
"T",
">",
"T",
"put",
"(",
"Object",
"jsonObject",
",",
"String",
"key",
",",
"Object",
"value",
",",
"Configuration",
"configuration",
")",
"{",
"notNull",
"(",
"jsonObject",
",",
"\"json can not be null\"",
")",
";",
"notEmpty",
"(",
"key",
",",
"\"key can not be null or empty\"",
")",
";",
"notNull",
"(",
"configuration",
",",
"\"configuration can not be null\"",
")",
";",
"EvaluationContext",
"evaluationContext",
"=",
"path",
".",
"evaluate",
"(",
"jsonObject",
",",
"jsonObject",
",",
"configuration",
",",
"true",
")",
";",
"for",
"(",
"PathRef",
"updateOperation",
":",
"evaluationContext",
".",
"updateOperations",
"(",
")",
")",
"{",
"updateOperation",
".",
"put",
"(",
"key",
",",
"value",
",",
"configuration",
")",
";",
"}",
"return",
"resultByConfiguration",
"(",
"jsonObject",
",",
"configuration",
",",
"evaluationContext",
")",
";",
"}"
] |
Adds or updates the Object this path points to in the provided jsonObject with a key with a value
@param jsonObject a json object
@param key the key to add or update
@param value the new value
@param configuration configuration to use
@param <T> expected return type
@return the updated jsonObject or the path list to updated objects if option AS_PATH_LIST is set.
|
[
"Adds",
"or",
"updates",
"the",
"Object",
"this",
"path",
"points",
"to",
"in",
"the",
"provided",
"jsonObject",
"with",
"a",
"key",
"with",
"a",
"value"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L294-L303
|
13,816
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
|
JsonPath.read
|
@SuppressWarnings({"unchecked"})
public <T> T read(URL jsonURL) throws IOException {
return read(jsonURL, Configuration.defaultConfiguration());
}
|
java
|
@SuppressWarnings({"unchecked"})
public <T> T read(URL jsonURL) throws IOException {
return read(jsonURL, Configuration.defaultConfiguration());
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
"}",
")",
"public",
"<",
"T",
">",
"T",
"read",
"(",
"URL",
"jsonURL",
")",
"throws",
"IOException",
"{",
"return",
"read",
"(",
"jsonURL",
",",
"Configuration",
".",
"defaultConfiguration",
"(",
")",
")",
";",
"}"
] |
Applies this JsonPath to the provided json URL
@param jsonURL url to read from
@param <T> expected return type
@return list of objects matched by the given path
@throws IOException
|
[
"Applies",
"this",
"JsonPath",
"to",
"the",
"provided",
"json",
"URL"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L352-L355
|
13,817
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
|
JsonPath.compile
|
public static JsonPath compile(String jsonPath, Predicate... filters) {
notEmpty(jsonPath, "json can not be null or empty");
return new JsonPath(jsonPath, filters);
}
|
java
|
public static JsonPath compile(String jsonPath, Predicate... filters) {
notEmpty(jsonPath, "json can not be null or empty");
return new JsonPath(jsonPath, filters);
}
|
[
"public",
"static",
"JsonPath",
"compile",
"(",
"String",
"jsonPath",
",",
"Predicate",
"...",
"filters",
")",
"{",
"notEmpty",
"(",
"jsonPath",
",",
"\"json can not be null or empty\"",
")",
";",
"return",
"new",
"JsonPath",
"(",
"jsonPath",
",",
"filters",
")",
";",
"}"
] |
Compiles a JsonPath
@param jsonPath to compile
@param filters filters to be applied to the filter place holders [?] in the path
@return compiled JsonPath
|
[
"Compiles",
"a",
"JsonPath"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L460-L464
|
13,818
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
|
JsonPath.read
|
@SuppressWarnings({"unchecked"})
public static <T> T read(String json, String jsonPath, Predicate... filters) {
return new ParseContextImpl().parse(json).read(jsonPath, filters);
}
|
java
|
@SuppressWarnings({"unchecked"})
public static <T> T read(String json, String jsonPath, Predicate... filters) {
return new ParseContextImpl().parse(json).read(jsonPath, filters);
}
|
[
"@",
"SuppressWarnings",
"(",
"{",
"\"unchecked\"",
"}",
")",
"public",
"static",
"<",
"T",
">",
"T",
"read",
"(",
"String",
"json",
",",
"String",
"jsonPath",
",",
"Predicate",
"...",
"filters",
")",
"{",
"return",
"new",
"ParseContextImpl",
"(",
")",
".",
"parse",
"(",
"json",
")",
".",
"read",
"(",
"jsonPath",
",",
"filters",
")",
";",
"}"
] |
Creates a new JsonPath and applies it to the provided Json string
@param json a json string
@param jsonPath the json path
@param filters filters to be applied to the filter place holders [?] in the path
@param <T> expected return type
@return list of objects matched by the given path
|
[
"Creates",
"a",
"new",
"JsonPath",
"and",
"applies",
"it",
"to",
"the",
"provided",
"Json",
"string"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L496-L499
|
13,819
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/internal/path/CompiledPath.java
|
CompiledPath.invertScannerFunctionRelationship
|
private RootPathToken invertScannerFunctionRelationship(final RootPathToken path) {
if (path.isFunctionPath() && path.next() instanceof ScanPathToken) {
PathToken token = path;
PathToken prior = null;
while (null != (token = token.next()) && !(token instanceof FunctionPathToken)) {
prior = token;
}
// Invert the relationship $..path.function() to $.function($..path)
if (token instanceof FunctionPathToken) {
prior.setNext(null);
path.setTail(prior);
// Now generate a new parameter from our path
Parameter parameter = new Parameter();
parameter.setPath(new CompiledPath(path, true));
parameter.setType(ParamType.PATH);
((FunctionPathToken)token).setParameters(Arrays.asList(parameter));
RootPathToken functionRoot = new RootPathToken('$');
functionRoot.setTail(token);
functionRoot.setNext(token);
// Define the function as the root
return functionRoot;
}
}
return path;
}
|
java
|
private RootPathToken invertScannerFunctionRelationship(final RootPathToken path) {
if (path.isFunctionPath() && path.next() instanceof ScanPathToken) {
PathToken token = path;
PathToken prior = null;
while (null != (token = token.next()) && !(token instanceof FunctionPathToken)) {
prior = token;
}
// Invert the relationship $..path.function() to $.function($..path)
if (token instanceof FunctionPathToken) {
prior.setNext(null);
path.setTail(prior);
// Now generate a new parameter from our path
Parameter parameter = new Parameter();
parameter.setPath(new CompiledPath(path, true));
parameter.setType(ParamType.PATH);
((FunctionPathToken)token).setParameters(Arrays.asList(parameter));
RootPathToken functionRoot = new RootPathToken('$');
functionRoot.setTail(token);
functionRoot.setNext(token);
// Define the function as the root
return functionRoot;
}
}
return path;
}
|
[
"private",
"RootPathToken",
"invertScannerFunctionRelationship",
"(",
"final",
"RootPathToken",
"path",
")",
"{",
"if",
"(",
"path",
".",
"isFunctionPath",
"(",
")",
"&&",
"path",
".",
"next",
"(",
")",
"instanceof",
"ScanPathToken",
")",
"{",
"PathToken",
"token",
"=",
"path",
";",
"PathToken",
"prior",
"=",
"null",
";",
"while",
"(",
"null",
"!=",
"(",
"token",
"=",
"token",
".",
"next",
"(",
")",
")",
"&&",
"!",
"(",
"token",
"instanceof",
"FunctionPathToken",
")",
")",
"{",
"prior",
"=",
"token",
";",
"}",
"// Invert the relationship $..path.function() to $.function($..path)",
"if",
"(",
"token",
"instanceof",
"FunctionPathToken",
")",
"{",
"prior",
".",
"setNext",
"(",
"null",
")",
";",
"path",
".",
"setTail",
"(",
"prior",
")",
";",
"// Now generate a new parameter from our path",
"Parameter",
"parameter",
"=",
"new",
"Parameter",
"(",
")",
";",
"parameter",
".",
"setPath",
"(",
"new",
"CompiledPath",
"(",
"path",
",",
"true",
")",
")",
";",
"parameter",
".",
"setType",
"(",
"ParamType",
".",
"PATH",
")",
";",
"(",
"(",
"FunctionPathToken",
")",
"token",
")",
".",
"setParameters",
"(",
"Arrays",
".",
"asList",
"(",
"parameter",
")",
")",
";",
"RootPathToken",
"functionRoot",
"=",
"new",
"RootPathToken",
"(",
"'",
"'",
")",
";",
"functionRoot",
".",
"setTail",
"(",
"token",
")",
";",
"functionRoot",
".",
"setNext",
"(",
"token",
")",
";",
"// Define the function as the root",
"return",
"functionRoot",
";",
"}",
"}",
"return",
"path",
";",
"}"
] |
In the event the writer of the path referenced a function at the tail end of a scanner, augment the query such
that the root node is the function and the parameter to the function is the scanner. This way we maintain
relative sanity in the path expression, functions either evaluate scalar values or arrays, they're
not re-entrant nor should they maintain state, they do however take parameters.
@param path
this is our old root path which will become a parameter (assuming there's a scanner terminated by a function
@return
A function with the scanner as input, or if this situation doesn't exist just the input path
|
[
"In",
"the",
"event",
"the",
"writer",
"of",
"the",
"path",
"referenced",
"a",
"function",
"at",
"the",
"tail",
"end",
"of",
"a",
"scanner",
"augment",
"the",
"query",
"such",
"that",
"the",
"root",
"node",
"is",
"the",
"function",
"and",
"the",
"parameter",
"to",
"the",
"function",
"is",
"the",
"scanner",
".",
"This",
"way",
"we",
"maintain",
"relative",
"sanity",
"in",
"the",
"path",
"expression",
"functions",
"either",
"evaluate",
"scalar",
"values",
"or",
"arrays",
"they",
"re",
"not",
"re",
"-",
"entrant",
"nor",
"should",
"they",
"maintain",
"state",
"they",
"do",
"however",
"take",
"parameters",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/internal/path/CompiledPath.java#L62-L88
|
13,820
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayPathToken.java
|
ArrayPathToken.checkArrayModel
|
protected boolean checkArrayModel(String currentPath, Object model, EvaluationContextImpl ctx) {
if (model == null){
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException("The path " + currentPath + " is null");
}
}
if (!ctx.jsonProvider().isArray(model)) {
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException(format("Filter: %s can only be applied to arrays. Current context is: %s", toString(), model));
}
}
return true;
}
|
java
|
protected boolean checkArrayModel(String currentPath, Object model, EvaluationContextImpl ctx) {
if (model == null){
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException("The path " + currentPath + " is null");
}
}
if (!ctx.jsonProvider().isArray(model)) {
if (! isUpstreamDefinite()) {
return false;
} else {
throw new PathNotFoundException(format("Filter: %s can only be applied to arrays. Current context is: %s", toString(), model));
}
}
return true;
}
|
[
"protected",
"boolean",
"checkArrayModel",
"(",
"String",
"currentPath",
",",
"Object",
"model",
",",
"EvaluationContextImpl",
"ctx",
")",
"{",
"if",
"(",
"model",
"==",
"null",
")",
"{",
"if",
"(",
"!",
"isUpstreamDefinite",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"PathNotFoundException",
"(",
"\"The path \"",
"+",
"currentPath",
"+",
"\" is null\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"ctx",
".",
"jsonProvider",
"(",
")",
".",
"isArray",
"(",
"model",
")",
")",
"{",
"if",
"(",
"!",
"isUpstreamDefinite",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"PathNotFoundException",
"(",
"format",
"(",
"\"Filter: %s can only be applied to arrays. Current context is: %s\"",
",",
"toString",
"(",
")",
",",
"model",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Check if model is non-null and array.
@param currentPath
@param model
@param ctx
@return false if current evaluation call must be skipped, true otherwise
@throws PathNotFoundException if model is null and evaluation must be interrupted
@throws InvalidPathException if model is not an array and evaluation must be interrupted
|
[
"Check",
"if",
"model",
"is",
"non",
"-",
"null",
"and",
"array",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/internal/path/ArrayPathToken.java#L36-L52
|
13,821
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java
|
PathFunctionFactory.newFunction
|
public static PathFunction newFunction(String name) throws InvalidPathException {
Class functionClazz = FUNCTIONS.get(name);
if(functionClazz == null){
throw new InvalidPathException("Function with name: " + name + " does not exist.");
} else {
try {
return (PathFunction)functionClazz.newInstance();
} catch (Exception e) {
throw new InvalidPathException("Function of name: " + name + " cannot be created", e);
}
}
}
|
java
|
public static PathFunction newFunction(String name) throws InvalidPathException {
Class functionClazz = FUNCTIONS.get(name);
if(functionClazz == null){
throw new InvalidPathException("Function with name: " + name + " does not exist.");
} else {
try {
return (PathFunction)functionClazz.newInstance();
} catch (Exception e) {
throw new InvalidPathException("Function of name: " + name + " cannot be created", e);
}
}
}
|
[
"public",
"static",
"PathFunction",
"newFunction",
"(",
"String",
"name",
")",
"throws",
"InvalidPathException",
"{",
"Class",
"functionClazz",
"=",
"FUNCTIONS",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"functionClazz",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidPathException",
"(",
"\"Function with name: \"",
"+",
"name",
"+",
"\" does not exist.\"",
")",
";",
"}",
"else",
"{",
"try",
"{",
"return",
"(",
"PathFunction",
")",
"functionClazz",
".",
"newInstance",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"InvalidPathException",
"(",
"\"Function of name: \"",
"+",
"name",
"+",
"\" cannot be created\"",
",",
"e",
")",
";",
"}",
"}",
"}"
] |
Returns the function by name or throws InvalidPathException if function not found.
@see #FUNCTIONS
@see PathFunction
@param name
The name of the function
@return
The implementation of a function
@throws InvalidPathException
|
[
"Returns",
"the",
"function",
"by",
"name",
"or",
"throws",
"InvalidPathException",
"if",
"function",
"not",
"found",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java#L66-L77
|
13,822
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Criteria.java
|
Criteria.and
|
public Criteria and(String key) {
checkComplete();
return new Criteria(this.criteriaChain, ValueNode.toValueNode(prefixPath(key)));
}
|
java
|
public Criteria and(String key) {
checkComplete();
return new Criteria(this.criteriaChain, ValueNode.toValueNode(prefixPath(key)));
}
|
[
"public",
"Criteria",
"and",
"(",
"String",
"key",
")",
"{",
"checkComplete",
"(",
")",
";",
"return",
"new",
"Criteria",
"(",
"this",
".",
"criteriaChain",
",",
"ValueNode",
".",
"toValueNode",
"(",
"prefixPath",
"(",
"key",
")",
")",
")",
";",
"}"
] |
Static factory method to create a Criteria using the provided key
@param key ads new filed to criteria
@return the criteria builder
|
[
"Static",
"factory",
"method",
"to",
"create",
"a",
"Criteria",
"using",
"the",
"provided",
"key"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L109-L112
|
13,823
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Criteria.java
|
Criteria.is
|
public Criteria is(Object o) {
this.criteriaType = RelationalOperator.EQ;
this.right = ValueNode.toValueNode(o);
return this;
}
|
java
|
public Criteria is(Object o) {
this.criteriaType = RelationalOperator.EQ;
this.right = ValueNode.toValueNode(o);
return this;
}
|
[
"public",
"Criteria",
"is",
"(",
"Object",
"o",
")",
"{",
"this",
".",
"criteriaType",
"=",
"RelationalOperator",
".",
"EQ",
";",
"this",
".",
"right",
"=",
"ValueNode",
".",
"toValueNode",
"(",
"o",
")",
";",
"return",
"this",
";",
"}"
] |
Creates a criterion using equality
@param o
@return the criteria
|
[
"Creates",
"a",
"criterion",
"using",
"equality"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L120-L124
|
13,824
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Criteria.java
|
Criteria.regex
|
public Criteria regex(Pattern pattern) {
notNull(pattern, "pattern can not be null");
this.criteriaType = RelationalOperator.REGEX;
this.right = ValueNode.toValueNode(pattern);
return this;
}
|
java
|
public Criteria regex(Pattern pattern) {
notNull(pattern, "pattern can not be null");
this.criteriaType = RelationalOperator.REGEX;
this.right = ValueNode.toValueNode(pattern);
return this;
}
|
[
"public",
"Criteria",
"regex",
"(",
"Pattern",
"pattern",
")",
"{",
"notNull",
"(",
"pattern",
",",
"\"pattern can not be null\"",
")",
";",
"this",
".",
"criteriaType",
"=",
"RelationalOperator",
".",
"REGEX",
";",
"this",
".",
"right",
"=",
"ValueNode",
".",
"toValueNode",
"(",
"pattern",
")",
";",
"return",
"this",
";",
"}"
] |
Creates a criterion using a Regex
@param pattern
@return the criteria
|
[
"Creates",
"a",
"criterion",
"using",
"a",
"Regex"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L202-L207
|
13,825
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Criteria.java
|
Criteria.parse
|
@Deprecated
public static Criteria parse(String criteria) {
if(criteria == null){
throw new InvalidPathException("Criteria can not be null");
}
String[] split = criteria.trim().split(" ");
if(split.length == 3){
return create(split[0], split[1], split[2]);
} else if(split.length == 1){
return create(split[0], "EXISTS", "true");
} else {
throw new InvalidPathException("Could not parse criteria");
}
}
|
java
|
@Deprecated
public static Criteria parse(String criteria) {
if(criteria == null){
throw new InvalidPathException("Criteria can not be null");
}
String[] split = criteria.trim().split(" ");
if(split.length == 3){
return create(split[0], split[1], split[2]);
} else if(split.length == 1){
return create(split[0], "EXISTS", "true");
} else {
throw new InvalidPathException("Could not parse criteria");
}
}
|
[
"@",
"Deprecated",
"public",
"static",
"Criteria",
"parse",
"(",
"String",
"criteria",
")",
"{",
"if",
"(",
"criteria",
"==",
"null",
")",
"{",
"throw",
"new",
"InvalidPathException",
"(",
"\"Criteria can not be null\"",
")",
";",
"}",
"String",
"[",
"]",
"split",
"=",
"criteria",
".",
"trim",
"(",
")",
".",
"split",
"(",
"\" \"",
")",
";",
"if",
"(",
"split",
".",
"length",
"==",
"3",
")",
"{",
"return",
"create",
"(",
"split",
"[",
"0",
"]",
",",
"split",
"[",
"1",
"]",
",",
"split",
"[",
"2",
"]",
")",
";",
"}",
"else",
"if",
"(",
"split",
".",
"length",
"==",
"1",
")",
"{",
"return",
"create",
"(",
"split",
"[",
"0",
"]",
",",
"\"EXISTS\"",
",",
"\"true\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidPathException",
"(",
"\"Could not parse criteria\"",
")",
";",
"}",
"}"
] |
Parse the provided criteria
Deprecated use {@link Filter#parse(String)}
@param criteria
@return a criteria
|
[
"Parse",
"the",
"provided",
"criteria"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L468-L481
|
13,826
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Criteria.java
|
Criteria.create
|
@Deprecated
public static Criteria create(String left, String operator, String right) {
Criteria criteria = new Criteria(ValueNode.toValueNode(left));
criteria.criteriaType = RelationalOperator.fromString(operator);
criteria.right = ValueNode.toValueNode(right);
return criteria;
}
|
java
|
@Deprecated
public static Criteria create(String left, String operator, String right) {
Criteria criteria = new Criteria(ValueNode.toValueNode(left));
criteria.criteriaType = RelationalOperator.fromString(operator);
criteria.right = ValueNode.toValueNode(right);
return criteria;
}
|
[
"@",
"Deprecated",
"public",
"static",
"Criteria",
"create",
"(",
"String",
"left",
",",
"String",
"operator",
",",
"String",
"right",
")",
"{",
"Criteria",
"criteria",
"=",
"new",
"Criteria",
"(",
"ValueNode",
".",
"toValueNode",
"(",
"left",
")",
")",
";",
"criteria",
".",
"criteriaType",
"=",
"RelationalOperator",
".",
"fromString",
"(",
"operator",
")",
";",
"criteria",
".",
"right",
"=",
"ValueNode",
".",
"toValueNode",
"(",
"right",
")",
";",
"return",
"criteria",
";",
"}"
] |
Creates a new criteria
@param left path to evaluate in criteria
@param operator operator
@param right expected value
@return a new Criteria
|
[
"Creates",
"a",
"new",
"criteria"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L490-L496
|
13,827
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Configuration.java
|
Configuration.addEvaluationListeners
|
public Configuration addEvaluationListeners(EvaluationListener... evaluationListener){
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListener).build();
}
|
java
|
public Configuration addEvaluationListeners(EvaluationListener... evaluationListener){
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListener).build();
}
|
[
"public",
"Configuration",
"addEvaluationListeners",
"(",
"EvaluationListener",
"...",
"evaluationListener",
")",
"{",
"return",
"Configuration",
".",
"builder",
"(",
")",
".",
"jsonProvider",
"(",
"jsonProvider",
")",
".",
"mappingProvider",
"(",
"mappingProvider",
")",
".",
"options",
"(",
"options",
")",
".",
"evaluationListener",
"(",
"evaluationListener",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Creates a new Configuration by the provided evaluation listeners to the current listeners
@param evaluationListener listeners
@return a new configuration
|
[
"Creates",
"a",
"new",
"Configuration",
"by",
"the",
"provided",
"evaluation",
"listeners",
"to",
"the",
"current",
"listeners"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Configuration.java#L70-L72
|
13,828
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Configuration.java
|
Configuration.addOptions
|
public Configuration addOptions(Option... options) {
EnumSet<Option> opts = EnumSet.noneOf(Option.class);
opts.addAll(this.options);
opts.addAll(asList(options));
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(opts).evaluationListener(evaluationListeners).build();
}
|
java
|
public Configuration addOptions(Option... options) {
EnumSet<Option> opts = EnumSet.noneOf(Option.class);
opts.addAll(this.options);
opts.addAll(asList(options));
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(opts).evaluationListener(evaluationListeners).build();
}
|
[
"public",
"Configuration",
"addOptions",
"(",
"Option",
"...",
"options",
")",
"{",
"EnumSet",
"<",
"Option",
">",
"opts",
"=",
"EnumSet",
".",
"noneOf",
"(",
"Option",
".",
"class",
")",
";",
"opts",
".",
"addAll",
"(",
"this",
".",
"options",
")",
";",
"opts",
".",
"addAll",
"(",
"asList",
"(",
"options",
")",
")",
";",
"return",
"Configuration",
".",
"builder",
"(",
")",
".",
"jsonProvider",
"(",
"jsonProvider",
")",
".",
"mappingProvider",
"(",
"mappingProvider",
")",
".",
"options",
"(",
"opts",
")",
".",
"evaluationListener",
"(",
"evaluationListeners",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Creates a new configuration by adding the new options to the options used in this configuration.
@param options options to add
@return a new configuration
|
[
"Creates",
"a",
"new",
"configuration",
"by",
"adding",
"the",
"new",
"options",
"to",
"the",
"options",
"used",
"in",
"this",
"configuration",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Configuration.java#L130-L135
|
13,829
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Configuration.java
|
Configuration.setOptions
|
public Configuration setOptions(Option... options) {
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build();
}
|
java
|
public Configuration setOptions(Option... options) {
return Configuration.builder().jsonProvider(jsonProvider).mappingProvider(mappingProvider).options(options).evaluationListener(evaluationListeners).build();
}
|
[
"public",
"Configuration",
"setOptions",
"(",
"Option",
"...",
"options",
")",
"{",
"return",
"Configuration",
".",
"builder",
"(",
")",
".",
"jsonProvider",
"(",
"jsonProvider",
")",
".",
"mappingProvider",
"(",
"mappingProvider",
")",
".",
"options",
"(",
"options",
")",
".",
"evaluationListener",
"(",
"evaluationListeners",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Creates a new configuration with the provided options. Options in this configuration are discarded.
@param options
@return the new configuration instance
|
[
"Creates",
"a",
"new",
"configuration",
"with",
"the",
"provided",
"options",
".",
"Options",
"in",
"this",
"configuration",
"are",
"discarded",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Configuration.java#L142-L144
|
13,830
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/Configuration.java
|
Configuration.defaultConfiguration
|
public static Configuration defaultConfiguration() {
Defaults defaults = getEffectiveDefaults();
return Configuration.builder().jsonProvider(defaults.jsonProvider()).options(defaults.options()).build();
}
|
java
|
public static Configuration defaultConfiguration() {
Defaults defaults = getEffectiveDefaults();
return Configuration.builder().jsonProvider(defaults.jsonProvider()).options(defaults.options()).build();
}
|
[
"public",
"static",
"Configuration",
"defaultConfiguration",
"(",
")",
"{",
"Defaults",
"defaults",
"=",
"getEffectiveDefaults",
"(",
")",
";",
"return",
"Configuration",
".",
"builder",
"(",
")",
".",
"jsonProvider",
"(",
"defaults",
".",
"jsonProvider",
"(",
")",
")",
".",
"options",
"(",
"defaults",
".",
"options",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Creates a new configuration based on default values
@return a new configuration based on defaults
|
[
"Creates",
"a",
"new",
"configuration",
"based",
"on",
"default",
"values"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/Configuration.java#L167-L170
|
13,831
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
|
AbstractJsonProvider.getMapValue
|
public Object getMapValue(Object obj, String key){
Map m = (Map) obj;
if(!m.containsKey(key)){
return JsonProvider.UNDEFINED;
} else {
return m.get(key);
}
}
|
java
|
public Object getMapValue(Object obj, String key){
Map m = (Map) obj;
if(!m.containsKey(key)){
return JsonProvider.UNDEFINED;
} else {
return m.get(key);
}
}
|
[
"public",
"Object",
"getMapValue",
"(",
"Object",
"obj",
",",
"String",
"key",
")",
"{",
"Map",
"m",
"=",
"(",
"Map",
")",
"obj",
";",
"if",
"(",
"!",
"m",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"return",
"JsonProvider",
".",
"UNDEFINED",
";",
"}",
"else",
"{",
"return",
"m",
".",
"get",
"(",
"key",
")",
";",
"}",
"}"
] |
Extracts a value from an map
@param obj a map
@param key property key
@return the map entry or {@link com.jayway.jsonpath.spi.json.JsonProvider#UNDEFINED} for missing properties
|
[
"Extracts",
"a",
"value",
"from",
"an",
"map"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L72-L79
|
13,832
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
|
AbstractJsonProvider.setProperty
|
@SuppressWarnings("unchecked")
public void setProperty(Object obj, Object key, Object value) {
if (isMap(obj))
((Map) obj).put(key.toString(), value);
else {
throw new JsonPathException("setProperty operation cannot be used with " + obj!=null?obj.getClass().getName():"null");
}
}
|
java
|
@SuppressWarnings("unchecked")
public void setProperty(Object obj, Object key, Object value) {
if (isMap(obj))
((Map) obj).put(key.toString(), value);
else {
throw new JsonPathException("setProperty operation cannot be used with " + obj!=null?obj.getClass().getName():"null");
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"void",
"setProperty",
"(",
"Object",
"obj",
",",
"Object",
"key",
",",
"Object",
"value",
")",
"{",
"if",
"(",
"isMap",
"(",
"obj",
")",
")",
"(",
"(",
"Map",
")",
"obj",
")",
".",
"put",
"(",
"key",
".",
"toString",
"(",
")",
",",
"value",
")",
";",
"else",
"{",
"throw",
"new",
"JsonPathException",
"(",
"\"setProperty operation cannot be used with \"",
"+",
"obj",
"!=",
"null",
"?",
"obj",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
":",
"\"null\"",
")",
";",
"}",
"}"
] |
Sets a value in an object
@param obj an object
@param key a String key
@param value the value to set
|
[
"Sets",
"a",
"value",
"in",
"an",
"object"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L88-L95
|
13,833
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
|
AbstractJsonProvider.removeProperty
|
@SuppressWarnings("unchecked")
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
((Map) obj).remove(key.toString());
else {
List list = (List) obj;
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
list.remove(index);
}
}
|
java
|
@SuppressWarnings("unchecked")
public void removeProperty(Object obj, Object key) {
if (isMap(obj))
((Map) obj).remove(key.toString());
else {
List list = (List) obj;
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
list.remove(index);
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"void",
"removeProperty",
"(",
"Object",
"obj",
",",
"Object",
"key",
")",
"{",
"if",
"(",
"isMap",
"(",
"obj",
")",
")",
"(",
"(",
"Map",
")",
"obj",
")",
".",
"remove",
"(",
"key",
".",
"toString",
"(",
")",
")",
";",
"else",
"{",
"List",
"list",
"=",
"(",
"List",
")",
"obj",
";",
"int",
"index",
"=",
"key",
"instanceof",
"Integer",
"?",
"(",
"Integer",
")",
"key",
":",
"Integer",
".",
"parseInt",
"(",
"key",
".",
"toString",
"(",
")",
")",
";",
"list",
".",
"remove",
"(",
"index",
")",
";",
"}",
"}"
] |
Removes a value in an object or array
@param obj an array or an object
@param key a String key or a numerical index to remove
|
[
"Removes",
"a",
"value",
"in",
"an",
"object",
"or",
"array"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L105-L114
|
13,834
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
|
AbstractJsonProvider.getPropertyKeys
|
@SuppressWarnings("unchecked")
public Collection<String> getPropertyKeys(Object obj) {
if (isArray(obj)) {
throw new UnsupportedOperationException();
} else {
return ((Map) obj).keySet();
}
}
|
java
|
@SuppressWarnings("unchecked")
public Collection<String> getPropertyKeys(Object obj) {
if (isArray(obj)) {
throw new UnsupportedOperationException();
} else {
return ((Map) obj).keySet();
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"Collection",
"<",
"String",
">",
"getPropertyKeys",
"(",
"Object",
"obj",
")",
"{",
"if",
"(",
"isArray",
"(",
"obj",
")",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
")",
";",
"}",
"else",
"{",
"return",
"(",
"(",
"Map",
")",
"obj",
")",
".",
"keySet",
"(",
")",
";",
"}",
"}"
] |
Returns the keys from the given object
@param obj an object
@return the keys for an object
|
[
"Returns",
"the",
"keys",
"from",
"the",
"given",
"object"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L133-L140
|
13,835
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java
|
AbstractJsonProvider.length
|
public int length(Object obj) {
if (isArray(obj)) {
return ((List) obj).size();
} else if (isMap(obj)){
return getPropertyKeys(obj).size();
} else if(obj instanceof String){
return ((String)obj).length();
}
throw new JsonPathException("length operation cannot be applied to " + obj!=null?obj.getClass().getName():"null");
}
|
java
|
public int length(Object obj) {
if (isArray(obj)) {
return ((List) obj).size();
} else if (isMap(obj)){
return getPropertyKeys(obj).size();
} else if(obj instanceof String){
return ((String)obj).length();
}
throw new JsonPathException("length operation cannot be applied to " + obj!=null?obj.getClass().getName():"null");
}
|
[
"public",
"int",
"length",
"(",
"Object",
"obj",
")",
"{",
"if",
"(",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"(",
"(",
"List",
")",
"obj",
")",
".",
"size",
"(",
")",
";",
"}",
"else",
"if",
"(",
"isMap",
"(",
"obj",
")",
")",
"{",
"return",
"getPropertyKeys",
"(",
"obj",
")",
".",
"size",
"(",
")",
";",
"}",
"else",
"if",
"(",
"obj",
"instanceof",
"String",
")",
"{",
"return",
"(",
"(",
"String",
")",
"obj",
")",
".",
"length",
"(",
")",
";",
"}",
"throw",
"new",
"JsonPathException",
"(",
"\"length operation cannot be applied to \"",
"+",
"obj",
"!=",
"null",
"?",
"obj",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
":",
"\"null\"",
")",
";",
"}"
] |
Get the length of an array or object
@param obj an array or an object
@return the number of entries in the array or object
|
[
"Get",
"the",
"length",
"of",
"an",
"array",
"or",
"object"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/spi/json/AbstractJsonProvider.java#L148-L157
|
13,836
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java
|
Parameter.toList
|
public static <T> List<T> toList(final Class<T> type, final EvaluationContext ctx, final List<Parameter> parameters) {
List<T> values = new ArrayList();
if (null != parameters) {
for (Parameter param : parameters) {
consume(type, ctx, values, param.getValue());
}
}
return values;
}
|
java
|
public static <T> List<T> toList(final Class<T> type, final EvaluationContext ctx, final List<Parameter> parameters) {
List<T> values = new ArrayList();
if (null != parameters) {
for (Parameter param : parameters) {
consume(type, ctx, values, param.getValue());
}
}
return values;
}
|
[
"public",
"static",
"<",
"T",
">",
"List",
"<",
"T",
">",
"toList",
"(",
"final",
"Class",
"<",
"T",
">",
"type",
",",
"final",
"EvaluationContext",
"ctx",
",",
"final",
"List",
"<",
"Parameter",
">",
"parameters",
")",
"{",
"List",
"<",
"T",
">",
"values",
"=",
"new",
"ArrayList",
"(",
")",
";",
"if",
"(",
"null",
"!=",
"parameters",
")",
"{",
"for",
"(",
"Parameter",
"param",
":",
"parameters",
")",
"{",
"consume",
"(",
"type",
",",
"ctx",
",",
"values",
",",
"param",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"values",
";",
"}"
] |
Translate the collection of parameters into a collection of values of type T.
@param type
The type to translate the collection into.
@param ctx
Context.
@param parameters
Collection of parameters.
@param <T>
Type T returned as a List of T.
@return
List of T either empty or containing contents.
|
[
"Translate",
"the",
"collection",
"of",
"parameters",
"into",
"a",
"collection",
"of",
"values",
"of",
"type",
"T",
"."
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java#L91-L99
|
13,837
|
json-path/JsonPath
|
json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java
|
Parameter.consume
|
public static void consume(Class expectedType, EvaluationContext ctx, Collection collection, Object value) {
if (ctx.configuration().jsonProvider().isArray(value)) {
for (Object o : ctx.configuration().jsonProvider().toIterable(value)) {
if (o != null && expectedType.isAssignableFrom(o.getClass())) {
collection.add(o);
} else if (o != null && expectedType == String.class) {
collection.add(o.toString());
}
}
} else {
if (value != null && expectedType.isAssignableFrom(value.getClass())) {
collection.add(value);
}
}
}
|
java
|
public static void consume(Class expectedType, EvaluationContext ctx, Collection collection, Object value) {
if (ctx.configuration().jsonProvider().isArray(value)) {
for (Object o : ctx.configuration().jsonProvider().toIterable(value)) {
if (o != null && expectedType.isAssignableFrom(o.getClass())) {
collection.add(o);
} else if (o != null && expectedType == String.class) {
collection.add(o.toString());
}
}
} else {
if (value != null && expectedType.isAssignableFrom(value.getClass())) {
collection.add(value);
}
}
}
|
[
"public",
"static",
"void",
"consume",
"(",
"Class",
"expectedType",
",",
"EvaluationContext",
"ctx",
",",
"Collection",
"collection",
",",
"Object",
"value",
")",
"{",
"if",
"(",
"ctx",
".",
"configuration",
"(",
")",
".",
"jsonProvider",
"(",
")",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"for",
"(",
"Object",
"o",
":",
"ctx",
".",
"configuration",
"(",
")",
".",
"jsonProvider",
"(",
")",
".",
"toIterable",
"(",
"value",
")",
")",
"{",
"if",
"(",
"o",
"!=",
"null",
"&&",
"expectedType",
".",
"isAssignableFrom",
"(",
"o",
".",
"getClass",
"(",
")",
")",
")",
"{",
"collection",
".",
"add",
"(",
"o",
")",
";",
"}",
"else",
"if",
"(",
"o",
"!=",
"null",
"&&",
"expectedType",
"==",
"String",
".",
"class",
")",
"{",
"collection",
".",
"add",
"(",
"o",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"value",
"!=",
"null",
"&&",
"expectedType",
".",
"isAssignableFrom",
"(",
"value",
".",
"getClass",
"(",
")",
")",
")",
"{",
"collection",
".",
"add",
"(",
"value",
")",
";",
"}",
"}",
"}"
] |
Either consume the object as an array and add each element to the collection, or alternatively add each element
@param expectedType
the expected class type to consume, if null or not of this type the element is not added to the array.
@param ctx
the JSON context to determine if this is an array or value.
@param collection
The collection to append into.
@param value
The value to evaluate.
|
[
"Either",
"consume",
"the",
"object",
"as",
"an",
"array",
"and",
"add",
"each",
"element",
"to",
"the",
"collection",
"or",
"alternatively",
"add",
"each",
"element"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path/src/main/java/com/jayway/jsonpath/internal/function/Parameter.java#L116-L130
|
13,838
|
json-path/JsonPath
|
json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java
|
IsCollectionWithSize.hasSize
|
@Factory
public static <E> Matcher<? super Collection<? extends E>> hasSize(Matcher<? super Integer> size) {
return new IsCollectionWithSize<E>(size);
}
|
java
|
@Factory
public static <E> Matcher<? super Collection<? extends E>> hasSize(Matcher<? super Integer> size) {
return new IsCollectionWithSize<E>(size);
}
|
[
"@",
"Factory",
"public",
"static",
"<",
"E",
">",
"Matcher",
"<",
"?",
"super",
"Collection",
"<",
"?",
"extends",
"E",
">",
">",
"hasSize",
"(",
"Matcher",
"<",
"?",
"super",
"Integer",
">",
"size",
")",
"{",
"return",
"new",
"IsCollectionWithSize",
"<",
"E",
">",
"(",
"size",
")",
";",
"}"
] |
Does collection size satisfy a given matcher?
|
[
"Does",
"collection",
"size",
"satisfy",
"a",
"given",
"matcher?"
] |
5a09489c3252b74bbf81992aadb3073be59c04f9
|
https://github.com/json-path/JsonPath/blob/5a09489c3252b74bbf81992aadb3073be59c04f9/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java#L63-L66
|
13,839
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java
|
LdaGibbsSampler.updateParams
|
private void updateParams() {
for (int m = 0; m < documents.length; m++) {
for (int k = 0; k < K; k++) {
thetasum[m][k] += (nd[m][k] + alpha) / (ndsum[m] + K * alpha);
}
}
for (int k = 0; k < K; k++) {
for (int w = 0; w < V; w++) {
phisum[k][w] += (word_topic_matrix[w][k] + beta) / (nwsum[k] + V * beta);
}
}
numstats++;
}
|
java
|
private void updateParams() {
for (int m = 0; m < documents.length; m++) {
for (int k = 0; k < K; k++) {
thetasum[m][k] += (nd[m][k] + alpha) / (ndsum[m] + K * alpha);
}
}
for (int k = 0; k < K; k++) {
for (int w = 0; w < V; w++) {
phisum[k][w] += (word_topic_matrix[w][k] + beta) / (nwsum[k] + V * beta);
}
}
numstats++;
}
|
[
"private",
"void",
"updateParams",
"(",
")",
"{",
"for",
"(",
"int",
"m",
"=",
"0",
";",
"m",
"<",
"documents",
".",
"length",
";",
"m",
"++",
")",
"{",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"K",
";",
"k",
"++",
")",
"{",
"thetasum",
"[",
"m",
"]",
"[",
"k",
"]",
"+=",
"(",
"nd",
"[",
"m",
"]",
"[",
"k",
"]",
"+",
"alpha",
")",
"/",
"(",
"ndsum",
"[",
"m",
"]",
"+",
"K",
"*",
"alpha",
")",
";",
"}",
"}",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"K",
";",
"k",
"++",
")",
"{",
"for",
"(",
"int",
"w",
"=",
"0",
";",
"w",
"<",
"V",
";",
"w",
"++",
")",
"{",
"phisum",
"[",
"k",
"]",
"[",
"w",
"]",
"+=",
"(",
"word_topic_matrix",
"[",
"w",
"]",
"[",
"k",
"]",
"+",
"beta",
")",
"/",
"(",
"nwsum",
"[",
"k",
"]",
"+",
"V",
"*",
"beta",
")",
";",
"}",
"}",
"numstats",
"++",
";",
"}"
] |
Add to the statistics the values of theta and phi for the current state.
|
[
"Add",
"to",
"the",
"statistics",
"the",
"values",
"of",
"theta",
"and",
"phi",
"for",
"the",
"current",
"state",
"."
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java#L300-L312
|
13,840
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java
|
LdaGibbsSampler.hist
|
public static void hist(float[] data, int fmax) {
float[] hist = new float[data.length];
// scale maximum
float hmax = 0;
for (int i = 0; i < data.length; i++) {
hmax = Math.max(data[i], hmax);
}
float shrink = fmax / hmax;
for (int i = 0; i < data.length; i++) {
hist[i] = shrink * data[i];
}
NumberFormat nf = new DecimalFormat("00");
String scale = "";
for (int i = 1; i < fmax / 10 + 1; i++) {
scale += " . " + i % 10;
}
System.out.println("x" + nf.format(hmax / fmax) + "\t0" + scale);
for (int i = 0; i < hist.length; i++) {
System.out.print(i + "\t|");
for (int j = 0; j < Math.round(hist[i]); j++) {
if ((j + 1) % 10 == 0)
System.out.print("]");
else
System.out.print("|");
}
System.out.println();
}
}
|
java
|
public static void hist(float[] data, int fmax) {
float[] hist = new float[data.length];
// scale maximum
float hmax = 0;
for (int i = 0; i < data.length; i++) {
hmax = Math.max(data[i], hmax);
}
float shrink = fmax / hmax;
for (int i = 0; i < data.length; i++) {
hist[i] = shrink * data[i];
}
NumberFormat nf = new DecimalFormat("00");
String scale = "";
for (int i = 1; i < fmax / 10 + 1; i++) {
scale += " . " + i % 10;
}
System.out.println("x" + nf.format(hmax / fmax) + "\t0" + scale);
for (int i = 0; i < hist.length; i++) {
System.out.print(i + "\t|");
for (int j = 0; j < Math.round(hist[i]); j++) {
if ((j + 1) % 10 == 0)
System.out.print("]");
else
System.out.print("|");
}
System.out.println();
}
}
|
[
"public",
"static",
"void",
"hist",
"(",
"float",
"[",
"]",
"data",
",",
"int",
"fmax",
")",
"{",
"float",
"[",
"]",
"hist",
"=",
"new",
"float",
"[",
"data",
".",
"length",
"]",
";",
"// scale maximum\r",
"float",
"hmax",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"hmax",
"=",
"Math",
".",
"max",
"(",
"data",
"[",
"i",
"]",
",",
"hmax",
")",
";",
"}",
"float",
"shrink",
"=",
"fmax",
"/",
"hmax",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"hist",
"[",
"i",
"]",
"=",
"shrink",
"*",
"data",
"[",
"i",
"]",
";",
"}",
"NumberFormat",
"nf",
"=",
"new",
"DecimalFormat",
"(",
"\"00\"",
")",
";",
"String",
"scale",
"=",
"\"\"",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"fmax",
"/",
"10",
"+",
"1",
";",
"i",
"++",
")",
"{",
"scale",
"+=",
"\" . \"",
"+",
"i",
"%",
"10",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"\"x\"",
"+",
"nf",
".",
"format",
"(",
"hmax",
"/",
"fmax",
")",
"+",
"\"\\t0\"",
"+",
"scale",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"hist",
".",
"length",
";",
"i",
"++",
")",
"{",
"System",
".",
"out",
".",
"print",
"(",
"i",
"+",
"\"\\t|\"",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"Math",
".",
"round",
"(",
"hist",
"[",
"i",
"]",
")",
";",
"j",
"++",
")",
"{",
"if",
"(",
"(",
"j",
"+",
"1",
")",
"%",
"10",
"==",
"0",
")",
"System",
".",
"out",
".",
"print",
"(",
"\"]\"",
")",
";",
"else",
"System",
".",
"out",
".",
"print",
"(",
"\"|\"",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
")",
";",
"}",
"}"
] |
Print table of multinomial data
@param data
vector of evidence
@param fmax
max frequency in display
the scaled histogram bin values
|
[
"Print",
"table",
"of",
"multinomial",
"data"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java#L374-L404
|
13,841
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java
|
LdaGibbsSampler.configure
|
public void configure(int iterations, int burnIn, int thinInterval,
int sampleLag) {
ITERATIONS = iterations;
BURN_IN = burnIn;
THIN_INTERVAL = thinInterval;
SAMPLE_LAG = sampleLag;
}
|
java
|
public void configure(int iterations, int burnIn, int thinInterval,
int sampleLag) {
ITERATIONS = iterations;
BURN_IN = burnIn;
THIN_INTERVAL = thinInterval;
SAMPLE_LAG = sampleLag;
}
|
[
"public",
"void",
"configure",
"(",
"int",
"iterations",
",",
"int",
"burnIn",
",",
"int",
"thinInterval",
",",
"int",
"sampleLag",
")",
"{",
"ITERATIONS",
"=",
"iterations",
";",
"BURN_IN",
"=",
"burnIn",
";",
"THIN_INTERVAL",
"=",
"thinInterval",
";",
"SAMPLE_LAG",
"=",
"sampleLag",
";",
"}"
] |
Configure the gibbs sampler
@param iterations
number of total iterations
@param burnIn
number of burn-in iterations
@param thinInterval
update statistics interval
@param sampleLag
sample interval (-1 for just one sample at the end)
|
[
"Configure",
"the",
"gibbs",
"sampler"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java#L418-L424
|
13,842
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java
|
LdaGibbsSampler.shadefloat
|
public static String shadefloat(float d, float max) {
int a = (int) Math.floor(d * 10 / max + 0.5);
if (a > 10 || a < 0) {
String x = lnf.format(d);
a = 5 - x.length();
for (int i = 0; i < a; i++) {
x += " ";
}
return "<" + x + ">";
}
return "[" + shades[a] + "]";
}
|
java
|
public static String shadefloat(float d, float max) {
int a = (int) Math.floor(d * 10 / max + 0.5);
if (a > 10 || a < 0) {
String x = lnf.format(d);
a = 5 - x.length();
for (int i = 0; i < a; i++) {
x += " ";
}
return "<" + x + ">";
}
return "[" + shades[a] + "]";
}
|
[
"public",
"static",
"String",
"shadefloat",
"(",
"float",
"d",
",",
"float",
"max",
")",
"{",
"int",
"a",
"=",
"(",
"int",
")",
"Math",
".",
"floor",
"(",
"d",
"*",
"10",
"/",
"max",
"+",
"0.5",
")",
";",
"if",
"(",
"a",
">",
"10",
"||",
"a",
"<",
"0",
")",
"{",
"String",
"x",
"=",
"lnf",
".",
"format",
"(",
"d",
")",
";",
"a",
"=",
"5",
"-",
"x",
".",
"length",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a",
";",
"i",
"++",
")",
"{",
"x",
"+=",
"\" \"",
";",
"}",
"return",
"\"<\"",
"+",
"x",
"+",
"\">\"",
";",
"}",
"return",
"\"[\"",
"+",
"shades",
"[",
"a",
"]",
"+",
"\"]\"",
";",
"}"
] |
create a string representation whose gray value appears as an indicator
of magnitude, cf. Hinton diagrams in statistics.
@param d
value
@param max
maximum value
@return
|
[
"create",
"a",
"string",
"representation",
"whose",
"gray",
"value",
"appears",
"as",
"an",
"indicator",
"of",
"magnitude",
"cf",
".",
"Hinton",
"diagrams",
"in",
"statistics",
"."
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/langmodel/lda/LdaGibbsSampler.java#L547-L558
|
13,843
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/util/hash/MurmurHash.java
|
MurmurHash.hash64
|
public long hash64( final byte[] data, int length, int seed) {
final long m = 0xc6a4a7935bd1e995L;
final int r = 47;
long h = (seed&0xffffffffl)^(length*m);
int length8 = length/8;
for (int i=0; i<length8; i++) {
final int i8 = i*8;
long k = ((long)data[i8+0]&0xff) +(((long)data[i8+1]&0xff)<<8)
+(((long)data[i8+2]&0xff)<<16) +(((long)data[i8+3]&0xff)<<24)
+(((long)data[i8+4]&0xff)<<32) +(((long)data[i8+5]&0xff)<<40)
+(((long)data[i8+6]&0xff)<<48) +(((long)data[i8+7]&0xff)<<56);
k *= m;
k ^= k >>> r;
k *= m;
h ^= k;
h *= m;
}
switch (length%8) {
case 7: h ^= (long)(data[(length&~7)+6]&0xff) << 48;
case 6: h ^= (long)(data[(length&~7)+5]&0xff) << 40;
case 5: h ^= (long)(data[(length&~7)+4]&0xff) << 32;
case 4: h ^= (long)(data[(length&~7)+3]&0xff) << 24;
case 3: h ^= (long)(data[(length&~7)+2]&0xff) << 16;
case 2: h ^= (long)(data[(length&~7)+1]&0xff) << 8;
case 1: h ^= (long)(data[length&~7]&0xff);
h *= m;
};
h ^= h >>> r;
h *= m;
h ^= h >>> r;
return h;
}
|
java
|
public long hash64( final byte[] data, int length, int seed) {
final long m = 0xc6a4a7935bd1e995L;
final int r = 47;
long h = (seed&0xffffffffl)^(length*m);
int length8 = length/8;
for (int i=0; i<length8; i++) {
final int i8 = i*8;
long k = ((long)data[i8+0]&0xff) +(((long)data[i8+1]&0xff)<<8)
+(((long)data[i8+2]&0xff)<<16) +(((long)data[i8+3]&0xff)<<24)
+(((long)data[i8+4]&0xff)<<32) +(((long)data[i8+5]&0xff)<<40)
+(((long)data[i8+6]&0xff)<<48) +(((long)data[i8+7]&0xff)<<56);
k *= m;
k ^= k >>> r;
k *= m;
h ^= k;
h *= m;
}
switch (length%8) {
case 7: h ^= (long)(data[(length&~7)+6]&0xff) << 48;
case 6: h ^= (long)(data[(length&~7)+5]&0xff) << 40;
case 5: h ^= (long)(data[(length&~7)+4]&0xff) << 32;
case 4: h ^= (long)(data[(length&~7)+3]&0xff) << 24;
case 3: h ^= (long)(data[(length&~7)+2]&0xff) << 16;
case 2: h ^= (long)(data[(length&~7)+1]&0xff) << 8;
case 1: h ^= (long)(data[length&~7]&0xff);
h *= m;
};
h ^= h >>> r;
h *= m;
h ^= h >>> r;
return h;
}
|
[
"public",
"long",
"hash64",
"(",
"final",
"byte",
"[",
"]",
"data",
",",
"int",
"length",
",",
"int",
"seed",
")",
"{",
"final",
"long",
"m",
"=",
"0xc6a4a7935bd1e995",
"",
"L",
";",
"final",
"int",
"r",
"=",
"47",
";",
"long",
"h",
"=",
"(",
"seed",
"&",
"0xffffffff",
"l",
")",
"^",
"(",
"length",
"*",
"m",
")",
";",
"int",
"length8",
"=",
"length",
"/",
"8",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length8",
";",
"i",
"++",
")",
"{",
"final",
"int",
"i8",
"=",
"i",
"*",
"8",
";",
"long",
"k",
"=",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"0",
"]",
"&",
"0xff",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"1",
"]",
"&",
"0xff",
")",
"<<",
"8",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"2",
"]",
"&",
"0xff",
")",
"<<",
"16",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"3",
"]",
"&",
"0xff",
")",
"<<",
"24",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"4",
"]",
"&",
"0xff",
")",
"<<",
"32",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"5",
"]",
"&",
"0xff",
")",
"<<",
"40",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"6",
"]",
"&",
"0xff",
")",
"<<",
"48",
")",
"+",
"(",
"(",
"(",
"long",
")",
"data",
"[",
"i8",
"+",
"7",
"]",
"&",
"0xff",
")",
"<<",
"56",
")",
";",
"k",
"*=",
"m",
";",
"k",
"^=",
"k",
">>>",
"r",
";",
"k",
"*=",
"m",
";",
"h",
"^=",
"k",
";",
"h",
"*=",
"m",
";",
"}",
"switch",
"(",
"length",
"%",
"8",
")",
"{",
"case",
"7",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"6",
"]",
"&",
"0xff",
")",
"<<",
"48",
";",
"case",
"6",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"5",
"]",
"&",
"0xff",
")",
"<<",
"40",
";",
"case",
"5",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"4",
"]",
"&",
"0xff",
")",
"<<",
"32",
";",
"case",
"4",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"3",
"]",
"&",
"0xff",
")",
"<<",
"24",
";",
"case",
"3",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"2",
"]",
"&",
"0xff",
")",
"<<",
"16",
";",
"case",
"2",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"(",
"length",
"&",
"~",
"7",
")",
"+",
"1",
"]",
"&",
"0xff",
")",
"<<",
"8",
";",
"case",
"1",
":",
"h",
"^=",
"(",
"long",
")",
"(",
"data",
"[",
"length",
"&",
"~",
"7",
"]",
"&",
"0xff",
")",
";",
"h",
"*=",
"m",
";",
"}",
";",
"h",
"^=",
"h",
">>>",
"r",
";",
"h",
"*=",
"m",
";",
"h",
"^=",
"h",
">>>",
"r",
";",
"return",
"h",
";",
"}"
] |
Generates 64 bit hash from byte array of the given length and seed.
@param data byte array to hash
@param length length of the array to hash
@param seed initial seed value
@return 64 bit hash of the given array
|
[
"Generates",
"64",
"bit",
"hash",
"from",
"byte",
"array",
"of",
"the",
"given",
"length",
"and",
"seed",
"."
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/util/hash/MurmurHash.java#L129-L168
|
13,844
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/similarity/train/WordCluster.java
|
WordCluster.weight
|
private float weight(int c1, int c2) {
float w;
float pc1 = wordProb.get(c1);
float pc2 = wordProb.get(c2);
if (c1==c2) {
float pcc = getProb(c1,c1);
w = clacW(pcc,pc1,pc2);
} else {
float pcc1 = getProb(c1, c2);
float p1= clacW(pcc1,pc1,pc2);
float pcc2 = getProb(c2, c1);
float p2 = clacW(pcc2,pc2,pc1);
w = p1 + p2;
}
setweight(c1, c2, w);
return w;
}
|
java
|
private float weight(int c1, int c2) {
float w;
float pc1 = wordProb.get(c1);
float pc2 = wordProb.get(c2);
if (c1==c2) {
float pcc = getProb(c1,c1);
w = clacW(pcc,pc1,pc2);
} else {
float pcc1 = getProb(c1, c2);
float p1= clacW(pcc1,pc1,pc2);
float pcc2 = getProb(c2, c1);
float p2 = clacW(pcc2,pc2,pc1);
w = p1 + p2;
}
setweight(c1, c2, w);
return w;
}
|
[
"private",
"float",
"weight",
"(",
"int",
"c1",
",",
"int",
"c2",
")",
"{",
"float",
"w",
";",
"float",
"pc1",
"=",
"wordProb",
".",
"get",
"(",
"c1",
")",
";",
"float",
"pc2",
"=",
"wordProb",
".",
"get",
"(",
"c2",
")",
";",
"if",
"(",
"c1",
"==",
"c2",
")",
"{",
"float",
"pcc",
"=",
"getProb",
"(",
"c1",
",",
"c1",
")",
";",
"w",
"=",
"clacW",
"(",
"pcc",
",",
"pc1",
",",
"pc2",
")",
";",
"}",
"else",
"{",
"float",
"pcc1",
"=",
"getProb",
"(",
"c1",
",",
"c2",
")",
";",
"float",
"p1",
"=",
"clacW",
"(",
"pcc1",
",",
"pc1",
",",
"pc2",
")",
";",
"float",
"pcc2",
"=",
"getProb",
"(",
"c2",
",",
"c1",
")",
";",
"float",
"p2",
"=",
"clacW",
"(",
"pcc2",
",",
"pc2",
",",
"pc1",
")",
";",
"w",
"=",
"p1",
"+",
"p2",
";",
"}",
"setweight",
"(",
"c1",
",",
"c2",
",",
"w",
")",
";",
"return",
"w",
";",
"}"
] |
total graph weight
@param c1
@param c2
@param b
@return
|
[
"total",
"graph",
"weight"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/similarity/train/WordCluster.java#L198-L215
|
13,845
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/nlp/similarity/train/WordCluster.java
|
WordCluster.calcL
|
public float calcL(int c1, int c2) {
float L = 0;
TIntIterator it = slots.iterator();
while(it.hasNext()){
int k = it.next();
if(k==c2)
continue;
L += weight(c1,c2,k);
}
it = slots.iterator();
while(it.hasNext()){
int k = it.next();
L -= getweight(c1,k);
L -= getweight(c2, k);
}
return L;
}
|
java
|
public float calcL(int c1, int c2) {
float L = 0;
TIntIterator it = slots.iterator();
while(it.hasNext()){
int k = it.next();
if(k==c2)
continue;
L += weight(c1,c2,k);
}
it = slots.iterator();
while(it.hasNext()){
int k = it.next();
L -= getweight(c1,k);
L -= getweight(c2, k);
}
return L;
}
|
[
"public",
"float",
"calcL",
"(",
"int",
"c1",
",",
"int",
"c2",
")",
"{",
"float",
"L",
"=",
"0",
";",
"TIntIterator",
"it",
"=",
"slots",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"int",
"k",
"=",
"it",
".",
"next",
"(",
")",
";",
"if",
"(",
"k",
"==",
"c2",
")",
"continue",
";",
"L",
"+=",
"weight",
"(",
"c1",
",",
"c2",
",",
"k",
")",
";",
"}",
"it",
"=",
"slots",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"int",
"k",
"=",
"it",
".",
"next",
"(",
")",
";",
"L",
"-=",
"getweight",
"(",
"c1",
",",
"k",
")",
";",
"L",
"-=",
"getweight",
"(",
"c2",
",",
"k",
")",
";",
"}",
"return",
"L",
";",
"}"
] |
calculate the value L
@param c1
@param c2
@return
|
[
"calculate",
"the",
"value",
"L"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/nlp/similarity/train/WordCluster.java#L424-L443
|
13,846
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/ml/classifier/hier/Tree.java
|
Tree.addEdge
|
private void addEdge(int i, int j) {
if(!nodes.contains(i)){
nodes.add(i);
edges.put(i, new HashSet<Integer>());
size++;
}else if(!edges.containsKey(i)){
edges.put(i, new HashSet<Integer>());
}
if(!nodes.contains(j)){
nodes.add(j);
size++;
}
edgesInv.put(j, i);
if(!edges.get(i).contains(j)){
edges.get(i).add(j);
}
}
|
java
|
private void addEdge(int i, int j) {
if(!nodes.contains(i)){
nodes.add(i);
edges.put(i, new HashSet<Integer>());
size++;
}else if(!edges.containsKey(i)){
edges.put(i, new HashSet<Integer>());
}
if(!nodes.contains(j)){
nodes.add(j);
size++;
}
edgesInv.put(j, i);
if(!edges.get(i).contains(j)){
edges.get(i).add(j);
}
}
|
[
"private",
"void",
"addEdge",
"(",
"int",
"i",
",",
"int",
"j",
")",
"{",
"if",
"(",
"!",
"nodes",
".",
"contains",
"(",
"i",
")",
")",
"{",
"nodes",
".",
"add",
"(",
"i",
")",
";",
"edges",
".",
"put",
"(",
"i",
",",
"new",
"HashSet",
"<",
"Integer",
">",
"(",
")",
")",
";",
"size",
"++",
";",
"}",
"else",
"if",
"(",
"!",
"edges",
".",
"containsKey",
"(",
"i",
")",
")",
"{",
"edges",
".",
"put",
"(",
"i",
",",
"new",
"HashSet",
"<",
"Integer",
">",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"nodes",
".",
"contains",
"(",
"j",
")",
")",
"{",
"nodes",
".",
"add",
"(",
"j",
")",
";",
"size",
"++",
";",
"}",
"edgesInv",
".",
"put",
"(",
"j",
",",
"i",
")",
";",
"if",
"(",
"!",
"edges",
".",
"get",
"(",
"i",
")",
".",
"contains",
"(",
"j",
")",
")",
"{",
"edges",
".",
"get",
"(",
"i",
")",
".",
"add",
"(",
"j",
")",
";",
"}",
"}"
] |
i -> j
@param i 父节点
@param j 子节点
|
[
"i",
"-",
">",
"j"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/ml/classifier/hier/Tree.java#L195-L214
|
13,847
|
FudanNLP/fnlp
|
fnlp-core/src/main/java/org/fnlp/ml/types/sv/HashSparseVector.java
|
HashSparseVector.plus
|
public void plus(ISparseVector sv) {
if(sv instanceof HashSparseVector){
TIntFloatIterator it = ((HashSparseVector) sv).data.iterator();
while(it.hasNext()){
it.advance();
data.adjustOrPutValue(it.key(), it.value(),it.value());
}
}else if(sv instanceof BinarySparseVector){
TIntIterator it = ((BinarySparseVector) sv).data.iterator();
while(it.hasNext()){
int i = it.next();
data.adjustOrPutValue(i,DefaultValue,DefaultValue);
}
}
}
|
java
|
public void plus(ISparseVector sv) {
if(sv instanceof HashSparseVector){
TIntFloatIterator it = ((HashSparseVector) sv).data.iterator();
while(it.hasNext()){
it.advance();
data.adjustOrPutValue(it.key(), it.value(),it.value());
}
}else if(sv instanceof BinarySparseVector){
TIntIterator it = ((BinarySparseVector) sv).data.iterator();
while(it.hasNext()){
int i = it.next();
data.adjustOrPutValue(i,DefaultValue,DefaultValue);
}
}
}
|
[
"public",
"void",
"plus",
"(",
"ISparseVector",
"sv",
")",
"{",
"if",
"(",
"sv",
"instanceof",
"HashSparseVector",
")",
"{",
"TIntFloatIterator",
"it",
"=",
"(",
"(",
"HashSparseVector",
")",
"sv",
")",
".",
"data",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"it",
".",
"advance",
"(",
")",
";",
"data",
".",
"adjustOrPutValue",
"(",
"it",
".",
"key",
"(",
")",
",",
"it",
".",
"value",
"(",
")",
",",
"it",
".",
"value",
"(",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"sv",
"instanceof",
"BinarySparseVector",
")",
"{",
"TIntIterator",
"it",
"=",
"(",
"(",
"BinarySparseVector",
")",
"sv",
")",
".",
"data",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"int",
"i",
"=",
"it",
".",
"next",
"(",
")",
";",
"data",
".",
"adjustOrPutValue",
"(",
"i",
",",
"DefaultValue",
",",
"DefaultValue",
")",
";",
"}",
"}",
"}"
] |
v + sv
@param sv
|
[
"v",
"+",
"sv"
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-core/src/main/java/org/fnlp/ml/types/sv/HashSparseVector.java#L100-L115
|
13,848
|
FudanNLP/fnlp
|
fnlp-train/src/main/java/org/fnlp/train/tag/TemplateSelection.java
|
TemplateSelection.SFFS
|
public void SFFS() throws Exception {
int NumTemplate = Templates.length;
CurSet = new boolean[NumTemplate];
LeftSet = new boolean[NumTemplate];
for (int i = 0; i < NumTemplate; i++) {
CurSet[i] = false;
LeftSet[i] = true;
}
Evaluate(Templates, CurSet);
boolean continueDelete = false;
while (SetSize(CurSet) <= NumTemplate) {
if (!continueDelete) {
Integer theInt = BooleanSet2Integer(CurSet);
int best = BestFeatureByAdding(CurSet, LeftSet);
if (best != -1) {
System.out.println("Add Best " + best);
AlreadyAdded.add(theInt);
CurSet[best] = true;
LeftSet[best] = false;
printAccuracy(CurSet);
}
}
Integer theInt = BooleanSet2Integer(CurSet);
// 被删除过的集合就不再删除了
if (AlreadyRemoved.contains(theInt)) {
continueDelete = false;
continue;
} else {
int worst = WorstFeatureByRemoving(CurSet);
boolean[] TestSet = CurSet.clone();
TestSet[worst] = false;
double accuracy = Evaluate(Templates, TestSet);
if (accuracy >= AccuracyRecords.get(theInt)) {
System.out.println("Remove Worst " + worst);
AlreadyRemoved.add(theInt);
CurSet[worst] = false;
LeftSet[worst] = true;
printAccuracy(CurSet);
if (SetSize(CurSet) == 0) {
continueDelete = false;
} else
continueDelete = true;
} else {
continueDelete = false;
continue;
}
}
}
printAccuracyRecords(AccuracyRecords);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
"/home/zliu/corpus/testTemplate/SFFS.ser"));
oos.writeObject(AccuracyRecords);
oos.close();
}
|
java
|
public void SFFS() throws Exception {
int NumTemplate = Templates.length;
CurSet = new boolean[NumTemplate];
LeftSet = new boolean[NumTemplate];
for (int i = 0; i < NumTemplate; i++) {
CurSet[i] = false;
LeftSet[i] = true;
}
Evaluate(Templates, CurSet);
boolean continueDelete = false;
while (SetSize(CurSet) <= NumTemplate) {
if (!continueDelete) {
Integer theInt = BooleanSet2Integer(CurSet);
int best = BestFeatureByAdding(CurSet, LeftSet);
if (best != -1) {
System.out.println("Add Best " + best);
AlreadyAdded.add(theInt);
CurSet[best] = true;
LeftSet[best] = false;
printAccuracy(CurSet);
}
}
Integer theInt = BooleanSet2Integer(CurSet);
// 被删除过的集合就不再删除了
if (AlreadyRemoved.contains(theInt)) {
continueDelete = false;
continue;
} else {
int worst = WorstFeatureByRemoving(CurSet);
boolean[] TestSet = CurSet.clone();
TestSet[worst] = false;
double accuracy = Evaluate(Templates, TestSet);
if (accuracy >= AccuracyRecords.get(theInt)) {
System.out.println("Remove Worst " + worst);
AlreadyRemoved.add(theInt);
CurSet[worst] = false;
LeftSet[worst] = true;
printAccuracy(CurSet);
if (SetSize(CurSet) == 0) {
continueDelete = false;
} else
continueDelete = true;
} else {
continueDelete = false;
continue;
}
}
}
printAccuracyRecords(AccuracyRecords);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
"/home/zliu/corpus/testTemplate/SFFS.ser"));
oos.writeObject(AccuracyRecords);
oos.close();
}
|
[
"public",
"void",
"SFFS",
"(",
")",
"throws",
"Exception",
"{",
"int",
"NumTemplate",
"=",
"Templates",
".",
"length",
";",
"CurSet",
"=",
"new",
"boolean",
"[",
"NumTemplate",
"]",
";",
"LeftSet",
"=",
"new",
"boolean",
"[",
"NumTemplate",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"NumTemplate",
";",
"i",
"++",
")",
"{",
"CurSet",
"[",
"i",
"]",
"=",
"false",
";",
"LeftSet",
"[",
"i",
"]",
"=",
"true",
";",
"}",
"Evaluate",
"(",
"Templates",
",",
"CurSet",
")",
";",
"boolean",
"continueDelete",
"=",
"false",
";",
"while",
"(",
"SetSize",
"(",
"CurSet",
")",
"<=",
"NumTemplate",
")",
"{",
"if",
"(",
"!",
"continueDelete",
")",
"{",
"Integer",
"theInt",
"=",
"BooleanSet2Integer",
"(",
"CurSet",
")",
";",
"int",
"best",
"=",
"BestFeatureByAdding",
"(",
"CurSet",
",",
"LeftSet",
")",
";",
"if",
"(",
"best",
"!=",
"-",
"1",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Add Best \"",
"+",
"best",
")",
";",
"AlreadyAdded",
".",
"add",
"(",
"theInt",
")",
";",
"CurSet",
"[",
"best",
"]",
"=",
"true",
";",
"LeftSet",
"[",
"best",
"]",
"=",
"false",
";",
"printAccuracy",
"(",
"CurSet",
")",
";",
"}",
"}",
"Integer",
"theInt",
"=",
"BooleanSet2Integer",
"(",
"CurSet",
")",
";",
"// 被删除过的集合就不再删除了",
"if",
"(",
"AlreadyRemoved",
".",
"contains",
"(",
"theInt",
")",
")",
"{",
"continueDelete",
"=",
"false",
";",
"continue",
";",
"}",
"else",
"{",
"int",
"worst",
"=",
"WorstFeatureByRemoving",
"(",
"CurSet",
")",
";",
"boolean",
"[",
"]",
"TestSet",
"=",
"CurSet",
".",
"clone",
"(",
")",
";",
"TestSet",
"[",
"worst",
"]",
"=",
"false",
";",
"double",
"accuracy",
"=",
"Evaluate",
"(",
"Templates",
",",
"TestSet",
")",
";",
"if",
"(",
"accuracy",
">=",
"AccuracyRecords",
".",
"get",
"(",
"theInt",
")",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Remove Worst \"",
"+",
"worst",
")",
";",
"AlreadyRemoved",
".",
"add",
"(",
"theInt",
")",
";",
"CurSet",
"[",
"worst",
"]",
"=",
"false",
";",
"LeftSet",
"[",
"worst",
"]",
"=",
"true",
";",
"printAccuracy",
"(",
"CurSet",
")",
";",
"if",
"(",
"SetSize",
"(",
"CurSet",
")",
"==",
"0",
")",
"{",
"continueDelete",
"=",
"false",
";",
"}",
"else",
"continueDelete",
"=",
"true",
";",
"}",
"else",
"{",
"continueDelete",
"=",
"false",
";",
"continue",
";",
"}",
"}",
"}",
"printAccuracyRecords",
"(",
"AccuracyRecords",
")",
";",
"ObjectOutputStream",
"oos",
"=",
"new",
"ObjectOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"\"/home/zliu/corpus/testTemplate/SFFS.ser\"",
")",
")",
";",
"oos",
".",
"writeObject",
"(",
"AccuracyRecords",
")",
";",
"oos",
".",
"close",
"(",
")",
";",
"}"
] |
SFFS alg.
@param templatefile
@throws Exception
|
[
"SFFS",
"alg",
"."
] |
ce258f3e4a5add2ba0b5e4cbac7cab2190af6659
|
https://github.com/FudanNLP/fnlp/blob/ce258f3e4a5add2ba0b5e4cbac7cab2190af6659/fnlp-train/src/main/java/org/fnlp/train/tag/TemplateSelection.java#L360-L414
|
13,849
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLInterfaceType.java
|
GraphQLInterfaceType.transform
|
public GraphQLInterfaceType transform(Consumer<Builder> builderConsumer) {
Builder builder = newInterface(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLInterfaceType transform(Consumer<Builder> builderConsumer) {
Builder builder = newInterface(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLInterfaceType",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newInterface",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLInterfaceType 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",
"GraphQLInterfaceType",
"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/GraphQLInterfaceType.java#L145-L149
|
13,850
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeInfo.java
|
TypeInfo.decorate
|
@SuppressWarnings("TypeParameterUnusedInFormals")
public <T extends GraphQLType> T decorate(GraphQLType objectType) {
GraphQLType out = objectType;
Stack<Class<?>> wrappingStack = new Stack<>();
wrappingStack.addAll(this.decoration);
while (!wrappingStack.isEmpty()) {
Class<?> clazz = wrappingStack.pop();
if (clazz.equals(NonNullType.class)) {
out = nonNull(out);
}
if (clazz.equals(ListType.class)) {
out = list(out);
}
}
// we handle both input and output graphql types
//noinspection unchecked
return (T) out;
}
|
java
|
@SuppressWarnings("TypeParameterUnusedInFormals")
public <T extends GraphQLType> T decorate(GraphQLType objectType) {
GraphQLType out = objectType;
Stack<Class<?>> wrappingStack = new Stack<>();
wrappingStack.addAll(this.decoration);
while (!wrappingStack.isEmpty()) {
Class<?> clazz = wrappingStack.pop();
if (clazz.equals(NonNullType.class)) {
out = nonNull(out);
}
if (clazz.equals(ListType.class)) {
out = list(out);
}
}
// we handle both input and output graphql types
//noinspection unchecked
return (T) out;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"TypeParameterUnusedInFormals\"",
")",
"public",
"<",
"T",
"extends",
"GraphQLType",
">",
"T",
"decorate",
"(",
"GraphQLType",
"objectType",
")",
"{",
"GraphQLType",
"out",
"=",
"objectType",
";",
"Stack",
"<",
"Class",
"<",
"?",
">",
">",
"wrappingStack",
"=",
"new",
"Stack",
"<>",
"(",
")",
";",
"wrappingStack",
".",
"addAll",
"(",
"this",
".",
"decoration",
")",
";",
"while",
"(",
"!",
"wrappingStack",
".",
"isEmpty",
"(",
")",
")",
"{",
"Class",
"<",
"?",
">",
"clazz",
"=",
"wrappingStack",
".",
"pop",
"(",
")",
";",
"if",
"(",
"clazz",
".",
"equals",
"(",
"NonNullType",
".",
"class",
")",
")",
"{",
"out",
"=",
"nonNull",
"(",
"out",
")",
";",
"}",
"if",
"(",
"clazz",
".",
"equals",
"(",
"ListType",
".",
"class",
")",
")",
"{",
"out",
"=",
"list",
"(",
"out",
")",
";",
"}",
"}",
"// we handle both input and output graphql types",
"//noinspection unchecked",
"return",
"(",
"T",
")",
"out",
";",
"}"
] |
This will decorate a graphql type with the original hierarchy of non null and list'ness
it originally contained in its definition type
@param objectType this should be a graphql type that was originally built from this raw type
@param <T> the type
@return the decorated type
|
[
"This",
"will",
"decorate",
"a",
"graphql",
"type",
"with",
"the",
"original",
"hierarchy",
"of",
"non",
"null",
"and",
"list",
"ness",
"it",
"originally",
"contained",
"in",
"its",
"definition",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeInfo.java#L80-L98
|
13,851
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLCodeRegistry.java
|
GraphQLCodeRegistry.getDataFetcher
|
public DataFetcher getDataFetcher(GraphQLFieldsContainer parentType, GraphQLFieldDefinition fieldDefinition) {
return getDataFetcherImpl(parentType, fieldDefinition, dataFetcherMap, systemDataFetcherMap);
}
|
java
|
public DataFetcher getDataFetcher(GraphQLFieldsContainer parentType, GraphQLFieldDefinition fieldDefinition) {
return getDataFetcherImpl(parentType, fieldDefinition, dataFetcherMap, systemDataFetcherMap);
}
|
[
"public",
"DataFetcher",
"getDataFetcher",
"(",
"GraphQLFieldsContainer",
"parentType",
",",
"GraphQLFieldDefinition",
"fieldDefinition",
")",
"{",
"return",
"getDataFetcherImpl",
"(",
"parentType",
",",
"fieldDefinition",
",",
"dataFetcherMap",
",",
"systemDataFetcherMap",
")",
";",
"}"
] |
Returns a data fetcher associated with a field within a container type
@param parentType the container type
@param fieldDefinition the field definition
@return the DataFetcher associated with this field. All fields have data fetchers
|
[
"Returns",
"a",
"data",
"fetcher",
"associated",
"with",
"a",
"field",
"within",
"a",
"container",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLCodeRegistry.java#L57-L59
|
13,852
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/nextgen/BatchedExecutionStrategy.java
|
BatchedExecutionStrategy.resolveNodes
|
private CompletableFuture<NodeMultiZipper<ExecutionResultNode>> resolveNodes(ExecutionContext executionContext, List<NodeMultiZipper<ExecutionResultNode>> unresolvedNodes) {
assertNotEmpty(unresolvedNodes, "unresolvedNodes can't be empty");
ExecutionResultNode commonRoot = unresolvedNodes.get(0).getCommonRoot();
CompletableFuture<List<List<NodeZipper<ExecutionResultNode>>>> listListCF = Async.flatMap(unresolvedNodes,
executionResultMultiZipper -> fetchAndAnalyze(executionContext, executionResultMultiZipper.getZippers()));
return flatList(listListCF).thenApply(zippers -> new NodeMultiZipper<ExecutionResultNode>(commonRoot, zippers, RESULT_NODE_ADAPTER));
}
|
java
|
private CompletableFuture<NodeMultiZipper<ExecutionResultNode>> resolveNodes(ExecutionContext executionContext, List<NodeMultiZipper<ExecutionResultNode>> unresolvedNodes) {
assertNotEmpty(unresolvedNodes, "unresolvedNodes can't be empty");
ExecutionResultNode commonRoot = unresolvedNodes.get(0).getCommonRoot();
CompletableFuture<List<List<NodeZipper<ExecutionResultNode>>>> listListCF = Async.flatMap(unresolvedNodes,
executionResultMultiZipper -> fetchAndAnalyze(executionContext, executionResultMultiZipper.getZippers()));
return flatList(listListCF).thenApply(zippers -> new NodeMultiZipper<ExecutionResultNode>(commonRoot, zippers, RESULT_NODE_ADAPTER));
}
|
[
"private",
"CompletableFuture",
"<",
"NodeMultiZipper",
"<",
"ExecutionResultNode",
">",
">",
"resolveNodes",
"(",
"ExecutionContext",
"executionContext",
",",
"List",
"<",
"NodeMultiZipper",
"<",
"ExecutionResultNode",
">",
">",
"unresolvedNodes",
")",
"{",
"assertNotEmpty",
"(",
"unresolvedNodes",
",",
"\"unresolvedNodes can't be empty\"",
")",
";",
"ExecutionResultNode",
"commonRoot",
"=",
"unresolvedNodes",
".",
"get",
"(",
"0",
")",
".",
"getCommonRoot",
"(",
")",
";",
"CompletableFuture",
"<",
"List",
"<",
"List",
"<",
"NodeZipper",
"<",
"ExecutionResultNode",
">",
">",
">",
">",
"listListCF",
"=",
"Async",
".",
"flatMap",
"(",
"unresolvedNodes",
",",
"executionResultMultiZipper",
"->",
"fetchAndAnalyze",
"(",
"executionContext",
",",
"executionResultMultiZipper",
".",
"getZippers",
"(",
")",
")",
")",
";",
"return",
"flatList",
"(",
"listListCF",
")",
".",
"thenApply",
"(",
"zippers",
"->",
"new",
"NodeMultiZipper",
"<",
"ExecutionResultNode",
">",
"(",
"commonRoot",
",",
"zippers",
",",
"RESULT_NODE_ADAPTER",
")",
")",
";",
"}"
] |
all multizipper have the same root
|
[
"all",
"multizipper",
"have",
"the",
"same",
"root"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/nextgen/BatchedExecutionStrategy.java#L68-L75
|
13,853
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLFieldDefinition.java
|
GraphQLFieldDefinition.transform
|
public GraphQLFieldDefinition transform(Consumer<Builder> builderConsumer) {
Builder builder = newFieldDefinition(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLFieldDefinition transform(Consumer<Builder> builderConsumer) {
Builder builder = newFieldDefinition(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLFieldDefinition",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newFieldDefinition",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLFieldDefinition 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",
"GraphQLFieldDefinition",
"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/GraphQLFieldDefinition.java#L167-L171
|
13,854
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/instrumentation/SimpleInstrumentationContext.java
|
SimpleInstrumentationContext.whenDispatched
|
public static <U> SimpleInstrumentationContext<U> whenDispatched(Consumer<CompletableFuture<U>> codeToRun) {
return new SimpleInstrumentationContext<>(codeToRun, null);
}
|
java
|
public static <U> SimpleInstrumentationContext<U> whenDispatched(Consumer<CompletableFuture<U>> codeToRun) {
return new SimpleInstrumentationContext<>(codeToRun, null);
}
|
[
"public",
"static",
"<",
"U",
">",
"SimpleInstrumentationContext",
"<",
"U",
">",
"whenDispatched",
"(",
"Consumer",
"<",
"CompletableFuture",
"<",
"U",
">",
">",
"codeToRun",
")",
"{",
"return",
"new",
"SimpleInstrumentationContext",
"<>",
"(",
"codeToRun",
",",
"null",
")",
";",
"}"
] |
Allows for the more fluent away to return an instrumentation context that runs the specified
code on instrumentation step dispatch.
@param codeToRun the code to run on dispatch
@param <U> the generic type
@return an instrumentation context
|
[
"Allows",
"for",
"the",
"more",
"fluent",
"away",
"to",
"return",
"an",
"instrumentation",
"context",
"that",
"runs",
"the",
"specified",
"code",
"on",
"instrumentation",
"step",
"dispatch",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/instrumentation/SimpleInstrumentationContext.java#L61-L63
|
13,855
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/instrumentation/SimpleInstrumentationContext.java
|
SimpleInstrumentationContext.whenCompleted
|
public static <U> SimpleInstrumentationContext<U> whenCompleted(BiConsumer<U, Throwable> codeToRun) {
return new SimpleInstrumentationContext<>(null, codeToRun);
}
|
java
|
public static <U> SimpleInstrumentationContext<U> whenCompleted(BiConsumer<U, Throwable> codeToRun) {
return new SimpleInstrumentationContext<>(null, codeToRun);
}
|
[
"public",
"static",
"<",
"U",
">",
"SimpleInstrumentationContext",
"<",
"U",
">",
"whenCompleted",
"(",
"BiConsumer",
"<",
"U",
",",
"Throwable",
">",
"codeToRun",
")",
"{",
"return",
"new",
"SimpleInstrumentationContext",
"<>",
"(",
"null",
",",
"codeToRun",
")",
";",
"}"
] |
Allows for the more fluent away to return an instrumentation context that runs the specified
code on instrumentation step completion.
@param codeToRun the code to run on completion
@param <U> the generic type
@return an instrumentation context
|
[
"Allows",
"for",
"the",
"more",
"fluent",
"away",
"to",
"return",
"an",
"instrumentation",
"context",
"that",
"runs",
"the",
"specified",
"code",
"on",
"instrumentation",
"step",
"completion",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/instrumentation/SimpleInstrumentationContext.java#L74-L76
|
13,856
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/reactive/NonBlockingMutexExecutor.java
|
NonBlockingMutexExecutor.run
|
private void run(final RunNode current) {
try {
current.runnable.run();
} catch (final Throwable thrown) {
reportFailure(Thread.currentThread(), thrown);
}
}
|
java
|
private void run(final RunNode current) {
try {
current.runnable.run();
} catch (final Throwable thrown) {
reportFailure(Thread.currentThread(), thrown);
}
}
|
[
"private",
"void",
"run",
"(",
"final",
"RunNode",
"current",
")",
"{",
"try",
"{",
"current",
".",
"runnable",
".",
"run",
"(",
")",
";",
"}",
"catch",
"(",
"final",
"Throwable",
"thrown",
")",
"{",
"reportFailure",
"(",
"Thread",
".",
"currentThread",
"(",
")",
",",
"thrown",
")",
";",
"}",
"}"
] |
Runs a single RunNode and deals with any thing it throws
|
[
"Runs",
"a",
"single",
"RunNode",
"and",
"deals",
"with",
"any",
"thing",
"it",
"throws"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/reactive/NonBlockingMutexExecutor.java#L60-L66
|
13,857
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/reactive/NonBlockingMutexExecutor.java
|
NonBlockingMutexExecutor.runAll
|
private void runAll(RunNode next) {
for (; ; ) {
final RunNode current = next;
run(current);
if ((next = current.get()) == null) { // try advance, if we get null test
if (last.compareAndSet(current, null)) {
return; // end-of-queue: we're done.
} else {
//noinspection StatementWithEmptyBody
while ((next = current.get()) == null) {
// Thread.onSpinWait(); in Java 9
}
}
}
}
}
|
java
|
private void runAll(RunNode next) {
for (; ; ) {
final RunNode current = next;
run(current);
if ((next = current.get()) == null) { // try advance, if we get null test
if (last.compareAndSet(current, null)) {
return; // end-of-queue: we're done.
} else {
//noinspection StatementWithEmptyBody
while ((next = current.get()) == null) {
// Thread.onSpinWait(); in Java 9
}
}
}
}
}
|
[
"private",
"void",
"runAll",
"(",
"RunNode",
"next",
")",
"{",
"for",
"(",
";",
";",
")",
"{",
"final",
"RunNode",
"current",
"=",
"next",
";",
"run",
"(",
"current",
")",
";",
"if",
"(",
"(",
"next",
"=",
"current",
".",
"get",
"(",
")",
")",
"==",
"null",
")",
"{",
"// try advance, if we get null test",
"if",
"(",
"last",
".",
"compareAndSet",
"(",
"current",
",",
"null",
")",
")",
"{",
"return",
";",
"// end-of-queue: we're done.",
"}",
"else",
"{",
"//noinspection StatementWithEmptyBody",
"while",
"(",
"(",
"next",
"=",
"current",
".",
"get",
"(",
")",
")",
"==",
"null",
")",
"{",
"// Thread.onSpinWait(); in Java 9",
"}",
"}",
"}",
"}",
"}"
] |
Runs all the RunNodes starting with `next`
|
[
"Runs",
"all",
"the",
"RunNodes",
"starting",
"with",
"next"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/reactive/NonBlockingMutexExecutor.java#L69-L84
|
13,858
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/SchemaUtil.java
|
SchemaUtil.findImplementations
|
@Deprecated
public List<GraphQLObjectType> findImplementations(GraphQLSchema schema, GraphQLInterfaceType interfaceType) {
List<GraphQLObjectType> result = new ArrayList<>();
for (GraphQLType type : schema.getAllTypesAsList()) {
if (!(type instanceof GraphQLObjectType)) {
continue;
}
GraphQLObjectType objectType = (GraphQLObjectType) type;
if ((objectType).getInterfaces().contains(interfaceType)) {
result.add(objectType);
}
}
return result;
}
|
java
|
@Deprecated
public List<GraphQLObjectType> findImplementations(GraphQLSchema schema, GraphQLInterfaceType interfaceType) {
List<GraphQLObjectType> result = new ArrayList<>();
for (GraphQLType type : schema.getAllTypesAsList()) {
if (!(type instanceof GraphQLObjectType)) {
continue;
}
GraphQLObjectType objectType = (GraphQLObjectType) type;
if ((objectType).getInterfaces().contains(interfaceType)) {
result.add(objectType);
}
}
return result;
}
|
[
"@",
"Deprecated",
"public",
"List",
"<",
"GraphQLObjectType",
">",
"findImplementations",
"(",
"GraphQLSchema",
"schema",
",",
"GraphQLInterfaceType",
"interfaceType",
")",
"{",
"List",
"<",
"GraphQLObjectType",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"GraphQLType",
"type",
":",
"schema",
".",
"getAllTypesAsList",
"(",
")",
")",
"{",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"GraphQLObjectType",
")",
")",
"{",
"continue",
";",
"}",
"GraphQLObjectType",
"objectType",
"=",
"(",
"GraphQLObjectType",
")",
"type",
";",
"if",
"(",
"(",
"objectType",
")",
".",
"getInterfaces",
"(",
")",
".",
"contains",
"(",
"interfaceType",
")",
")",
"{",
"result",
".",
"add",
"(",
"objectType",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
This method is deprecated due to a performance concern.
The Algorithm complexity: O(n^2), where n is number of registered GraphQLTypes
That indexing operation is performed twice per input document:
1. during validation
2. during execution
We now indexed all types at the schema creation, which has brought complexity down to O(1)
@param schema GraphQL schema
@param interfaceType an interface type to find implementations for
@return List of object types implementing provided interface
@deprecated use {@link graphql.schema.GraphQLSchema#getImplementations(GraphQLInterfaceType)} instead
|
[
"This",
"method",
"is",
"deprecated",
"due",
"to",
"a",
"performance",
"concern",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/SchemaUtil.java#L87-L100
|
13,859
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/Async.java
|
Async.toCompletableFuture
|
public static <T> CompletableFuture<T> toCompletableFuture(T t) {
if (t instanceof CompletionStage) {
//noinspection unchecked
return ((CompletionStage<T>) t).toCompletableFuture();
} else {
return CompletableFuture.completedFuture(t);
}
}
|
java
|
public static <T> CompletableFuture<T> toCompletableFuture(T t) {
if (t instanceof CompletionStage) {
//noinspection unchecked
return ((CompletionStage<T>) t).toCompletableFuture();
} else {
return CompletableFuture.completedFuture(t);
}
}
|
[
"public",
"static",
"<",
"T",
">",
"CompletableFuture",
"<",
"T",
">",
"toCompletableFuture",
"(",
"T",
"t",
")",
"{",
"if",
"(",
"t",
"instanceof",
"CompletionStage",
")",
"{",
"//noinspection unchecked",
"return",
"(",
"(",
"CompletionStage",
"<",
"T",
">",
")",
"t",
")",
".",
"toCompletableFuture",
"(",
")",
";",
"}",
"else",
"{",
"return",
"CompletableFuture",
".",
"completedFuture",
"(",
"t",
")",
";",
"}",
"}"
] |
Turns an object T into a CompletableFuture if its not already
@param t - the object to check
@param <T> for two
@return a CompletableFuture
|
[
"Turns",
"an",
"object",
"T",
"into",
"a",
"CompletableFuture",
"if",
"its",
"not",
"already"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/Async.java#L102-L109
|
13,860
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.addAll
|
public Optional<GraphQLError> addAll(Collection<SDLDefinition> definitions) {
for (SDLDefinition definition : definitions) {
Optional<GraphQLError> error = add(definition);
if (error.isPresent()) {
return error;
}
}
return Optional.empty();
}
|
java
|
public Optional<GraphQLError> addAll(Collection<SDLDefinition> definitions) {
for (SDLDefinition definition : definitions) {
Optional<GraphQLError> error = add(definition);
if (error.isPresent()) {
return error;
}
}
return Optional.empty();
}
|
[
"public",
"Optional",
"<",
"GraphQLError",
">",
"addAll",
"(",
"Collection",
"<",
"SDLDefinition",
">",
"definitions",
")",
"{",
"for",
"(",
"SDLDefinition",
"definition",
":",
"definitions",
")",
"{",
"Optional",
"<",
"GraphQLError",
">",
"error",
"=",
"add",
"(",
"definition",
")",
";",
"if",
"(",
"error",
".",
"isPresent",
"(",
")",
")",
"{",
"return",
"error",
";",
"}",
"}",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}"
] |
Adds a a collections of definitions to the registry
@param definitions the definitions to add
@return an optional error for the first problem, typically type redefinition
|
[
"Adds",
"a",
"a",
"collections",
"of",
"definitions",
"to",
"the",
"registry"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L146-L154
|
13,861
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.add
|
public Optional<GraphQLError> add(SDLDefinition definition) {
// extensions
if (definition instanceof ObjectTypeExtensionDefinition) {
ObjectTypeExtensionDefinition newEntry = (ObjectTypeExtensionDefinition) definition;
return defineExt(objectTypeExtensions, newEntry, ObjectTypeExtensionDefinition::getName);
} else if (definition instanceof InterfaceTypeExtensionDefinition) {
InterfaceTypeExtensionDefinition newEntry = (InterfaceTypeExtensionDefinition) definition;
return defineExt(interfaceTypeExtensions, newEntry, InterfaceTypeExtensionDefinition::getName);
} else if (definition instanceof UnionTypeExtensionDefinition) {
UnionTypeExtensionDefinition newEntry = (UnionTypeExtensionDefinition) definition;
return defineExt(unionTypeExtensions, newEntry, UnionTypeExtensionDefinition::getName);
} else if (definition instanceof EnumTypeExtensionDefinition) {
EnumTypeExtensionDefinition newEntry = (EnumTypeExtensionDefinition) definition;
return defineExt(enumTypeExtensions, newEntry, EnumTypeExtensionDefinition::getName);
} else if (definition instanceof ScalarTypeExtensionDefinition) {
ScalarTypeExtensionDefinition newEntry = (ScalarTypeExtensionDefinition) definition;
return defineExt(scalarTypeExtensions, newEntry, ScalarTypeExtensionDefinition::getName);
} else if (definition instanceof InputObjectTypeExtensionDefinition) {
InputObjectTypeExtensionDefinition newEntry = (InputObjectTypeExtensionDefinition) definition;
return defineExt(inputObjectTypeExtensions, newEntry, InputObjectTypeExtensionDefinition::getName);
//
// normal
} else if (definition instanceof ScalarTypeDefinition) {
ScalarTypeDefinition newEntry = (ScalarTypeDefinition) definition;
return define(scalarTypes, scalarTypes, newEntry);
} else if (definition instanceof TypeDefinition) {
TypeDefinition newEntry = (TypeDefinition) definition;
return define(types, types, newEntry);
} else if (definition instanceof DirectiveDefinition) {
DirectiveDefinition newEntry = (DirectiveDefinition) definition;
return define(directiveDefinitions, directiveDefinitions, newEntry);
} else if (definition instanceof SchemaDefinition) {
SchemaDefinition newSchema = (SchemaDefinition) definition;
if (schema != null) {
return Optional.of(new SchemaRedefinitionError(this.schema, newSchema));
} else {
schema = newSchema;
}
} else {
return Assert.assertShouldNeverHappen();
}
return Optional.empty();
}
|
java
|
public Optional<GraphQLError> add(SDLDefinition definition) {
// extensions
if (definition instanceof ObjectTypeExtensionDefinition) {
ObjectTypeExtensionDefinition newEntry = (ObjectTypeExtensionDefinition) definition;
return defineExt(objectTypeExtensions, newEntry, ObjectTypeExtensionDefinition::getName);
} else if (definition instanceof InterfaceTypeExtensionDefinition) {
InterfaceTypeExtensionDefinition newEntry = (InterfaceTypeExtensionDefinition) definition;
return defineExt(interfaceTypeExtensions, newEntry, InterfaceTypeExtensionDefinition::getName);
} else if (definition instanceof UnionTypeExtensionDefinition) {
UnionTypeExtensionDefinition newEntry = (UnionTypeExtensionDefinition) definition;
return defineExt(unionTypeExtensions, newEntry, UnionTypeExtensionDefinition::getName);
} else if (definition instanceof EnumTypeExtensionDefinition) {
EnumTypeExtensionDefinition newEntry = (EnumTypeExtensionDefinition) definition;
return defineExt(enumTypeExtensions, newEntry, EnumTypeExtensionDefinition::getName);
} else if (definition instanceof ScalarTypeExtensionDefinition) {
ScalarTypeExtensionDefinition newEntry = (ScalarTypeExtensionDefinition) definition;
return defineExt(scalarTypeExtensions, newEntry, ScalarTypeExtensionDefinition::getName);
} else if (definition instanceof InputObjectTypeExtensionDefinition) {
InputObjectTypeExtensionDefinition newEntry = (InputObjectTypeExtensionDefinition) definition;
return defineExt(inputObjectTypeExtensions, newEntry, InputObjectTypeExtensionDefinition::getName);
//
// normal
} else if (definition instanceof ScalarTypeDefinition) {
ScalarTypeDefinition newEntry = (ScalarTypeDefinition) definition;
return define(scalarTypes, scalarTypes, newEntry);
} else if (definition instanceof TypeDefinition) {
TypeDefinition newEntry = (TypeDefinition) definition;
return define(types, types, newEntry);
} else if (definition instanceof DirectiveDefinition) {
DirectiveDefinition newEntry = (DirectiveDefinition) definition;
return define(directiveDefinitions, directiveDefinitions, newEntry);
} else if (definition instanceof SchemaDefinition) {
SchemaDefinition newSchema = (SchemaDefinition) definition;
if (schema != null) {
return Optional.of(new SchemaRedefinitionError(this.schema, newSchema));
} else {
schema = newSchema;
}
} else {
return Assert.assertShouldNeverHappen();
}
return Optional.empty();
}
|
[
"public",
"Optional",
"<",
"GraphQLError",
">",
"add",
"(",
"SDLDefinition",
"definition",
")",
"{",
"// extensions",
"if",
"(",
"definition",
"instanceof",
"ObjectTypeExtensionDefinition",
")",
"{",
"ObjectTypeExtensionDefinition",
"newEntry",
"=",
"(",
"ObjectTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"objectTypeExtensions",
",",
"newEntry",
",",
"ObjectTypeExtensionDefinition",
"::",
"getName",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"InterfaceTypeExtensionDefinition",
")",
"{",
"InterfaceTypeExtensionDefinition",
"newEntry",
"=",
"(",
"InterfaceTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"interfaceTypeExtensions",
",",
"newEntry",
",",
"InterfaceTypeExtensionDefinition",
"::",
"getName",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"UnionTypeExtensionDefinition",
")",
"{",
"UnionTypeExtensionDefinition",
"newEntry",
"=",
"(",
"UnionTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"unionTypeExtensions",
",",
"newEntry",
",",
"UnionTypeExtensionDefinition",
"::",
"getName",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"EnumTypeExtensionDefinition",
")",
"{",
"EnumTypeExtensionDefinition",
"newEntry",
"=",
"(",
"EnumTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"enumTypeExtensions",
",",
"newEntry",
",",
"EnumTypeExtensionDefinition",
"::",
"getName",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"ScalarTypeExtensionDefinition",
")",
"{",
"ScalarTypeExtensionDefinition",
"newEntry",
"=",
"(",
"ScalarTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"scalarTypeExtensions",
",",
"newEntry",
",",
"ScalarTypeExtensionDefinition",
"::",
"getName",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"InputObjectTypeExtensionDefinition",
")",
"{",
"InputObjectTypeExtensionDefinition",
"newEntry",
"=",
"(",
"InputObjectTypeExtensionDefinition",
")",
"definition",
";",
"return",
"defineExt",
"(",
"inputObjectTypeExtensions",
",",
"newEntry",
",",
"InputObjectTypeExtensionDefinition",
"::",
"getName",
")",
";",
"//",
"// normal",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"ScalarTypeDefinition",
")",
"{",
"ScalarTypeDefinition",
"newEntry",
"=",
"(",
"ScalarTypeDefinition",
")",
"definition",
";",
"return",
"define",
"(",
"scalarTypes",
",",
"scalarTypes",
",",
"newEntry",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"TypeDefinition",
")",
"{",
"TypeDefinition",
"newEntry",
"=",
"(",
"TypeDefinition",
")",
"definition",
";",
"return",
"define",
"(",
"types",
",",
"types",
",",
"newEntry",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"DirectiveDefinition",
")",
"{",
"DirectiveDefinition",
"newEntry",
"=",
"(",
"DirectiveDefinition",
")",
"definition",
";",
"return",
"define",
"(",
"directiveDefinitions",
",",
"directiveDefinitions",
",",
"newEntry",
")",
";",
"}",
"else",
"if",
"(",
"definition",
"instanceof",
"SchemaDefinition",
")",
"{",
"SchemaDefinition",
"newSchema",
"=",
"(",
"SchemaDefinition",
")",
"definition",
";",
"if",
"(",
"schema",
"!=",
"null",
")",
"{",
"return",
"Optional",
".",
"of",
"(",
"new",
"SchemaRedefinitionError",
"(",
"this",
".",
"schema",
",",
"newSchema",
")",
")",
";",
"}",
"else",
"{",
"schema",
"=",
"newSchema",
";",
"}",
"}",
"else",
"{",
"return",
"Assert",
".",
"assertShouldNeverHappen",
"(",
")",
";",
"}",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}"
] |
Adds a definition to the registry
@param definition the definition to add
@return an optional error
|
[
"Adds",
"a",
"definition",
"to",
"the",
"registry"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L163-L205
|
13,862
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.getTypes
|
public <T extends TypeDefinition> List<T> getTypes(Class<T> targetClass) {
return types.values().stream()
.filter(targetClass::isInstance)
.map(targetClass::cast)
.collect(Collectors.toList());
}
|
java
|
public <T extends TypeDefinition> List<T> getTypes(Class<T> targetClass) {
return types.values().stream()
.filter(targetClass::isInstance)
.map(targetClass::cast)
.collect(Collectors.toList());
}
|
[
"public",
"<",
"T",
"extends",
"TypeDefinition",
">",
"List",
"<",
"T",
">",
"getTypes",
"(",
"Class",
"<",
"T",
">",
"targetClass",
")",
"{",
"return",
"types",
".",
"values",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"targetClass",
"::",
"isInstance",
")",
".",
"map",
"(",
"targetClass",
"::",
"cast",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"}"
] |
Returns a list of types in the registry of that specified class
@param targetClass the class to search for
@param <T> must extend TypeDefinition
@return a list of types of the target class
|
[
"Returns",
"a",
"list",
"of",
"types",
"in",
"the",
"registry",
"of",
"that",
"specified",
"class"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L401-L406
|
13,863
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.getTypesMap
|
public <T extends TypeDefinition> Map<String, T> getTypesMap(Class<T> targetClass) {
List<T> list = getTypes(targetClass);
return FpKit.getByName(list, TypeDefinition::getName, FpKit.mergeFirst());
}
|
java
|
public <T extends TypeDefinition> Map<String, T> getTypesMap(Class<T> targetClass) {
List<T> list = getTypes(targetClass);
return FpKit.getByName(list, TypeDefinition::getName, FpKit.mergeFirst());
}
|
[
"public",
"<",
"T",
"extends",
"TypeDefinition",
">",
"Map",
"<",
"String",
",",
"T",
">",
"getTypesMap",
"(",
"Class",
"<",
"T",
">",
"targetClass",
")",
"{",
"List",
"<",
"T",
">",
"list",
"=",
"getTypes",
"(",
"targetClass",
")",
";",
"return",
"FpKit",
".",
"getByName",
"(",
"list",
",",
"TypeDefinition",
"::",
"getName",
",",
"FpKit",
".",
"mergeFirst",
"(",
")",
")",
";",
"}"
] |
Returns a map of types in the registry of that specified class keyed by name
@param targetClass the class to search for
@param <T> must extend TypeDefinition
@return a map of types
|
[
"Returns",
"a",
"map",
"of",
"types",
"in",
"the",
"registry",
"of",
"that",
"specified",
"class",
"keyed",
"by",
"name"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L416-L419
|
13,864
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.getImplementationsOf
|
public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) {
List<ObjectTypeDefinition> objectTypeDefinitions = getTypes(ObjectTypeDefinition.class);
return objectTypeDefinitions.stream().filter(objectTypeDefinition -> {
List<Type> implementsList = objectTypeDefinition.getImplements();
for (Type iFace : implementsList) {
Optional<InterfaceTypeDefinition> interfaceTypeDef = getType(iFace, InterfaceTypeDefinition.class);
if (interfaceTypeDef.isPresent()) {
boolean equals = interfaceTypeDef.get().getName().equals(targetInterface.getName());
if (equals) {
return true;
}
}
}
return false;
}).collect(Collectors.toList());
}
|
java
|
public List<ObjectTypeDefinition> getImplementationsOf(InterfaceTypeDefinition targetInterface) {
List<ObjectTypeDefinition> objectTypeDefinitions = getTypes(ObjectTypeDefinition.class);
return objectTypeDefinitions.stream().filter(objectTypeDefinition -> {
List<Type> implementsList = objectTypeDefinition.getImplements();
for (Type iFace : implementsList) {
Optional<InterfaceTypeDefinition> interfaceTypeDef = getType(iFace, InterfaceTypeDefinition.class);
if (interfaceTypeDef.isPresent()) {
boolean equals = interfaceTypeDef.get().getName().equals(targetInterface.getName());
if (equals) {
return true;
}
}
}
return false;
}).collect(Collectors.toList());
}
|
[
"public",
"List",
"<",
"ObjectTypeDefinition",
">",
"getImplementationsOf",
"(",
"InterfaceTypeDefinition",
"targetInterface",
")",
"{",
"List",
"<",
"ObjectTypeDefinition",
">",
"objectTypeDefinitions",
"=",
"getTypes",
"(",
"ObjectTypeDefinition",
".",
"class",
")",
";",
"return",
"objectTypeDefinitions",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"objectTypeDefinition",
"->",
"{",
"List",
"<",
"Type",
">",
"implementsList",
"=",
"objectTypeDefinition",
".",
"getImplements",
"(",
")",
";",
"for",
"(",
"Type",
"iFace",
":",
"implementsList",
")",
"{",
"Optional",
"<",
"InterfaceTypeDefinition",
">",
"interfaceTypeDef",
"=",
"getType",
"(",
"iFace",
",",
"InterfaceTypeDefinition",
".",
"class",
")",
";",
"if",
"(",
"interfaceTypeDef",
".",
"isPresent",
"(",
")",
")",
"{",
"boolean",
"equals",
"=",
"interfaceTypeDef",
".",
"get",
"(",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"targetInterface",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"equals",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"}"
] |
Returns the list of object types that implement the given interface type
@param targetInterface the target to search for
@return the list of object types that implement the given interface type
|
[
"Returns",
"the",
"list",
"of",
"object",
"types",
"that",
"implement",
"the",
"given",
"interface",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L428-L443
|
13,865
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
|
TypeDefinitionRegistry.isPossibleType
|
@SuppressWarnings("ConstantConditions")
public boolean isPossibleType(Type abstractType, Type possibleObjectType) {
if (!isInterfaceOrUnion(abstractType)) {
return false;
}
if (!isObjectType(possibleObjectType)) {
return false;
}
ObjectTypeDefinition targetObjectTypeDef = getType(possibleObjectType, ObjectTypeDefinition.class).get();
TypeDefinition abstractTypeDef = getType(abstractType).get();
if (abstractTypeDef instanceof UnionTypeDefinition) {
List<Type> memberTypes = ((UnionTypeDefinition) abstractTypeDef).getMemberTypes();
for (Type memberType : memberTypes) {
Optional<ObjectTypeDefinition> checkType = getType(memberType, ObjectTypeDefinition.class);
if (checkType.isPresent()) {
if (checkType.get().getName().equals(targetObjectTypeDef.getName())) {
return true;
}
}
}
return false;
} else {
InterfaceTypeDefinition iFace = (InterfaceTypeDefinition) abstractTypeDef;
List<ObjectTypeDefinition> objectTypeDefinitions = getImplementationsOf(iFace);
return objectTypeDefinitions.stream()
.anyMatch(od -> od.getName().equals(targetObjectTypeDef.getName()));
}
}
|
java
|
@SuppressWarnings("ConstantConditions")
public boolean isPossibleType(Type abstractType, Type possibleObjectType) {
if (!isInterfaceOrUnion(abstractType)) {
return false;
}
if (!isObjectType(possibleObjectType)) {
return false;
}
ObjectTypeDefinition targetObjectTypeDef = getType(possibleObjectType, ObjectTypeDefinition.class).get();
TypeDefinition abstractTypeDef = getType(abstractType).get();
if (abstractTypeDef instanceof UnionTypeDefinition) {
List<Type> memberTypes = ((UnionTypeDefinition) abstractTypeDef).getMemberTypes();
for (Type memberType : memberTypes) {
Optional<ObjectTypeDefinition> checkType = getType(memberType, ObjectTypeDefinition.class);
if (checkType.isPresent()) {
if (checkType.get().getName().equals(targetObjectTypeDef.getName())) {
return true;
}
}
}
return false;
} else {
InterfaceTypeDefinition iFace = (InterfaceTypeDefinition) abstractTypeDef;
List<ObjectTypeDefinition> objectTypeDefinitions = getImplementationsOf(iFace);
return objectTypeDefinitions.stream()
.anyMatch(od -> od.getName().equals(targetObjectTypeDef.getName()));
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"ConstantConditions\"",
")",
"public",
"boolean",
"isPossibleType",
"(",
"Type",
"abstractType",
",",
"Type",
"possibleObjectType",
")",
"{",
"if",
"(",
"!",
"isInterfaceOrUnion",
"(",
"abstractType",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isObjectType",
"(",
"possibleObjectType",
")",
")",
"{",
"return",
"false",
";",
"}",
"ObjectTypeDefinition",
"targetObjectTypeDef",
"=",
"getType",
"(",
"possibleObjectType",
",",
"ObjectTypeDefinition",
".",
"class",
")",
".",
"get",
"(",
")",
";",
"TypeDefinition",
"abstractTypeDef",
"=",
"getType",
"(",
"abstractType",
")",
".",
"get",
"(",
")",
";",
"if",
"(",
"abstractTypeDef",
"instanceof",
"UnionTypeDefinition",
")",
"{",
"List",
"<",
"Type",
">",
"memberTypes",
"=",
"(",
"(",
"UnionTypeDefinition",
")",
"abstractTypeDef",
")",
".",
"getMemberTypes",
"(",
")",
";",
"for",
"(",
"Type",
"memberType",
":",
"memberTypes",
")",
"{",
"Optional",
"<",
"ObjectTypeDefinition",
">",
"checkType",
"=",
"getType",
"(",
"memberType",
",",
"ObjectTypeDefinition",
".",
"class",
")",
";",
"if",
"(",
"checkType",
".",
"isPresent",
"(",
")",
")",
"{",
"if",
"(",
"checkType",
".",
"get",
"(",
")",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"targetObjectTypeDef",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}",
"else",
"{",
"InterfaceTypeDefinition",
"iFace",
"=",
"(",
"InterfaceTypeDefinition",
")",
"abstractTypeDef",
";",
"List",
"<",
"ObjectTypeDefinition",
">",
"objectTypeDefinitions",
"=",
"getImplementationsOf",
"(",
"iFace",
")",
";",
"return",
"objectTypeDefinitions",
".",
"stream",
"(",
")",
".",
"anyMatch",
"(",
"od",
"->",
"od",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"targetObjectTypeDef",
".",
"getName",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Returns true of the abstract type is in implemented by the object type
@param abstractType the abstract type to check (interface or union)
@param possibleObjectType the object type to check
@return true if the object type implements the abstract type
|
[
"Returns",
"true",
"of",
"the",
"abstract",
"type",
"is",
"in",
"implemented",
"by",
"the",
"object",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java#L453-L480
|
13,866
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionPath.java
|
ExecutionPath.fromList
|
public static ExecutionPath fromList(List<?> objects) {
assertNotNull(objects);
ExecutionPath path = ExecutionPath.rootPath();
for (Object object : objects) {
if (object instanceof Number) {
path = path.segment(((Number) object).intValue());
} else {
path = path.segment(String.valueOf(object));
}
}
return path;
}
|
java
|
public static ExecutionPath fromList(List<?> objects) {
assertNotNull(objects);
ExecutionPath path = ExecutionPath.rootPath();
for (Object object : objects) {
if (object instanceof Number) {
path = path.segment(((Number) object).intValue());
} else {
path = path.segment(String.valueOf(object));
}
}
return path;
}
|
[
"public",
"static",
"ExecutionPath",
"fromList",
"(",
"List",
"<",
"?",
">",
"objects",
")",
"{",
"assertNotNull",
"(",
"objects",
")",
";",
"ExecutionPath",
"path",
"=",
"ExecutionPath",
".",
"rootPath",
"(",
")",
";",
"for",
"(",
"Object",
"object",
":",
"objects",
")",
"{",
"if",
"(",
"object",
"instanceof",
"Number",
")",
"{",
"path",
"=",
"path",
".",
"segment",
"(",
"(",
"(",
"Number",
")",
"object",
")",
".",
"intValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"path",
"=",
"path",
".",
"segment",
"(",
"String",
".",
"valueOf",
"(",
"object",
")",
")",
";",
"}",
"}",
"return",
"path",
";",
"}"
] |
This will create an execution path from the list of objects
@param objects the path objects
@return a new execution path
|
[
"This",
"will",
"create",
"an",
"execution",
"path",
"from",
"the",
"list",
"of",
"objects"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionPath.java#L119-L130
|
13,867
|
graphql-java/graphql-java
|
src/main/java/graphql/language/AstPrinter.java
|
AstPrinter.printAst
|
public static String printAst(Node node) {
StringWriter sw = new StringWriter();
printAst(sw, node);
return sw.toString();
}
|
java
|
public static String printAst(Node node) {
StringWriter sw = new StringWriter();
printAst(sw, node);
return sw.toString();
}
|
[
"public",
"static",
"String",
"printAst",
"(",
"Node",
"node",
")",
"{",
"StringWriter",
"sw",
"=",
"new",
"StringWriter",
"(",
")",
";",
"printAst",
"(",
"sw",
",",
"node",
")",
";",
"return",
"sw",
".",
"toString",
"(",
")",
";",
"}"
] |
This will pretty print the AST node in graphql language format
@param node the AST node to print
@return the printed node in graphql language format
|
[
"This",
"will",
"pretty",
"print",
"the",
"AST",
"node",
"in",
"graphql",
"language",
"format"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/language/AstPrinter.java#L576-L580
|
13,868
|
graphql-java/graphql-java
|
src/main/java/graphql/language/AstPrinter.java
|
AstPrinter.printAstCompact
|
public static String printAstCompact(Node node) {
StringWriter sw = new StringWriter();
printImpl(sw, node, true);
return sw.toString();
}
|
java
|
public static String printAstCompact(Node node) {
StringWriter sw = new StringWriter();
printImpl(sw, node, true);
return sw.toString();
}
|
[
"public",
"static",
"String",
"printAstCompact",
"(",
"Node",
"node",
")",
"{",
"StringWriter",
"sw",
"=",
"new",
"StringWriter",
"(",
")",
";",
"printImpl",
"(",
"sw",
",",
"node",
",",
"true",
")",
";",
"return",
"sw",
".",
"toString",
"(",
")",
";",
"}"
] |
This will print the Ast node in graphql language format in a compact manner, with no new lines
and comments stripped out of the text.
@param node the AST node to print
@return the printed node in a compact graphql language format
|
[
"This",
"will",
"print",
"the",
"Ast",
"node",
"in",
"graphql",
"language",
"format",
"in",
"a",
"compact",
"manner",
"with",
"no",
"new",
"lines",
"and",
"comments",
"stripped",
"out",
"of",
"the",
"text",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/language/AstPrinter.java#L600-L604
|
13,869
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLSchema.java
|
GraphQLSchema.transform
|
public GraphQLSchema transform(Consumer<Builder> builderConsumer) {
Builder builder = newSchema(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLSchema transform(Consumer<Builder> builderConsumer) {
Builder builder = newSchema(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLSchema",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newSchema",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLSchema 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 GraphQLSchema object based on calling build on that builder
|
[
"This",
"helps",
"you",
"transform",
"the",
"current",
"GraphQLSchema",
"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/schema/GraphQLSchema.java#L252-L256
|
13,870
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLSchema.java
|
GraphQLSchema.newSchema
|
public static Builder newSchema(GraphQLSchema existingSchema) {
return new Builder()
.query(existingSchema.getQueryType())
.mutation(existingSchema.getMutationType())
.subscription(existingSchema.getSubscriptionType())
.codeRegistry(existingSchema.getCodeRegistry())
.clearAdditionalTypes()
.clearDirectives()
.additionalDirectives(existingSchema.directives)
.additionalTypes(existingSchema.additionalTypes);
}
|
java
|
public static Builder newSchema(GraphQLSchema existingSchema) {
return new Builder()
.query(existingSchema.getQueryType())
.mutation(existingSchema.getMutationType())
.subscription(existingSchema.getSubscriptionType())
.codeRegistry(existingSchema.getCodeRegistry())
.clearAdditionalTypes()
.clearDirectives()
.additionalDirectives(existingSchema.directives)
.additionalTypes(existingSchema.additionalTypes);
}
|
[
"public",
"static",
"Builder",
"newSchema",
"(",
"GraphQLSchema",
"existingSchema",
")",
"{",
"return",
"new",
"Builder",
"(",
")",
".",
"query",
"(",
"existingSchema",
".",
"getQueryType",
"(",
")",
")",
".",
"mutation",
"(",
"existingSchema",
".",
"getMutationType",
"(",
")",
")",
".",
"subscription",
"(",
"existingSchema",
".",
"getSubscriptionType",
"(",
")",
")",
".",
"codeRegistry",
"(",
"existingSchema",
".",
"getCodeRegistry",
"(",
")",
")",
".",
"clearAdditionalTypes",
"(",
")",
".",
"clearDirectives",
"(",
")",
".",
"additionalDirectives",
"(",
"existingSchema",
".",
"directives",
")",
".",
"additionalTypes",
"(",
"existingSchema",
".",
"additionalTypes",
")",
";",
"}"
] |
This allows you to build a schema from an existing schema. It copies everything from the existing
schema and then allows you to replace them.
@param existingSchema the existing schema
@return a new schema builder
|
[
"This",
"allows",
"you",
"to",
"build",
"a",
"schema",
"from",
"an",
"existing",
"schema",
".",
"It",
"copies",
"everything",
"from",
"the",
"existing",
"schema",
"and",
"then",
"allows",
"you",
"to",
"replace",
"them",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLSchema.java#L273-L283
|
13,871
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.getByName
|
public static <T> Map<String, T> getByName(List<T> namedObjects, Function<T, String> nameFn, BinaryOperator<T> mergeFunc) {
return namedObjects.stream().collect(Collectors.toMap(
nameFn,
identity(),
mergeFunc,
LinkedHashMap::new)
);
}
|
java
|
public static <T> Map<String, T> getByName(List<T> namedObjects, Function<T, String> nameFn, BinaryOperator<T> mergeFunc) {
return namedObjects.stream().collect(Collectors.toMap(
nameFn,
identity(),
mergeFunc,
LinkedHashMap::new)
);
}
|
[
"public",
"static",
"<",
"T",
">",
"Map",
"<",
"String",
",",
"T",
">",
"getByName",
"(",
"List",
"<",
"T",
">",
"namedObjects",
",",
"Function",
"<",
"T",
",",
"String",
">",
"nameFn",
",",
"BinaryOperator",
"<",
"T",
">",
"mergeFunc",
")",
"{",
"return",
"namedObjects",
".",
"stream",
"(",
")",
".",
"collect",
"(",
"Collectors",
".",
"toMap",
"(",
"nameFn",
",",
"identity",
"(",
")",
",",
"mergeFunc",
",",
"LinkedHashMap",
"::",
"new",
")",
")",
";",
"}"
] |
From a list of named things, get a map of them by name, merging them according to the merge function
|
[
"From",
"a",
"list",
"of",
"named",
"things",
"get",
"a",
"map",
"of",
"them",
"by",
"name",
"merging",
"them",
"according",
"to",
"the",
"merge",
"function"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L31-L38
|
13,872
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.groupingBy
|
public static <T, NewKey> Map<NewKey, List<T>> groupingBy(List<T> list, Function<T, NewKey> function) {
return list.stream().collect(Collectors.groupingBy(function, LinkedHashMap::new, mapping(Function.identity(), Collectors.toList())));
}
|
java
|
public static <T, NewKey> Map<NewKey, List<T>> groupingBy(List<T> list, Function<T, NewKey> function) {
return list.stream().collect(Collectors.groupingBy(function, LinkedHashMap::new, mapping(Function.identity(), Collectors.toList())));
}
|
[
"public",
"static",
"<",
"T",
",",
"NewKey",
">",
"Map",
"<",
"NewKey",
",",
"List",
"<",
"T",
">",
">",
"groupingBy",
"(",
"List",
"<",
"T",
">",
"list",
",",
"Function",
"<",
"T",
",",
"NewKey",
">",
"function",
")",
"{",
"return",
"list",
".",
"stream",
"(",
")",
".",
"collect",
"(",
"Collectors",
".",
"groupingBy",
"(",
"function",
",",
"LinkedHashMap",
"::",
"new",
",",
"mapping",
"(",
"Function",
".",
"identity",
"(",
")",
",",
"Collectors",
".",
"toList",
"(",
")",
")",
")",
")",
";",
"}"
] |
normal groupingBy but with LinkedHashMap
|
[
"normal",
"groupingBy",
"but",
"with",
"LinkedHashMap"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L41-L43
|
13,873
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.getByName
|
public static <T> Map<String, T> getByName(List<T> namedObjects, Function<T, String> nameFn) {
return getByName(namedObjects, nameFn, mergeFirst());
}
|
java
|
public static <T> Map<String, T> getByName(List<T> namedObjects, Function<T, String> nameFn) {
return getByName(namedObjects, nameFn, mergeFirst());
}
|
[
"public",
"static",
"<",
"T",
">",
"Map",
"<",
"String",
",",
"T",
">",
"getByName",
"(",
"List",
"<",
"T",
">",
"namedObjects",
",",
"Function",
"<",
"T",
",",
"String",
">",
"nameFn",
")",
"{",
"return",
"getByName",
"(",
"namedObjects",
",",
"nameFn",
",",
"mergeFirst",
"(",
")",
")",
";",
"}"
] |
From a list of named things, get a map of them by name, merging them first one added
|
[
"From",
"a",
"list",
"of",
"named",
"things",
"get",
"a",
"map",
"of",
"them",
"by",
"name",
"merging",
"them",
"first",
"one",
"added"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L47-L49
|
13,874
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.toCollection
|
@SuppressWarnings("unchecked")
public static <T> Collection<T> toCollection(Object iterableResult) {
if (iterableResult.getClass().isArray()) {
List<Object> collect = IntStream.range(0, Array.getLength(iterableResult))
.mapToObj(i -> Array.get(iterableResult, i))
.collect(Collectors.toList());
return (List<T>) collect;
}
if (iterableResult instanceof Collection) {
return (Collection<T>) iterableResult;
}
Iterable<T> iterable = (Iterable<T>) iterableResult;
Iterator<T> iterator = iterable.iterator();
List<T> list = new ArrayList<>();
while (iterator.hasNext()) {
list.add(iterator.next());
}
return list;
}
|
java
|
@SuppressWarnings("unchecked")
public static <T> Collection<T> toCollection(Object iterableResult) {
if (iterableResult.getClass().isArray()) {
List<Object> collect = IntStream.range(0, Array.getLength(iterableResult))
.mapToObj(i -> Array.get(iterableResult, i))
.collect(Collectors.toList());
return (List<T>) collect;
}
if (iterableResult instanceof Collection) {
return (Collection<T>) iterableResult;
}
Iterable<T> iterable = (Iterable<T>) iterableResult;
Iterator<T> iterator = iterable.iterator();
List<T> list = new ArrayList<>();
while (iterator.hasNext()) {
list.add(iterator.next());
}
return list;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"<",
"T",
">",
"Collection",
"<",
"T",
">",
"toCollection",
"(",
"Object",
"iterableResult",
")",
"{",
"if",
"(",
"iterableResult",
".",
"getClass",
"(",
")",
".",
"isArray",
"(",
")",
")",
"{",
"List",
"<",
"Object",
">",
"collect",
"=",
"IntStream",
".",
"range",
"(",
"0",
",",
"Array",
".",
"getLength",
"(",
"iterableResult",
")",
")",
".",
"mapToObj",
"(",
"i",
"->",
"Array",
".",
"get",
"(",
"iterableResult",
",",
"i",
")",
")",
".",
"collect",
"(",
"Collectors",
".",
"toList",
"(",
")",
")",
";",
"return",
"(",
"List",
"<",
"T",
">",
")",
"collect",
";",
"}",
"if",
"(",
"iterableResult",
"instanceof",
"Collection",
")",
"{",
"return",
"(",
"Collection",
"<",
"T",
">",
")",
"iterableResult",
";",
"}",
"Iterable",
"<",
"T",
">",
"iterable",
"=",
"(",
"Iterable",
"<",
"T",
">",
")",
"iterableResult",
";",
"Iterator",
"<",
"T",
">",
"iterator",
"=",
"iterable",
".",
"iterator",
"(",
")",
";",
"List",
"<",
"T",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"while",
"(",
"iterator",
".",
"hasNext",
"(",
")",
")",
"{",
"list",
".",
"add",
"(",
"iterator",
".",
"next",
"(",
")",
")",
";",
"}",
"return",
"list",
";",
"}"
] |
Converts an object that should be an Iterable into a Collection efficiently, leaving
it alone if it is already is one. Useful when you want to get the size of something
@param iterableResult the result object
@param <T> the type of thing
@return an Iterable from that object
@throws java.lang.ClassCastException if its not an Iterable
|
[
"Converts",
"an",
"object",
"that",
"should",
"be",
"an",
"Iterable",
"into",
"a",
"Collection",
"efficiently",
"leaving",
"it",
"alone",
"if",
"it",
"is",
"already",
"is",
"one",
".",
"Useful",
"when",
"you",
"want",
"to",
"get",
"the",
"size",
"of",
"something"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L66-L84
|
13,875
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.concat
|
public static <T> List<T> concat(List<T> l1, List<T> l2) {
ArrayList<T> l = new ArrayList<>(l1);
l.addAll(l2);
l.trimToSize();
return l;
}
|
java
|
public static <T> List<T> concat(List<T> l1, List<T> l2) {
ArrayList<T> l = new ArrayList<>(l1);
l.addAll(l2);
l.trimToSize();
return l;
}
|
[
"public",
"static",
"<",
"T",
">",
"List",
"<",
"T",
">",
"concat",
"(",
"List",
"<",
"T",
">",
"l1",
",",
"List",
"<",
"T",
">",
"l2",
")",
"{",
"ArrayList",
"<",
"T",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
"l1",
")",
";",
"l",
".",
"addAll",
"(",
"l2",
")",
";",
"l",
".",
"trimToSize",
"(",
")",
";",
"return",
"l",
";",
"}"
] |
Concatenates two lists into one
@param l1 the first list to concatenate
@param l2 the second list to concatenate
@param <T> the type of element of the lists
@return a <strong>new</strong> list composed of the two concatenated lists elements
|
[
"Concatenates",
"two",
"lists",
"into",
"one"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L108-L113
|
13,876
|
graphql-java/graphql-java
|
src/main/java/graphql/util/FpKit.java
|
FpKit.valuesToList
|
public static <T> List<T> valuesToList(Map<?, T> map) {
return new ArrayList<>(map.values());
}
|
java
|
public static <T> List<T> valuesToList(Map<?, T> map) {
return new ArrayList<>(map.values());
}
|
[
"public",
"static",
"<",
"T",
">",
"List",
"<",
"T",
">",
"valuesToList",
"(",
"Map",
"<",
"?",
",",
"T",
">",
"map",
")",
"{",
"return",
"new",
"ArrayList",
"<>",
"(",
"map",
".",
"values",
"(",
")",
")",
";",
"}"
] |
quickly turn a map of values into its list equivalent
|
[
"quickly",
"turn",
"a",
"map",
"of",
"values",
"into",
"its",
"list",
"equivalent"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/util/FpKit.java#L117-L119
|
13,877
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/TypeRuntimeWiring.java
|
TypeRuntimeWiring.newTypeWiring
|
public static TypeRuntimeWiring newTypeWiring(String typeName, UnaryOperator<Builder> builderFunction) {
return builderFunction.apply(newTypeWiring(typeName)).build();
}
|
java
|
public static TypeRuntimeWiring newTypeWiring(String typeName, UnaryOperator<Builder> builderFunction) {
return builderFunction.apply(newTypeWiring(typeName)).build();
}
|
[
"public",
"static",
"TypeRuntimeWiring",
"newTypeWiring",
"(",
"String",
"typeName",
",",
"UnaryOperator",
"<",
"Builder",
">",
"builderFunction",
")",
"{",
"return",
"builderFunction",
".",
"apply",
"(",
"newTypeWiring",
"(",
"typeName",
")",
")",
".",
"build",
"(",
")",
";",
"}"
] |
This form allows a lambda to be used as the builder
@param typeName the name of the type to wire
@param builderFunction a function that will be given the builder to use
@return the same builder back please
|
[
"This",
"form",
"allows",
"a",
"lambda",
"to",
"be",
"used",
"as",
"the",
"builder"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/TypeRuntimeWiring.java#L53-L55
|
13,878
|
graphql-java/graphql-java
|
src/main/java/graphql/cachecontrol/CacheControl.java
|
CacheControl.hint
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Integer maxAge, Scope scope) {
assertNotNull(dataFetchingEnvironment);
assertNotNull(scope);
hint(dataFetchingEnvironment.getExecutionStepInfo().getPath(), maxAge, scope);
return this;
}
|
java
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Integer maxAge, Scope scope) {
assertNotNull(dataFetchingEnvironment);
assertNotNull(scope);
hint(dataFetchingEnvironment.getExecutionStepInfo().getPath(), maxAge, scope);
return this;
}
|
[
"public",
"CacheControl",
"hint",
"(",
"DataFetchingEnvironment",
"dataFetchingEnvironment",
",",
"Integer",
"maxAge",
",",
"Scope",
"scope",
")",
"{",
"assertNotNull",
"(",
"dataFetchingEnvironment",
")",
";",
"assertNotNull",
"(",
"scope",
")",
";",
"hint",
"(",
"dataFetchingEnvironment",
".",
"getExecutionStepInfo",
"(",
")",
".",
"getPath",
"(",
")",
",",
"maxAge",
",",
"scope",
")",
";",
"return",
"this",
";",
"}"
] |
This creates a cache control hint for the specified field being fetched
@param dataFetchingEnvironment the path to the field that has the cache control hint
@param maxAge the caching time in seconds
@param scope the scope of the cache control hint
@return this object builder style
|
[
"This",
"creates",
"a",
"cache",
"control",
"hint",
"for",
"the",
"specified",
"field",
"being",
"fetched"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/cachecontrol/CacheControl.java#L123-L128
|
13,879
|
graphql-java/graphql-java
|
src/main/java/graphql/cachecontrol/CacheControl.java
|
CacheControl.hint
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Integer maxAge) {
hint(dataFetchingEnvironment, maxAge, Scope.PUBLIC);
return this;
}
|
java
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Integer maxAge) {
hint(dataFetchingEnvironment, maxAge, Scope.PUBLIC);
return this;
}
|
[
"public",
"CacheControl",
"hint",
"(",
"DataFetchingEnvironment",
"dataFetchingEnvironment",
",",
"Integer",
"maxAge",
")",
"{",
"hint",
"(",
"dataFetchingEnvironment",
",",
"maxAge",
",",
"Scope",
".",
"PUBLIC",
")",
";",
"return",
"this",
";",
"}"
] |
This creates a cache control hint for the specified field being fetched with a PUBLIC scope
@param dataFetchingEnvironment the path to the field that has the cache control hint
@param maxAge the caching time in seconds
@return this object builder style
|
[
"This",
"creates",
"a",
"cache",
"control",
"hint",
"for",
"the",
"specified",
"field",
"being",
"fetched",
"with",
"a",
"PUBLIC",
"scope"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/cachecontrol/CacheControl.java#L138-L141
|
13,880
|
graphql-java/graphql-java
|
src/main/java/graphql/cachecontrol/CacheControl.java
|
CacheControl.hint
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Scope scope) {
return hint(dataFetchingEnvironment, null, scope);
}
|
java
|
public CacheControl hint(DataFetchingEnvironment dataFetchingEnvironment, Scope scope) {
return hint(dataFetchingEnvironment, null, scope);
}
|
[
"public",
"CacheControl",
"hint",
"(",
"DataFetchingEnvironment",
"dataFetchingEnvironment",
",",
"Scope",
"scope",
")",
"{",
"return",
"hint",
"(",
"dataFetchingEnvironment",
",",
"null",
",",
"scope",
")",
";",
"}"
] |
This creates a cache control hint for the specified field being fetched with a specified scope
@param dataFetchingEnvironment the path to the field that has the cache control hint
@param scope the scope of the cache control hint
@return this object builder style
|
[
"This",
"creates",
"a",
"cache",
"control",
"hint",
"for",
"the",
"specified",
"field",
"being",
"fetched",
"with",
"a",
"specified",
"scope"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/cachecontrol/CacheControl.java#L151-L153
|
13,881
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLUnionType.java
|
GraphQLUnionType.transform
|
public GraphQLUnionType transform(Consumer<Builder> builderConsumer) {
Builder builder = newUnionType(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLUnionType transform(Consumer<Builder> builderConsumer) {
Builder builder = newUnionType(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLUnionType",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newUnionType",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLUnionType 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",
"GraphQLUnionType",
"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/GraphQLUnionType.java#L129-L133
|
13,882
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/instrumentation/fieldvalidation/SimpleFieldValidation.java
|
SimpleFieldValidation.addRule
|
public SimpleFieldValidation addRule(ExecutionPath fieldPath, BiFunction<FieldAndArguments, FieldValidationEnvironment, Optional<GraphQLError>> rule) {
rules.put(fieldPath, rule);
return this;
}
|
java
|
public SimpleFieldValidation addRule(ExecutionPath fieldPath, BiFunction<FieldAndArguments, FieldValidationEnvironment, Optional<GraphQLError>> rule) {
rules.put(fieldPath, rule);
return this;
}
|
[
"public",
"SimpleFieldValidation",
"addRule",
"(",
"ExecutionPath",
"fieldPath",
",",
"BiFunction",
"<",
"FieldAndArguments",
",",
"FieldValidationEnvironment",
",",
"Optional",
"<",
"GraphQLError",
">",
">",
"rule",
")",
"{",
"rules",
".",
"put",
"(",
"fieldPath",
",",
"rule",
")",
";",
"return",
"this",
";",
"}"
] |
Adds the rule against the field address path. If the rule returns an error, it will be added to the list of errors
@param fieldPath the path to the field
@param rule the rule function
@return this validator
|
[
"Adds",
"the",
"rule",
"against",
"the",
"field",
"address",
"path",
".",
"If",
"the",
"rule",
"returns",
"an",
"error",
"it",
"will",
"be",
"added",
"to",
"the",
"list",
"of",
"errors"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/instrumentation/fieldvalidation/SimpleFieldValidation.java#L34-L37
|
13,883
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionStrategy.java
|
ExecutionStrategy.completeValueForObject
|
protected CompletableFuture<ExecutionResult> completeValueForObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLObjectType resolvedObjectType, Object result) {
ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo();
FieldCollectorParameters collectorParameters = newParameters()
.schema(executionContext.getGraphQLSchema())
.objectType(resolvedObjectType)
.fragments(executionContext.getFragmentsByName())
.variables(executionContext.getVariables())
.build();
MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, parameters.getField());
ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType);
NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo);
ExecutionStrategyParameters newParameters = parameters.transform(builder ->
builder.executionStepInfo(newExecutionStepInfo)
.fields(subFields)
.nonNullFieldValidator(nonNullableFieldValidator)
.source(result)
);
// Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy.
return executionContext.getQueryStrategy().execute(executionContext, newParameters);
}
|
java
|
protected CompletableFuture<ExecutionResult> completeValueForObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLObjectType resolvedObjectType, Object result) {
ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo();
FieldCollectorParameters collectorParameters = newParameters()
.schema(executionContext.getGraphQLSchema())
.objectType(resolvedObjectType)
.fragments(executionContext.getFragmentsByName())
.variables(executionContext.getVariables())
.build();
MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, parameters.getField());
ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull(resolvedObjectType);
NonNullableFieldValidator nonNullableFieldValidator = new NonNullableFieldValidator(executionContext, newExecutionStepInfo);
ExecutionStrategyParameters newParameters = parameters.transform(builder ->
builder.executionStepInfo(newExecutionStepInfo)
.fields(subFields)
.nonNullFieldValidator(nonNullableFieldValidator)
.source(result)
);
// Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy.
return executionContext.getQueryStrategy().execute(executionContext, newParameters);
}
|
[
"protected",
"CompletableFuture",
"<",
"ExecutionResult",
">",
"completeValueForObject",
"(",
"ExecutionContext",
"executionContext",
",",
"ExecutionStrategyParameters",
"parameters",
",",
"GraphQLObjectType",
"resolvedObjectType",
",",
"Object",
"result",
")",
"{",
"ExecutionStepInfo",
"executionStepInfo",
"=",
"parameters",
".",
"getExecutionStepInfo",
"(",
")",
";",
"FieldCollectorParameters",
"collectorParameters",
"=",
"newParameters",
"(",
")",
".",
"schema",
"(",
"executionContext",
".",
"getGraphQLSchema",
"(",
")",
")",
".",
"objectType",
"(",
"resolvedObjectType",
")",
".",
"fragments",
"(",
"executionContext",
".",
"getFragmentsByName",
"(",
")",
")",
".",
"variables",
"(",
"executionContext",
".",
"getVariables",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"MergedSelectionSet",
"subFields",
"=",
"fieldCollector",
".",
"collectFields",
"(",
"collectorParameters",
",",
"parameters",
".",
"getField",
"(",
")",
")",
";",
"ExecutionStepInfo",
"newExecutionStepInfo",
"=",
"executionStepInfo",
".",
"changeTypeWithPreservedNonNull",
"(",
"resolvedObjectType",
")",
";",
"NonNullableFieldValidator",
"nonNullableFieldValidator",
"=",
"new",
"NonNullableFieldValidator",
"(",
"executionContext",
",",
"newExecutionStepInfo",
")",
";",
"ExecutionStrategyParameters",
"newParameters",
"=",
"parameters",
".",
"transform",
"(",
"builder",
"->",
"builder",
".",
"executionStepInfo",
"(",
"newExecutionStepInfo",
")",
".",
"fields",
"(",
"subFields",
")",
".",
"nonNullFieldValidator",
"(",
"nonNullableFieldValidator",
")",
".",
"source",
"(",
"result",
")",
")",
";",
"// Calling this from the executionContext to ensure we shift back from mutation strategy to the query strategy.",
"return",
"executionContext",
".",
"getQueryStrategy",
"(",
")",
".",
"execute",
"(",
"executionContext",
",",
"newParameters",
")",
";",
"}"
] |
Called to turn an java object value into an graphql object value
@param executionContext contains the top level execution parameters
@param parameters contains the parameters holding the fields to be executed and source object
@param resolvedObjectType the resolved object type
@param result the result to be coerced
@return a promise to an {@link ExecutionResult}
|
[
"Called",
"to",
"turn",
"an",
"java",
"object",
"value",
"into",
"an",
"graphql",
"object",
"value"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionStrategy.java#L614-L639
|
13,884
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/ExecutionStrategy.java
|
ExecutionStrategy.createExecutionStepInfo
|
protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionContext,
ExecutionStrategyParameters parameters,
GraphQLFieldDefinition fieldDefinition,
GraphQLObjectType fieldContainer) {
GraphQLOutputType fieldType = fieldDefinition.getType();
List<Argument> fieldArgs = parameters.getField().getArguments();
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), fieldArgs, executionContext.getVariables());
return newExecutionStepInfo()
.type(fieldType)
.fieldDefinition(fieldDefinition)
.fieldContainer(fieldContainer)
.field(parameters.getField())
.path(parameters.getPath())
.parentInfo(parameters.getExecutionStepInfo())
.arguments(argumentValues)
.build();
}
|
java
|
protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionContext,
ExecutionStrategyParameters parameters,
GraphQLFieldDefinition fieldDefinition,
GraphQLObjectType fieldContainer) {
GraphQLOutputType fieldType = fieldDefinition.getType();
List<Argument> fieldArgs = parameters.getField().getArguments();
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), fieldArgs, executionContext.getVariables());
return newExecutionStepInfo()
.type(fieldType)
.fieldDefinition(fieldDefinition)
.fieldContainer(fieldContainer)
.field(parameters.getField())
.path(parameters.getPath())
.parentInfo(parameters.getExecutionStepInfo())
.arguments(argumentValues)
.build();
}
|
[
"protected",
"ExecutionStepInfo",
"createExecutionStepInfo",
"(",
"ExecutionContext",
"executionContext",
",",
"ExecutionStrategyParameters",
"parameters",
",",
"GraphQLFieldDefinition",
"fieldDefinition",
",",
"GraphQLObjectType",
"fieldContainer",
")",
"{",
"GraphQLOutputType",
"fieldType",
"=",
"fieldDefinition",
".",
"getType",
"(",
")",
";",
"List",
"<",
"Argument",
">",
"fieldArgs",
"=",
"parameters",
".",
"getField",
"(",
")",
".",
"getArguments",
"(",
")",
";",
"GraphQLCodeRegistry",
"codeRegistry",
"=",
"executionContext",
".",
"getGraphQLSchema",
"(",
")",
".",
"getCodeRegistry",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"argumentValues",
"=",
"valuesResolver",
".",
"getArgumentValues",
"(",
"codeRegistry",
",",
"fieldDefinition",
".",
"getArguments",
"(",
")",
",",
"fieldArgs",
",",
"executionContext",
".",
"getVariables",
"(",
")",
")",
";",
"return",
"newExecutionStepInfo",
"(",
")",
".",
"type",
"(",
"fieldType",
")",
".",
"fieldDefinition",
"(",
"fieldDefinition",
")",
".",
"fieldContainer",
"(",
"fieldContainer",
")",
".",
"field",
"(",
"parameters",
".",
"getField",
"(",
")",
")",
".",
"path",
"(",
"parameters",
".",
"getPath",
"(",
")",
")",
".",
"parentInfo",
"(",
"parameters",
".",
"getExecutionStepInfo",
"(",
")",
")",
".",
"arguments",
"(",
"argumentValues",
")",
".",
"build",
"(",
")",
";",
"}"
] |
Builds the type info hierarchy for the current field
@param executionContext the execution context in play
@param parameters contains the parameters holding the fields to be executed and source object
@param fieldDefinition the field definition to build type info for
@param fieldContainer the field container
@return a new type info
|
[
"Builds",
"the",
"type",
"info",
"hierarchy",
"for",
"the",
"current",
"field"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/ExecutionStrategy.java#L779-L798
|
13,885
|
graphql-java/graphql-java
|
src/main/java/graphql/parser/MultiSourceReader.java
|
MultiSourceReader.getSourceAndLineFromOverallLine
|
public SourceAndLine getSourceAndLineFromOverallLine(int overallLineNumber) {
SourceAndLine sourceAndLine = new SourceAndLine();
if (sourceParts.isEmpty()) {
return sourceAndLine;
}
SourcePart currentPart;
if (currentIndex >= sourceParts.size()) {
currentPart = sourceParts.get(sourceParts.size() - 1);
} else {
currentPart = sourceParts.get(currentIndex);
}
int page = 0;
int previousPage;
for (SourcePart sourcePart : sourceParts) {
sourceAndLine.sourceName = sourcePart.sourceName;
if (sourcePart == currentPart) {
// we cant go any further
int offset = currentPart.lineReader.getLineNumber();
previousPage = page;
page += offset;
if (page > overallLineNumber) {
sourceAndLine.line = overallLineNumber - previousPage;
} else {
sourceAndLine.line = page;
}
return sourceAndLine;
} else {
previousPage = page;
page += sourcePart.lineReader.getLineNumber();
if (page > overallLineNumber) {
sourceAndLine.line = overallLineNumber - previousPage;
return sourceAndLine;
}
}
}
sourceAndLine.line = overallLineNumber - page;
return sourceAndLine;
}
|
java
|
public SourceAndLine getSourceAndLineFromOverallLine(int overallLineNumber) {
SourceAndLine sourceAndLine = new SourceAndLine();
if (sourceParts.isEmpty()) {
return sourceAndLine;
}
SourcePart currentPart;
if (currentIndex >= sourceParts.size()) {
currentPart = sourceParts.get(sourceParts.size() - 1);
} else {
currentPart = sourceParts.get(currentIndex);
}
int page = 0;
int previousPage;
for (SourcePart sourcePart : sourceParts) {
sourceAndLine.sourceName = sourcePart.sourceName;
if (sourcePart == currentPart) {
// we cant go any further
int offset = currentPart.lineReader.getLineNumber();
previousPage = page;
page += offset;
if (page > overallLineNumber) {
sourceAndLine.line = overallLineNumber - previousPage;
} else {
sourceAndLine.line = page;
}
return sourceAndLine;
} else {
previousPage = page;
page += sourcePart.lineReader.getLineNumber();
if (page > overallLineNumber) {
sourceAndLine.line = overallLineNumber - previousPage;
return sourceAndLine;
}
}
}
sourceAndLine.line = overallLineNumber - page;
return sourceAndLine;
}
|
[
"public",
"SourceAndLine",
"getSourceAndLineFromOverallLine",
"(",
"int",
"overallLineNumber",
")",
"{",
"SourceAndLine",
"sourceAndLine",
"=",
"new",
"SourceAndLine",
"(",
")",
";",
"if",
"(",
"sourceParts",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"sourceAndLine",
";",
"}",
"SourcePart",
"currentPart",
";",
"if",
"(",
"currentIndex",
">=",
"sourceParts",
".",
"size",
"(",
")",
")",
"{",
"currentPart",
"=",
"sourceParts",
".",
"get",
"(",
"sourceParts",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"}",
"else",
"{",
"currentPart",
"=",
"sourceParts",
".",
"get",
"(",
"currentIndex",
")",
";",
"}",
"int",
"page",
"=",
"0",
";",
"int",
"previousPage",
";",
"for",
"(",
"SourcePart",
"sourcePart",
":",
"sourceParts",
")",
"{",
"sourceAndLine",
".",
"sourceName",
"=",
"sourcePart",
".",
"sourceName",
";",
"if",
"(",
"sourcePart",
"==",
"currentPart",
")",
"{",
"// we cant go any further",
"int",
"offset",
"=",
"currentPart",
".",
"lineReader",
".",
"getLineNumber",
"(",
")",
";",
"previousPage",
"=",
"page",
";",
"page",
"+=",
"offset",
";",
"if",
"(",
"page",
">",
"overallLineNumber",
")",
"{",
"sourceAndLine",
".",
"line",
"=",
"overallLineNumber",
"-",
"previousPage",
";",
"}",
"else",
"{",
"sourceAndLine",
".",
"line",
"=",
"page",
";",
"}",
"return",
"sourceAndLine",
";",
"}",
"else",
"{",
"previousPage",
"=",
"page",
";",
"page",
"+=",
"sourcePart",
".",
"lineReader",
".",
"getLineNumber",
"(",
")",
";",
"if",
"(",
"page",
">",
"overallLineNumber",
")",
"{",
"sourceAndLine",
".",
"line",
"=",
"overallLineNumber",
"-",
"previousPage",
";",
"return",
"sourceAndLine",
";",
"}",
"}",
"}",
"sourceAndLine",
".",
"line",
"=",
"overallLineNumber",
"-",
"page",
";",
"return",
"sourceAndLine",
";",
"}"
] |
This returns the source name and line number given an overall line number
This is zeroes based like {@link java.io.LineNumberReader#getLineNumber()}
@param overallLineNumber the over all line number
@return the source name and relative line number to that source
|
[
"This",
"returns",
"the",
"source",
"name",
"and",
"line",
"number",
"given",
"an",
"overall",
"line",
"number"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/parser/MultiSourceReader.java#L93-L130
|
13,886
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/NonNullableFieldValidator.java
|
NonNullableFieldValidator.validate
|
public <T> T validate(ExecutionPath path, T result) throws NonNullableFieldWasNullException {
if (result == null) {
if (executionStepInfo.isNonNullType()) {
// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability
//
// > If the field returns null because of an error which has already been added to the "errors" list in the response,
// > the "errors" list must not be further affected. That is, only one error should be added to the errors list per field.
//
// We interpret this to cover the null field path only. So here we use the variant of addError() that checks
// for the current path already.
//
// Other places in the code base use the addError() that does not care about previous errors on that path being there.
//
// We will do this until the spec makes this more explicit.
//
NonNullableFieldWasNullException nonNullException = new NonNullableFieldWasNullException(executionStepInfo, path);
executionContext.addError(new NonNullableFieldWasNullError(nonNullException), path);
throw nonNullException;
}
}
return result;
}
|
java
|
public <T> T validate(ExecutionPath path, T result) throws NonNullableFieldWasNullException {
if (result == null) {
if (executionStepInfo.isNonNullType()) {
// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability
//
// > If the field returns null because of an error which has already been added to the "errors" list in the response,
// > the "errors" list must not be further affected. That is, only one error should be added to the errors list per field.
//
// We interpret this to cover the null field path only. So here we use the variant of addError() that checks
// for the current path already.
//
// Other places in the code base use the addError() that does not care about previous errors on that path being there.
//
// We will do this until the spec makes this more explicit.
//
NonNullableFieldWasNullException nonNullException = new NonNullableFieldWasNullException(executionStepInfo, path);
executionContext.addError(new NonNullableFieldWasNullError(nonNullException), path);
throw nonNullException;
}
}
return result;
}
|
[
"public",
"<",
"T",
">",
"T",
"validate",
"(",
"ExecutionPath",
"path",
",",
"T",
"result",
")",
"throws",
"NonNullableFieldWasNullException",
"{",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"if",
"(",
"executionStepInfo",
".",
"isNonNullType",
"(",
")",
")",
"{",
"// see http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability",
"//",
"// > If the field returns null because of an error which has already been added to the \"errors\" list in the response,",
"// > the \"errors\" list must not be further affected. That is, only one error should be added to the errors list per field.",
"//",
"// We interpret this to cover the null field path only. So here we use the variant of addError() that checks",
"// for the current path already.",
"//",
"// Other places in the code base use the addError() that does not care about previous errors on that path being there.",
"//",
"// We will do this until the spec makes this more explicit.",
"//",
"NonNullableFieldWasNullException",
"nonNullException",
"=",
"new",
"NonNullableFieldWasNullException",
"(",
"executionStepInfo",
",",
"path",
")",
";",
"executionContext",
".",
"addError",
"(",
"new",
"NonNullableFieldWasNullError",
"(",
"nonNullException",
")",
",",
"path",
")",
";",
"throw",
"nonNullException",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Called to check that a value is non null if the type requires it to be non null
@param path the path to this place
@param result the result to check
@param <T> the type of the result
@return the result back
@throws NonNullableFieldWasNullException if the value is null but the type requires it to be non null
|
[
"Called",
"to",
"check",
"that",
"a",
"value",
"is",
"non",
"null",
"if",
"the",
"type",
"requires",
"it",
"to",
"be",
"non",
"null"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/NonNullableFieldValidator.java#L34-L55
|
13,887
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLTypeUtil.java
|
GraphQLTypeUtil.isLeaf
|
public static boolean isLeaf(GraphQLType type) {
GraphQLUnmodifiedType unmodifiedType = unwrapAll(type);
return
unmodifiedType instanceof GraphQLScalarType
|| unmodifiedType instanceof GraphQLEnumType;
}
|
java
|
public static boolean isLeaf(GraphQLType type) {
GraphQLUnmodifiedType unmodifiedType = unwrapAll(type);
return
unmodifiedType instanceof GraphQLScalarType
|| unmodifiedType instanceof GraphQLEnumType;
}
|
[
"public",
"static",
"boolean",
"isLeaf",
"(",
"GraphQLType",
"type",
")",
"{",
"GraphQLUnmodifiedType",
"unmodifiedType",
"=",
"unwrapAll",
"(",
"type",
")",
";",
"return",
"unmodifiedType",
"instanceof",
"GraphQLScalarType",
"||",
"unmodifiedType",
"instanceof",
"GraphQLEnumType",
";",
"}"
] |
Returns true if the given type is a leaf type, that it cant contain any more fields
@param type the type to check
@return true if the given type is a leaf type
|
[
"Returns",
"true",
"if",
"the",
"given",
"type",
"is",
"a",
"leaf",
"type",
"that",
"it",
"cant",
"contain",
"any",
"more",
"fields"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLTypeUtil.java#L121-L126
|
13,888
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLTypeUtil.java
|
GraphQLTypeUtil.isInput
|
public static boolean isInput(GraphQLType type) {
GraphQLUnmodifiedType unmodifiedType = unwrapAll(type);
return
unmodifiedType instanceof GraphQLScalarType
|| unmodifiedType instanceof GraphQLEnumType
|| unmodifiedType instanceof GraphQLInputObjectType;
}
|
java
|
public static boolean isInput(GraphQLType type) {
GraphQLUnmodifiedType unmodifiedType = unwrapAll(type);
return
unmodifiedType instanceof GraphQLScalarType
|| unmodifiedType instanceof GraphQLEnumType
|| unmodifiedType instanceof GraphQLInputObjectType;
}
|
[
"public",
"static",
"boolean",
"isInput",
"(",
"GraphQLType",
"type",
")",
"{",
"GraphQLUnmodifiedType",
"unmodifiedType",
"=",
"unwrapAll",
"(",
"type",
")",
";",
"return",
"unmodifiedType",
"instanceof",
"GraphQLScalarType",
"||",
"unmodifiedType",
"instanceof",
"GraphQLEnumType",
"||",
"unmodifiedType",
"instanceof",
"GraphQLInputObjectType",
";",
"}"
] |
Returns true if the given type is an input type
@param type the type to check
@return true if the given type is an input type
|
[
"Returns",
"true",
"if",
"the",
"given",
"type",
"is",
"an",
"input",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLTypeUtil.java#L135-L141
|
13,889
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLTypeUtil.java
|
GraphQLTypeUtil.unwrapOne
|
public static GraphQLType unwrapOne(GraphQLType type) {
if (isNonNull(type)) {
return ((GraphQLNonNull) type).getWrappedType();
} else if (isList(type)) {
return ((GraphQLList) type).getWrappedType();
}
return type;
}
|
java
|
public static GraphQLType unwrapOne(GraphQLType type) {
if (isNonNull(type)) {
return ((GraphQLNonNull) type).getWrappedType();
} else if (isList(type)) {
return ((GraphQLList) type).getWrappedType();
}
return type;
}
|
[
"public",
"static",
"GraphQLType",
"unwrapOne",
"(",
"GraphQLType",
"type",
")",
"{",
"if",
"(",
"isNonNull",
"(",
"type",
")",
")",
"{",
"return",
"(",
"(",
"GraphQLNonNull",
")",
"type",
")",
".",
"getWrappedType",
"(",
")",
";",
"}",
"else",
"if",
"(",
"isList",
"(",
"type",
")",
")",
"{",
"return",
"(",
"(",
"GraphQLList",
")",
"type",
")",
".",
"getWrappedType",
"(",
")",
";",
"}",
"return",
"type",
";",
"}"
] |
Unwraps one layer of the type or just returns the type again if its not a wrapped type
@param type the type to unwrapOne
@return the unwrapped type or the same type again if its not wrapped
|
[
"Unwraps",
"one",
"layer",
"of",
"the",
"type",
"or",
"just",
"returns",
"the",
"type",
"again",
"if",
"its",
"not",
"a",
"wrapped",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLTypeUtil.java#L150-L157
|
13,890
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLTypeUtil.java
|
GraphQLTypeUtil.unwrapAll
|
public static GraphQLUnmodifiedType unwrapAll(GraphQLType type) {
while (true) {
if (isNotWrapped(type)) {
return (GraphQLUnmodifiedType) type;
}
type = unwrapOne(type);
}
}
|
java
|
public static GraphQLUnmodifiedType unwrapAll(GraphQLType type) {
while (true) {
if (isNotWrapped(type)) {
return (GraphQLUnmodifiedType) type;
}
type = unwrapOne(type);
}
}
|
[
"public",
"static",
"GraphQLUnmodifiedType",
"unwrapAll",
"(",
"GraphQLType",
"type",
")",
"{",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"isNotWrapped",
"(",
"type",
")",
")",
"{",
"return",
"(",
"GraphQLUnmodifiedType",
")",
"type",
";",
"}",
"type",
"=",
"unwrapOne",
"(",
"type",
")",
";",
"}",
"}"
] |
Unwraps all layers of the type or just returns the type again if its not a wrapped type
@param type the type to unwrapOne
@return the underlying type
|
[
"Unwraps",
"all",
"layers",
"of",
"the",
"type",
"or",
"just",
"returns",
"the",
"type",
"again",
"if",
"its",
"not",
"a",
"wrapped",
"type"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/GraphQLTypeUtil.java#L166-L173
|
13,891
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/MergedField.java
|
MergedField.getResultKey
|
public String getResultKey() {
Field singleField = getSingleField();
if (singleField.getAlias() != null) {
return singleField.getAlias();
}
return singleField.getName();
}
|
java
|
public String getResultKey() {
Field singleField = getSingleField();
if (singleField.getAlias() != null) {
return singleField.getAlias();
}
return singleField.getName();
}
|
[
"public",
"String",
"getResultKey",
"(",
")",
"{",
"Field",
"singleField",
"=",
"getSingleField",
"(",
")",
";",
"if",
"(",
"singleField",
".",
"getAlias",
"(",
")",
"!=",
"null",
")",
"{",
"return",
"singleField",
".",
"getAlias",
"(",
")",
";",
"}",
"return",
"singleField",
".",
"getName",
"(",
")",
";",
"}"
] |
Returns the key of this MergedField for the overall result.
This is either an alias or the field name.
@return the key for this MergedField.
|
[
"Returns",
"the",
"key",
"of",
"this",
"MergedField",
"for",
"the",
"overall",
"result",
".",
"This",
"is",
"either",
"an",
"alias",
"or",
"the",
"field",
"name",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/MergedField.java#L86-L92
|
13,892
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/AbortExecutionException.java
|
AbortExecutionException.toExecutionResult
|
public ExecutionResult toExecutionResult() {
ExecutionResult executionResult = new ExecutionResultImpl(this);
if (!this.getUnderlyingErrors().isEmpty()) {
executionResult = new ExecutionResultImpl(this.getUnderlyingErrors());
}
return executionResult;
}
|
java
|
public ExecutionResult toExecutionResult() {
ExecutionResult executionResult = new ExecutionResultImpl(this);
if (!this.getUnderlyingErrors().isEmpty()) {
executionResult = new ExecutionResultImpl(this.getUnderlyingErrors());
}
return executionResult;
}
|
[
"public",
"ExecutionResult",
"toExecutionResult",
"(",
")",
"{",
"ExecutionResult",
"executionResult",
"=",
"new",
"ExecutionResultImpl",
"(",
"this",
")",
";",
"if",
"(",
"!",
"this",
".",
"getUnderlyingErrors",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"executionResult",
"=",
"new",
"ExecutionResultImpl",
"(",
"this",
".",
"getUnderlyingErrors",
"(",
")",
")",
";",
"}",
"return",
"executionResult",
";",
"}"
] |
This is useful for turning this abort signal into an execution result which
is an error state with the underlying errors in it.
@return an excution result with the errors from this exception
|
[
"This",
"is",
"useful",
"for",
"turning",
"this",
"abort",
"signal",
"into",
"an",
"execution",
"result",
"which",
"is",
"an",
"error",
"state",
"with",
"the",
"underlying",
"errors",
"in",
"it",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/AbortExecutionException.java#L72-L78
|
13,893
|
graphql-java/graphql-java
|
src/main/java/graphql/introspection/IntrospectionResultToSchema.java
|
IntrospectionResultToSchema.createSchemaDefinition
|
public Document createSchemaDefinition(ExecutionResult introspectionResult) {
Map<String, Object> introspectionResultMap = introspectionResult.getData();
return createSchemaDefinition(introspectionResultMap);
}
|
java
|
public Document createSchemaDefinition(ExecutionResult introspectionResult) {
Map<String, Object> introspectionResultMap = introspectionResult.getData();
return createSchemaDefinition(introspectionResultMap);
}
|
[
"public",
"Document",
"createSchemaDefinition",
"(",
"ExecutionResult",
"introspectionResult",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionResultMap",
"=",
"introspectionResult",
".",
"getData",
"(",
")",
";",
"return",
"createSchemaDefinition",
"(",
"introspectionResultMap",
")",
";",
"}"
] |
Returns a IDL Document that represents the schema as defined by the introspection execution result
@param introspectionResult the result of an introspection query on a schema
@return a IDL Document of the schema
|
[
"Returns",
"a",
"IDL",
"Document",
"that",
"represents",
"the",
"schema",
"as",
"defined",
"by",
"the",
"introspection",
"execution",
"result"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/introspection/IntrospectionResultToSchema.java#L53-L56
|
13,894
|
graphql-java/graphql-java
|
src/main/java/graphql/introspection/IntrospectionResultToSchema.java
|
IntrospectionResultToSchema.createSchemaDefinition
|
@SuppressWarnings("unchecked")
public Document createSchemaDefinition(Map<String, Object> introspectionResult) {
assertTrue(introspectionResult.get("__schema") != null, "__schema expected");
Map<String, Object> schema = (Map<String, Object>) introspectionResult.get("__schema");
Map<String, Object> queryType = (Map<String, Object>) schema.get("queryType");
assertNotNull(queryType, "queryType expected");
TypeName query = TypeName.newTypeName().name((String) queryType.get("name")).build();
boolean nonDefaultQueryName = !"Query".equals(query.getName());
SchemaDefinition.Builder schemaDefinition = SchemaDefinition.newSchemaDefinition();
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("query").typeName(query).build());
Map<String, Object> mutationType = (Map<String, Object>) schema.get("mutationType");
boolean nonDefaultMutationName = false;
if (mutationType != null) {
TypeName mutation = TypeName.newTypeName().name((String) mutationType.get("name")).build();
nonDefaultMutationName = !"Mutation".equals(mutation.getName());
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("mutation").typeName(mutation).build());
}
Map<String, Object> subscriptionType = (Map<String, Object>) schema.get("subscriptionType");
boolean nonDefaultSubscriptionName = false;
if (subscriptionType != null) {
TypeName subscription = TypeName.newTypeName().name(((String) subscriptionType.get("name"))).build();
nonDefaultSubscriptionName = !"Subscription".equals(subscription.getName());
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("subscription").typeName(subscription).build());
}
Document.Builder document = Document.newDocument();
if (nonDefaultQueryName || nonDefaultMutationName || nonDefaultSubscriptionName) {
document.definition(schemaDefinition.build());
}
List<Map<String, Object>> types = (List<Map<String, Object>>) schema.get("types");
for (Map<String, Object> type : types) {
TypeDefinition typeDefinition = createTypeDefinition(type);
if (typeDefinition == null) continue;
document.definition(typeDefinition);
}
return document.build();
}
|
java
|
@SuppressWarnings("unchecked")
public Document createSchemaDefinition(Map<String, Object> introspectionResult) {
assertTrue(introspectionResult.get("__schema") != null, "__schema expected");
Map<String, Object> schema = (Map<String, Object>) introspectionResult.get("__schema");
Map<String, Object> queryType = (Map<String, Object>) schema.get("queryType");
assertNotNull(queryType, "queryType expected");
TypeName query = TypeName.newTypeName().name((String) queryType.get("name")).build();
boolean nonDefaultQueryName = !"Query".equals(query.getName());
SchemaDefinition.Builder schemaDefinition = SchemaDefinition.newSchemaDefinition();
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("query").typeName(query).build());
Map<String, Object> mutationType = (Map<String, Object>) schema.get("mutationType");
boolean nonDefaultMutationName = false;
if (mutationType != null) {
TypeName mutation = TypeName.newTypeName().name((String) mutationType.get("name")).build();
nonDefaultMutationName = !"Mutation".equals(mutation.getName());
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("mutation").typeName(mutation).build());
}
Map<String, Object> subscriptionType = (Map<String, Object>) schema.get("subscriptionType");
boolean nonDefaultSubscriptionName = false;
if (subscriptionType != null) {
TypeName subscription = TypeName.newTypeName().name(((String) subscriptionType.get("name"))).build();
nonDefaultSubscriptionName = !"Subscription".equals(subscription.getName());
schemaDefinition.operationTypeDefinition(OperationTypeDefinition.newOperationTypeDefinition().name("subscription").typeName(subscription).build());
}
Document.Builder document = Document.newDocument();
if (nonDefaultQueryName || nonDefaultMutationName || nonDefaultSubscriptionName) {
document.definition(schemaDefinition.build());
}
List<Map<String, Object>> types = (List<Map<String, Object>>) schema.get("types");
for (Map<String, Object> type : types) {
TypeDefinition typeDefinition = createTypeDefinition(type);
if (typeDefinition == null) continue;
document.definition(typeDefinition);
}
return document.build();
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"Document",
"createSchemaDefinition",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionResult",
")",
"{",
"assertTrue",
"(",
"introspectionResult",
".",
"get",
"(",
"\"__schema\"",
")",
"!=",
"null",
",",
"\"__schema expected\"",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"schema",
"=",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"introspectionResult",
".",
"get",
"(",
"\"__schema\"",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"queryType",
"=",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"schema",
".",
"get",
"(",
"\"queryType\"",
")",
";",
"assertNotNull",
"(",
"queryType",
",",
"\"queryType expected\"",
")",
";",
"TypeName",
"query",
"=",
"TypeName",
".",
"newTypeName",
"(",
")",
".",
"name",
"(",
"(",
"String",
")",
"queryType",
".",
"get",
"(",
"\"name\"",
")",
")",
".",
"build",
"(",
")",
";",
"boolean",
"nonDefaultQueryName",
"=",
"!",
"\"Query\"",
".",
"equals",
"(",
"query",
".",
"getName",
"(",
")",
")",
";",
"SchemaDefinition",
".",
"Builder",
"schemaDefinition",
"=",
"SchemaDefinition",
".",
"newSchemaDefinition",
"(",
")",
";",
"schemaDefinition",
".",
"operationTypeDefinition",
"(",
"OperationTypeDefinition",
".",
"newOperationTypeDefinition",
"(",
")",
".",
"name",
"(",
"\"query\"",
")",
".",
"typeName",
"(",
"query",
")",
".",
"build",
"(",
")",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"mutationType",
"=",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"schema",
".",
"get",
"(",
"\"mutationType\"",
")",
";",
"boolean",
"nonDefaultMutationName",
"=",
"false",
";",
"if",
"(",
"mutationType",
"!=",
"null",
")",
"{",
"TypeName",
"mutation",
"=",
"TypeName",
".",
"newTypeName",
"(",
")",
".",
"name",
"(",
"(",
"String",
")",
"mutationType",
".",
"get",
"(",
"\"name\"",
")",
")",
".",
"build",
"(",
")",
";",
"nonDefaultMutationName",
"=",
"!",
"\"Mutation\"",
".",
"equals",
"(",
"mutation",
".",
"getName",
"(",
")",
")",
";",
"schemaDefinition",
".",
"operationTypeDefinition",
"(",
"OperationTypeDefinition",
".",
"newOperationTypeDefinition",
"(",
")",
".",
"name",
"(",
"\"mutation\"",
")",
".",
"typeName",
"(",
"mutation",
")",
".",
"build",
"(",
")",
")",
";",
"}",
"Map",
"<",
"String",
",",
"Object",
">",
"subscriptionType",
"=",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"schema",
".",
"get",
"(",
"\"subscriptionType\"",
")",
";",
"boolean",
"nonDefaultSubscriptionName",
"=",
"false",
";",
"if",
"(",
"subscriptionType",
"!=",
"null",
")",
"{",
"TypeName",
"subscription",
"=",
"TypeName",
".",
"newTypeName",
"(",
")",
".",
"name",
"(",
"(",
"(",
"String",
")",
"subscriptionType",
".",
"get",
"(",
"\"name\"",
")",
")",
")",
".",
"build",
"(",
")",
";",
"nonDefaultSubscriptionName",
"=",
"!",
"\"Subscription\"",
".",
"equals",
"(",
"subscription",
".",
"getName",
"(",
")",
")",
";",
"schemaDefinition",
".",
"operationTypeDefinition",
"(",
"OperationTypeDefinition",
".",
"newOperationTypeDefinition",
"(",
")",
".",
"name",
"(",
"\"subscription\"",
")",
".",
"typeName",
"(",
"subscription",
")",
".",
"build",
"(",
")",
")",
";",
"}",
"Document",
".",
"Builder",
"document",
"=",
"Document",
".",
"newDocument",
"(",
")",
";",
"if",
"(",
"nonDefaultQueryName",
"||",
"nonDefaultMutationName",
"||",
"nonDefaultSubscriptionName",
")",
"{",
"document",
".",
"definition",
"(",
"schemaDefinition",
".",
"build",
"(",
")",
")",
";",
"}",
"List",
"<",
"Map",
"<",
"String",
",",
"Object",
">",
">",
"types",
"=",
"(",
"List",
"<",
"Map",
"<",
"String",
",",
"Object",
">",
">",
")",
"schema",
".",
"get",
"(",
"\"types\"",
")",
";",
"for",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"type",
":",
"types",
")",
"{",
"TypeDefinition",
"typeDefinition",
"=",
"createTypeDefinition",
"(",
"type",
")",
";",
"if",
"(",
"typeDefinition",
"==",
"null",
")",
"continue",
";",
"document",
".",
"definition",
"(",
"typeDefinition",
")",
";",
"}",
"return",
"document",
".",
"build",
"(",
")",
";",
"}"
] |
Returns a IDL Document that reprSesents the schema as defined by the introspection result map
@param introspectionResult the result of an introspection query on a schema
@return a IDL Document of the schema
|
[
"Returns",
"a",
"IDL",
"Document",
"that",
"reprSesents",
"the",
"schema",
"as",
"defined",
"by",
"the",
"introspection",
"result",
"map"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/introspection/IntrospectionResultToSchema.java#L66-L109
|
13,895
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/idl/SchemaTypeChecker.java
|
SchemaTypeChecker.checkNamedUniqueness
|
static <T, E extends GraphQLError> void checkNamedUniqueness(List<GraphQLError> errors, List<T> listOfNamedThings, Function<T, String> namer, BiFunction<String, T, E> errorFunction) {
Set<String> names = new LinkedHashSet<>();
listOfNamedThings.forEach(thing -> {
String name = namer.apply(thing);
if (names.contains(name)) {
errors.add(errorFunction.apply(name, thing));
} else {
names.add(name);
}
});
}
|
java
|
static <T, E extends GraphQLError> void checkNamedUniqueness(List<GraphQLError> errors, List<T> listOfNamedThings, Function<T, String> namer, BiFunction<String, T, E> errorFunction) {
Set<String> names = new LinkedHashSet<>();
listOfNamedThings.forEach(thing -> {
String name = namer.apply(thing);
if (names.contains(name)) {
errors.add(errorFunction.apply(name, thing));
} else {
names.add(name);
}
});
}
|
[
"static",
"<",
"T",
",",
"E",
"extends",
"GraphQLError",
">",
"void",
"checkNamedUniqueness",
"(",
"List",
"<",
"GraphQLError",
">",
"errors",
",",
"List",
"<",
"T",
">",
"listOfNamedThings",
",",
"Function",
"<",
"T",
",",
"String",
">",
"namer",
",",
"BiFunction",
"<",
"String",
",",
"T",
",",
"E",
">",
"errorFunction",
")",
"{",
"Set",
"<",
"String",
">",
"names",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"listOfNamedThings",
".",
"forEach",
"(",
"thing",
"->",
"{",
"String",
"name",
"=",
"namer",
".",
"apply",
"(",
"thing",
")",
";",
"if",
"(",
"names",
".",
"contains",
"(",
"name",
")",
")",
"{",
"errors",
".",
"add",
"(",
"errorFunction",
".",
"apply",
"(",
"name",
",",
"thing",
")",
")",
";",
"}",
"else",
"{",
"names",
".",
"add",
"(",
"name",
")",
";",
"}",
"}",
")",
";",
"}"
] |
A simple function that takes a list of things, asks for their names and checks that the
names are unique within that list. If not it calls the error handler function
@param errors the error list
@param listOfNamedThings the list of named things
@param namer the function naming a thing
@param errorFunction the function producing an error
|
[
"A",
"simple",
"function",
"that",
"takes",
"a",
"list",
"of",
"things",
"asks",
"for",
"their",
"names",
"and",
"checks",
"that",
"the",
"names",
"are",
"unique",
"within",
"that",
"list",
".",
"If",
"not",
"it",
"calls",
"the",
"error",
"handler",
"function"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/idl/SchemaTypeChecker.java#L375-L385
|
13,896
|
graphql-java/graphql-java
|
src/main/java/graphql/Assert.java
|
Assert.assertValidName
|
public static String assertValidName(String name) {
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
return name;
}
throw new AssertException(String.format(invalidNameErrorMessage, name));
}
|
java
|
public static String assertValidName(String name) {
if (name != null && !name.isEmpty() && name.matches("[_A-Za-z][_0-9A-Za-z]*")) {
return name;
}
throw new AssertException(String.format(invalidNameErrorMessage, name));
}
|
[
"public",
"static",
"String",
"assertValidName",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"!=",
"null",
"&&",
"!",
"name",
".",
"isEmpty",
"(",
")",
"&&",
"name",
".",
"matches",
"(",
"\"[_A-Za-z][_0-9A-Za-z]*\"",
")",
")",
"{",
"return",
"name",
";",
"}",
"throw",
"new",
"AssertException",
"(",
"String",
".",
"format",
"(",
"invalidNameErrorMessage",
",",
"name",
")",
")",
";",
"}"
] |
Validates that the Lexical token name matches the current spec.
currently non null, non empty,
@param name - the name to be validated.
@return the name if valid, or AssertException if invalid.
|
[
"Validates",
"that",
"the",
"Lexical",
"token",
"name",
"matches",
"the",
"current",
"spec",
".",
"currently",
"non",
"null",
"non",
"empty"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/Assert.java#L96-L101
|
13,897
|
graphql-java/graphql-java
|
src/main/java/graphql/execution/instrumentation/tracing/TracingSupport.java
|
TracingSupport.snapshotTracingData
|
public Map<String, Object> snapshotTracingData() {
Map<String, Object> traceMap = new LinkedHashMap<>();
traceMap.put("version", 1L);
traceMap.put("startTime", rfc3339(startRequestTime));
traceMap.put("endTime", rfc3339(Instant.now()));
traceMap.put("duration", System.nanoTime() - startRequestNanos);
traceMap.put("parsing", copyMap(parseMap));
traceMap.put("validation", copyMap(validationMap));
traceMap.put("execution", executionData());
return traceMap;
}
|
java
|
public Map<String, Object> snapshotTracingData() {
Map<String, Object> traceMap = new LinkedHashMap<>();
traceMap.put("version", 1L);
traceMap.put("startTime", rfc3339(startRequestTime));
traceMap.put("endTime", rfc3339(Instant.now()));
traceMap.put("duration", System.nanoTime() - startRequestNanos);
traceMap.put("parsing", copyMap(parseMap));
traceMap.put("validation", copyMap(validationMap));
traceMap.put("execution", executionData());
return traceMap;
}
|
[
"public",
"Map",
"<",
"String",
",",
"Object",
">",
"snapshotTracingData",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"traceMap",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"traceMap",
".",
"put",
"(",
"\"version\"",
",",
"1L",
")",
";",
"traceMap",
".",
"put",
"(",
"\"startTime\"",
",",
"rfc3339",
"(",
"startRequestTime",
")",
")",
";",
"traceMap",
".",
"put",
"(",
"\"endTime\"",
",",
"rfc3339",
"(",
"Instant",
".",
"now",
"(",
")",
")",
")",
";",
"traceMap",
".",
"put",
"(",
"\"duration\"",
",",
"System",
".",
"nanoTime",
"(",
")",
"-",
"startRequestNanos",
")",
";",
"traceMap",
".",
"put",
"(",
"\"parsing\"",
",",
"copyMap",
"(",
"parseMap",
")",
")",
";",
"traceMap",
".",
"put",
"(",
"\"validation\"",
",",
"copyMap",
"(",
"validationMap",
")",
")",
";",
"traceMap",
".",
"put",
"(",
"\"execution\"",
",",
"executionData",
"(",
")",
")",
";",
"return",
"traceMap",
";",
"}"
] |
This will snapshot this tracing and return a map of the results
@return a snapshot of the tracing data
|
[
"This",
"will",
"snapshot",
"this",
"tracing",
"and",
"return",
"a",
"map",
"of",
"the",
"results"
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/execution/instrumentation/tracing/TracingSupport.java#L126-L138
|
13,898
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/GraphQLEnumType.java
|
GraphQLEnumType.transform
|
public GraphQLEnumType transform(Consumer<Builder> builderConsumer) {
Builder builder = newEnum(this);
builderConsumer.accept(builder);
return builder.build();
}
|
java
|
public GraphQLEnumType transform(Consumer<Builder> builderConsumer) {
Builder builder = newEnum(this);
builderConsumer.accept(builder);
return builder.build();
}
|
[
"public",
"GraphQLEnumType",
"transform",
"(",
"Consumer",
"<",
"Builder",
">",
"builderConsumer",
")",
"{",
"Builder",
"builder",
"=",
"newEnum",
"(",
"this",
")",
";",
"builderConsumer",
".",
"accept",
"(",
"builder",
")",
";",
"return",
"builder",
".",
"build",
"(",
")",
";",
"}"
] |
This helps you transform the current GraphQLEnumType 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",
"GraphQLEnumType",
"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/GraphQLEnumType.java#L194-L198
|
13,899
|
graphql-java/graphql-java
|
src/main/java/graphql/schema/diff/DiffSet.java
|
DiffSet.diffSet
|
public static DiffSet diffSet(Map<String, Object> introspectionOld, Map<String, Object> introspectionNew) {
return new DiffSet(introspectionOld, introspectionNew);
}
|
java
|
public static DiffSet diffSet(Map<String, Object> introspectionOld, Map<String, Object> introspectionNew) {
return new DiffSet(introspectionOld, introspectionNew);
}
|
[
"public",
"static",
"DiffSet",
"diffSet",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionOld",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"introspectionNew",
")",
"{",
"return",
"new",
"DiffSet",
"(",
"introspectionOld",
",",
"introspectionNew",
")",
";",
"}"
] |
Creates a diff set out of the result of 2 introspection queries.
@param introspectionOld the older introspection query
@param introspectionNew the newer introspection query
@return a diff set representing them
|
[
"Creates",
"a",
"diff",
"set",
"out",
"of",
"the",
"result",
"of",
"2",
"introspection",
"queries",
"."
] |
9214b6044317849388bd88a14b54fc1c18c9f29f
|
https://github.com/graphql-java/graphql-java/blob/9214b6044317849388bd88a14b54fc1c18c9f29f/src/main/java/graphql/schema/diff/DiffSet.java#L51-L53
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.