repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.invokeCallbackMethod | private JsonNode invokeCallbackMethod(final InvokeRequest req, final String cookie) {
Object obj = this.getObject(req.getObjref());
Method method = this.findCallbackMethod(obj.getClass(), cookie);
final Class<?>[] argTypes = method.getParameterTypes();
final Object[] args = new Object[argTypes.length];
for (int i = 0; i < argTypes.length; i++) {
args[i] = JsiiObjectMapper.treeToValue(req.getArgs().get(i), argTypes[i]);
}
return JsiiObjectMapper.valueToTree(invokeMethod(obj, method, args));
} | java | private JsonNode invokeCallbackMethod(final InvokeRequest req, final String cookie) {
Object obj = this.getObject(req.getObjref());
Method method = this.findCallbackMethod(obj.getClass(), cookie);
final Class<?>[] argTypes = method.getParameterTypes();
final Object[] args = new Object[argTypes.length];
for (int i = 0; i < argTypes.length; i++) {
args[i] = JsiiObjectMapper.treeToValue(req.getArgs().get(i), argTypes[i]);
}
return JsiiObjectMapper.valueToTree(invokeMethod(obj, method, args));
} | [
"private",
"JsonNode",
"invokeCallbackMethod",
"(",
"final",
"InvokeRequest",
"req",
",",
"final",
"String",
"cookie",
")",
"{",
"Object",
"obj",
"=",
"this",
".",
"getObject",
"(",
"req",
".",
"getObjref",
"(",
")",
")",
";",
"Method",
"method",
"=",
"thi... | Invokes an override for a method.
@param req The request
@param cookie The cookie
@return The method's return value | [
"Invokes",
"an",
"override",
"for",
"a",
"method",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L361-L372 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.invokeMethod | private Object invokeMethod(final Object obj, final Method method, final Object... args) {
// turn method to accessible. otherwise, we won't be able to callback to methods
// on non-public classes.
boolean accessibility = method.isAccessible();
method.setAccessible(true);
try {
try {
return method.invoke(obj, args);
} catch (Exception e) {
this.log("Error while invoking %s with %s: %s", method, Arrays.toString(args), Throwables.getStackTraceAsString(e));
throw e;
}
} catch (InvocationTargetException e) {
throw new JsiiException(e.getTargetException());
} catch (IllegalAccessException e) {
throw new JsiiException(e);
} finally {
// revert accessibility.
method.setAccessible(accessibility);
}
} | java | private Object invokeMethod(final Object obj, final Method method, final Object... args) {
// turn method to accessible. otherwise, we won't be able to callback to methods
// on non-public classes.
boolean accessibility = method.isAccessible();
method.setAccessible(true);
try {
try {
return method.invoke(obj, args);
} catch (Exception e) {
this.log("Error while invoking %s with %s: %s", method, Arrays.toString(args), Throwables.getStackTraceAsString(e));
throw e;
}
} catch (InvocationTargetException e) {
throw new JsiiException(e.getTargetException());
} catch (IllegalAccessException e) {
throw new JsiiException(e);
} finally {
// revert accessibility.
method.setAccessible(accessibility);
}
} | [
"private",
"Object",
"invokeMethod",
"(",
"final",
"Object",
"obj",
",",
"final",
"Method",
"method",
",",
"final",
"Object",
"...",
"args",
")",
"{",
"// turn method to accessible. otherwise, we won't be able to callback to methods",
"// on non-public classes.",
"boolean",
... | Invokes a Java method, even if the method is protected.
@param obj The object
@param method The method
@param args Method arguments
@return The return value | [
"Invokes",
"a",
"Java",
"method",
"even",
"if",
"the",
"method",
"is",
"protected",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L381-L402 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.processCallback | private void processCallback(final Callback callback) {
try {
JsonNode result = handleCallback(callback);
this.getClient().completeCallback(callback, null, result);
} catch (JsiiException e) {
this.getClient().completeCallback(callback, e.getMessage(), null);
}
} | java | private void processCallback(final Callback callback) {
try {
JsonNode result = handleCallback(callback);
this.getClient().completeCallback(callback, null, result);
} catch (JsiiException e) {
this.getClient().completeCallback(callback, e.getMessage(), null);
}
} | [
"private",
"void",
"processCallback",
"(",
"final",
"Callback",
"callback",
")",
"{",
"try",
"{",
"JsonNode",
"result",
"=",
"handleCallback",
"(",
"callback",
")",
";",
"this",
".",
"getClient",
"(",
")",
".",
"completeCallback",
"(",
"callback",
",",
"null... | Process a single callback by invoking the native method it refers to.
@param callback The callback to process. | [
"Process",
"a",
"single",
"callback",
"by",
"invoking",
"the",
"native",
"method",
"it",
"refers",
"to",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L408-L415 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.findCallbackMethod | private Method findCallbackMethod(final Class<?> klass, final String signature) {
for (Method method : klass.getMethods()) {
if (method.toString().equals(signature)) {
// found!
return method;
}
}
throw new JsiiException("Unable to find callback method with signature: " + signature);
} | java | private Method findCallbackMethod(final Class<?> klass, final String signature) {
for (Method method : klass.getMethods()) {
if (method.toString().equals(signature)) {
// found!
return method;
}
}
throw new JsiiException("Unable to find callback method with signature: " + signature);
} | [
"private",
"Method",
"findCallbackMethod",
"(",
"final",
"Class",
"<",
"?",
">",
"klass",
",",
"final",
"String",
"signature",
")",
"{",
"for",
"(",
"Method",
"method",
":",
"klass",
".",
"getMethods",
"(",
")",
")",
"{",
"if",
"(",
"method",
".",
"toS... | Finds the Java method that implements a callback.
@param klass The java class.
@param signature Method signature
@return a {@link Method}. | [
"Finds",
"the",
"Java",
"method",
"that",
"implements",
"a",
"callback",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L423-L433 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.discoverOverrides | private static Collection<JsiiOverride> discoverOverrides(final Class<?> classToInspect) {
Map<String, JsiiOverride> overrides = new HashMap<>();
Class<?> klass = classToInspect;
// if we reached a generated jsii class or Object, we should stop collecting those overrides since
// all the rest of the hierarchy is generated all the way up to JsiiObject and java.lang.Object.
while (klass != null
&& klass.getDeclaredAnnotationsByType(Jsii.class).length == 0
&& klass != Object.class) {
// add all the methods in the current class
for (Method method : klass.getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers())) {
continue;
}
String methodName = method.getName();
// check if this is a property ("getXXX" or "setXXX", oh java!)
if (isJavaPropertyMethod(methodName)) {
String propertyName = javaPropertyToJSProperty(methodName);
// skip if this property is already in the overrides list
if (overrides.containsKey(propertyName)) {
continue;
}
JsiiOverride override = new JsiiOverride();
override.setProperty(propertyName);
overrides.put(propertyName, override);
} else {
// if this method is already overridden, skip it
if (overrides.containsKey(methodName)) {
continue;
}
// we use the method's .toString() as a cookie, which will later be used to identify the
// method when it is called back.
JsiiOverride override = new JsiiOverride();
override.setMethod(methodName);
override.setCookie(method.toString());
overrides.put(methodName, override);
}
}
klass = klass.getSuperclass();
}
return overrides.values();
} | java | private static Collection<JsiiOverride> discoverOverrides(final Class<?> classToInspect) {
Map<String, JsiiOverride> overrides = new HashMap<>();
Class<?> klass = classToInspect;
// if we reached a generated jsii class or Object, we should stop collecting those overrides since
// all the rest of the hierarchy is generated all the way up to JsiiObject and java.lang.Object.
while (klass != null
&& klass.getDeclaredAnnotationsByType(Jsii.class).length == 0
&& klass != Object.class) {
// add all the methods in the current class
for (Method method : klass.getDeclaredMethods()) {
if (Modifier.isPrivate(method.getModifiers())) {
continue;
}
String methodName = method.getName();
// check if this is a property ("getXXX" or "setXXX", oh java!)
if (isJavaPropertyMethod(methodName)) {
String propertyName = javaPropertyToJSProperty(methodName);
// skip if this property is already in the overrides list
if (overrides.containsKey(propertyName)) {
continue;
}
JsiiOverride override = new JsiiOverride();
override.setProperty(propertyName);
overrides.put(propertyName, override);
} else {
// if this method is already overridden, skip it
if (overrides.containsKey(methodName)) {
continue;
}
// we use the method's .toString() as a cookie, which will later be used to identify the
// method when it is called back.
JsiiOverride override = new JsiiOverride();
override.setMethod(methodName);
override.setCookie(method.toString());
overrides.put(methodName, override);
}
}
klass = klass.getSuperclass();
}
return overrides.values();
} | [
"private",
"static",
"Collection",
"<",
"JsiiOverride",
">",
"discoverOverrides",
"(",
"final",
"Class",
"<",
"?",
">",
"classToInspect",
")",
"{",
"Map",
"<",
"String",
",",
"JsiiOverride",
">",
"overrides",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"Cl... | Prepare a list of methods which are overridden by Java classes.
@param classToInspect The java class to inspect for
@return A list of method names that should be overridden. | [
"Prepare",
"a",
"list",
"of",
"methods",
"which",
"are",
"overridden",
"by",
"Java",
"classes",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L469-L520 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.tryGetJsiiAnnotation | static Jsii tryGetJsiiAnnotation(final Class<?> type, final boolean inherited) {
Jsii[] ann;
if (inherited) {
ann = (Jsii[]) type.getAnnotationsByType(Jsii.class);
} else {
ann = (Jsii[]) type.getDeclaredAnnotationsByType(Jsii.class);
}
if (ann.length == 0) {
return null;
}
return ann[0];
} | java | static Jsii tryGetJsiiAnnotation(final Class<?> type, final boolean inherited) {
Jsii[] ann;
if (inherited) {
ann = (Jsii[]) type.getAnnotationsByType(Jsii.class);
} else {
ann = (Jsii[]) type.getDeclaredAnnotationsByType(Jsii.class);
}
if (ann.length == 0) {
return null;
}
return ann[0];
} | [
"static",
"Jsii",
"tryGetJsiiAnnotation",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
",",
"final",
"boolean",
"inherited",
")",
"{",
"Jsii",
"[",
"]",
"ann",
";",
"if",
"(",
"inherited",
")",
"{",
"ann",
"=",
"(",
"Jsii",
"[",
"]",
")",
"type",
... | Attempts to find the @Jsii annotation from a type.
@param type The type.
@param inherited If 'true' will look for the annotation up the class hierarchy.
@return The annotation or null. | [
"Attempts",
"to",
"find",
"the"
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L532-L546 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java | JsiiEngine.loadModuleForClass | String loadModuleForClass(Class<?> nativeClass) {
final Jsii jsii = tryGetJsiiAnnotation(nativeClass, true);
if (jsii == null) {
throw new JsiiException("Unable to find @Jsii annotation for class");
}
this.loadModule(jsii.module());
return jsii.fqn();
} | java | String loadModuleForClass(Class<?> nativeClass) {
final Jsii jsii = tryGetJsiiAnnotation(nativeClass, true);
if (jsii == null) {
throw new JsiiException("Unable to find @Jsii annotation for class");
}
this.loadModule(jsii.module());
return jsii.fqn();
} | [
"String",
"loadModuleForClass",
"(",
"Class",
"<",
"?",
">",
"nativeClass",
")",
"{",
"final",
"Jsii",
"jsii",
"=",
"tryGetJsiiAnnotation",
"(",
"nativeClass",
",",
"true",
")",
";",
"if",
"(",
"jsii",
"==",
"null",
")",
"{",
"throw",
"new",
"JsiiException... | Given a java class that extends a Jsii proxy, loads the corresponding jsii module
and returns the FQN of the jsii type.
@param nativeClass The java class.
@return The FQN. | [
"Given",
"a",
"java",
"class",
"that",
"extends",
"a",
"Jsii",
"proxy",
"loads",
"the",
"corresponding",
"jsii",
"module",
"and",
"returns",
"the",
"FQN",
"of",
"the",
"jsii",
"type",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiEngine.java#L554-L562 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/Util.java | Util.readString | static String readString(final InputStream is) {
try (final Scanner s = new Scanner(is, "UTF-8")) {
s.useDelimiter("\\A");
if (s.hasNext()) {
return s.next();
} else {
return "";
}
}
} | java | static String readString(final InputStream is) {
try (final Scanner s = new Scanner(is, "UTF-8")) {
s.useDelimiter("\\A");
if (s.hasNext()) {
return s.next();
} else {
return "";
}
}
} | [
"static",
"String",
"readString",
"(",
"final",
"InputStream",
"is",
")",
"{",
"try",
"(",
"final",
"Scanner",
"s",
"=",
"new",
"Scanner",
"(",
"is",
",",
"\"UTF-8\"",
")",
")",
"{",
"s",
".",
"useDelimiter",
"(",
"\"\\\\A\"",
")",
";",
"if",
"(",
"s... | Reads a string from an input stream.
@param is The input stream.,
@return A string. | [
"Reads",
"a",
"string",
"from",
"an",
"input",
"stream",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/Util.java#L32-L41 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/Util.java | Util.extractResource | static String extractResource(final Class<?> klass, final String resourceName, final String outputDirectory) throws IOException {
String directory = outputDirectory;
if (directory == null) {
directory = Files.createTempDirectory("jsii-java-runtime-resource").toString();
}
Path target = Paths.get(directory, resourceName);
// make sure directory tree is created, for the case of "@scoped/deps"
Files.createDirectories(target.getParent());
try (InputStream inputStream = klass.getResourceAsStream(resourceName)) {
Files.copy(inputStream, target);
}
return target.toAbsolutePath().toString();
} | java | static String extractResource(final Class<?> klass, final String resourceName, final String outputDirectory) throws IOException {
String directory = outputDirectory;
if (directory == null) {
directory = Files.createTempDirectory("jsii-java-runtime-resource").toString();
}
Path target = Paths.get(directory, resourceName);
// make sure directory tree is created, for the case of "@scoped/deps"
Files.createDirectories(target.getParent());
try (InputStream inputStream = klass.getResourceAsStream(resourceName)) {
Files.copy(inputStream, target);
}
return target.toAbsolutePath().toString();
} | [
"static",
"String",
"extractResource",
"(",
"final",
"Class",
"<",
"?",
">",
"klass",
",",
"final",
"String",
"resourceName",
",",
"final",
"String",
"outputDirectory",
")",
"throws",
"IOException",
"{",
"String",
"directory",
"=",
"outputDirectory",
";",
"if",
... | Extracts a resource file from the .jar and saves it into an output directory.
@param url The URL of the resource
@param outputDirectory The output directory (optional)
@return The full path of the saved resource
@throws IOException If there was an I/O error | [
"Extracts",
"a",
"resource",
"file",
"from",
"the",
".",
"jar",
"and",
"saves",
"it",
"into",
"an",
"output",
"directory",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/Util.java#L102-L118 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiCall | @Nullable
protected final <T> T jsiiCall(final String method, final Class<T> returnType, @Nullable final Object... args) {
return JsiiObjectMapper.treeToValue(JsiiObject.engine.getClient()
.callMethod(this.objRef,
method,
JsiiObjectMapper.valueToTree(args)),
returnType);
} | java | @Nullable
protected final <T> T jsiiCall(final String method, final Class<T> returnType, @Nullable final Object... args) {
return JsiiObjectMapper.treeToValue(JsiiObject.engine.getClient()
.callMethod(this.objRef,
method,
JsiiObjectMapper.valueToTree(args)),
returnType);
} | [
"@",
"Nullable",
"protected",
"final",
"<",
"T",
">",
"T",
"jsiiCall",
"(",
"final",
"String",
"method",
",",
"final",
"Class",
"<",
"T",
">",
"returnType",
",",
"@",
"Nullable",
"final",
"Object",
"...",
"args",
")",
"{",
"return",
"JsiiObjectMapper",
"... | Calls a JavaScript method on the object.
@param method The name of the method.
@param returnType The return type.
@param args Method arguments.
@param <T> Java type for the return value.
@return A return value. | [
"Calls",
"a",
"JavaScript",
"method",
"on",
"the",
"object",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L54-L61 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiStaticCall | @Nullable
protected static <T> T jsiiStaticCall(final Class<?> nativeClass, final String method, final Class<T> returnType, @Nullable final Object... args) {
String fqn = engine.loadModuleForClass(nativeClass);
return JsiiObjectMapper.treeToValue(engine.getClient()
.callStaticMethod(fqn, method, JsiiObjectMapper.valueToTree(args)),
returnType);
} | java | @Nullable
protected static <T> T jsiiStaticCall(final Class<?> nativeClass, final String method, final Class<T> returnType, @Nullable final Object... args) {
String fqn = engine.loadModuleForClass(nativeClass);
return JsiiObjectMapper.treeToValue(engine.getClient()
.callStaticMethod(fqn, method, JsiiObjectMapper.valueToTree(args)),
returnType);
} | [
"@",
"Nullable",
"protected",
"static",
"<",
"T",
">",
"T",
"jsiiStaticCall",
"(",
"final",
"Class",
"<",
"?",
">",
"nativeClass",
",",
"final",
"String",
"method",
",",
"final",
"Class",
"<",
"T",
">",
"returnType",
",",
"@",
"Nullable",
"final",
"Objec... | Calls a static method.
@param nativeClass The java class.
@param method The method to call.
@param returnType The return type.
@param args The method arguments.
@param <T> Return type.
@return Return value. | [
"Calls",
"a",
"static",
"method",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L72-L78 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiAsyncCall | @Nullable
protected final <T> T jsiiAsyncCall(final String method, final Class<T> returnType, @Nullable final Object... args) {
JsiiClient client = engine.getClient();
JsiiPromise promise = client.beginAsyncMethod(this.objRef, method, JsiiObjectMapper.valueToTree(args));
engine.processAllPendingCallbacks();
return JsiiObjectMapper.treeToValue(client.endAsyncMethod(promise), returnType);
} | java | @Nullable
protected final <T> T jsiiAsyncCall(final String method, final Class<T> returnType, @Nullable final Object... args) {
JsiiClient client = engine.getClient();
JsiiPromise promise = client.beginAsyncMethod(this.objRef, method, JsiiObjectMapper.valueToTree(args));
engine.processAllPendingCallbacks();
return JsiiObjectMapper.treeToValue(client.endAsyncMethod(promise), returnType);
} | [
"@",
"Nullable",
"protected",
"final",
"<",
"T",
">",
"T",
"jsiiAsyncCall",
"(",
"final",
"String",
"method",
",",
"final",
"Class",
"<",
"T",
">",
"returnType",
",",
"@",
"Nullable",
"final",
"Object",
"...",
"args",
")",
"{",
"JsiiClient",
"client",
"=... | Calls an async method on the object.
@param method The name of the method.
@param returnType The return type.
@param args Method arguments.
@param <T> Java type for the return value.
@return A ereturn value. | [
"Calls",
"an",
"async",
"method",
"on",
"the",
"object",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L88-L96 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiGet | @Nullable
protected final <T> T jsiiGet(final String property, final Class<T> type) {
return JsiiObjectMapper.treeToValue(engine.getClient().getPropertyValue(this.objRef, property), type);
} | java | @Nullable
protected final <T> T jsiiGet(final String property, final Class<T> type) {
return JsiiObjectMapper.treeToValue(engine.getClient().getPropertyValue(this.objRef, property), type);
} | [
"@",
"Nullable",
"protected",
"final",
"<",
"T",
">",
"T",
"jsiiGet",
"(",
"final",
"String",
"property",
",",
"final",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"return",
"JsiiObjectMapper",
".",
"treeToValue",
"(",
"engine",
".",
"getClient",
"(",
")",... | Gets a property value from the object.
@param property The property name.
@param type The Java type of the property.
@param <T> The Java type of the property.
@return The property value. | [
"Gets",
"a",
"property",
"value",
"from",
"the",
"object",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L105-L108 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiStaticGet | @Nullable
protected static <T> T jsiiStaticGet(final Class<?> nativeClass, final String property, final Class<T> type) {
String fqn = engine.loadModuleForClass(nativeClass);
return JsiiObjectMapper.treeToValue(engine.getClient().getStaticPropertyValue(fqn, property), type);
} | java | @Nullable
protected static <T> T jsiiStaticGet(final Class<?> nativeClass, final String property, final Class<T> type) {
String fqn = engine.loadModuleForClass(nativeClass);
return JsiiObjectMapper.treeToValue(engine.getClient().getStaticPropertyValue(fqn, property), type);
} | [
"@",
"Nullable",
"protected",
"static",
"<",
"T",
">",
"T",
"jsiiStaticGet",
"(",
"final",
"Class",
"<",
"?",
">",
"nativeClass",
",",
"final",
"String",
"property",
",",
"final",
"Class",
"<",
"T",
">",
"type",
")",
"{",
"String",
"fqn",
"=",
"engine"... | Returns the value of a static property.
@param nativeClass The java class.
@param property The name of the property.
@param type The expected java return type.
@param <T> Return type
@return Return value | [
"Returns",
"the",
"value",
"of",
"a",
"static",
"property",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L118-L122 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiSet | protected final void jsiiSet(final String property, @Nullable final Object value) {
engine.getClient().setPropertyValue(this.objRef, property, JsiiObjectMapper.valueToTree(value));
} | java | protected final void jsiiSet(final String property, @Nullable final Object value) {
engine.getClient().setPropertyValue(this.objRef, property, JsiiObjectMapper.valueToTree(value));
} | [
"protected",
"final",
"void",
"jsiiSet",
"(",
"final",
"String",
"property",
",",
"@",
"Nullable",
"final",
"Object",
"value",
")",
"{",
"engine",
".",
"getClient",
"(",
")",
".",
"setPropertyValue",
"(",
"this",
".",
"objRef",
",",
"property",
",",
"JsiiO... | Sets a property value of an object.
@param property The name of the property.
@param value The property value. | [
"Sets",
"a",
"property",
"value",
"of",
"an",
"object",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L129-L131 | train |
awslabs/jsii | packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java | JsiiObject.jsiiStaticSet | protected static void jsiiStaticSet(final Class<?> nativeClass, final String property, @Nullable final Object value) {
String fqn = engine.loadModuleForClass(nativeClass);
engine.getClient().setStaticPropertyValue(fqn, property, JsiiObjectMapper.valueToTree(value));
} | java | protected static void jsiiStaticSet(final Class<?> nativeClass, final String property, @Nullable final Object value) {
String fqn = engine.loadModuleForClass(nativeClass);
engine.getClient().setStaticPropertyValue(fqn, property, JsiiObjectMapper.valueToTree(value));
} | [
"protected",
"static",
"void",
"jsiiStaticSet",
"(",
"final",
"Class",
"<",
"?",
">",
"nativeClass",
",",
"final",
"String",
"property",
",",
"@",
"Nullable",
"final",
"Object",
"value",
")",
"{",
"String",
"fqn",
"=",
"engine",
".",
"loadModuleForClass",
"(... | Sets a value for a static property.
@param nativeClass The java class.
@param property The name of the property
@param value The value | [
"Sets",
"a",
"value",
"for",
"a",
"static",
"property",
"."
] | 6bbf743f5f65e98e5199ad31c93961533ffc40e5 | https://github.com/awslabs/jsii/blob/6bbf743f5f65e98e5199ad31c93961533ffc40e5/packages/jsii-java-runtime/project/src/main/java/software/amazon/jsii/JsiiObject.java#L139-L142 | train |
NordicSemiconductor/Android-Scanner-Compat-Library | scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeUtils.java | BluetoothLeUtils.checkAdapterStateOn | @RequiresPermission(Manifest.permission.BLUETOOTH)
static void checkAdapterStateOn(@Nullable final BluetoothAdapter adapter) {
if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) {
throw new IllegalStateException("BT Adapter is not turned ON");
}
} | java | @RequiresPermission(Manifest.permission.BLUETOOTH)
static void checkAdapterStateOn(@Nullable final BluetoothAdapter adapter) {
if (adapter == null || adapter.getState() != BluetoothAdapter.STATE_ON) {
throw new IllegalStateException("BT Adapter is not turned ON");
}
} | [
"@",
"RequiresPermission",
"(",
"Manifest",
".",
"permission",
".",
"BLUETOOTH",
")",
"static",
"void",
"checkAdapterStateOn",
"(",
"@",
"Nullable",
"final",
"BluetoothAdapter",
"adapter",
")",
"{",
"if",
"(",
"adapter",
"==",
"null",
"||",
"adapter",
".",
"ge... | Ensure Bluetooth is turned on.
@throws IllegalStateException If {@code adapter} is null or Bluetooth state is not
{@link BluetoothAdapter#STATE_ON}. | [
"Ensure",
"Bluetooth",
"is",
"turned",
"on",
"."
] | 569982877c77c005649f728809d3199faf2080af | https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/569982877c77c005649f728809d3199faf2080af/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeUtils.java#L137-L142 | train |
NordicSemiconductor/Android-Scanner-Compat-Library | scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanFilter.java | ScanFilter.matchesServiceUuid | private static boolean matchesServiceUuid(@NonNull final UUID uuid,
@Nullable final UUID mask,
@NonNull final UUID data) {
if (mask == null) {
return uuid.equals(data);
}
if ((uuid.getLeastSignificantBits() & mask.getLeastSignificantBits()) !=
(data.getLeastSignificantBits() & mask.getLeastSignificantBits())) {
return false;
}
return ((uuid.getMostSignificantBits() & mask.getMostSignificantBits()) ==
(data.getMostSignificantBits() & mask.getMostSignificantBits()));
} | java | private static boolean matchesServiceUuid(@NonNull final UUID uuid,
@Nullable final UUID mask,
@NonNull final UUID data) {
if (mask == null) {
return uuid.equals(data);
}
if ((uuid.getLeastSignificantBits() & mask.getLeastSignificantBits()) !=
(data.getLeastSignificantBits() & mask.getLeastSignificantBits())) {
return false;
}
return ((uuid.getMostSignificantBits() & mask.getMostSignificantBits()) ==
(data.getMostSignificantBits() & mask.getMostSignificantBits()));
} | [
"private",
"static",
"boolean",
"matchesServiceUuid",
"(",
"@",
"NonNull",
"final",
"UUID",
"uuid",
",",
"@",
"Nullable",
"final",
"UUID",
"mask",
",",
"@",
"NonNull",
"final",
"UUID",
"data",
")",
"{",
"if",
"(",
"mask",
"==",
"null",
")",
"{",
"return"... | Check if the uuid pattern matches the particular service uuid. | [
"Check",
"if",
"the",
"uuid",
"pattern",
"matches",
"the",
"particular",
"service",
"uuid",
"."
] | 569982877c77c005649f728809d3199faf2080af | https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/569982877c77c005649f728809d3199faf2080af/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanFilter.java#L350-L362 | train |
NordicSemiconductor/Android-Scanner-Compat-Library | scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanFilter.java | ScanFilter.matchesPartialData | @SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean matchesPartialData(@Nullable final byte[] data,
@Nullable final byte[] dataMask,
@Nullable final byte[] parsedData) {
if (data == null) {
// If filter data is null it means it doesn't matter.
// We return true if any data matching the manufacturerId were found.
return parsedData != null;
}
if (parsedData == null || parsedData.length < data.length) {
return false;
}
if (dataMask == null) {
for (int i = 0; i < data.length; ++i) {
if (parsedData[i] != data[i]) {
return false;
}
}
return true;
}
for (int i = 0; i < data.length; ++i) {
if ((dataMask[i] & parsedData[i]) != (dataMask[i] & data[i])) {
return false;
}
}
return true;
} | java | @SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean matchesPartialData(@Nullable final byte[] data,
@Nullable final byte[] dataMask,
@Nullable final byte[] parsedData) {
if (data == null) {
// If filter data is null it means it doesn't matter.
// We return true if any data matching the manufacturerId were found.
return parsedData != null;
}
if (parsedData == null || parsedData.length < data.length) {
return false;
}
if (dataMask == null) {
for (int i = 0; i < data.length; ++i) {
if (parsedData[i] != data[i]) {
return false;
}
}
return true;
}
for (int i = 0; i < data.length; ++i) {
if ((dataMask[i] & parsedData[i]) != (dataMask[i] & data[i])) {
return false;
}
}
return true;
} | [
"@",
"SuppressWarnings",
"(",
"\"BooleanMethodIsAlwaysInverted\"",
")",
"private",
"boolean",
"matchesPartialData",
"(",
"@",
"Nullable",
"final",
"byte",
"[",
"]",
"data",
",",
"@",
"Nullable",
"final",
"byte",
"[",
"]",
"dataMask",
",",
"@",
"Nullable",
"final... | Check whether the data pattern matches the parsed data. | [
"Check",
"whether",
"the",
"data",
"pattern",
"matches",
"the",
"parsed",
"data",
"."
] | 569982877c77c005649f728809d3199faf2080af | https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/569982877c77c005649f728809d3199faf2080af/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/ScanFilter.java#L365-L391 | train |
NordicSemiconductor/Android-Scanner-Compat-Library | scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeScannerCompat.java | BluetoothLeScannerCompat.getScanner | @NonNull
public synchronized static BluetoothLeScannerCompat getScanner() {
if (instance != null)
return instance;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
return instance = new BluetoothLeScannerImplOreo();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return instance = new BluetoothLeScannerImplMarshmallow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
return instance = new BluetoothLeScannerImplLollipop();
return instance = new BluetoothLeScannerImplJB();
} | java | @NonNull
public synchronized static BluetoothLeScannerCompat getScanner() {
if (instance != null)
return instance;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
return instance = new BluetoothLeScannerImplOreo();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
return instance = new BluetoothLeScannerImplMarshmallow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
return instance = new BluetoothLeScannerImplLollipop();
return instance = new BluetoothLeScannerImplJB();
} | [
"@",
"NonNull",
"public",
"synchronized",
"static",
"BluetoothLeScannerCompat",
"getScanner",
"(",
")",
"{",
"if",
"(",
"instance",
"!=",
"null",
")",
"return",
"instance",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION... | Returns the scanner compat object
@return scanner implementation | [
"Returns",
"the",
"scanner",
"compat",
"object"
] | 569982877c77c005649f728809d3199faf2080af | https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/569982877c77c005649f728809d3199faf2080af/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeScannerCompat.java#L96-L107 | train |
NordicSemiconductor/Android-Scanner-Compat-Library | scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeScannerImplJB.java | BluetoothLeScannerImplJB.setPowerSaveSettings | private void setPowerSaveSettings() {
long minRest = Long.MAX_VALUE, minScan = Long.MAX_VALUE;
synchronized (wrappers) {
for (final ScanCallbackWrapper wrapper : wrappers.values()) {
final ScanSettings settings = wrapper.scanSettings;
if (settings.hasPowerSaveMode()) {
if (minRest > settings.getPowerSaveRest()) {
minRest = settings.getPowerSaveRest();
}
if (minScan > settings.getPowerSaveScan()) {
minScan = settings.getPowerSaveScan();
}
}
}
}
if (minRest < Long.MAX_VALUE && minScan < Long.MAX_VALUE) {
powerSaveRestInterval = minRest;
powerSaveScanInterval = minScan;
if (powerSaveHandler != null) {
powerSaveHandler.removeCallbacks(powerSaveScanTask);
powerSaveHandler.removeCallbacks(powerSaveSleepTask);
powerSaveHandler.postDelayed(powerSaveSleepTask, powerSaveScanInterval);
}
} else {
powerSaveRestInterval = powerSaveScanInterval = 0;
if (powerSaveHandler != null) {
powerSaveHandler.removeCallbacks(powerSaveScanTask);
powerSaveHandler.removeCallbacks(powerSaveSleepTask);
}
}
} | java | private void setPowerSaveSettings() {
long minRest = Long.MAX_VALUE, minScan = Long.MAX_VALUE;
synchronized (wrappers) {
for (final ScanCallbackWrapper wrapper : wrappers.values()) {
final ScanSettings settings = wrapper.scanSettings;
if (settings.hasPowerSaveMode()) {
if (minRest > settings.getPowerSaveRest()) {
minRest = settings.getPowerSaveRest();
}
if (minScan > settings.getPowerSaveScan()) {
minScan = settings.getPowerSaveScan();
}
}
}
}
if (minRest < Long.MAX_VALUE && minScan < Long.MAX_VALUE) {
powerSaveRestInterval = minRest;
powerSaveScanInterval = minScan;
if (powerSaveHandler != null) {
powerSaveHandler.removeCallbacks(powerSaveScanTask);
powerSaveHandler.removeCallbacks(powerSaveSleepTask);
powerSaveHandler.postDelayed(powerSaveSleepTask, powerSaveScanInterval);
}
} else {
powerSaveRestInterval = powerSaveScanInterval = 0;
if (powerSaveHandler != null) {
powerSaveHandler.removeCallbacks(powerSaveScanTask);
powerSaveHandler.removeCallbacks(powerSaveSleepTask);
}
}
} | [
"private",
"void",
"setPowerSaveSettings",
"(",
")",
"{",
"long",
"minRest",
"=",
"Long",
".",
"MAX_VALUE",
",",
"minScan",
"=",
"Long",
".",
"MAX_VALUE",
";",
"synchronized",
"(",
"wrappers",
")",
"{",
"for",
"(",
"final",
"ScanCallbackWrapper",
"wrapper",
... | This method goes through registered callbacks and sets the power rest and scan intervals
to next lowest value. | [
"This",
"method",
"goes",
"through",
"registered",
"callbacks",
"and",
"sets",
"the",
"power",
"rest",
"and",
"scan",
"intervals",
"to",
"next",
"lowest",
"value",
"."
] | 569982877c77c005649f728809d3199faf2080af | https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library/blob/569982877c77c005649f728809d3199faf2080af/scanner/src/main/java/no/nordicsemi/android/support/v18/scanner/BluetoothLeScannerImplJB.java#L213-L243 | train |
alibaba/Virtualview-Android | virtualview/src/main/java/com/tmall/wireless/vaf/expr/engine/CodeReader.java | CodeReader.setCode | public void setCode(ExprCode code) {
mCode = code;
mStartPos = mCode.mStartPos;
mCurIndex = mStartPos;
} | java | public void setCode(ExprCode code) {
mCode = code;
mStartPos = mCode.mStartPos;
mCurIndex = mStartPos;
} | [
"public",
"void",
"setCode",
"(",
"ExprCode",
"code",
")",
"{",
"mCode",
"=",
"code",
";",
"mStartPos",
"=",
"mCode",
".",
"mStartPos",
";",
"mCurIndex",
"=",
"mStartPos",
";",
"}"
] | private int mCount; | [
"private",
"int",
"mCount",
";"
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/virtualview/src/main/java/com/tmall/wireless/vaf/expr/engine/CodeReader.java#L39-L44 | train |
alibaba/Virtualview-Android | virtualview/src/main/java/com/tmall/wireless/vaf/virtualview/Helper/RtlHelper.java | RtlHelper.isRtl | public static boolean isRtl() {
if (sEnable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
}
return false;
} | java | public static boolean isRtl() {
if (sEnable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return View.LAYOUT_DIRECTION_RTL == TextUtils.getLayoutDirectionFromLocale(Locale.getDefault());
}
return false;
} | [
"public",
"static",
"boolean",
"isRtl",
"(",
")",
"{",
"if",
"(",
"sEnable",
"&&",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"JELLY_BEAN_MR1",
")",
"{",
"return",
"View",
".",
"LAYOUT_DIRECTION_RTL",
"==",
"TextUtils"... | In Rtl env or not.
@return true if in Rtl env. | [
"In",
"Rtl",
"env",
"or",
"not",
"."
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/virtualview/src/main/java/com/tmall/wireless/vaf/virtualview/Helper/RtlHelper.java#L33-L39 | train |
alibaba/Virtualview-Android | virtualview/src/main/java/com/tmall/wireless/vaf/virtualview/Helper/RtlHelper.java | RtlHelper.getRealLeft | public static int getRealLeft(boolean isRtl, int parentLeft, int parentWidth, int left, int width) {
if (isRtl) {
// 1, trim the parent's left.
left -= parentLeft;
// 2, calculate the RTL left.
left = parentWidth - width - left;
// 3, add the parent's left.
left += parentLeft;
}
return left;
} | java | public static int getRealLeft(boolean isRtl, int parentLeft, int parentWidth, int left, int width) {
if (isRtl) {
// 1, trim the parent's left.
left -= parentLeft;
// 2, calculate the RTL left.
left = parentWidth - width - left;
// 3, add the parent's left.
left += parentLeft;
}
return left;
} | [
"public",
"static",
"int",
"getRealLeft",
"(",
"boolean",
"isRtl",
",",
"int",
"parentLeft",
",",
"int",
"parentWidth",
",",
"int",
"left",
",",
"int",
"width",
")",
"{",
"if",
"(",
"isRtl",
")",
"{",
"// 1, trim the parent's left.",
"left",
"-=",
"parentLef... | Convert left to RTL left if need.
@param parentLeft parent's left
@param parentWidth parent's width
@param left self's left
@param width self's width
@return | [
"Convert",
"left",
"to",
"RTL",
"left",
"if",
"need",
"."
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/virtualview/src/main/java/com/tmall/wireless/vaf/virtualview/Helper/RtlHelper.java#L49-L59 | train |
alibaba/Virtualview-Android | app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java | ViewServer.get | public static ViewServer get(Context context) {
ApplicationInfo info = context.getApplicationInfo();
if (BUILD_TYPE_USER.equals(Build.TYPE) &&
(info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
if (sServer == null) {
sServer = new ViewServer(ViewServer.VIEW_SERVER_DEFAULT_PORT);
}
if (!sServer.isRunning()) {
try {
sServer.start();
} catch (IOException e) {
Log.d(LOG_TAG, "Error:", e);
}
}
} else {
sServer = new NoopViewServer();
}
return sServer;
} | java | public static ViewServer get(Context context) {
ApplicationInfo info = context.getApplicationInfo();
if (BUILD_TYPE_USER.equals(Build.TYPE) &&
(info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
if (sServer == null) {
sServer = new ViewServer(ViewServer.VIEW_SERVER_DEFAULT_PORT);
}
if (!sServer.isRunning()) {
try {
sServer.start();
} catch (IOException e) {
Log.d(LOG_TAG, "Error:", e);
}
}
} else {
sServer = new NoopViewServer();
}
return sServer;
} | [
"public",
"static",
"ViewServer",
"get",
"(",
"Context",
"context",
")",
"{",
"ApplicationInfo",
"info",
"=",
"context",
".",
"getApplicationInfo",
"(",
")",
";",
"if",
"(",
"BUILD_TYPE_USER",
".",
"equals",
"(",
"Build",
".",
"TYPE",
")",
"&&",
"(",
"info... | Returns a unique instance of the ViewServer. This method should only be
called from the main thread of your application. The server will have
the same lifetime as your process.
If your application does not have the <code>android:debuggable</code>
flag set in its manifest, the server returned by this method will
be a dummy object that does not do anything. This allows you to use
the same code in debug and release versions of your application.
@param context A Context used to check whether the application is
debuggable, this can be the application context | [
"Returns",
"a",
"unique",
"instance",
"of",
"the",
"ViewServer",
".",
"This",
"method",
"should",
"only",
"be",
"called",
"from",
"the",
"main",
"thread",
"of",
"your",
"application",
".",
"The",
"server",
"will",
"have",
"the",
"same",
"lifetime",
"as",
"... | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java#L173-L193 | train |
alibaba/Virtualview-Android | app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java | ViewServer.removeWindow | public void removeWindow(View view) {
mWindowsLock.writeLock().lock();
try {
mWindows.remove(view.getRootView());
} finally {
mWindowsLock.writeLock().unlock();
}
fireWindowsChangedEvent();
} | java | public void removeWindow(View view) {
mWindowsLock.writeLock().lock();
try {
mWindows.remove(view.getRootView());
} finally {
mWindowsLock.writeLock().unlock();
}
fireWindowsChangedEvent();
} | [
"public",
"void",
"removeWindow",
"(",
"View",
"view",
")",
"{",
"mWindowsLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"mWindows",
".",
"remove",
"(",
"view",
".",
"getRootView",
"(",
")",
")",
";",
"}",
"finally",
"{",
... | Invoke this method to unregister a view hierarchy.
@param view A view that belongs to the view hierarchy/window to unregister
@see #addWindow(View, String) | [
"Invoke",
"this",
"method",
"to",
"unregister",
"a",
"view",
"hierarchy",
"."
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java#L353-L361 | train |
alibaba/Virtualview-Android | app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java | ViewServer.setFocusedWindow | public void setFocusedWindow(View view) {
mFocusLock.writeLock().lock();
try {
mFocusedWindow = view == null ? null : view.getRootView();
} finally {
mFocusLock.writeLock().unlock();
}
fireFocusChangedEvent();
} | java | public void setFocusedWindow(View view) {
mFocusLock.writeLock().lock();
try {
mFocusedWindow = view == null ? null : view.getRootView();
} finally {
mFocusLock.writeLock().unlock();
}
fireFocusChangedEvent();
} | [
"public",
"void",
"setFocusedWindow",
"(",
"View",
"view",
")",
"{",
"mFocusLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"mFocusedWindow",
"=",
"view",
"==",
"null",
"?",
"null",
":",
"view",
".",
"getRootView",
"(",
")",
... | Invoke this method to change the currently focused window.
@param view A view that belongs to the view hierarchy/window that has focus,
or null to remove focus | [
"Invoke",
"this",
"method",
"to",
"change",
"the",
"currently",
"focused",
"window",
"."
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java#L379-L387 | train |
alibaba/Virtualview-Android | app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java | ViewServer.run | public void run() {
try {
mServer = new ServerSocket(mPort, VIEW_SERVER_MAX_CONNECTIONS, InetAddress.getLocalHost());
} catch (Exception e) {
Log.w(LOG_TAG, "Starting ServerSocket error: ", e);
}
while (mServer != null && Thread.currentThread() == mThread) {
// Any uncaught exception will crash the system process
try {
Socket client = mServer.accept();
if (mThreadPool != null) {
mThreadPool.submit(new ViewServerWorker(client));
} else {
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
Log.w(LOG_TAG, "Connection error: ", e);
}
}
} | java | public void run() {
try {
mServer = new ServerSocket(mPort, VIEW_SERVER_MAX_CONNECTIONS, InetAddress.getLocalHost());
} catch (Exception e) {
Log.w(LOG_TAG, "Starting ServerSocket error: ", e);
}
while (mServer != null && Thread.currentThread() == mThread) {
// Any uncaught exception will crash the system process
try {
Socket client = mServer.accept();
if (mThreadPool != null) {
mThreadPool.submit(new ViewServerWorker(client));
} else {
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
Log.w(LOG_TAG, "Connection error: ", e);
}
}
} | [
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"mServer",
"=",
"new",
"ServerSocket",
"(",
"mPort",
",",
"VIEW_SERVER_MAX_CONNECTIONS",
",",
"InetAddress",
".",
"getLocalHost",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"Log"... | Main server loop. | [
"Main",
"server",
"loop",
"."
] | 30c65791f34458ec840e00d2b84ab2912ea102f0 | https://github.com/alibaba/Virtualview-Android/blob/30c65791f34458ec840e00d2b84ab2912ea102f0/app/src/main/java/com/tmall/wireless/virtualviewdemo/ViewServer.java#L392-L416 | train |
restfb/restfb | src/main/java/com/restfb/util/UrlUtils.java | UrlUtils.removeQueryParameter | public static String removeQueryParameter(String url, String key) {
String[] urlParts = url.split("\\?");
if (urlParts.length == 2) {
Map<String, List<String>> paramMap = extractParametersFromQueryString(urlParts[1]);
if (paramMap.containsKey(key)) {
String queryValue = paramMap.get(key).get(0);
String result = url.replace(key + "=" + queryValue, "");
// improper separators have to be fixed
// @TODO find a better way to solve this
result = result.replace("?&", "?").replace("&&", "&");
if (result.endsWith("&")) {
return result.substring(0, result.length() - 1);
} else {
return result;
}
}
}
return url;
} | java | public static String removeQueryParameter(String url, String key) {
String[] urlParts = url.split("\\?");
if (urlParts.length == 2) {
Map<String, List<String>> paramMap = extractParametersFromQueryString(urlParts[1]);
if (paramMap.containsKey(key)) {
String queryValue = paramMap.get(key).get(0);
String result = url.replace(key + "=" + queryValue, "");
// improper separators have to be fixed
// @TODO find a better way to solve this
result = result.replace("?&", "?").replace("&&", "&");
if (result.endsWith("&")) {
return result.substring(0, result.length() - 1);
} else {
return result;
}
}
}
return url;
} | [
"public",
"static",
"String",
"removeQueryParameter",
"(",
"String",
"url",
",",
"String",
"key",
")",
"{",
"String",
"[",
"]",
"urlParts",
"=",
"url",
".",
"split",
"(",
"\"\\\\?\"",
")",
";",
"if",
"(",
"urlParts",
".",
"length",
"==",
"2",
")",
"{",... | Remove the given key from the url query string and return the new URL as String.
@param url
The URL from which parameters are extracted.
@param key
the key, that should be removed
@return the modified URL as String | [
"Remove",
"the",
"given",
"key",
"from",
"the",
"url",
"query",
"string",
"and",
"return",
"the",
"new",
"URL",
"as",
"String",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/util/UrlUtils.java#L204-L223 | train |
restfb/restfb | src/main/java/com/restfb/BaseFacebookClient.java | BaseFacebookClient.verifyParameterLegality | protected void verifyParameterLegality(Parameter... parameters) {
for (Parameter parameter : parameters)
if (illegalParamNames.contains(parameter.name)) {
throw new IllegalArgumentException(
"Parameter '" + parameter.name + "' is reserved for RestFB use - you cannot specify it yourself.");
}
} | java | protected void verifyParameterLegality(Parameter... parameters) {
for (Parameter parameter : parameters)
if (illegalParamNames.contains(parameter.name)) {
throw new IllegalArgumentException(
"Parameter '" + parameter.name + "' is reserved for RestFB use - you cannot specify it yourself.");
}
} | [
"protected",
"void",
"verifyParameterLegality",
"(",
"Parameter",
"...",
"parameters",
")",
"{",
"for",
"(",
"Parameter",
"parameter",
":",
"parameters",
")",
"if",
"(",
"illegalParamNames",
".",
"contains",
"(",
"parameter",
".",
"name",
")",
")",
"{",
"throw... | Verifies that the provided parameter names don't collide with the ones we internally pass along to Facebook.
@param parameters
The parameters to check.
@throws IllegalArgumentException
If there's a parameter name collision. | [
"Verifies",
"that",
"the",
"provided",
"parameter",
"names",
"don",
"t",
"collide",
"with",
"the",
"ones",
"we",
"internally",
"pass",
"along",
"to",
"Facebook",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/BaseFacebookClient.java#L136-L142 | train |
restfb/restfb | src/main/lombok/com/restfb/types/webhook/messaging/NlpResult.java | NlpResult.getEntities | public <T extends BaseNlpEntity> List<T> getEntities(Class<T> clazz) {
List<BaseNlpEntity> resultList = new ArrayList<>();
for (BaseNlpEntity item : getEntities()) {
if (item.getClass().equals(clazz)) {
resultList.add(item);
}
}
return (List<T>) resultList;
} | java | public <T extends BaseNlpEntity> List<T> getEntities(Class<T> clazz) {
List<BaseNlpEntity> resultList = new ArrayList<>();
for (BaseNlpEntity item : getEntities()) {
if (item.getClass().equals(clazz)) {
resultList.add(item);
}
}
return (List<T>) resultList;
} | [
"public",
"<",
"T",
"extends",
"BaseNlpEntity",
">",
"List",
"<",
"T",
">",
"getEntities",
"(",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"List",
"<",
"BaseNlpEntity",
">",
"resultList",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Bas... | returns a subset of the found entities.
Only entities that are of type <code>T</code> are returned. T needs to extend the {@link BaseNlpEntity}.
@param clazz
the filter class
@return List of entites, only the filtered elements are returned. | [
"returns",
"a",
"subset",
"of",
"the",
"found",
"entities",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/webhook/messaging/NlpResult.java#L138-L146 | train |
restfb/restfb | src/main/lombok/com/restfb/types/Comments.java | Comments.fillOrder | private void fillOrder(JsonObject summary) {
if (summary != null) {
order = summary.getString("order", order);
}
if (order == null && openGraphCommentOrder != null) {
order = openGraphCommentOrder;
}
} | java | private void fillOrder(JsonObject summary) {
if (summary != null) {
order = summary.getString("order", order);
}
if (order == null && openGraphCommentOrder != null) {
order = openGraphCommentOrder;
}
} | [
"private",
"void",
"fillOrder",
"(",
"JsonObject",
"summary",
")",
"{",
"if",
"(",
"summary",
"!=",
"null",
")",
"{",
"order",
"=",
"summary",
".",
"getString",
"(",
"\"order\"",
",",
"order",
")",
";",
"}",
"if",
"(",
"order",
"==",
"null",
"&&",
"o... | set the order the comments are sorted | [
"set",
"the",
"order",
"the",
"comments",
"are",
"sorted"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/Comments.java#L157-L165 | train |
restfb/restfb | src/main/lombok/com/restfb/types/Comments.java | Comments.fillCanComment | private void fillCanComment(JsonObject summary) {
if (summary != null && summary.get("can_comment") != null) {
canComment = summary.get("can_comment").asBoolean();
}
if (canComment == null && openGraphCanComment != null) {
canComment = openGraphCanComment;
}
} | java | private void fillCanComment(JsonObject summary) {
if (summary != null && summary.get("can_comment") != null) {
canComment = summary.get("can_comment").asBoolean();
}
if (canComment == null && openGraphCanComment != null) {
canComment = openGraphCanComment;
}
} | [
"private",
"void",
"fillCanComment",
"(",
"JsonObject",
"summary",
")",
"{",
"if",
"(",
"summary",
"!=",
"null",
"&&",
"summary",
".",
"get",
"(",
"\"can_comment\"",
")",
"!=",
"null",
")",
"{",
"canComment",
"=",
"summary",
".",
"get",
"(",
"\"can_comment... | set the can_comment | [
"set",
"the",
"can_comment"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/Comments.java#L170-L178 | train |
restfb/restfb | src/main/java/com/restfb/util/EncodingUtils.java | EncodingUtils.decodeBase64 | public static byte[] decodeBase64(String base64) {
if (base64 == null)
throw new NullPointerException("Parameter 'base64' cannot be null.");
String fixedBase64 = padBase64(base64);
return Base64.getDecoder().decode(fixedBase64);
} | java | public static byte[] decodeBase64(String base64) {
if (base64 == null)
throw new NullPointerException("Parameter 'base64' cannot be null.");
String fixedBase64 = padBase64(base64);
return Base64.getDecoder().decode(fixedBase64);
} | [
"public",
"static",
"byte",
"[",
"]",
"decodeBase64",
"(",
"String",
"base64",
")",
"{",
"if",
"(",
"base64",
"==",
"null",
")",
"throw",
"new",
"NullPointerException",
"(",
"\"Parameter 'base64' cannot be null.\"",
")",
";",
"String",
"fixedBase64",
"=",
"padBa... | Decodes a base64-encoded string, padding out if necessary.
@param base64
The base64-encoded string to decode.
@return A decoded version of {@code base64}.
@throws NullPointerException
If {@code base64} is {@code null}. | [
"Decodes",
"a",
"base64",
"-",
"encoded",
"string",
"padding",
"out",
"if",
"necessary",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/util/EncodingUtils.java#L53-L59 | train |
restfb/restfb | src/main/java/com/restfb/util/EncodingUtils.java | EncodingUtils.encodeAppSecretProof | public static String encodeAppSecretProof(String appSecret, String accessToken) {
try {
byte[] key = appSecret.getBytes(StandardCharsets.UTF_8);
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
byte[] raw = mac.doFinal(accessToken.getBytes());
byte[] hex = encodeHex(raw);
return new String(hex, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IllegalStateException("Creation of appsecret_proof has failed", e);
}
} | java | public static String encodeAppSecretProof(String appSecret, String accessToken) {
try {
byte[] key = appSecret.getBytes(StandardCharsets.UTF_8);
SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(signingKey);
byte[] raw = mac.doFinal(accessToken.getBytes());
byte[] hex = encodeHex(raw);
return new String(hex, StandardCharsets.UTF_8);
} catch (Exception e) {
throw new IllegalStateException("Creation of appsecret_proof has failed", e);
}
} | [
"public",
"static",
"String",
"encodeAppSecretProof",
"(",
"String",
"appSecret",
",",
"String",
"accessToken",
")",
"{",
"try",
"{",
"byte",
"[",
"]",
"key",
"=",
"appSecret",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"UTF_8",
")",
";",
"SecretKeySpec",
... | Generates an appsecret_proof for facebook.
See https://developers.facebook.com/docs/graph-api/securing-requests for more info
@param appSecret
The facebook application secret
@param accessToken
The facebook access token
@return A Hex encoded SHA256 Hash as a String | [
"Generates",
"an",
"appsecret_proof",
"for",
"facebook",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/util/EncodingUtils.java#L112-L124 | train |
restfb/restfb | src/main/java/com/restfb/json/JsonObject.java | JsonObject.remove | public JsonObject remove(String name) {
if (name == null) {
throw new NullPointerException(NAME_IS_NULL);
}
int index = indexOf(name);
if (index != -1) {
table.remove(index);
names.remove(index);
values.remove(index);
}
return this;
} | java | public JsonObject remove(String name) {
if (name == null) {
throw new NullPointerException(NAME_IS_NULL);
}
int index = indexOf(name);
if (index != -1) {
table.remove(index);
names.remove(index);
values.remove(index);
}
return this;
} | [
"public",
"JsonObject",
"remove",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"NAME_IS_NULL",
")",
";",
"}",
"int",
"index",
"=",
"indexOf",
"(",
"name",
")",
";",
"if",
"(",
... | Removes a member with the specified name from this object. If this object contains multiple members with the given
name, only the last one is removed. If this object does not contain a member with the specified name, the object is
not modified.
@param name
the name of the member to remove
@return the object itself, to enable method chaining | [
"Removes",
"a",
"member",
"with",
"the",
"specified",
"name",
"from",
"this",
"object",
".",
"If",
"this",
"object",
"contains",
"multiple",
"members",
"with",
"the",
"given",
"name",
"only",
"the",
"last",
"one",
"is",
"removed",
".",
"If",
"this",
"objec... | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/json/JsonObject.java#L501-L512 | train |
restfb/restfb | src/main/java/com/restfb/json/JsonObject.java | JsonObject.merge | public JsonObject merge(JsonObject object) {
if (object == null) {
throw new NullPointerException(OBJECT_IS_NULL);
}
for (Member member : object) {
this.set(member.name, member.value);
}
return this;
} | java | public JsonObject merge(JsonObject object) {
if (object == null) {
throw new NullPointerException(OBJECT_IS_NULL);
}
for (Member member : object) {
this.set(member.name, member.value);
}
return this;
} | [
"public",
"JsonObject",
"merge",
"(",
"JsonObject",
"object",
")",
"{",
"if",
"(",
"object",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"OBJECT_IS_NULL",
")",
";",
"}",
"for",
"(",
"Member",
"member",
":",
"object",
")",
"{",
"t... | Copies all members of the specified object into this object. When the specified object contains
members with names that also exist in this object, the existing values in this object will be
replaced by the corresponding values in the specified object.
@param object
the object to merge
@return the object itself, to enable method chaining | [
"Copies",
"all",
"members",
"of",
"the",
"specified",
"object",
"into",
"this",
"object",
".",
"When",
"the",
"specified",
"object",
"contains",
"members",
"with",
"names",
"that",
"also",
"exist",
"in",
"this",
"object",
"the",
"existing",
"values",
"in",
"... | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/json/JsonObject.java#L536-L544 | train |
restfb/restfb | src/main/java/com/restfb/DefaultFacebookClient.java | DefaultFacebookClient.urlDecodeSignedRequestToken | protected String urlDecodeSignedRequestToken(String signedRequestToken) {
verifyParameterPresence("signedRequestToken", signedRequestToken);
return signedRequestToken.replace("-", "+").replace("_", "/").trim();
} | java | protected String urlDecodeSignedRequestToken(String signedRequestToken) {
verifyParameterPresence("signedRequestToken", signedRequestToken);
return signedRequestToken.replace("-", "+").replace("_", "/").trim();
} | [
"protected",
"String",
"urlDecodeSignedRequestToken",
"(",
"String",
"signedRequestToken",
")",
"{",
"verifyParameterPresence",
"(",
"\"signedRequestToken\"",
",",
"signedRequestToken",
")",
";",
"return",
"signedRequestToken",
".",
"replace",
"(",
"\"-\"",
",",
"\"+\"",
... | Decodes a component of a signed request received from Facebook using FB's special URL-encoding strategy.
@param signedRequestToken
Token to decode.
@return The decoded token. | [
"Decodes",
"a",
"component",
"of",
"a",
"signed",
"request",
"received",
"from",
"Facebook",
"using",
"FB",
"s",
"special",
"URL",
"-",
"encoding",
"strategy",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultFacebookClient.java#L619-L622 | train |
restfb/restfb | src/main/java/com/restfb/DefaultFacebookClient.java | DefaultFacebookClient.verifySignedRequest | protected boolean verifySignedRequest(String appSecret, String algorithm, String encodedPayload, byte[] signature) {
verifyParameterPresence("appSecret", appSecret);
verifyParameterPresence("algorithm", algorithm);
verifyParameterPresence("encodedPayload", encodedPayload);
verifyParameterPresence("signature", signature);
// Normalize algorithm name...FB calls it differently than Java does
if ("HMAC-SHA256".equalsIgnoreCase(algorithm)) {
algorithm = "HMACSHA256";
}
try {
Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(toBytes(appSecret), algorithm));
byte[] payloadSignature = mac.doFinal(toBytes(encodedPayload));
return Arrays.equals(signature, payloadSignature);
} catch (Exception e) {
throw new FacebookSignedRequestVerificationException("Unable to perform signed request verification", e);
}
} | java | protected boolean verifySignedRequest(String appSecret, String algorithm, String encodedPayload, byte[] signature) {
verifyParameterPresence("appSecret", appSecret);
verifyParameterPresence("algorithm", algorithm);
verifyParameterPresence("encodedPayload", encodedPayload);
verifyParameterPresence("signature", signature);
// Normalize algorithm name...FB calls it differently than Java does
if ("HMAC-SHA256".equalsIgnoreCase(algorithm)) {
algorithm = "HMACSHA256";
}
try {
Mac mac = Mac.getInstance(algorithm);
mac.init(new SecretKeySpec(toBytes(appSecret), algorithm));
byte[] payloadSignature = mac.doFinal(toBytes(encodedPayload));
return Arrays.equals(signature, payloadSignature);
} catch (Exception e) {
throw new FacebookSignedRequestVerificationException("Unable to perform signed request verification", e);
}
} | [
"protected",
"boolean",
"verifySignedRequest",
"(",
"String",
"appSecret",
",",
"String",
"algorithm",
",",
"String",
"encodedPayload",
",",
"byte",
"[",
"]",
"signature",
")",
"{",
"verifyParameterPresence",
"(",
"\"appSecret\"",
",",
"appSecret",
")",
";",
"veri... | Verifies that the signed request is really from Facebook.
@param appSecret
The secret for the app that can verify this signed request.
@param algorithm
Signature algorithm specified by FB in the decoded payload.
@param encodedPayload
The encoded payload used to generate a signature for comparison against the provided {@code signature}.
@param signature
The decoded signature extracted from the signed request. Compared against a signature generated from
{@code encodedPayload}.
@return {@code true} if the signed request is verified, {@code false} if not. | [
"Verifies",
"that",
"the",
"signed",
"request",
"is",
"really",
"from",
"Facebook",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultFacebookClient.java#L657-L676 | train |
restfb/restfb | src/main/java/com/restfb/DefaultFacebookClient.java | DefaultFacebookClient.toParameterString | protected String toParameterString(boolean withJsonParameter, Parameter... parameters) {
if (!isBlank(accessToken)) {
parameters = parametersWithAdditionalParameter(Parameter.with(ACCESS_TOKEN_PARAM_NAME, accessToken), parameters);
}
if (!isBlank(accessToken) && !isBlank(appSecret)) {
parameters = parametersWithAdditionalParameter(
Parameter.with(APP_SECRET_PROOF_PARAM_NAME, obtainAppSecretProof(accessToken, appSecret)), parameters);
}
if (withJsonParameter) {
parameters = parametersWithAdditionalParameter(Parameter.with(FORMAT_PARAM_NAME, "json"), parameters);
}
StringBuilder parameterStringBuilder = new StringBuilder();
boolean first = true;
for (Parameter parameter : parameters) {
if (first) {
first = false;
} else {
parameterStringBuilder.append("&");
}
parameterStringBuilder.append(urlEncode(parameter.name));
parameterStringBuilder.append("=");
parameterStringBuilder.append(urlEncodedValueForParameterName(parameter.name, parameter.value));
}
return parameterStringBuilder.toString();
} | java | protected String toParameterString(boolean withJsonParameter, Parameter... parameters) {
if (!isBlank(accessToken)) {
parameters = parametersWithAdditionalParameter(Parameter.with(ACCESS_TOKEN_PARAM_NAME, accessToken), parameters);
}
if (!isBlank(accessToken) && !isBlank(appSecret)) {
parameters = parametersWithAdditionalParameter(
Parameter.with(APP_SECRET_PROOF_PARAM_NAME, obtainAppSecretProof(accessToken, appSecret)), parameters);
}
if (withJsonParameter) {
parameters = parametersWithAdditionalParameter(Parameter.with(FORMAT_PARAM_NAME, "json"), parameters);
}
StringBuilder parameterStringBuilder = new StringBuilder();
boolean first = true;
for (Parameter parameter : parameters) {
if (first) {
first = false;
} else {
parameterStringBuilder.append("&");
}
parameterStringBuilder.append(urlEncode(parameter.name));
parameterStringBuilder.append("=");
parameterStringBuilder.append(urlEncodedValueForParameterName(parameter.name, parameter.value));
}
return parameterStringBuilder.toString();
} | [
"protected",
"String",
"toParameterString",
"(",
"boolean",
"withJsonParameter",
",",
"Parameter",
"...",
"parameters",
")",
"{",
"if",
"(",
"!",
"isBlank",
"(",
"accessToken",
")",
")",
"{",
"parameters",
"=",
"parametersWithAdditionalParameter",
"(",
"Parameter",
... | Generate the parameter string to be included in the Facebook API request.
@param withJsonParameter
add additional parameter format with type json
@param parameters
Arbitrary number of extra parameters to include in the request.
@return The parameter string to include in the Facebook API request.
@throws FacebookJsonMappingException
If an error occurs when building the parameter string. | [
"Generate",
"the",
"parameter",
"string",
"to",
"be",
"included",
"in",
"the",
"Facebook",
"API",
"request",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultFacebookClient.java#L875-L905 | train |
restfb/restfb | src/main/java/com/restfb/DefaultFacebookClient.java | DefaultFacebookClient.getFacebookGraphEndpointUrl | protected String getFacebookGraphEndpointUrl() {
if (apiVersion.isUrlElementRequired()) {
return getFacebookEndpointUrls().getGraphEndpoint() + '/' + apiVersion.getUrlElement();
} else {
return getFacebookEndpointUrls().getGraphEndpoint();
}
} | java | protected String getFacebookGraphEndpointUrl() {
if (apiVersion.isUrlElementRequired()) {
return getFacebookEndpointUrls().getGraphEndpoint() + '/' + apiVersion.getUrlElement();
} else {
return getFacebookEndpointUrls().getGraphEndpoint();
}
} | [
"protected",
"String",
"getFacebookGraphEndpointUrl",
"(",
")",
"{",
"if",
"(",
"apiVersion",
".",
"isUrlElementRequired",
"(",
")",
")",
"{",
"return",
"getFacebookEndpointUrls",
"(",
")",
".",
"getGraphEndpoint",
"(",
")",
"+",
"'",
"'",
"+",
"apiVersion",
"... | Returns the base endpoint URL for the Graph API.
@return The base endpoint URL for the Graph API. | [
"Returns",
"the",
"base",
"endpoint",
"URL",
"for",
"the",
"Graph",
"API",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultFacebookClient.java#L931-L937 | train |
restfb/restfb | src/main/java/com/restfb/DefaultFacebookClient.java | DefaultFacebookClient.getFacebookGraphVideoEndpointUrl | protected String getFacebookGraphVideoEndpointUrl() {
if (apiVersion.isUrlElementRequired()) {
return getFacebookEndpointUrls().getGraphVideoEndpoint() + '/' + apiVersion.getUrlElement();
} else {
return getFacebookEndpointUrls().getGraphVideoEndpoint();
}
} | java | protected String getFacebookGraphVideoEndpointUrl() {
if (apiVersion.isUrlElementRequired()) {
return getFacebookEndpointUrls().getGraphVideoEndpoint() + '/' + apiVersion.getUrlElement();
} else {
return getFacebookEndpointUrls().getGraphVideoEndpoint();
}
} | [
"protected",
"String",
"getFacebookGraphVideoEndpointUrl",
"(",
")",
"{",
"if",
"(",
"apiVersion",
".",
"isUrlElementRequired",
"(",
")",
")",
"{",
"return",
"getFacebookEndpointUrls",
"(",
")",
".",
"getGraphVideoEndpoint",
"(",
")",
"+",
"'",
"'",
"+",
"apiVer... | Returns the base endpoint URL for the Graph API's video upload functionality.
@return The base endpoint URL for the Graph API's video upload functionality.
@since 1.6.5 | [
"Returns",
"the",
"base",
"endpoint",
"URL",
"for",
"the",
"Graph",
"API",
"s",
"video",
"upload",
"functionality",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultFacebookClient.java#L945-L951 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getDoubleFrom | public Double getDoubleFrom(JsonValue json) {
if (json.isNumber()) {
return json.asDouble();
} else {
return Double.valueOf(json.asString());
}
} | java | public Double getDoubleFrom(JsonValue json) {
if (json.isNumber()) {
return json.asDouble();
} else {
return Double.valueOf(json.asString());
}
} | [
"public",
"Double",
"getDoubleFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isNumber",
"(",
")",
")",
"{",
"return",
"json",
".",
"asDouble",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Double",
".",
"valueOf",
"(",
"json",
".",... | convert jsonvalue to a Double
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"Double"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L78-L84 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getIntegerFrom | public Integer getIntegerFrom(JsonValue json) {
if (json.isNumber()) {
return json.asInt();
} else {
return Integer.valueOf(json.asString());
}
} | java | public Integer getIntegerFrom(JsonValue json) {
if (json.isNumber()) {
return json.asInt();
} else {
return Integer.valueOf(json.asString());
}
} | [
"public",
"Integer",
"getIntegerFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isNumber",
"(",
")",
")",
"{",
"return",
"json",
".",
"asInt",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Integer",
".",
"valueOf",
"(",
"json",
".",... | convert jsonvalue to a Integer
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"Integer"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L92-L98 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getStringFrom | public String getStringFrom(JsonValue json) {
if (json.isString()) {
return json.asString();
} else {
return json.toString();
}
} | java | public String getStringFrom(JsonValue json) {
if (json.isString()) {
return json.asString();
} else {
return json.toString();
}
} | [
"public",
"String",
"getStringFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isString",
"(",
")",
")",
"{",
"return",
"json",
".",
"asString",
"(",
")",
";",
"}",
"else",
"{",
"return",
"json",
".",
"toString",
"(",
")",
";",
"... | convert jsonvalue to a String
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"String"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L106-L112 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getFloatFrom | public Float getFloatFrom(JsonValue json) {
if (json.isNumber()) {
return json.asFloat();
} else {
return new BigDecimal(json.asString()).floatValue();
}
} | java | public Float getFloatFrom(JsonValue json) {
if (json.isNumber()) {
return json.asFloat();
} else {
return new BigDecimal(json.asString()).floatValue();
}
} | [
"public",
"Float",
"getFloatFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isNumber",
"(",
")",
")",
"{",
"return",
"json",
".",
"asFloat",
"(",
")",
";",
"}",
"else",
"{",
"return",
"new",
"BigDecimal",
"(",
"json",
".",
"asStri... | convert jsonvalue to a Float
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"Float"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L120-L126 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getBigIntegerFrom | public BigInteger getBigIntegerFrom(JsonValue json) {
if (json.isString()) {
return new BigInteger(json.asString());
} else {
return new BigInteger(json.toString());
}
} | java | public BigInteger getBigIntegerFrom(JsonValue json) {
if (json.isString()) {
return new BigInteger(json.asString());
} else {
return new BigInteger(json.toString());
}
} | [
"public",
"BigInteger",
"getBigIntegerFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isString",
"(",
")",
")",
"{",
"return",
"new",
"BigInteger",
"(",
"json",
".",
"asString",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",... | convert jsonvalue to a BigInteger
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"BigInteger"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L134-L140 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getLongFrom | public Long getLongFrom(JsonValue json) {
if (json.isNumber()) {
return json.asLong();
} else {
return Long.valueOf(json.asString());
}
} | java | public Long getLongFrom(JsonValue json) {
if (json.isNumber()) {
return json.asLong();
} else {
return Long.valueOf(json.asString());
}
} | [
"public",
"Long",
"getLongFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isNumber",
"(",
")",
")",
"{",
"return",
"json",
".",
"asLong",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Long",
".",
"valueOf",
"(",
"json",
".",
"asSt... | convert jsonvalue to a Long
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"Long"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L148-L154 | train |
restfb/restfb | src/main/java/com/restfb/JsonHelper.java | JsonHelper.getBigDecimalFrom | public BigDecimal getBigDecimalFrom(JsonValue json) {
if (json.isString()) {
return new BigDecimal(json.asString());
} else {
return new BigDecimal(json.toString());
}
} | java | public BigDecimal getBigDecimalFrom(JsonValue json) {
if (json.isString()) {
return new BigDecimal(json.asString());
} else {
return new BigDecimal(json.toString());
}
} | [
"public",
"BigDecimal",
"getBigDecimalFrom",
"(",
"JsonValue",
"json",
")",
"{",
"if",
"(",
"json",
".",
"isString",
"(",
")",
")",
"{",
"return",
"new",
"BigDecimal",
"(",
"json",
".",
"asString",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",... | convert jsonvalue to a BigDecimal
@param json
@return | [
"convert",
"jsonvalue",
"to",
"a",
"BigDecimal"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/JsonHelper.java#L162-L168 | train |
restfb/restfb | src/main/lombok/com/restfb/types/Reactions.java | Reactions.fillTotalCount | private void fillTotalCount(JsonObject summary) {
if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
totalCount = summary.getLong("total_count", totalCount);
}
} | java | private void fillTotalCount(JsonObject summary) {
if (totalCount == 0 && summary != null && summary.get("total_count") != null) {
totalCount = summary.getLong("total_count", totalCount);
}
} | [
"private",
"void",
"fillTotalCount",
"(",
"JsonObject",
"summary",
")",
"{",
"if",
"(",
"totalCount",
"==",
"0",
"&&",
"summary",
"!=",
"null",
"&&",
"summary",
".",
"get",
"(",
"\"total_count\"",
")",
"!=",
"null",
")",
"{",
"totalCount",
"=",
"summary",
... | add change count value, if summary is set and count is empty | [
"add",
"change",
"count",
"value",
"if",
"summary",
"is",
"set",
"and",
"count",
"is",
"empty"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/Reactions.java#L106-L110 | train |
restfb/restfb | src/main/java/com/restfb/DefaultWebRequestor.java | DefaultWebRequestor.createFormFieldName | protected String createFormFieldName(BinaryAttachment binaryAttachment) {
if (binaryAttachment.getFieldName() != null) {
return binaryAttachment.getFieldName();
}
String name = binaryAttachment.getFilename();
int fileExtensionIndex = name.lastIndexOf('.');
return fileExtensionIndex > 0 ? name.substring(0, fileExtensionIndex) : name;
} | java | protected String createFormFieldName(BinaryAttachment binaryAttachment) {
if (binaryAttachment.getFieldName() != null) {
return binaryAttachment.getFieldName();
}
String name = binaryAttachment.getFilename();
int fileExtensionIndex = name.lastIndexOf('.');
return fileExtensionIndex > 0 ? name.substring(0, fileExtensionIndex) : name;
} | [
"protected",
"String",
"createFormFieldName",
"(",
"BinaryAttachment",
"binaryAttachment",
")",
"{",
"if",
"(",
"binaryAttachment",
".",
"getFieldName",
"(",
")",
"!=",
"null",
")",
"{",
"return",
"binaryAttachment",
".",
"getFieldName",
"(",
")",
";",
"}",
"Str... | Creates the form field name for the binary attachment filename by stripping off the file extension - for example,
the filename "test.png" would return "test".
@param binaryAttachment
The binary attachment for which to create the form field name.
@return The form field name for the given binary attachment. | [
"Creates",
"the",
"form",
"field",
"name",
"for",
"the",
"binary",
"attachment",
"filename",
"by",
"stripping",
"off",
"the",
"file",
"extension",
"-",
"for",
"example",
"the",
"filename",
"test",
".",
"png",
"would",
"return",
"test",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultWebRequestor.java#L281-L289 | train |
restfb/restfb | src/main/lombok/com/restfb/types/webhook/messaging/MessagingItem.java | MessagingItem.getItem | public InnerMessagingItem getItem() {
if (optin != null) {
return optin;
}
if (postback != null) {
return postback;
}
if (delivery != null) {
return delivery;
}
if (read != null) {
return read;
}
if (accountLinking != null) {
return accountLinking;
}
if (message != null) {
return message;
}
if (checkoutUpdate != null) {
return checkoutUpdate;
}
if (payment != null) {
return payment;
}
if (referral != null) {
return referral;
}
if (policyEnforcement != null) {
return policyEnforcement;
}
if (passThreadControl != null) {
return passThreadControl;
}
if (takeThreadControl != null) {
return takeThreadControl;
}
if (requestThreadControl != null) {
return requestThreadControl;
}
if (appRoles != null) {
return appRoles;
}
return null;
} | java | public InnerMessagingItem getItem() {
if (optin != null) {
return optin;
}
if (postback != null) {
return postback;
}
if (delivery != null) {
return delivery;
}
if (read != null) {
return read;
}
if (accountLinking != null) {
return accountLinking;
}
if (message != null) {
return message;
}
if (checkoutUpdate != null) {
return checkoutUpdate;
}
if (payment != null) {
return payment;
}
if (referral != null) {
return referral;
}
if (policyEnforcement != null) {
return policyEnforcement;
}
if (passThreadControl != null) {
return passThreadControl;
}
if (takeThreadControl != null) {
return takeThreadControl;
}
if (requestThreadControl != null) {
return requestThreadControl;
}
if (appRoles != null) {
return appRoles;
}
return null;
} | [
"public",
"InnerMessagingItem",
"getItem",
"(",
")",
"{",
"if",
"(",
"optin",
"!=",
"null",
")",
"{",
"return",
"optin",
";",
"}",
"if",
"(",
"postback",
"!=",
"null",
")",
"{",
"return",
"postback",
";",
"}",
"if",
"(",
"delivery",
"!=",
"null",
")"... | generic access to the inner item.
depending on the inner elements the corresponding element is returned. So you can get an {@link OptinItem},
{@link PostbackItem}, {@link DeliveryItem}, {@link AccountLinkingItem} or {@link MessageItem}
@return the inner item. | [
"generic",
"access",
"to",
"the",
"inner",
"item",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/webhook/messaging/MessagingItem.java#L137-L195 | train |
restfb/restfb | src/main/lombok/com/restfb/types/webhook/messaging/AppRoles.java | AppRoles.getRoles | public List<String> getRoles(String appId) {
if (roles.containsKey(appId)) {
return Collections.unmodifiableList(roles.get(appId));
} else {
return null;
}
} | java | public List<String> getRoles(String appId) {
if (roles.containsKey(appId)) {
return Collections.unmodifiableList(roles.get(appId));
} else {
return null;
}
} | [
"public",
"List",
"<",
"String",
">",
"getRoles",
"(",
"String",
"appId",
")",
"{",
"if",
"(",
"roles",
".",
"containsKey",
"(",
"appId",
")",
")",
"{",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"roles",
".",
"get",
"(",
"appId",
")",
")",... | get the roles to the given app id
@param appId
@return List of app roles | [
"get",
"the",
"roles",
"to",
"the",
"given",
"app",
"id"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/types/webhook/messaging/AppRoles.java#L50-L56 | train |
restfb/restfb | src/main/java/com/restfb/exception/generator/DefaultFacebookExceptionGenerator.java | DefaultFacebookExceptionGenerator.skipResponseStatusExceptionParsing | protected void skipResponseStatusExceptionParsing(String json) throws ResponseErrorJsonParsingException {
// If this is not an object, it's not an error response.
if (!json.startsWith("{")) {
throw new ResponseErrorJsonParsingException();
}
int subStrEnd = Math.min(50, json.length());
if (!json.substring(0, subStrEnd).contains("\"error\"")) {
throw new ResponseErrorJsonParsingException();
}
} | java | protected void skipResponseStatusExceptionParsing(String json) throws ResponseErrorJsonParsingException {
// If this is not an object, it's not an error response.
if (!json.startsWith("{")) {
throw new ResponseErrorJsonParsingException();
}
int subStrEnd = Math.min(50, json.length());
if (!json.substring(0, subStrEnd).contains("\"error\"")) {
throw new ResponseErrorJsonParsingException();
}
} | [
"protected",
"void",
"skipResponseStatusExceptionParsing",
"(",
"String",
"json",
")",
"throws",
"ResponseErrorJsonParsingException",
"{",
"// If this is not an object, it's not an error response.",
"if",
"(",
"!",
"json",
".",
"startsWith",
"(",
"\"{\"",
")",
")",
"{",
"... | checks if a string may be a json and contains a error string somewhere, this is used for speedup the error parsing
@param json | [
"checks",
"if",
"a",
"string",
"may",
"be",
"a",
"json",
"and",
"contains",
"a",
"error",
"string",
"somewhere",
"this",
"is",
"used",
"for",
"speedup",
"the",
"error",
"parsing"
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/exception/generator/DefaultFacebookExceptionGenerator.java#L124-L134 | train |
restfb/restfb | src/main/lombok/com/restfb/BinaryAttachment.java | BinaryAttachment.getData | public InputStream getData() {
if (data != null) {
return new ByteArrayInputStream(data);
} else if (dataStream != null) {
return dataStream;
} else {
throw new IllegalStateException("Either the byte[] or the stream mustn't be null at this point.");
}
} | java | public InputStream getData() {
if (data != null) {
return new ByteArrayInputStream(data);
} else if (dataStream != null) {
return dataStream;
} else {
throw new IllegalStateException("Either the byte[] or the stream mustn't be null at this point.");
}
} | [
"public",
"InputStream",
"getData",
"(",
")",
"{",
"if",
"(",
"data",
"!=",
"null",
")",
"{",
"return",
"new",
"ByteArrayInputStream",
"(",
"data",
")",
";",
"}",
"else",
"if",
"(",
"dataStream",
"!=",
"null",
")",
"{",
"return",
"dataStream",
";",
"}"... | The attachment's data.
@return The attachment's data. | [
"The",
"attachment",
"s",
"data",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/BinaryAttachment.java#L398-L406 | train |
restfb/restfb | src/main/lombok/com/restfb/BinaryAttachment.java | BinaryAttachment.getContentType | public String getContentType() {
if (contentType != null) {
return contentType;
}
if (dataStream != null) {
try {
contentType = URLConnection.guessContentTypeFromStream(dataStream);
} catch (IOException ioe) {
// ignore exception
}
}
if (data != null) {
contentType = URLConnection.guessContentTypeFromName(filename);
}
// fallback - if we have no contenttype and cannot detect one, use 'application/octet-stream'
if (contentType == null) {
contentType = "application/octet-stream";
}
return contentType;
} | java | public String getContentType() {
if (contentType != null) {
return contentType;
}
if (dataStream != null) {
try {
contentType = URLConnection.guessContentTypeFromStream(dataStream);
} catch (IOException ioe) {
// ignore exception
}
}
if (data != null) {
contentType = URLConnection.guessContentTypeFromName(filename);
}
// fallback - if we have no contenttype and cannot detect one, use 'application/octet-stream'
if (contentType == null) {
contentType = "application/octet-stream";
}
return contentType;
} | [
"public",
"String",
"getContentType",
"(",
")",
"{",
"if",
"(",
"contentType",
"!=",
"null",
")",
"{",
"return",
"contentType",
";",
"}",
"if",
"(",
"dataStream",
"!=",
"null",
")",
"{",
"try",
"{",
"contentType",
"=",
"URLConnection",
".",
"guessContentTy... | return the given content type or try to guess from stream or file name. Depending of the available data.
@return the content type | [
"return",
"the",
"given",
"content",
"type",
"or",
"try",
"to",
"guess",
"from",
"stream",
"or",
"file",
"name",
".",
"Depending",
"of",
"the",
"available",
"data",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/lombok/com/restfb/BinaryAttachment.java#L413-L436 | train |
restfb/restfb | src/main/java/com/restfb/DefaultJsonMapper.java | DefaultJsonMapper.logMultipleMappingFailedForField | protected void logMultipleMappingFailedForField(String facebookFieldName,
FieldWithAnnotation<Facebook> fieldWithAnnotation, String json) {
if (!MAPPER_LOGGER.isTraceEnabled()) {
return;
}
Field field = fieldWithAnnotation.getField();
MAPPER_LOGGER.trace(
"Could not map '{}' to {}. {}, but continuing on because '{}"
+ "' is mapped to multiple fields in {}. JSON is {}",
facebookFieldName, field.getDeclaringClass().getSimpleName(), field.getName(), facebookFieldName,
field.getDeclaringClass().getSimpleName(), json);
} | java | protected void logMultipleMappingFailedForField(String facebookFieldName,
FieldWithAnnotation<Facebook> fieldWithAnnotation, String json) {
if (!MAPPER_LOGGER.isTraceEnabled()) {
return;
}
Field field = fieldWithAnnotation.getField();
MAPPER_LOGGER.trace(
"Could not map '{}' to {}. {}, but continuing on because '{}"
+ "' is mapped to multiple fields in {}. JSON is {}",
facebookFieldName, field.getDeclaringClass().getSimpleName(), field.getName(), facebookFieldName,
field.getDeclaringClass().getSimpleName(), json);
} | [
"protected",
"void",
"logMultipleMappingFailedForField",
"(",
"String",
"facebookFieldName",
",",
"FieldWithAnnotation",
"<",
"Facebook",
">",
"fieldWithAnnotation",
",",
"String",
"json",
")",
"{",
"if",
"(",
"!",
"MAPPER_LOGGER",
".",
"isTraceEnabled",
"(",
")",
"... | Dumps out a log message when one of a multiple-mapped Facebook field name JSON-to-Java mapping operation fails.
@param facebookFieldName
The Facebook field name.
@param fieldWithAnnotation
The Java field to map to and its annotation.
@param json
The JSON that failed to map to the Java field. | [
"Dumps",
"out",
"a",
"log",
"message",
"when",
"one",
"of",
"a",
"multiple",
"-",
"mapped",
"Facebook",
"field",
"name",
"JSON",
"-",
"to",
"-",
"Java",
"mapping",
"operation",
"fails",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultJsonMapper.java#L297-L310 | train |
restfb/restfb | src/main/java/com/restfb/DefaultJsonMapper.java | DefaultJsonMapper.facebookFieldNamesWithMultipleMappings | protected Set<String> facebookFieldNamesWithMultipleMappings(
List<FieldWithAnnotation<Facebook>> fieldsWithAnnotation) {
Map<String, Integer> facebookFieldsNamesWithOccurrenceCount = new HashMap<>();
Set<String> facebookFieldNamesWithMultipleMappings = new HashSet<>();
// Get a count of Facebook field name occurrences for each
// @Facebook-annotated field
for (FieldWithAnnotation<Facebook> fieldWithAnnotation : fieldsWithAnnotation) {
String fieldName = getFacebookFieldName(fieldWithAnnotation);
int occurrenceCount = facebookFieldsNamesWithOccurrenceCount.containsKey(fieldName)
? facebookFieldsNamesWithOccurrenceCount.get(fieldName)
: 0;
facebookFieldsNamesWithOccurrenceCount.put(fieldName, occurrenceCount + 1);
}
// Pull out only those field names with multiple mappings
for (Entry<String, Integer> entry : facebookFieldsNamesWithOccurrenceCount.entrySet()) {
if (entry.getValue() > 1) {
facebookFieldNamesWithMultipleMappings.add(entry.getKey());
}
}
return unmodifiableSet(facebookFieldNamesWithMultipleMappings);
} | java | protected Set<String> facebookFieldNamesWithMultipleMappings(
List<FieldWithAnnotation<Facebook>> fieldsWithAnnotation) {
Map<String, Integer> facebookFieldsNamesWithOccurrenceCount = new HashMap<>();
Set<String> facebookFieldNamesWithMultipleMappings = new HashSet<>();
// Get a count of Facebook field name occurrences for each
// @Facebook-annotated field
for (FieldWithAnnotation<Facebook> fieldWithAnnotation : fieldsWithAnnotation) {
String fieldName = getFacebookFieldName(fieldWithAnnotation);
int occurrenceCount = facebookFieldsNamesWithOccurrenceCount.containsKey(fieldName)
? facebookFieldsNamesWithOccurrenceCount.get(fieldName)
: 0;
facebookFieldsNamesWithOccurrenceCount.put(fieldName, occurrenceCount + 1);
}
// Pull out only those field names with multiple mappings
for (Entry<String, Integer> entry : facebookFieldsNamesWithOccurrenceCount.entrySet()) {
if (entry.getValue() > 1) {
facebookFieldNamesWithMultipleMappings.add(entry.getKey());
}
}
return unmodifiableSet(facebookFieldNamesWithMultipleMappings);
} | [
"protected",
"Set",
"<",
"String",
">",
"facebookFieldNamesWithMultipleMappings",
"(",
"List",
"<",
"FieldWithAnnotation",
"<",
"Facebook",
">",
">",
"fieldsWithAnnotation",
")",
"{",
"Map",
"<",
"String",
",",
"Integer",
">",
"facebookFieldsNamesWithOccurrenceCount",
... | Finds any Facebook JSON fields that are mapped to more than 1 Java field.
@param fieldsWithAnnotation
Java fields annotated with the {@code Facebook} annotation.
@return Any Facebook JSON fields that are mapped to more than 1 Java field. | [
"Finds",
"any",
"Facebook",
"JSON",
"fields",
"that",
"are",
"mapped",
"to",
"more",
"than",
"1",
"Java",
"field",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/DefaultJsonMapper.java#L343-L366 | train |
restfb/restfb | src/main/java/com/restfb/util/ObjectUtil.java | ObjectUtil.isEmptyCollectionOrMap | public static boolean isEmptyCollectionOrMap(Object obj) {
if (obj instanceof Collection) {
return ((Collection) obj).isEmpty();
}
return (obj instanceof Map && ((Map) obj).isEmpty());
} | java | public static boolean isEmptyCollectionOrMap(Object obj) {
if (obj instanceof Collection) {
return ((Collection) obj).isEmpty();
}
return (obj instanceof Map && ((Map) obj).isEmpty());
} | [
"public",
"static",
"boolean",
"isEmptyCollectionOrMap",
"(",
"Object",
"obj",
")",
"{",
"if",
"(",
"obj",
"instanceof",
"Collection",
")",
"{",
"return",
"(",
"(",
"Collection",
")",
"obj",
")",
".",
"isEmpty",
"(",
")",
";",
"}",
"return",
"(",
"obj",
... | Checks is the object is a empty 'collection' or 'map'.
@param obj
the object that is checked
@return {@code true} if the given object is a empty collection or an empty map, {@code false} otherwise | [
"Checks",
"is",
"the",
"object",
"is",
"a",
"empty",
"collection",
"or",
"map",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/util/ObjectUtil.java#L59-L65 | train |
restfb/restfb | src/main/java/com/restfb/logging/RestFBLogger.java | RestFBLogger.getLoggerInstance | public static RestFBLogger getLoggerInstance(String logCategory) {
Object obj;
Class[] ctrTypes = new Class[] { String.class };
Object[] ctrArgs = new Object[] { logCategory };
try {
Constructor loggerClassConstructor = usedLoggerClass.getConstructor(ctrTypes);
obj = loggerClassConstructor.newInstance(ctrArgs);
} catch (Exception e) {
throw new FacebookLoggerException("cannot create logger: " + logCategory);
}
return (RestFBLogger) obj;
} | java | public static RestFBLogger getLoggerInstance(String logCategory) {
Object obj;
Class[] ctrTypes = new Class[] { String.class };
Object[] ctrArgs = new Object[] { logCategory };
try {
Constructor loggerClassConstructor = usedLoggerClass.getConstructor(ctrTypes);
obj = loggerClassConstructor.newInstance(ctrArgs);
} catch (Exception e) {
throw new FacebookLoggerException("cannot create logger: " + logCategory);
}
return (RestFBLogger) obj;
} | [
"public",
"static",
"RestFBLogger",
"getLoggerInstance",
"(",
"String",
"logCategory",
")",
"{",
"Object",
"obj",
";",
"Class",
"[",
"]",
"ctrTypes",
"=",
"new",
"Class",
"[",
"]",
"{",
"String",
".",
"class",
"}",
";",
"Object",
"[",
"]",
"ctrArgs",
"="... | returns the instance of the logger that belongs to the category.
@param logCategory
the category of the logger
@return a instance of the logger | [
"returns",
"the",
"instance",
"of",
"the",
"logger",
"that",
"belongs",
"to",
"the",
"category",
"."
] | fb77ba5486d1339e7deb81b9830670fa209b1047 | https://github.com/restfb/restfb/blob/fb77ba5486d1339e7deb81b9830670fa209b1047/src/main/java/com/restfb/logging/RestFBLogger.java#L88-L100 | train |
jpmml/jpmml-evaluator | pmml-evaluator/src/main/java/org/jpmml/evaluator/LevenshteinDistanceUtil.java | LevenshteinDistanceUtil.limitedCompare | static int limitedCompare(CharSequence left, CharSequence right, final boolean caseSensitive, final int threshold) { // NOPMD
if (left == null || right == null) {
throw new IllegalArgumentException("Strings must not be null");
}
if (threshold < 0) {
throw new IllegalArgumentException("Threshold must not be negative");
}
/*
* This implementation only computes the distance if it's less than or
* equal to the threshold value, returning -1 if it's greater. The
* advantage is performance: unbounded distance is O(nm), but a bound of
* k allows us to reduce it to O(km) time by only computing a diagonal
* stripe of width 2k + 1 of the cost table. It is also possible to use
* this to compute the unbounded Levenshtein distance by starting the
* threshold at 1 and doubling each time until the distance is found;
* this is O(dm), where d is the distance.
*
* One subtlety comes from needing to ignore entries on the border of
* our stripe eg. p[] = |#|#|#|* d[] = *|#|#|#| We must ignore the entry
* to the left of the leftmost member We must ignore the entry above the
* rightmost member
*
* Another subtlety comes from our stripe running off the matrix if the
* strings aren't of the same size. Since string s is always swapped to
* be the shorter of the two, the stripe will always run off to the
* upper right instead of the lower left of the matrix.
*
* As a concrete example, suppose s is of length 5, t is of length 7,
* and our threshold is 1. In this case we're going to walk a stripe of
* length 3. The matrix would look like so:
*
* <pre>
* 1 2 3 4 5
* 1 |#|#| | | |
* 2 |#|#|#| | |
* 3 | |#|#|#| |
* 4 | | |#|#|#|
* 5 | | | |#|#|
* 6 | | | | |#|
* 7 | | | | | |
* </pre>
*
* Note how the stripe leads off the table as there is no possible way
* to turn a string of length 5 into one of length 7 in edit distance of
* 1.
*
* Additionally, this implementation decreases memory usage by using two
* single-dimensional arrays and swapping them back and forth instead of
* allocating an entire n by m matrix. This requires a few minor
* changes, such as immediately returning when it's detected that the
* stripe has run off the matrix and initially filling the arrays with
* large values so that entries we don't compute are ignored.
*
* See Algorithms on Strings, Trees and Sequences by Dan Gusfield for
* some discussion.
*/
int n = left.length(); // length of left
int m = right.length(); // length of right
// if one string is empty, the edit distance is necessarily the length
// of the other
if (n == 0) {
return m <= threshold ? m : -1;
} else if (m == 0) {
return n <= threshold ? n : -1;
}
if (n > m) {
// swap the two strings to consume less memory
final CharSequence tmp = left;
left = right;
right = tmp;
n = m;
m = right.length();
}
int[] p = new int[n + 1]; // 'previous' cost array, horizontally
int[] d = new int[n + 1]; // cost array, horizontally
int[] tempD; // placeholder to assist in swapping p and d
// fill in starting table values
final int boundary = Math.min(n, threshold) + 1;
for (int i = 0; i < boundary; i++) {
p[i] = i;
}
// these fills ensure that the value above the rightmost entry of our
// stripe will be ignored in following loop iterations
Arrays.fill(p, boundary, p.length, Integer.MAX_VALUE);
Arrays.fill(d, Integer.MAX_VALUE);
// iterates through t
for (int j = 1; j <= m; j++) {
final char rightJ = right.charAt(j - 1); // jth character of right
d[0] = j;
// compute stripe indices, constrain to array size
final int min = Math.max(1, j - threshold);
final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min(
n, j + threshold);
// the stripe may lead off of the table if s and t are of different
// sizes
if (min > max) {
return -1;
}
// ignore entry left of leftmost
if (min > 1) {
d[min - 1] = Integer.MAX_VALUE;
}
// iterates through [min, max] in s
for (int i = min; i <= max; i++) {
final char leftI = left.charAt(i - 1);
if (equals(leftI, rightJ, caseSensitive)) {
// diagonally left and up
d[i] = p[i - 1];
} else {
// 1 + minimum of cell to the left, to the top, diagonally
// left and up
d[i] = 1 + Math.min(Math.min(d[i - 1], p[i]), p[i - 1]);
}
}
// copy current distance counts to 'previous row' distance counts
tempD = p;
p = d;
d = tempD;
}
// if p[n] is greater than the threshold, there's no guarantee on it
// being the correct
// distance
if (p[n] <= threshold) {
return p[n];
}
return -1;
} | java | static int limitedCompare(CharSequence left, CharSequence right, final boolean caseSensitive, final int threshold) { // NOPMD
if (left == null || right == null) {
throw new IllegalArgumentException("Strings must not be null");
}
if (threshold < 0) {
throw new IllegalArgumentException("Threshold must not be negative");
}
/*
* This implementation only computes the distance if it's less than or
* equal to the threshold value, returning -1 if it's greater. The
* advantage is performance: unbounded distance is O(nm), but a bound of
* k allows us to reduce it to O(km) time by only computing a diagonal
* stripe of width 2k + 1 of the cost table. It is also possible to use
* this to compute the unbounded Levenshtein distance by starting the
* threshold at 1 and doubling each time until the distance is found;
* this is O(dm), where d is the distance.
*
* One subtlety comes from needing to ignore entries on the border of
* our stripe eg. p[] = |#|#|#|* d[] = *|#|#|#| We must ignore the entry
* to the left of the leftmost member We must ignore the entry above the
* rightmost member
*
* Another subtlety comes from our stripe running off the matrix if the
* strings aren't of the same size. Since string s is always swapped to
* be the shorter of the two, the stripe will always run off to the
* upper right instead of the lower left of the matrix.
*
* As a concrete example, suppose s is of length 5, t is of length 7,
* and our threshold is 1. In this case we're going to walk a stripe of
* length 3. The matrix would look like so:
*
* <pre>
* 1 2 3 4 5
* 1 |#|#| | | |
* 2 |#|#|#| | |
* 3 | |#|#|#| |
* 4 | | |#|#|#|
* 5 | | | |#|#|
* 6 | | | | |#|
* 7 | | | | | |
* </pre>
*
* Note how the stripe leads off the table as there is no possible way
* to turn a string of length 5 into one of length 7 in edit distance of
* 1.
*
* Additionally, this implementation decreases memory usage by using two
* single-dimensional arrays and swapping them back and forth instead of
* allocating an entire n by m matrix. This requires a few minor
* changes, such as immediately returning when it's detected that the
* stripe has run off the matrix and initially filling the arrays with
* large values so that entries we don't compute are ignored.
*
* See Algorithms on Strings, Trees and Sequences by Dan Gusfield for
* some discussion.
*/
int n = left.length(); // length of left
int m = right.length(); // length of right
// if one string is empty, the edit distance is necessarily the length
// of the other
if (n == 0) {
return m <= threshold ? m : -1;
} else if (m == 0) {
return n <= threshold ? n : -1;
}
if (n > m) {
// swap the two strings to consume less memory
final CharSequence tmp = left;
left = right;
right = tmp;
n = m;
m = right.length();
}
int[] p = new int[n + 1]; // 'previous' cost array, horizontally
int[] d = new int[n + 1]; // cost array, horizontally
int[] tempD; // placeholder to assist in swapping p and d
// fill in starting table values
final int boundary = Math.min(n, threshold) + 1;
for (int i = 0; i < boundary; i++) {
p[i] = i;
}
// these fills ensure that the value above the rightmost entry of our
// stripe will be ignored in following loop iterations
Arrays.fill(p, boundary, p.length, Integer.MAX_VALUE);
Arrays.fill(d, Integer.MAX_VALUE);
// iterates through t
for (int j = 1; j <= m; j++) {
final char rightJ = right.charAt(j - 1); // jth character of right
d[0] = j;
// compute stripe indices, constrain to array size
final int min = Math.max(1, j - threshold);
final int max = j > Integer.MAX_VALUE - threshold ? n : Math.min(
n, j + threshold);
// the stripe may lead off of the table if s and t are of different
// sizes
if (min > max) {
return -1;
}
// ignore entry left of leftmost
if (min > 1) {
d[min - 1] = Integer.MAX_VALUE;
}
// iterates through [min, max] in s
for (int i = min; i <= max; i++) {
final char leftI = left.charAt(i - 1);
if (equals(leftI, rightJ, caseSensitive)) {
// diagonally left and up
d[i] = p[i - 1];
} else {
// 1 + minimum of cell to the left, to the top, diagonally
// left and up
d[i] = 1 + Math.min(Math.min(d[i - 1], p[i]), p[i - 1]);
}
}
// copy current distance counts to 'previous row' distance counts
tempD = p;
p = d;
d = tempD;
}
// if p[n] is greater than the threshold, there's no guarantee on it
// being the correct
// distance
if (p[n] <= threshold) {
return p[n];
}
return -1;
} | [
"static",
"int",
"limitedCompare",
"(",
"CharSequence",
"left",
",",
"CharSequence",
"right",
",",
"final",
"boolean",
"caseSensitive",
",",
"final",
"int",
"threshold",
")",
"{",
"// NOPMD",
"if",
"(",
"left",
"==",
"null",
"||",
"right",
"==",
"null",
")",... | Find the Levenshtein distance between two CharSequences if it's less than or
equal to a given threshold.
<p>
This implementation follows from Algorithms on Strings, Trees and
Sequences by Dan Gusfield and Chas Emerick's implementation of the
Levenshtein distance algorithm from <a
href="http://www.merriampark.com/ld.htm"
>http://www.merriampark.com/ld.htm</a>
</p>
<pre>
limitedCompare(null, *, *) = IllegalArgumentException
limitedCompare(*, null, *) = IllegalArgumentException
limitedCompare(*, *, -1) = IllegalArgumentException
limitedCompare("","", 0) = 0
limitedCompare("aaapppp", "", 8) = 7
limitedCompare("aaapppp", "", 7) = 7
limitedCompare("aaapppp", "", 6)) = -1
limitedCompare("elephant", "hippo", 7) = 7
limitedCompare("elephant", "hippo", 6) = -1
limitedCompare("hippo", "elephant", 7) = 7
limitedCompare("hippo", "elephant", 6) = -1
</pre>
@param left the first string, must not be null
@param right the second string, must not be null
@param threshold the target threshold, must not be negative
@return result distance, or -1 | [
"Find",
"the",
"Levenshtein",
"distance",
"between",
"two",
"CharSequences",
"if",
"it",
"s",
"less",
"than",
"or",
"equal",
"to",
"a",
"given",
"threshold",
"."
] | ac8a48775877b6fa9dbc5f259871f3278489cc61 | https://github.com/jpmml/jpmml-evaluator/blob/ac8a48775877b6fa9dbc5f259871f3278489cc61/pmml-evaluator/src/main/java/org/jpmml/evaluator/LevenshteinDistanceUtil.java#L57-L197 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/writer/ConrefPushParser.java | ConrefPushParser.updateList | private void updateList(final File filename) {
try {
final URI reletivePath = toURI(filename.getAbsolutePath().substring(new File(normalize(tempDir.toString())).getPath().length() + 1));
final FileInfo f = job.getOrCreateFileInfo(reletivePath);
if (hasConref) {
f.hasConref = true;
}
if (hasKeyref) {
f.hasKeyref = true;
}
job.write();
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
}
} | java | private void updateList(final File filename) {
try {
final URI reletivePath = toURI(filename.getAbsolutePath().substring(new File(normalize(tempDir.toString())).getPath().length() + 1));
final FileInfo f = job.getOrCreateFileInfo(reletivePath);
if (hasConref) {
f.hasConref = true;
}
if (hasKeyref) {
f.hasKeyref = true;
}
job.write();
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
}
} | [
"private",
"void",
"updateList",
"(",
"final",
"File",
"filename",
")",
"{",
"try",
"{",
"final",
"URI",
"reletivePath",
"=",
"toURI",
"(",
"filename",
".",
"getAbsolutePath",
"(",
")",
".",
"substring",
"(",
"new",
"File",
"(",
"normalize",
"(",
"tempDir"... | Update conref list in job configuration and in conref list file.
@param filename filename | [
"Update",
"conref",
"list",
"in",
"job",
"configuration",
"and",
"in",
"conref",
"list",
"file",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/writer/ConrefPushParser.java#L171-L187 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/platform/PluginRequirement.java | PluginRequirement.addPlugins | public void addPlugins(final String s) {
final StringTokenizer t = new StringTokenizer(s, REQUIREMENT_SEPARATOR);
while (t.hasMoreTokens()) {
plugins.add(t.nextToken());
}
} | java | public void addPlugins(final String s) {
final StringTokenizer t = new StringTokenizer(s, REQUIREMENT_SEPARATOR);
while (t.hasMoreTokens()) {
plugins.add(t.nextToken());
}
} | [
"public",
"void",
"addPlugins",
"(",
"final",
"String",
"s",
")",
"{",
"final",
"StringTokenizer",
"t",
"=",
"new",
"StringTokenizer",
"(",
"s",
",",
"REQUIREMENT_SEPARATOR",
")",
";",
"while",
"(",
"t",
".",
"hasMoreTokens",
"(",
")",
")",
"{",
"plugins",... | Add plugins.
@param s plugins name | [
"Add",
"plugins",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/platform/PluginRequirement.java#L34-L39 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/DitaValReader.java | DitaValReader.refineAction | private void refineAction(final Action action, final FilterKey key) {
if (key.value != null && bindingMap != null && !bindingMap.isEmpty()) {
final Map<String, Set<Element>> schemeMap = bindingMap.get(key.attribute);
if (schemeMap != null && !schemeMap.isEmpty()) {
for (final Set<Element> submap: schemeMap.values()) {
for (final Element e: submap) {
final Element subRoot = searchForKey(e, key.value);
if (subRoot != null) {
insertAction(subRoot, key.attribute, action);
}
}
}
}
}
} | java | private void refineAction(final Action action, final FilterKey key) {
if (key.value != null && bindingMap != null && !bindingMap.isEmpty()) {
final Map<String, Set<Element>> schemeMap = bindingMap.get(key.attribute);
if (schemeMap != null && !schemeMap.isEmpty()) {
for (final Set<Element> submap: schemeMap.values()) {
for (final Element e: submap) {
final Element subRoot = searchForKey(e, key.value);
if (subRoot != null) {
insertAction(subRoot, key.attribute, action);
}
}
}
}
}
} | [
"private",
"void",
"refineAction",
"(",
"final",
"Action",
"action",
",",
"final",
"FilterKey",
"key",
")",
"{",
"if",
"(",
"key",
".",
"value",
"!=",
"null",
"&&",
"bindingMap",
"!=",
"null",
"&&",
"!",
"bindingMap",
".",
"isEmpty",
"(",
")",
")",
"{"... | Refine action key with information from subject schemes. | [
"Refine",
"action",
"key",
"with",
"information",
"from",
"subject",
"schemes",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/DitaValReader.java#L295-L309 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/DitaValReader.java | DitaValReader.insertAction | private void insertAction(final Element subTree, final QName attName, final Action action) {
if (subTree == null || action == null) {
return;
}
final LinkedList<Element> queue = new LinkedList<>();
// Skip the sub-tree root because it has been added already.
NodeList children = subTree.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.offer((Element)children.item(i));
}
}
while (!queue.isEmpty()) {
final Element node = queue.poll();
children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.offer((Element)children.item(i));
}
}
if (SUBJECTSCHEME_SUBJECTDEF.matches(node)) {
final String key = node.getAttribute(ATTRIBUTE_NAME_KEYS);
if (key != null && !key.trim().isEmpty()) {
final FilterKey k = new FilterKey(attName, key);
if (!filterMap.containsKey(k)) {
filterMap.put(k, action);
}
}
}
}
} | java | private void insertAction(final Element subTree, final QName attName, final Action action) {
if (subTree == null || action == null) {
return;
}
final LinkedList<Element> queue = new LinkedList<>();
// Skip the sub-tree root because it has been added already.
NodeList children = subTree.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.offer((Element)children.item(i));
}
}
while (!queue.isEmpty()) {
final Element node = queue.poll();
children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.offer((Element)children.item(i));
}
}
if (SUBJECTSCHEME_SUBJECTDEF.matches(node)) {
final String key = node.getAttribute(ATTRIBUTE_NAME_KEYS);
if (key != null && !key.trim().isEmpty()) {
final FilterKey k = new FilterKey(attName, key);
if (!filterMap.containsKey(k)) {
filterMap.put(k, action);
}
}
}
}
} | [
"private",
"void",
"insertAction",
"(",
"final",
"Element",
"subTree",
",",
"final",
"QName",
"attName",
",",
"final",
"Action",
"action",
")",
"{",
"if",
"(",
"subTree",
"==",
"null",
"||",
"action",
"==",
"null",
")",
"{",
"return",
";",
"}",
"final",
... | Insert subject scheme based action into filetermap if key not present in the map
@param subTree subject scheme definition element
@param attName attribute name
@param action action to insert | [
"Insert",
"subject",
"scheme",
"based",
"action",
"into",
"filetermap",
"if",
"key",
"not",
"present",
"in",
"the",
"map"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/DitaValReader.java#L318-L351 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/DitaValReader.java | DitaValReader.searchForKey | private Element searchForKey(final Element root, final String keyValue) {
if (root == null || keyValue == null) {
return null;
}
final LinkedList<Element> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
final Element node = queue.removeFirst();
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.add((Element)children.item(i));
}
}
if (SUBJECTSCHEME_SUBJECTDEF.matches(node)) {
final String key = node.getAttribute(ATTRIBUTE_NAME_KEYS);
if (keyValue.equals(key)) {
return node;
}
}
}
return null;
} | java | private Element searchForKey(final Element root, final String keyValue) {
if (root == null || keyValue == null) {
return null;
}
final LinkedList<Element> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
final Element node = queue.removeFirst();
final NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
queue.add((Element)children.item(i));
}
}
if (SUBJECTSCHEME_SUBJECTDEF.matches(node)) {
final String key = node.getAttribute(ATTRIBUTE_NAME_KEYS);
if (keyValue.equals(key)) {
return node;
}
}
}
return null;
} | [
"private",
"Element",
"searchForKey",
"(",
"final",
"Element",
"root",
",",
"final",
"String",
"keyValue",
")",
"{",
"if",
"(",
"root",
"==",
"null",
"||",
"keyValue",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"final",
"LinkedList",
"<",
"Eleme... | Search subject scheme elements for a given key
@param root subject scheme element tree to search through
@param keyValue key to locate
@return element that matches the key, otherwise {@code null} | [
"Search",
"subject",
"scheme",
"elements",
"for",
"a",
"given",
"key"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/DitaValReader.java#L359-L381 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/DitaValReader.java | DitaValReader.insertAction | private void insertAction(final Action action, final FilterKey key) {
if (filterMap.get(key) == null) {
filterMap.put(key, action);
} else {
logger.info(MessageUtils.getMessage("DOTJ007I", key.toString()).toString());
}
} | java | private void insertAction(final Action action, final FilterKey key) {
if (filterMap.get(key) == null) {
filterMap.put(key, action);
} else {
logger.info(MessageUtils.getMessage("DOTJ007I", key.toString()).toString());
}
} | [
"private",
"void",
"insertAction",
"(",
"final",
"Action",
"action",
",",
"final",
"FilterKey",
"key",
")",
"{",
"if",
"(",
"filterMap",
".",
"get",
"(",
"key",
")",
"==",
"null",
")",
"{",
"filterMap",
".",
"put",
"(",
"key",
",",
"action",
")",
";"... | Insert action into filetermap if key not present in the map | [
"Insert",
"action",
"into",
"filetermap",
"if",
"key",
"not",
"present",
"in",
"the",
"map"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/DitaValReader.java#L387-L393 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/DebugAndFilterModule.java | DebugAndFilterModule.outputSubjectScheme | private void outputSubjectScheme() throws DITAOTException {
try {
final Map<URI, Set<URI>> graph = SubjectSchemeReader.readMapFromXML(new File(job.tempDir, FILE_NAME_SUBJECT_RELATION));
final Queue<URI> queue = new LinkedList<>(graph.keySet());
final Set<URI> visitedSet = new HashSet<>();
final DocumentBuilder builder = XMLUtils.getDocumentBuilder();
builder.setEntityResolver(CatalogUtils.getCatalogResolver());
while (!queue.isEmpty()) {
final URI parent = queue.poll();
final Set<URI> children = graph.get(parent);
if (children != null) {
queue.addAll(children);
}
if (ROOT_URI.equals(parent) || visitedSet.contains(parent)) {
continue;
}
visitedSet.add(parent);
final File tmprel = new File(FileUtils.resolve(job.tempDir, parent) + SUBJECT_SCHEME_EXTENSION);
final Document parentRoot;
if (!tmprel.exists()) {
final URI src = job.getFileInfo(parent).src;
parentRoot = builder.parse(src.toString());
} else {
parentRoot = builder.parse(tmprel);
}
if (children != null) {
for (final URI childpath: children) {
final Document childRoot = builder.parse(job.getInputFile().resolve(childpath.getPath()).toString());
mergeScheme(parentRoot, childRoot);
generateScheme(new File(job.tempDir, childpath.getPath() + SUBJECT_SCHEME_EXTENSION), childRoot);
}
}
//Output parent scheme
generateScheme(new File(job.tempDir, parent.getPath() + SUBJECT_SCHEME_EXTENSION), parentRoot);
}
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
throw new DITAOTException(e);
}
} | java | private void outputSubjectScheme() throws DITAOTException {
try {
final Map<URI, Set<URI>> graph = SubjectSchemeReader.readMapFromXML(new File(job.tempDir, FILE_NAME_SUBJECT_RELATION));
final Queue<URI> queue = new LinkedList<>(graph.keySet());
final Set<URI> visitedSet = new HashSet<>();
final DocumentBuilder builder = XMLUtils.getDocumentBuilder();
builder.setEntityResolver(CatalogUtils.getCatalogResolver());
while (!queue.isEmpty()) {
final URI parent = queue.poll();
final Set<URI> children = graph.get(parent);
if (children != null) {
queue.addAll(children);
}
if (ROOT_URI.equals(parent) || visitedSet.contains(parent)) {
continue;
}
visitedSet.add(parent);
final File tmprel = new File(FileUtils.resolve(job.tempDir, parent) + SUBJECT_SCHEME_EXTENSION);
final Document parentRoot;
if (!tmprel.exists()) {
final URI src = job.getFileInfo(parent).src;
parentRoot = builder.parse(src.toString());
} else {
parentRoot = builder.parse(tmprel);
}
if (children != null) {
for (final URI childpath: children) {
final Document childRoot = builder.parse(job.getInputFile().resolve(childpath.getPath()).toString());
mergeScheme(parentRoot, childRoot);
generateScheme(new File(job.tempDir, childpath.getPath() + SUBJECT_SCHEME_EXTENSION), childRoot);
}
}
//Output parent scheme
generateScheme(new File(job.tempDir, parent.getPath() + SUBJECT_SCHEME_EXTENSION), parentRoot);
}
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
throw new DITAOTException(e);
}
} | [
"private",
"void",
"outputSubjectScheme",
"(",
")",
"throws",
"DITAOTException",
"{",
"try",
"{",
"final",
"Map",
"<",
"URI",
",",
"Set",
"<",
"URI",
">",
">",
"graph",
"=",
"SubjectSchemeReader",
".",
"readMapFromXML",
"(",
"new",
"File",
"(",
"job",
".",... | Output subject schema file.
@throws DITAOTException if generation files | [
"Output",
"subject",
"schema",
"file",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/DebugAndFilterModule.java#L318-L365 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/DebugAndFilterModule.java | DebugAndFilterModule.generateScheme | private void generateScheme(final File filename, final Document root) throws DITAOTException {
final File p = filename.getParentFile();
if (!p.exists() && !p.mkdirs()) {
throw new DITAOTException("Failed to make directory " + p.getAbsolutePath());
}
Result res = null;
try {
res = new StreamResult(new FileOutputStream(filename));
final DOMSource ds = new DOMSource(root);
final TransformerFactory tff = TransformerFactory.newInstance();
final Transformer tf = tff.newTransformer();
tf.transform(ds, res);
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
throw new DITAOTException(e);
} finally {
try {
close(res);
} catch (IOException e) {
throw new DITAOTException(e);
}
}
} | java | private void generateScheme(final File filename, final Document root) throws DITAOTException {
final File p = filename.getParentFile();
if (!p.exists() && !p.mkdirs()) {
throw new DITAOTException("Failed to make directory " + p.getAbsolutePath());
}
Result res = null;
try {
res = new StreamResult(new FileOutputStream(filename));
final DOMSource ds = new DOMSource(root);
final TransformerFactory tff = TransformerFactory.newInstance();
final Transformer tf = tff.newTransformer();
tf.transform(ds, res);
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
logger.error(e.getMessage(), e) ;
throw new DITAOTException(e);
} finally {
try {
close(res);
} catch (IOException e) {
throw new DITAOTException(e);
}
}
} | [
"private",
"void",
"generateScheme",
"(",
"final",
"File",
"filename",
",",
"final",
"Document",
"root",
")",
"throws",
"DITAOTException",
"{",
"final",
"File",
"p",
"=",
"filename",
".",
"getParentFile",
"(",
")",
";",
"if",
"(",
"!",
"p",
".",
"exists",
... | Serialize subject scheme file.
@param filename output filepath
@param root subject scheme document
@throws DITAOTException if generation fails | [
"Serialize",
"subject",
"scheme",
"file",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/DebugAndFilterModule.java#L477-L501 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/DebugAndFilterModule.java | DebugAndFilterModule.getPathtoProject | public static File getPathtoProject(final File filename, final File traceFilename, final File inputMap, final Job job) {
if (job.getGeneratecopyouter() != Job.Generate.OLDSOLUTION) {
if (isOutFile(traceFilename, inputMap)) {
return toFile(getRelativePathFromOut(traceFilename.getAbsoluteFile(), job));
} else {
return getRelativePath(traceFilename.getAbsoluteFile(), inputMap.getAbsoluteFile()).getParentFile();
}
} else {
return FileUtils.getRelativePath(filename);
}
} | java | public static File getPathtoProject(final File filename, final File traceFilename, final File inputMap, final Job job) {
if (job.getGeneratecopyouter() != Job.Generate.OLDSOLUTION) {
if (isOutFile(traceFilename, inputMap)) {
return toFile(getRelativePathFromOut(traceFilename.getAbsoluteFile(), job));
} else {
return getRelativePath(traceFilename.getAbsoluteFile(), inputMap.getAbsoluteFile()).getParentFile();
}
} else {
return FileUtils.getRelativePath(filename);
}
} | [
"public",
"static",
"File",
"getPathtoProject",
"(",
"final",
"File",
"filename",
",",
"final",
"File",
"traceFilename",
",",
"final",
"File",
"inputMap",
",",
"final",
"Job",
"job",
")",
"{",
"if",
"(",
"job",
".",
"getGeneratecopyouter",
"(",
")",
"!=",
... | Get path to base directory
@param filename relative input file path from base directory
@param traceFilename absolute input file
@param inputMap absolute path to start file
@return path to base directory, {@code null} if not available | [
"Get",
"path",
"to",
"base",
"directory"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/DebugAndFilterModule.java#L511-L521 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/DebugAndFilterModule.java | DebugAndFilterModule.getRelativePathFromOut | private static String getRelativePathFromOut(final File overflowingFile, final Job job) {
final URI relativePath = URLUtils.getRelativePath(job.getInputFile(), overflowingFile.toURI());
final File outputDir = job.getOutputDir().getAbsoluteFile();
final File outputPathName = new File(outputDir, "index.html");
final File finalOutFilePathName = resolve(outputDir, relativePath.getPath());
final File finalRelativePathName = FileUtils.getRelativePath(finalOutFilePathName, outputPathName);
File parentDir = finalRelativePathName.getParentFile();
if (parentDir == null || parentDir.getPath().isEmpty()) {
parentDir = new File(".");
}
return parentDir.getPath() + File.separator;
} | java | private static String getRelativePathFromOut(final File overflowingFile, final Job job) {
final URI relativePath = URLUtils.getRelativePath(job.getInputFile(), overflowingFile.toURI());
final File outputDir = job.getOutputDir().getAbsoluteFile();
final File outputPathName = new File(outputDir, "index.html");
final File finalOutFilePathName = resolve(outputDir, relativePath.getPath());
final File finalRelativePathName = FileUtils.getRelativePath(finalOutFilePathName, outputPathName);
File parentDir = finalRelativePathName.getParentFile();
if (parentDir == null || parentDir.getPath().isEmpty()) {
parentDir = new File(".");
}
return parentDir.getPath() + File.separator;
} | [
"private",
"static",
"String",
"getRelativePathFromOut",
"(",
"final",
"File",
"overflowingFile",
",",
"final",
"Job",
"job",
")",
"{",
"final",
"URI",
"relativePath",
"=",
"URLUtils",
".",
"getRelativePath",
"(",
"job",
".",
"getInputFile",
"(",
")",
",",
"ov... | Just for the overflowing files.
@param overflowingFile overflowingFile
@return relative system path to out which ends in {@link java.io.File#separator File.separator} | [
"Just",
"for",
"the",
"overflowing",
"files",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/DebugAndFilterModule.java#L527-L538 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/MoveMetaModule.java | MoveMetaModule.execute | @Override
public AbstractPipelineOutput execute(final AbstractPipelineInput input) throws DITAOTException {
final Collection<FileInfo> fis = job.getFileInfo(fi -> fi.isInput);
if (!fis.isEmpty()) {
final Map<URI, Map<String, Element>> mapSet = getMapMetadata(fis);
pushMetadata(mapSet);
pullTopicMetadata(input, fis);
}
return null;
} | java | @Override
public AbstractPipelineOutput execute(final AbstractPipelineInput input) throws DITAOTException {
final Collection<FileInfo> fis = job.getFileInfo(fi -> fi.isInput);
if (!fis.isEmpty()) {
final Map<URI, Map<String, Element>> mapSet = getMapMetadata(fis);
pushMetadata(mapSet);
pullTopicMetadata(input, fis);
}
return null;
} | [
"@",
"Override",
"public",
"AbstractPipelineOutput",
"execute",
"(",
"final",
"AbstractPipelineInput",
"input",
")",
"throws",
"DITAOTException",
"{",
"final",
"Collection",
"<",
"FileInfo",
">",
"fis",
"=",
"job",
".",
"getFileInfo",
"(",
"fi",
"->",
"fi",
".",... | Entry point of MoveMetaModule.
@param input Input parameters and resources.
@return null
@throws DITAOTException exception | [
"Entry",
"point",
"of",
"MoveMetaModule",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/MoveMetaModule.java#L59-L69 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/MoveMetaModule.java | MoveMetaModule.pushMetadata | private void pushMetadata(final Map<URI, Map<String, Element>> mapSet) {
if (!mapSet.isEmpty()) {
//process map first
final DitaMapMetaWriter mapInserter = new DitaMapMetaWriter();
mapInserter.setLogger(logger);
mapInserter.setJob(job);
for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
final URI key = stripFragment(entry.getKey());
final FileInfo fi = job.getFileInfo(key);
if (fi == null) {
logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
continue;
}
final URI targetFileName = job.tempDirURI.resolve(fi.uri);
assert targetFileName.isAbsolute();
if (fi.format != null && ATTR_FORMAT_VALUE_DITAMAP.equals(fi.format)) {
mapInserter.setMetaTable(entry.getValue());
if (toFile(targetFileName).exists()) {
logger.info("Processing " + targetFileName);
mapInserter.read(toFile(targetFileName));
} else {
logger.error("File " + targetFileName + " does not exist");
}
}
}
//process topic
final DitaMetaWriter topicInserter = new DitaMetaWriter();
topicInserter.setLogger(logger);
topicInserter.setJob(job);
for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
final URI key = stripFragment(entry.getKey());
final FileInfo fi = job.getFileInfo(key);
if (fi == null) {
logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
continue;
}
final URI targetFileName = job.tempDirURI.resolve(fi.uri);
assert targetFileName.isAbsolute();
if (fi.format == null || fi.format.equals(ATTR_FORMAT_VALUE_DITA)) {
final String topicid = entry.getKey().getFragment();
topicInserter.setTopicId(topicid);
topicInserter.setMetaTable(entry.getValue());
if (toFile(targetFileName).exists()) {
topicInserter.read(toFile(targetFileName));
} else {
logger.error("File " + targetFileName + " does not exist");
}
}
}
}
} | java | private void pushMetadata(final Map<URI, Map<String, Element>> mapSet) {
if (!mapSet.isEmpty()) {
//process map first
final DitaMapMetaWriter mapInserter = new DitaMapMetaWriter();
mapInserter.setLogger(logger);
mapInserter.setJob(job);
for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
final URI key = stripFragment(entry.getKey());
final FileInfo fi = job.getFileInfo(key);
if (fi == null) {
logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
continue;
}
final URI targetFileName = job.tempDirURI.resolve(fi.uri);
assert targetFileName.isAbsolute();
if (fi.format != null && ATTR_FORMAT_VALUE_DITAMAP.equals(fi.format)) {
mapInserter.setMetaTable(entry.getValue());
if (toFile(targetFileName).exists()) {
logger.info("Processing " + targetFileName);
mapInserter.read(toFile(targetFileName));
} else {
logger.error("File " + targetFileName + " does not exist");
}
}
}
//process topic
final DitaMetaWriter topicInserter = new DitaMetaWriter();
topicInserter.setLogger(logger);
topicInserter.setJob(job);
for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
final URI key = stripFragment(entry.getKey());
final FileInfo fi = job.getFileInfo(key);
if (fi == null) {
logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
continue;
}
final URI targetFileName = job.tempDirURI.resolve(fi.uri);
assert targetFileName.isAbsolute();
if (fi.format == null || fi.format.equals(ATTR_FORMAT_VALUE_DITA)) {
final String topicid = entry.getKey().getFragment();
topicInserter.setTopicId(topicid);
topicInserter.setMetaTable(entry.getValue());
if (toFile(targetFileName).exists()) {
topicInserter.read(toFile(targetFileName));
} else {
logger.error("File " + targetFileName + " does not exist");
}
}
}
}
} | [
"private",
"void",
"pushMetadata",
"(",
"final",
"Map",
"<",
"URI",
",",
"Map",
"<",
"String",
",",
"Element",
">",
">",
"mapSet",
")",
"{",
"if",
"(",
"!",
"mapSet",
".",
"isEmpty",
"(",
")",
")",
"{",
"//process map first",
"final",
"DitaMapMetaWriter"... | Push information from topicmeta in the map into the corresponding topics and maps. | [
"Push",
"information",
"from",
"topicmeta",
"in",
"the",
"map",
"into",
"the",
"corresponding",
"topics",
"and",
"maps",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/MoveMetaModule.java#L146-L198 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/MoveMetaModule.java | MoveMetaModule.getMapMetadata | private Map<URI, Map<String, Element>> getMapMetadata(final Collection<FileInfo> fis) {
final MapMetaReader metaReader = new MapMetaReader();
metaReader.setLogger(logger);
metaReader.setJob(job);
for (final FileInfo f : fis) {
final File mapFile = new File(job.tempDir, f.file.getPath());
//FIXME: this reader gets the parent path of input file
metaReader.read(mapFile);
}
return metaReader.getMapping();
} | java | private Map<URI, Map<String, Element>> getMapMetadata(final Collection<FileInfo> fis) {
final MapMetaReader metaReader = new MapMetaReader();
metaReader.setLogger(logger);
metaReader.setJob(job);
for (final FileInfo f : fis) {
final File mapFile = new File(job.tempDir, f.file.getPath());
//FIXME: this reader gets the parent path of input file
metaReader.read(mapFile);
}
return metaReader.getMapping();
} | [
"private",
"Map",
"<",
"URI",
",",
"Map",
"<",
"String",
",",
"Element",
">",
">",
"getMapMetadata",
"(",
"final",
"Collection",
"<",
"FileInfo",
">",
"fis",
")",
"{",
"final",
"MapMetaReader",
"metaReader",
"=",
"new",
"MapMetaReader",
"(",
")",
";",
"m... | Read metadata from topicmeta elements in maps. | [
"Read",
"metadata",
"from",
"topicmeta",
"elements",
"in",
"maps",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/MoveMetaModule.java#L203-L213 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/writer/ConkeyrefFilter.java | ConkeyrefFilter.getRelativePath | private URI getRelativePath(final URI href) {
final URI keyValue;
final URI inputMap = job.getFileInfo(fi -> fi.isInput).stream()
.map(fi -> fi.uri)
.findFirst()
.orElse(null);
if (inputMap != null) {
final URI tmpMap = job.tempDirURI.resolve(inputMap);
keyValue = tmpMap.resolve(stripFragment(href));
} else {
keyValue = job.tempDirURI.resolve(stripFragment(href));
}
return URLUtils.getRelativePath(currentFile, keyValue);
} | java | private URI getRelativePath(final URI href) {
final URI keyValue;
final URI inputMap = job.getFileInfo(fi -> fi.isInput).stream()
.map(fi -> fi.uri)
.findFirst()
.orElse(null);
if (inputMap != null) {
final URI tmpMap = job.tempDirURI.resolve(inputMap);
keyValue = tmpMap.resolve(stripFragment(href));
} else {
keyValue = job.tempDirURI.resolve(stripFragment(href));
}
return URLUtils.getRelativePath(currentFile, keyValue);
} | [
"private",
"URI",
"getRelativePath",
"(",
"final",
"URI",
"href",
")",
"{",
"final",
"URI",
"keyValue",
";",
"final",
"URI",
"inputMap",
"=",
"job",
".",
"getFileInfo",
"(",
"fi",
"->",
"fi",
".",
"isInput",
")",
".",
"stream",
"(",
")",
".",
"map",
... | Update href URI.
@param href href URI
@return updated href URI | [
"Update",
"href",
"URI",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/writer/ConkeyrefFilter.java#L92-L105 | train |
dita-ot/dita-ot | src/main/plugins/org.dita.htmlhelp/src/main/java/org/dita/dost/ant/CheckLang.java | CheckLang.setActiveProjectProperty | private void setActiveProjectProperty(final String propertyName, final String propertyValue) {
final Project activeProject = getProject();
if (activeProject != null) {
activeProject.setProperty(propertyName, propertyValue);
}
} | java | private void setActiveProjectProperty(final String propertyName, final String propertyValue) {
final Project activeProject = getProject();
if (activeProject != null) {
activeProject.setProperty(propertyName, propertyValue);
}
} | [
"private",
"void",
"setActiveProjectProperty",
"(",
"final",
"String",
"propertyName",
",",
"final",
"String",
"propertyValue",
")",
"{",
"final",
"Project",
"activeProject",
"=",
"getProject",
"(",
")",
";",
"if",
"(",
"activeProject",
"!=",
"null",
")",
"{",
... | Sets property in active ant project with name specified inpropertyName,
and value specified in propertyValue parameter | [
"Sets",
"property",
"in",
"active",
"ant",
"project",
"with",
"name",
"specified",
"inpropertyName",
"and",
"value",
"specified",
"in",
"propertyValue",
"parameter"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/plugins/org.dita.htmlhelp/src/main/java/org/dita/dost/ant/CheckLang.java#L123-L128 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/ant/DITAOTEchoTask.java | DITAOTEchoTask.readParamValues | private String[] readParamValues() throws BuildException {
final ArrayList<String> prop = new ArrayList<>();
for (final ParamElem p : params) {
if (!p.isValid()) {
throw new BuildException("Incomplete parameter");
}
if (isValid(getProject(), getLocation(), p.getIf(), p.getUnless())) {
final int idx = Integer.parseInt(p.getName()) - 1;
if (idx >= prop.size()) {
prop.ensureCapacity(idx + 1);
while (prop.size() < idx + 1) {
prop.add(null);
}
}
prop.set(idx, p.getValue());
}
}
return prop.toArray(new String[0]);
} | java | private String[] readParamValues() throws BuildException {
final ArrayList<String> prop = new ArrayList<>();
for (final ParamElem p : params) {
if (!p.isValid()) {
throw new BuildException("Incomplete parameter");
}
if (isValid(getProject(), getLocation(), p.getIf(), p.getUnless())) {
final int idx = Integer.parseInt(p.getName()) - 1;
if (idx >= prop.size()) {
prop.ensureCapacity(idx + 1);
while (prop.size() < idx + 1) {
prop.add(null);
}
}
prop.set(idx, p.getValue());
}
}
return prop.toArray(new String[0]);
} | [
"private",
"String",
"[",
"]",
"readParamValues",
"(",
")",
"throws",
"BuildException",
"{",
"final",
"ArrayList",
"<",
"String",
">",
"prop",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"final",
"ParamElem",
"p",
":",
"params",
")",
"{",
... | Read parameter values to an array.
@return parameter values where array index corresponds to parameter name | [
"Read",
"parameter",
"values",
"to",
"an",
"array",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/ant/DITAOTEchoTask.java#L87-L105 | train |
dita-ot/dita-ot | src/main/plugins/org.dita.eclipsehelp/src/main/java/org/dita/dost/writer/EclipseIndexWriter.java | EclipseIndexWriter.getIndexFileName | @Override
public String getIndexFileName(final String outputFileRoot) {
final File indexDir = new File(outputFileRoot).getParentFile();
setFilePath(indexDir.getAbsolutePath());
return new File(indexDir, "index.xml").getAbsolutePath();
} | java | @Override
public String getIndexFileName(final String outputFileRoot) {
final File indexDir = new File(outputFileRoot).getParentFile();
setFilePath(indexDir.getAbsolutePath());
return new File(indexDir, "index.xml").getAbsolutePath();
} | [
"@",
"Override",
"public",
"String",
"getIndexFileName",
"(",
"final",
"String",
"outputFileRoot",
")",
"{",
"final",
"File",
"indexDir",
"=",
"new",
"File",
"(",
"outputFileRoot",
")",
".",
"getParentFile",
"(",
")",
";",
"setFilePath",
"(",
"indexDir",
".",
... | Get index file name.
@param outputFileRoot root path
@return index file name | [
"Get",
"index",
"file",
"name",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/plugins/org.dita.eclipsehelp/src/main/java/org/dita/dost/writer/EclipseIndexWriter.java#L162-L167 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/ant/IntegratorTask.java | IntegratorTask.setDitadir | @Deprecated
public void setDitadir(final File ditaDir) {
if (!ditaDir.isAbsolute()) {
throw new IllegalArgumentException("ditadir attribute value must be an absolute path: " + ditaDir);
}
this.ditaDir = ditaDir;
} | java | @Deprecated
public void setDitadir(final File ditaDir) {
if (!ditaDir.isAbsolute()) {
throw new IllegalArgumentException("ditadir attribute value must be an absolute path: " + ditaDir);
}
this.ditaDir = ditaDir;
} | [
"@",
"Deprecated",
"public",
"void",
"setDitadir",
"(",
"final",
"File",
"ditaDir",
")",
"{",
"if",
"(",
"!",
"ditaDir",
".",
"isAbsolute",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"ditadir attribute value must be an absolute path: \"",... | Set the ditaDir.
@param ditaDir ditaDir | [
"Set",
"the",
"ditaDir",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/ant/IntegratorTask.java#L48-L54 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/writer/SeparateChunkTopicParser.java | SeparateChunkTopicParser.getTopicDoc | private Element getTopicDoc(final URI absolutePathToFile) {
final DocumentBuilder builder = getDocumentBuilder();
try {
final Document doc = builder.parse(absolutePathToFile.toString());
return doc.getDocumentElement();
} catch (final SAXException | IOException e) {
logger.error("Failed to parse " + absolutePathToFile + ": " + e.getMessage(), e);
}
return null;
} | java | private Element getTopicDoc(final URI absolutePathToFile) {
final DocumentBuilder builder = getDocumentBuilder();
try {
final Document doc = builder.parse(absolutePathToFile.toString());
return doc.getDocumentElement();
} catch (final SAXException | IOException e) {
logger.error("Failed to parse " + absolutePathToFile + ": " + e.getMessage(), e);
}
return null;
} | [
"private",
"Element",
"getTopicDoc",
"(",
"final",
"URI",
"absolutePathToFile",
")",
"{",
"final",
"DocumentBuilder",
"builder",
"=",
"getDocumentBuilder",
"(",
")",
";",
"try",
"{",
"final",
"Document",
"doc",
"=",
"builder",
".",
"parse",
"(",
"absolutePathToF... | get the document node of a topic file.
@param absolutePathToFile topic file
@return element. | [
"get",
"the",
"document",
"node",
"of",
"a",
"topic",
"file",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/writer/SeparateChunkTopicParser.java#L260-L269 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.addSubTerm | public void addSubTerm(final IndexTerm term) {
int i = 0;
final int subTermNum = subTerms.size();
if (IndexTermPrefix.SEE != term.getTermPrefix() && IndexTermPrefix.SEE_ALSO != term.getTermPrefix()) {
//if the term is not "index-see" or "index-see-also"
leaf = false;
}
for (; i < subTermNum; i++) {
final IndexTerm subTerm = subTerms.get(i);
if (subTerm.equals(term)) {
return;
}
// Add targets when same term name and same term key
if (subTerm.getTermFullName().equals(term.getTermFullName())
&& subTerm.getTermKey().equals(term.getTermKey())) {
subTerm.addTargets(term.getTargetList());
subTerm.addSubTerms(term.getSubTerms());
return;
}
}
if (i == subTermNum) {
subTerms.add(term);
}
} | java | public void addSubTerm(final IndexTerm term) {
int i = 0;
final int subTermNum = subTerms.size();
if (IndexTermPrefix.SEE != term.getTermPrefix() && IndexTermPrefix.SEE_ALSO != term.getTermPrefix()) {
//if the term is not "index-see" or "index-see-also"
leaf = false;
}
for (; i < subTermNum; i++) {
final IndexTerm subTerm = subTerms.get(i);
if (subTerm.equals(term)) {
return;
}
// Add targets when same term name and same term key
if (subTerm.getTermFullName().equals(term.getTermFullName())
&& subTerm.getTermKey().equals(term.getTermKey())) {
subTerm.addTargets(term.getTargetList());
subTerm.addSubTerms(term.getSubTerms());
return;
}
}
if (i == subTermNum) {
subTerms.add(term);
}
} | [
"public",
"void",
"addSubTerm",
"(",
"final",
"IndexTerm",
"term",
")",
"{",
"int",
"i",
"=",
"0",
";",
"final",
"int",
"subTermNum",
"=",
"subTerms",
".",
"size",
"(",
")",
";",
"if",
"(",
"IndexTermPrefix",
".",
"SEE",
"!=",
"term",
".",
"getTermPref... | Add a sub term into the sub term list.
@param term index term to be added | [
"Add",
"a",
"sub",
"term",
"into",
"the",
"sub",
"term",
"list",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L183-L211 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.addSubTerms | public void addSubTerms(final List<IndexTerm> terms) {
int subTermsNum;
if (terms == null) {
return;
}
subTermsNum = terms.size();
for (int i = 0; i < subTermsNum; i++) {
addSubTerm(terms.get(i));
}
} | java | public void addSubTerms(final List<IndexTerm> terms) {
int subTermsNum;
if (terms == null) {
return;
}
subTermsNum = terms.size();
for (int i = 0; i < subTermsNum; i++) {
addSubTerm(terms.get(i));
}
} | [
"public",
"void",
"addSubTerms",
"(",
"final",
"List",
"<",
"IndexTerm",
">",
"terms",
")",
"{",
"int",
"subTermsNum",
";",
"if",
"(",
"terms",
"==",
"null",
")",
"{",
"return",
";",
"}",
"subTermsNum",
"=",
"terms",
".",
"size",
"(",
")",
";",
"for"... | Add all the sub terms in the list.
@param terms terms list | [
"Add",
"all",
"the",
"sub",
"terms",
"in",
"the",
"list",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L218-L228 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.sortSubTerms | public void sortSubTerms() {
final int subTermNum = subTerms.size();
if (subTerms != null && subTermNum > 0) {
Collections.sort(subTerms);
for (final IndexTerm subTerm : subTerms) {
subTerm.sortSubTerms();
}
}
} | java | public void sortSubTerms() {
final int subTermNum = subTerms.size();
if (subTerms != null && subTermNum > 0) {
Collections.sort(subTerms);
for (final IndexTerm subTerm : subTerms) {
subTerm.sortSubTerms();
}
}
} | [
"public",
"void",
"sortSubTerms",
"(",
")",
"{",
"final",
"int",
"subTermNum",
"=",
"subTerms",
".",
"size",
"(",
")",
";",
"if",
"(",
"subTerms",
"!=",
"null",
"&&",
"subTermNum",
">",
"0",
")",
"{",
"Collections",
".",
"sort",
"(",
"subTerms",
")",
... | Sort all the subterms iteratively. | [
"Sort",
"all",
"the",
"subterms",
"iteratively",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L278-L287 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.compareTo | @Override
public int compareTo(final IndexTerm obj) {
return DITAOTCollator.getInstance(termLocale).compare(termKey, obj.getTermKey());
} | java | @Override
public int compareTo(final IndexTerm obj) {
return DITAOTCollator.getInstance(termLocale).compare(termKey, obj.getTermKey());
} | [
"@",
"Override",
"public",
"int",
"compareTo",
"(",
"final",
"IndexTerm",
"obj",
")",
"{",
"return",
"DITAOTCollator",
".",
"getInstance",
"(",
"termLocale",
")",
".",
"compare",
"(",
"termKey",
",",
"obj",
".",
"getTermKey",
"(",
")",
")",
";",
"}"
] | Compare the given indexterm with current term.
@param obj object to compare with
@return int | [
"Compare",
"the",
"given",
"indexterm",
"with",
"current",
"term",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L295-L298 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.addTargets | public void addTargets(final List<IndexTermTarget> targets) {
int targetNum;
if (targets == null) {
return;
}
targetNum = targets.size();
for (int i = 0; i < targetNum; i++) {
addTarget(targets.get(i));
}
} | java | public void addTargets(final List<IndexTermTarget> targets) {
int targetNum;
if (targets == null) {
return;
}
targetNum = targets.size();
for (int i = 0; i < targetNum; i++) {
addTarget(targets.get(i));
}
} | [
"public",
"void",
"addTargets",
"(",
"final",
"List",
"<",
"IndexTermTarget",
">",
"targets",
")",
"{",
"int",
"targetNum",
";",
"if",
"(",
"targets",
"==",
"null",
")",
"{",
"return",
";",
"}",
"targetNum",
"=",
"targets",
".",
"size",
"(",
")",
";",
... | Add all the indexterm targets in the list.
@param targets list of targets | [
"Add",
"all",
"the",
"indexterm",
"targets",
"in",
"the",
"list",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L325-L336 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.getTermFullName | public String getTermFullName() {
if (termPrefix == null) {
return termName;
} else {
if (termLocale == null) {
return termPrefix.message + STRING_BLANK + termName;
} else {
final String key = "IndexTerm." + termPrefix.message.toLowerCase().trim().replace(' ', '-');
final String msg = Messages.getString(key, termLocale);
if (rtlLocaleList.contains(termLocale.toString())) {
return termName + STRING_BLANK + msg;
} else {
return msg + STRING_BLANK + termName;
}
}
}
} | java | public String getTermFullName() {
if (termPrefix == null) {
return termName;
} else {
if (termLocale == null) {
return termPrefix.message + STRING_BLANK + termName;
} else {
final String key = "IndexTerm." + termPrefix.message.toLowerCase().trim().replace(' ', '-');
final String msg = Messages.getString(key, termLocale);
if (rtlLocaleList.contains(termLocale.toString())) {
return termName + STRING_BLANK + msg;
} else {
return msg + STRING_BLANK + termName;
}
}
}
} | [
"public",
"String",
"getTermFullName",
"(",
")",
"{",
"if",
"(",
"termPrefix",
"==",
"null",
")",
"{",
"return",
"termName",
";",
"}",
"else",
"{",
"if",
"(",
"termLocale",
"==",
"null",
")",
"{",
"return",
"termPrefix",
".",
"message",
"+",
"STRING_BLAN... | Get the full term, with any prefix.
@return full term with prefix | [
"Get",
"the",
"full",
"term",
"with",
"any",
"prefix",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L377-L393 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/index/IndexTerm.java | IndexTerm.updateSubTerm | public void updateSubTerm() {
if (subTerms.size() == 1) {
// if there is only one subterm, it is necessary to update
final IndexTerm term = subTerms.get(0); // get the only subterm
if (term.getTermPrefix() == IndexTermPrefix.SEE) {
//if the only subterm is index-see update it to index-see-also
term.setTermPrefix(IndexTermPrefix.SEE_ALSO);
}
// subTerms.set(0, term);
}
} | java | public void updateSubTerm() {
if (subTerms.size() == 1) {
// if there is only one subterm, it is necessary to update
final IndexTerm term = subTerms.get(0); // get the only subterm
if (term.getTermPrefix() == IndexTermPrefix.SEE) {
//if the only subterm is index-see update it to index-see-also
term.setTermPrefix(IndexTermPrefix.SEE_ALSO);
}
// subTerms.set(0, term);
}
} | [
"public",
"void",
"updateSubTerm",
"(",
")",
"{",
"if",
"(",
"subTerms",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"// if there is only one subterm, it is necessary to update",
"final",
"IndexTerm",
"term",
"=",
"subTerms",
".",
"get",
"(",
"0",
")",
";",
... | Update the sub-term prefix from "See also" to "See" if there is only one sub-term. | [
"Update",
"the",
"sub",
"-",
"term",
"prefix",
"from",
"See",
"also",
"to",
"See",
"if",
"there",
"is",
"only",
"one",
"sub",
"-",
"term",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/index/IndexTerm.java#L398-L408 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.read | public void read(final URI filename, final Document doc) {
currentFile = filename;
rootScope = null;
// TODO: use KeyScope implementation that retains order
KeyScope keyScope = readScopes(doc);
keyScope = cascadeChildKeys(keyScope);
// TODO: determine effective key definitions here
keyScope = inheritParentKeys(keyScope);
rootScope = resolveIntermediate(keyScope);
} | java | public void read(final URI filename, final Document doc) {
currentFile = filename;
rootScope = null;
// TODO: use KeyScope implementation that retains order
KeyScope keyScope = readScopes(doc);
keyScope = cascadeChildKeys(keyScope);
// TODO: determine effective key definitions here
keyScope = inheritParentKeys(keyScope);
rootScope = resolveIntermediate(keyScope);
} | [
"public",
"void",
"read",
"(",
"final",
"URI",
"filename",
",",
"final",
"Document",
"doc",
")",
"{",
"currentFile",
"=",
"filename",
";",
"rootScope",
"=",
"null",
";",
"// TODO: use KeyScope implementation that retains order",
"KeyScope",
"keyScope",
"=",
"readSco... | Read key definitions
@param filename absolute URI to DITA map with key definitions
@param doc key definition DITA map | [
"Read",
"key",
"definitions"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L100-L109 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.readScopes | private KeyScope readScopes(final Document doc) {
final List<KeyScope> scopes = readScopes(doc.getDocumentElement());
if (scopes.size() == 1 && scopes.get(0).name == null) {
return scopes.get(0);
} else {
return new KeyScope("#root", null, Collections.emptyMap(), scopes);
}
} | java | private KeyScope readScopes(final Document doc) {
final List<KeyScope> scopes = readScopes(doc.getDocumentElement());
if (scopes.size() == 1 && scopes.get(0).name == null) {
return scopes.get(0);
} else {
return new KeyScope("#root", null, Collections.emptyMap(), scopes);
}
} | [
"private",
"KeyScope",
"readScopes",
"(",
"final",
"Document",
"doc",
")",
"{",
"final",
"List",
"<",
"KeyScope",
">",
"scopes",
"=",
"readScopes",
"(",
"doc",
".",
"getDocumentElement",
"(",
")",
")",
";",
"if",
"(",
"scopes",
".",
"size",
"(",
")",
"... | Read keys scopes in map. | [
"Read",
"keys",
"scopes",
"in",
"map",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L112-L119 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.readScope | private void readScope(final Element scope, final Map<String, KeyDef> keyDefs) {
final List<Element> maps = new ArrayList<>();
maps.add(scope);
for (final Element child: getChildElements(scope)) {
collectMaps(child, maps);
}
for (final Element map: maps) {
readMap(map, keyDefs);
}
} | java | private void readScope(final Element scope, final Map<String, KeyDef> keyDefs) {
final List<Element> maps = new ArrayList<>();
maps.add(scope);
for (final Element child: getChildElements(scope)) {
collectMaps(child, maps);
}
for (final Element map: maps) {
readMap(map, keyDefs);
}
} | [
"private",
"void",
"readScope",
"(",
"final",
"Element",
"scope",
",",
"final",
"Map",
"<",
"String",
",",
"KeyDef",
">",
"keyDefs",
")",
"{",
"final",
"List",
"<",
"Element",
">",
"maps",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"maps",
".",
"a... | Read key definitions from a key scope. | [
"Read",
"key",
"definitions",
"from",
"a",
"key",
"scope",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L170-L179 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.readMap | private void readMap(final Element map, final Map<String, KeyDef> keyDefs) {
readKeyDefinition(map, keyDefs);
for (final Element elem: getChildElements(map)) {
if (!(SUBMAP.matches(elem) || elem.getAttributeNode(ATTRIBUTE_NAME_KEYSCOPE) != null)) {
readMap(elem, keyDefs);
}
}
} | java | private void readMap(final Element map, final Map<String, KeyDef> keyDefs) {
readKeyDefinition(map, keyDefs);
for (final Element elem: getChildElements(map)) {
if (!(SUBMAP.matches(elem) || elem.getAttributeNode(ATTRIBUTE_NAME_KEYSCOPE) != null)) {
readMap(elem, keyDefs);
}
}
} | [
"private",
"void",
"readMap",
"(",
"final",
"Element",
"map",
",",
"final",
"Map",
"<",
"String",
",",
"KeyDef",
">",
"keyDefs",
")",
"{",
"readKeyDefinition",
"(",
"map",
",",
"keyDefs",
")",
";",
"for",
"(",
"final",
"Element",
"elem",
":",
"getChildEl... | Recursively read key definitions from a single map fragment. | [
"Recursively",
"read",
"key",
"definitions",
"from",
"a",
"single",
"map",
"fragment",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L195-L202 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.cascadeChildKeys | private KeyScope cascadeChildKeys(final KeyScope rootScope) {
final Map<String, KeyDef> res = new HashMap<>(rootScope.keyDefinition);
cascadeChildKeys(rootScope, res, "");
return new KeyScope(rootScope.id, rootScope.name, res, new ArrayList<>(rootScope.childScopes));
} | java | private KeyScope cascadeChildKeys(final KeyScope rootScope) {
final Map<String, KeyDef> res = new HashMap<>(rootScope.keyDefinition);
cascadeChildKeys(rootScope, res, "");
return new KeyScope(rootScope.id, rootScope.name, res, new ArrayList<>(rootScope.childScopes));
} | [
"private",
"KeyScope",
"cascadeChildKeys",
"(",
"final",
"KeyScope",
"rootScope",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"KeyDef",
">",
"res",
"=",
"new",
"HashMap",
"<>",
"(",
"rootScope",
".",
"keyDefinition",
")",
";",
"cascadeChildKeys",
"(",
"roo... | Cascade child keys with prefixes to parent key scopes. | [
"Cascade",
"child",
"keys",
"with",
"prefixes",
"to",
"parent",
"key",
"scopes",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L226-L230 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/KeyrefReader.java | KeyrefReader.resolveIntermediate | private KeyScope resolveIntermediate(final KeyScope scope) {
final Map<String, KeyDef> keys = new HashMap<>(scope.keyDefinition);
for (final Map.Entry<String, KeyDef> e: scope.keyDefinition.entrySet()) {
final KeyDef res = resolveIntermediate(scope, e.getValue(), Collections.singletonList(e.getValue()));
keys.put(e.getKey(), res);
}
final List<KeyScope> children = new ArrayList<>();
for (final KeyScope child: scope.childScopes) {
final KeyScope resolvedChild = resolveIntermediate(child);
children.add(resolvedChild);
}
return new KeyScope(scope.id, scope.name, keys, children);
} | java | private KeyScope resolveIntermediate(final KeyScope scope) {
final Map<String, KeyDef> keys = new HashMap<>(scope.keyDefinition);
for (final Map.Entry<String, KeyDef> e: scope.keyDefinition.entrySet()) {
final KeyDef res = resolveIntermediate(scope, e.getValue(), Collections.singletonList(e.getValue()));
keys.put(e.getKey(), res);
}
final List<KeyScope> children = new ArrayList<>();
for (final KeyScope child: scope.childScopes) {
final KeyScope resolvedChild = resolveIntermediate(child);
children.add(resolvedChild);
}
return new KeyScope(scope.id, scope.name, keys, children);
} | [
"private",
"KeyScope",
"resolveIntermediate",
"(",
"final",
"KeyScope",
"scope",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"KeyDef",
">",
"keys",
"=",
"new",
"HashMap",
"<>",
"(",
"scope",
".",
"keyDefinition",
")",
";",
"for",
"(",
"final",
"Map",
"... | Resolve intermediate key references. | [
"Resolve",
"intermediate",
"key",
"references",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/KeyrefReader.java#L271-L283 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/ConrefPushReader.java | ConrefPushReader.replaceContent | private DocumentFragment replaceContent(final DocumentFragment pushcontent) {
final NodeList children = pushcontent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
switch (child.getNodeType()) {
case Node.ELEMENT_NODE:
final Element e = (Element) child;
replaceLinkAttributes(e);
final NodeList elements = e.getElementsByTagName("*");
for (int j = 0; i < elements.getLength(); i++) {
replaceLinkAttributes((Element) elements.item(j));
}
break;
}
}
return pushcontent;
} | java | private DocumentFragment replaceContent(final DocumentFragment pushcontent) {
final NodeList children = pushcontent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
switch (child.getNodeType()) {
case Node.ELEMENT_NODE:
final Element e = (Element) child;
replaceLinkAttributes(e);
final NodeList elements = e.getElementsByTagName("*");
for (int j = 0; i < elements.getLength(); i++) {
replaceLinkAttributes((Element) elements.item(j));
}
break;
}
}
return pushcontent;
} | [
"private",
"DocumentFragment",
"replaceContent",
"(",
"final",
"DocumentFragment",
"pushcontent",
")",
"{",
"final",
"NodeList",
"children",
"=",
"pushcontent",
".",
"getChildNodes",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"children",
... | Rewrite link attributes. | [
"Rewrite",
"link",
"attributes",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/ConrefPushReader.java#L224-L240 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java | DitamapIndexTermReader.needPushTerm | private boolean needPushTerm() {
if (elementStack.empty()) {
return false;
}
if (elementStack.peek() instanceof TopicrefElement) {
// for dita files the indexterm has been moved to its <prolog>
// therefore we don't need to collect these terms again.
final TopicrefElement elem = (TopicrefElement) elementStack.peek();
if (indexMoved && (elem.getFormat() == null || elem.getFormat().equals(ATTR_FORMAT_VALUE_DITA) || elem.getFormat().equals(ATTR_FORMAT_VALUE_DITAMAP))) {
return false;
}
}
return true;
} | java | private boolean needPushTerm() {
if (elementStack.empty()) {
return false;
}
if (elementStack.peek() instanceof TopicrefElement) {
// for dita files the indexterm has been moved to its <prolog>
// therefore we don't need to collect these terms again.
final TopicrefElement elem = (TopicrefElement) elementStack.peek();
if (indexMoved && (elem.getFormat() == null || elem.getFormat().equals(ATTR_FORMAT_VALUE_DITA) || elem.getFormat().equals(ATTR_FORMAT_VALUE_DITAMAP))) {
return false;
}
}
return true;
} | [
"private",
"boolean",
"needPushTerm",
"(",
")",
"{",
"if",
"(",
"elementStack",
".",
"empty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"elementStack",
".",
"peek",
"(",
")",
"instanceof",
"TopicrefElement",
")",
"{",
"// for dita files t... | Check element stack for the root topicref or indexterm element. | [
"Check",
"element",
"stack",
"for",
"the",
"root",
"topicref",
"or",
"indexterm",
"element",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/reader/DitamapIndexTermReader.java#L338-L353 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/util/DitaClass.java | DitaClass.matches | public boolean matches(final Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
return matches(((Element) node).getAttribute(ATTRIBUTE_NAME_CLASS));
}
return false;
} | java | public boolean matches(final Node node) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
return matches(((Element) node).getAttribute(ATTRIBUTE_NAME_CLASS));
}
return false;
} | [
"public",
"boolean",
"matches",
"(",
"final",
"Node",
"node",
")",
"{",
"if",
"(",
"node",
".",
"getNodeType",
"(",
")",
"==",
"Node",
".",
"ELEMENT_NODE",
")",
"{",
"return",
"matches",
"(",
"(",
"(",
"Element",
")",
"node",
")",
".",
"getAttribute",
... | Test if given DITA class string matches this DITA class.
@param node DOM DITA element
@return {@code true} if given node is an Element and its class matches this class, otherwise {@code false} | [
"Test",
"if",
"given",
"DITA",
"class",
"string",
"matches",
"this",
"DITA",
"class",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/util/DitaClass.java#L175-L180 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/KeyrefModule.java | KeyrefModule.execute | @Override
public AbstractPipelineOutput execute(final AbstractPipelineInput input)
throws DITAOTException {
if (fileInfoFilter == null) {
fileInfoFilter = f -> f.format == null || f.format.equals(ATTR_FORMAT_VALUE_DITA) || f.format.equals(ATTR_FORMAT_VALUE_DITAMAP);
}
final Collection<FileInfo> fis = job.getFileInfo(fileInfoFilter).stream()
.filter(f -> f.hasKeyref)
.collect(Collectors.toSet());
if (!fis.isEmpty()) {
try {
final String cls = Optional
.ofNullable(job.getProperty("temp-file-name-scheme"))
.orElse(configuration.get("temp-file-name-scheme"));
tempFileNameScheme = (GenMapAndTopicListModule.TempFileNameScheme) Class.forName(cls).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
tempFileNameScheme.setBaseDir(job.getInputDir());
initFilters();
final Document doc = readMap();
final KeyrefReader reader = new KeyrefReader();
reader.setLogger(logger);
final Job.FileInfo in = job.getFileInfo(fi -> fi.isInput).iterator().next();
final URI mapFile = in.uri;
logger.info("Reading " + job.tempDirURI.resolve(mapFile).toString());
reader.read(job.tempDirURI.resolve(mapFile), doc);
final KeyScope rootScope = reader.getKeyDefinition();
final List<ResolveTask> jobs = collectProcessingTopics(fis, rootScope, doc);
writeMap(doc);
transtype = input.getAttribute(ANT_INVOKER_EXT_PARAM_TRANSTYPE);
delayConrefUtils = transtype.equals(INDEX_TYPE_ECLIPSEHELP) ? new DelayConrefUtils() : null;
for (final ResolveTask r: jobs) {
if (r.out != null) {
processFile(r);
}
}
for (final ResolveTask r: jobs) {
if (r.out == null) {
processFile(r);
}
}
// Store job configuration updates
for (final URI file: normalProcessingRole) {
final FileInfo f = job.getFileInfo(file);
if (f != null) {
f.isResourceOnly = false;
job.add(f);
}
}
try {
job.write();
} catch (final IOException e) {
throw new DITAOTException("Failed to store job state: " + e.getMessage(), e);
}
}
return null;
} | java | @Override
public AbstractPipelineOutput execute(final AbstractPipelineInput input)
throws DITAOTException {
if (fileInfoFilter == null) {
fileInfoFilter = f -> f.format == null || f.format.equals(ATTR_FORMAT_VALUE_DITA) || f.format.equals(ATTR_FORMAT_VALUE_DITAMAP);
}
final Collection<FileInfo> fis = job.getFileInfo(fileInfoFilter).stream()
.filter(f -> f.hasKeyref)
.collect(Collectors.toSet());
if (!fis.isEmpty()) {
try {
final String cls = Optional
.ofNullable(job.getProperty("temp-file-name-scheme"))
.orElse(configuration.get("temp-file-name-scheme"));
tempFileNameScheme = (GenMapAndTopicListModule.TempFileNameScheme) Class.forName(cls).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
tempFileNameScheme.setBaseDir(job.getInputDir());
initFilters();
final Document doc = readMap();
final KeyrefReader reader = new KeyrefReader();
reader.setLogger(logger);
final Job.FileInfo in = job.getFileInfo(fi -> fi.isInput).iterator().next();
final URI mapFile = in.uri;
logger.info("Reading " + job.tempDirURI.resolve(mapFile).toString());
reader.read(job.tempDirURI.resolve(mapFile), doc);
final KeyScope rootScope = reader.getKeyDefinition();
final List<ResolveTask> jobs = collectProcessingTopics(fis, rootScope, doc);
writeMap(doc);
transtype = input.getAttribute(ANT_INVOKER_EXT_PARAM_TRANSTYPE);
delayConrefUtils = transtype.equals(INDEX_TYPE_ECLIPSEHELP) ? new DelayConrefUtils() : null;
for (final ResolveTask r: jobs) {
if (r.out != null) {
processFile(r);
}
}
for (final ResolveTask r: jobs) {
if (r.out == null) {
processFile(r);
}
}
// Store job configuration updates
for (final URI file: normalProcessingRole) {
final FileInfo f = job.getFileInfo(file);
if (f != null) {
f.isResourceOnly = false;
job.add(f);
}
}
try {
job.write();
} catch (final IOException e) {
throw new DITAOTException("Failed to store job state: " + e.getMessage(), e);
}
}
return null;
} | [
"@",
"Override",
"public",
"AbstractPipelineOutput",
"execute",
"(",
"final",
"AbstractPipelineInput",
"input",
")",
"throws",
"DITAOTException",
"{",
"if",
"(",
"fileInfoFilter",
"==",
"null",
")",
"{",
"fileInfoFilter",
"=",
"f",
"->",
"f",
".",
"format",
"=="... | Entry point of KeyrefModule.
@param input Input parameters and resources.
@return null
@throws DITAOTException exception | [
"Entry",
"point",
"of",
"KeyrefModule",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/KeyrefModule.java#L85-L148 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/KeyrefModule.java | KeyrefModule.collectProcessingTopics | private List<ResolveTask> collectProcessingTopics(final Collection<FileInfo> fis, final KeyScope rootScope, final Document doc) {
final List<ResolveTask> res = new ArrayList<>();
final FileInfo input = job.getFileInfo(fi -> fi.isInput).iterator().next();
res.add(new ResolveTask(rootScope, input, null));
// Collect topics from map and rewrite topicrefs for duplicates
walkMap(doc.getDocumentElement(), rootScope, res);
// Collect topics not in map and map itself
for (final FileInfo f: fis) {
if (!usage.containsKey(f.uri)) {
res.add(processTopic(f, rootScope, f.isResourceOnly));
}
}
final List<ResolveTask> deduped = removeDuplicateResolveTargets(res);
if (fileInfoFilter != null) {
return adjustResourceRenames(deduped.stream()
.filter(rs -> fileInfoFilter.test(rs.in))
.collect(Collectors.toList()));
} else {
return adjustResourceRenames(deduped);
}
} | java | private List<ResolveTask> collectProcessingTopics(final Collection<FileInfo> fis, final KeyScope rootScope, final Document doc) {
final List<ResolveTask> res = new ArrayList<>();
final FileInfo input = job.getFileInfo(fi -> fi.isInput).iterator().next();
res.add(new ResolveTask(rootScope, input, null));
// Collect topics from map and rewrite topicrefs for duplicates
walkMap(doc.getDocumentElement(), rootScope, res);
// Collect topics not in map and map itself
for (final FileInfo f: fis) {
if (!usage.containsKey(f.uri)) {
res.add(processTopic(f, rootScope, f.isResourceOnly));
}
}
final List<ResolveTask> deduped = removeDuplicateResolveTargets(res);
if (fileInfoFilter != null) {
return adjustResourceRenames(deduped.stream()
.filter(rs -> fileInfoFilter.test(rs.in))
.collect(Collectors.toList()));
} else {
return adjustResourceRenames(deduped);
}
} | [
"private",
"List",
"<",
"ResolveTask",
">",
"collectProcessingTopics",
"(",
"final",
"Collection",
"<",
"FileInfo",
">",
"fis",
",",
"final",
"KeyScope",
"rootScope",
",",
"final",
"Document",
"doc",
")",
"{",
"final",
"List",
"<",
"ResolveTask",
">",
"res",
... | Collect topics for key reference processing and modify map to reflect new file names. | [
"Collect",
"topics",
"for",
"key",
"reference",
"processing",
"and",
"modify",
"map",
"to",
"reflect",
"new",
"file",
"names",
"."
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/KeyrefModule.java#L155-L176 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/KeyrefModule.java | KeyrefModule.removeDuplicateResolveTargets | private List<ResolveTask> removeDuplicateResolveTargets(List<ResolveTask> renames) {
return renames.stream()
.collect(Collectors.groupingBy(
rt -> rt.scope,
Collectors.toMap(
rt -> rt.in.uri,
Function.identity(),
(rt1, rt2) -> rt1
)
)).values().stream()
.flatMap(m -> m.values().stream())
.collect(Collectors.toList());
} | java | private List<ResolveTask> removeDuplicateResolveTargets(List<ResolveTask> renames) {
return renames.stream()
.collect(Collectors.groupingBy(
rt -> rt.scope,
Collectors.toMap(
rt -> rt.in.uri,
Function.identity(),
(rt1, rt2) -> rt1
)
)).values().stream()
.flatMap(m -> m.values().stream())
.collect(Collectors.toList());
} | [
"private",
"List",
"<",
"ResolveTask",
">",
"removeDuplicateResolveTargets",
"(",
"List",
"<",
"ResolveTask",
">",
"renames",
")",
"{",
"return",
"renames",
".",
"stream",
"(",
")",
".",
"collect",
"(",
"Collectors",
".",
"groupingBy",
"(",
"rt",
"->",
"rt",... | Remove duplicate sources within the same scope | [
"Remove",
"duplicate",
"sources",
"within",
"the",
"same",
"scope"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/KeyrefModule.java#L179-L191 | train |
dita-ot/dita-ot | src/main/java/org/dita/dost/module/KeyrefModule.java | KeyrefModule.adjustResourceRenames | List<ResolveTask> adjustResourceRenames(final List<ResolveTask> renames) {
final Map<KeyScope, List<ResolveTask>> scopes = renames.stream().collect(Collectors.groupingBy(rt -> rt.scope));
final List<ResolveTask> res = new ArrayList<>();
for (final Map.Entry<KeyScope, List<ResolveTask>> group : scopes.entrySet()) {
final KeyScope scope = group.getKey();
final List<ResolveTask> tasks = group.getValue();
final Map<URI, URI> rewrites = tasks.stream()
// FIXME this should be filtered out earlier
.filter(t -> t.out != null)
.collect(toMap(
t -> t.in.uri,
t -> t.out.uri
));
final KeyScope resScope = rewriteScopeTargets(scope, rewrites);
tasks.stream().map(t -> new ResolveTask(resScope, t.in, t.out)).forEach(res::add);
}
return res;
} | java | List<ResolveTask> adjustResourceRenames(final List<ResolveTask> renames) {
final Map<KeyScope, List<ResolveTask>> scopes = renames.stream().collect(Collectors.groupingBy(rt -> rt.scope));
final List<ResolveTask> res = new ArrayList<>();
for (final Map.Entry<KeyScope, List<ResolveTask>> group : scopes.entrySet()) {
final KeyScope scope = group.getKey();
final List<ResolveTask> tasks = group.getValue();
final Map<URI, URI> rewrites = tasks.stream()
// FIXME this should be filtered out earlier
.filter(t -> t.out != null)
.collect(toMap(
t -> t.in.uri,
t -> t.out.uri
));
final KeyScope resScope = rewriteScopeTargets(scope, rewrites);
tasks.stream().map(t -> new ResolveTask(resScope, t.in, t.out)).forEach(res::add);
}
return res;
} | [
"List",
"<",
"ResolveTask",
">",
"adjustResourceRenames",
"(",
"final",
"List",
"<",
"ResolveTask",
">",
"renames",
")",
"{",
"final",
"Map",
"<",
"KeyScope",
",",
"List",
"<",
"ResolveTask",
">",
">",
"scopes",
"=",
"renames",
".",
"stream",
"(",
")",
"... | Adjust key targets per rewrites | [
"Adjust",
"key",
"targets",
"per",
"rewrites"
] | ea776b3c60c03d9f033b6f7ea072349e49dbcdd2 | https://github.com/dita-ot/dita-ot/blob/ea776b3c60c03d9f033b6f7ea072349e49dbcdd2/src/main/java/org/dita/dost/module/KeyrefModule.java#L194-L213 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.