id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
162,600 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/StandaloneHiveRunner.java | StandaloneHiveRunner.evaluateStatement | public HiveShellContainer evaluateStatement(List<? extends Script> scripts, Object target, TemporaryFolder temporaryFolder, Statement base) throws Throwable {
container = null;
FileUtil.setPermission(temporaryFolder.getRoot(), FsPermission.getDirDefault());
try {
LOGGER.info("Setting up {} in {}", getName(), temporaryFolder.getRoot().getAbsolutePath());
container = createHiveServerContainer(scripts, target, temporaryFolder);
base.evaluate();
return container;
} finally {
tearDown();
}
} | java | public HiveShellContainer evaluateStatement(List<? extends Script> scripts, Object target, TemporaryFolder temporaryFolder, Statement base) throws Throwable {
container = null;
FileUtil.setPermission(temporaryFolder.getRoot(), FsPermission.getDirDefault());
try {
LOGGER.info("Setting up {} in {}", getName(), temporaryFolder.getRoot().getAbsolutePath());
container = createHiveServerContainer(scripts, target, temporaryFolder);
base.evaluate();
return container;
} finally {
tearDown();
}
} | [
"public",
"HiveShellContainer",
"evaluateStatement",
"(",
"List",
"<",
"?",
"extends",
"Script",
">",
"scripts",
",",
"Object",
"target",
",",
"TemporaryFolder",
"temporaryFolder",
",",
"Statement",
"base",
")",
"throws",
"Throwable",
"{",
"container",
"=",
"null",
";",
"FileUtil",
".",
"setPermission",
"(",
"temporaryFolder",
".",
"getRoot",
"(",
")",
",",
"FsPermission",
".",
"getDirDefault",
"(",
")",
")",
";",
"try",
"{",
"LOGGER",
".",
"info",
"(",
"\"Setting up {} in {}\"",
",",
"getName",
"(",
")",
",",
"temporaryFolder",
".",
"getRoot",
"(",
")",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"container",
"=",
"createHiveServerContainer",
"(",
"scripts",
",",
"target",
",",
"temporaryFolder",
")",
";",
"base",
".",
"evaluate",
"(",
")",
";",
"return",
"container",
";",
"}",
"finally",
"{",
"tearDown",
"(",
")",
";",
"}",
"}"
] | Drives the unit test. | [
"Drives",
"the",
"unit",
"test",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/StandaloneHiveRunner.java#L160-L171 |
162,601 | klarna/HiveRunner | src/main/java/com/klarna/hiverunner/StandaloneHiveRunner.java | StandaloneHiveRunner.createHiveServerContainer | private HiveShellContainer createHiveServerContainer(final List<? extends Script> scripts, final Object testCase, TemporaryFolder baseDir)
throws IOException {
HiveServerContext context = new StandaloneHiveServerContext(baseDir, config);
final HiveServerContainer hiveTestHarness = new HiveServerContainer(context);
HiveShellBuilder hiveShellBuilder = new HiveShellBuilder();
hiveShellBuilder.setCommandShellEmulation(config.getCommandShellEmulator());
HiveShellField shellSetter = loadScriptUnderTest(testCase, hiveShellBuilder);
if (scripts != null) {
hiveShellBuilder.overrideScriptsUnderTest(scripts);
}
hiveShellBuilder.setHiveServerContainer(hiveTestHarness);
loadAnnotatedResources(testCase, hiveShellBuilder);
loadAnnotatedProperties(testCase, hiveShellBuilder);
loadAnnotatedSetupScripts(testCase, hiveShellBuilder);
// Build shell
final HiveShellContainer shell = hiveShellBuilder.buildShell();
// Set shell
shellSetter.setShell(shell);
if (shellSetter.isAutoStart()) {
shell.start();
}
return shell;
} | java | private HiveShellContainer createHiveServerContainer(final List<? extends Script> scripts, final Object testCase, TemporaryFolder baseDir)
throws IOException {
HiveServerContext context = new StandaloneHiveServerContext(baseDir, config);
final HiveServerContainer hiveTestHarness = new HiveServerContainer(context);
HiveShellBuilder hiveShellBuilder = new HiveShellBuilder();
hiveShellBuilder.setCommandShellEmulation(config.getCommandShellEmulator());
HiveShellField shellSetter = loadScriptUnderTest(testCase, hiveShellBuilder);
if (scripts != null) {
hiveShellBuilder.overrideScriptsUnderTest(scripts);
}
hiveShellBuilder.setHiveServerContainer(hiveTestHarness);
loadAnnotatedResources(testCase, hiveShellBuilder);
loadAnnotatedProperties(testCase, hiveShellBuilder);
loadAnnotatedSetupScripts(testCase, hiveShellBuilder);
// Build shell
final HiveShellContainer shell = hiveShellBuilder.buildShell();
// Set shell
shellSetter.setShell(shell);
if (shellSetter.isAutoStart()) {
shell.start();
}
return shell;
} | [
"private",
"HiveShellContainer",
"createHiveServerContainer",
"(",
"final",
"List",
"<",
"?",
"extends",
"Script",
">",
"scripts",
",",
"final",
"Object",
"testCase",
",",
"TemporaryFolder",
"baseDir",
")",
"throws",
"IOException",
"{",
"HiveServerContext",
"context",
"=",
"new",
"StandaloneHiveServerContext",
"(",
"baseDir",
",",
"config",
")",
";",
"final",
"HiveServerContainer",
"hiveTestHarness",
"=",
"new",
"HiveServerContainer",
"(",
"context",
")",
";",
"HiveShellBuilder",
"hiveShellBuilder",
"=",
"new",
"HiveShellBuilder",
"(",
")",
";",
"hiveShellBuilder",
".",
"setCommandShellEmulation",
"(",
"config",
".",
"getCommandShellEmulator",
"(",
")",
")",
";",
"HiveShellField",
"shellSetter",
"=",
"loadScriptUnderTest",
"(",
"testCase",
",",
"hiveShellBuilder",
")",
";",
"if",
"(",
"scripts",
"!=",
"null",
")",
"{",
"hiveShellBuilder",
".",
"overrideScriptsUnderTest",
"(",
"scripts",
")",
";",
"}",
"hiveShellBuilder",
".",
"setHiveServerContainer",
"(",
"hiveTestHarness",
")",
";",
"loadAnnotatedResources",
"(",
"testCase",
",",
"hiveShellBuilder",
")",
";",
"loadAnnotatedProperties",
"(",
"testCase",
",",
"hiveShellBuilder",
")",
";",
"loadAnnotatedSetupScripts",
"(",
"testCase",
",",
"hiveShellBuilder",
")",
";",
"// Build shell",
"final",
"HiveShellContainer",
"shell",
"=",
"hiveShellBuilder",
".",
"buildShell",
"(",
")",
";",
"// Set shell",
"shellSetter",
".",
"setShell",
"(",
"shell",
")",
";",
"if",
"(",
"shellSetter",
".",
"isAutoStart",
"(",
")",
")",
"{",
"shell",
".",
"start",
"(",
")",
";",
"}",
"return",
"shell",
";",
"}"
] | Traverses the test case annotations. Will inject a HiveShell in the test case that envelopes the HiveServer. | [
"Traverses",
"the",
"test",
"case",
"annotations",
".",
"Will",
"inject",
"a",
"HiveShell",
"in",
"the",
"test",
"case",
"that",
"envelopes",
"the",
"HiveServer",
"."
] | c8899237db6122127f16e3d8a740c1f8657c2ae3 | https://github.com/klarna/HiveRunner/blob/c8899237db6122127f16e3d8a740c1f8657c2ae3/src/main/java/com/klarna/hiverunner/StandaloneHiveRunner.java#L187-L221 |
162,602 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newInsert | public static Command newInsert(Object object,
String outIdentifier) {
return getCommandFactoryProvider().newInsert( object,
outIdentifier );
} | java | public static Command newInsert(Object object,
String outIdentifier) {
return getCommandFactoryProvider().newInsert( object,
outIdentifier );
} | [
"public",
"static",
"Command",
"newInsert",
"(",
"Object",
"object",
",",
"String",
"outIdentifier",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newInsert",
"(",
"object",
",",
"outIdentifier",
")",
";",
"}"
] | Inserts a new instance but references via the outIdentifier, which is returned as part of the ExecutionResults
@param object
@param outIdentifier
@return | [
"Inserts",
"a",
"new",
"instance",
"but",
"references",
"via",
"the",
"outIdentifier",
"which",
"is",
"returned",
"as",
"part",
"of",
"the",
"ExecutionResults"
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L69-L73 |
162,603 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newInsert | public static Command newInsert(Object object,
String outIdentifier,
boolean returnObject,
String entryPoint ) {
return getCommandFactoryProvider().newInsert( object,
outIdentifier,
returnObject,
entryPoint );
} | java | public static Command newInsert(Object object,
String outIdentifier,
boolean returnObject,
String entryPoint ) {
return getCommandFactoryProvider().newInsert( object,
outIdentifier,
returnObject,
entryPoint );
} | [
"public",
"static",
"Command",
"newInsert",
"(",
"Object",
"object",
",",
"String",
"outIdentifier",
",",
"boolean",
"returnObject",
",",
"String",
"entryPoint",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newInsert",
"(",
"object",
",",
"outIdentifier",
",",
"returnObject",
",",
"entryPoint",
")",
";",
"}"
] | Inserts a new instance but references via the outIdentifier, which is returned as part of the ExecutionResults
The outIdentifier can be null.
The entryPoint, which can also be null, specifies the entrypoint the object is inserted into.
@param object
@param outIdentifier
@param entryPoint
@return | [
"Inserts",
"a",
"new",
"instance",
"but",
"references",
"via",
"the",
"outIdentifier",
"which",
"is",
"returned",
"as",
"part",
"of",
"the",
"ExecutionResults",
"The",
"outIdentifier",
"can",
"be",
"null",
".",
"The",
"entryPoint",
"which",
"can",
"also",
"be",
"null",
"specifies",
"the",
"entrypoint",
"the",
"object",
"is",
"inserted",
"into",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L85-L93 |
162,604 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newInsertElements | public static Command newInsertElements(Collection objects, String outIdentifier, boolean returnObject, String entryPoint) {
return getCommandFactoryProvider().newInsertElements( objects, outIdentifier, returnObject, entryPoint );
} | java | public static Command newInsertElements(Collection objects, String outIdentifier, boolean returnObject, String entryPoint) {
return getCommandFactoryProvider().newInsertElements( objects, outIdentifier, returnObject, entryPoint );
} | [
"public",
"static",
"Command",
"newInsertElements",
"(",
"Collection",
"objects",
",",
"String",
"outIdentifier",
",",
"boolean",
"returnObject",
",",
"String",
"entryPoint",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newInsertElements",
"(",
"objects",
",",
"outIdentifier",
",",
"returnObject",
",",
"entryPoint",
")",
";",
"}"
] | Iterate and insert each of the elements of the Collection.
@param objects
The objects to insert
@param outIdentifier
Identifier to lookup the returned objects
@param returnObject
boolean to specify whether the inserted Collection is part of the ExecutionResults
@param entryPoint
Optional EntryPoint for the insertions
@return | [
"Iterate",
"and",
"insert",
"each",
"of",
"the",
"elements",
"of",
"the",
"Collection",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L120-L122 |
162,605 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newSetGlobal | public static Command newSetGlobal(String identifier,
Object object) {
return getCommandFactoryProvider().newSetGlobal( identifier,
object );
} | java | public static Command newSetGlobal(String identifier,
Object object) {
return getCommandFactoryProvider().newSetGlobal( identifier,
object );
} | [
"public",
"static",
"Command",
"newSetGlobal",
"(",
"String",
"identifier",
",",
"Object",
"object",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newSetGlobal",
"(",
"identifier",
",",
"object",
")",
";",
"}"
] | Sets the global. Does not add the global to the ExecutionResults.
@param identifier
The identifier of the global
@param object
The instance to be set as the global.
@return | [
"Sets",
"the",
"global",
".",
"Does",
"not",
"add",
"the",
"global",
"to",
"the",
"ExecutionResults",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L185-L189 |
162,606 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newGetGlobal | public static Command newGetGlobal(String identifier,
String outIdentifier) {
return getCommandFactoryProvider().newGetGlobal( identifier,
outIdentifier );
} | java | public static Command newGetGlobal(String identifier,
String outIdentifier) {
return getCommandFactoryProvider().newGetGlobal( identifier,
outIdentifier );
} | [
"public",
"static",
"Command",
"newGetGlobal",
"(",
"String",
"identifier",
",",
"String",
"outIdentifier",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newGetGlobal",
"(",
"identifier",
",",
"outIdentifier",
")",
";",
"}"
] | Gets the global and adds it ot the BatchExecutionresults using the alternative outIdentifier.
@param identifier
The identifier of the global
@param outIdentifier
The identifier used in the ExecutionResults to store the global.
@return | [
"Gets",
"the",
"global",
"and",
"adds",
"it",
"ot",
"the",
"BatchExecutionresults",
"using",
"the",
"alternative",
"outIdentifier",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L248-L252 |
162,607 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newStartProcess | public static Command newStartProcess(String processId,
Map<String, Object> parameters) {
return getCommandFactoryProvider().newStartProcess( processId,
parameters );
} | java | public static Command newStartProcess(String processId,
Map<String, Object> parameters) {
return getCommandFactoryProvider().newStartProcess( processId,
parameters );
} | [
"public",
"static",
"Command",
"newStartProcess",
"(",
"String",
"processId",
",",
"Map",
"<",
"String",
",",
"Object",
">",
"parameters",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newStartProcess",
"(",
"processId",
",",
"parameters",
")",
";",
"}"
] | Start a process using the given parameters.
@param processId
@param parameters
@return | [
"Start",
"a",
"process",
"using",
"the",
"given",
"parameters",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L283-L287 |
162,608 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newQuery | public static Command newQuery(String identifier,
String name) {
return getCommandFactoryProvider().newQuery( identifier,
name );
} | java | public static Command newQuery(String identifier,
String name) {
return getCommandFactoryProvider().newQuery( identifier,
name );
} | [
"public",
"static",
"Command",
"newQuery",
"(",
"String",
"identifier",
",",
"String",
"name",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newQuery",
"(",
"identifier",
",",
"name",
")",
";",
"}"
] | Executes a query. The query results will be added to the ExecutionResults using the
given identifier.
@param identifier
The identifier to be used for the results when added to the ExecutionResults
@param name
The name of the query to execute
@return | [
"Executes",
"a",
"query",
".",
"The",
"query",
"results",
"will",
"be",
"added",
"to",
"the",
"ExecutionResults",
"using",
"the",
"given",
"identifier",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L329-L334 |
162,609 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java | CommandFactory.newQuery | public static Command newQuery(String identifier,
String name,
Object[] arguments) {
return getCommandFactoryProvider().newQuery( identifier,
name,
arguments );
} | java | public static Command newQuery(String identifier,
String name,
Object[] arguments) {
return getCommandFactoryProvider().newQuery( identifier,
name,
arguments );
} | [
"public",
"static",
"Command",
"newQuery",
"(",
"String",
"identifier",
",",
"String",
"name",
",",
"Object",
"[",
"]",
"arguments",
")",
"{",
"return",
"getCommandFactoryProvider",
"(",
")",
".",
"newQuery",
"(",
"identifier",
",",
"name",
",",
"arguments",
")",
";",
"}"
] | Executes a query using the given parameters. The query results will be added to the
ExecutionResults using the given identifier.
@param identifier
The identifier to be used for the results when added to the ExecutionResults
@param name
The name of the query to execute
@param arguments
The arguments to be used for the query parameters
@return | [
"Executes",
"a",
"query",
"using",
"the",
"given",
"parameters",
".",
"The",
"query",
"results",
"will",
"be",
"added",
"to",
"the",
"ExecutionResults",
"using",
"the",
"given",
"identifier",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/command/CommandFactory.java#L348-L354 |
162,610 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/builder/KnowledgeBuilderFactory.java | KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration | public static KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration(Properties properties,
ClassLoader... classLoaders) {
return FactoryServiceHolder.factoryService.newKnowledgeBuilderConfiguration( properties, classLoaders );
} | java | public static KnowledgeBuilderConfiguration newKnowledgeBuilderConfiguration(Properties properties,
ClassLoader... classLoaders) {
return FactoryServiceHolder.factoryService.newKnowledgeBuilderConfiguration( properties, classLoaders );
} | [
"public",
"static",
"KnowledgeBuilderConfiguration",
"newKnowledgeBuilderConfiguration",
"(",
"Properties",
"properties",
",",
"ClassLoader",
"...",
"classLoaders",
")",
"{",
"return",
"FactoryServiceHolder",
".",
"factoryService",
".",
"newKnowledgeBuilderConfiguration",
"(",
"properties",
",",
"classLoaders",
")",
";",
"}"
] | Create a KnowledgeBuilderConfiguration on which properties can be set. Use
the given properties file and ClassLoader - either of which can be null.
@return
The KnowledgeBuilderConfiguration. | [
"Create",
"a",
"KnowledgeBuilderConfiguration",
"on",
"which",
"properties",
"can",
"be",
"set",
".",
"Use",
"the",
"given",
"properties",
"file",
"and",
"ClassLoader",
"-",
"either",
"of",
"which",
"can",
"be",
"null",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/builder/KnowledgeBuilderFactory.java#L84-L87 |
162,611 | kiegroup/droolsjbpm-knowledge | kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java | OSGiLocator.unregister | public static synchronized void unregister(final String serviceName,
final Callable<Class< ? >> factory) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null ) {
l.remove( factory );
}
}
} | java | public static synchronized void unregister(final String serviceName,
final Callable<Class< ? >> factory) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null ) {
l.remove( factory );
}
}
} | [
"public",
"static",
"synchronized",
"void",
"unregister",
"(",
"final",
"String",
"serviceName",
",",
"final",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
"factory",
")",
"{",
"if",
"(",
"serviceName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serviceName cannot be null\"",
")",
";",
"}",
"if",
"(",
"factories",
"!=",
"null",
")",
"{",
"List",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
"l",
"=",
"factories",
".",
"get",
"(",
"serviceName",
")",
";",
"if",
"(",
"l",
"!=",
"null",
")",
"{",
"l",
".",
"remove",
"(",
"factory",
")",
";",
"}",
"}",
"}"
] | Removes the given service provider factory from the set of
providers for the service.
@param serviceName
The fully qualified name of the service interface.
@param factory
A factory for creating a specific type of service
provider. May be <tt>null</tt> in which case this
method does nothing.
@throws IllegalArgumentException if serviceName is <tt>null</tt> | [
"Removes",
"the",
"given",
"service",
"provider",
"factory",
"from",
"the",
"set",
"of",
"providers",
"for",
"the",
"service",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java#L68-L79 |
162,612 | kiegroup/droolsjbpm-knowledge | kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java | OSGiLocator.register | public static synchronized void register(final String serviceName,
final Callable<Class< ? >> factory) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factory != null ) {
if ( factories == null ) {
factories = new HashMap<String, List<Callable<Class< ? >>>>();
}
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l == null ) {
l = new ArrayList<Callable<Class< ? >>>();
factories.put( serviceName,
l );
}
l.add( factory );
}
} | java | public static synchronized void register(final String serviceName,
final Callable<Class< ? >> factory) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factory != null ) {
if ( factories == null ) {
factories = new HashMap<String, List<Callable<Class< ? >>>>();
}
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l == null ) {
l = new ArrayList<Callable<Class< ? >>>();
factories.put( serviceName,
l );
}
l.add( factory );
}
} | [
"public",
"static",
"synchronized",
"void",
"register",
"(",
"final",
"String",
"serviceName",
",",
"final",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
"factory",
")",
"{",
"if",
"(",
"serviceName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serviceName cannot be null\"",
")",
";",
"}",
"if",
"(",
"factory",
"!=",
"null",
")",
"{",
"if",
"(",
"factories",
"==",
"null",
")",
"{",
"factories",
"=",
"new",
"HashMap",
"<",
"String",
",",
"List",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
">",
"(",
")",
";",
"}",
"List",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
"l",
"=",
"factories",
".",
"get",
"(",
"serviceName",
")",
";",
"if",
"(",
"l",
"==",
"null",
")",
"{",
"l",
"=",
"new",
"ArrayList",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
"(",
")",
";",
"factories",
".",
"put",
"(",
"serviceName",
",",
"l",
")",
";",
"}",
"l",
".",
"add",
"(",
"factory",
")",
";",
"}",
"}"
] | Adds the given service provider factory to the set of
providers for the service.
@param serviceName
The fully qualified name of the service interface.
@param factory
A factory for creating a specific type of service
provider. May be <tt>null</tt> in which case this
method does nothing.
@throws IllegalArgumentException if serviceName is <tt>null</tt> | [
"Adds",
"the",
"given",
"service",
"provider",
"factory",
"to",
"the",
"set",
"of",
"providers",
"for",
"the",
"service",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java#L93-L110 |
162,613 | kiegroup/droolsjbpm-knowledge | kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java | OSGiLocator.locate | public static synchronized Class< ? > locate(final String serviceName) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null && !l.isEmpty() ) {
Callable<Class< ? >> c = l.get( l.size() - 1 );
try {
return c.call();
} catch ( Exception e ) {
}
}
}
return null;
} | java | public static synchronized Class< ? > locate(final String serviceName) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null && !l.isEmpty() ) {
Callable<Class< ? >> c = l.get( l.size() - 1 );
try {
return c.call();
} catch ( Exception e ) {
}
}
}
return null;
} | [
"public",
"static",
"synchronized",
"Class",
"<",
"?",
">",
"locate",
"(",
"final",
"String",
"serviceName",
")",
"{",
"if",
"(",
"serviceName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serviceName cannot be null\"",
")",
";",
"}",
"if",
"(",
"factories",
"!=",
"null",
")",
"{",
"List",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
"l",
"=",
"factories",
".",
"get",
"(",
"serviceName",
")",
";",
"if",
"(",
"l",
"!=",
"null",
"&&",
"!",
"l",
".",
"isEmpty",
"(",
")",
")",
"{",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
"c",
"=",
"l",
".",
"get",
"(",
"l",
".",
"size",
"(",
")",
"-",
"1",
")",
";",
"try",
"{",
"return",
"c",
".",
"call",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds the preferred provider for the given service. The preferred
provider is the last one added to the set of providers.
@param serviceName
The fully qualified name of the service interface.
@return
The last provider added for the service if any exists.
Otherwise, it returns <tt>null</tt>.
@throws IllegalArgumentException if serviceName is <tt>null</tt> | [
"Finds",
"the",
"preferred",
"provider",
"for",
"the",
"given",
"service",
".",
"The",
"preferred",
"provider",
"is",
"the",
"last",
"one",
"added",
"to",
"the",
"set",
"of",
"providers",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java#L123-L138 |
162,614 | kiegroup/droolsjbpm-knowledge | kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java | OSGiLocator.locateAll | public static synchronized List<Class< ? >> locateAll(final String serviceName) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
List<Class< ? >> classes = new ArrayList<Class< ? >>();
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null ) {
for ( Callable<Class< ? >> c : l ) {
try {
classes.add( c.call() );
} catch ( Exception e ) {
}
}
}
}
return classes;
} | java | public static synchronized List<Class< ? >> locateAll(final String serviceName) {
if ( serviceName == null ) {
throw new IllegalArgumentException( "serviceName cannot be null" );
}
List<Class< ? >> classes = new ArrayList<Class< ? >>();
if ( factories != null ) {
List<Callable<Class< ? >>> l = factories.get( serviceName );
if ( l != null ) {
for ( Callable<Class< ? >> c : l ) {
try {
classes.add( c.call() );
} catch ( Exception e ) {
}
}
}
}
return classes;
} | [
"public",
"static",
"synchronized",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"locateAll",
"(",
"final",
"String",
"serviceName",
")",
"{",
"if",
"(",
"serviceName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"serviceName cannot be null\"",
")",
";",
"}",
"List",
"<",
"Class",
"<",
"?",
">",
">",
"classes",
"=",
"new",
"ArrayList",
"<",
"Class",
"<",
"?",
">",
">",
"(",
")",
";",
"if",
"(",
"factories",
"!=",
"null",
")",
"{",
"List",
"<",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
">",
"l",
"=",
"factories",
".",
"get",
"(",
"serviceName",
")",
";",
"if",
"(",
"l",
"!=",
"null",
")",
"{",
"for",
"(",
"Callable",
"<",
"Class",
"<",
"?",
">",
">",
"c",
":",
"l",
")",
"{",
"try",
"{",
"classes",
".",
"add",
"(",
"c",
".",
"call",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"}",
"}",
"return",
"classes",
";",
"}"
] | Finds all providers for the given service.
@param serviceName
The fully qualified name of the service interface.
@return
The ordered set of providers for the service if any exists.
Otherwise, it returns an empty list.
@throws IllegalArgumentException if serviceName is <tt>null</tt> | [
"Finds",
"all",
"providers",
"for",
"the",
"given",
"service",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-api/src/main/java/org/kie/api/internal/utils/OSGiLocator.java#L150-L167 |
162,615 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/logger/KnowledgeRuntimeLoggerFactory.java | KnowledgeRuntimeLoggerFactory.newFileLogger | public static KieRuntimeLogger newFileLogger(KieRuntimeEventManager session,
String fileName) {
return getKnowledgeRuntimeLoggerProvider().newFileLogger( session,
fileName );
} | java | public static KieRuntimeLogger newFileLogger(KieRuntimeEventManager session,
String fileName) {
return getKnowledgeRuntimeLoggerProvider().newFileLogger( session,
fileName );
} | [
"public",
"static",
"KieRuntimeLogger",
"newFileLogger",
"(",
"KieRuntimeEventManager",
"session",
",",
"String",
"fileName",
")",
"{",
"return",
"getKnowledgeRuntimeLoggerProvider",
"(",
")",
".",
"newFileLogger",
"(",
"session",
",",
"fileName",
")",
";",
"}"
] | Creates a file logger in the current thread. The file is in XML format, suitable for interpretation by Eclipse's Drools Audit View
or other tools. Note that while events are written as they happen, the file will not be flushed until it is closed or the underlying
file buffer is filled. If you need real time logging then use a Console Logger or a Threaded File Logger.
@param session
@param fileName - .log is appended to this.
@return | [
"Creates",
"a",
"file",
"logger",
"in",
"the",
"current",
"thread",
".",
"The",
"file",
"is",
"in",
"XML",
"format",
"suitable",
"for",
"interpretation",
"by",
"Eclipse",
"s",
"Drools",
"Audit",
"View",
"or",
"other",
"tools",
".",
"Note",
"that",
"while",
"events",
"are",
"written",
"as",
"they",
"happen",
"the",
"file",
"will",
"not",
"be",
"flushed",
"until",
"it",
"is",
"closed",
"or",
"the",
"underlying",
"file",
"buffer",
"is",
"filled",
".",
"If",
"you",
"need",
"real",
"time",
"logging",
"then",
"use",
"a",
"Console",
"Logger",
"or",
"a",
"Threaded",
"File",
"Logger",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/logger/KnowledgeRuntimeLoggerFactory.java#L52-L56 |
162,616 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorIO.java | DeploymentDescriptorIO.toXml | public static String toXml(DeploymentDescriptor descriptor) {
try {
Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.jboss.org/jbpm deployment-descriptor.xsd");
marshaller.setSchema(schema);
StringWriter stringWriter = new StringWriter();
// clone the object and cleanup transients
DeploymentDescriptor clone = ((DeploymentDescriptorImpl) descriptor).clearClone();
marshaller.marshal(clone, stringWriter);
String output = stringWriter.toString();
return output;
} catch (Exception e) {
throw new RuntimeException("Unable to generate xml from deployment descriptor", e);
}
} | java | public static String toXml(DeploymentDescriptor descriptor) {
try {
Marshaller marshaller = getContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.jboss.org/jbpm deployment-descriptor.xsd");
marshaller.setSchema(schema);
StringWriter stringWriter = new StringWriter();
// clone the object and cleanup transients
DeploymentDescriptor clone = ((DeploymentDescriptorImpl) descriptor).clearClone();
marshaller.marshal(clone, stringWriter);
String output = stringWriter.toString();
return output;
} catch (Exception e) {
throw new RuntimeException("Unable to generate xml from deployment descriptor", e);
}
} | [
"public",
"static",
"String",
"toXml",
"(",
"DeploymentDescriptor",
"descriptor",
")",
"{",
"try",
"{",
"Marshaller",
"marshaller",
"=",
"getContext",
"(",
")",
".",
"createMarshaller",
"(",
")",
";",
"marshaller",
".",
"setProperty",
"(",
"Marshaller",
".",
"JAXB_FORMATTED_OUTPUT",
",",
"Boolean",
".",
"TRUE",
")",
";",
"marshaller",
".",
"setProperty",
"(",
"Marshaller",
".",
"JAXB_SCHEMA_LOCATION",
",",
"\"http://www.jboss.org/jbpm deployment-descriptor.xsd\"",
")",
";",
"marshaller",
".",
"setSchema",
"(",
"schema",
")",
";",
"StringWriter",
"stringWriter",
"=",
"new",
"StringWriter",
"(",
")",
";",
"// clone the object and cleanup transients",
"DeploymentDescriptor",
"clone",
"=",
"(",
"(",
"DeploymentDescriptorImpl",
")",
"descriptor",
")",
".",
"clearClone",
"(",
")",
";",
"marshaller",
".",
"marshal",
"(",
"clone",
",",
"stringWriter",
")",
";",
"String",
"output",
"=",
"stringWriter",
".",
"toString",
"(",
")",
";",
"return",
"output",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unable to generate xml from deployment descriptor\"",
",",
"e",
")",
";",
"}",
"}"
] | Serializes descriptor instance to XML
@param descriptor descriptor to be serialized
@return xml representation of descriptor as string | [
"Serializes",
"descriptor",
"instance",
"to",
"XML"
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/runtime/manager/deploy/DeploymentDescriptorIO.java#L68-L87 |
162,617 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/runtime/conf/ObjectModelResolverProvider.java | ObjectModelResolverProvider.getResolvers | public static List<ObjectModelResolver> getResolvers() {
if (resolvers == null) {
synchronized (serviceLoader) {
if (resolvers == null) {
List<ObjectModelResolver> foundResolvers = new ArrayList<ObjectModelResolver>();
for (ObjectModelResolver resolver : serviceLoader) {
foundResolvers.add(resolver);
}
resolvers = foundResolvers;
}
}
}
return resolvers;
} | java | public static List<ObjectModelResolver> getResolvers() {
if (resolvers == null) {
synchronized (serviceLoader) {
if (resolvers == null) {
List<ObjectModelResolver> foundResolvers = new ArrayList<ObjectModelResolver>();
for (ObjectModelResolver resolver : serviceLoader) {
foundResolvers.add(resolver);
}
resolvers = foundResolvers;
}
}
}
return resolvers;
} | [
"public",
"static",
"List",
"<",
"ObjectModelResolver",
">",
"getResolvers",
"(",
")",
"{",
"if",
"(",
"resolvers",
"==",
"null",
")",
"{",
"synchronized",
"(",
"serviceLoader",
")",
"{",
"if",
"(",
"resolvers",
"==",
"null",
")",
"{",
"List",
"<",
"ObjectModelResolver",
">",
"foundResolvers",
"=",
"new",
"ArrayList",
"<",
"ObjectModelResolver",
">",
"(",
")",
";",
"for",
"(",
"ObjectModelResolver",
"resolver",
":",
"serviceLoader",
")",
"{",
"foundResolvers",
".",
"add",
"(",
"resolver",
")",
";",
"}",
"resolvers",
"=",
"foundResolvers",
";",
"}",
"}",
"}",
"return",
"resolvers",
";",
"}"
] | Returns all found resolvers
@return | [
"Returns",
"all",
"found",
"resolvers"
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/runtime/conf/ObjectModelResolverProvider.java#L36-L50 |
162,618 | kiegroup/droolsjbpm-knowledge | kie-internal/src/main/java/org/kie/internal/runtime/conf/ObjectModelResolverProvider.java | ObjectModelResolverProvider.get | public static ObjectModelResolver get(String resolverId) {
List<ObjectModelResolver> resolvers = getResolvers();
for (ObjectModelResolver resolver : resolvers) {
if (resolver.accept(resolverId)) {
return resolver;
}
}
return null;
} | java | public static ObjectModelResolver get(String resolverId) {
List<ObjectModelResolver> resolvers = getResolvers();
for (ObjectModelResolver resolver : resolvers) {
if (resolver.accept(resolverId)) {
return resolver;
}
}
return null;
} | [
"public",
"static",
"ObjectModelResolver",
"get",
"(",
"String",
"resolverId",
")",
"{",
"List",
"<",
"ObjectModelResolver",
">",
"resolvers",
"=",
"getResolvers",
"(",
")",
";",
"for",
"(",
"ObjectModelResolver",
"resolver",
":",
"resolvers",
")",
"{",
"if",
"(",
"resolver",
".",
"accept",
"(",
"resolverId",
")",
")",
"{",
"return",
"resolver",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns first resolver that accepts the given resolverId.
In case none is found null is returned.
@param resolverId identifier of the resolver
@return found resolver or null otherwise | [
"Returns",
"first",
"resolver",
"that",
"accepts",
"the",
"given",
"resolverId",
".",
"In",
"case",
"none",
"is",
"found",
"null",
"is",
"returned",
"."
] | fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5 | https://github.com/kiegroup/droolsjbpm-knowledge/blob/fbe6de817c9f27cd4f6ef07e808e5c7bc946d4e5/kie-internal/src/main/java/org/kie/internal/runtime/conf/ObjectModelResolverProvider.java#L58-L68 |
162,619 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/QueuePoller.java | QueuePoller.reset | void reset()
{
if (!hasStopped)
{
throw new IllegalStateException("cannot reset a non stopped queue poller");
}
hasStopped = false;
run = true;
lastLoop = null;
loop = new Semaphore(0);
} | java | void reset()
{
if (!hasStopped)
{
throw new IllegalStateException("cannot reset a non stopped queue poller");
}
hasStopped = false;
run = true;
lastLoop = null;
loop = new Semaphore(0);
} | [
"void",
"reset",
"(",
")",
"{",
"if",
"(",
"!",
"hasStopped",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"cannot reset a non stopped queue poller\"",
")",
";",
"}",
"hasStopped",
"=",
"false",
";",
"run",
"=",
"true",
";",
"lastLoop",
"=",
"null",
";",
"loop",
"=",
"new",
"Semaphore",
"(",
"0",
")",
";",
"}"
] | Will make the thread ready to run once again after it has stopped. | [
"Will",
"make",
"the",
"thread",
"ready",
"to",
"run",
"once",
"again",
"after",
"it",
"has",
"stopped",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/QueuePoller.java#L87-L97 |
162,620 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/QueuePoller.java | QueuePoller.releaseResources | void releaseResources(JobInstance ji)
{
this.peremption.remove(ji.getId());
this.actualNbThread.decrementAndGet();
for (ResourceManagerBase rm : this.resourceManagers)
{
rm.releaseResource(ji);
}
if (!this.strictPollingPeriod)
{
// Force a new loop at once. This makes queues more fluid.
loop.release(1);
}
this.engine.signalEndOfRun();
} | java | void releaseResources(JobInstance ji)
{
this.peremption.remove(ji.getId());
this.actualNbThread.decrementAndGet();
for (ResourceManagerBase rm : this.resourceManagers)
{
rm.releaseResource(ji);
}
if (!this.strictPollingPeriod)
{
// Force a new loop at once. This makes queues more fluid.
loop.release(1);
}
this.engine.signalEndOfRun();
} | [
"void",
"releaseResources",
"(",
"JobInstance",
"ji",
")",
"{",
"this",
".",
"peremption",
".",
"remove",
"(",
"ji",
".",
"getId",
"(",
")",
")",
";",
"this",
".",
"actualNbThread",
".",
"decrementAndGet",
"(",
")",
";",
"for",
"(",
"ResourceManagerBase",
"rm",
":",
"this",
".",
"resourceManagers",
")",
"{",
"rm",
".",
"releaseResource",
"(",
"ji",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"strictPollingPeriod",
")",
"{",
"// Force a new loop at once. This makes queues more fluid.",
"loop",
".",
"release",
"(",
"1",
")",
";",
"}",
"this",
".",
"engine",
".",
"signalEndOfRun",
"(",
")",
";",
"}"
] | Called when a payload thread has ended. This also notifies the poller to poll once again. | [
"Called",
"when",
"a",
"payload",
"thread",
"has",
"ended",
".",
"This",
"also",
"notifies",
"the",
"poller",
"to",
"poll",
"once",
"again",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/QueuePoller.java#L409-L425 |
162,621 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngineFactory.java | JqmEngineFactory.startEngine | public static JqmEngineOperations startEngine(String name, JqmEngineHandler handler)
{
JqmEngine e = new JqmEngine();
e.start(name, handler);
return e;
} | java | public static JqmEngineOperations startEngine(String name, JqmEngineHandler handler)
{
JqmEngine e = new JqmEngine();
e.start(name, handler);
return e;
} | [
"public",
"static",
"JqmEngineOperations",
"startEngine",
"(",
"String",
"name",
",",
"JqmEngineHandler",
"handler",
")",
"{",
"JqmEngine",
"e",
"=",
"new",
"JqmEngine",
"(",
")",
";",
"e",
".",
"start",
"(",
"name",
",",
"handler",
")",
";",
"return",
"e",
";",
"}"
] | Creates and start an engine representing the node named as the given parameter.
@param name
name of the node, as present in the configuration (case sensitive)
@param handler
can be null. A set of callbacks hooked on different engine life cycle events.
@return an object allowing to stop the engine. | [
"Creates",
"and",
"start",
"an",
"engine",
"representing",
"the",
"node",
"named",
"as",
"the",
"given",
"parameter",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngineFactory.java#L23-L28 |
162,622 | enioka/jqm | jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ErrorHandler.java | ErrorHandler.toResponse | @Override
public Response toResponse(ErrorDto e)
{
// String type = headers.getContentType() == null ? MediaType.APPLICATION_JSON : headers.getContentType();
return Response.status(e.httpStatus).entity(e).type(MediaType.APPLICATION_JSON).build();
} | java | @Override
public Response toResponse(ErrorDto e)
{
// String type = headers.getContentType() == null ? MediaType.APPLICATION_JSON : headers.getContentType();
return Response.status(e.httpStatus).entity(e).type(MediaType.APPLICATION_JSON).build();
} | [
"@",
"Override",
"public",
"Response",
"toResponse",
"(",
"ErrorDto",
"e",
")",
"{",
"// String type = headers.getContentType() == null ? MediaType.APPLICATION_JSON : headers.getContentType();",
"return",
"Response",
".",
"status",
"(",
"e",
".",
"httpStatus",
")",
".",
"entity",
"(",
"e",
")",
".",
"type",
"(",
"MediaType",
".",
"APPLICATION_JSON",
")",
".",
"build",
"(",
")",
";",
"}"
] | private HttpServletResponse headers; | [
"private",
"HttpServletResponse",
"headers",
";"
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ErrorHandler.java#L29-L34 |
162,623 | enioka/jqm | jqm-all/jqm-client/jqm-api-client-core/src/main/java/com/enioka/jqm/api/JqmClientFactory.java | JqmClientFactory.getClient | public static JqmClient getClient(String name, Properties p, boolean cached)
{
Properties p2 = null;
if (binder == null)
{
bind();
}
if (p == null)
{
p2 = props;
}
else
{
p2 = new Properties(props);
p2.putAll(p);
}
return binder.getClientFactory().getClient(name, p2, cached);
} | java | public static JqmClient getClient(String name, Properties p, boolean cached)
{
Properties p2 = null;
if (binder == null)
{
bind();
}
if (p == null)
{
p2 = props;
}
else
{
p2 = new Properties(props);
p2.putAll(p);
}
return binder.getClientFactory().getClient(name, p2, cached);
} | [
"public",
"static",
"JqmClient",
"getClient",
"(",
"String",
"name",
",",
"Properties",
"p",
",",
"boolean",
"cached",
")",
"{",
"Properties",
"p2",
"=",
"null",
";",
"if",
"(",
"binder",
"==",
"null",
")",
"{",
"bind",
"(",
")",
";",
"}",
"if",
"(",
"p",
"==",
"null",
")",
"{",
"p2",
"=",
"props",
";",
"}",
"else",
"{",
"p2",
"=",
"new",
"Properties",
"(",
"props",
")",
";",
"p2",
".",
"putAll",
"(",
"p",
")",
";",
"}",
"return",
"binder",
".",
"getClientFactory",
"(",
")",
".",
"getClient",
"(",
"name",
",",
"p2",
",",
"cached",
")",
";",
"}"
] | Return a new client that may be cached or not. Given properties are always use when not cached, and only used at creation time for
cached clients.
@param name
if null, default client. Otherwise, helpful to retrieve cached clients later.
@param p
a set of properties. Implementation specific. Unknown properties are silently ignored.
@param cached
if false, the client will not be cached and subsequent calls with the same name will return different objects. | [
"Return",
"a",
"new",
"client",
"that",
"may",
"be",
"cached",
"or",
"not",
".",
"Given",
"properties",
"are",
"always",
"use",
"when",
"not",
"cached",
"and",
"only",
"used",
"at",
"creation",
"time",
"for",
"cached",
"clients",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-client/jqm-api-client-core/src/main/java/com/enioka/jqm/api/JqmClientFactory.java#L157-L174 |
162,624 | enioka/jqm | jqm-all/jqm-admin/src/main/java/com/enioka/api/admin/ScheduledJob.java | ScheduledJob.create | public static ScheduledJob create(String cronExpression)
{
ScheduledJob res = new ScheduledJob();
res.cronExpression = cronExpression;
return res;
} | java | public static ScheduledJob create(String cronExpression)
{
ScheduledJob res = new ScheduledJob();
res.cronExpression = cronExpression;
return res;
} | [
"public",
"static",
"ScheduledJob",
"create",
"(",
"String",
"cronExpression",
")",
"{",
"ScheduledJob",
"res",
"=",
"new",
"ScheduledJob",
"(",
")",
";",
"res",
".",
"cronExpression",
"=",
"cronExpression",
";",
"return",
"res",
";",
"}"
] | Fluent API builder.
@param cronExpression
@return | [
"Fluent",
"API",
"builder",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-admin/src/main/java/com/enioka/api/admin/ScheduledJob.java#L37-L42 |
162,625 | enioka/jqm | jqm-all/jqm-xml/src/main/java/com/enioka/jqm/tools/XmlQueueExporter.java | XmlQueueExporter.export | static void export(String path, String queueName, DbConn cnx) throws JqmXmlException
{
// Argument tests
if (queueName == null)
{
throw new IllegalArgumentException("queue name cannot be null");
}
if (cnx == null)
{
throw new IllegalArgumentException("database connection cannot be null");
}
Queue q = CommonXml.findQueue(queueName, cnx);
if (q == null)
{
throw new IllegalArgumentException("there is no queue named " + queueName);
}
List<Queue> l = new ArrayList<>();
l.add(q);
export(path, l, cnx);
} | java | static void export(String path, String queueName, DbConn cnx) throws JqmXmlException
{
// Argument tests
if (queueName == null)
{
throw new IllegalArgumentException("queue name cannot be null");
}
if (cnx == null)
{
throw new IllegalArgumentException("database connection cannot be null");
}
Queue q = CommonXml.findQueue(queueName, cnx);
if (q == null)
{
throw new IllegalArgumentException("there is no queue named " + queueName);
}
List<Queue> l = new ArrayList<>();
l.add(q);
export(path, l, cnx);
} | [
"static",
"void",
"export",
"(",
"String",
"path",
",",
"String",
"queueName",
",",
"DbConn",
"cnx",
")",
"throws",
"JqmXmlException",
"{",
"// Argument tests",
"if",
"(",
"queueName",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"queue name cannot be null\"",
")",
";",
"}",
"if",
"(",
"cnx",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"database connection cannot be null\"",
")",
";",
"}",
"Queue",
"q",
"=",
"CommonXml",
".",
"findQueue",
"(",
"queueName",
",",
"cnx",
")",
";",
"if",
"(",
"q",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"there is no queue named \"",
"+",
"queueName",
")",
";",
"}",
"List",
"<",
"Queue",
">",
"l",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"l",
".",
"add",
"(",
"q",
")",
";",
"export",
"(",
"path",
",",
"l",
",",
"cnx",
")",
";",
"}"
] | Exports a single queue to an XML file. | [
"Exports",
"a",
"single",
"queue",
"to",
"an",
"XML",
"file",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-xml/src/main/java/com/enioka/jqm/tools/XmlQueueExporter.java#L41-L61 |
162,626 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java | Helpers.createMessage | static void createMessage(String textMessage, JobInstance jobInstance, DbConn cnx)
{
cnx.runUpdate("message_insert", jobInstance.getId(), textMessage);
} | java | static void createMessage(String textMessage, JobInstance jobInstance, DbConn cnx)
{
cnx.runUpdate("message_insert", jobInstance.getId(), textMessage);
} | [
"static",
"void",
"createMessage",
"(",
"String",
"textMessage",
",",
"JobInstance",
"jobInstance",
",",
"DbConn",
"cnx",
")",
"{",
"cnx",
".",
"runUpdate",
"(",
"\"message_insert\"",
",",
"jobInstance",
".",
"getId",
"(",
")",
",",
"textMessage",
")",
";",
"}"
] | Create a text message that will be stored in the database. Must be called inside a transaction. | [
"Create",
"a",
"text",
"message",
"that",
"will",
"be",
"stored",
"in",
"the",
"database",
".",
"Must",
"be",
"called",
"inside",
"a",
"transaction",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java#L190-L193 |
162,627 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java | Helpers.createDeliverable | static int createDeliverable(String path, String originalFileName, String fileFamily, Integer jobId, DbConn cnx)
{
QueryResult qr = cnx.runUpdate("deliverable_insert", fileFamily, path, jobId, originalFileName, UUID.randomUUID().toString());
return qr.getGeneratedId();
} | java | static int createDeliverable(String path, String originalFileName, String fileFamily, Integer jobId, DbConn cnx)
{
QueryResult qr = cnx.runUpdate("deliverable_insert", fileFamily, path, jobId, originalFileName, UUID.randomUUID().toString());
return qr.getGeneratedId();
} | [
"static",
"int",
"createDeliverable",
"(",
"String",
"path",
",",
"String",
"originalFileName",
",",
"String",
"fileFamily",
",",
"Integer",
"jobId",
",",
"DbConn",
"cnx",
")",
"{",
"QueryResult",
"qr",
"=",
"cnx",
".",
"runUpdate",
"(",
"\"deliverable_insert\"",
",",
"fileFamily",
",",
"path",
",",
"jobId",
",",
"originalFileName",
",",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"return",
"qr",
".",
"getGeneratedId",
"(",
")",
";",
"}"
] | Create a Deliverable inside the database that will track a file created by a JobInstance Must be called from inside a transaction
@param path
FilePath (relative to a root directory - cf. Node)
@param originalFileName
FileName
@param fileFamily
File family (may be null). E.g.: "daily report"
@param jobId
Job Instance ID
@param cnx
the DbConn to use. | [
"Create",
"a",
"Deliverable",
"inside",
"the",
"database",
"that",
"will",
"track",
"a",
"file",
"created",
"by",
"a",
"JobInstance",
"Must",
"be",
"called",
"from",
"inside",
"a",
"transaction"
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java#L209-L213 |
162,628 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java | Helpers.initSingleParam | static void initSingleParam(String key, String initValue, DbConn cnx)
{
try
{
cnx.runSelectSingle("globalprm_select_by_key", 2, String.class, key);
return;
}
catch (NoResultException e)
{
GlobalParameter.create(cnx, key, initValue);
}
catch (NonUniqueResultException e)
{
// It exists! Nothing to do...
}
} | java | static void initSingleParam(String key, String initValue, DbConn cnx)
{
try
{
cnx.runSelectSingle("globalprm_select_by_key", 2, String.class, key);
return;
}
catch (NoResultException e)
{
GlobalParameter.create(cnx, key, initValue);
}
catch (NonUniqueResultException e)
{
// It exists! Nothing to do...
}
} | [
"static",
"void",
"initSingleParam",
"(",
"String",
"key",
",",
"String",
"initValue",
",",
"DbConn",
"cnx",
")",
"{",
"try",
"{",
"cnx",
".",
"runSelectSingle",
"(",
"\"globalprm_select_by_key\"",
",",
"2",
",",
"String",
".",
"class",
",",
"key",
")",
";",
"return",
";",
"}",
"catch",
"(",
"NoResultException",
"e",
")",
"{",
"GlobalParameter",
".",
"create",
"(",
"cnx",
",",
"key",
",",
"initValue",
")",
";",
"}",
"catch",
"(",
"NonUniqueResultException",
"e",
")",
"{",
"// It exists! Nothing to do...",
"}",
"}"
] | Checks if a parameter exists. If it exists, it is left untouched. If it doesn't, it is created. Only works for parameters which key
is unique. Must be called from within an open transaction. | [
"Checks",
"if",
"a",
"parameter",
"exists",
".",
"If",
"it",
"exists",
"it",
"is",
"left",
"untouched",
".",
"If",
"it",
"doesn",
"t",
"it",
"is",
"created",
".",
"Only",
"works",
"for",
"parameters",
"which",
"key",
"is",
"unique",
".",
"Must",
"be",
"called",
"from",
"within",
"an",
"open",
"transaction",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java#L219-L234 |
162,629 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java | Helpers.setSingleParam | static void setSingleParam(String key, String value, DbConn cnx)
{
QueryResult r = cnx.runUpdate("globalprm_update_value_by_key", value, key);
if (r.nbUpdated == 0)
{
cnx.runUpdate("globalprm_insert", key, value);
}
cnx.commit();
} | java | static void setSingleParam(String key, String value, DbConn cnx)
{
QueryResult r = cnx.runUpdate("globalprm_update_value_by_key", value, key);
if (r.nbUpdated == 0)
{
cnx.runUpdate("globalprm_insert", key, value);
}
cnx.commit();
} | [
"static",
"void",
"setSingleParam",
"(",
"String",
"key",
",",
"String",
"value",
",",
"DbConn",
"cnx",
")",
"{",
"QueryResult",
"r",
"=",
"cnx",
".",
"runUpdate",
"(",
"\"globalprm_update_value_by_key\"",
",",
"value",
",",
"key",
")",
";",
"if",
"(",
"r",
".",
"nbUpdated",
"==",
"0",
")",
"{",
"cnx",
".",
"runUpdate",
"(",
"\"globalprm_insert\"",
",",
"key",
",",
"value",
")",
";",
"}",
"cnx",
".",
"commit",
"(",
")",
";",
"}"
] | Checks if a parameter exists. If it exists, it is updated. If it doesn't, it is created. Only works for parameters which key is
unique. Will create a transaction on the given entity manager. | [
"Checks",
"if",
"a",
"parameter",
"exists",
".",
"If",
"it",
"exists",
"it",
"is",
"updated",
".",
"If",
"it",
"doesn",
"t",
"it",
"is",
"created",
".",
"Only",
"works",
"for",
"parameters",
"which",
"key",
"is",
"unique",
".",
"Will",
"create",
"a",
"transaction",
"on",
"the",
"given",
"entity",
"manager",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/Helpers.java#L240-L248 |
162,630 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/DbConn.java | DbConn.close | public void close()
{
if (transac_open)
{
try
{
this._cnx.rollback();
}
catch (Exception e)
{
// Ignore.
}
}
for (Statement s : toClose)
{
closeQuietly(s);
}
toClose.clear();
closeQuietly(_cnx);
_cnx = null;
} | java | public void close()
{
if (transac_open)
{
try
{
this._cnx.rollback();
}
catch (Exception e)
{
// Ignore.
}
}
for (Statement s : toClose)
{
closeQuietly(s);
}
toClose.clear();
closeQuietly(_cnx);
_cnx = null;
} | [
"public",
"void",
"close",
"(",
")",
"{",
"if",
"(",
"transac_open",
")",
"{",
"try",
"{",
"this",
".",
"_cnx",
".",
"rollback",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Ignore.",
"}",
"}",
"for",
"(",
"Statement",
"s",
":",
"toClose",
")",
"{",
"closeQuietly",
"(",
"s",
")",
";",
"}",
"toClose",
".",
"clear",
"(",
")",
";",
"closeQuietly",
"(",
"_cnx",
")",
";",
"_cnx",
"=",
"null",
";",
"}"
] | Close all JDBC objects related to this connection. | [
"Close",
"all",
"JDBC",
"objects",
"related",
"to",
"this",
"connection",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/DbConn.java#L407-L429 |
162,631 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/RunningJobInstanceManager.java | RunningJobInstanceManager.killAll | void killAll()
{
for (RjiRegistration reg : this.instancesById.values().toArray(new RjiRegistration[] {}))
{
reg.rji.handleInstruction(Instruction.KILL);
}
} | java | void killAll()
{
for (RjiRegistration reg : this.instancesById.values().toArray(new RjiRegistration[] {}))
{
reg.rji.handleInstruction(Instruction.KILL);
}
} | [
"void",
"killAll",
"(",
")",
"{",
"for",
"(",
"RjiRegistration",
"reg",
":",
"this",
".",
"instancesById",
".",
"values",
"(",
")",
".",
"toArray",
"(",
"new",
"RjiRegistration",
"[",
"]",
"{",
"}",
")",
")",
"{",
"reg",
".",
"rji",
".",
"handleInstruction",
"(",
"Instruction",
".",
"KILL",
")",
";",
"}",
"}"
] | Send a kill signal to all running instances and return as soon as the signal is sent. | [
"Send",
"a",
"kill",
"signal",
"to",
"all",
"running",
"instances",
"and",
"return",
"as",
"soon",
"as",
"the",
"signal",
"is",
"sent",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/RunningJobInstanceManager.java#L78-L84 |
162,632 | enioka/jqm | jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ServiceClient.java | ServiceClient.setJobQueue | @Override
public void setJobQueue(int jobId, Queue queue)
{
JqmClientFactory.getClient().setJobQueue(jobId, queue);
} | java | @Override
public void setJobQueue(int jobId, Queue queue)
{
JqmClientFactory.getClient().setJobQueue(jobId, queue);
} | [
"@",
"Override",
"public",
"void",
"setJobQueue",
"(",
"int",
"jobId",
",",
"Queue",
"queue",
")",
"{",
"JqmClientFactory",
".",
"getClient",
"(",
")",
".",
"setJobQueue",
"(",
"jobId",
",",
"queue",
")",
";",
"}"
] | No need to expose. Client side work. | [
"No",
"need",
"to",
"expose",
".",
"Client",
"side",
"work",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ServiceClient.java#L173-L177 |
162,633 | enioka/jqm | jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ServiceClient.java | ServiceClient.getJobs | @Override
public List<JobInstance> getJobs(Query query)
{
return JqmClientFactory.getClient().getJobs(query);
} | java | @Override
public List<JobInstance> getJobs(Query query)
{
return JqmClientFactory.getClient().getJobs(query);
} | [
"@",
"Override",
"public",
"List",
"<",
"JobInstance",
">",
"getJobs",
"(",
"Query",
"query",
")",
"{",
"return",
"JqmClientFactory",
".",
"getClient",
"(",
")",
".",
"getJobs",
"(",
"query",
")",
";",
"}"
] | Not exposed directly - the Query object passed as parameter actually contains results... | [
"Not",
"exposed",
"directly",
"-",
"the",
"Query",
"object",
"passed",
"as",
"parameter",
"actually",
"contains",
"results",
"..."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-ws/src/main/java/com/enioka/jqm/api/ServiceClient.java#L275-L279 |
162,634 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngine.java | JqmEngine.stop | @Override
public void stop()
{
synchronized (killHook)
{
jqmlogger.info("JQM engine " + this.node.getName() + " has received a stop order");
// Kill hook should be removed
try
{
if (!Runtime.getRuntime().removeShutdownHook(killHook))
{
jqmlogger.error("The engine could not unregister its shutdown hook");
}
}
catch (IllegalStateException e)
{
// This happens if the stop sequence is initiated by the shutdown hook itself.
jqmlogger.info("Stop order is due to an admin operation (KILL/INT)");
}
}
// Stop pollers
int pollerCount = pollers.size();
for (QueuePoller p : pollers.values())
{
p.stop();
}
// Scheduler
this.scheduler.stop();
// Jetty is closed automatically when all pollers are down
// Wait for the end of the world
if (pollerCount > 0)
{
try
{
this.ended.acquire();
}
catch (InterruptedException e)
{
jqmlogger.error("interrupted", e);
}
}
// Send a KILL signal to remaining job instances, and wait some more.
if (this.getCurrentlyRunningJobCount() > 0)
{
this.runningJobInstanceManager.killAll();
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
jqmlogger.error("interrupted", e);
}
}
jqmlogger.debug("Stop order was correctly handled. Engine for node " + this.node.getName() + " has stopped.");
} | java | @Override
public void stop()
{
synchronized (killHook)
{
jqmlogger.info("JQM engine " + this.node.getName() + " has received a stop order");
// Kill hook should be removed
try
{
if (!Runtime.getRuntime().removeShutdownHook(killHook))
{
jqmlogger.error("The engine could not unregister its shutdown hook");
}
}
catch (IllegalStateException e)
{
// This happens if the stop sequence is initiated by the shutdown hook itself.
jqmlogger.info("Stop order is due to an admin operation (KILL/INT)");
}
}
// Stop pollers
int pollerCount = pollers.size();
for (QueuePoller p : pollers.values())
{
p.stop();
}
// Scheduler
this.scheduler.stop();
// Jetty is closed automatically when all pollers are down
// Wait for the end of the world
if (pollerCount > 0)
{
try
{
this.ended.acquire();
}
catch (InterruptedException e)
{
jqmlogger.error("interrupted", e);
}
}
// Send a KILL signal to remaining job instances, and wait some more.
if (this.getCurrentlyRunningJobCount() > 0)
{
this.runningJobInstanceManager.killAll();
try
{
Thread.sleep(10000);
}
catch (InterruptedException e)
{
jqmlogger.error("interrupted", e);
}
}
jqmlogger.debug("Stop order was correctly handled. Engine for node " + this.node.getName() + " has stopped.");
} | [
"@",
"Override",
"public",
"void",
"stop",
"(",
")",
"{",
"synchronized",
"(",
"killHook",
")",
"{",
"jqmlogger",
".",
"info",
"(",
"\"JQM engine \"",
"+",
"this",
".",
"node",
".",
"getName",
"(",
")",
"+",
"\" has received a stop order\"",
")",
";",
"// Kill hook should be removed",
"try",
"{",
"if",
"(",
"!",
"Runtime",
".",
"getRuntime",
"(",
")",
".",
"removeShutdownHook",
"(",
"killHook",
")",
")",
"{",
"jqmlogger",
".",
"error",
"(",
"\"The engine could not unregister its shutdown hook\"",
")",
";",
"}",
"}",
"catch",
"(",
"IllegalStateException",
"e",
")",
"{",
"// This happens if the stop sequence is initiated by the shutdown hook itself.",
"jqmlogger",
".",
"info",
"(",
"\"Stop order is due to an admin operation (KILL/INT)\"",
")",
";",
"}",
"}",
"// Stop pollers",
"int",
"pollerCount",
"=",
"pollers",
".",
"size",
"(",
")",
";",
"for",
"(",
"QueuePoller",
"p",
":",
"pollers",
".",
"values",
"(",
")",
")",
"{",
"p",
".",
"stop",
"(",
")",
";",
"}",
"// Scheduler",
"this",
".",
"scheduler",
".",
"stop",
"(",
")",
";",
"// Jetty is closed automatically when all pollers are down",
"// Wait for the end of the world",
"if",
"(",
"pollerCount",
">",
"0",
")",
"{",
"try",
"{",
"this",
".",
"ended",
".",
"acquire",
"(",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"jqmlogger",
".",
"error",
"(",
"\"interrupted\"",
",",
"e",
")",
";",
"}",
"}",
"// Send a KILL signal to remaining job instances, and wait some more.",
"if",
"(",
"this",
".",
"getCurrentlyRunningJobCount",
"(",
")",
">",
"0",
")",
"{",
"this",
".",
"runningJobInstanceManager",
".",
"killAll",
"(",
")",
";",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"10000",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"jqmlogger",
".",
"error",
"(",
"\"interrupted\"",
",",
"e",
")",
";",
"}",
"}",
"jqmlogger",
".",
"debug",
"(",
"\"Stop order was correctly handled. Engine for node \"",
"+",
"this",
".",
"node",
".",
"getName",
"(",
")",
"+",
"\" has stopped.\"",
")",
";",
"}"
] | Gracefully stop the engine | [
"Gracefully",
"stop",
"the",
"engine"
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngine.java#L266-L328 |
162,635 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngine.java | JqmEngine.purgeDeadJobInstances | private void purgeDeadJobInstances(DbConn cnx, Node node)
{
for (JobInstance ji : JobInstance.select(cnx, "ji_select_by_node", node.getId()))
{
try
{
cnx.runSelectSingle("history_select_state_by_id", String.class, ji.getId());
}
catch (NoResultException e)
{
History.create(cnx, ji, State.CRASHED, Calendar.getInstance());
Message.create(cnx,
"Job was supposed to be running at server startup - usually means it was killed along a server by an admin or a crash",
ji.getId());
}
cnx.runUpdate("ji_delete_by_id", ji.getId());
}
cnx.commit();
} | java | private void purgeDeadJobInstances(DbConn cnx, Node node)
{
for (JobInstance ji : JobInstance.select(cnx, "ji_select_by_node", node.getId()))
{
try
{
cnx.runSelectSingle("history_select_state_by_id", String.class, ji.getId());
}
catch (NoResultException e)
{
History.create(cnx, ji, State.CRASHED, Calendar.getInstance());
Message.create(cnx,
"Job was supposed to be running at server startup - usually means it was killed along a server by an admin or a crash",
ji.getId());
}
cnx.runUpdate("ji_delete_by_id", ji.getId());
}
cnx.commit();
} | [
"private",
"void",
"purgeDeadJobInstances",
"(",
"DbConn",
"cnx",
",",
"Node",
"node",
")",
"{",
"for",
"(",
"JobInstance",
"ji",
":",
"JobInstance",
".",
"select",
"(",
"cnx",
",",
"\"ji_select_by_node\"",
",",
"node",
".",
"getId",
"(",
")",
")",
")",
"{",
"try",
"{",
"cnx",
".",
"runSelectSingle",
"(",
"\"history_select_state_by_id\"",
",",
"String",
".",
"class",
",",
"ji",
".",
"getId",
"(",
")",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"e",
")",
"{",
"History",
".",
"create",
"(",
"cnx",
",",
"ji",
",",
"State",
".",
"CRASHED",
",",
"Calendar",
".",
"getInstance",
"(",
")",
")",
";",
"Message",
".",
"create",
"(",
"cnx",
",",
"\"Job was supposed to be running at server startup - usually means it was killed along a server by an admin or a crash\"",
",",
"ji",
".",
"getId",
"(",
")",
")",
";",
"}",
"cnx",
".",
"runUpdate",
"(",
"\"ji_delete_by_id\"",
",",
"ji",
".",
"getId",
"(",
")",
")",
";",
"}",
"cnx",
".",
"commit",
"(",
")",
";",
"}"
] | To be called at node startup - it purges all job instances associated to this node.
@param cnx
@param node | [
"To",
"be",
"called",
"at",
"node",
"startup",
"-",
"it",
"purges",
"all",
"job",
"instances",
"associated",
"to",
"this",
"node",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JqmEngine.java#L492-L511 |
162,636 | enioka/jqm | jqm-all/jqm-runner/jqm-runner-java/src/main/java/com/enioka/jqm/tools/ClassloaderManager.java | ClassloaderManager.getClasspath | private URL[] getClasspath(JobInstance ji, JobRunnerCallback cb) throws JqmPayloadException
{
switch (ji.getJD().getPathType())
{
case MAVEN:
return mavenResolver.resolve(ji);
case MEMORY:
return new URL[0];
case FS:
default:
return fsResolver.getLibraries(ji.getNode(), ji.getJD());
}
} | java | private URL[] getClasspath(JobInstance ji, JobRunnerCallback cb) throws JqmPayloadException
{
switch (ji.getJD().getPathType())
{
case MAVEN:
return mavenResolver.resolve(ji);
case MEMORY:
return new URL[0];
case FS:
default:
return fsResolver.getLibraries(ji.getNode(), ji.getJD());
}
} | [
"private",
"URL",
"[",
"]",
"getClasspath",
"(",
"JobInstance",
"ji",
",",
"JobRunnerCallback",
"cb",
")",
"throws",
"JqmPayloadException",
"{",
"switch",
"(",
"ji",
".",
"getJD",
"(",
")",
".",
"getPathType",
"(",
")",
")",
"{",
"case",
"MAVEN",
":",
"return",
"mavenResolver",
".",
"resolve",
"(",
"ji",
")",
";",
"case",
"MEMORY",
":",
"return",
"new",
"URL",
"[",
"0",
"]",
";",
"case",
"FS",
":",
"default",
":",
"return",
"fsResolver",
".",
"getLibraries",
"(",
"ji",
".",
"getNode",
"(",
")",
",",
"ji",
".",
"getJD",
"(",
")",
")",
";",
"}",
"}"
] | Returns all the URL that should be inside the classpath. This includes the jar itself if any.
@throws JqmPayloadException | [
"Returns",
"all",
"the",
"URL",
"that",
"should",
"be",
"inside",
"the",
"classpath",
".",
"This",
"includes",
"the",
"jar",
"itself",
"if",
"any",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-runner/jqm-runner-java/src/main/java/com/enioka/jqm/tools/ClassloaderManager.java#L222-L234 |
162,637 | enioka/jqm | jqm-all/jqm-providers/src/main/java/com/enioka/jqm/providers/PayloadInterceptor.java | PayloadInterceptor.forceCleanup | public static int forceCleanup(Thread t)
{
int i = 0;
for (Map.Entry<ConnectionPool, Set<ConnPair>> e : conns.entrySet())
{
for (ConnPair c : e.getValue())
{
if (c.thread.equals(t))
{
try
{
// This will in turn remove it from the static Map.
c.conn.getHandler().invoke(c.conn, Connection.class.getMethod("close"), null);
}
catch (Throwable e1)
{
e1.printStackTrace();
}
i++;
}
}
}
return i;
} | java | public static int forceCleanup(Thread t)
{
int i = 0;
for (Map.Entry<ConnectionPool, Set<ConnPair>> e : conns.entrySet())
{
for (ConnPair c : e.getValue())
{
if (c.thread.equals(t))
{
try
{
// This will in turn remove it from the static Map.
c.conn.getHandler().invoke(c.conn, Connection.class.getMethod("close"), null);
}
catch (Throwable e1)
{
e1.printStackTrace();
}
i++;
}
}
}
return i;
} | [
"public",
"static",
"int",
"forceCleanup",
"(",
"Thread",
"t",
")",
"{",
"int",
"i",
"=",
"0",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"ConnectionPool",
",",
"Set",
"<",
"ConnPair",
">",
">",
"e",
":",
"conns",
".",
"entrySet",
"(",
")",
")",
"{",
"for",
"(",
"ConnPair",
"c",
":",
"e",
".",
"getValue",
"(",
")",
")",
"{",
"if",
"(",
"c",
".",
"thread",
".",
"equals",
"(",
"t",
")",
")",
"{",
"try",
"{",
"// This will in turn remove it from the static Map.",
"c",
".",
"conn",
".",
"getHandler",
"(",
")",
".",
"invoke",
"(",
"c",
".",
"conn",
",",
"Connection",
".",
"class",
".",
"getMethod",
"(",
"\"close\"",
")",
",",
"null",
")",
";",
"}",
"catch",
"(",
"Throwable",
"e1",
")",
"{",
"e1",
".",
"printStackTrace",
"(",
")",
";",
"}",
"i",
"++",
";",
"}",
"}",
"}",
"return",
"i",
";",
"}"
] | Called by the engine to trigger the cleanup at the end of a payload thread. | [
"Called",
"by",
"the",
"engine",
"to",
"trigger",
"the",
"cleanup",
"at",
"the",
"end",
"of",
"a",
"payload",
"thread",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-providers/src/main/java/com/enioka/jqm/providers/PayloadInterceptor.java#L98-L121 |
162,638 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/GlobalParameter.java | GlobalParameter.create | public static GlobalParameter create(DbConn cnx, String key, String value)
{
QueryResult r = cnx.runUpdate("globalprm_insert", key, value);
GlobalParameter res = new GlobalParameter();
res.id = r.getGeneratedId();
res.key = key;
res.value = value;
return res;
} | java | public static GlobalParameter create(DbConn cnx, String key, String value)
{
QueryResult r = cnx.runUpdate("globalprm_insert", key, value);
GlobalParameter res = new GlobalParameter();
res.id = r.getGeneratedId();
res.key = key;
res.value = value;
return res;
} | [
"public",
"static",
"GlobalParameter",
"create",
"(",
"DbConn",
"cnx",
",",
"String",
"key",
",",
"String",
"value",
")",
"{",
"QueryResult",
"r",
"=",
"cnx",
".",
"runUpdate",
"(",
"\"globalprm_insert\"",
",",
"key",
",",
"value",
")",
";",
"GlobalParameter",
"res",
"=",
"new",
"GlobalParameter",
"(",
")",
";",
"res",
".",
"id",
"=",
"r",
".",
"getGeneratedId",
"(",
")",
";",
"res",
".",
"key",
"=",
"key",
";",
"res",
".",
"value",
"=",
"value",
";",
"return",
"res",
";",
"}"
] | Create a new GP entry in the database. No commit performed. | [
"Create",
"a",
"new",
"GP",
"entry",
"in",
"the",
"database",
".",
"No",
"commit",
"performed",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/GlobalParameter.java#L110-L118 |
162,639 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/GlobalParameter.java | GlobalParameter.getParameter | public static String getParameter(DbConn cnx, String key, String defaultValue)
{
try
{
return cnx.runSelectSingle("globalprm_select_by_key", 3, String.class, key);
}
catch (NoResultException e)
{
return defaultValue;
}
} | java | public static String getParameter(DbConn cnx, String key, String defaultValue)
{
try
{
return cnx.runSelectSingle("globalprm_select_by_key", 3, String.class, key);
}
catch (NoResultException e)
{
return defaultValue;
}
} | [
"public",
"static",
"String",
"getParameter",
"(",
"DbConn",
"cnx",
",",
"String",
"key",
",",
"String",
"defaultValue",
")",
"{",
"try",
"{",
"return",
"cnx",
".",
"runSelectSingle",
"(",
"\"globalprm_select_by_key\"",
",",
"3",
",",
"String",
".",
"class",
",",
"key",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"e",
")",
"{",
"return",
"defaultValue",
";",
"}",
"}"
] | Retrieve the value of a single-valued parameter.
@param key
@param defaultValue
@param cnx | [
"Retrieve",
"the",
"value",
"of",
"a",
"single",
"-",
"valued",
"parameter",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/GlobalParameter.java#L154-L164 |
162,640 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JndiContext.java | JndiContext.createJndiContext | static JndiContext createJndiContext() throws NamingException
{
try
{
if (!NamingManager.hasInitialContextFactoryBuilder())
{
JndiContext ctx = new JndiContext();
NamingManager.setInitialContextFactoryBuilder(ctx);
return ctx;
}
else
{
return (JndiContext) NamingManager.getInitialContext(null);
}
}
catch (Exception e)
{
jqmlogger.error("Could not create JNDI context: " + e.getMessage());
NamingException ex = new NamingException("Could not initialize JNDI Context");
ex.setRootCause(e);
throw ex;
}
} | java | static JndiContext createJndiContext() throws NamingException
{
try
{
if (!NamingManager.hasInitialContextFactoryBuilder())
{
JndiContext ctx = new JndiContext();
NamingManager.setInitialContextFactoryBuilder(ctx);
return ctx;
}
else
{
return (JndiContext) NamingManager.getInitialContext(null);
}
}
catch (Exception e)
{
jqmlogger.error("Could not create JNDI context: " + e.getMessage());
NamingException ex = new NamingException("Could not initialize JNDI Context");
ex.setRootCause(e);
throw ex;
}
} | [
"static",
"JndiContext",
"createJndiContext",
"(",
")",
"throws",
"NamingException",
"{",
"try",
"{",
"if",
"(",
"!",
"NamingManager",
".",
"hasInitialContextFactoryBuilder",
"(",
")",
")",
"{",
"JndiContext",
"ctx",
"=",
"new",
"JndiContext",
"(",
")",
";",
"NamingManager",
".",
"setInitialContextFactoryBuilder",
"(",
"ctx",
")",
";",
"return",
"ctx",
";",
"}",
"else",
"{",
"return",
"(",
"JndiContext",
")",
"NamingManager",
".",
"getInitialContext",
"(",
"null",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"jqmlogger",
".",
"error",
"(",
"\"Could not create JNDI context: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"NamingException",
"ex",
"=",
"new",
"NamingException",
"(",
"\"Could not initialize JNDI Context\"",
")",
";",
"ex",
".",
"setRootCause",
"(",
"e",
")",
";",
"throw",
"ex",
";",
"}",
"}"
] | Will create a JNDI Context and register it as the initial context factory builder
@return the context
@throws NamingException
on any issue during initial context factory builder registration | [
"Will",
"create",
"a",
"JNDI",
"Context",
"and",
"register",
"it",
"as",
"the",
"initial",
"context",
"factory",
"builder"
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JndiContext.java#L75-L97 |
162,641 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JndiContext.java | JndiContext.getParentCl | private static ClassLoader getParentCl()
{
try
{
Method m = ClassLoader.class.getMethod("getPlatformClassLoader");
return (ClassLoader) m.invoke(null);
}
catch (NoSuchMethodException e)
{
// Java < 9, just use the bootstrap CL.
return null;
}
catch (Exception e)
{
throw new JqmInitError("Could not fetch Platform Class Loader", e);
}
} | java | private static ClassLoader getParentCl()
{
try
{
Method m = ClassLoader.class.getMethod("getPlatformClassLoader");
return (ClassLoader) m.invoke(null);
}
catch (NoSuchMethodException e)
{
// Java < 9, just use the bootstrap CL.
return null;
}
catch (Exception e)
{
throw new JqmInitError("Could not fetch Platform Class Loader", e);
}
} | [
"private",
"static",
"ClassLoader",
"getParentCl",
"(",
")",
"{",
"try",
"{",
"Method",
"m",
"=",
"ClassLoader",
".",
"class",
".",
"getMethod",
"(",
"\"getPlatformClassLoader\"",
")",
";",
"return",
"(",
"ClassLoader",
")",
"m",
".",
"invoke",
"(",
"null",
")",
";",
"}",
"catch",
"(",
"NoSuchMethodException",
"e",
")",
"{",
"// Java < 9, just use the bootstrap CL.",
"return",
"null",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"JqmInitError",
"(",
"\"Could not fetch Platform Class Loader\"",
",",
"e",
")",
";",
"}",
"}"
] | A helper - in Java 9, the extension CL was renamed to platform CL and hosts all the JDK classes. Before 9, it was useless and we used
bootstrap CL instead.
@return the base CL to use. | [
"A",
"helper",
"-",
"in",
"Java",
"9",
"the",
"extension",
"CL",
"was",
"renamed",
"to",
"platform",
"CL",
"and",
"hosts",
"all",
"the",
"JDK",
"classes",
".",
"Before",
"9",
"it",
"was",
"useless",
"and",
"we",
"used",
"bootstrap",
"CL",
"instead",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/JndiContext.java#L413-L429 |
162,642 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.loadProperties | public static Properties loadProperties(String[] filesToLoad)
{
Properties p = new Properties();
InputStream fis = null;
for (String path : filesToLoad)
{
try
{
fis = Db.class.getClassLoader().getResourceAsStream(path);
if (fis != null)
{
p.load(fis);
jqmlogger.info("A jqm.properties file was found at {}", path);
}
}
catch (IOException e)
{
// We allow no configuration files, but not an unreadable configuration file.
throw new DatabaseException("META-INF/jqm.properties file is invalid", e);
}
finally
{
closeQuietly(fis);
}
}
// Overload the datasource name from environment variable if any (tests only).
String dbName = System.getenv("DB");
if (dbName != null)
{
p.put("com.enioka.jqm.jdbc.datasource", "jdbc/" + dbName);
}
// Done
return p;
} | java | public static Properties loadProperties(String[] filesToLoad)
{
Properties p = new Properties();
InputStream fis = null;
for (String path : filesToLoad)
{
try
{
fis = Db.class.getClassLoader().getResourceAsStream(path);
if (fis != null)
{
p.load(fis);
jqmlogger.info("A jqm.properties file was found at {}", path);
}
}
catch (IOException e)
{
// We allow no configuration files, but not an unreadable configuration file.
throw new DatabaseException("META-INF/jqm.properties file is invalid", e);
}
finally
{
closeQuietly(fis);
}
}
// Overload the datasource name from environment variable if any (tests only).
String dbName = System.getenv("DB");
if (dbName != null)
{
p.put("com.enioka.jqm.jdbc.datasource", "jdbc/" + dbName);
}
// Done
return p;
} | [
"public",
"static",
"Properties",
"loadProperties",
"(",
"String",
"[",
"]",
"filesToLoad",
")",
"{",
"Properties",
"p",
"=",
"new",
"Properties",
"(",
")",
";",
"InputStream",
"fis",
"=",
"null",
";",
"for",
"(",
"String",
"path",
":",
"filesToLoad",
")",
"{",
"try",
"{",
"fis",
"=",
"Db",
".",
"class",
".",
"getClassLoader",
"(",
")",
".",
"getResourceAsStream",
"(",
"path",
")",
";",
"if",
"(",
"fis",
"!=",
"null",
")",
"{",
"p",
".",
"load",
"(",
"fis",
")",
";",
"jqmlogger",
".",
"info",
"(",
"\"A jqm.properties file was found at {}\"",
",",
"path",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// We allow no configuration files, but not an unreadable configuration file.",
"throw",
"new",
"DatabaseException",
"(",
"\"META-INF/jqm.properties file is invalid\"",
",",
"e",
")",
";",
"}",
"finally",
"{",
"closeQuietly",
"(",
"fis",
")",
";",
"}",
"}",
"// Overload the datasource name from environment variable if any (tests only).",
"String",
"dbName",
"=",
"System",
".",
"getenv",
"(",
"\"DB\"",
")",
";",
"if",
"(",
"dbName",
"!=",
"null",
")",
"{",
"p",
".",
"put",
"(",
"\"com.enioka.jqm.jdbc.datasource\"",
",",
"\"jdbc/\"",
"+",
"dbName",
")",
";",
"}",
"// Done",
"return",
"p",
";",
"}"
] | Helper method to load a property file from class path.
@param filesToLoad
an array of paths (class path paths) designating where the files may be. All files are loaded, in the order
given. Missing files are silently ignored.
@return a Properties object, which may be empty but not null. | [
"Helper",
"method",
"to",
"load",
"a",
"property",
"file",
"from",
"class",
"path",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L225-L260 |
162,643 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.init | private void init(boolean upgrade)
{
initAdapter();
initQueries();
if (upgrade)
{
dbUpgrade();
}
// First contact with the DB is version checking (if no connection opened by pool).
// If DB is in wrong version or not available, just wait for it to be ready.
boolean versionValid = false;
while (!versionValid)
{
try
{
checkSchemaVersion();
versionValid = true;
}
catch (Exception e)
{
String msg = e.getLocalizedMessage();
if (e.getCause() != null)
{
msg += " - " + e.getCause().getLocalizedMessage();
}
jqmlogger.error("Database not ready: " + msg + ". Waiting for database...");
try
{
Thread.sleep(10000);
}
catch (Exception e2)
{
}
}
}
} | java | private void init(boolean upgrade)
{
initAdapter();
initQueries();
if (upgrade)
{
dbUpgrade();
}
// First contact with the DB is version checking (if no connection opened by pool).
// If DB is in wrong version or not available, just wait for it to be ready.
boolean versionValid = false;
while (!versionValid)
{
try
{
checkSchemaVersion();
versionValid = true;
}
catch (Exception e)
{
String msg = e.getLocalizedMessage();
if (e.getCause() != null)
{
msg += " - " + e.getCause().getLocalizedMessage();
}
jqmlogger.error("Database not ready: " + msg + ". Waiting for database...");
try
{
Thread.sleep(10000);
}
catch (Exception e2)
{
}
}
}
} | [
"private",
"void",
"init",
"(",
"boolean",
"upgrade",
")",
"{",
"initAdapter",
"(",
")",
";",
"initQueries",
"(",
")",
";",
"if",
"(",
"upgrade",
")",
"{",
"dbUpgrade",
"(",
")",
";",
"}",
"// First contact with the DB is version checking (if no connection opened by pool).",
"// If DB is in wrong version or not available, just wait for it to be ready.",
"boolean",
"versionValid",
"=",
"false",
";",
"while",
"(",
"!",
"versionValid",
")",
"{",
"try",
"{",
"checkSchemaVersion",
"(",
")",
";",
"versionValid",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"String",
"msg",
"=",
"e",
".",
"getLocalizedMessage",
"(",
")",
";",
"if",
"(",
"e",
".",
"getCause",
"(",
")",
"!=",
"null",
")",
"{",
"msg",
"+=",
"\" - \"",
"+",
"e",
".",
"getCause",
"(",
")",
".",
"getLocalizedMessage",
"(",
")",
";",
"}",
"jqmlogger",
".",
"error",
"(",
"\"Database not ready: \"",
"+",
"msg",
"+",
"\". Waiting for database...\"",
")",
";",
"try",
"{",
"Thread",
".",
"sleep",
"(",
"10000",
")",
";",
"}",
"catch",
"(",
"Exception",
"e2",
")",
"{",
"}",
"}",
"}",
"}"
] | Main database initialization. To be called only when _ds is a valid DataSource. | [
"Main",
"database",
"initialization",
".",
"To",
"be",
"called",
"only",
"when",
"_ds",
"is",
"a",
"valid",
"DataSource",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L265-L301 |
162,644 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.dbUpgrade | private void dbUpgrade()
{
DbConn cnx = this.getConn();
Map<String, Object> rs = null;
int db_schema_version = 0;
try
{
rs = cnx.runSelectSingleRow("version_select_latest");
db_schema_version = (Integer) rs.get("VERSION_D1");
}
catch (Exception e)
{
// Database is to be created, so version 0 is OK.
}
cnx.rollback();
if (SCHEMA_VERSION > db_schema_version)
{
jqmlogger.warn("Database is being upgraded from version {} to version {}", db_schema_version, SCHEMA_VERSION);
// Upgrade scripts are named from_to.sql with 5 padding (e.g. 00000_00003.sql)
// We try to find the fastest path (e.g. a direct 00000_00005.sql for creating a version 5 schema from nothing)
// This is a simplistic and non-optimal algorithm as we try only a single path (no going back)
int loop_from = db_schema_version;
int to = db_schema_version;
List<String> toApply = new ArrayList<>();
toApply.addAll(adapter.preSchemaCreationScripts());
while (to != SCHEMA_VERSION)
{
boolean progressed = false;
for (int loop_to = SCHEMA_VERSION; loop_to > db_schema_version; loop_to--)
{
String migrationFileName = String.format("/sql/%05d_%05d.sql", loop_from, loop_to);
jqmlogger.debug("Trying migration script {}", migrationFileName);
if (Db.class.getResource(migrationFileName) != null)
{
toApply.add(migrationFileName);
to = loop_to;
loop_from = loop_to;
progressed = true;
break;
}
}
if (!progressed)
{
break;
}
}
if (to != SCHEMA_VERSION)
{
throw new DatabaseException(
"There is no migration path from version " + db_schema_version + " to version " + SCHEMA_VERSION);
}
for (String s : toApply)
{
jqmlogger.info("Running migration script {}", s);
ScriptRunner.run(cnx, s);
}
cnx.commit(); // Yes, really. For advanced DB!
cnx.close(); // HSQLDB does not refresh its schema without this.
cnx = getConn();
cnx.runUpdate("version_insert", SCHEMA_VERSION, SCHEMA_COMPATIBLE_VERSION);
cnx.commit();
jqmlogger.info("Database is now up to date");
}
else
{
jqmlogger.info("Database is already up to date");
}
cnx.close();
} | java | private void dbUpgrade()
{
DbConn cnx = this.getConn();
Map<String, Object> rs = null;
int db_schema_version = 0;
try
{
rs = cnx.runSelectSingleRow("version_select_latest");
db_schema_version = (Integer) rs.get("VERSION_D1");
}
catch (Exception e)
{
// Database is to be created, so version 0 is OK.
}
cnx.rollback();
if (SCHEMA_VERSION > db_schema_version)
{
jqmlogger.warn("Database is being upgraded from version {} to version {}", db_schema_version, SCHEMA_VERSION);
// Upgrade scripts are named from_to.sql with 5 padding (e.g. 00000_00003.sql)
// We try to find the fastest path (e.g. a direct 00000_00005.sql for creating a version 5 schema from nothing)
// This is a simplistic and non-optimal algorithm as we try only a single path (no going back)
int loop_from = db_schema_version;
int to = db_schema_version;
List<String> toApply = new ArrayList<>();
toApply.addAll(adapter.preSchemaCreationScripts());
while (to != SCHEMA_VERSION)
{
boolean progressed = false;
for (int loop_to = SCHEMA_VERSION; loop_to > db_schema_version; loop_to--)
{
String migrationFileName = String.format("/sql/%05d_%05d.sql", loop_from, loop_to);
jqmlogger.debug("Trying migration script {}", migrationFileName);
if (Db.class.getResource(migrationFileName) != null)
{
toApply.add(migrationFileName);
to = loop_to;
loop_from = loop_to;
progressed = true;
break;
}
}
if (!progressed)
{
break;
}
}
if (to != SCHEMA_VERSION)
{
throw new DatabaseException(
"There is no migration path from version " + db_schema_version + " to version " + SCHEMA_VERSION);
}
for (String s : toApply)
{
jqmlogger.info("Running migration script {}", s);
ScriptRunner.run(cnx, s);
}
cnx.commit(); // Yes, really. For advanced DB!
cnx.close(); // HSQLDB does not refresh its schema without this.
cnx = getConn();
cnx.runUpdate("version_insert", SCHEMA_VERSION, SCHEMA_COMPATIBLE_VERSION);
cnx.commit();
jqmlogger.info("Database is now up to date");
}
else
{
jqmlogger.info("Database is already up to date");
}
cnx.close();
} | [
"private",
"void",
"dbUpgrade",
"(",
")",
"{",
"DbConn",
"cnx",
"=",
"this",
".",
"getConn",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Object",
">",
"rs",
"=",
"null",
";",
"int",
"db_schema_version",
"=",
"0",
";",
"try",
"{",
"rs",
"=",
"cnx",
".",
"runSelectSingleRow",
"(",
"\"version_select_latest\"",
")",
";",
"db_schema_version",
"=",
"(",
"Integer",
")",
"rs",
".",
"get",
"(",
"\"VERSION_D1\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// Database is to be created, so version 0 is OK.",
"}",
"cnx",
".",
"rollback",
"(",
")",
";",
"if",
"(",
"SCHEMA_VERSION",
">",
"db_schema_version",
")",
"{",
"jqmlogger",
".",
"warn",
"(",
"\"Database is being upgraded from version {} to version {}\"",
",",
"db_schema_version",
",",
"SCHEMA_VERSION",
")",
";",
"// Upgrade scripts are named from_to.sql with 5 padding (e.g. 00000_00003.sql)",
"// We try to find the fastest path (e.g. a direct 00000_00005.sql for creating a version 5 schema from nothing)",
"// This is a simplistic and non-optimal algorithm as we try only a single path (no going back)",
"int",
"loop_from",
"=",
"db_schema_version",
";",
"int",
"to",
"=",
"db_schema_version",
";",
"List",
"<",
"String",
">",
"toApply",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"toApply",
".",
"addAll",
"(",
"adapter",
".",
"preSchemaCreationScripts",
"(",
")",
")",
";",
"while",
"(",
"to",
"!=",
"SCHEMA_VERSION",
")",
"{",
"boolean",
"progressed",
"=",
"false",
";",
"for",
"(",
"int",
"loop_to",
"=",
"SCHEMA_VERSION",
";",
"loop_to",
">",
"db_schema_version",
";",
"loop_to",
"--",
")",
"{",
"String",
"migrationFileName",
"=",
"String",
".",
"format",
"(",
"\"/sql/%05d_%05d.sql\"",
",",
"loop_from",
",",
"loop_to",
")",
";",
"jqmlogger",
".",
"debug",
"(",
"\"Trying migration script {}\"",
",",
"migrationFileName",
")",
";",
"if",
"(",
"Db",
".",
"class",
".",
"getResource",
"(",
"migrationFileName",
")",
"!=",
"null",
")",
"{",
"toApply",
".",
"add",
"(",
"migrationFileName",
")",
";",
"to",
"=",
"loop_to",
";",
"loop_from",
"=",
"loop_to",
";",
"progressed",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"progressed",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"to",
"!=",
"SCHEMA_VERSION",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"\"There is no migration path from version \"",
"+",
"db_schema_version",
"+",
"\" to version \"",
"+",
"SCHEMA_VERSION",
")",
";",
"}",
"for",
"(",
"String",
"s",
":",
"toApply",
")",
"{",
"jqmlogger",
".",
"info",
"(",
"\"Running migration script {}\"",
",",
"s",
")",
";",
"ScriptRunner",
".",
"run",
"(",
"cnx",
",",
"s",
")",
";",
"}",
"cnx",
".",
"commit",
"(",
")",
";",
"// Yes, really. For advanced DB!",
"cnx",
".",
"close",
"(",
")",
";",
"// HSQLDB does not refresh its schema without this.",
"cnx",
"=",
"getConn",
"(",
")",
";",
"cnx",
".",
"runUpdate",
"(",
"\"version_insert\"",
",",
"SCHEMA_VERSION",
",",
"SCHEMA_COMPATIBLE_VERSION",
")",
";",
"cnx",
".",
"commit",
"(",
")",
";",
"jqmlogger",
".",
"info",
"(",
"\"Database is now up to date\"",
")",
";",
"}",
"else",
"{",
"jqmlogger",
".",
"info",
"(",
"\"Database is already up to date\"",
")",
";",
"}",
"cnx",
".",
"close",
"(",
")",
";",
"}"
] | Updates the database. Never call this during normal operations, upgrade is a user-controlled operation. | [
"Updates",
"the",
"database",
".",
"Never",
"call",
"this",
"during",
"normal",
"operations",
"upgrade",
"is",
"a",
"user",
"-",
"controlled",
"operation",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L359-L435 |
162,645 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.initAdapter | private void initAdapter()
{
Connection tmp = null;
DatabaseMetaData meta = null;
try
{
tmp = _ds.getConnection();
meta = tmp.getMetaData();
product = meta.getDatabaseProductName().toLowerCase();
}
catch (SQLException e)
{
throw new DatabaseException("Cannot connect to the database", e);
}
finally
{
try
{
if (tmp != null)
{
tmp.close();
}
}
catch (SQLException e)
{
// Nothing to do.
}
}
DbAdapter newAdpt = null;
for (String s : ADAPTERS)
{
try
{
Class<? extends DbAdapter> clazz = Db.class.getClassLoader().loadClass(s).asSubclass(DbAdapter.class);
newAdpt = clazz.newInstance();
if (newAdpt.compatibleWith(meta))
{
adapter = newAdpt;
break;
}
}
catch (Exception e)
{
throw new DatabaseException("Issue when loading database adapter named: " + s, e);
}
}
if (adapter == null)
{
throw new DatabaseException("Unsupported database! There is no JQM database adapter compatible with product name " + product);
}
else
{
jqmlogger.info("Using database adapter {}", adapter.getClass().getCanonicalName());
}
} | java | private void initAdapter()
{
Connection tmp = null;
DatabaseMetaData meta = null;
try
{
tmp = _ds.getConnection();
meta = tmp.getMetaData();
product = meta.getDatabaseProductName().toLowerCase();
}
catch (SQLException e)
{
throw new DatabaseException("Cannot connect to the database", e);
}
finally
{
try
{
if (tmp != null)
{
tmp.close();
}
}
catch (SQLException e)
{
// Nothing to do.
}
}
DbAdapter newAdpt = null;
for (String s : ADAPTERS)
{
try
{
Class<? extends DbAdapter> clazz = Db.class.getClassLoader().loadClass(s).asSubclass(DbAdapter.class);
newAdpt = clazz.newInstance();
if (newAdpt.compatibleWith(meta))
{
adapter = newAdpt;
break;
}
}
catch (Exception e)
{
throw new DatabaseException("Issue when loading database adapter named: " + s, e);
}
}
if (adapter == null)
{
throw new DatabaseException("Unsupported database! There is no JQM database adapter compatible with product name " + product);
}
else
{
jqmlogger.info("Using database adapter {}", adapter.getClass().getCanonicalName());
}
} | [
"private",
"void",
"initAdapter",
"(",
")",
"{",
"Connection",
"tmp",
"=",
"null",
";",
"DatabaseMetaData",
"meta",
"=",
"null",
";",
"try",
"{",
"tmp",
"=",
"_ds",
".",
"getConnection",
"(",
")",
";",
"meta",
"=",
"tmp",
".",
"getMetaData",
"(",
")",
";",
"product",
"=",
"meta",
".",
"getDatabaseProductName",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"\"Cannot connect to the database\"",
",",
"e",
")",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"tmp",
"!=",
"null",
")",
"{",
"tmp",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"// Nothing to do.",
"}",
"}",
"DbAdapter",
"newAdpt",
"=",
"null",
";",
"for",
"(",
"String",
"s",
":",
"ADAPTERS",
")",
"{",
"try",
"{",
"Class",
"<",
"?",
"extends",
"DbAdapter",
">",
"clazz",
"=",
"Db",
".",
"class",
".",
"getClassLoader",
"(",
")",
".",
"loadClass",
"(",
"s",
")",
".",
"asSubclass",
"(",
"DbAdapter",
".",
"class",
")",
";",
"newAdpt",
"=",
"clazz",
".",
"newInstance",
"(",
")",
";",
"if",
"(",
"newAdpt",
".",
"compatibleWith",
"(",
"meta",
")",
")",
"{",
"adapter",
"=",
"newAdpt",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"\"Issue when loading database adapter named: \"",
"+",
"s",
",",
"e",
")",
";",
"}",
"}",
"if",
"(",
"adapter",
"==",
"null",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"\"Unsupported database! There is no JQM database adapter compatible with product name \"",
"+",
"product",
")",
";",
"}",
"else",
"{",
"jqmlogger",
".",
"info",
"(",
"\"Using database adapter {}\"",
",",
"adapter",
".",
"getClass",
"(",
")",
".",
"getCanonicalName",
"(",
")",
")",
";",
"}",
"}"
] | Creates the adapter for the target database. | [
"Creates",
"the",
"adapter",
"for",
"the",
"target",
"database",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L440-L496 |
162,646 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.getConn | public DbConn getConn()
{
Connection cnx = null;
try
{
Thread.interrupted(); // this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly.
cnx = _ds.getConnection();
if (cnx.getAutoCommit())
{
cnx.setAutoCommit(false);
cnx.rollback(); // To ensure no open transaction created by the pool before changing TX mode
}
if (cnx.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED)
{
cnx.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}
return new DbConn(this, cnx);
}
catch (SQLException e)
{
DbHelper.closeQuietly(cnx); // May have been left open when the pool has given us a failed connection.
throw new DatabaseException(e);
}
} | java | public DbConn getConn()
{
Connection cnx = null;
try
{
Thread.interrupted(); // this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly.
cnx = _ds.getConnection();
if (cnx.getAutoCommit())
{
cnx.setAutoCommit(false);
cnx.rollback(); // To ensure no open transaction created by the pool before changing TX mode
}
if (cnx.getTransactionIsolation() != Connection.TRANSACTION_READ_COMMITTED)
{
cnx.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
}
return new DbConn(this, cnx);
}
catch (SQLException e)
{
DbHelper.closeQuietly(cnx); // May have been left open when the pool has given us a failed connection.
throw new DatabaseException(e);
}
} | [
"public",
"DbConn",
"getConn",
"(",
")",
"{",
"Connection",
"cnx",
"=",
"null",
";",
"try",
"{",
"Thread",
".",
"interrupted",
"(",
")",
";",
"// this is VERY sad. Needed for Oracle driver which otherwise fails spectacularly.",
"cnx",
"=",
"_ds",
".",
"getConnection",
"(",
")",
";",
"if",
"(",
"cnx",
".",
"getAutoCommit",
"(",
")",
")",
"{",
"cnx",
".",
"setAutoCommit",
"(",
"false",
")",
";",
"cnx",
".",
"rollback",
"(",
")",
";",
"// To ensure no open transaction created by the pool before changing TX mode",
"}",
"if",
"(",
"cnx",
".",
"getTransactionIsolation",
"(",
")",
"!=",
"Connection",
".",
"TRANSACTION_READ_COMMITTED",
")",
"{",
"cnx",
".",
"setTransactionIsolation",
"(",
"Connection",
".",
"TRANSACTION_READ_COMMITTED",
")",
";",
"}",
"return",
"new",
"DbConn",
"(",
"this",
",",
"cnx",
")",
";",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"DbHelper",
".",
"closeQuietly",
"(",
"cnx",
")",
";",
"// May have been left open when the pool has given us a failed connection.",
"throw",
"new",
"DatabaseException",
"(",
"e",
")",
";",
"}",
"}"
] | A connection to the database. Should be short-lived. No transaction active by default.
@return a new open connection. | [
"A",
"connection",
"to",
"the",
"database",
".",
"Should",
"be",
"short",
"-",
"lived",
".",
"No",
"transaction",
"active",
"by",
"default",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L513-L538 |
162,647 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java | Db.getQuery | String getQuery(String key)
{
String res = this.adapter.getSqlText(key);
if (res == null)
{
throw new DatabaseException("Query " + key + " does not exist");
}
return res;
} | java | String getQuery(String key)
{
String res = this.adapter.getSqlText(key);
if (res == null)
{
throw new DatabaseException("Query " + key + " does not exist");
}
return res;
} | [
"String",
"getQuery",
"(",
"String",
"key",
")",
"{",
"String",
"res",
"=",
"this",
".",
"adapter",
".",
"getSqlText",
"(",
"key",
")",
";",
"if",
"(",
"res",
"==",
"null",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"\"Query \"",
"+",
"key",
"+",
"\" does not exist\"",
")",
";",
"}",
"return",
"res",
";",
"}"
] | Gets the interpolated text of a query from cache. If key does not exist, an exception is thrown.
@param key
name of the query
@return the query text | [
"Gets",
"the",
"interpolated",
"text",
"of",
"a",
"query",
"from",
"cache",
".",
"If",
"key",
"does",
"not",
"exist",
"an",
"exception",
"is",
"thrown",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/Db.java#L547-L555 |
162,648 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/JobInstance.java | JobInstance.addParameter | public RuntimeParameter addParameter(String key, String value)
{
RuntimeParameter jp = new RuntimeParameter();
jp.setJi(this.getId());
jp.setKey(key);
jp.setValue(value);
return jp;
} | java | public RuntimeParameter addParameter(String key, String value)
{
RuntimeParameter jp = new RuntimeParameter();
jp.setJi(this.getId());
jp.setKey(key);
jp.setValue(value);
return jp;
} | [
"public",
"RuntimeParameter",
"addParameter",
"(",
"String",
"key",
",",
"String",
"value",
")",
"{",
"RuntimeParameter",
"jp",
"=",
"new",
"RuntimeParameter",
"(",
")",
";",
"jp",
".",
"setJi",
"(",
"this",
".",
"getId",
"(",
")",
")",
";",
"jp",
".",
"setKey",
"(",
"key",
")",
";",
"jp",
".",
"setValue",
"(",
"value",
")",
";",
"return",
"jp",
";",
"}"
] | Helper method to add a parameter without having to create it explicitely. The created parameter should be persisted afterwards.
@param key
name of the parameter to add
@param value
value of the parameter to create
@return the newly created parameter | [
"Helper",
"method",
"to",
"add",
"a",
"parameter",
"without",
"having",
"to",
"create",
"it",
"explicitely",
".",
"The",
"created",
"parameter",
"should",
"be",
"persisted",
"afterwards",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/model/JobInstance.java#L89-L96 |
162,649 | enioka/jqm | jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/RunningJobInstance.java | RunningJobInstance.endOfRunDb | void endOfRunDb()
{
DbConn cnx = null;
try
{
cnx = Helpers.getNewDbSession();
// Done: put inside history & remove instance from queue.
History.create(cnx, this.ji, this.resultStatus, endDate);
jqmlogger.trace("An History was just created for job instance " + this.ji.getId());
cnx.runUpdate("ji_delete_by_id", this.ji.getId());
cnx.commit();
}
catch (RuntimeException e)
{
endBlockDbFailureAnalysis(e);
}
finally
{
Helpers.closeQuietly(cnx);
}
} | java | void endOfRunDb()
{
DbConn cnx = null;
try
{
cnx = Helpers.getNewDbSession();
// Done: put inside history & remove instance from queue.
History.create(cnx, this.ji, this.resultStatus, endDate);
jqmlogger.trace("An History was just created for job instance " + this.ji.getId());
cnx.runUpdate("ji_delete_by_id", this.ji.getId());
cnx.commit();
}
catch (RuntimeException e)
{
endBlockDbFailureAnalysis(e);
}
finally
{
Helpers.closeQuietly(cnx);
}
} | [
"void",
"endOfRunDb",
"(",
")",
"{",
"DbConn",
"cnx",
"=",
"null",
";",
"try",
"{",
"cnx",
"=",
"Helpers",
".",
"getNewDbSession",
"(",
")",
";",
"// Done: put inside history & remove instance from queue.",
"History",
".",
"create",
"(",
"cnx",
",",
"this",
".",
"ji",
",",
"this",
".",
"resultStatus",
",",
"endDate",
")",
";",
"jqmlogger",
".",
"trace",
"(",
"\"An History was just created for job instance \"",
"+",
"this",
".",
"ji",
".",
"getId",
"(",
")",
")",
";",
"cnx",
".",
"runUpdate",
"(",
"\"ji_delete_by_id\"",
",",
"this",
".",
"ji",
".",
"getId",
"(",
")",
")",
";",
"cnx",
".",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"e",
")",
"{",
"endBlockDbFailureAnalysis",
"(",
"e",
")",
";",
"}",
"finally",
"{",
"Helpers",
".",
"closeQuietly",
"(",
"cnx",
")",
";",
"}",
"}"
] | Part of the endOfRun process that needs the database. May be deferred if the database is not available. | [
"Part",
"of",
"the",
"endOfRun",
"process",
"that",
"needs",
"the",
"database",
".",
"May",
"be",
"deferred",
"if",
"the",
"database",
"is",
"not",
"available",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-engine/src/main/java/com/enioka/jqm/tools/RunningJobInstance.java#L292-L314 |
162,650 | enioka/jqm | jqm-all/jqm-client/jqm-api-client-jdbc/src/main/java/com/enioka/jqm/api/JdbcClient.java | JdbcClient.highlanderMode | private Integer highlanderMode(JobDef jd, DbConn cnx)
{
if (!jd.isHighlander())
{
return null;
}
try
{
Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
return existing;
}
catch (NoResultException ex)
{
// Just continue, this means no existing waiting JI in queue.
}
// Now we need to actually synchronize through the database to avoid double posting
// TODO: use a dedicated table, not the JobDef one. Will avoid locking the configuration.
ResultSet rs = cnx.runSelect(true, "jd_select_by_id", jd.getId());
// Now we have a lock, just retry - some other client may have created a job instance recently.
try
{
Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
rs.close();
cnx.commit(); // Do not keep the lock!
return existing;
}
catch (NoResultException ex)
{
// Just continue, this means no existing waiting JI in queue. We keep the lock!
}
catch (SQLException e)
{
// Who cares.
jqmlogger.warn("Issue when closing a ResultSet. Transaction or session leak is possible.", e);
}
jqmlogger.trace("Highlander mode analysis is done: nor existing JO, must create a new one. Lock is hold.");
return null;
} | java | private Integer highlanderMode(JobDef jd, DbConn cnx)
{
if (!jd.isHighlander())
{
return null;
}
try
{
Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
return existing;
}
catch (NoResultException ex)
{
// Just continue, this means no existing waiting JI in queue.
}
// Now we need to actually synchronize through the database to avoid double posting
// TODO: use a dedicated table, not the JobDef one. Will avoid locking the configuration.
ResultSet rs = cnx.runSelect(true, "jd_select_by_id", jd.getId());
// Now we have a lock, just retry - some other client may have created a job instance recently.
try
{
Integer existing = cnx.runSelectSingle("ji_select_existing_highlander", Integer.class, jd.getId());
rs.close();
cnx.commit(); // Do not keep the lock!
return existing;
}
catch (NoResultException ex)
{
// Just continue, this means no existing waiting JI in queue. We keep the lock!
}
catch (SQLException e)
{
// Who cares.
jqmlogger.warn("Issue when closing a ResultSet. Transaction or session leak is possible.", e);
}
jqmlogger.trace("Highlander mode analysis is done: nor existing JO, must create a new one. Lock is hold.");
return null;
} | [
"private",
"Integer",
"highlanderMode",
"(",
"JobDef",
"jd",
",",
"DbConn",
"cnx",
")",
"{",
"if",
"(",
"!",
"jd",
".",
"isHighlander",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"Integer",
"existing",
"=",
"cnx",
".",
"runSelectSingle",
"(",
"\"ji_select_existing_highlander\"",
",",
"Integer",
".",
"class",
",",
"jd",
".",
"getId",
"(",
")",
")",
";",
"return",
"existing",
";",
"}",
"catch",
"(",
"NoResultException",
"ex",
")",
"{",
"// Just continue, this means no existing waiting JI in queue.",
"}",
"// Now we need to actually synchronize through the database to avoid double posting",
"// TODO: use a dedicated table, not the JobDef one. Will avoid locking the configuration.",
"ResultSet",
"rs",
"=",
"cnx",
".",
"runSelect",
"(",
"true",
",",
"\"jd_select_by_id\"",
",",
"jd",
".",
"getId",
"(",
")",
")",
";",
"// Now we have a lock, just retry - some other client may have created a job instance recently.",
"try",
"{",
"Integer",
"existing",
"=",
"cnx",
".",
"runSelectSingle",
"(",
"\"ji_select_existing_highlander\"",
",",
"Integer",
".",
"class",
",",
"jd",
".",
"getId",
"(",
")",
")",
";",
"rs",
".",
"close",
"(",
")",
";",
"cnx",
".",
"commit",
"(",
")",
";",
"// Do not keep the lock!",
"return",
"existing",
";",
"}",
"catch",
"(",
"NoResultException",
"ex",
")",
"{",
"// Just continue, this means no existing waiting JI in queue. We keep the lock!",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"// Who cares.",
"jqmlogger",
".",
"warn",
"(",
"\"Issue when closing a ResultSet. Transaction or session leak is possible.\"",
",",
"e",
")",
";",
"}",
"jqmlogger",
".",
"trace",
"(",
"\"Highlander mode analysis is done: nor existing JO, must create a new one. Lock is hold.\"",
")",
";",
"return",
"null",
";",
"}"
] | Helper. Current transaction is committed in some cases. | [
"Helper",
".",
"Current",
"transaction",
"is",
"committed",
"in",
"some",
"cases",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-client/jqm-api-client-jdbc/src/main/java/com/enioka/jqm/api/JdbcClient.java#L374-L415 |
162,651 | enioka/jqm | jqm-all/jqm-client/jqm-api-client-jdbc/src/main/java/com/enioka/jqm/api/JdbcClient.java | JdbcClient.getStringPredicate | private String getStringPredicate(String fieldName, List<String> filterValues, List<Object> prms)
{
if (filterValues != null && !filterValues.isEmpty())
{
String res = "";
for (String filterValue : filterValues)
{
if (filterValue == null)
{
continue;
}
if (!filterValue.isEmpty())
{
prms.add(filterValue);
if (filterValue.contains("%"))
{
res += String.format("(%s LIKE ?) OR ", fieldName);
}
else
{
res += String.format("(%s = ?) OR ", fieldName);
}
}
else
{
res += String.format("(%s IS NULL OR %s = '') OR ", fieldName, fieldName);
}
}
if (!res.isEmpty())
{
res = "AND (" + res.substring(0, res.length() - 4) + ") ";
return res;
}
}
return "";
} | java | private String getStringPredicate(String fieldName, List<String> filterValues, List<Object> prms)
{
if (filterValues != null && !filterValues.isEmpty())
{
String res = "";
for (String filterValue : filterValues)
{
if (filterValue == null)
{
continue;
}
if (!filterValue.isEmpty())
{
prms.add(filterValue);
if (filterValue.contains("%"))
{
res += String.format("(%s LIKE ?) OR ", fieldName);
}
else
{
res += String.format("(%s = ?) OR ", fieldName);
}
}
else
{
res += String.format("(%s IS NULL OR %s = '') OR ", fieldName, fieldName);
}
}
if (!res.isEmpty())
{
res = "AND (" + res.substring(0, res.length() - 4) + ") ";
return res;
}
}
return "";
} | [
"private",
"String",
"getStringPredicate",
"(",
"String",
"fieldName",
",",
"List",
"<",
"String",
">",
"filterValues",
",",
"List",
"<",
"Object",
">",
"prms",
")",
"{",
"if",
"(",
"filterValues",
"!=",
"null",
"&&",
"!",
"filterValues",
".",
"isEmpty",
"(",
")",
")",
"{",
"String",
"res",
"=",
"\"\"",
";",
"for",
"(",
"String",
"filterValue",
":",
"filterValues",
")",
"{",
"if",
"(",
"filterValue",
"==",
"null",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"filterValue",
".",
"isEmpty",
"(",
")",
")",
"{",
"prms",
".",
"add",
"(",
"filterValue",
")",
";",
"if",
"(",
"filterValue",
".",
"contains",
"(",
"\"%\"",
")",
")",
"{",
"res",
"+=",
"String",
".",
"format",
"(",
"\"(%s LIKE ?) OR \"",
",",
"fieldName",
")",
";",
"}",
"else",
"{",
"res",
"+=",
"String",
".",
"format",
"(",
"\"(%s = ?) OR \"",
",",
"fieldName",
")",
";",
"}",
"}",
"else",
"{",
"res",
"+=",
"String",
".",
"format",
"(",
"\"(%s IS NULL OR %s = '') OR \"",
",",
"fieldName",
",",
"fieldName",
")",
";",
"}",
"}",
"if",
"(",
"!",
"res",
".",
"isEmpty",
"(",
")",
")",
"{",
"res",
"=",
"\"AND (\"",
"+",
"res",
".",
"substring",
"(",
"0",
",",
"res",
".",
"length",
"(",
")",
"-",
"4",
")",
"+",
"\") \"",
";",
"return",
"res",
";",
"}",
"}",
"return",
"\"\"",
";",
"}"
] | GetJob helper - String predicates are all created the same way, so this factors some code. | [
"GetJob",
"helper",
"-",
"String",
"predicates",
"are",
"all",
"created",
"the",
"same",
"way",
"so",
"this",
"factors",
"some",
"code",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-client/jqm-api-client-jdbc/src/main/java/com/enioka/jqm/api/JdbcClient.java#L1099-L1134 |
162,652 | enioka/jqm | jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/DbAdapter.java | DbAdapter.prepare | public void prepare(Properties p, Connection cnx)
{
this.tablePrefix = p.getProperty("com.enioka.jqm.jdbc.tablePrefix", "");
queries.putAll(DbImplBase.queries);
for (Map.Entry<String, String> entry : DbImplBase.queries.entrySet())
{
queries.put(entry.getKey(), this.adaptSql(entry.getValue()));
}
} | java | public void prepare(Properties p, Connection cnx)
{
this.tablePrefix = p.getProperty("com.enioka.jqm.jdbc.tablePrefix", "");
queries.putAll(DbImplBase.queries);
for (Map.Entry<String, String> entry : DbImplBase.queries.entrySet())
{
queries.put(entry.getKey(), this.adaptSql(entry.getValue()));
}
} | [
"public",
"void",
"prepare",
"(",
"Properties",
"p",
",",
"Connection",
"cnx",
")",
"{",
"this",
".",
"tablePrefix",
"=",
"p",
".",
"getProperty",
"(",
"\"com.enioka.jqm.jdbc.tablePrefix\"",
",",
"\"\"",
")",
";",
"queries",
".",
"putAll",
"(",
"DbImplBase",
".",
"queries",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"entry",
":",
"DbImplBase",
".",
"queries",
".",
"entrySet",
"(",
")",
")",
"{",
"queries",
".",
"put",
"(",
"entry",
".",
"getKey",
"(",
")",
",",
"this",
".",
"adaptSql",
"(",
"entry",
".",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}"
] | Called after creating the first connection. The adapter should create its caches and do all initialization it requires. Most
importantly, the SQL query cache should be created.
@param cnx
an open ready to use connection to the database. | [
"Called",
"after",
"creating",
"the",
"first",
"connection",
".",
"The",
"adapter",
"should",
"create",
"its",
"caches",
"and",
"do",
"all",
"initialization",
"it",
"requires",
".",
"Most",
"importantly",
"the",
"SQL",
"query",
"cache",
"should",
"be",
"created",
"."
] | 391733b8e291404b97c714c3727a241c4a861f98 | https://github.com/enioka/jqm/blob/391733b8e291404b97c714c3727a241c4a861f98/jqm-all/jqm-model/src/main/java/com/enioka/jqm/jdbc/DbAdapter.java#L94-L102 |
162,653 | Angads25/android-filepicker | filepicker/src/main/java/com/github/angads25/filepicker/utils/ExtensionFilter.java | ExtensionFilter.accept | @Override
public boolean accept(File file) {
//All directories are added in the least that can be read by the Application
if (file.isDirectory()&&file.canRead())
{ return true;
}
else if(properties.selection_type==DialogConfigs.DIR_SELECT)
{ /* True for files, If the selection type is Directory type, ie.
* Only directory has to be selected from the list, then all files are
* ignored.
*/
return false;
}
else
{ /* Check whether name of the file ends with the extension. Added if it
* does.
*/
String name = file.getName().toLowerCase(Locale.getDefault());
for (String ext : validExtensions) {
if (name.endsWith(ext)) {
return true;
}
}
}
return false;
} | java | @Override
public boolean accept(File file) {
//All directories are added in the least that can be read by the Application
if (file.isDirectory()&&file.canRead())
{ return true;
}
else if(properties.selection_type==DialogConfigs.DIR_SELECT)
{ /* True for files, If the selection type is Directory type, ie.
* Only directory has to be selected from the list, then all files are
* ignored.
*/
return false;
}
else
{ /* Check whether name of the file ends with the extension. Added if it
* does.
*/
String name = file.getName().toLowerCase(Locale.getDefault());
for (String ext : validExtensions) {
if (name.endsWith(ext)) {
return true;
}
}
}
return false;
} | [
"@",
"Override",
"public",
"boolean",
"accept",
"(",
"File",
"file",
")",
"{",
"//All directories are added in the least that can be read by the Application",
"if",
"(",
"file",
".",
"isDirectory",
"(",
")",
"&&",
"file",
".",
"canRead",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"properties",
".",
"selection_type",
"==",
"DialogConfigs",
".",
"DIR_SELECT",
")",
"{",
"/* True for files, If the selection type is Directory type, ie.\n * Only directory has to be selected from the list, then all files are\n * ignored.\n */",
"return",
"false",
";",
"}",
"else",
"{",
"/* Check whether name of the file ends with the extension. Added if it\n * does.\n */",
"String",
"name",
"=",
"file",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
"Locale",
".",
"getDefault",
"(",
")",
")",
";",
"for",
"(",
"String",
"ext",
":",
"validExtensions",
")",
"{",
"if",
"(",
"name",
".",
"endsWith",
"(",
"ext",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Function to filter files based on defined rules. | [
"Function",
"to",
"filter",
"files",
"based",
"on",
"defined",
"rules",
"."
] | 46fd8825e6d88c69462078a0300d905739a803ea | https://github.com/Angads25/android-filepicker/blob/46fd8825e6d88c69462078a0300d905739a803ea/filepicker/src/main/java/com/github/angads25/filepicker/utils/ExtensionFilter.java#L49-L74 |
162,654 | omadahealth/SwipyRefreshLayout | lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java | SwipyRefreshLayout.setSize | public void setSize(int size) {
if (size != MaterialProgressDrawable.LARGE && size != MaterialProgressDrawable.DEFAULT) {
return;
}
final DisplayMetrics metrics = getResources().getDisplayMetrics();
if (size == MaterialProgressDrawable.LARGE) {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER_LARGE * metrics.density);
} else {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
}
// force the bounds of the progress circle inside the circle view to
// update by setting it to null before updating its size and then
// re-setting it
mCircleView.setImageDrawable(null);
mProgress.updateSizes(size);
mCircleView.setImageDrawable(mProgress);
} | java | public void setSize(int size) {
if (size != MaterialProgressDrawable.LARGE && size != MaterialProgressDrawable.DEFAULT) {
return;
}
final DisplayMetrics metrics = getResources().getDisplayMetrics();
if (size == MaterialProgressDrawable.LARGE) {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER_LARGE * metrics.density);
} else {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
}
// force the bounds of the progress circle inside the circle view to
// update by setting it to null before updating its size and then
// re-setting it
mCircleView.setImageDrawable(null);
mProgress.updateSizes(size);
mCircleView.setImageDrawable(mProgress);
} | [
"public",
"void",
"setSize",
"(",
"int",
"size",
")",
"{",
"if",
"(",
"size",
"!=",
"MaterialProgressDrawable",
".",
"LARGE",
"&&",
"size",
"!=",
"MaterialProgressDrawable",
".",
"DEFAULT",
")",
"{",
"return",
";",
"}",
"final",
"DisplayMetrics",
"metrics",
"=",
"getResources",
"(",
")",
".",
"getDisplayMetrics",
"(",
")",
";",
"if",
"(",
"size",
"==",
"MaterialProgressDrawable",
".",
"LARGE",
")",
"{",
"mCircleHeight",
"=",
"mCircleWidth",
"=",
"(",
"int",
")",
"(",
"CIRCLE_DIAMETER_LARGE",
"*",
"metrics",
".",
"density",
")",
";",
"}",
"else",
"{",
"mCircleHeight",
"=",
"mCircleWidth",
"=",
"(",
"int",
")",
"(",
"CIRCLE_DIAMETER",
"*",
"metrics",
".",
"density",
")",
";",
"}",
"// force the bounds of the progress circle inside the circle view to",
"// update by setting it to null before updating its size and then",
"// re-setting it",
"mCircleView",
".",
"setImageDrawable",
"(",
"null",
")",
";",
"mProgress",
".",
"updateSizes",
"(",
"size",
")",
";",
"mCircleView",
".",
"setImageDrawable",
"(",
"mProgress",
")",
";",
"}"
] | One of DEFAULT, or LARGE. | [
"One",
"of",
"DEFAULT",
"or",
"LARGE",
"."
] | 890e92d7f2779dce85d3358093135d6b3be58986 | https://github.com/omadahealth/SwipyRefreshLayout/blob/890e92d7f2779dce85d3358093135d6b3be58986/lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java#L246-L262 |
162,655 | omadahealth/SwipyRefreshLayout | lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java | SwipyRefreshLayout.setRefreshing | public void setRefreshing(boolean refreshing) {
if (refreshing && mRefreshing != refreshing) {
// scale and show
mRefreshing = refreshing;
int endTarget = 0;
if (!mUsingCustomStart) {
switch (mDirection) {
case BOTTOM:
endTarget = getMeasuredHeight() - (int) (mSpinnerFinalOffset);
break;
case TOP:
default:
endTarget = (int) (mSpinnerFinalOffset - Math.abs(mOriginalOffsetTop));
break;
}
} else {
endTarget = (int) mSpinnerFinalOffset;
}
setTargetOffsetTopAndBottom(endTarget - mCurrentTargetOffsetTop,
true /* requires update */);
mNotify = false;
startScaleUpAnimation(mRefreshListener);
} else {
setRefreshing(refreshing, false /* notify */);
}
} | java | public void setRefreshing(boolean refreshing) {
if (refreshing && mRefreshing != refreshing) {
// scale and show
mRefreshing = refreshing;
int endTarget = 0;
if (!mUsingCustomStart) {
switch (mDirection) {
case BOTTOM:
endTarget = getMeasuredHeight() - (int) (mSpinnerFinalOffset);
break;
case TOP:
default:
endTarget = (int) (mSpinnerFinalOffset - Math.abs(mOriginalOffsetTop));
break;
}
} else {
endTarget = (int) mSpinnerFinalOffset;
}
setTargetOffsetTopAndBottom(endTarget - mCurrentTargetOffsetTop,
true /* requires update */);
mNotify = false;
startScaleUpAnimation(mRefreshListener);
} else {
setRefreshing(refreshing, false /* notify */);
}
} | [
"public",
"void",
"setRefreshing",
"(",
"boolean",
"refreshing",
")",
"{",
"if",
"(",
"refreshing",
"&&",
"mRefreshing",
"!=",
"refreshing",
")",
"{",
"// scale and show",
"mRefreshing",
"=",
"refreshing",
";",
"int",
"endTarget",
"=",
"0",
";",
"if",
"(",
"!",
"mUsingCustomStart",
")",
"{",
"switch",
"(",
"mDirection",
")",
"{",
"case",
"BOTTOM",
":",
"endTarget",
"=",
"getMeasuredHeight",
"(",
")",
"-",
"(",
"int",
")",
"(",
"mSpinnerFinalOffset",
")",
";",
"break",
";",
"case",
"TOP",
":",
"default",
":",
"endTarget",
"=",
"(",
"int",
")",
"(",
"mSpinnerFinalOffset",
"-",
"Math",
".",
"abs",
"(",
"mOriginalOffsetTop",
")",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"endTarget",
"=",
"(",
"int",
")",
"mSpinnerFinalOffset",
";",
"}",
"setTargetOffsetTopAndBottom",
"(",
"endTarget",
"-",
"mCurrentTargetOffsetTop",
",",
"true",
"/* requires update */",
")",
";",
"mNotify",
"=",
"false",
";",
"startScaleUpAnimation",
"(",
"mRefreshListener",
")",
";",
"}",
"else",
"{",
"setRefreshing",
"(",
"refreshing",
",",
"false",
"/* notify */",
")",
";",
"}",
"}"
] | Notify the widget that refresh state has changed. Do not call this when
refresh is triggered by a swipe gesture.
@param refreshing Whether or not the view should show refresh progress. | [
"Notify",
"the",
"widget",
"that",
"refresh",
"state",
"has",
"changed",
".",
"Do",
"not",
"call",
"this",
"when",
"refresh",
"is",
"triggered",
"by",
"a",
"swipe",
"gesture",
"."
] | 890e92d7f2779dce85d3358093135d6b3be58986 | https://github.com/omadahealth/SwipyRefreshLayout/blob/890e92d7f2779dce85d3358093135d6b3be58986/lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java#L361-L386 |
162,656 | omadahealth/SwipyRefreshLayout | lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java | SwipyRefreshLayout.setAnimationProgress | private void setAnimationProgress(float progress) {
if (isAlphaUsedForScale()) {
setColorViewAlpha((int) (progress * MAX_ALPHA));
} else {
ViewCompat.setScaleX(mCircleView, progress);
ViewCompat.setScaleY(mCircleView, progress);
}
} | java | private void setAnimationProgress(float progress) {
if (isAlphaUsedForScale()) {
setColorViewAlpha((int) (progress * MAX_ALPHA));
} else {
ViewCompat.setScaleX(mCircleView, progress);
ViewCompat.setScaleY(mCircleView, progress);
}
} | [
"private",
"void",
"setAnimationProgress",
"(",
"float",
"progress",
")",
"{",
"if",
"(",
"isAlphaUsedForScale",
"(",
")",
")",
"{",
"setColorViewAlpha",
"(",
"(",
"int",
")",
"(",
"progress",
"*",
"MAX_ALPHA",
")",
")",
";",
"}",
"else",
"{",
"ViewCompat",
".",
"setScaleX",
"(",
"mCircleView",
",",
"progress",
")",
";",
"ViewCompat",
".",
"setScaleY",
"(",
"mCircleView",
",",
"progress",
")",
";",
"}",
"}"
] | Pre API 11, this does an alpha animation.
@param progress | [
"Pre",
"API",
"11",
"this",
"does",
"an",
"alpha",
"animation",
"."
] | 890e92d7f2779dce85d3358093135d6b3be58986 | https://github.com/omadahealth/SwipyRefreshLayout/blob/890e92d7f2779dce85d3358093135d6b3be58986/lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java#L415-L422 |
162,657 | omadahealth/SwipyRefreshLayout | lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java | SwipyRefreshLayout.setProgressBackgroundColor | public void setProgressBackgroundColor(int colorRes) {
mCircleView.setBackgroundColor(colorRes);
mProgress.setBackgroundColor(getResources().getColor(colorRes));
} | java | public void setProgressBackgroundColor(int colorRes) {
mCircleView.setBackgroundColor(colorRes);
mProgress.setBackgroundColor(getResources().getColor(colorRes));
} | [
"public",
"void",
"setProgressBackgroundColor",
"(",
"int",
"colorRes",
")",
"{",
"mCircleView",
".",
"setBackgroundColor",
"(",
"colorRes",
")",
";",
"mProgress",
".",
"setBackgroundColor",
"(",
"getResources",
"(",
")",
".",
"getColor",
"(",
"colorRes",
")",
")",
";",
"}"
] | Set the background color of the progress spinner disc.
@param colorRes Resource id of the color. | [
"Set",
"the",
"background",
"color",
"of",
"the",
"progress",
"spinner",
"disc",
"."
] | 890e92d7f2779dce85d3358093135d6b3be58986 | https://github.com/omadahealth/SwipyRefreshLayout/blob/890e92d7f2779dce85d3358093135d6b3be58986/lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java#L485-L488 |
162,658 | omadahealth/SwipyRefreshLayout | lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java | SwipyRefreshLayout.setRawDirection | private void setRawDirection(SwipyRefreshLayoutDirection direction) {
if (mDirection == direction) {
return;
}
mDirection = direction;
switch (mDirection) {
case BOTTOM:
mCurrentTargetOffsetTop = mOriginalOffsetTop = getMeasuredHeight();
break;
case TOP:
default:
mCurrentTargetOffsetTop = mOriginalOffsetTop = -mCircleView.getMeasuredHeight();
break;
}
} | java | private void setRawDirection(SwipyRefreshLayoutDirection direction) {
if (mDirection == direction) {
return;
}
mDirection = direction;
switch (mDirection) {
case BOTTOM:
mCurrentTargetOffsetTop = mOriginalOffsetTop = getMeasuredHeight();
break;
case TOP:
default:
mCurrentTargetOffsetTop = mOriginalOffsetTop = -mCircleView.getMeasuredHeight();
break;
}
} | [
"private",
"void",
"setRawDirection",
"(",
"SwipyRefreshLayoutDirection",
"direction",
")",
"{",
"if",
"(",
"mDirection",
"==",
"direction",
")",
"{",
"return",
";",
"}",
"mDirection",
"=",
"direction",
";",
"switch",
"(",
"mDirection",
")",
"{",
"case",
"BOTTOM",
":",
"mCurrentTargetOffsetTop",
"=",
"mOriginalOffsetTop",
"=",
"getMeasuredHeight",
"(",
")",
";",
"break",
";",
"case",
"TOP",
":",
"default",
":",
"mCurrentTargetOffsetTop",
"=",
"mOriginalOffsetTop",
"=",
"-",
"mCircleView",
".",
"getMeasuredHeight",
"(",
")",
";",
"break",
";",
"}",
"}"
] | only TOP or Bottom | [
"only",
"TOP",
"or",
"Bottom"
] | 890e92d7f2779dce85d3358093135d6b3be58986 | https://github.com/omadahealth/SwipyRefreshLayout/blob/890e92d7f2779dce85d3358093135d6b3be58986/lib/src/main/java/com/orangegangsters/github/swipyrefreshlayout/library/SwipyRefreshLayout.java#L1136-L1151 |
162,659 | sksamuel/scrimage | scrimage-core/src/main/java/com/sksamuel/scrimage/PixelTools.java | PixelTools.uniform | public static boolean uniform(Color color, Pixel[] pixels) {
return Arrays.stream(pixels).allMatch(p -> p.toInt() == color.toRGB().toInt());
} | java | public static boolean uniform(Color color, Pixel[] pixels) {
return Arrays.stream(pixels).allMatch(p -> p.toInt() == color.toRGB().toInt());
} | [
"public",
"static",
"boolean",
"uniform",
"(",
"Color",
"color",
",",
"Pixel",
"[",
"]",
"pixels",
")",
"{",
"return",
"Arrays",
".",
"stream",
"(",
"pixels",
")",
".",
"allMatch",
"(",
"p",
"->",
"p",
".",
"toInt",
"(",
")",
"==",
"color",
".",
"toRGB",
"(",
")",
".",
"toInt",
"(",
")",
")",
";",
"}"
] | Returns true if all pixels in the array have the same color | [
"Returns",
"true",
"if",
"all",
"pixels",
"in",
"the",
"array",
"have",
"the",
"same",
"color"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-core/src/main/java/com/sksamuel/scrimage/PixelTools.java#L74-L76 |
162,660 | sksamuel/scrimage | scrimage-core/src/main/java/com/sksamuel/scrimage/PixelTools.java | PixelTools.scale | public static int scale(Double factor, int pixel) {
return rgb(
(int) Math.round(factor * red(pixel)),
(int) Math.round(factor * green(pixel)),
(int) Math.round(factor * blue(pixel))
);
} | java | public static int scale(Double factor, int pixel) {
return rgb(
(int) Math.round(factor * red(pixel)),
(int) Math.round(factor * green(pixel)),
(int) Math.round(factor * blue(pixel))
);
} | [
"public",
"static",
"int",
"scale",
"(",
"Double",
"factor",
",",
"int",
"pixel",
")",
"{",
"return",
"rgb",
"(",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"factor",
"*",
"red",
"(",
"pixel",
")",
")",
",",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"factor",
"*",
"green",
"(",
"pixel",
")",
")",
",",
"(",
"int",
")",
"Math",
".",
"round",
"(",
"factor",
"*",
"blue",
"(",
"pixel",
")",
")",
")",
";",
"}"
] | Scales the brightness of a pixel. | [
"Scales",
"the",
"brightness",
"of",
"a",
"pixel",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-core/src/main/java/com/sksamuel/scrimage/PixelTools.java#L81-L87 |
162,661 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinAttributes.java | MarvinAttributes.set | public void set(String name, Object value) {
hashAttributes.put(name, value);
if (plugin != null) {
plugin.invalidate();
}
} | java | public void set(String name, Object value) {
hashAttributes.put(name, value);
if (plugin != null) {
plugin.invalidate();
}
} | [
"public",
"void",
"set",
"(",
"String",
"name",
",",
"Object",
"value",
")",
"{",
"hashAttributes",
".",
"put",
"(",
"name",
",",
"value",
")",
";",
"if",
"(",
"plugin",
"!=",
"null",
")",
"{",
"plugin",
".",
"invalidate",
"(",
")",
";",
"}",
"}"
] | Set an attribute.
@param name attribute name.
@param value attribute value. | [
"Set",
"an",
"attribute",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinAttributes.java#L34-L40 |
162,662 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Spectrum.java | Spectrum.wavelengthToRGB | public static int wavelengthToRGB(float wavelength) {
float gamma = 0.80f;
float r, g, b, factor;
int w = (int)wavelength;
if (w < 380) {
r = 0.0f;
g = 0.0f;
b = 0.0f;
} else if (w < 440) {
r = -(wavelength - 440) / (440 - 380);
g = 0.0f;
b = 1.0f;
} else if (w < 490) {
r = 0.0f;
g = (wavelength - 440) / (490 - 440);
b = 1.0f;
} else if (w < 510) {
r = 0.0f;
g = 1.0f;
b = -(wavelength - 510) / (510 - 490);
} else if (w < 580) {
r = (wavelength - 510) / (580 - 510);
g = 1.0f;
b = 0.0f;
} else if (w < 645) {
r = 1.0f;
g = -(wavelength - 645) / (645 - 580);
b = 0.0f;
} else if (w <= 780) {
r = 1.0f;
g = 0.0f;
b = 0.0f;
} else {
r = 0.0f;
g = 0.0f;
b = 0.0f;
}
// Let the intensity fall off near the vision limits
if (380 <= w && w <= 419)
factor = 0.3f + 0.7f*(wavelength - 380) / (420 - 380);
else if (420 <= w && w <= 700)
factor = 1.0f;
else if (701 <= w && w <= 780)
factor = 0.3f + 0.7f*(780 - wavelength) / (780 - 700);
else
factor = 0.0f;
int ir = adjust(r, factor, gamma);
int ig = adjust(g, factor, gamma);
int ib = adjust(b, factor, gamma);
return 0xff000000 | (ir << 16) | (ig << 8) | ib;
} | java | public static int wavelengthToRGB(float wavelength) {
float gamma = 0.80f;
float r, g, b, factor;
int w = (int)wavelength;
if (w < 380) {
r = 0.0f;
g = 0.0f;
b = 0.0f;
} else if (w < 440) {
r = -(wavelength - 440) / (440 - 380);
g = 0.0f;
b = 1.0f;
} else if (w < 490) {
r = 0.0f;
g = (wavelength - 440) / (490 - 440);
b = 1.0f;
} else if (w < 510) {
r = 0.0f;
g = 1.0f;
b = -(wavelength - 510) / (510 - 490);
} else if (w < 580) {
r = (wavelength - 510) / (580 - 510);
g = 1.0f;
b = 0.0f;
} else if (w < 645) {
r = 1.0f;
g = -(wavelength - 645) / (645 - 580);
b = 0.0f;
} else if (w <= 780) {
r = 1.0f;
g = 0.0f;
b = 0.0f;
} else {
r = 0.0f;
g = 0.0f;
b = 0.0f;
}
// Let the intensity fall off near the vision limits
if (380 <= w && w <= 419)
factor = 0.3f + 0.7f*(wavelength - 380) / (420 - 380);
else if (420 <= w && w <= 700)
factor = 1.0f;
else if (701 <= w && w <= 780)
factor = 0.3f + 0.7f*(780 - wavelength) / (780 - 700);
else
factor = 0.0f;
int ir = adjust(r, factor, gamma);
int ig = adjust(g, factor, gamma);
int ib = adjust(b, factor, gamma);
return 0xff000000 | (ir << 16) | (ig << 8) | ib;
} | [
"public",
"static",
"int",
"wavelengthToRGB",
"(",
"float",
"wavelength",
")",
"{",
"float",
"gamma",
"=",
"0.80f",
";",
"float",
"r",
",",
"g",
",",
"b",
",",
"factor",
";",
"int",
"w",
"=",
"(",
"int",
")",
"wavelength",
";",
"if",
"(",
"w",
"<",
"380",
")",
"{",
"r",
"=",
"0.0f",
";",
"g",
"=",
"0.0f",
";",
"b",
"=",
"0.0f",
";",
"}",
"else",
"if",
"(",
"w",
"<",
"440",
")",
"{",
"r",
"=",
"-",
"(",
"wavelength",
"-",
"440",
")",
"/",
"(",
"440",
"-",
"380",
")",
";",
"g",
"=",
"0.0f",
";",
"b",
"=",
"1.0f",
";",
"}",
"else",
"if",
"(",
"w",
"<",
"490",
")",
"{",
"r",
"=",
"0.0f",
";",
"g",
"=",
"(",
"wavelength",
"-",
"440",
")",
"/",
"(",
"490",
"-",
"440",
")",
";",
"b",
"=",
"1.0f",
";",
"}",
"else",
"if",
"(",
"w",
"<",
"510",
")",
"{",
"r",
"=",
"0.0f",
";",
"g",
"=",
"1.0f",
";",
"b",
"=",
"-",
"(",
"wavelength",
"-",
"510",
")",
"/",
"(",
"510",
"-",
"490",
")",
";",
"}",
"else",
"if",
"(",
"w",
"<",
"580",
")",
"{",
"r",
"=",
"(",
"wavelength",
"-",
"510",
")",
"/",
"(",
"580",
"-",
"510",
")",
";",
"g",
"=",
"1.0f",
";",
"b",
"=",
"0.0f",
";",
"}",
"else",
"if",
"(",
"w",
"<",
"645",
")",
"{",
"r",
"=",
"1.0f",
";",
"g",
"=",
"-",
"(",
"wavelength",
"-",
"645",
")",
"/",
"(",
"645",
"-",
"580",
")",
";",
"b",
"=",
"0.0f",
";",
"}",
"else",
"if",
"(",
"w",
"<=",
"780",
")",
"{",
"r",
"=",
"1.0f",
";",
"g",
"=",
"0.0f",
";",
"b",
"=",
"0.0f",
";",
"}",
"else",
"{",
"r",
"=",
"0.0f",
";",
"g",
"=",
"0.0f",
";",
"b",
"=",
"0.0f",
";",
"}",
"// Let the intensity fall off near the vision limits",
"if",
"(",
"380",
"<=",
"w",
"&&",
"w",
"<=",
"419",
")",
"factor",
"=",
"0.3f",
"+",
"0.7f",
"*",
"(",
"wavelength",
"-",
"380",
")",
"/",
"(",
"420",
"-",
"380",
")",
";",
"else",
"if",
"(",
"420",
"<=",
"w",
"&&",
"w",
"<=",
"700",
")",
"factor",
"=",
"1.0f",
";",
"else",
"if",
"(",
"701",
"<=",
"w",
"&&",
"w",
"<=",
"780",
")",
"factor",
"=",
"0.3f",
"+",
"0.7f",
"*",
"(",
"780",
"-",
"wavelength",
")",
"/",
"(",
"780",
"-",
"700",
")",
";",
"else",
"factor",
"=",
"0.0f",
";",
"int",
"ir",
"=",
"adjust",
"(",
"r",
",",
"factor",
",",
"gamma",
")",
";",
"int",
"ig",
"=",
"adjust",
"(",
"g",
",",
"factor",
",",
"gamma",
")",
";",
"int",
"ib",
"=",
"adjust",
"(",
"b",
",",
"factor",
",",
"gamma",
")",
";",
"return",
"0xff000000",
"|",
"(",
"ir",
"<<",
"16",
")",
"|",
"(",
"ig",
"<<",
"8",
")",
"|",
"ib",
";",
"}"
] | Convert a wavelength to an RGB value.
@param wavelength wavelength in nanometres
@return the RGB value | [
"Convert",
"a",
"wavelength",
"to",
"an",
"RGB",
"value",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Spectrum.java#L35-L89 |
162,663 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ConvolveFilter.java | ConvolveFilter.convolveHV | public static void convolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) {
int index = 0;
float[] matrix = kernel.getKernelData( null );
int rows = kernel.getHeight();
int cols = kernel.getWidth();
int rows2 = rows/2;
int cols2 = cols/2;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
float r = 0, g = 0, b = 0, a = 0;
for (int row = -rows2; row <= rows2; row++) {
int iy = y+row;
int ioffset;
if (0 <= iy && iy < height)
ioffset = iy*width;
else if ( edgeAction == CLAMP_EDGES )
ioffset = y*width;
else if ( edgeAction == WRAP_EDGES )
ioffset = ((iy+height) % height) * width;
else
continue;
int moffset = cols*(row+rows2)+cols2;
for (int col = -cols2; col <= cols2; col++) {
float f = matrix[moffset+col];
if (f != 0) {
int ix = x+col;
if (!(0 <= ix && ix < width)) {
if ( edgeAction == CLAMP_EDGES )
ix = x;
else if ( edgeAction == WRAP_EDGES )
ix = (x+width) % width;
else
continue;
}
int rgb = inPixels[ioffset+ix];
a += f * ((rgb >> 24) & 0xff);
r += f * ((rgb >> 16) & 0xff);
g += f * ((rgb >> 8) & 0xff);
b += f * (rgb & 0xff);
}
}
}
int ia = alpha ? PixelUtils.clamp((int)(a+0.5)) : 0xff;
int ir = PixelUtils.clamp((int)(r+0.5));
int ig = PixelUtils.clamp((int)(g+0.5));
int ib = PixelUtils.clamp((int)(b+0.5));
outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
}
}
} | java | public static void convolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) {
int index = 0;
float[] matrix = kernel.getKernelData( null );
int rows = kernel.getHeight();
int cols = kernel.getWidth();
int rows2 = rows/2;
int cols2 = cols/2;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
float r = 0, g = 0, b = 0, a = 0;
for (int row = -rows2; row <= rows2; row++) {
int iy = y+row;
int ioffset;
if (0 <= iy && iy < height)
ioffset = iy*width;
else if ( edgeAction == CLAMP_EDGES )
ioffset = y*width;
else if ( edgeAction == WRAP_EDGES )
ioffset = ((iy+height) % height) * width;
else
continue;
int moffset = cols*(row+rows2)+cols2;
for (int col = -cols2; col <= cols2; col++) {
float f = matrix[moffset+col];
if (f != 0) {
int ix = x+col;
if (!(0 <= ix && ix < width)) {
if ( edgeAction == CLAMP_EDGES )
ix = x;
else if ( edgeAction == WRAP_EDGES )
ix = (x+width) % width;
else
continue;
}
int rgb = inPixels[ioffset+ix];
a += f * ((rgb >> 24) & 0xff);
r += f * ((rgb >> 16) & 0xff);
g += f * ((rgb >> 8) & 0xff);
b += f * (rgb & 0xff);
}
}
}
int ia = alpha ? PixelUtils.clamp((int)(a+0.5)) : 0xff;
int ir = PixelUtils.clamp((int)(r+0.5));
int ig = PixelUtils.clamp((int)(g+0.5));
int ib = PixelUtils.clamp((int)(b+0.5));
outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib;
}
}
} | [
"public",
"static",
"void",
"convolveHV",
"(",
"Kernel",
"kernel",
",",
"int",
"[",
"]",
"inPixels",
",",
"int",
"[",
"]",
"outPixels",
",",
"int",
"width",
",",
"int",
"height",
",",
"boolean",
"alpha",
",",
"int",
"edgeAction",
")",
"{",
"int",
"index",
"=",
"0",
";",
"float",
"[",
"]",
"matrix",
"=",
"kernel",
".",
"getKernelData",
"(",
"null",
")",
";",
"int",
"rows",
"=",
"kernel",
".",
"getHeight",
"(",
")",
";",
"int",
"cols",
"=",
"kernel",
".",
"getWidth",
"(",
")",
";",
"int",
"rows2",
"=",
"rows",
"/",
"2",
";",
"int",
"cols2",
"=",
"cols",
"/",
"2",
";",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"height",
";",
"y",
"++",
")",
"{",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"width",
";",
"x",
"++",
")",
"{",
"float",
"r",
"=",
"0",
",",
"g",
"=",
"0",
",",
"b",
"=",
"0",
",",
"a",
"=",
"0",
";",
"for",
"(",
"int",
"row",
"=",
"-",
"rows2",
";",
"row",
"<=",
"rows2",
";",
"row",
"++",
")",
"{",
"int",
"iy",
"=",
"y",
"+",
"row",
";",
"int",
"ioffset",
";",
"if",
"(",
"0",
"<=",
"iy",
"&&",
"iy",
"<",
"height",
")",
"ioffset",
"=",
"iy",
"*",
"width",
";",
"else",
"if",
"(",
"edgeAction",
"==",
"CLAMP_EDGES",
")",
"ioffset",
"=",
"y",
"*",
"width",
";",
"else",
"if",
"(",
"edgeAction",
"==",
"WRAP_EDGES",
")",
"ioffset",
"=",
"(",
"(",
"iy",
"+",
"height",
")",
"%",
"height",
")",
"*",
"width",
";",
"else",
"continue",
";",
"int",
"moffset",
"=",
"cols",
"*",
"(",
"row",
"+",
"rows2",
")",
"+",
"cols2",
";",
"for",
"(",
"int",
"col",
"=",
"-",
"cols2",
";",
"col",
"<=",
"cols2",
";",
"col",
"++",
")",
"{",
"float",
"f",
"=",
"matrix",
"[",
"moffset",
"+",
"col",
"]",
";",
"if",
"(",
"f",
"!=",
"0",
")",
"{",
"int",
"ix",
"=",
"x",
"+",
"col",
";",
"if",
"(",
"!",
"(",
"0",
"<=",
"ix",
"&&",
"ix",
"<",
"width",
")",
")",
"{",
"if",
"(",
"edgeAction",
"==",
"CLAMP_EDGES",
")",
"ix",
"=",
"x",
";",
"else",
"if",
"(",
"edgeAction",
"==",
"WRAP_EDGES",
")",
"ix",
"=",
"(",
"x",
"+",
"width",
")",
"%",
"width",
";",
"else",
"continue",
";",
"}",
"int",
"rgb",
"=",
"inPixels",
"[",
"ioffset",
"+",
"ix",
"]",
";",
"a",
"+=",
"f",
"*",
"(",
"(",
"rgb",
">>",
"24",
")",
"&",
"0xff",
")",
";",
"r",
"+=",
"f",
"*",
"(",
"(",
"rgb",
">>",
"16",
")",
"&",
"0xff",
")",
";",
"g",
"+=",
"f",
"*",
"(",
"(",
"rgb",
">>",
"8",
")",
"&",
"0xff",
")",
";",
"b",
"+=",
"f",
"*",
"(",
"rgb",
"&",
"0xff",
")",
";",
"}",
"}",
"}",
"int",
"ia",
"=",
"alpha",
"?",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"a",
"+",
"0.5",
")",
")",
":",
"0xff",
";",
"int",
"ir",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"r",
"+",
"0.5",
")",
")",
";",
"int",
"ig",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"g",
"+",
"0.5",
")",
")",
";",
"int",
"ib",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"b",
"+",
"0.5",
")",
")",
";",
"outPixels",
"[",
"index",
"++",
"]",
"=",
"(",
"ia",
"<<",
"24",
")",
"|",
"(",
"ir",
"<<",
"16",
")",
"|",
"(",
"ig",
"<<",
"8",
")",
"|",
"ib",
";",
"}",
"}",
"}"
] | Convolve with a 2D kernel.
@param kernel the kernel
@param inPixels the input pixels
@param outPixels the output pixels
@param width the width
@param height the height
@param alpha include alpha channel
@param edgeAction what to do at the edges | [
"Convolve",
"with",
"a",
"2D",
"kernel",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ConvolveFilter.java#L253-L305 |
162,664 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/misc/DaisyFilter.java | DaisyFilter.initPixelsArray | private void initPixelsArray(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
pixels = new int[width * height];
image.getRGB(0, 0, width, height, pixels, 0, width);
} | java | private void initPixelsArray(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
pixels = new int[width * height];
image.getRGB(0, 0, width, height, pixels, 0, width);
} | [
"private",
"void",
"initPixelsArray",
"(",
"BufferedImage",
"image",
")",
"{",
"int",
"width",
"=",
"image",
".",
"getWidth",
"(",
")",
";",
"int",
"height",
"=",
"image",
".",
"getHeight",
"(",
")",
";",
"pixels",
"=",
"new",
"int",
"[",
"width",
"*",
"height",
"]",
";",
"image",
".",
"getRGB",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
",",
"pixels",
",",
"0",
",",
"width",
")",
";",
"}"
] | takes the pixels from a BufferedImage and stores them in an array | [
"takes",
"the",
"pixels",
"from",
"a",
"BufferedImage",
"and",
"stores",
"them",
"in",
"an",
"array"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/misc/DaisyFilter.java#L158-L164 |
162,665 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/misc/DaisyFilter.java | DaisyFilter.changeColor | private int[] changeColor() {
int[] changedPixels = new int[pixels.length];
double frequenz = 2 * Math.PI / 1020;
for (int i = 0; i < pixels.length; i++) {
int argb = pixels[i];
int a = (argb >> 24) & 0xff;
int r = (argb >> 16) & 0xff;
int g = (argb >> 8) & 0xff;
int b = argb & 0xff;
r = (int) (255 * Math.sin(frequenz * r));
b = (int) (-255 * Math.cos(frequenz * b) + 255);
changedPixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
}
return changedPixels;
} | java | private int[] changeColor() {
int[] changedPixels = new int[pixels.length];
double frequenz = 2 * Math.PI / 1020;
for (int i = 0; i < pixels.length; i++) {
int argb = pixels[i];
int a = (argb >> 24) & 0xff;
int r = (argb >> 16) & 0xff;
int g = (argb >> 8) & 0xff;
int b = argb & 0xff;
r = (int) (255 * Math.sin(frequenz * r));
b = (int) (-255 * Math.cos(frequenz * b) + 255);
changedPixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
}
return changedPixels;
} | [
"private",
"int",
"[",
"]",
"changeColor",
"(",
")",
"{",
"int",
"[",
"]",
"changedPixels",
"=",
"new",
"int",
"[",
"pixels",
".",
"length",
"]",
";",
"double",
"frequenz",
"=",
"2",
"*",
"Math",
".",
"PI",
"/",
"1020",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"pixels",
".",
"length",
";",
"i",
"++",
")",
"{",
"int",
"argb",
"=",
"pixels",
"[",
"i",
"]",
";",
"int",
"a",
"=",
"(",
"argb",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r",
"=",
"(",
"argb",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g",
"=",
"(",
"argb",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b",
"=",
"argb",
"&",
"0xff",
";",
"r",
"=",
"(",
"int",
")",
"(",
"255",
"*",
"Math",
".",
"sin",
"(",
"frequenz",
"*",
"r",
")",
")",
";",
"b",
"=",
"(",
"int",
")",
"(",
"-",
"255",
"*",
"Math",
".",
"cos",
"(",
"frequenz",
"*",
"b",
")",
"+",
"255",
")",
";",
"changedPixels",
"[",
"i",
"]",
"=",
"(",
"a",
"<<",
"24",
")",
"|",
"(",
"r",
"<<",
"16",
")",
"|",
"(",
"g",
"<<",
"8",
")",
"|",
"b",
";",
"}",
"return",
"changedPixels",
";",
"}"
] | changes the color of the image - more red and less blue
@return new pixel array | [
"changes",
"the",
"color",
"of",
"the",
"image",
"-",
"more",
"red",
"and",
"less",
"blue"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/misc/DaisyFilter.java#L171-L189 |
162,666 | sksamuel/scrimage | scrimage-core/src/main/java/com/sksamuel/scrimage/Orientation.java | Orientation.imageOrientationsOf | private static Set<String> imageOrientationsOf(ImageMetadata metadata) {
String exifIFD0DirName = new ExifIFD0Directory().getName();
Tag[] tags = Arrays.stream(metadata.getDirectories())
.filter(dir -> dir.getName().equals(exifIFD0DirName))
.findFirst()
.map(Directory::getTags)
.orElseGet(() -> new Tag[0]);
return Arrays.stream(tags)
.filter(tag -> tag.getType() == 274)
.map(Tag::getRawValue)
.collect(Collectors.toSet());
} | java | private static Set<String> imageOrientationsOf(ImageMetadata metadata) {
String exifIFD0DirName = new ExifIFD0Directory().getName();
Tag[] tags = Arrays.stream(metadata.getDirectories())
.filter(dir -> dir.getName().equals(exifIFD0DirName))
.findFirst()
.map(Directory::getTags)
.orElseGet(() -> new Tag[0]);
return Arrays.stream(tags)
.filter(tag -> tag.getType() == 274)
.map(Tag::getRawValue)
.collect(Collectors.toSet());
} | [
"private",
"static",
"Set",
"<",
"String",
">",
"imageOrientationsOf",
"(",
"ImageMetadata",
"metadata",
")",
"{",
"String",
"exifIFD0DirName",
"=",
"new",
"ExifIFD0Directory",
"(",
")",
".",
"getName",
"(",
")",
";",
"Tag",
"[",
"]",
"tags",
"=",
"Arrays",
".",
"stream",
"(",
"metadata",
".",
"getDirectories",
"(",
")",
")",
".",
"filter",
"(",
"dir",
"->",
"dir",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"exifIFD0DirName",
")",
")",
".",
"findFirst",
"(",
")",
".",
"map",
"(",
"Directory",
"::",
"getTags",
")",
".",
"orElseGet",
"(",
"(",
")",
"->",
"new",
"Tag",
"[",
"0",
"]",
")",
";",
"return",
"Arrays",
".",
"stream",
"(",
"tags",
")",
".",
"filter",
"(",
"tag",
"->",
"tag",
".",
"getType",
"(",
")",
"==",
"274",
")",
".",
"map",
"(",
"Tag",
"::",
"getRawValue",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"}"
] | returns the values of the orientation tag | [
"returns",
"the",
"values",
"of",
"the",
"orientation",
"tag"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-core/src/main/java/com/sksamuel/scrimage/Orientation.java#L65-L79 |
162,667 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/math/Noise.java | Noise.noise1 | public static float noise1(float x) {
int bx0, bx1;
float rx0, rx1, sx, t, u, v;
if (start) {
start = false;
init();
}
t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0+1) & BM;
rx0 = t - (int)t;
rx1 = rx0 - 1.0f;
sx = sCurve(rx0);
u = rx0 * g1[p[bx0]];
v = rx1 * g1[p[bx1]];
return 2.3f*lerp(sx, u, v);
} | java | public static float noise1(float x) {
int bx0, bx1;
float rx0, rx1, sx, t, u, v;
if (start) {
start = false;
init();
}
t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0+1) & BM;
rx0 = t - (int)t;
rx1 = rx0 - 1.0f;
sx = sCurve(rx0);
u = rx0 * g1[p[bx0]];
v = rx1 * g1[p[bx1]];
return 2.3f*lerp(sx, u, v);
} | [
"public",
"static",
"float",
"noise1",
"(",
"float",
"x",
")",
"{",
"int",
"bx0",
",",
"bx1",
";",
"float",
"rx0",
",",
"rx1",
",",
"sx",
",",
"t",
",",
"u",
",",
"v",
";",
"if",
"(",
"start",
")",
"{",
"start",
"=",
"false",
";",
"init",
"(",
")",
";",
"}",
"t",
"=",
"x",
"+",
"N",
";",
"bx0",
"=",
"(",
"(",
"int",
")",
"t",
")",
"&",
"BM",
";",
"bx1",
"=",
"(",
"bx0",
"+",
"1",
")",
"&",
"BM",
";",
"rx0",
"=",
"t",
"-",
"(",
"int",
")",
"t",
";",
"rx1",
"=",
"rx0",
"-",
"1.0f",
";",
"sx",
"=",
"sCurve",
"(",
"rx0",
")",
";",
"u",
"=",
"rx0",
"*",
"g1",
"[",
"p",
"[",
"bx0",
"]",
"]",
";",
"v",
"=",
"rx1",
"*",
"g1",
"[",
"p",
"[",
"bx1",
"]",
"]",
";",
"return",
"2.3f",
"*",
"lerp",
"(",
"sx",
",",
"u",
",",
"v",
")",
";",
"}"
] | Compute 1-dimensional Perlin noise.
@param x the x value
@return noise value at x in the range -1..1 | [
"Compute",
"1",
"-",
"dimensional",
"Perlin",
"noise",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/math/Noise.java#L89-L109 |
162,668 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/math/Noise.java | Noise.noise2 | public static float noise2(float x, float y) {
int bx0, bx1, by0, by1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, q[], sx, sy, a, b, t, u, v;
int i, j;
if (start) {
start = false;
init();
}
t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0+1) & BM;
rx0 = t - (int)t;
rx1 = rx0 - 1.0f;
t = y + N;
by0 = ((int)t) & BM;
by1 = (by0+1) & BM;
ry0 = t - (int)t;
ry1 = ry0 - 1.0f;
i = p[bx0];
j = p[bx1];
b00 = p[i + by0];
b10 = p[j + by0];
b01 = p[i + by1];
b11 = p[j + by1];
sx = sCurve(rx0);
sy = sCurve(ry0);
q = g2[b00]; u = rx0 * q[0] + ry0 * q[1];
q = g2[b10]; v = rx1 * q[0] + ry0 * q[1];
a = lerp(sx, u, v);
q = g2[b01]; u = rx0 * q[0] + ry1 * q[1];
q = g2[b11]; v = rx1 * q[0] + ry1 * q[1];
b = lerp(sx, u, v);
return 1.5f*lerp(sy, a, b);
} | java | public static float noise2(float x, float y) {
int bx0, bx1, by0, by1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, q[], sx, sy, a, b, t, u, v;
int i, j;
if (start) {
start = false;
init();
}
t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0+1) & BM;
rx0 = t - (int)t;
rx1 = rx0 - 1.0f;
t = y + N;
by0 = ((int)t) & BM;
by1 = (by0+1) & BM;
ry0 = t - (int)t;
ry1 = ry0 - 1.0f;
i = p[bx0];
j = p[bx1];
b00 = p[i + by0];
b10 = p[j + by0];
b01 = p[i + by1];
b11 = p[j + by1];
sx = sCurve(rx0);
sy = sCurve(ry0);
q = g2[b00]; u = rx0 * q[0] + ry0 * q[1];
q = g2[b10]; v = rx1 * q[0] + ry0 * q[1];
a = lerp(sx, u, v);
q = g2[b01]; u = rx0 * q[0] + ry1 * q[1];
q = g2[b11]; v = rx1 * q[0] + ry1 * q[1];
b = lerp(sx, u, v);
return 1.5f*lerp(sy, a, b);
} | [
"public",
"static",
"float",
"noise2",
"(",
"float",
"x",
",",
"float",
"y",
")",
"{",
"int",
"bx0",
",",
"bx1",
",",
"by0",
",",
"by1",
",",
"b00",
",",
"b10",
",",
"b01",
",",
"b11",
";",
"float",
"rx0",
",",
"rx1",
",",
"ry0",
",",
"ry1",
",",
"q",
"[",
"]",
",",
"sx",
",",
"sy",
",",
"a",
",",
"b",
",",
"t",
",",
"u",
",",
"v",
";",
"int",
"i",
",",
"j",
";",
"if",
"(",
"start",
")",
"{",
"start",
"=",
"false",
";",
"init",
"(",
")",
";",
"}",
"t",
"=",
"x",
"+",
"N",
";",
"bx0",
"=",
"(",
"(",
"int",
")",
"t",
")",
"&",
"BM",
";",
"bx1",
"=",
"(",
"bx0",
"+",
"1",
")",
"&",
"BM",
";",
"rx0",
"=",
"t",
"-",
"(",
"int",
")",
"t",
";",
"rx1",
"=",
"rx0",
"-",
"1.0f",
";",
"t",
"=",
"y",
"+",
"N",
";",
"by0",
"=",
"(",
"(",
"int",
")",
"t",
")",
"&",
"BM",
";",
"by1",
"=",
"(",
"by0",
"+",
"1",
")",
"&",
"BM",
";",
"ry0",
"=",
"t",
"-",
"(",
"int",
")",
"t",
";",
"ry1",
"=",
"ry0",
"-",
"1.0f",
";",
"i",
"=",
"p",
"[",
"bx0",
"]",
";",
"j",
"=",
"p",
"[",
"bx1",
"]",
";",
"b00",
"=",
"p",
"[",
"i",
"+",
"by0",
"]",
";",
"b10",
"=",
"p",
"[",
"j",
"+",
"by0",
"]",
";",
"b01",
"=",
"p",
"[",
"i",
"+",
"by1",
"]",
";",
"b11",
"=",
"p",
"[",
"j",
"+",
"by1",
"]",
";",
"sx",
"=",
"sCurve",
"(",
"rx0",
")",
";",
"sy",
"=",
"sCurve",
"(",
"ry0",
")",
";",
"q",
"=",
"g2",
"[",
"b00",
"]",
";",
"u",
"=",
"rx0",
"*",
"q",
"[",
"0",
"]",
"+",
"ry0",
"*",
"q",
"[",
"1",
"]",
";",
"q",
"=",
"g2",
"[",
"b10",
"]",
";",
"v",
"=",
"rx1",
"*",
"q",
"[",
"0",
"]",
"+",
"ry0",
"*",
"q",
"[",
"1",
"]",
";",
"a",
"=",
"lerp",
"(",
"sx",
",",
"u",
",",
"v",
")",
";",
"q",
"=",
"g2",
"[",
"b01",
"]",
";",
"u",
"=",
"rx0",
"*",
"q",
"[",
"0",
"]",
"+",
"ry1",
"*",
"q",
"[",
"1",
"]",
";",
"q",
"=",
"g2",
"[",
"b11",
"]",
";",
"v",
"=",
"rx1",
"*",
"q",
"[",
"0",
"]",
"+",
"ry1",
"*",
"q",
"[",
"1",
"]",
";",
"b",
"=",
"lerp",
"(",
"sx",
",",
"u",
",",
"v",
")",
";",
"return",
"1.5f",
"*",
"lerp",
"(",
"sy",
",",
"a",
",",
"b",
")",
";",
"}"
] | Compute 2-dimensional Perlin noise.
@param x the x coordinate
@param y the y coordinate
@return noise value at (x,y) | [
"Compute",
"2",
"-",
"dimensional",
"Perlin",
"noise",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/math/Noise.java#L117-L159 |
162,669 | sksamuel/scrimage | scrimage-core/src/main/java/com/sksamuel/scrimage/LinearSubpixelInterpolator.java | LinearSubpixelInterpolator.integerPixelCoordinatesAndWeights | private List<Pair<Integer, Double>> integerPixelCoordinatesAndWeights(double d, int numPixels) {
if (d <= 0.5) return Collections.singletonList(new Pair<>(0, 1.0));
else if (d >= numPixels - 0.5) return Collections.singletonList(new Pair<>(numPixels - 1, 1.0));
else {
double shifted = d - 0.5;
double floor = Math.floor(shifted);
double floorWeight = 1 - (shifted - floor);
double ceil = Math.ceil(shifted);
double ceilWeight = 1 - floorWeight;
assert (floorWeight + ceilWeight == 1);
return Arrays.asList(new Pair<>((int) floor, floorWeight), new Pair<>((int) ceil, ceilWeight));
}
} | java | private List<Pair<Integer, Double>> integerPixelCoordinatesAndWeights(double d, int numPixels) {
if (d <= 0.5) return Collections.singletonList(new Pair<>(0, 1.0));
else if (d >= numPixels - 0.5) return Collections.singletonList(new Pair<>(numPixels - 1, 1.0));
else {
double shifted = d - 0.5;
double floor = Math.floor(shifted);
double floorWeight = 1 - (shifted - floor);
double ceil = Math.ceil(shifted);
double ceilWeight = 1 - floorWeight;
assert (floorWeight + ceilWeight == 1);
return Arrays.asList(new Pair<>((int) floor, floorWeight), new Pair<>((int) ceil, ceilWeight));
}
} | [
"private",
"List",
"<",
"Pair",
"<",
"Integer",
",",
"Double",
">",
">",
"integerPixelCoordinatesAndWeights",
"(",
"double",
"d",
",",
"int",
"numPixels",
")",
"{",
"if",
"(",
"d",
"<=",
"0.5",
")",
"return",
"Collections",
".",
"singletonList",
"(",
"new",
"Pair",
"<>",
"(",
"0",
",",
"1.0",
")",
")",
";",
"else",
"if",
"(",
"d",
">=",
"numPixels",
"-",
"0.5",
")",
"return",
"Collections",
".",
"singletonList",
"(",
"new",
"Pair",
"<>",
"(",
"numPixels",
"-",
"1",
",",
"1.0",
")",
")",
";",
"else",
"{",
"double",
"shifted",
"=",
"d",
"-",
"0.5",
";",
"double",
"floor",
"=",
"Math",
".",
"floor",
"(",
"shifted",
")",
";",
"double",
"floorWeight",
"=",
"1",
"-",
"(",
"shifted",
"-",
"floor",
")",
";",
"double",
"ceil",
"=",
"Math",
".",
"ceil",
"(",
"shifted",
")",
";",
"double",
"ceilWeight",
"=",
"1",
"-",
"floorWeight",
";",
"assert",
"(",
"floorWeight",
"+",
"ceilWeight",
"==",
"1",
")",
";",
"return",
"Arrays",
".",
"asList",
"(",
"new",
"Pair",
"<>",
"(",
"(",
"int",
")",
"floor",
",",
"floorWeight",
")",
",",
"new",
"Pair",
"<>",
"(",
"(",
"int",
")",
"ceil",
",",
"ceilWeight",
")",
")",
";",
"}",
"}"
] | Operates on one dimension at a time. | [
"Operates",
"on",
"one",
"dimension",
"at",
"a",
"time",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-core/src/main/java/com/sksamuel/scrimage/LinearSubpixelInterpolator.java#L25-L37 |
162,670 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.createImage | public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0)
throw new RuntimeException("Image fetch aborted");
if ((pg.status() & ImageObserver.ERROR) != 0)
throw new RuntimeException("Image fetch error");
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
return p;
} | java | public static BufferedImage createImage(ImageProducer producer) {
PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
try {
pg.grabPixels();
} catch (InterruptedException e) {
throw new RuntimeException("Image fetch interrupted");
}
if ((pg.status() & ImageObserver.ABORT) != 0)
throw new RuntimeException("Image fetch aborted");
if ((pg.status() & ImageObserver.ERROR) != 0)
throw new RuntimeException("Image fetch error");
BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
return p;
} | [
"public",
"static",
"BufferedImage",
"createImage",
"(",
"ImageProducer",
"producer",
")",
"{",
"PixelGrabber",
"pg",
"=",
"new",
"PixelGrabber",
"(",
"producer",
",",
"0",
",",
"0",
",",
"-",
"1",
",",
"-",
"1",
",",
"null",
",",
"0",
",",
"0",
")",
";",
"try",
"{",
"pg",
".",
"grabPixels",
"(",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Image fetch interrupted\"",
")",
";",
"}",
"if",
"(",
"(",
"pg",
".",
"status",
"(",
")",
"&",
"ImageObserver",
".",
"ABORT",
")",
"!=",
"0",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Image fetch aborted\"",
")",
";",
"if",
"(",
"(",
"pg",
".",
"status",
"(",
")",
"&",
"ImageObserver",
".",
"ERROR",
")",
"!=",
"0",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Image fetch error\"",
")",
";",
"BufferedImage",
"p",
"=",
"new",
"BufferedImage",
"(",
"pg",
".",
"getWidth",
"(",
")",
",",
"pg",
".",
"getHeight",
"(",
")",
",",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
";",
"p",
".",
"setRGB",
"(",
"0",
",",
"0",
",",
"pg",
".",
"getWidth",
"(",
")",
",",
"pg",
".",
"getHeight",
"(",
")",
",",
"(",
"int",
"[",
"]",
")",
"pg",
".",
"getPixels",
"(",
")",
",",
"0",
",",
"pg",
".",
"getWidth",
"(",
")",
")",
";",
"return",
"p",
";",
"}"
] | Cretae a BufferedImage from an ImageProducer.
@param producer the ImageProducer
@return a new TYPE_INT_ARGB BufferedImage | [
"Cretae",
"a",
"BufferedImage",
"from",
"an",
"ImageProducer",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L35-L49 |
162,671 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.convertImageToARGB | public static BufferedImage convertImageToARGB( Image image ) {
if ( image instanceof BufferedImage && ((BufferedImage)image).getType() == BufferedImage.TYPE_INT_ARGB )
return (BufferedImage)image;
BufferedImage p = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = p.createGraphics();
g.drawImage( image, 0, 0, null );
g.dispose();
return p;
} | java | public static BufferedImage convertImageToARGB( Image image ) {
if ( image instanceof BufferedImage && ((BufferedImage)image).getType() == BufferedImage.TYPE_INT_ARGB )
return (BufferedImage)image;
BufferedImage p = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = p.createGraphics();
g.drawImage( image, 0, 0, null );
g.dispose();
return p;
} | [
"public",
"static",
"BufferedImage",
"convertImageToARGB",
"(",
"Image",
"image",
")",
"{",
"if",
"(",
"image",
"instanceof",
"BufferedImage",
"&&",
"(",
"(",
"BufferedImage",
")",
"image",
")",
".",
"getType",
"(",
")",
"==",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
"return",
"(",
"BufferedImage",
")",
"image",
";",
"BufferedImage",
"p",
"=",
"new",
"BufferedImage",
"(",
"image",
".",
"getWidth",
"(",
"null",
")",
",",
"image",
".",
"getHeight",
"(",
"null",
")",
",",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
";",
"Graphics2D",
"g",
"=",
"p",
".",
"createGraphics",
"(",
")",
";",
"g",
".",
"drawImage",
"(",
"image",
",",
"0",
",",
"0",
",",
"null",
")",
";",
"g",
".",
"dispose",
"(",
")",
";",
"return",
"p",
";",
"}"
] | Convert an Image into a TYPE_INT_ARGB BufferedImage. If the image is already of this type, the original image is returned unchanged.
@param image the image to convert
@return the converted image | [
"Convert",
"an",
"Image",
"into",
"a",
"TYPE_INT_ARGB",
"BufferedImage",
".",
"If",
"the",
"image",
"is",
"already",
"of",
"this",
"type",
"the",
"original",
"image",
"is",
"returned",
"unchanged",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L56-L64 |
162,672 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.cloneImage | public static BufferedImage cloneImage( BufferedImage image ) {
BufferedImage newImage = new BufferedImage( image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB );
Graphics2D g = newImage.createGraphics();
g.drawRenderedImage( image, null );
g.dispose();
return newImage;
} | java | public static BufferedImage cloneImage( BufferedImage image ) {
BufferedImage newImage = new BufferedImage( image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB );
Graphics2D g = newImage.createGraphics();
g.drawRenderedImage( image, null );
g.dispose();
return newImage;
} | [
"public",
"static",
"BufferedImage",
"cloneImage",
"(",
"BufferedImage",
"image",
")",
"{",
"BufferedImage",
"newImage",
"=",
"new",
"BufferedImage",
"(",
"image",
".",
"getWidth",
"(",
")",
",",
"image",
".",
"getHeight",
"(",
")",
",",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
";",
"Graphics2D",
"g",
"=",
"newImage",
".",
"createGraphics",
"(",
")",
";",
"g",
".",
"drawRenderedImage",
"(",
"image",
",",
"null",
")",
";",
"g",
".",
"dispose",
"(",
")",
";",
"return",
"newImage",
";",
"}"
] | Clones a BufferedImage.
@param image the image to clone
@return the cloned image | [
"Clones",
"a",
"BufferedImage",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L88-L94 |
162,673 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.paintCheckedBackground | public static void paintCheckedBackground(Component c, Graphics g, int x, int y, int width, int height) {
if ( backgroundImage == null ) {
backgroundImage = new BufferedImage( 64, 64, BufferedImage.TYPE_INT_ARGB );
Graphics bg = backgroundImage.createGraphics();
for ( int by = 0; by < 64; by += 8 ) {
for ( int bx = 0; bx < 64; bx += 8 ) {
bg.setColor( ((bx^by) & 8) != 0 ? Color.lightGray : Color.white );
bg.fillRect( bx, by, 8, 8 );
}
}
bg.dispose();
}
if ( backgroundImage != null ) {
Shape saveClip = g.getClip();
Rectangle r = g.getClipBounds();
if (r == null)
r = new Rectangle(c.getSize());
r = r.intersection(new Rectangle(x, y, width, height));
g.setClip(r);
int w = backgroundImage.getWidth();
int h = backgroundImage.getHeight();
if (w != -1 && h != -1) {
int x1 = (r.x / w) * w;
int y1 = (r.y / h) * h;
int x2 = ((r.x + r.width + w - 1) / w) * w;
int y2 = ((r.y + r.height + h - 1) / h) * h;
for (y = y1; y < y2; y += h)
for (x = x1; x < x2; x += w)
g.drawImage(backgroundImage, x, y, c);
}
g.setClip(saveClip);
}
} | java | public static void paintCheckedBackground(Component c, Graphics g, int x, int y, int width, int height) {
if ( backgroundImage == null ) {
backgroundImage = new BufferedImage( 64, 64, BufferedImage.TYPE_INT_ARGB );
Graphics bg = backgroundImage.createGraphics();
for ( int by = 0; by < 64; by += 8 ) {
for ( int bx = 0; bx < 64; bx += 8 ) {
bg.setColor( ((bx^by) & 8) != 0 ? Color.lightGray : Color.white );
bg.fillRect( bx, by, 8, 8 );
}
}
bg.dispose();
}
if ( backgroundImage != null ) {
Shape saveClip = g.getClip();
Rectangle r = g.getClipBounds();
if (r == null)
r = new Rectangle(c.getSize());
r = r.intersection(new Rectangle(x, y, width, height));
g.setClip(r);
int w = backgroundImage.getWidth();
int h = backgroundImage.getHeight();
if (w != -1 && h != -1) {
int x1 = (r.x / w) * w;
int y1 = (r.y / h) * h;
int x2 = ((r.x + r.width + w - 1) / w) * w;
int y2 = ((r.y + r.height + h - 1) / h) * h;
for (y = y1; y < y2; y += h)
for (x = x1; x < x2; x += w)
g.drawImage(backgroundImage, x, y, c);
}
g.setClip(saveClip);
}
} | [
"public",
"static",
"void",
"paintCheckedBackground",
"(",
"Component",
"c",
",",
"Graphics",
"g",
",",
"int",
"x",
",",
"int",
"y",
",",
"int",
"width",
",",
"int",
"height",
")",
"{",
"if",
"(",
"backgroundImage",
"==",
"null",
")",
"{",
"backgroundImage",
"=",
"new",
"BufferedImage",
"(",
"64",
",",
"64",
",",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
";",
"Graphics",
"bg",
"=",
"backgroundImage",
".",
"createGraphics",
"(",
")",
";",
"for",
"(",
"int",
"by",
"=",
"0",
";",
"by",
"<",
"64",
";",
"by",
"+=",
"8",
")",
"{",
"for",
"(",
"int",
"bx",
"=",
"0",
";",
"bx",
"<",
"64",
";",
"bx",
"+=",
"8",
")",
"{",
"bg",
".",
"setColor",
"(",
"(",
"(",
"bx",
"^",
"by",
")",
"&",
"8",
")",
"!=",
"0",
"?",
"Color",
".",
"lightGray",
":",
"Color",
".",
"white",
")",
";",
"bg",
".",
"fillRect",
"(",
"bx",
",",
"by",
",",
"8",
",",
"8",
")",
";",
"}",
"}",
"bg",
".",
"dispose",
"(",
")",
";",
"}",
"if",
"(",
"backgroundImage",
"!=",
"null",
")",
"{",
"Shape",
"saveClip",
"=",
"g",
".",
"getClip",
"(",
")",
";",
"Rectangle",
"r",
"=",
"g",
".",
"getClipBounds",
"(",
")",
";",
"if",
"(",
"r",
"==",
"null",
")",
"r",
"=",
"new",
"Rectangle",
"(",
"c",
".",
"getSize",
"(",
")",
")",
";",
"r",
"=",
"r",
".",
"intersection",
"(",
"new",
"Rectangle",
"(",
"x",
",",
"y",
",",
"width",
",",
"height",
")",
")",
";",
"g",
".",
"setClip",
"(",
"r",
")",
";",
"int",
"w",
"=",
"backgroundImage",
".",
"getWidth",
"(",
")",
";",
"int",
"h",
"=",
"backgroundImage",
".",
"getHeight",
"(",
")",
";",
"if",
"(",
"w",
"!=",
"-",
"1",
"&&",
"h",
"!=",
"-",
"1",
")",
"{",
"int",
"x1",
"=",
"(",
"r",
".",
"x",
"/",
"w",
")",
"*",
"w",
";",
"int",
"y1",
"=",
"(",
"r",
".",
"y",
"/",
"h",
")",
"*",
"h",
";",
"int",
"x2",
"=",
"(",
"(",
"r",
".",
"x",
"+",
"r",
".",
"width",
"+",
"w",
"-",
"1",
")",
"/",
"w",
")",
"*",
"w",
";",
"int",
"y2",
"=",
"(",
"(",
"r",
".",
"y",
"+",
"r",
".",
"height",
"+",
"h",
"-",
"1",
")",
"/",
"h",
")",
"*",
"h",
";",
"for",
"(",
"y",
"=",
"y1",
";",
"y",
"<",
"y2",
";",
"y",
"+=",
"h",
")",
"for",
"(",
"x",
"=",
"x1",
";",
"x",
"<",
"x2",
";",
"x",
"+=",
"w",
")",
"g",
".",
"drawImage",
"(",
"backgroundImage",
",",
"x",
",",
"y",
",",
")",
";",
"}",
"g",
".",
"setClip",
"(",
"saveClip",
")",
";",
"}",
"}"
] | Paint a check pattern, used for a background to indicate image transparency.
@param c the component to draw into
@param g the Graphics objects
@param x the x position
@param y the y position
@param width the width
@param height the height | [
"Paint",
"a",
"check",
"pattern",
"used",
"for",
"a",
"background",
"to",
"indicate",
"image",
"transparency",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L105-L138 |
162,674 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.getSelectedBounds | public static Rectangle getSelectedBounds(BufferedImage p) {
int width = p.getWidth();
int height = p.getHeight();
int maxX = 0, maxY = 0, minX = width, minY = height;
boolean anySelected = false;
int y1;
int [] pixels = null;
for (y1 = height-1; y1 >= 0; y1--) {
pixels = getRGB( p, 0, y1, width, 1, pixels );
for (int x = 0; x < minX; x++) {
if ((pixels[x] & 0xff000000) != 0) {
minX = x;
maxY = y1;
anySelected = true;
break;
}
}
for (int x = width-1; x >= maxX; x--) {
if ((pixels[x] & 0xff000000) != 0) {
maxX = x;
maxY = y1;
anySelected = true;
break;
}
}
if ( anySelected )
break;
}
pixels = null;
for (int y = 0; y < y1; y++) {
pixels = getRGB( p, 0, y, width, 1, pixels );
for (int x = 0; x < minX; x++) {
if ((pixels[x] & 0xff000000) != 0) {
minX = x;
if ( y < minY )
minY = y;
anySelected = true;
break;
}
}
for (int x = width-1; x >= maxX; x--) {
if ((pixels[x] & 0xff000000) != 0) {
maxX = x;
if ( y < minY )
minY = y;
anySelected = true;
break;
}
}
}
if ( anySelected )
return new Rectangle( minX, minY, maxX-minX+1, maxY-minY+1 );
return null;
} | java | public static Rectangle getSelectedBounds(BufferedImage p) {
int width = p.getWidth();
int height = p.getHeight();
int maxX = 0, maxY = 0, minX = width, minY = height;
boolean anySelected = false;
int y1;
int [] pixels = null;
for (y1 = height-1; y1 >= 0; y1--) {
pixels = getRGB( p, 0, y1, width, 1, pixels );
for (int x = 0; x < minX; x++) {
if ((pixels[x] & 0xff000000) != 0) {
minX = x;
maxY = y1;
anySelected = true;
break;
}
}
for (int x = width-1; x >= maxX; x--) {
if ((pixels[x] & 0xff000000) != 0) {
maxX = x;
maxY = y1;
anySelected = true;
break;
}
}
if ( anySelected )
break;
}
pixels = null;
for (int y = 0; y < y1; y++) {
pixels = getRGB( p, 0, y, width, 1, pixels );
for (int x = 0; x < minX; x++) {
if ((pixels[x] & 0xff000000) != 0) {
minX = x;
if ( y < minY )
minY = y;
anySelected = true;
break;
}
}
for (int x = width-1; x >= maxX; x--) {
if ((pixels[x] & 0xff000000) != 0) {
maxX = x;
if ( y < minY )
minY = y;
anySelected = true;
break;
}
}
}
if ( anySelected )
return new Rectangle( minX, minY, maxX-minX+1, maxY-minY+1 );
return null;
} | [
"public",
"static",
"Rectangle",
"getSelectedBounds",
"(",
"BufferedImage",
"p",
")",
"{",
"int",
"width",
"=",
"p",
".",
"getWidth",
"(",
")",
";",
"int",
"height",
"=",
"p",
".",
"getHeight",
"(",
")",
";",
"int",
"maxX",
"=",
"0",
",",
"maxY",
"=",
"0",
",",
"minX",
"=",
"width",
",",
"minY",
"=",
"height",
";",
"boolean",
"anySelected",
"=",
"false",
";",
"int",
"y1",
";",
"int",
"[",
"]",
"pixels",
"=",
"null",
";",
"for",
"(",
"y1",
"=",
"height",
"-",
"1",
";",
"y1",
">=",
"0",
";",
"y1",
"--",
")",
"{",
"pixels",
"=",
"getRGB",
"(",
"p",
",",
"0",
",",
"y1",
",",
"width",
",",
"1",
",",
"pixels",
")",
";",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"minX",
";",
"x",
"++",
")",
"{",
"if",
"(",
"(",
"pixels",
"[",
"x",
"]",
"&",
"0xff000000",
")",
"!=",
"0",
")",
"{",
"minX",
"=",
"x",
";",
"maxY",
"=",
"y1",
";",
"anySelected",
"=",
"true",
";",
"break",
";",
"}",
"}",
"for",
"(",
"int",
"x",
"=",
"width",
"-",
"1",
";",
"x",
">=",
"maxX",
";",
"x",
"--",
")",
"{",
"if",
"(",
"(",
"pixels",
"[",
"x",
"]",
"&",
"0xff000000",
")",
"!=",
"0",
")",
"{",
"maxX",
"=",
"x",
";",
"maxY",
"=",
"y1",
";",
"anySelected",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"anySelected",
")",
"break",
";",
"}",
"pixels",
"=",
"null",
";",
"for",
"(",
"int",
"y",
"=",
"0",
";",
"y",
"<",
"y1",
";",
"y",
"++",
")",
"{",
"pixels",
"=",
"getRGB",
"(",
"p",
",",
"0",
",",
"y",
",",
"width",
",",
"1",
",",
"pixels",
")",
";",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"minX",
";",
"x",
"++",
")",
"{",
"if",
"(",
"(",
"pixels",
"[",
"x",
"]",
"&",
"0xff000000",
")",
"!=",
"0",
")",
"{",
"minX",
"=",
"x",
";",
"if",
"(",
"y",
"<",
"minY",
")",
"minY",
"=",
"y",
";",
"anySelected",
"=",
"true",
";",
"break",
";",
"}",
"}",
"for",
"(",
"int",
"x",
"=",
"width",
"-",
"1",
";",
"x",
">=",
"maxX",
";",
"x",
"--",
")",
"{",
"if",
"(",
"(",
"pixels",
"[",
"x",
"]",
"&",
"0xff000000",
")",
"!=",
"0",
")",
"{",
"maxX",
"=",
"x",
";",
"if",
"(",
"y",
"<",
"minY",
")",
"minY",
"=",
"y",
";",
"anySelected",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"anySelected",
")",
"return",
"new",
"Rectangle",
"(",
"minX",
",",
"minY",
",",
"maxX",
"-",
"minX",
"+",
"1",
",",
"maxY",
"-",
"minY",
"+",
"1",
")",
";",
"return",
"null",
";",
"}"
] | Calculates the bounds of the non-transparent parts of the given image.
@param p the image
@return the bounds of the non-transparent area | [
"Calculates",
"the",
"bounds",
"of",
"the",
"non",
"-",
"transparent",
"parts",
"of",
"the",
"given",
"image",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L145-L199 |
162,675 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java | ImageUtils.composeThroughMask | public static void composeThroughMask(Raster src, WritableRaster dst, Raster sel) {
int x = src.getMinX();
int y = src.getMinY();
int w = src.getWidth();
int h = src.getHeight();
int srcRGB[] = null;
int selRGB[] = null;
int dstRGB[] = null;
for ( int i = 0; i < h; i++ ) {
srcRGB = src.getPixels(x, y, w, 1, srcRGB);
selRGB = sel.getPixels(x, y, w, 1, selRGB);
dstRGB = dst.getPixels(x, y, w, 1, dstRGB);
int k = x;
for ( int j = 0; j < w; j++ ) {
int sr = srcRGB[k];
int dir = dstRGB[k];
int sg = srcRGB[k+1];
int dig = dstRGB[k+1];
int sb = srcRGB[k+2];
int dib = dstRGB[k+2];
int sa = srcRGB[k+3];
int dia = dstRGB[k+3];
float a = selRGB[k+3]/255f;
float ac = 1-a;
dstRGB[k] = (int)(a*sr + ac*dir);
dstRGB[k+1] = (int)(a*sg + ac*dig);
dstRGB[k+2] = (int)(a*sb + ac*dib);
dstRGB[k+3] = (int)(a*sa + ac*dia);
k += 4;
}
dst.setPixels(x, y, w, 1, dstRGB);
y++;
}
} | java | public static void composeThroughMask(Raster src, WritableRaster dst, Raster sel) {
int x = src.getMinX();
int y = src.getMinY();
int w = src.getWidth();
int h = src.getHeight();
int srcRGB[] = null;
int selRGB[] = null;
int dstRGB[] = null;
for ( int i = 0; i < h; i++ ) {
srcRGB = src.getPixels(x, y, w, 1, srcRGB);
selRGB = sel.getPixels(x, y, w, 1, selRGB);
dstRGB = dst.getPixels(x, y, w, 1, dstRGB);
int k = x;
for ( int j = 0; j < w; j++ ) {
int sr = srcRGB[k];
int dir = dstRGB[k];
int sg = srcRGB[k+1];
int dig = dstRGB[k+1];
int sb = srcRGB[k+2];
int dib = dstRGB[k+2];
int sa = srcRGB[k+3];
int dia = dstRGB[k+3];
float a = selRGB[k+3]/255f;
float ac = 1-a;
dstRGB[k] = (int)(a*sr + ac*dir);
dstRGB[k+1] = (int)(a*sg + ac*dig);
dstRGB[k+2] = (int)(a*sb + ac*dib);
dstRGB[k+3] = (int)(a*sa + ac*dia);
k += 4;
}
dst.setPixels(x, y, w, 1, dstRGB);
y++;
}
} | [
"public",
"static",
"void",
"composeThroughMask",
"(",
"Raster",
"src",
",",
"WritableRaster",
"dst",
",",
"Raster",
"sel",
")",
"{",
"int",
"x",
"=",
"src",
".",
"getMinX",
"(",
")",
";",
"int",
"y",
"=",
"src",
".",
"getMinY",
"(",
")",
";",
"int",
"w",
"=",
"src",
".",
"getWidth",
"(",
")",
";",
"int",
"h",
"=",
"src",
".",
"getHeight",
"(",
")",
";",
"int",
"srcRGB",
"[",
"]",
"=",
"null",
";",
"int",
"selRGB",
"[",
"]",
"=",
"null",
";",
"int",
"dstRGB",
"[",
"]",
"=",
"null",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"h",
";",
"i",
"++",
")",
"{",
"srcRGB",
"=",
"src",
".",
"getPixels",
"(",
"x",
",",
"y",
",",
"w",
",",
"1",
",",
"srcRGB",
")",
";",
"selRGB",
"=",
"sel",
".",
"getPixels",
"(",
"x",
",",
"y",
",",
"w",
",",
"1",
",",
"selRGB",
")",
";",
"dstRGB",
"=",
"dst",
".",
"getPixels",
"(",
"x",
",",
"y",
",",
"w",
",",
"1",
",",
"dstRGB",
")",
";",
"int",
"k",
"=",
"x",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"w",
";",
"j",
"++",
")",
"{",
"int",
"sr",
"=",
"srcRGB",
"[",
"k",
"]",
";",
"int",
"dir",
"=",
"dstRGB",
"[",
"k",
"]",
";",
"int",
"sg",
"=",
"srcRGB",
"[",
"k",
"+",
"1",
"]",
";",
"int",
"dig",
"=",
"dstRGB",
"[",
"k",
"+",
"1",
"]",
";",
"int",
"sb",
"=",
"srcRGB",
"[",
"k",
"+",
"2",
"]",
";",
"int",
"dib",
"=",
"dstRGB",
"[",
"k",
"+",
"2",
"]",
";",
"int",
"sa",
"=",
"srcRGB",
"[",
"k",
"+",
"3",
"]",
";",
"int",
"dia",
"=",
"dstRGB",
"[",
"k",
"+",
"3",
"]",
";",
"float",
"a",
"=",
"selRGB",
"[",
"k",
"+",
"3",
"]",
"/",
"255f",
";",
"float",
"ac",
"=",
"1",
"-",
"a",
";",
"dstRGB",
"[",
"k",
"]",
"=",
"(",
"int",
")",
"(",
"a",
"*",
"sr",
"+",
"ac",
"*",
"dir",
")",
";",
"dstRGB",
"[",
"k",
"+",
"1",
"]",
"=",
"(",
"int",
")",
"(",
"a",
"*",
"sg",
"+",
"ac",
"*",
"dig",
")",
";",
"dstRGB",
"[",
"k",
"+",
"2",
"]",
"=",
"(",
"int",
")",
"(",
"a",
"*",
"sb",
"+",
"ac",
"*",
"dib",
")",
";",
"dstRGB",
"[",
"k",
"+",
"3",
"]",
"=",
"(",
"int",
")",
"(",
"a",
"*",
"sa",
"+",
"ac",
"*",
"dia",
")",
";",
"k",
"+=",
"4",
";",
"}",
"dst",
".",
"setPixels",
"(",
"x",
",",
"y",
",",
"w",
",",
"1",
",",
"dstRGB",
")",
";",
"y",
"++",
";",
"}",
"}"
] | Compose src onto dst using the alpha of sel to interpolate between the two.
I can't think of a way to do this using AlphaComposite.
@param src the source raster
@param dst the destination raster
@param sel the mask raster | [
"Compose",
"src",
"onto",
"dst",
"using",
"the",
"alpha",
"of",
"sel",
"to",
"interpolate",
"between",
"the",
"two",
".",
"I",
"can",
"t",
"think",
"of",
"a",
"way",
"to",
"do",
"this",
"using",
"AlphaComposite",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageUtils.java#L208-L247 |
162,676 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/DiffusionFilter.java | DiffusionFilter.setMatrix | public void setMatrix(int[] matrix) {
this.matrix = matrix;
sum = 0;
for (int i = 0; i < matrix.length; i++)
sum += matrix[i];
} | java | public void setMatrix(int[] matrix) {
this.matrix = matrix;
sum = 0;
for (int i = 0; i < matrix.length; i++)
sum += matrix[i];
} | [
"public",
"void",
"setMatrix",
"(",
"int",
"[",
"]",
"matrix",
")",
"{",
"this",
".",
"matrix",
"=",
"matrix",
";",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"matrix",
".",
"length",
";",
"i",
"++",
")",
"sum",
"+=",
"matrix",
"[",
"i",
"]",
";",
"}"
] | Set the dither matrix.
@param matrix the dither matrix
@see #getMatrix | [
"Set",
"the",
"dither",
"matrix",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/DiffusionFilter.java#L86-L91 |
162,677 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.gain | public static float gain(float a, float b) {
/*
float p = (float)Math.log(1.0 - b) / (float)Math.log(0.5);
if (a < .001)
return 0.0f;
else if (a > .999)
return 1.0f;
if (a < 0.5)
return (float)Math.pow(2 * a, p) / 2;
else
return 1.0f - (float)Math.pow(2 * (1. - a), p) / 2;
*/
float c = (1.0f/b-2.0f) * (1.0f-2.0f*a);
if (a < 0.5)
return a/(c+1.0f);
else
return (c-a)/(c-1.0f);
} | java | public static float gain(float a, float b) {
/*
float p = (float)Math.log(1.0 - b) / (float)Math.log(0.5);
if (a < .001)
return 0.0f;
else if (a > .999)
return 1.0f;
if (a < 0.5)
return (float)Math.pow(2 * a, p) / 2;
else
return 1.0f - (float)Math.pow(2 * (1. - a), p) / 2;
*/
float c = (1.0f/b-2.0f) * (1.0f-2.0f*a);
if (a < 0.5)
return a/(c+1.0f);
else
return (c-a)/(c-1.0f);
} | [
"public",
"static",
"float",
"gain",
"(",
"float",
"a",
",",
"float",
"b",
")",
"{",
"/*\n\t\tfloat p = (float)Math.log(1.0 - b) / (float)Math.log(0.5);\n\n\t\tif (a < .001)\n\t\t\treturn 0.0f;\n\t\telse if (a > .999)\n\t\t\treturn 1.0f;\n\t\tif (a < 0.5)\n\t\t\treturn (float)Math.pow(2 * a, p) / 2;\n\t\telse\n\t\t\treturn 1.0f - (float)Math.pow(2 * (1. - a), p) / 2;\n*/",
"float",
"c",
"=",
"(",
"1.0f",
"/",
"b",
"-",
"2.0f",
")",
"*",
"(",
"1.0f",
"-",
"2.0f",
"*",
"a",
")",
";",
"if",
"(",
"a",
"<",
"0.5",
")",
"return",
"a",
"/",
"(",
"c",
"+",
"1.0f",
")",
";",
"else",
"return",
"(",
"c",
"-",
"a",
")",
"/",
"(",
"c",
"-",
"1.0f",
")",
";",
"}"
] | A variant of the gamma function.
@param a the number to apply gain to
@param b the gain parameter. 0.5 means no change, smaller values reduce gain, larger values increase gain.
@return the output value | [
"A",
"variant",
"of",
"the",
"gamma",
"function",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L62-L80 |
162,678 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.smoothPulse | public static float smoothPulse(float a1, float a2, float b1, float b2, float x) {
if (x < a1 || x >= b2)
return 0;
if (x >= a2) {
if (x < b1)
return 1.0f;
x = (x - b1) / (b2 - b1);
return 1.0f - (x*x * (3.0f - 2.0f*x));
}
x = (x - a1) / (a2 - a1);
return x*x * (3.0f - 2.0f*x);
} | java | public static float smoothPulse(float a1, float a2, float b1, float b2, float x) {
if (x < a1 || x >= b2)
return 0;
if (x >= a2) {
if (x < b1)
return 1.0f;
x = (x - b1) / (b2 - b1);
return 1.0f - (x*x * (3.0f - 2.0f*x));
}
x = (x - a1) / (a2 - a1);
return x*x * (3.0f - 2.0f*x);
} | [
"public",
"static",
"float",
"smoothPulse",
"(",
"float",
"a1",
",",
"float",
"a2",
",",
"float",
"b1",
",",
"float",
"b2",
",",
"float",
"x",
")",
"{",
"if",
"(",
"x",
"<",
"a1",
"||",
"x",
">=",
"b2",
")",
"return",
"0",
";",
"if",
"(",
"x",
">=",
"a2",
")",
"{",
"if",
"(",
"x",
"<",
"b1",
")",
"return",
"1.0f",
";",
"x",
"=",
"(",
"x",
"-",
"b1",
")",
"/",
"(",
"b2",
"-",
"b1",
")",
";",
"return",
"1.0f",
"-",
"(",
"x",
"*",
"x",
"*",
"(",
"3.0f",
"-",
"2.0f",
"*",
"x",
")",
")",
";",
"}",
"x",
"=",
"(",
"x",
"-",
"a1",
")",
"/",
"(",
"a2",
"-",
"a1",
")",
";",
"return",
"x",
"*",
"x",
"*",
"(",
"3.0f",
"-",
"2.0f",
"*",
"x",
")",
";",
"}"
] | A smoothed pulse function. A cubic function is used to smooth the step between two thresholds.
@param a1 the lower threshold position for the start of the pulse
@param a2 the upper threshold position for the start of the pulse
@param b1 the lower threshold position for the end of the pulse
@param b2 the upper threshold position for the end of the pulse
@param x the input parameter
@return the output value | [
"A",
"smoothed",
"pulse",
"function",
".",
"A",
"cubic",
"function",
"is",
"used",
"to",
"smooth",
"the",
"step",
"between",
"two",
"thresholds",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L112-L123 |
162,679 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.smoothStep | public static float smoothStep(float a, float b, float x) {
if (x < a)
return 0;
if (x >= b)
return 1;
x = (x - a) / (b - a);
return x*x * (3 - 2*x);
} | java | public static float smoothStep(float a, float b, float x) {
if (x < a)
return 0;
if (x >= b)
return 1;
x = (x - a) / (b - a);
return x*x * (3 - 2*x);
} | [
"public",
"static",
"float",
"smoothStep",
"(",
"float",
"a",
",",
"float",
"b",
",",
"float",
"x",
")",
"{",
"if",
"(",
"x",
"<",
"a",
")",
"return",
"0",
";",
"if",
"(",
"x",
">=",
"b",
")",
"return",
"1",
";",
"x",
"=",
"(",
"x",
"-",
"a",
")",
"/",
"(",
"b",
"-",
"a",
")",
";",
"return",
"x",
"*",
"x",
"*",
"(",
"3",
"-",
"2",
"*",
"x",
")",
";",
"}"
] | A smoothed step function. A cubic function is used to smooth the step between two thresholds.
@param a the lower threshold position
@param b the upper threshold position
@param x the input parameter
@return the output value | [
"A",
"smoothed",
"step",
"function",
".",
"A",
"cubic",
"function",
"is",
"used",
"to",
"smooth",
"the",
"step",
"between",
"two",
"thresholds",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L132-L139 |
162,680 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.mixColors | public static int mixColors(float t, int rgb1, int rgb2) {
int a1 = (rgb1 >> 24) & 0xff;
int r1 = (rgb1 >> 16) & 0xff;
int g1 = (rgb1 >> 8) & 0xff;
int b1 = rgb1 & 0xff;
int a2 = (rgb2 >> 24) & 0xff;
int r2 = (rgb2 >> 16) & 0xff;
int g2 = (rgb2 >> 8) & 0xff;
int b2 = rgb2 & 0xff;
a1 = lerp(t, a1, a2);
r1 = lerp(t, r1, r2);
g1 = lerp(t, g1, g2);
b1 = lerp(t, b1, b2);
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
} | java | public static int mixColors(float t, int rgb1, int rgb2) {
int a1 = (rgb1 >> 24) & 0xff;
int r1 = (rgb1 >> 16) & 0xff;
int g1 = (rgb1 >> 8) & 0xff;
int b1 = rgb1 & 0xff;
int a2 = (rgb2 >> 24) & 0xff;
int r2 = (rgb2 >> 16) & 0xff;
int g2 = (rgb2 >> 8) & 0xff;
int b2 = rgb2 & 0xff;
a1 = lerp(t, a1, a2);
r1 = lerp(t, r1, r2);
g1 = lerp(t, g1, g2);
b1 = lerp(t, b1, b2);
return (a1 << 24) | (r1 << 16) | (g1 << 8) | b1;
} | [
"public",
"static",
"int",
"mixColors",
"(",
"float",
"t",
",",
"int",
"rgb1",
",",
"int",
"rgb2",
")",
"{",
"int",
"a1",
"=",
"(",
"rgb1",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r1",
"=",
"(",
"rgb1",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g1",
"=",
"(",
"rgb1",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b1",
"=",
"rgb1",
"&",
"0xff",
";",
"int",
"a2",
"=",
"(",
"rgb2",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r2",
"=",
"(",
"rgb2",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g2",
"=",
"(",
"rgb2",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b2",
"=",
"rgb2",
"&",
"0xff",
";",
"a1",
"=",
"lerp",
"(",
"t",
",",
"a1",
",",
"a2",
")",
";",
"r1",
"=",
"lerp",
"(",
"t",
",",
"r1",
",",
"r2",
")",
";",
"g1",
"=",
"lerp",
"(",
"t",
",",
"g1",
",",
"g2",
")",
";",
"b1",
"=",
"lerp",
"(",
"t",
",",
"b1",
",",
"b2",
")",
";",
"return",
"(",
"a1",
"<<",
"24",
")",
"|",
"(",
"r1",
"<<",
"16",
")",
"|",
"(",
"g1",
"<<",
"8",
")",
"|",
"b1",
";",
"}"
] | Linear interpolation of ARGB values.
@param t the interpolation parameter
@param rgb1 the lower interpolation range
@param rgb2 the upper interpolation range
@return the interpolated value | [
"Linear",
"interpolation",
"of",
"ARGB",
"values",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L266-L280 |
162,681 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.bilinearInterpolate | public static int bilinearInterpolate(float x, float y, int nw, int ne, int sw, int se) {
float m0, m1;
int a0 = (nw >> 24) & 0xff;
int r0 = (nw >> 16) & 0xff;
int g0 = (nw >> 8) & 0xff;
int b0 = nw & 0xff;
int a1 = (ne >> 24) & 0xff;
int r1 = (ne >> 16) & 0xff;
int g1 = (ne >> 8) & 0xff;
int b1 = ne & 0xff;
int a2 = (sw >> 24) & 0xff;
int r2 = (sw >> 16) & 0xff;
int g2 = (sw >> 8) & 0xff;
int b2 = sw & 0xff;
int a3 = (se >> 24) & 0xff;
int r3 = (se >> 16) & 0xff;
int g3 = (se >> 8) & 0xff;
int b3 = se & 0xff;
float cx = 1.0f-x;
float cy = 1.0f-y;
m0 = cx * a0 + x * a1;
m1 = cx * a2 + x * a3;
int a = (int)(cy * m0 + y * m1);
m0 = cx * r0 + x * r1;
m1 = cx * r2 + x * r3;
int r = (int)(cy * m0 + y * m1);
m0 = cx * g0 + x * g1;
m1 = cx * g2 + x * g3;
int g = (int)(cy * m0 + y * m1);
m0 = cx * b0 + x * b1;
m1 = cx * b2 + x * b3;
int b = (int)(cy * m0 + y * m1);
return (a << 24) | (r << 16) | (g << 8) | b;
} | java | public static int bilinearInterpolate(float x, float y, int nw, int ne, int sw, int se) {
float m0, m1;
int a0 = (nw >> 24) & 0xff;
int r0 = (nw >> 16) & 0xff;
int g0 = (nw >> 8) & 0xff;
int b0 = nw & 0xff;
int a1 = (ne >> 24) & 0xff;
int r1 = (ne >> 16) & 0xff;
int g1 = (ne >> 8) & 0xff;
int b1 = ne & 0xff;
int a2 = (sw >> 24) & 0xff;
int r2 = (sw >> 16) & 0xff;
int g2 = (sw >> 8) & 0xff;
int b2 = sw & 0xff;
int a3 = (se >> 24) & 0xff;
int r3 = (se >> 16) & 0xff;
int g3 = (se >> 8) & 0xff;
int b3 = se & 0xff;
float cx = 1.0f-x;
float cy = 1.0f-y;
m0 = cx * a0 + x * a1;
m1 = cx * a2 + x * a3;
int a = (int)(cy * m0 + y * m1);
m0 = cx * r0 + x * r1;
m1 = cx * r2 + x * r3;
int r = (int)(cy * m0 + y * m1);
m0 = cx * g0 + x * g1;
m1 = cx * g2 + x * g3;
int g = (int)(cy * m0 + y * m1);
m0 = cx * b0 + x * b1;
m1 = cx * b2 + x * b3;
int b = (int)(cy * m0 + y * m1);
return (a << 24) | (r << 16) | (g << 8) | b;
} | [
"public",
"static",
"int",
"bilinearInterpolate",
"(",
"float",
"x",
",",
"float",
"y",
",",
"int",
"nw",
",",
"int",
"ne",
",",
"int",
"sw",
",",
"int",
"se",
")",
"{",
"float",
"m0",
",",
"m1",
";",
"int",
"a0",
"=",
"(",
"nw",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r0",
"=",
"(",
"nw",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g0",
"=",
"(",
"nw",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b0",
"=",
"nw",
"&",
"0xff",
";",
"int",
"a1",
"=",
"(",
"ne",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r1",
"=",
"(",
"ne",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g1",
"=",
"(",
"ne",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b1",
"=",
"ne",
"&",
"0xff",
";",
"int",
"a2",
"=",
"(",
"sw",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r2",
"=",
"(",
"sw",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g2",
"=",
"(",
"sw",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b2",
"=",
"sw",
"&",
"0xff",
";",
"int",
"a3",
"=",
"(",
"se",
">>",
"24",
")",
"&",
"0xff",
";",
"int",
"r3",
"=",
"(",
"se",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g3",
"=",
"(",
"se",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b3",
"=",
"se",
"&",
"0xff",
";",
"float",
"cx",
"=",
"1.0f",
"-",
"x",
";",
"float",
"cy",
"=",
"1.0f",
"-",
"y",
";",
"m0",
"=",
"cx",
"*",
"a0",
"+",
"x",
"*",
"a1",
";",
"m1",
"=",
"cx",
"*",
"a2",
"+",
"x",
"*",
"a3",
";",
"int",
"a",
"=",
"(",
"int",
")",
"(",
"cy",
"*",
"m0",
"+",
"y",
"*",
"m1",
")",
";",
"m0",
"=",
"cx",
"*",
"r0",
"+",
"x",
"*",
"r1",
";",
"m1",
"=",
"cx",
"*",
"r2",
"+",
"x",
"*",
"r3",
";",
"int",
"r",
"=",
"(",
"int",
")",
"(",
"cy",
"*",
"m0",
"+",
"y",
"*",
"m1",
")",
";",
"m0",
"=",
"cx",
"*",
"g0",
"+",
"x",
"*",
"g1",
";",
"m1",
"=",
"cx",
"*",
"g2",
"+",
"x",
"*",
"g3",
";",
"int",
"g",
"=",
"(",
"int",
")",
"(",
"cy",
"*",
"m0",
"+",
"y",
"*",
"m1",
")",
";",
"m0",
"=",
"cx",
"*",
"b0",
"+",
"x",
"*",
"b1",
";",
"m1",
"=",
"cx",
"*",
"b2",
"+",
"x",
"*",
"b3",
";",
"int",
"b",
"=",
"(",
"int",
")",
"(",
"cy",
"*",
"m0",
"+",
"y",
"*",
"m1",
")",
";",
"return",
"(",
"a",
"<<",
"24",
")",
"|",
"(",
"r",
"<<",
"16",
")",
"|",
"(",
"g",
"<<",
"8",
")",
"|",
"b",
";",
"}"
] | Bilinear interpolation of ARGB values.
@param x the X interpolation parameter 0..1
@param y the y interpolation parameter 0..1
@param rgb array of four ARGB values in the order NW, NE, SW, SE
@return the interpolated value | [
"Bilinear",
"interpolation",
"of",
"ARGB",
"values",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L289-L328 |
162,682 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.brightnessNTSC | public static int brightnessNTSC(int rgb) {
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = rgb & 0xff;
return (int)(r*0.299f + g*0.587f + b*0.114f);
} | java | public static int brightnessNTSC(int rgb) {
int r = (rgb >> 16) & 0xff;
int g = (rgb >> 8) & 0xff;
int b = rgb & 0xff;
return (int)(r*0.299f + g*0.587f + b*0.114f);
} | [
"public",
"static",
"int",
"brightnessNTSC",
"(",
"int",
"rgb",
")",
"{",
"int",
"r",
"=",
"(",
"rgb",
">>",
"16",
")",
"&",
"0xff",
";",
"int",
"g",
"=",
"(",
"rgb",
">>",
"8",
")",
"&",
"0xff",
";",
"int",
"b",
"=",
"rgb",
"&",
"0xff",
";",
"return",
"(",
"int",
")",
"(",
"r",
"*",
"0.299f",
"+",
"g",
"*",
"0.587f",
"+",
"b",
"*",
"0.114f",
")",
";",
"}"
] | Return the NTSC gray level of an RGB value.
@param rgb1 the input pixel
@return the gray level (0-255) | [
"Return",
"the",
"NTSC",
"gray",
"level",
"of",
"an",
"RGB",
"value",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L335-L340 |
162,683 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java | ImageMath.colorSpline | public static int colorSpline(int x, int numKnots, int[] xknots, int[] yknots) {
int span;
int numSpans = numKnots - 3;
float k0, k1, k2, k3;
float c0, c1, c2, c3;
if (numSpans < 1)
throw new IllegalArgumentException("Too few knots in spline");
for (span = 0; span < numSpans; span++)
if (xknots[span+1] > x)
break;
if (span > numKnots-3)
span = numKnots-3;
float t = (float)(x-xknots[span]) / (xknots[span+1]-xknots[span]);
span--;
if (span < 0) {
span = 0;
t = 0;
}
int v = 0;
for (int i = 0; i < 4; i++) {
int shift = i * 8;
k0 = (yknots[span] >> shift) & 0xff;
k1 = (yknots[span+1] >> shift) & 0xff;
k2 = (yknots[span+2] >> shift) & 0xff;
k3 = (yknots[span+3] >> shift) & 0xff;
c3 = m00*k0 + m01*k1 + m02*k2 + m03*k3;
c2 = m10*k0 + m11*k1 + m12*k2 + m13*k3;
c1 = m20*k0 + m21*k1 + m22*k2 + m23*k3;
c0 = m30*k0 + m31*k1 + m32*k2 + m33*k3;
int n = (int)(((c3*t + c2)*t + c1)*t + c0);
if (n < 0)
n = 0;
else if (n > 255)
n = 255;
v |= n << shift;
}
return v;
} | java | public static int colorSpline(int x, int numKnots, int[] xknots, int[] yknots) {
int span;
int numSpans = numKnots - 3;
float k0, k1, k2, k3;
float c0, c1, c2, c3;
if (numSpans < 1)
throw new IllegalArgumentException("Too few knots in spline");
for (span = 0; span < numSpans; span++)
if (xknots[span+1] > x)
break;
if (span > numKnots-3)
span = numKnots-3;
float t = (float)(x-xknots[span]) / (xknots[span+1]-xknots[span]);
span--;
if (span < 0) {
span = 0;
t = 0;
}
int v = 0;
for (int i = 0; i < 4; i++) {
int shift = i * 8;
k0 = (yknots[span] >> shift) & 0xff;
k1 = (yknots[span+1] >> shift) & 0xff;
k2 = (yknots[span+2] >> shift) & 0xff;
k3 = (yknots[span+3] >> shift) & 0xff;
c3 = m00*k0 + m01*k1 + m02*k2 + m03*k3;
c2 = m10*k0 + m11*k1 + m12*k2 + m13*k3;
c1 = m20*k0 + m21*k1 + m22*k2 + m23*k3;
c0 = m30*k0 + m31*k1 + m32*k2 + m33*k3;
int n = (int)(((c3*t + c2)*t + c1)*t + c0);
if (n < 0)
n = 0;
else if (n > 255)
n = 255;
v |= n << shift;
}
return v;
} | [
"public",
"static",
"int",
"colorSpline",
"(",
"int",
"x",
",",
"int",
"numKnots",
",",
"int",
"[",
"]",
"xknots",
",",
"int",
"[",
"]",
"yknots",
")",
"{",
"int",
"span",
";",
"int",
"numSpans",
"=",
"numKnots",
"-",
"3",
";",
"float",
"k0",
",",
"k1",
",",
"k2",
",",
"k3",
";",
"float",
"c0",
",",
"c1",
",",
"c2",
",",
"c3",
";",
"if",
"(",
"numSpans",
"<",
"1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Too few knots in spline\"",
")",
";",
"for",
"(",
"span",
"=",
"0",
";",
"span",
"<",
"numSpans",
";",
"span",
"++",
")",
"if",
"(",
"xknots",
"[",
"span",
"+",
"1",
"]",
">",
"x",
")",
"break",
";",
"if",
"(",
"span",
">",
"numKnots",
"-",
"3",
")",
"span",
"=",
"numKnots",
"-",
"3",
";",
"float",
"t",
"=",
"(",
"float",
")",
"(",
"x",
"-",
"xknots",
"[",
"span",
"]",
")",
"/",
"(",
"xknots",
"[",
"span",
"+",
"1",
"]",
"-",
"xknots",
"[",
"span",
"]",
")",
";",
"span",
"--",
";",
"if",
"(",
"span",
"<",
"0",
")",
"{",
"span",
"=",
"0",
";",
"t",
"=",
"0",
";",
"}",
"int",
"v",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"4",
";",
"i",
"++",
")",
"{",
"int",
"shift",
"=",
"i",
"*",
"8",
";",
"k0",
"=",
"(",
"yknots",
"[",
"span",
"]",
">>",
"shift",
")",
"&",
"0xff",
";",
"k1",
"=",
"(",
"yknots",
"[",
"span",
"+",
"1",
"]",
">>",
"shift",
")",
"&",
"0xff",
";",
"k2",
"=",
"(",
"yknots",
"[",
"span",
"+",
"2",
"]",
">>",
"shift",
")",
"&",
"0xff",
";",
"k3",
"=",
"(",
"yknots",
"[",
"span",
"+",
"3",
"]",
">>",
"shift",
")",
"&",
"0xff",
";",
"c3",
"=",
"m00",
"*",
"k0",
"+",
"m01",
"*",
"k1",
"+",
"m02",
"*",
"k2",
"+",
"m03",
"*",
"k3",
";",
"c2",
"=",
"m10",
"*",
"k0",
"+",
"m11",
"*",
"k1",
"+",
"m12",
"*",
"k2",
"+",
"m13",
"*",
"k3",
";",
"c1",
"=",
"m20",
"*",
"k0",
"+",
"m21",
"*",
"k1",
"+",
"m22",
"*",
"k2",
"+",
"m23",
"*",
"k3",
";",
"c0",
"=",
"m30",
"*",
"k0",
"+",
"m31",
"*",
"k1",
"+",
"m32",
"*",
"k2",
"+",
"m33",
"*",
"k3",
";",
"int",
"n",
"=",
"(",
"int",
")",
"(",
"(",
"(",
"c3",
"*",
"t",
"+",
"c2",
")",
"*",
"t",
"+",
"c1",
")",
"*",
"t",
"+",
"c0",
")",
";",
"if",
"(",
"n",
"<",
"0",
")",
"n",
"=",
"0",
";",
"else",
"if",
"(",
"n",
">",
"255",
")",
"n",
"=",
"255",
";",
"v",
"|=",
"n",
"<<",
"shift",
";",
"}",
"return",
"v",
";",
"}"
] | Compute a Catmull-Rom spline for RGB values, but with variable knot spacing.
@param x the input parameter
@param numKnots the number of knots in the spline
@param xknots the array of knot x values
@param yknots the array of knot y values
@return the spline value | [
"Compute",
"a",
"Catmull",
"-",
"Rom",
"spline",
"for",
"RGB",
"values",
"but",
"with",
"variable",
"knot",
"spacing",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/ImageMath.java#L491-L534 |
162,684 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.copyTo | public void copyTo(Gradient g) {
g.numKnots = numKnots;
g.map = (int[])map.clone();
g.xKnots = (int[])xKnots.clone();
g.yKnots = (int[])yKnots.clone();
g.knotTypes = (byte[])knotTypes.clone();
} | java | public void copyTo(Gradient g) {
g.numKnots = numKnots;
g.map = (int[])map.clone();
g.xKnots = (int[])xKnots.clone();
g.yKnots = (int[])yKnots.clone();
g.knotTypes = (byte[])knotTypes.clone();
} | [
"public",
"void",
"copyTo",
"(",
"Gradient",
"g",
")",
"{",
"g",
".",
"numKnots",
"=",
"numKnots",
";",
"g",
".",
"map",
"=",
"(",
"int",
"[",
"]",
")",
"map",
".",
"clone",
"(",
")",
";",
"g",
".",
"xKnots",
"=",
"(",
"int",
"[",
"]",
")",
"xKnots",
".",
"clone",
"(",
")",
";",
"g",
".",
"yKnots",
"=",
"(",
"int",
"[",
"]",
")",
"yKnots",
".",
"clone",
"(",
")",
";",
"g",
".",
"knotTypes",
"=",
"(",
"byte",
"[",
"]",
")",
"knotTypes",
".",
"clone",
"(",
")",
";",
"}"
] | Copy one Gradient into another.
@param g the Gradient to copy into | [
"Copy",
"one",
"Gradient",
"into",
"another",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L138-L144 |
162,685 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.setColor | public void setColor(int n, int color) {
int firstColor = map[0];
int lastColor = map[256-1];
if (n > 0)
for (int i = 0; i < n; i++)
map[i] = ImageMath.mixColors((float)i/n, firstColor, color);
if (n < 256-1)
for (int i = n; i < 256; i++)
map[i] = ImageMath.mixColors((float)(i-n)/(256-n), color, lastColor);
} | java | public void setColor(int n, int color) {
int firstColor = map[0];
int lastColor = map[256-1];
if (n > 0)
for (int i = 0; i < n; i++)
map[i] = ImageMath.mixColors((float)i/n, firstColor, color);
if (n < 256-1)
for (int i = n; i < 256; i++)
map[i] = ImageMath.mixColors((float)(i-n)/(256-n), color, lastColor);
} | [
"public",
"void",
"setColor",
"(",
"int",
"n",
",",
"int",
"color",
")",
"{",
"int",
"firstColor",
"=",
"map",
"[",
"0",
"]",
";",
"int",
"lastColor",
"=",
"map",
"[",
"256",
"-",
"1",
"]",
";",
"if",
"(",
"n",
">",
"0",
")",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"map",
"[",
"i",
"]",
"=",
"ImageMath",
".",
"mixColors",
"(",
"(",
"float",
")",
"i",
"/",
"n",
",",
"firstColor",
",",
"color",
")",
";",
"if",
"(",
"n",
"<",
"256",
"-",
"1",
")",
"for",
"(",
"int",
"i",
"=",
"n",
";",
"i",
"<",
"256",
";",
"i",
"++",
")",
"map",
"[",
"i",
"]",
"=",
"ImageMath",
".",
"mixColors",
"(",
"(",
"float",
")",
"(",
"i",
"-",
"n",
")",
"/",
"(",
"256",
"-",
"n",
")",
"",
",",
"color",
",",
"lastColor",
")",
";",
"}"
] | Set a knot color.
@param n the knot index
@param color the color | [
"Set",
"a",
"knot",
"color",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L151-L160 |
162,686 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.setKnotType | public void setKnotType(int n, int type) {
knotTypes[n] = (byte)((knotTypes[n] & ~COLOR_MASK) | type);
rebuildGradient();
} | java | public void setKnotType(int n, int type) {
knotTypes[n] = (byte)((knotTypes[n] & ~COLOR_MASK) | type);
rebuildGradient();
} | [
"public",
"void",
"setKnotType",
"(",
"int",
"n",
",",
"int",
"type",
")",
"{",
"knotTypes",
"[",
"n",
"]",
"=",
"(",
"byte",
")",
"(",
"(",
"knotTypes",
"[",
"n",
"]",
"&",
"~",
"COLOR_MASK",
")",
"|",
"type",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Set a knot type.
@param n the knot index
@param type the type
@see #getKnotType | [
"Set",
"a",
"knot",
"type",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L197-L200 |
162,687 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.setKnotBlend | public void setKnotBlend(int n, int type) {
knotTypes[n] = (byte)((knotTypes[n] & ~BLEND_MASK) | type);
rebuildGradient();
} | java | public void setKnotBlend(int n, int type) {
knotTypes[n] = (byte)((knotTypes[n] & ~BLEND_MASK) | type);
rebuildGradient();
} | [
"public",
"void",
"setKnotBlend",
"(",
"int",
"n",
",",
"int",
"type",
")",
"{",
"knotTypes",
"[",
"n",
"]",
"=",
"(",
"byte",
")",
"(",
"(",
"knotTypes",
"[",
"n",
"]",
"&",
"~",
"BLEND_MASK",
")",
"|",
"type",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Set a knot blend type.
@param n the knot index
@param type the knot blend type
@see #getKnotBlend | [
"Set",
"a",
"knot",
"blend",
"type",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L218-L221 |
162,688 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.setKnots | public void setKnots(int[] x, int[] rgb, byte[] types) {
numKnots = rgb.length+2;
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
if (x != null)
System.arraycopy(x, 0, xKnots, 1, numKnots-2);
else
for (int i = 1; i > numKnots-1; i++)
xKnots[i] = 255*i/(numKnots-2);
System.arraycopy(rgb, 0, yKnots, 1, numKnots-2);
if (types != null)
System.arraycopy(types, 0, knotTypes, 1, numKnots-2);
else
for (int i = 0; i > numKnots; i++)
knotTypes[i] = RGB|SPLINE;
sortKnots();
rebuildGradient();
} | java | public void setKnots(int[] x, int[] rgb, byte[] types) {
numKnots = rgb.length+2;
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
if (x != null)
System.arraycopy(x, 0, xKnots, 1, numKnots-2);
else
for (int i = 1; i > numKnots-1; i++)
xKnots[i] = 255*i/(numKnots-2);
System.arraycopy(rgb, 0, yKnots, 1, numKnots-2);
if (types != null)
System.arraycopy(types, 0, knotTypes, 1, numKnots-2);
else
for (int i = 0; i > numKnots; i++)
knotTypes[i] = RGB|SPLINE;
sortKnots();
rebuildGradient();
} | [
"public",
"void",
"setKnots",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"rgb",
",",
"byte",
"[",
"]",
"types",
")",
"{",
"numKnots",
"=",
"rgb",
".",
"length",
"+",
"2",
";",
"xKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"yKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"knotTypes",
"=",
"new",
"byte",
"[",
"numKnots",
"]",
";",
"if",
"(",
"x",
"!=",
"null",
")",
"System",
".",
"arraycopy",
"(",
"x",
",",
"0",
",",
"xKnots",
",",
"1",
",",
"numKnots",
"-",
"2",
")",
";",
"else",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
">",
"numKnots",
"-",
"1",
";",
"i",
"++",
")",
"xKnots",
"[",
"i",
"]",
"=",
"255",
"*",
"i",
"/",
"(",
"numKnots",
"-",
"2",
")",
";",
"System",
".",
"arraycopy",
"(",
"rgb",
",",
"0",
",",
"yKnots",
",",
"1",
",",
"numKnots",
"-",
"2",
")",
";",
"if",
"(",
"types",
"!=",
"null",
")",
"System",
".",
"arraycopy",
"(",
"types",
",",
"0",
",",
"knotTypes",
",",
"1",
",",
"numKnots",
"-",
"2",
")",
";",
"else",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
">",
"numKnots",
";",
"i",
"++",
")",
"knotTypes",
"[",
"i",
"]",
"=",
"RGB",
"|",
"SPLINE",
";",
"sortKnots",
"(",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Set the values of all the knots.
This version does not require the "extra" knots at -1 and 256
@param x the knot positions
@param rgb the knot colors
@param types the knot types | [
"Set",
"the",
"values",
"of",
"all",
"the",
"knots",
".",
"This",
"version",
"does",
"not",
"require",
"the",
"extra",
"knots",
"at",
"-",
"1",
"and",
"256"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L288-L306 |
162,689 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.setKnots | public void setKnots(int[] x, int[] y, byte[] types, int offset, int count) {
numKnots = count;
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
System.arraycopy(x, offset, xKnots, 0, numKnots);
System.arraycopy(y, offset, yKnots, 0, numKnots);
System.arraycopy(types, offset, knotTypes, 0, numKnots);
sortKnots();
rebuildGradient();
} | java | public void setKnots(int[] x, int[] y, byte[] types, int offset, int count) {
numKnots = count;
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
System.arraycopy(x, offset, xKnots, 0, numKnots);
System.arraycopy(y, offset, yKnots, 0, numKnots);
System.arraycopy(types, offset, knotTypes, 0, numKnots);
sortKnots();
rebuildGradient();
} | [
"public",
"void",
"setKnots",
"(",
"int",
"[",
"]",
"x",
",",
"int",
"[",
"]",
"y",
",",
"byte",
"[",
"]",
"types",
",",
"int",
"offset",
",",
"int",
"count",
")",
"{",
"numKnots",
"=",
"count",
";",
"xKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"yKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"knotTypes",
"=",
"new",
"byte",
"[",
"numKnots",
"]",
";",
"System",
".",
"arraycopy",
"(",
"x",
",",
"offset",
",",
"xKnots",
",",
"0",
",",
"numKnots",
")",
";",
"System",
".",
"arraycopy",
"(",
"y",
",",
"offset",
",",
"yKnots",
",",
"0",
",",
"numKnots",
")",
";",
"System",
".",
"arraycopy",
"(",
"types",
",",
"offset",
",",
"knotTypes",
",",
"0",
",",
"numKnots",
")",
";",
"sortKnots",
"(",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Set the values of a set of knots.
@param x the knot positions
@param y the knot colors
@param types the knot types
@param offset the first knot to set
@param count the number of knots | [
"Set",
"the",
"values",
"of",
"a",
"set",
"of",
"knots",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L316-L326 |
162,690 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.splitSpan | public void splitSpan(int n) {
int x = (xKnots[n] + xKnots[n+1])/2;
addKnot(x, getColor(x/256.0f), knotTypes[n]);
rebuildGradient();
} | java | public void splitSpan(int n) {
int x = (xKnots[n] + xKnots[n+1])/2;
addKnot(x, getColor(x/256.0f), knotTypes[n]);
rebuildGradient();
} | [
"public",
"void",
"splitSpan",
"(",
"int",
"n",
")",
"{",
"int",
"x",
"=",
"(",
"xKnots",
"[",
"n",
"]",
"+",
"xKnots",
"[",
"n",
"+",
"1",
"]",
")",
"/",
"2",
";",
"addKnot",
"(",
"x",
",",
"getColor",
"(",
"x",
"/",
"256.0f",
")",
",",
"knotTypes",
"[",
"n",
"]",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Split a span into two by adding a knot in the middle.
@param n the span index | [
"Split",
"a",
"span",
"into",
"two",
"by",
"adding",
"a",
"knot",
"in",
"the",
"middle",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L332-L336 |
162,691 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.knotAt | public int knotAt(int x) {
for (int i = 1; i < numKnots-1; i++)
if (xKnots[i+1] > x)
return i;
return 1;
} | java | public int knotAt(int x) {
for (int i = 1; i < numKnots-1; i++)
if (xKnots[i+1] > x)
return i;
return 1;
} | [
"public",
"int",
"knotAt",
"(",
"int",
"x",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"numKnots",
"-",
"1",
";",
"i",
"++",
")",
"if",
"(",
"xKnots",
"[",
"i",
"+",
"1",
"]",
">",
"x",
")",
"return",
"i",
";",
"return",
"1",
";",
"}"
] | Return the knot at a given position.
@param x the position
@return the knot number, or 1 if no knot found | [
"Return",
"the",
"knot",
"at",
"a",
"given",
"position",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L365-L370 |
162,692 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.randomize | public void randomize() {
numKnots = 4 + (int)(6*Math.random());
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
for (int i = 0; i < numKnots; i++) {
xKnots[i] = (int)(255 * Math.random());
yKnots[i] = 0xff000000 | ((int)(255 * Math.random()) << 16) | ((int)(255 * Math.random()) << 8) | (int)(255 * Math.random());
knotTypes[i] = RGB|SPLINE;
}
xKnots[0] = -1;
xKnots[1] = 0;
xKnots[numKnots-2] = 255;
xKnots[numKnots-1] = 256;
sortKnots();
rebuildGradient();
} | java | public void randomize() {
numKnots = 4 + (int)(6*Math.random());
xKnots = new int[numKnots];
yKnots = new int[numKnots];
knotTypes = new byte[numKnots];
for (int i = 0; i < numKnots; i++) {
xKnots[i] = (int)(255 * Math.random());
yKnots[i] = 0xff000000 | ((int)(255 * Math.random()) << 16) | ((int)(255 * Math.random()) << 8) | (int)(255 * Math.random());
knotTypes[i] = RGB|SPLINE;
}
xKnots[0] = -1;
xKnots[1] = 0;
xKnots[numKnots-2] = 255;
xKnots[numKnots-1] = 256;
sortKnots();
rebuildGradient();
} | [
"public",
"void",
"randomize",
"(",
")",
"{",
"numKnots",
"=",
"4",
"+",
"(",
"int",
")",
"(",
"6",
"*",
"Math",
".",
"random",
"(",
")",
")",
";",
"xKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"yKnots",
"=",
"new",
"int",
"[",
"numKnots",
"]",
";",
"knotTypes",
"=",
"new",
"byte",
"[",
"numKnots",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numKnots",
";",
"i",
"++",
")",
"{",
"xKnots",
"[",
"i",
"]",
"=",
"(",
"int",
")",
"(",
"255",
"*",
"Math",
".",
"random",
"(",
")",
")",
";",
"yKnots",
"[",
"i",
"]",
"=",
"0xff000000",
"|",
"(",
"(",
"int",
")",
"(",
"255",
"*",
"Math",
".",
"random",
"(",
")",
")",
"<<",
"16",
")",
"|",
"(",
"(",
"int",
")",
"(",
"255",
"*",
"Math",
".",
"random",
"(",
")",
")",
"<<",
"8",
")",
"|",
"(",
"int",
")",
"(",
"255",
"*",
"Math",
".",
"random",
"(",
")",
")",
";",
"knotTypes",
"[",
"i",
"]",
"=",
"RGB",
"|",
"SPLINE",
";",
"}",
"xKnots",
"[",
"0",
"]",
"=",
"-",
"1",
";",
"xKnots",
"[",
"1",
"]",
"=",
"0",
";",
"xKnots",
"[",
"numKnots",
"-",
"2",
"]",
"=",
"255",
";",
"xKnots",
"[",
"numKnots",
"-",
"1",
"]",
"=",
"256",
";",
"sortKnots",
"(",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Randomize the gradient. | [
"Randomize",
"the",
"gradient",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L464-L480 |
162,693 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java | Gradient.mutate | public void mutate(float amount) {
for (int i = 0; i < numKnots; i++) {
int rgb = yKnots[i];
int r = ((rgb >> 16) & 0xff);
int g = ((rgb >> 8) & 0xff);
int b = (rgb & 0xff);
r = PixelUtils.clamp( (int)(r + amount * 255 * (Math.random()-0.5)) );
g = PixelUtils.clamp( (int)(g + amount * 255 * (Math.random()-0.5)) );
b = PixelUtils.clamp( (int)(b + amount * 255 * (Math.random()-0.5)) );
yKnots[i] = 0xff000000 | (r << 16) | (g << 8) | b;
knotTypes[i] = RGB|SPLINE;
}
sortKnots();
rebuildGradient();
} | java | public void mutate(float amount) {
for (int i = 0; i < numKnots; i++) {
int rgb = yKnots[i];
int r = ((rgb >> 16) & 0xff);
int g = ((rgb >> 8) & 0xff);
int b = (rgb & 0xff);
r = PixelUtils.clamp( (int)(r + amount * 255 * (Math.random()-0.5)) );
g = PixelUtils.clamp( (int)(g + amount * 255 * (Math.random()-0.5)) );
b = PixelUtils.clamp( (int)(b + amount * 255 * (Math.random()-0.5)) );
yKnots[i] = 0xff000000 | (r << 16) | (g << 8) | b;
knotTypes[i] = RGB|SPLINE;
}
sortKnots();
rebuildGradient();
} | [
"public",
"void",
"mutate",
"(",
"float",
"amount",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numKnots",
";",
"i",
"++",
")",
"{",
"int",
"rgb",
"=",
"yKnots",
"[",
"i",
"]",
";",
"int",
"r",
"=",
"(",
"(",
"rgb",
">>",
"16",
")",
"&",
"0xff",
")",
";",
"int",
"g",
"=",
"(",
"(",
"rgb",
">>",
"8",
")",
"&",
"0xff",
")",
";",
"int",
"b",
"=",
"(",
"rgb",
"&",
"0xff",
")",
";",
"r",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"r",
"+",
"amount",
"*",
"255",
"*",
"(",
"Math",
".",
"random",
"(",
")",
"-",
"0.5",
")",
")",
")",
";",
"g",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"g",
"+",
"amount",
"*",
"255",
"*",
"(",
"Math",
".",
"random",
"(",
")",
"-",
"0.5",
")",
")",
")",
";",
"b",
"=",
"PixelUtils",
".",
"clamp",
"(",
"(",
"int",
")",
"(",
"b",
"+",
"amount",
"*",
"255",
"*",
"(",
"Math",
".",
"random",
"(",
")",
"-",
"0.5",
")",
")",
")",
";",
"yKnots",
"[",
"i",
"]",
"=",
"0xff000000",
"|",
"(",
"r",
"<<",
"16",
")",
"|",
"(",
"g",
"<<",
"8",
")",
"|",
"b",
";",
"knotTypes",
"[",
"i",
"]",
"=",
"RGB",
"|",
"SPLINE",
";",
"}",
"sortKnots",
"(",
")",
";",
"rebuildGradient",
"(",
")",
";",
"}"
] | Mutate the gradient.
@param amount the amount in the range zero to one | [
"Mutate",
"the",
"gradient",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/jhlabs/image/Gradient.java#L486-L500 |
162,694 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.setBufferedImage | public void setBufferedImage(BufferedImage img) {
image = img;
width = img.getWidth();
height = img.getHeight();
updateColorArray();
} | java | public void setBufferedImage(BufferedImage img) {
image = img;
width = img.getWidth();
height = img.getHeight();
updateColorArray();
} | [
"public",
"void",
"setBufferedImage",
"(",
"BufferedImage",
"img",
")",
"{",
"image",
"=",
"img",
";",
"width",
"=",
"img",
".",
"getWidth",
"(",
")",
";",
"height",
"=",
"img",
".",
"getHeight",
"(",
")",
";",
"updateColorArray",
"(",
")",
";",
"}"
] | Sets a new image
@param BufferedImage imagem | [
"Sets",
"a",
"new",
"image"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L353-L358 |
162,695 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.getNewImageInstance | public BufferedImage getNewImageInstance() {
BufferedImage buf = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
buf.setData(image.getData());
return buf;
} | java | public BufferedImage getNewImageInstance() {
BufferedImage buf = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
buf.setData(image.getData());
return buf;
} | [
"public",
"BufferedImage",
"getNewImageInstance",
"(",
")",
"{",
"BufferedImage",
"buf",
"=",
"new",
"BufferedImage",
"(",
"image",
".",
"getWidth",
"(",
")",
",",
"image",
".",
"getHeight",
"(",
")",
",",
"image",
".",
"getType",
"(",
")",
")",
";",
"buf",
".",
"setData",
"(",
"image",
".",
"getData",
"(",
")",
")",
";",
"return",
"buf",
";",
"}"
] | Return a new instance of the BufferedImage
@return BufferedImage | [
"Return",
"a",
"new",
"instance",
"of",
"the",
"BufferedImage"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L467-L471 |
162,696 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.getBufferedImage | public BufferedImage getBufferedImage(int width, int height) {
// using the new approach of Java 2D API
BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) buf.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(image, 0, 0, width, height, null);
g2d.dispose();
return (buf);
} | java | public BufferedImage getBufferedImage(int width, int height) {
// using the new approach of Java 2D API
BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) buf.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(image, 0, 0, width, height, null);
g2d.dispose();
return (buf);
} | [
"public",
"BufferedImage",
"getBufferedImage",
"(",
"int",
"width",
",",
"int",
"height",
")",
"{",
"// using the new approach of Java 2D API",
"BufferedImage",
"buf",
"=",
"new",
"BufferedImage",
"(",
"width",
",",
"height",
",",
"BufferedImage",
".",
"TYPE_INT_ARGB",
")",
";",
"Graphics2D",
"g2d",
"=",
"(",
"Graphics2D",
")",
"buf",
".",
"getGraphics",
"(",
")",
";",
"g2d",
".",
"setRenderingHint",
"(",
"RenderingHints",
".",
"KEY_INTERPOLATION",
",",
"RenderingHints",
".",
"VALUE_INTERPOLATION_BILINEAR",
")",
";",
"g2d",
".",
"drawImage",
"(",
"image",
",",
"0",
",",
"0",
",",
"width",
",",
"height",
",",
"null",
")",
";",
"g2d",
".",
"dispose",
"(",
")",
";",
"return",
"(",
"buf",
")",
";",
"}"
] | Resize and return the image passing the new height and width
@param height
@param width
@return | [
"Resize",
"and",
"return",
"the",
"image",
"passing",
"the",
"new",
"height",
"and",
"width"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L480-L488 |
162,697 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.resize | public void resize(int w, int h) {
// using the new approach of Java 2D API
BufferedImage buf = new BufferedImage(w, h, image.getType());
Graphics2D g2d = (Graphics2D) buf.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(image, 0, 0, w, h, null);
g2d.dispose();
image = buf;
width = w;
height = h;
updateColorArray();
} | java | public void resize(int w, int h) {
// using the new approach of Java 2D API
BufferedImage buf = new BufferedImage(w, h, image.getType());
Graphics2D g2d = (Graphics2D) buf.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(image, 0, 0, w, h, null);
g2d.dispose();
image = buf;
width = w;
height = h;
updateColorArray();
} | [
"public",
"void",
"resize",
"(",
"int",
"w",
",",
"int",
"h",
")",
"{",
"// using the new approach of Java 2D API",
"BufferedImage",
"buf",
"=",
"new",
"BufferedImage",
"(",
"w",
",",
"h",
",",
"image",
".",
"getType",
"(",
")",
")",
";",
"Graphics2D",
"g2d",
"=",
"(",
"Graphics2D",
")",
"buf",
".",
"getGraphics",
"(",
")",
";",
"g2d",
".",
"setRenderingHint",
"(",
"RenderingHints",
".",
"KEY_INTERPOLATION",
",",
"RenderingHints",
".",
"VALUE_INTERPOLATION_BILINEAR",
")",
";",
"g2d",
".",
"drawImage",
"(",
"image",
",",
"0",
",",
"0",
",",
"w",
",",
"h",
",",
"null",
")",
";",
"g2d",
".",
"dispose",
"(",
")",
";",
"image",
"=",
"buf",
";",
"width",
"=",
"w",
";",
"height",
"=",
"h",
";",
"updateColorArray",
"(",
")",
";",
"}"
] | Resize the image passing the new height and width
@param height
@param width
@return | [
"Resize",
"the",
"image",
"passing",
"the",
"new",
"height",
"and",
"width"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L534-L546 |
162,698 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.multi8p | public double multi8p(int x, int y, double masc) {
int aR = getIntComponent0(x - 1, y - 1);
int bR = getIntComponent0(x - 1, y);
int cR = getIntComponent0(x - 1, y + 1);
int aG = getIntComponent1(x - 1, y - 1);
int bG = getIntComponent1(x - 1, y);
int cG = getIntComponent1(x - 1, y + 1);
int aB = getIntComponent1(x - 1, y - 1);
int bB = getIntComponent1(x - 1, y);
int cB = getIntComponent1(x - 1, y + 1);
int dR = getIntComponent0(x, y - 1);
int eR = getIntComponent0(x, y);
int fR = getIntComponent0(x, y + 1);
int dG = getIntComponent1(x, y - 1);
int eG = getIntComponent1(x, y);
int fG = getIntComponent1(x, y + 1);
int dB = getIntComponent1(x, y - 1);
int eB = getIntComponent1(x, y);
int fB = getIntComponent1(x, y + 1);
int gR = getIntComponent0(x + 1, y - 1);
int hR = getIntComponent0(x + 1, y);
int iR = getIntComponent0(x + 1, y + 1);
int gG = getIntComponent1(x + 1, y - 1);
int hG = getIntComponent1(x + 1, y);
int iG = getIntComponent1(x + 1, y + 1);
int gB = getIntComponent1(x + 1, y - 1);
int hB = getIntComponent1(x + 1, y);
int iB = getIntComponent1(x + 1, y + 1);
double rgb = 0;
rgb = ((aR * masc) + (bR * masc) + (cR * masc) +
(dR * masc) + (eR * masc) + (fR * masc) +
(gR * masc) + (hR * masc) + (iR * masc));
return (rgb);
} | java | public double multi8p(int x, int y, double masc) {
int aR = getIntComponent0(x - 1, y - 1);
int bR = getIntComponent0(x - 1, y);
int cR = getIntComponent0(x - 1, y + 1);
int aG = getIntComponent1(x - 1, y - 1);
int bG = getIntComponent1(x - 1, y);
int cG = getIntComponent1(x - 1, y + 1);
int aB = getIntComponent1(x - 1, y - 1);
int bB = getIntComponent1(x - 1, y);
int cB = getIntComponent1(x - 1, y + 1);
int dR = getIntComponent0(x, y - 1);
int eR = getIntComponent0(x, y);
int fR = getIntComponent0(x, y + 1);
int dG = getIntComponent1(x, y - 1);
int eG = getIntComponent1(x, y);
int fG = getIntComponent1(x, y + 1);
int dB = getIntComponent1(x, y - 1);
int eB = getIntComponent1(x, y);
int fB = getIntComponent1(x, y + 1);
int gR = getIntComponent0(x + 1, y - 1);
int hR = getIntComponent0(x + 1, y);
int iR = getIntComponent0(x + 1, y + 1);
int gG = getIntComponent1(x + 1, y - 1);
int hG = getIntComponent1(x + 1, y);
int iG = getIntComponent1(x + 1, y + 1);
int gB = getIntComponent1(x + 1, y - 1);
int hB = getIntComponent1(x + 1, y);
int iB = getIntComponent1(x + 1, y + 1);
double rgb = 0;
rgb = ((aR * masc) + (bR * masc) + (cR * masc) +
(dR * masc) + (eR * masc) + (fR * masc) +
(gR * masc) + (hR * masc) + (iR * masc));
return (rgb);
} | [
"public",
"double",
"multi8p",
"(",
"int",
"x",
",",
"int",
"y",
",",
"double",
"masc",
")",
"{",
"int",
"aR",
"=",
"getIntComponent0",
"(",
"x",
"-",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"bR",
"=",
"getIntComponent0",
"(",
"x",
"-",
"1",
",",
"y",
")",
";",
"int",
"cR",
"=",
"getIntComponent0",
"(",
"x",
"-",
"1",
",",
"y",
"+",
"1",
")",
";",
"int",
"aG",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"bG",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
")",
";",
"int",
"cG",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
"+",
"1",
")",
";",
"int",
"aB",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"bB",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
")",
";",
"int",
"cB",
"=",
"getIntComponent1",
"(",
"x",
"-",
"1",
",",
"y",
"+",
"1",
")",
";",
"int",
"dR",
"=",
"getIntComponent0",
"(",
"x",
",",
"y",
"-",
"1",
")",
";",
"int",
"eR",
"=",
"getIntComponent0",
"(",
"x",
",",
"y",
")",
";",
"int",
"fR",
"=",
"getIntComponent0",
"(",
"x",
",",
"y",
"+",
"1",
")",
";",
"int",
"dG",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
"-",
"1",
")",
";",
"int",
"eG",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
")",
";",
"int",
"fG",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
"+",
"1",
")",
";",
"int",
"dB",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
"-",
"1",
")",
";",
"int",
"eB",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
")",
";",
"int",
"fB",
"=",
"getIntComponent1",
"(",
"x",
",",
"y",
"+",
"1",
")",
";",
"int",
"gR",
"=",
"getIntComponent0",
"(",
"x",
"+",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"hR",
"=",
"getIntComponent0",
"(",
"x",
"+",
"1",
",",
"y",
")",
";",
"int",
"iR",
"=",
"getIntComponent0",
"(",
"x",
"+",
"1",
",",
"y",
"+",
"1",
")",
";",
"int",
"gG",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"hG",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
")",
";",
"int",
"iG",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
"+",
"1",
")",
";",
"int",
"gB",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
"-",
"1",
")",
";",
"int",
"hB",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
")",
";",
"int",
"iB",
"=",
"getIntComponent1",
"(",
"x",
"+",
"1",
",",
"y",
"+",
"1",
")",
";",
"double",
"rgb",
"=",
"0",
";",
"rgb",
"=",
"(",
"(",
"aR",
"*",
"masc",
")",
"+",
"(",
"bR",
"*",
"masc",
")",
"+",
"(",
"cR",
"*",
"masc",
")",
"+",
"(",
"dR",
"*",
"masc",
")",
"+",
"(",
"eR",
"*",
"masc",
")",
"+",
"(",
"fR",
"*",
"masc",
")",
"+",
"(",
"gR",
"*",
"masc",
")",
"+",
"(",
"hR",
"*",
"masc",
")",
"+",
"(",
"iR",
"*",
"masc",
")",
")",
";",
"return",
"(",
"rgb",
")",
";",
"}"
] | Multiple of gradient windwos per masc relation of x y
@return int[] | [
"Multiple",
"of",
"gradient",
"windwos",
"per",
"masc",
"relation",
"of",
"x",
"y"
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L565-L606 |
162,699 | sksamuel/scrimage | scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java | MarvinImage.fillRect | public void fillRect(int x, int y, int w, int h, Color c) {
int color = c.getRGB();
for (int i = x; i < x + w; i++) {
for (int j = y; j < y + h; j++) {
setIntColor(i, j, color);
}
}
} | java | public void fillRect(int x, int y, int w, int h, Color c) {
int color = c.getRGB();
for (int i = x; i < x + w; i++) {
for (int j = y; j < y + h; j++) {
setIntColor(i, j, color);
}
}
} | [
"public",
"void",
"fillRect",
"(",
"int",
"x",
",",
"int",
"y",
",",
"int",
"w",
",",
"int",
"h",
",",
"Color",
"c",
")",
"{",
"int",
"color",
"=",
"c",
".",
"getRGB",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"x",
";",
"i",
"<",
"x",
"+",
"w",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"y",
";",
"j",
"<",
"y",
"+",
"h",
";",
"j",
"++",
")",
"{",
"setIntColor",
"(",
"i",
",",
"j",
",",
"color",
")",
";",
"}",
"}",
"}"
] | Fills a rectangle in the image.
@param x rect�s start position in x-axis
@param y rect�s start positioj in y-axis
@param w rect�s width
@param h rect�s height
@param c rect�s color | [
"Fills",
"a",
"rectangle",
"in",
"the",
"image",
"."
] | 52dab448136e6657a71951b0e6b7d5e64dc979ac | https://github.com/sksamuel/scrimage/blob/52dab448136e6657a71951b0e6b7d5e64dc979ac/scrimage-filters/src/main/java/thirdparty/marvin/image/MarvinImage.java#L707-L714 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.